///////////////////// validation function for form  start from here///////////////////////////////////

function checkEmail (strng) 
{
if (strng == "")
{
alert("Please enter an email address\n");
return false;
}

var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(strng))) { 
alert("Please enter a valid email address\n");
return false;
}
else {
//test email for illegal characters
var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
if (strng.match(illegalChars)) {
alert("The email address contains illegal characters\n");
return false;
}
}
return true;
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone1 (strng) {
if (strng == "") {
alert("Please enter 10 digit phone number\n");
return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
alert("The phone number should be numeric");
return false;;

}
if (!(stripped.length == 10)) {
alert("Please enter 10 digit phone number \n");
return false;
} 
return true;
}
// phone number - strip out delimiters and check for 10 digits


// username - 4-10 chars, uc, lc, and underscore only.
function checkUsername (strng) {
if (strng == "")
{
alert("Please enter the name\n");
return false;
}
var illegalChars = /[^a-zA-Z0-9_" "]/; // allow letters, numbers, and underscores space
if (illegalChars.test(strng))
{
alert("The name contains illegal characters\n");
return false;
} 
return true;
}       
// non-empty textbox
function street(strng) {
if (strng.length == 0) {
alert("Please enter the address\n");
return false;
}
return true;	  
}

function city1(strng) {
if (strng.length == 0) {
alert("Please enter the city\n");
return false;
}
return true;
}

// valid selector from dropdown list

function checkDropdown(choice) {
if (choice == 0) {
alert("Please select the state\n");
return false;
} 
return true;
}  

// phone number - strip out delimiters and check for 10 digits

function checkzip (strng) {
if (strng == "") {
alert("Please enter zip code\n");
return false;
}
var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
if (isNaN(parseInt(stripped))) {
alert("Please enter correct zip code\n");
return false;

}
if (!(stripped.length == 5)) {
alert("Please enter correct zip code\n");
return false;
} 
return true;
}
function security_code(strng) {
if (strng.length == 0) {
alert("Please enter security code\n");
return false;
}
return true;
}

///////////////////// validation function for form  end  here///////////////////////////////////
function validateSubmit()
{  
	if(!checkUsername(document.contact.name.value))
	{ 
	document.contact.name.focus();
    return false;
	}
	if(!street(document.contact.address.value))
	{ 
	document.contact.address.focus();
    return false;
	}
	if(!city1(document.contact.city.value))
	{ 
	document.contact.city.focus();
    return false;
	}
	if(!checkzip(document.contact.zip.value))
	{ 
	document.contact.zip.focus();
     return false;
	}
	if(!checkPhone1(document.contact.phone.value))
	{ 
	document.contact.phone.focus();
    return false;
	}
	
	if(!checkEmail(document.contact.email.value))
	{ 
	document.contact.email.focus();
    return false;
	}
	if(document.contact.security_code.value=='')
	{
	alert("Please enter security code");
	document.contact.security_code.focus();
    return false;
	}
	
	
	//alert("ddsfdsf");
	
	
 	return true;
}	
/////////////////function for change the filed tab/////////////////////////////////
function autotab(original,destination){
if (original.getAttribute&&original.value.length==original.getAttribute("maxlength"))
destination.focus()
}

