function ValidarLogin (f) {
	if (f.email.value=='') {
		alert ("User field cannot be empty");
	} else if (f.password.value==''){
		alert ("Password field cannot be empty");
	} else {
		f.submit();
	}
		
}
function ValidLogin () {
	if (document.form_affiliate.email.value=='') {
		alert ("The email field can not be empty");
	} else if (document.form_affiliate.password.value==''){
		alert ("The password field can not be empty");
	} else {
		document.form_affiliate.submit();
	}
		
}

function validaremail(theElement)
{
var s = theElement;
var filter=/^[A-Za-z0-9_\.\-]+@([A-Za-z0-9_\.\-]+\.)+[A-Za-z]{2,4}$/;
if (s.length == 0 ) return true;
if (filter.test(s))
return true;
else
return false;
}

function ValidarFormUser (f) {
	var error = "";
	if (f.lastname.value == '') {
		error+="El campo apellido no puede ser vacio. \n";
	} 
	if (f.firstname.value == '') {
		error+="El campo nombre no puede ser vacio. \n";
	}
	if (f.login.value == '') {
		error+="El campo nombre de usuario no puede ser vacio. \n";
	}
	if (f.password.value == '') {
		error+="El campo password no puede ser vacio. \n";
	}
	if (f.password2.value == '') {
		error+="El campo reingresar password no puede ser vacio. \n";
	}
	if (f.email.value == '') {
		error+="El campo email no puede ser vacio. \n";
	}
	if (f.password.value != f.password2.value) {
		error+="Los password no coinciden. \n";
	}
	if (!validaremail(f.email.value)) {
		error+="El campo email no es valido. \n";		
	}
	if (error==""){
		f.submit();
	} else {
		alert (error);
	}

}

function confirmar_borrar (mensaje) {
	if (confirm(mensaje)) {
		form.submit();
	} 
}

function validdate(Cadena){
	var Fecha= new String(Cadena)	// Crea un string
	var RealFecha= new Date()	// Para sacar la fecha de hoy
	// Cadena Anio
	var Ano= new String(Fecha.substring(Fecha.lastIndexOf("-")+1,Fecha.length))
	// Cadena Mes
	var Mes= new String(Fecha.substring(Fecha.indexOf("-")+1,Fecha.lastIndexOf("-")))
	// Cadena Dia
	var Dia= new String(Fecha.substring(0,Fecha.indexOf("-")))

	// Valido el anio
	if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
        	alert('Year is not valid')
		return false
	}
	// Valido el Mes
	if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
		alert('Month is not valid')
		return false
	}
	// Valido el Dia
	if (isNaN(Dia) || parseInt(Dia, 10)<1 || parseInt(Dia, 10)>31){
		alert('Day is not valid')
		return false
	}
	if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
		if (Mes==2 && Dia > 28 || Dia>30) {
			alert('Day is not valid')
			return false
		}
	}
	
  //para que envie los datos, quitar las  2 lineas siguientes
  //alert("Fecha correcta.")
  //return false	
}

function valid()
{
	var msg="";
	var ok=1;
	var creditnumber = document.form.number.value;
	if (document.form.firstname.value=="")
	{
		msg += "* Please complete your  first name \n";
		ok = 0;
	}
	if(document.form.lastname.value=="")
	{
		msg += "* Please complete the last name \n";
		ok = 0;
	}
	if (document.form.address.value=="")
	{
		msg += "* Please complete the address \n";
		ok = 0;
	}
	if (document.form.city.value=="")
	{
		msg += "* Please complete the city \n";
		ok = 0;
	}
	if (document.form.state.value=="")
	{
		msg += "* Please select the state \n";
		ok = 0;
	}
	if (document.form.zip.value=="")
	{
		msg += "* Please complete the zipcode \n";
		ok = 0;
	}
	if (document.form.country.value=="")
	{
		msg += "* Please complete the country \n";
		ok = 0;
	}
	if (document.form.agree.checked==false)
	{
		msg += "* Please check box for terms of agreement \n";
		ok = 0;
	}						
	if (document.form.phone1.value=="")
	{
		msg += "* Please complete the phone \n";
		ok = 0;
	}	
	if (document.form.email.value=="")
	{
		msg += "* Please complete the email \n";
		ok = 0;
	}
	if (validaremail(document.form.email.value)==false)
	{
		msg += "* The email is not valid \n";
		ok = 0;		
	}
	if (document.form.password.value=="")
	{
		msg += "* Please complete the password \n";
		ok = 0;
	}
	if (document.form.password2.value=="")
	{
		msg += "* Please complete the confirm password \n";
		ok = 0;
	}
	if (document.form.password.value != document.form.password2.value)
	{
		msg += "* The administrator passwords do not match \n";
		ok = 0;		
	}
	if (document.form.password.value.length <= 4)
	{
		msg += "* The Administrator password must be more than 4 characters \n";
		ok = 0;			
	}
	if (document.form.password_afiliado.value=="")
	{
		msg += "* Please complete the employee password \n";
		ok = 0;
	}
	if (document.form.password_afiliado2.value=="")
	{
		msg += "* Please complete the confirm employee password \n";
		ok = 0;
	}
	if (document.form.password_afiliado.value != document.form.password_afiliado2.value)
	{
		msg += "* The employee passwords do not match \n";
		ok = 0;		
	}
	if (document.form.password_afiliado.value.length <= 4)
	{
		msg += "* The employee password must be more than 4 characters \n";
		ok = 0;			
	}	
	if (document.form.number.value == "")
	{
		msg += "* Please complete the credit card number \n";
		ok = 0;		
	}	
	if (creditnumber.length > 17 || creditnumber.length < 12 ) 
	{
		msg += "* The credit card length not is valid \n";
		ok = 0;		
	}

	if (ok)
	{
		document.form.submit();
	}
	else
	{
		alert(msg);
	}
}