function validateEmail(str) {	
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert(INVALID_EMAIL_ADDRESS)
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert(INVALID_EMAIL_ADDRESS)
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert(INVALID_EMAIL_ADDRESS)
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert(INVALID_EMAIL_ADDRESS)
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert(INVALID_EMAIL_ADDRESS)
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert(INVALID_EMAIL_ADDRESS)
	    return false
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert(INVALID_EMAIL_ADDRESS)
	    return false
	 }

	 return true					
}

function setupLightboxGallery(){
	$(document).ready(function () {		
		$("a[rel='lightbox']").lightBox({fixedNavigation:true});					
	});
}

/* Name		:createCookie
* Purpose	:creates a new cookie
* Returns	:n/a
*/
function createCookie(name, value, expireInDays){
	if(expireInDays){
		var dDate = new Date();
		dDate.setTime(dDate.getTime() + (expireInDays * 24 * 60 * 60 * 1000));
		var sExpires = "; expires=" + dDate.toGMTString();
	}else{
		var sExpires = "";
	}
	document.cookie = name + "=" + value + sExpires + "; path=/";
}
/* Name		:eraseCookie
* Purpose	:erases a cookie
* Returns	:n/a
*/
function eraseCookie(name){
	createCookie(name, "", -1);
}
/* Name		:readCookie
* Purpose	:reads a cookie
* Returns	:n/a
*/
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i = 0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function displayVideoLightbox(pageUrl){
	$(document).ready(function () {		
		if(pageUrl == "video" || pageUrl == "video-quick-projects"){
			$("#videoLightbox").show();			
		}else{
			$("#videoLightbox").hide();
		}
	});
}

function hideVideoLightbox(){
	/*To fix IE8 issue where the sound playback continues after closing the popup*/		
	var flashContentDiv = document.getElementById("videoLightbox");
	flashContentDiv.innerHTML = "";
	moSwf = null;
	$("#videoLightbox").hide();
}

function ieFix(topLevel) {	
	var ua = navigator.userAgent;
	var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
	var isMSIE5_5 = isMSIE && (ua.indexOf('MSIE 5.5') != -1);
	var isMSIE6 = isMSIE && (ua.indexOf('MSIE 6.0') != -1);

	if (isMSIE5_5 || isMSIE6){	
		$("#siteMenu li").hover(
		  function () {
		    $(this).addClass("hover");		    
		  },
		  function () {
		  	$(this).removeClass("hover");	
		  }
		);	
	}
}