//***********************
//email validation script
//
//use:
//<form name="frmSample" method="post" action="#" onSubmit="return validate_email()">
//	<p>Enter an Email Address : <input type="text" name="email"></p>
//	<p><input type="submit" name="Submit" value="Submit"></p>
//</form>
//***********************
function echeck(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")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid Email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid Email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid Email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid Email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid Email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid Email")
		    return false
		 }

 		 return true					
	}

function validate_email(){
	var emailID=document.frmSample.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email Address")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
 
 
 //******************************************
 //record x and y positions of current window
 //Jon Espenlaub
 //jon@zcarton.com
 //www.zcarton.com
 //06.16.02
 //******************************************
 function defineXCoor () {
 	browserName = navigator.appName;
 	if (browserName == "Microsoft Internet Explorer") {
 		xPos = self.screenLeft;
 	}else{
 		xPos = self.screenX;
 	}
 	return xPos;
 }
 
 function defineYCoor () {
 	browserName = navigator.appName;
 	if (browserName == "Microsoft Internet Explorer") {
 		yPos = self.screenTop;
 	}else{
 		yPos = self.screenY;
 	}
 	return yPos;
 }
 
 
 
 
 
 
 
 
 
 //*************************
 //dynamically center window
 //Jon Espenlaub
 //jon@zcarton.com
 //www.zcarton.com
 //06.16.02
 //*************************
 function zCenter (windowWidth, windowHeight) {
 	//-------------------------------------
 	//get current coordinates of the window
 	//-------------------------------------
 	originalXPos = defineXCoor ();
 	originalYPos = defineYCoor ();
 	
 	//-----------------------
 	//figure coordinate goals
 	//-----------------------
 	screenWidth = window.screen.availWidth;
 	screenHeight = window.screen.availHeight;
 	goalXPos = parseInt(screenWidth/2) - parseInt(windowWidth/2);
 	goalYPos = parseInt(screenHeight/2) - parseInt(windowHeight/2);
 	
 	//------
 	//easing
 	//------
 	xDiff = Math.abs (originalXPos - goalXPos);
 	yDiff = Math.abs (originalYPos - goalYPos);
 	while (xDiff > 0 || yDiff >0) {
 		xDiff /= 2;
 		yDiff /= 2;
 		window.moveBy (-xDiff, -yDiff);
 	}
 	
 	//testing
 	//alert ("close window");
 	//window.close ();
 }
 

 //*************************
 //open window and center
 //Jon Espenlaub
 //jon@zcarton.com
 //www.zcarton.com
 //06.16.02
 //*************************
 function zOpenWindow (objectName, site, name, windowWidth, windowHeight) {
 	screenWidth = window.screen.availWidth;
 	screenHeight = window.screen.availHeight;
 	xPos = parseInt(screenWidth/2) - parseInt(windowWidth/2);
 	yPos = parseInt(screenHeight/2) - parseInt(windowHeight/2);
 
 	//Navigator or Explorer
 	browserName = navigator.appName;
 	if (browserName == "Microsoft Internet Explorer") {
 		prefs = "left="+xPos+",top="+yPos+",height="+windowHeight+",width="+windowWidth;
 	}else{
 		var prefs = "screenX="+xPos+",screenY="+yPos+",height="+windowHeight+",width="+windowWidth;
 	}
 	//document.write (prefs);
 	objectName = window.open(site, name, prefs);
 	objectName.focus();
}