//-- the following script captures the x and y co-ordinates of the mouse


var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else {  // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}  
//	if (tempX < 0){tempX = 0;}
//	if (tempY < 0){tempY = 0;}  
//	document.Show.MouseX.value = tempX;
//	document.Show.MouseY.value = tempY;
//	return true;
}


function showMenu(menu){
	document.getElementById(menu).style.display="block";
	document.getElementById(menu).style.left=tempX-60;

}
function hideMenu(menu){
	document.getElementById(menu).style.display="none";	
}


// Hang & Level Scripts

// --------to open a window (Generic)
function popWin(url,name,width,height) { // opens a popup Window
			var etc = "menubar=no,scrollbars=no,resizable=no,width=" + width + ",height=" + height  ;
    window.open(url,name,etc);
}

function showDiv(name){
	document.getElementById(name).style.display="block";
	return;
}
function hideDiv(name){
	document.getElementById(name).style.display="none";
	return;
}



// functions for the selections widget
function toggleDiv(name){
	var theMenu=name;
	var theState=document.getElementById(theMenu).style.display;
	if(theState=="block"){
		hideDiv(theMenu);
	}else{
		showDiv(theMenu);
	}
}

// tool features toggle
function hideAllFeatures(){
	hideDiv('feature_intro');
	hideDiv('feature_a');
	hideDiv('feature_b');
	hideDiv('feature_c');
	hideDiv('feature_d');
	hideDiv('feature_e');
	hideDiv('feature_f');
	hideDiv('feature_g');
	hideDiv('feature_h');
	hideDiv('feature_i');
	hideDiv('feature_j');
	hideDiv('feature_k');
}


// form validation for the mailing list sign up
function checkMailingListForm(){
	var errorStringTemp="";

	
}


// form validation for the FAQ sign up
function checkSubmitFaqForm(){
	var errorStringTemp="";
	var theForm=document.getElementById('submitFaqForm');
	// for the case where there are multiple checks on the form reset ALL the form elements to the default class
	theForm.submitFaqName.className="formElement";
	theForm.submitFaqEmail.className="formElement";
	//validate the name
	if(theForm.submitFaqName.value==""){
		errorStringTemp=errorStringTemp + "Please enter your name in the form. \n";
		theForm.submitFaqName.className="formElementSel";
	}
	//validate email address
	if(theForm.submitFaqEmail.value==""){
		errorStringTemp=errorStringTemp + "Please enter your email address in the form. \n";
		theForm.submitFaqEmail.className="formElementSel";
	}else{// /if there is an email address make sure it is in valid format
		var themail=theForm.submitFaqEmail.value;
		if(echeck(themail)==false){
			errorStringTemp=errorStringTemp + "Please enter a valid email address in the form. \n";
			theForm.submitFaqEmail.className="formElementSel";
		}
	}
	// process the result 
	if(errorStringTemp==""){
	theForm.target="_blank";
	theForm.submit();
	//clear the form values
	theForm.submitFaqName.value="";
	theForm.submitFaqEmail.value="";
	theForm.message.value="";
	}else{
		alert(errorStringTemp);	
	}
	
}


// form validation for the send a link to a friend widget
function checkTellAFriendForm(){
	var errorStringTemp="";
	var theForm=document.getElementById('tellAFriendForm');
	// for the case where there are multiple checks on the form reset ALL the form elements to the default class
	theForm.un01.className="formElement";
	theForm.un02.className="formElement";
	theForm.un03.className="formElement";
	theForm.un04.className="formElement";
	//check the values
	//validate the name
	if(theForm.un01.value==""){
		errorStringTemp=errorStringTemp + "Please enter your name in the form. \n";
		theForm.un01.className="formElementSel";
	}
	//validate email address
	if(theForm.un02.value==""){
		errorStringTemp=errorStringTemp + "Please enter your email address in the form. \n";
		theForm.un02.className="formElementSel";
	}else{// /if there is an email address make sure it is in valid format
		var themail=theForm.un02.value;
		if(echeck(themail)==false){
			errorStringTemp=errorStringTemp + "Please enter a valid email address in the form. \n";
			theForm.un02.className="formElementSel";
		}
	}
	//validate recipient's email address
	if(theForm.un03.value==""){
		errorStringTemp=errorStringTemp + "Please enter a recipient email address in the form. \n";
		theForm.un03.className="formElementSel";
	}else{// /if there is an email address make sure it is in valid format
		var themail=theForm.un03.value;
		if(echeck(themail)==false){
			errorStringTemp=errorStringTemp + "Please enter a valid email address for the recipient in the form. \n";
			theForm.un03.className="formElementSel";
		}
	}
	
	
	// process the result 
	if(errorStringTemp==""){
	theForm.target="_blank";
	theForm.submit();
	
	//clear the form values
	theForm.un01.value="";
	theForm.un02.value="";
	theForm.un03.value="";
	theForm.un04.value="";
	// hide the widget
	hideDiv('tellAFriendDiv');

	}else{
	var theErrorString="We're sorry - but there seems to be some required information missing. Please enter the information detailed below and click Send Email when you are finished. \n\n" + errorStringTemp;
	 alert(theErrorString);
	}
	
}

// simple email validation
function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if((str==null)||(str=="")){
/*			alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		   return false;
		}
		if (str.indexOf(at)==-1){
		   /*alert("Please enter a valid email address...");
		   document.getElementById('email').focus();*/
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   /*alert("Please enter a valid email address...");
		   document.getElementById('email').focus();*/
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    /*alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		  /*  alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
/*		    alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
/*		    alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
/*		    alert("Please enter a valid email address...");
			document.getElementById('email').focus();*/
		    return false;
		 }

 		 return true;				
}
	
	

