﻿var submitBtn = 'emailSignupBtn';
var errorDiv = 'errorMsg';
var emailpatt=/^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/g;

////////
function addLoadEvent(func) 
	{ 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') 
		{  
		window.onload = func;  
		} else {  
		window.onload = function() 
			{  
			if (oldonload) 
				{  
				oldonload();  
				}  
			func();  
			}  
		}  
	}


////////
function verifyEmailSignupForm(isTeacherSignupForm)
	{
	var Email = document.getElementById ("signupEmail1").value;
	var Email1 = document.getElementById ("signupEmail2").value;
	
	var error = false;
	showErrorMsg('');

	if (isTeacherSignupForm)
		{
		var firstNameT = document.getElementById ("firstName").value;
		var lastNameT = document.getElementById ("lastName").value;
		var schoolT = document.getElementById ("school").value;
		var gradeLevelT = document.getElementById ("gradeLevel").value;

		var addrT = document.getElementById ("addr1").value;
		var cityT = document.getElementById ("city").value;
		var stateT = document.getElementById ("state").value;
		var zipT = document.getElementById ("zip").value;

		if (firstNameT == '')
			{
			showErrorMsg("Please enter your first name");
			document.getElementById ("firstName").focus();	
			error  = true;
			}
		if (lastNameT == '')
			{
			showErrorMsg("Please enter your last name", true);
			document.getElementById ("lastName").focus();
			error  = true;
			}

		if (addrT == '')
			{
			showErrorMsg("Please enter your street address", true);
			document.getElementById ("addr1").focus();
			error  = true;
			}
		if (cityT == '')
			{
			showErrorMsg("Please enter your city", true);
			document.getElementById ("city").focus();
			error  = true;
			}
		if (stateT == '')
			{
			showErrorMsg("Please enter your state", true);
			document.getElementById ("state").focus();
			error  = true;
			}
/*
		if (zipT == '')
			{
			showErrorMsg("Please enter your ZIP code", true);
			document.getElementById ("zip").focus();
			error  = true;
			}
*/


		if (schoolT == '')
			{
			showErrorMsg("Please enter your school\'s name", true);
			document.getElementById ("school").focus();
			error  = true;
			}
		if (gradeLevelT == '')
			{
			showErrorMsg("Please enter your grade level", true);
			document.getElementById ("gradeLevel").focus();
			error  = true;
			}
		}
	
	
	
	if (Email.length == 0)
		{
		showErrorMsg("Please enter your email address", true);
		document.getElementById ("signupEmail1").focus();
		error  = true;
		}
	else if (Email1.length == 0)
		{
		showErrorMsg("Please verify  your email address", true);
		document.getElementById ("signupEmail2").focus();
		error  = true;
		} else {
		if(Email.match(emailpatt)==null)
			{
			showErrorMsg("Please enter your email address in the proper format");
			document.getElementById ("signupEmail1").focus();
			error  = true;
			} else {
			if(Email != Email1)
				{
				showErrorMsg("The entries for &quot;Email&quot; and &quot;Verify E-mail&quot; must same");
				document.getElementById ("signupEmail2").focus();
				error  = true;
				}
			}
		}
	if (!error)	
		{
		disableEmailSignupSubmitBtn();
		document.emailSignupForm.submit();
		}
	}

////	
function disableEmailSignupSubmitBtn()
	{
	d = document.getElementById(submitBtn);
	d.style.display = 'none';
		
	}
////	
function showErrorMsg(msg, isAppend)
	{
	d = document.getElementById(errorDiv);
	d.innerHTML = (isAppend ? d.innerHTML + '<br>'  : '') +  msg;
	d.style.display = 'block';
	setOpacity(d, 0) ;
	fadeIn(errorDiv, 0);
	}
	
////	
function fadeIn(objId,opacity) 
	{
	if (opacity <= 100) 
		{
		obj = document.getElementById(objId);
		setOpacity(obj, opacity);
		opacity += 5;
		window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 20);
		}
	}
////
function setOpacity(obj, opacity) 
	{
	opacity = (opacity == 100)?99.999:opacity;
	
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	}