//valitation
function validate()
{
// NAME
	var l=document.frm_contact.name.value.length;
	var m=document.frm_contact.name.value;
	var p=document.frm_contact.name;
	for(var i=0; i<l-1; i++)
		{
		n=m.substring(i, i+2);
		if(n=="  " || n==".." || n=="''")
			{
			alert("Invalid name, Please re-enter")
			p.select();
			return false;
			}
		}
		
	if(m=='') {
		alert("Enter your  Name");
		p.select();
		return false;
	}       
	
	for (var i=0; i<l; i++)
		{
		var q=m.substring(i, i + 1);
		if (((q < "a" || "z" < q) && (q < "A" || "Z" < q)) && q != ' ' && q!='.' && q!="'") {
			alert("\nThe Name field only accepts letters & spaces.\n\nPlease re-enter your Name.");
			p.select();
			return false;
		}
	}
 
	 //PHONE
	var m1=document.frm_contact.code.value;
	var m4=document.frm_contact.code.value.length;
	var p1=document.frm_contact.code;
	
	
	if(m1=='') {
		alert("Enter your Phone Code");
		p1.select();
		return false;
	}
	 
	
	if((m1!='') && isNaN(m1.substr(0,5)))
	{
		alert("Please enter Numbers only");
		p1.select();
		return false;
	}
	 
	 //PHONE
	var m1=document.frm_contact.phone.value;
	var m4=document.frm_contact.phone.value.length;
	var p1=document.frm_contact.phone;
	
	
	if(m1=='') {
		alert("Enter your Phone No");
		p1.select();
		return false;
	}
	 
	
	if((m1!='') && isNaN(m1.substr(0,5)))
	{
		alert("Please enter Numbers only");
		p1.select();
		return false;
	}
	 
	 
	//ADDRESS
	var l=document.frm_contact.address.value.length;
	var m=document.frm_contact.address.value;
	var p=document.frm_contact.address;
	if(m=='') {
		alert("Enter your Adress");
		p.select();
		return false;
	} 
	
	//City
	var l=document.frm_contact.city.value.length;
	var m=document.frm_contact.city.value;
	var p=document.frm_contact.city;
	if(m=='') {
		alert("Enter your City");
		p.select();
		return false;
	}  
	//State
	var l=document.frm_contact.state.value.length;
	var m=document.frm_contact.state.value;
	var p=document.frm_contact.state;
	if(m=='') {
		alert("Enter your State");
		p.select();
		return false;
	}  
	 
	//zipcode
	var m1=document.frm_contact.zip.value;
	var m4=document.frm_contact.zip.value.length;
	var p1=document.frm_contact.zip;
	
	
	if(m1=='') {
		alert("Enter your Zip Code");
		p1.select();
		return false;
	}
	 
	
	if((m1!='') && isNaN(m1.substr(0,5)))
	{
		alert("Please enter Numbers only");
		p1.select();
		return false;
	}
	
	//EMAIL
	var m=document.frm_contact.email;
	var n=document.frm_contact.email.value;
	if ((n==null)||(n=="")){
		alert("Please Enter your Email ID")
		m.select()
		return false
	}
	if (echeck(n)==false){
		alert('Please enter valid email ID');
		m.select();
		return false;
	}
	function echeck(str) {
	at = str.indexOf("@");
	dot = str.lastIndexOf(".");
	lengt = str.length;
	con1 = str.substring(0,at);
	con2 = str.substring(at+1,dot);
	con3 = str.substring(dot+1,lengt);

	if(con1=='' || con2=='' || con3=='') return false;

	if(str.indexOf("  ") > -1 || str.indexOf("..") > -1 || str.indexOf("__") > -1 || str.indexOf("--") > -1) return false;
	
	if(at==-1 || dot==-1) return false;

	x = con1.substring(0,1);
	if ((x < "a" || "z" < x) && (x < "A" || "Z" < x) && isNaN(x)) return false;

	x = con1.substring((con1.length)-1,(con1.length));
	if ((x < "a" || "z" < x) && (x < "A" || "Z" < x) && isNaN(x)) return false;

	x = con1.substring(1,(con1.length)-1);
	for(i=0, y=0; i<con1.length-2; i++, y=x.substring(i, i+1)) if ((y < "a" || "z" < y) && (y < "A" || "Z" < y) && isNaN(y) && y!='.' && y!='_' && y!='-') return false;
	
	x = con2.substring(0,1);
	if ((x < "a" || "z" < x) && (x < "A" || "Z" < x) && isNaN(x)) return false;

	x = con2.substring((con2.length)-1,(con2.length));
	if ((x < "a" || "z" < x) && (x < "A" || "Z" < x) && isNaN(x)) return false;
	
	x = con2.substring(1,(con2.length)-1);
	for(i=0, y=0; i<con2.length-2; i++, y=x.substring(i, i+1)) if ((y < "a" || "z" < y) && (y < "A" || "Z" < y) && isNaN(y) && y!='.' && y!='_' && y!='-') return false;		
	
	for(i=0, x=0; i<con3.length; i++, x = con3.substring(i, i+1)) if ((x < "a" || "z" < x) && (x < "A" || "Z" < x)) return false;
	if ((con3.length)<2 || (con3.length)>4)  return false;
}

//part
	var l=document.frm_contact.part.value.length;
	var m=document.frm_contact.part.value;
	var p=document.frm_contact.part;
	if(m=='') {
		alert("Enter your Part No");
		p.select();
		return false;
	}  

//serial
	var l=document.frm_contact.serial.value.length;
	var m=document.frm_contact.serial.value;
	var p=document.frm_contact.serial;
	if(m=='') {
		alert("Enter your Serial #");
		p.select();
		return false;
	}

//Spam
	var m=document.frm_contact.spam.value;
	if(m!=6) {
		alert("To submit - select Need RMA @ drop down option");
		p.select();
		return false;
	}	   	
  
}


function isKeyNav(c){
	switch(c){
		//case 10:	//CarriageReturn
		//case 13:	//LineFeed
		case 0:		//Invisible Characters
		case 8:		//Backspace
		//case 9:		//Tab
		//case 33:	//PageUp
		//case 34:	//PageDown
		//case 35:	//End
		//case 36:	//Home
		//case 45:	//Ins
		//case 46:	//Del
			return true;
	}
	return false;
}



function isKeyNumeric(c){
	if(c>=48 && c<=57){
		return true;
	}
	return false;
}

function isValidKey(fldType, evt, c) {
	keyEntered = false;
	if(c==null){
		c = getKey(evt);
		if(isKeyNav(c)){	
			setKey(evt, 0);
			return false;
		}
		if(c==34 || c==124 || c==126){   //Removed for Veyond  c==39 
	
			setKey(evt, 0);
			return false;
		}		
		keyEntered = true;
	} else {
		c = ascii(c);
	}
	validKey = false;
	switch(fldType){
		case "phoneNumber":
			validKey = isValidPhoneNumberKey(c);
			break;
		case "phoneExtn":
			validKey = isValidPhoneExtnKey(c);
			break;
	}
	if(!validKey && keyEntered){
		if(evt.preventDefault){
			evt.preventDefault();
		}
		evt.returnValue = false;	
		setKey(evt, 0);
	}
	return validKey;
}

function isValidPhoneExtnKey(c){
	if(isKeyNumeric(c)){ //Numbers
		return true;
	}
	return false;
}

function isValidPhoneNumberKey(c){
	if(isKeyNumeric(c)){ //Numbers
		return true;
	}
	return false;
}

function isValidPhoneExtn(element, blnRequired){
	isValid = true;srcElement = element;
	if(element!=null
	   && element.value!=null){
	   element.value = trim(element.value);
	   if(element.value.length>0){
	   	for(i=0;i<element.value.length;i++){
	   		if(!isValidZipCodeKey(element.value.charCodeAt(i))){
	   			isValid = false;
	   			break;
	   		}
	   	}
	   } else {
	   	if(blnRequired) {
	   		isValid = false;
	   	}
	   }
	}
	return isValid;
}

function isValidPhoneNumber(element, blnRequired){
	isValid = true;srcElement = element;
	if(element!=null
	   && element.value!=null){
	   element.value = trim(element.value);
	   if(element.value.length>0){
	   	if(element.value.length!=14){
	   		return false;
	   	}
	   	for(i=0;i<element.value.length;i++){
			switch(i){
				case 0:
					if(element.value.charCodeAt(i)!=40){
						return false;
					}
					break;
				case 4:
					if(element.value.charCodeAt(i)!=41){
						return false;
					}
					break;
				case 5: 
					if(element.value.charCodeAt(i)!=32){
						return false;
					}
					break;
				case 9:
					if(element.value.charCodeAt(i)!=45){
						return false;
					}
					break;
				default:
					if(!isValidPhoneNumberKey(element.value.charCodeAt(i))){
						return false;
					}
					break;
			}
	   	}
	   } else {
	   	if(blnRequired) {
	   		isValid = false;
	   	}
	   }
	}
	return isValid;
}

function Del(Word) {
	a = Word.indexOf("<");
	b = Word.indexOf(">");
	len = Word.length;
	c = Word.substring(0, a);
	if(b == -1)
		b = a;
		d = Word.substring((b + 1), len);
		Word = c + d;
		tagCheck = Word.indexOf("<");
		if(tagCheck != -1)
			Word = Del(Word);
	return Word;
}


