

/*
	newFreeCap : function () {

	    // loads new freeCap image
	    if(document.getElementById) {

		// extract image name from image source (i.e. cut off ?randomness)
		var theImage = $('tx_srfreecap_pi2_captcha_image');
		var parts = theImage.src.split("&");
		// add ?(random) to prevent browser/isp caching
		// parts[0] should be id=page_id
		// parts[1] should be L=sys_language_uid
		theImage.src = parts[0] + "&" + parts[1] + "&set=" + Math.round(Math.random()*100000);



var pluginSrfreecap = {
	    } else {
		alert("Sorry, cannot autoreload new image\nSubmit the form and a new image will be loaded");
	    }
	}
}


var helper = {

	Version: '0.1',
	extKey: 'sfpHelper',

	hideElements : function (boxId, tagName) {

	    hideMe = new Array();
	    hideMe = $A($(boxId).getElementsByTagName(tagName)).each(function(e) {

		    if (e.style.visibility == '' || e.style.visibility == 'visible') {
			    e.style.visibility = 'hidden';
		    } else {
			    e.style.visibility = 'visible';
		    }

	    });
	},

	hideElementByClassName : function (container, className) {

		var overlaysOpen = document.getElementsByClassName(className,container);
		overlaysOpen.each(function(element) {
			element.setStyle ({
				display: 'none'
			})
		});

	},

	preloadImages : function(imglist) {
	    var imgs = new Array();
	    var count;
	    if (document.images) {
		for (count=0; count<imglist.length; count++) {
		    imgs[count]=new Image(); imgs[count].src=imglist[count];
		}
	    }
	},

	sfHover : function(idList, tagList) {

		var count;

		for (count=0; count<idList.length; count++) {

			if ($(idList[count])) {

				var sfEls = $(idList[count]).getElementsByTagName(tagList[count]);
				var ulSiblings = $(idList[count]).immediateDescendants();

				for (var i=0; i<sfEls.length; i++) {

					sfEls[i].onmouseover=function() {

						if(this.className.match('index') == 'index') {

							var liIndex = this.className.match(new RegExp('index_[0-9]')).toString().split('_')[1];
							var liCounter = 0;

							if(this.parentNode.id == 'mainNavigation') {

								ulSiblings.each(function(e){
									liCounter ++;
									if(liIndex == liCounter) {

										var rId = helper.uniqueId();
										e.id = 'liM'+rId;
										$('liM'+rId).addClassName('sfhover'+liIndex);
									}
								});
							}
						}

						var rId = helper.uniqueId();
						this.id = 'li'+rId;

						if (!$('li'+rId).hasClassName('sfhover')) {
							$('li'+rId).addClassName('sfhover');
							$('li'+rId).addClassName('sfhover0');
						}

					}

					sfEls[i].onmouseout=function() {

						if(this.className.match('index') == 'index') {
							var liIndex = this.className.match(new RegExp('index_[0-9]')).toString().split('_')[1];
						}

						$(this.id).removeClassName('sfhover');
						$(this.id).removeClassName('sfhover'+liIndex);
						$(this.id).removeClassName('sfhover0');
					}

				}


			}
		}


	},

	getUrlParams : function (url) {
		return url.split('?');
	},

	random : function(imgs) {
	    var imgsNum = 0;

	    imgs.each(function(imgs){
		imgsNum ++
	    });

	    var imgSelect = Math.round(Math.random()*(imgsNum-1));
	    var bgImage = imgs[imgSelect];

	    $('header').setStyle({
		backgroundImage: 'url('+bgImage+')'
	    });
	},

	mark : function(element,errorMsg,marked) {
		try{
		   var elm = $(element);
		    var eadvice = 'captcha-advice-required-' + element;
	    if(marked) {
		   advice = '<div class="validation-advice" id="'+ eadvice +'" style="display:none" >' + errorMsg + '</div>'
					    switch (elm.type.toLowerCase()) {
						    case 'checkbox':
						    case 'radio':
							    var p = elm.parentNode;
							    if(p) {
								    new Insertion.Bottom(p, advice);
							    } else {
								    new Insertion.After(elm, advice);
							    }
							    break;
						    default:
							    new Insertion.After(elm, advice);
					}
				    if(typeof Effect == 'undefined') {
					    $(eadvice).style.display = 'block';
				    } else {
					    new Effect.Appear($(eadvice), {duration : 1 });
				    }
			    elm.removeClassName('validation-passed');
			    elm.addClassName('validation-failed');
			    return false;
		    } else {
			    if($(eadvice) != null) $(eadvice).remove();
			    elm.removeClassName('validation-failed');
			    //elm.addClassName('validation-passed');
			    return true;
		    }
		    } catch(e) {
			    throw(e)
		    }
	    },


	//showloading
	loading : function (boxId, action) {

	    var ajaxLoader = $(boxId);

	    if (ajaxLoader) {

		 if (action == 'start') {
		    Effect.Appear (ajaxLoader);
		 } else {
		   ajaxLoader.hide();
		}

	    }
	},

	overlay : function (element,boxOverlay,boxParent,overlayClass) {

		//create a uniqe id
		var rId = this.uniqueId();

		if (boxOverlay.style.display == 'none') {

			boxOverlay.id = 'b'+rId;

			// creat a dynamic margin
			element.id = 'a'+rId;
			var aTagWidth = $('a'+rId).getWidth();

			boxOverlay.style.marginLeft = 20+aTagWidth+'px';

			helper.hideElementByClassName(boxParent,overlayClass);

			//close open overlayBoxes
			Effect.Appear(boxOverlay);

		}
	},

	//create a uniqe id
	uniqueId : function () {
		var d = new Date();
		var rId = Math.round(Math.random()*d);
		return rId;
	},

	cursor : function (element) {
		element.style.cursor='pointer';
	}

}

preloadImages = function(imglist) {
	var imgs = new Array();
	var count;
	if (document.images) {
		for (count=0; count<imglist.length; count++) {
			imgs[count]=new Image(); imgs[count].src=imglist[count];
		}
	}
}

sfHover = function(idList, tagList) {
	var count;
	for (count=0; count<idList.length; count++) {
		var sfEls = document.getElementById(idList[count]).getElementsByTagName(tagList[count]);
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=' sfhover';
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(' sfhover\\b'), '');
			}
		}
	}	
}

// Mouseover on homepage

mHover = function(idContainer, idOut, idOver) {
	document.getElementById(idContainer).onmouseover=function() {
		document.getElementById(idOut).style.display='none';
		document.getElementById(idOver).style.display='block';
		}
	document.getElementById(idContainer).onmouseout=function() {
		document.getElementById(idOut).style.display='block';
		document.getElementById(idOver).style.display='none';
		}
}

// Popup window for add this function
var  addthis_url   = '';
var  addthis_title = '';
var  addthis_pub = 'webfactory';

function addthis_click(obj, str){

 var aturl  = 'http://www.addthis.com/bookmark.php';
 aturl += '?v=1';
 aturl += '&pub='+addthis_pub;
 aturl += '&url='+encodeURIComponent(addthis_url);
 aturl += '&title='+encodeURIComponent(addthis_title);

 window.open(aturl,'addthis','scrollbars=yes,menubar=no,width=620,height=520,resizable=yes,toolbar=no,location=no,status=no,screenX=200,screenY=100,left=200,top=100');


 return false;
}



*/

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;

		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			
			
            //document.adBanner.src = adImages[thisAd];
			
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}


function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
	 
}



window.onerror=handleError;

function handleError()
{
	return true;
}

function expand_nav(link1)
{
	var ul = find_enclosing_ul(link1)
	if (ul.style.display == 'none')
	{
		ul.style.display = 'block'
	}
	else
	{
		ul.style.display = 'none'
	}
	if (link1.className == 'down')
	{
		link1.className='down_open'
	}
	else
	{
		link1.className='down'
	}
	
}
		
function find_enclosing_ul(link1)
{
	var search_node = link1
	while (true)
	{
		var node = search_node.nextSibling
		if (node && node.nodeName == 'UL')
		{
			break
		}
		else
		{
			search_node = node
		}
	}
	return node	
}


function chktell(){
	if(document.tellfriend.from.value==""){
		alert("Please enter From address")
		document.tellfriend.from.focus();
		return false
	}
	if(document.tellfriend.to.value==""){
		alert("Please enter To address")
		document.tellfriend.to.focus();
		return false
	}
	if(document.tellfriend.subject.value==""){
		alert("Please enter Subject")
		document.tellfriend.subject.focus();
		return false
	}
	if(document.tellfriend.from.value!=""){
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.tellfriend.from.value;
	   if(reg.test(address) == false) {
		  alert('Invalid Email Address');
		  document.tellfriend.from.focus()
		  document.tellfriend.from.value=""
		  return false;
	   }
	}
	if(document.tellfriend.to.value!=""){
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.tellfriend.to.value;
	   if(reg.test(address) == false) {
		  alert('Invalid Email Address');
		  document.tellfriend.to.focus()
		  document.tellfriend.to.value=""
		  return false;
	   }
	}
}

function chknews(){
	if(document.newsletter.firstname.value==""){
		alert("Please enter Firstname")
		document.newsletter.firstname.focus();
		return false
	}
	if(document.newsletter.lastname.value==""){
		alert("Please enter Lastname")
		document.newsletter.lastname.focus();
		return false
	}
	if(document.newsletter.email.value!=""){
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.newsletter.email.value;
	   if(reg.test(address) == false) {
		  alert('Invalid Email Address');
		  document.newsletter.email.focus()
		  document.newsletter.email.value=""
		  return false;
	   }
	}
	else{
		  alert('Please enter valid e-mail');
		  document.newsletter.email.focus()
		  document.newsletter.email.value=""
		  return false;
	}
}


function chkform(){
	if(document.guestbook.firstname.value=="")
	{
		alert("Please Enter Frst Name")
		document.guestbook.firstname.focus()
		return false
	}
	if(document.guestbook.captcha_response.value=="")
	{
		alert("Please fill the code")
		document.guestbook.captcha_response.focus()
		return false
	}
	if(document.guestbook.homepage.value!="")
	{
		val=document.guestbook.homepage.value
		if(val.indexOf('http://')>=0){
			alert("Please enter site name without 'http://'")
			document.guestbook.homepage.value=''
			document.guestbook.homepage.focus()
			return false
		}
	}
	if(document.guestbook.descrip.value=="")
	{
		alert("Please enter description")
		document.guestbook.descrip.focus()
		return false
	}
	if(document.guestbook.email.value!=""){
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var address = document.guestbook.email.value;
	   if(reg.test(address) == false) {
		  alert('Invalid Email Address');
		  document.guestbook.email.focus()
		  document.guestbook.email.value=""
		  return false;
	   }
	}
}

function chksearch(){
	if(document.searchfrm.keyword.value=="")
	{
		alert("Please Keyword to Search")
		document.searchfrm.keyword.focus()
		return false
	}
}
