//valida un email
function validarEmail(valor) { 
	valor = trim(valor);

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(valor)){
		return true
	} 
	else {
    	return false;
	}
}

//saco blancos al principio y al final
function trim(cadena) {
   cadena = cadena.replace(/^\s+/, '');
   cadena = cadena.replace(/\s+$/, '');
	return cadena;
}

//---------------------------------------------------------------------//
/*function incrementarClicks(id_c){
	var iframe = document.createElement("iframe");
	iframe.src = 'incrementarClicks.php?id_camp=' + id_c;
	iframe.style.zIndex = 10;
	iframe.height = '0px';
	iframe.id = "iframetemp";
	document.getElementsByTagName("BODY").item(0).appendChild(iframe);
	iframe.onLoad = closeIfr();
	
	return;
}*/
//---------------------------------------------------------------------//
function marqueeStop(){
	document.getElementById("marq").stop();
	document.getElementById("marqueeplay").style.display = "block";
	document.getElementById("marqueestop").style.display = "none";
}
function marqueePlay(){
	document.getElementById("marq").start();
	document.getElementById("marqueeplay").style.display = "none";
	document.getElementById("marqueestop").style.display = "block";
}
//---------------------------------------------------------------------//
function closeIfr(){
	setTimeout("document.getElementsByTagName('BODY').item(0).removeChild(document.getElementById('iframetemp'));",1000);
}
//---------------------------------------------------------------------//
function validarContacto(){
	var oCad = "";
	var bool = true;	
	var oMsjCto = document.getElementById("msjContacto");
	var oNombre = document.getElementById("nombre");
	var oEmail = document.getElementById("email");
	var oComentario = document.getElementById("comentario");
	
	
	if(trim(oNombre.value) == ""){
		oCad += "Por favor complete su nombre<br>";
		bool = false;
	}
	
	if(!validarEmail(oEmail.value) || trim(oEmail.value) == ""){
		oCad += "El e-mail está vac&iacute;o o su formato es incorrecto<br>";
		bool = false;
	}
	
	if(trim(oComentario.value) == ""){
		oCad += "Por favor ingrese un comentario<br>";
		bool = false;
	}
	
	if(bool){
		return true;
	}
	else{
		oMsjCto.style.display = "block";
		oMsjCto.innerHTML = oCad;
		return false;
	}
}

//---------------------------------------------------------------------//
function validarLogin(){
	var oUsr = document.getElementById("usr");
	var oPsw = document.getElementById("psw");
	var oMsjLogin = document.getElementById("msjLogin");
	
	if(trim(oUsr.value) == "" || trim(oPsw.value) == ""){
		oMsjLogin.style.display = "block";
		oMsjLogin.innerHTML = "Por favor, ingrese su usuario y password.";
		
		return false;
	}else	return true;
}



//---------------------------------------------------------------------//

function validarConcurso(){
	var oCad = "";
	var bool = true;	
	var oMsjCto = document.getElementById("msjContacto");
	var oNombre = document.getElementById("nombre");
	var oEmail = document.getElementById("email");
	var oDestino = document.getElementById("destino");
	
	
	if(trim(oNombre.value) == ""){
		oCad += "Por favor complete su nombre<br>";
		bool = false;
	}
	
	if(!validarEmail(oEmail.value) || trim(oEmail.value) == ""){
		oCad += "El e-mail está vac&iacute;o o su formato es incorrecto<br>";
		bool = false;
	}
	
	if(trim(oDestino.value) == ""){
		oCad += "Por favor ingrese un destino<br>";
		bool = false;
	}
	
	if(bool){
		return true;
	}
	else{
		oMsjCto.style.display = "block";
		oMsjCto.innerHTML = oCad;
		return false;
	}
}