// JavaScript Document
//-----------------------------------------------------------------
	  	function emailvalidatorme(frm_nam, fld_nam, msg_innam, fcs_nam) {
			var frm_nam;		//Form Name
			var fld_nam;		//Field Name
			var msg_innam;		//Message
			var fcs_nam;		//Focusing Field name
			
			fld_nam_full = "window.document." + frm_nam + "." + fld_nam;
			fld_fcs_full = "window.document." + frm_nam + "." + fcs_nam;
			//alert(fld_nam_full);
			if(eval(fld_nam_full + ".value.length") == 0) {
				alert("An Error Found:\n  - Enter " + msg_innam + ".");
				eval(fld_fcs_full).focus();
				return (false);
			} else {
				//-------------------------------------------------------------// Check for any invalid Character
				var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@._-";
				var allValid = true;
				for (i = 0;  i < eval(fld_nam_full + ".value.length");  i++)
				{
				  ch = eval(fld_nam_full + ".value").charAt(i);
				  for (j = 0;  j < checkOK.length;  j++)
					if (ch == checkOK.charAt(j))
					  break;
				  if (j == checkOK.length)
				  {
					allValid = false;
					break;
				  }
				}
				if (!allValid)
				{
				  alert("An Error Found:\n  - Invalid character(s) in the " + msg_innam + ".");
				  eval(fld_fcs_full).focus();
				  return (false);
				}
				//-------------------------------------------------------------// Counting number of '@' in the emailaddress
				var atSymbol = 0
				for(var a = 0; a < eval(fld_nam_full + ".value.length"); a++){
					if(eval(fld_nam_full + ".value").charAt(a) == "@"){
						atSymbol++
					}
				}
				
				if(atSymbol > 1){
					alert("An Error Found:\n  - Incomplete Email format (" + msg_innam + ")");
					eval(fld_fcs_full).focus();
					return (false);
				}
				//-------------------------------------------------------------
				if(atSymbol == 1 && eval(fld_nam_full + ".value").charAt(0) != "@"){
					var period = eval(fld_nam_full + ".value").indexOf(".",eval(fld_nam_full + ".value").indexOf("@")+2)//look for period at 2nd character after @ symbol
					var twoPeriods = (eval(fld_nam_full + ".value").charAt((period+1)) == ".") ? true : false// "." immediately following 1st "." ?
					
					//if period was not found OR 2 periods together OR field contains less than 5 characters OR period is in last position
					if(period == -1 || twoPeriods || eval(fld_nam_full + ".value").length < period + 2 || eval(fld_nam_full + ".value").charAt(eval(fld_nam_full + ".value").length-1)=="."){
						alert("An Error Found:\n  - Incomplete Email format (" + msg_innam + ")");
						eval(fld_fcs_full).focus();
						return (false);
					}
				}else{
					alert("An Error Found:\n  - Invalid Email format (" + msg_innam + ")");
					eval(fld_fcs_full).focus();
					return (false);
				}
				//-------------------------------------------------------------
			}
			return (true);
		}

//-----------------------------------------------------------------
	function currencyvalidatorme(frm_nam, fld_nam, msg_innam, fcs_nam) {
		var frm_nam;		//Form Name
		var fld_nam;		//Field Name
		var msg_innam;		//Message
		var fcs_nam;		//Focusing Field name
			
		fld_nam_full = "window.document." + frm_nam + "." + fld_nam;
		fld_fcs_full = "window.document." + frm_nam + "." + fcs_nam;
		//alert(fld_nam_full);
		if(eval(fld_nam_full + ".value.length") == 0) {
			alert("An Error Found:\n  - Enter " + msg_innam + ".");
			eval(fld_fcs_full).focus();
			return (false);
		} else {
		//-------------------------------------------------------------// Check for any invalid Character
			var checkOK = "0123456789.";
			var allValid = true;
			for (i = 0;  i < eval(fld_nam_full + ".value.length");  i++)
			{
			  ch = eval(fld_nam_full + ".value").charAt(i);
			  for (j = 0;  j < checkOK.length;  j++)
				if (ch == checkOK.charAt(j))
				  break;
			  if (j == checkOK.length)
			  {
				allValid = false;
				break;
			  }
			}
			if (!allValid)
			{
			  alert("An Error Found:\n  - Invalid character(s) in the " + msg_innam + ".");
			  eval(fld_fcs_full).focus();
			  return (false);
			}
		}
		//-------------------------------------------------------------// Counting number of '@' in the emailaddress
			var dotSymbol = 0
			for(var a = 0; a < eval(fld_nam_full + ".value.length"); a++){
				if(eval(fld_nam_full + ".value").charAt(a) == "."){
					dotSymbol++
				}
			}
			
			if(dotSymbol > 1){
				alert("An Error Found:\n  - Incomplete Price format (" + msg_innam + ")");
				eval(fld_fcs_full).focus();
				return (false);
			}
		//-------------------------------------------------------------//
		return (true);	
	}
//-----------------------------------------------------------------

function newuservalidator() {
	var theForm;
	theForm = window.document.frm_newuser;
	//=================================================
	if(theForm.txt_firstname.value == "") {
		alert("An Error Found:\n  - Enter First Name");
		theForm.txt_firstname.focus();
		return (false);
	}
	//=============================================
	if(theForm.txt_lastname.value == "") {
		alert("An Error Found:\n  - Enter Last Name");
		theForm.txt_lastname.focus();
		return (false);
	}
	//=============================================
	if(!emailvalidatorme('frm_newuser', 'txt_emailaddress', 'Email Address', 'txt_emailaddress')) {
		return (false);
	}
	//=============================================
	if(theForm.txt_password.value == "") {
		alert("An Error Found:\n  - Enter Password");
		theForm.txt_password.focus();
		return (false);
	} else {
		var passleng = theForm.txt_password.value;
		if(passleng.length < 6) {
			alert("An Error Found:\n  - Password should contain atleast 6 characters.");
			theForm.txt_password.focus();
			return (false);
		}
	}
	//=============================================
	if(theForm.txt_repassword.value == "") {
		alert("An Error Found:\n  - Re-Enter Password");
		theForm.txt_repassword.focus();
		return (false);
	} else {
		var repassleng = theForm.txt_repassword.value;
		if(repassleng.length < 6) {
			alert("An Error Found:\n  - Re-Password should contain atleast 6 characters.");
			theForm.txt_repassword.focus();
			return (false);
		}
		if(theForm.txt_repassword.value != theForm.txt_password.value) {
			alert("An Error Found:\n  - Re-Enter Password does not Match with the Password");
			theForm.txt_repassword.focus();
			return (false);
		}
	}
	//=================================================
	return (true);
}


function edituservalidator() {
	var theForm;
	theForm = window.document.frm_edituser;
	//=================================================
	if(theForm.txt_firstname.value == "") {
		alert("An Error Found:\n  - Enter First Name");
		theForm.txt_firstname.focus();
		return (false);
	}
	//=============================================
	if(theForm.txt_lastname.value == "") {
		alert("An Error Found:\n  - Enter Last Name");
		theForm.txt_lastname.focus();
		return (false);
	}
	//=================================================
	return (true);
}




function emailvalidation() {
	var theForm;
	theForm = window.document.frm_contact;
	//=================================================
	if(theForm.txt_name.value == "") {
		alert("An Error Found:\n  - Enter Full Name");
		theForm.txt_name.focus();
		return (false);
	}
	//=============================================
	if(!emailvalidatorme('frm_contact', 'txt_email', 'Email Address', 'txt_email')) {
		return (false);
	}
	//=============================================
	return (true);
}

function loginvalidation() {
	var theForm;
	theForm = window.document.frm_login;
	//=============================================
	if(!emailvalidatorme('frm_login', 'txt_user', 'Email Address', 'txt_user')) {
		return (false);
	}
	//=================================================
	if(theForm.txt_pass.value == "") {
		alert("An Error Found:\n  - Enter Password");
		theForm.txt_pass.focus();
		return (false);
	}
	//=============================================
	
	return (true);
}

function tellafriendvalidator() {
	var theForm;
	theForm = window.document.frm_tellafriend;
	//=================================================
	if(theForm.txt_yourname.value == "") {
		alert("An Error Found:\n  - Enter Your Name");
		theForm.txt_yourname.focus();
		return (false);
	}
	//=============================================
	if(!emailvalidatorme('frm_tellafriend', 'txt_youremail', 'Your Email Address', 'txt_youremail')) {
		return (false);
	}
	//=============================================
		if(theForm.txt_friendname.value == "") {
		alert("An Error Found:\n  - Name your friend");
		theForm.txt_friendname.focus();
		return (false);
	}
	//=============================================
	if(!emailvalidatorme('frm_tellafriend', 'txt_friendemail', 'Friend\'s Email Address', 'txt_friendemail')) {
		return (false);
	}
	//=============================================
		if(theForm.txt_comments.value == "") {
		alert("An Error Found:\n  - Empty messages cannot be sent.");
		theForm.txt_comments.focus();
		return (false);
	}
	//=============================================	
	return (true);
}

function getpassvalidator() {
	var theForm;
	theForm = window.document.frm_getpassword;
	//=================================================
	if(!emailvalidatorme('frm_getpassword', 'txt_emailaddress', 'Email Address', 'txt_emailaddress')) {
		return (false);
	}
	//=============================================
	return (true);
}


function emailSubscribevalidtor() {
	var theForm;
	theForm = window.document.frm_emailsignup;
	//=============================================
		if(theForm.txt_yourname.value == "") {
		alert("An Error Found:\n  - Enter Your Name to Subscribe for Email News Letters.");
		theForm.txt_yourname.focus();
		return (false);
	}
	//=============================================	
	if(!emailvalidatorme('frm_emailsignup', 'txt_youremail', 'Email Address', 'txt_youremail')) {
		return (false);
	}
	//=============================================
	return (true);
}

function changepasswordvalidator() {
	var theForm;
	theForm = window.document.frm_changepassword;
	//=================================================
	if(theForm.txt_prev_password.value == "") {
		alert("An Error Found:\n  - Enter Previous Password");
		theForm.txt_prev_password.focus();
		return (false);
	}
	//=============================================
	if(theForm.txt_password.value == "") {
		alert("An Error Found:\n  - Enter New Password");
		theForm.txt_password.focus();
		return (false);
	} else {
		var passleng = theForm.txt_password.value;
		if(passleng.length < 6) {
			alert("An Error Found:\n  - Password should contain atleast 6 characters.");
			theForm.txt_password.focus();
			return (false);
		}
	}
	//=============================================
	if(theForm.txt_repassword.value == "") {
		alert("An Error Found:\n  - Re-Enter New Password");
		theForm.txt_repassword.focus();
		return (false);
	} else {
		var repassleng = theForm.txt_repassword.value;
		if(repassleng.length < 6) {
			alert("An Error Found:\n  - ReEntering New Password should contain atleast 6 characters.");
			theForm.txt_repassword.focus();
			return (false);
		}
		if(theForm.txt_repassword.value != theForm.txt_password.value) {
			alert("An Error Found:\n  - Re-Enter New Password does not Match with the New Password");
			theForm.txt_repassword.focus();
			return (false);
		}
	}
	//=================================================
	return (true);
}









