// JavaScript Document
function nextbox(fldobj,nbox)
{
if(fldobj.value.length>2)
{document.publicform.elements[nbox].focus()}
}

function getKeyCode(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}
function keyRestrict(e, validchars) { 
	var key='', keychar='';
	key = getKeyCode(e);
	if (key == null) return true;
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	validchars = validchars.toLowerCase();
	if (validchars.indexOf(keychar) != -1)
		return true;
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
		return true;
	return false;
}

function verify() {
var themessage = "Le requieren terminar los campos siguientes: \r\n";
if (document.form.xname.value=="") {
themessage = themessage + "Nombre + ";
}
if (document.form.xorg.value=="") {
themessage = themessage + "Organización + ";
}
if (document.form.xdirection.value=="") {
themessage = themessage + "Dirección + ";
}
if (document.form.xcity.value=="") {
themessage = themessage + "Ciudad + ";
}
if (document.form.xstate.value=="") {
themessage = themessage + "Estado/Provincia + ";
}
if (document.form.xzip.value=="") {
themessage = themessage + "Zip/Código Postal + ";
}
if (document.form.xcountry.value=="") {
themessage = themessage + "País + ";
}
if (document.form.xtelephone.value=="") {
themessage = themessage + "Teléfono + ";
}
if (document.form.xfax.value=="") {
themessage = themessage + "Fax + ";
}
if (document.form.xemail.value=="") {
themessage = themessage + "E-mail";
}

if (document.form.xemail.value!="") {
	text=document.form.xemail.value
// Check For Bad Chars
	badchar = " ()<>\/[]{}+-*|;,'"
	for (i=0;i<text.length;i++) {
		for (j=0;j<badchar.length;j++) {
			if (text.charAt(i) == badchar.charAt(j)) {
				alert("Incorpore por favor su E-mail válido")				
//				alert("Your Email Address May Has Some Bad Character or there is some space between letters")
				return false
			}
		}
	}
	// There Should Be a dot (.) Symbol
	if (text.indexOf(".") == -1) {
		alert("Incorpore por favor su E-mail válido")
//		alert("Your Email Address Doesnot have any dot(.) symbol")
		return false
	}
	// There Should Be an @ Symbol
	if (text.indexOf("@") == -1) {
		alert("Incorpore por favor su E-mail válido")
//		alert("Your Email Address Doesnot have any @ symbol")
		return false
	}
	else {
	// Only one @ symbol should be found
		symbolfound = 0
		for (i=0;i<text.length;i++) {
			if (text.charAt(i) == "@") {
				symbolfound++
			}
			else {
				continue
			}
		}
		if (symbolfound != 1) {
			alert("Incorpore por favor su E-mail válido")
//			alert("Ooops  Your Email Address Has More Than One @ Symbol")
			return false
		}
	}
	// Check For Syntax Errors Such as .@  or   @.  or  ..
	if (text.indexOf("@.") != -1 || text.indexOf(".@") != -1 || text.indexOf("..") != -1) {
		alert("Incorpore por favor su E-mail válido")		
//		alert("Sorry Your Email Address has two symbol side by side and it is wrong")
		return false
	}
	// The first character shouldn't be @ or .
	if (text.charAt(0) == "@" || text.charAt(0) == ".") {
		alert("Incorpore por favor su E-mail válido")		
//		alert("E-mail: Your first character seem to be . or @ and it is wrong")
		return false
	}
	// The last character shouldn't be @ or .
	if (text.charAt(text.length-1) == "@" || text.charAt(text.length-1) == ".") {
		alert("Incorpore por favor su E-mail válido")		
//		alert("E-mail: Your last character seem to be . or @ and it is wrong")
		return false
	}
	// The @ Symbol should be found before .
	foundchar1 = text.indexOf("@")
	foundchar2 = text.indexOf(".")
	if (foundchar1 > foundchar2) {
		alert("Incorpore por favor su E-mail válido")		
//		alert("E-mail: Sorry The @ Symbol should be found before dot(.)symbol but it isnt in yours")
		return false
	}

}

var val1 = Number(document.form.xzip.value);
if(isNaN(val1))
{
	return alert("Introduzca por favor el código postal válido..");
}
var val2 = Number(document.form.xtelephone.value);
if(isNaN(val2))
{
	return alert("Incorpore por favor el número de teléfono válido..");
}

var val3 = Number(document.form.xfax.value);
if(isNaN(val3))
{
	return alert("Incorpore por favor el número de FAX válido..");
}

//alert if fields are empty and cancel form submit
if (themessage == "Le requieren terminar los campos siguientes: \r\n") 
{
  	window.open('', "Email", 'top=100,left=100,height=350,width=500');
	document.form.target="Email"; 
	document.form.action = "sendad.php"; 
	document.form.submit(); 
	document.form.reset();
}
else {
alert(themessage);
return false;
   }
}
