// JavaScript Document
/***********************
*	check form: form.js
*	Date: 03/01/2011
*
*/

function chk(email, formname) {
  invalid = "";
  if (!email)
    invalid = "No email address found!  Try reloading the page then use the 'email a script' feature again.";
  else {
    if ( (email.indexOf("@") == -1) || (email.indexOf(".") == -1) )
    invalid += "\n\nInvalid email address.  Your email address is missing an '@' sign and a '.' in the domain name (like '.com').  Please check your address then submit again.";
    if (email.indexOf(" e-mail address") > -1)
    invalid += "\n\nInvalid email address.  Make sure your email address included your username, the '@' sign, and the domain name (like '.com').";
    if (email.indexOf("\\") > -1)
    invalid += "\n\nEmail address contains an invalid back-slash (\\) character.  Remove the character and submit again.";
    if (email.indexOf("/") > -1)
    invalid += "\n\nEmail address contains an invalid forward-slash (/) character.  Remove the character and submit again.";
    if (email.indexOf("'") > -1)
    invalid += "\n\nEmail address contains an invalid apostrophe (') character.  Remove the character and submit again.";
    if (email.indexOf("zaz.com.br") > -1)
    invalid += "\n\nPlease do not use an email address that has an autoresponder set up for it.  Thanks.";
    if (email.indexOf("!") > -1)
    invalid += "\n\nEmail address contains an invalid exclamation point (!) character.  Remove the character or correct the email address then submit again.";
    if ( (email.indexOf(",") > -1) || (email.indexOf(";") > -1) )
    invalid += "\n\nPlease only enter one email address in the box at a time.  Remove the extra addresses and submit again.";
    if (email.indexOf("?subject") > -1)
    invalid += "\n\nPlease do not add '?subject=...' to your email address.  Scriptbot will send you the script with a pre-defined subject already.  Please remove the '?subject=...' from your email address and submit again.";
  }
  if (invalid == "") {
    var largeExpDate = new Date();
    largeExpDate.setTime(largeExpDate.getTime() + (31 * 24 * 3600 * 1000));
    SetCookie('email_address', email, largeExpDate);
    // Added new from Dan here Tuesday, October 31, 2006
    if (formname == "scriptbot") {
       checkWinGen("AdWindow",
                   "jss_sendWin",
                   "height=320,width=780,titlebar=no,resizable=yes,scrollbars=yes");
    }
    return true;
    // New from Dan ends here
  } else {
    alert("Oops, something is wrong...." + invalid);
    return false;
  }
}
function checkform( form )
{
	if (form.email.value == "") {
		alert( "Vui lòng nhập địa chỉ email của bạn.\nPlease enter your email address." );
		form.email.focus();
		return false ;
	}
	if (!validateEmail(form.email.value)){
		alert( "Vui lòng nhập đúng email.\nPlease enter correct your email address." );
		form.email.focus();
		return false;
	}
	return true ;
}

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
}

function IsNumeric(sText){
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
}
/************/
