// JavaScript Document

function trim (str) {
	str = str.replace(/^\s+/, '');
	for (var i = str.length - 1; i >= 0; i--) {
		if (/\S/.test(str.charAt(i))) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return str;
}

function areEqual(txt1, txt2, msg){
	if(txt1 == txt2)
		return true;
	else{
		alert(msg);
		return false;
	}			
}

function isEmail(strg, msg){
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strg))){
		alert(msg);
		return false;
	}else
		return true;
}

function validateEmail(email, msg){
	if(!isEmail(email.value, msg)){
		email.select();
	}
}

function compare(email1, email2, msg){
	if(!areEqual(trim(email1.value), trim(email2.value), msg)){
		email1.select();
	}
}

function begin(){
	tag = window.opener.document.getElementById('machine');
	document.getElementById('maquina').value = trim(tag.textContent||tag.innerText);
}

function validateContact(form){
	if(form.nombre.value == ""){
		alert("You must fill in the first name!");
		form.nombre.select();
		return false;
	}
	if(form.apellido.value == ""){
		alert("You must fill in the last name!");
		form.apellido.select();
		return false;
	}
	if(trim(form.correo.value)== ""){
		alert("You must fill in the email field !!!");
		form.correo.select();
		return false;
	} else {
		res = isEmail(form.correo.value, 'Email is not valid.');
		if(res==false){
			form.correo.select();
			return res;	
		}
	}
	if(trim(form.correo2.value)== ""){
		alert("You must fill in the email field !!!");
		form.correo2.select();
		return false;
	} else {
		if(!areEqual(form.correo.value, form.correo2.value, 'The email entries don\'t match.')){
			form.correo2.select();
			return false;
		}
	}
	if(form.telefono.value== ""){
		alert("You must fill in the phone!");
		form.telefono.select();
		return false;
	}
	if(form.mensaje.value== ""){
		alert("You must fill in the message!");
		form.mensaje.select();
		return false;
	}	
	if(form.pais.value== ""){
		alert("You must fill in the country!");
		form.pais.select();
		return false;
	}	
	if(form.ciudad.value== ""){
		alert("You must fill in the city!");
		form.ciudad.select();
		return false;
	}	
	return true;
}








//###############################################



/**
* Funcion que valida la longitud de las contrase?as
*
*/
function validate_pass(txt_box)
{
passwd=txt_box.value;

if (passwd.length < 6)
 {
    alert("La contraseņa debe tener 8 o mas caracteres!");
    return false;
 }
else
 {
 return true;
 }
}


/**
*
*Funcion que confirma si se desea borrar un item
*/
//
/*function if_borrar(confirm_txt, location)
{
  if (confirm(confirm_txt))
  {
    window.location=location;
  }else{
  	
  }
}*/


