
function enviarForm(){
	formulario = document.getElementById("formreg");
	if (isNotEmpty(formulario) ){
		formulario.target="grabarFrame";
		formulario.submit();	
	}
}

function contactoOk(){
	document.getElementById('ContactoDivForm').innerHTML='';
	launchErrorPopup(3);
	document.getElementById('divBotonEnviarContactos').innerHTML='';
}

function envioFormulario(nombreform){
	formulario = document.getElementById(nombreform);
	formulario.submit();	

}


function OKRecuperaPassword(){
	strtextoError = "Un email ha sido enviado a tu casilla de email. Visita el link dentro para cambiar tu contrase&ntilde;a";
	document.getElementById("textorecordar").innerHTML = strtextoError;
	document.getElementById("formulariorecordardiv").style.visibility="hidden";
}

function enviarFormForget(){
	formulario = document.getElementById("forgetForm");
	username =  document.getElementById("user").value;
	if (username == "" || username == null || username.charAt(0) == ' '){
		launchErrorPopup(1);
	}else{
		formulario.target="grabarFrame";
		formulario.submit();	
	}

}


function Videopopup(url) {
	url = "http://www.heineken.com.ar/wp-content/themes/default/players/"+url;
	window.open(url, 'videopopup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=430,height=400');
}

//chequea mail
function isValidEmail(strEmail){
 // validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
 validRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/
    if (strEmail.search(validRegExp) == -1) 
   {
      //alert('Direccion de e-mail no valida');
      return false;
    } 
    return true; 
}


function Anio(){

	strfield4=document.getElementById("dia").options[document.getElementById("dia").selectedIndex].text;
	strfield5=document.getElementById("mes").options[document.getElementById("mes").selectedIndex].text;
	uvyear = parseInt(document.getElementById("anio").options[document.getElementById("anio").selectedIndex].text);



    if (strfield4 == "DIA")
    {
	 document.getElementById("errorFecha").style.visibility="visible";
    alert("Falta seleccionar el dia")
    NoHayError = false;
    }

  //Mes
	if (strfield5 == "MES")
    {
	 document.getElementById("errorFecha").style.visibility="visible";
     alert("Falta seleccionar el mes")
    NoHayError = false;
    }
  //Aņo
	var yearcomparison;
	yearcomparison = 1900;

	if (uvyear > 1990)
    {
	
	 document.getElementById("errorFecha").style.visibility="visible";
    alert("Falta seleccionar el a&ntilde;o")
    NoHayError = false;
    }


}



function isNotEmpty(formulario) {


	strfield1= formulario.usuario.value;
	strnombre = formulario.nombre.value;
	strapellido = formulario.apellido.value;
	strtel = formulario.tel.value;
	strcelular= formulario.celular.value;
	strmail = formulario.email.value;
	strdireccion = formulario.direccion.value;
	strnro = formulario.nro.value;
	strcp = formulario.cp.value;
	strlocalidad = formulario.localidad.value;
	strdni = formulario.dni.value;
	strPass = formulario.Pass.value;
	strconfirmPass= formulario.confirmPass.value;


	strfield4=document.getElementById("dia").options[document.getElementById("dia").selectedIndex].text;
	strfield5=document.getElementById("mes").options[document.getElementById("mes").selectedIndex].text;
	uvyear = parseInt(document.getElementById("anio").options[document.getElementById("anio").selectedIndex].text);

	NoHayError = true;

	document.getElementById("errorUsuario").style.visibility="hidden";
	document.getElementById("errorNombre").style.visibility="hidden";
	document.getElementById("errorApellido").style.visibility="hidden";
	document.getElementById("errorTel").style.visibility="hidden";
	document.getElementById("errorCel").style.visibility="hidden";
	document.getElementById("errorDireccion").style.visibility="hidden";
	document.getElementById("errorNro").style.visibility="hidden";
	document.getElementById("errorCP").style.visibility="hidden";
	document.getElementById("errorLocalidad").style.visibility="hidden";
	document.getElementById("errorDNI").style.visibility="hidden";
	document.getElementById("errorPassword").style.visibility="hidden";
	document.getElementById("errorConfirmarPass").style.visibility="hidden";
	document.getElementById("errorMail").style.visibility="hidden";
	document.getElementById("errorFecha").style.visibility="hidden";
	document.getElementById("mensajeRegistracion").style.visibility="hidden";


/******Datos*******/
    if (strfield1 == "" || strfield1 == null || !isNaN(strfield1) || strfield1.charAt(0) == ' ' || strtel.length < 5)
    {
	// alert("Falta el usuario");
	 document.getElementById("errorUsuario").style.visibility="visible";
	 NoHayError = false;
    }


    if (strnombre == "" || strnombre == null || !isNaN(strnombre) || strnombre.charAt(0) == ' ')
    {
	 document.getElementById("errorNombre").style.visibility="visible";
//	 alert("Falta el Nombre")
	 NoHayError = false;
    }

    if (strapellido == "" || strapellido == null || !isNaN(strapellido) || strapellido.charAt(0) == ' ')
    {
	 document.getElementById("errorApellido").style.visibility="visible";
	// alert("Falta el Apellido")
	 NoHayError = false;
    }



    if (strtel == "" || strtel == null || strtel.charAt(0) == ' ' || strtel.length < 8)
    {
	 document.getElementById("errorTel").style.visibility="visible";
	//alert("Falta el Telefono")
     NoHayError = false;
    }


    if (strcelular == "" || strcelular == null || strcelular.charAt(0) == ' ' || strtel.length < 8)
    {
	 document.getElementById("errorCel").style.visibility="visible";
	 //alert("Falta el Celular")
     NoHayError = false;
    }


    if (strdireccion == "" || strdireccion == null || !isNaN(strdireccion) || strdireccion.charAt(0) == ' ')
    {
		 document.getElementById("errorDireccion").style.visibility="visible";

	// alert("Falta el Direccion")
     NoHayError = false;
    }


    if (strnro == "" || strnro == null || strnro.charAt(0) == ' ')
    {
	 document.getElementById("errorNro").style.visibility="visible";
	 //alert("Falta el numero")
	 NoHayError = false;
    }


    if (strcp == "" || strcp == null || strcp.charAt(0) == ' ')
    {
	 document.getElementById("errorCP").style.visibility="visible";
	 //alert("Falta el Codigo Postal")
     NoHayError = false;
    }

    if (strlocalidad == "" || strlocalidad == null || !isNaN(strlocalidad) || strlocalidad.charAt(0) == ' ')
    {
	 document.getElementById("errorLocalidad").style.visibility="visible";
	// alert("Falta la localidad")
     NoHayError = false;
    }

  if (strdni == "" || strdni == null ||  strdni.charAt(0) == ' ' || strdni.length < 8)
    {
		document.getElementById("errorDNI").style.visibility="visible";
	 //alert("Falta el DNI")
     NoHayError = false;
    }


    if (strPass == "" || strPass == null || strPass.charAt(0) == ' ' || strPass.length < 4)
    {
		 document.getElementById("errorPassword").style.visibility="visible";
	 //alert("Falta el password")
     NoHayError = false;
    }

    if (strconfirmPass == "" || strconfirmPass == null || strconfirmPass.charAt(0) == ' ' || strconfirmPass.length < 4)
    {
	 document.getElementById("errorConfirmarPass").style.visibility="visible";
	// alert("Falta confirmar password")
     NoHayError = false;
    }

    if (strPass != strconfirmPass)
    {
	 alert("Password con confirmar password no coinciden")
     NoHayError = false;
    }



/******Email********/

	if (!isValidEmail(strmail)){
    	 document.getElementById("errorMail").style.visibility="visible";
		NoHayError = false;
	}




/****Fecha de nacimiento******/
  //Dia

    if (strfield4 == "DIA")
    {
	 document.getElementById("errorFecha").style.visibility="visible";
  //  alert("Falta seleccionar el dia")
    NoHayError = false;
    }

  //Mes
	if (strfield5 == "MES")
    {
	 document.getElementById("errorFecha").style.visibility="visible";
  //   alert("Falta seleccionar el mes")
    NoHayError = false;
    }
  //Aņo
	var yearcomparison;
	yearcomparison = 1900;

	if (uvyear > 1990)
    {
	
	 document.getElementById("errorFecha").style.visibility="visible";
//    alert("Falta seleccionar el a&ntilde;o")
    NoHayError = false;
    }

//Cantidad de dias
	if((strfield5 == 2) && (strfield4 > 28)){
	 document.getElementById("errorFecha").style.visibility="visible";
	//alert("No existe ese dia en febrero");
	NoHayError = false;
	}

	if ((strfield5 == 4) && (strfield4==31)){
	 document.getElementById("errorFecha").style.visibility="visible";
	//	alert("No existe ese dia en abril");
		NoHayError = false;
	}

	if ((strfield5 == 6) && (strfield4==31)){
	 document.getElementById("errorFecha").style.visibility="visible";

//		alert("No existe ese dia en Junio");
		NoHayError = false;
	}
	
	if ((strfield5 == 9) && (strfield4 ==31 )){
	 document.getElementById("errorFecha").style.visibility="visible";

//		alert("No Existe ese dia en Septiembre");
		NoHayError = false;
	}
	
	if ((strfield5 == 11) && (strfield4 ==31 )){
	 document.getElementById("errorFecha").style.visibility="visible";

//		alert("No Existe ese dia en Septiembre");
		NoHayError = false;
	}

	if (NoHayError)
	{
		 return true;
	}else{
		 document.getElementById("mensajeRegistracion").style.visibility="visible";
		return false;
	}
   
}

function checkIfEmpty(obj,restore){
	if (obj.value == "" || obj.value == null || obj.value.charAt(0) == ' '){
		obj.value = restore;
	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function cargarCookieBackground(){
	if (readCookie('backgroundHNK'))
	{
		document.body.style.backgroundImage =readCookie('backgroundHNK');
		if (readCookie('backgroundPrefix') == "00NG"){
			changeColor("","black","FFFFFF");
		}else{
			changeColor("","white","");
		}
	}else{
		//changeBack();
		document.body.style.backgroundImage ='../../uploads/backgrounds/00NG-FINAL-CON-BORDE.jpg'
	}
}


function enviarContactoForm(){
	formulario = document.getElementById("formContacto");
	if ( CheckContactos(formulario) ){
		formulario.target="grabarFrame";
		formulario.submit();	
	}
}

function CheckContactos(formulario){
	nombre = formulario.nombre.value;
	apellido = formulario.apellido.value;
	mensaje = formulario.mensaje.value;
	strmail = formulario.email.value;
	
	NoHayError = true;

	document.getElementById("errorNombre").style.visibility="hidden";
	document.getElementById("errorApellido").style.visibility="hidden";
	document.getElementById("errorMensaje").style.visibility="hidden";
	document.getElementById("errorMail").style.visibility="hidden";
	document.getElementById("mensajeContacto").style.visibility="hidden";

	if (nombre == "" || nombre == null ||  nombre.charAt(0) == ' '){
		NoHayError = false;
	    document.getElementById("errorNombre").style.visibility="visible";
	}

	if (apellido == "" || apellido == null || apellido.charAt(0) == ' '){
		NoHayError = false;
	    document.getElementById("errorApellido").style.visibility="visible";
	}

	if (mensaje == "" || mensaje == null || mensaje.charAt(0) == ' '){
		NoHayError = false;
	    document.getElementById("errorMensaje").style.visibility="visible";
	}
	
	if (!isValidEmail(strmail)){
    	 document.getElementById("errorMail").style.visibility="visible";
		NoHayError = false;
	}


	if (NoHayError){
		 return true;
	}else{
		 document.getElementById("mensajeContacto").style.visibility="visible";
		return false;
	}
   
}

function launchErrorPopup(nmensaje){
	var msgError = new Array;
	if (nmensaje > 0 && nmensaje < 3){
		document.getElementById("popupdivexterno").style.top="20px";
	}
	msgError[0]="La combinaci&oacute;n de correo electr&oacute;nico/contrase&ntilde;a es incorrecta.<br><br>Comprob&aacute; los datos ingresados y que el bloqueo de may&uacute;sculas no est&eacute; activado e intentalo nuevamente.";
	msgError[1]="Comprob&aacute; que el nombre del usuario este bien escrito";
	msgError[2] = "El usuario ingresado es inexistente. Intenta nuevamente verificando tu nombre de usuario o registrate haciendo clic <a href='index.php?page_id=53'>aqu&iacute;</a> para poder acceder a nuestro site.";
	msgError[3] = "Muchas gracias por contactarnos. En breve nos comunicaremos para darle una respuesta a tu consulta.";
	msgError[4] = "Debes ser usuario registrado o estar logeado para jugar.";

	document.getElementById("popupdivexterno").style.visibility="visible";
	document.getElementById("popuptexto").innerHTML = msgError[nmensaje];
}

function destroyErrorPopUp(){
	document.getElementById("popupdivexterno").style.visibility="hidden";

}

function RedirectPopUp(){
	registerOk();
}

function isNumberKey(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode

	if (charCode == 8){
		 return true;
	}

	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return false;

 return true;
}




function isCharacter(evt)
{
 var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode == 8){
		 return true;
	}

	 if (charCode > 31 && (charCode < 48 || charCode > 57))
		return true;

	return false;
}



function textLimit(field, maxlen) {
	if (field.value.length > maxlen) {
		field.value = field.value.substring(0, maxlen);
		//alert('your input has been truncated!');
	}
}




function imagePopUp(url,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

	window.open(url, 'imgpopup', 'toolbar=0,status=no,scrollbars=0,location=0,statusbar=0,titlebar=no,location=no,menubar=0,resizable=0,width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition);
}

function VolverHome(){

	window.location.href="index.php";
}