function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+";path=/";
}

function begin_fade()
{
	$('#current_slide').fadeOut(1000,
		function(){
			if(fade)
			{
				switch_image();
				begin_fade();
			}
		}
	);
}
function switch_image()
{
	if(fade)
	{
		$('#current_slide').css('background', $('#next_slide').css('background'));

        $('#current_slide').fadeIn(4000,
            function(){
		        next_image = (current_image + 1 )% (images.length);
		        $('#next_slide').css('background',"url('" + images[next_image] + "')");

		        
		        $('.slide').removeClass("current");
		        $('#nav_' + current_image).addClass("current");
		        current_image = next_image;	
                }
            );			
	}
}

function trim(strText) { 

	while (strText.substring(0,1) == ' ') 
	{
		strText = strText.substring(1, strText.length);
	}
	
	while (strText.substring(strText.length-1,strText.length) == ' ')
	{
		strText = strText.substring(0, strText.length-1);
	}
	
	return strText;
}


function ValidateNumber(textbox){
	if(textbox.value != ""){
		if(isNaN(textbox.value)){
			alert("Please enter a number.");
			textbox.focus();
		}
	}
}


function ConfirmDelete(sName, sAdditionalText){
	var strConfirm = "Are you sure you want to delete '" + sName + "'?";
	if(sAdditionalText != ""){
		strConfirm += "\n" + sAdditionalText;
	}
	return confirm(strConfirm);
}


function IsValidEmail(str) {
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if(str.indexOf(at)==-1){ return false; }
	if(str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false; }
	if(str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false; }
	if(str.indexOf(at,(lat+1))!=-1){ return false; }
	if(str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false; }
	if(str.indexOf(dot,(lat+2))==-1){ return false; }
	if(str.indexOf(" ")!=-1){ return false; }
	return true;
}


