
function openwindow(url)
{
	window.open(url,'mywindow','menubar=0,resizable=1,width=750,height=595');//height=515
}

function Print(strVar) {
		document.write(strVar);
	}

/*Funciones para validar Formulario
/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

msg = "";

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
			return false;
		}
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			return false;
		}
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			return false;
		}
		if (str.indexOf(at,(lat+1))!=-1){
	 	return false;
		}
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			return false;
		}

		if (str.indexOf(dot,(lat+2))==-1){
			return false;
		}
		if (str.indexOf(" ")!=-1){
			return false;
		}
 		 return true					
	}

/* Funciones para validar telefono*/
function ValidateNo(NumStr, String)
{
    for(var Idx=0; Idx<NumStr.length; Idx++)
    {
        var Char = NumStr.charAt(Idx);
        var Match = false;

        for(var Idx1=0; Idx1<String.length; Idx1++)
        {
            if(Char == String.charAt (Idx1))
                Match = true;
        }

        if (!Match)
            return false;
    }
    return true;
}

function ValidateForm(){
	
	msg = "";
	var pattern = /[\d!/#\(\)\\%&\$"=¡¿,;\.:_\+\{\}\[\]\^\?¨~`\|°¬<>@\*´\'\-]/;
	var patternCity = /[\d!/#\(\)\\%&\$"=¡¿,;:_\+\{\}\[\]\^\?¨~`\|°¬<>@\*´\-]/;
	
	//valida Nombre en Photo
	if(document.data_photo.FirstName.value == "" || document.data_photo.FirstName.value == null)
		msg += "-Por favor introduzca su Nombre\n";
	if(document.data_photo.FirstName.value.search(pattern) != (-1))
		msg += "-Por favor, recuerde que su nombre solo debe llevar letras, sin números o caracteres especiales\n"

	//valida Apellido en Photo
	if(document.data_photo.LastName.value == "" || document.data_photo.LastName.value ==null)
		msg += "-Por favor introduzca su Apellido\n";
	if(document.data_photo.LastName.value.search(pattern) != (-1))
		msg += "-Por favor, recuerde que su Apellido solo debe llevar letras, sin números o caracteres especiales\n"

	//valida Ciudad en Photo
	if(document.data_photo.City.value == "" || document.data_photo.City.value ==null)
		msg += "-Por favor introduzca su Ciudad\n";
	if(document.data_photo.City.value.search(patternCity) != (-1))
		msg += "-Por favor, recuerde que la Cuidad solo debe llevar letras, sin números o caracteres especiales\n"
			
	//valida Codigo Postal	
	if(document.data_photo.ZC.value == ""  ||document.data_photo.ZC.value ==null)
		msg += "-Por favor introduzca su Codigo Postal\n";
	if(!ValidateNo(document.data_photo.ZC.value,"1234567890 "))
		msg += "-Por favor sólo numeros en (Codigo Postal:)\n";
		
   	//valida Email
	var emailID = document.data_photo.Email;
	if ((emailID.value==null)||(emailID.value==""))
		msg += "-Insertar Email por favor\n";
	else if(echeck(emailID.value)==false){
		emailID.value=""
		msg += "-El correo electrónico  no es válido\n";
	}
	
	if(document.data_photo.Acept.checked==false)
		msg += "-Acepte los terminos y condiciones\n";

	//En caso de Introducir Archivo
	//valida Titulo	
	if(document.data_photo.Title.value == ""||document.data_photo.Title.value ==null)
		msg += "-introduzca el Titulo de la Nota \n";
	
	//Archivos permitidos
	if(document.data_photo.File.value == ""||document.data_photo.File.value ==null)
	msg += "-introduzca un archivo al reportaje \n";
	ERFiles=/.jpg|.jpeg|.gif/i;
	//En caso de Adjuntar Archivo
	if(document.data_photo.File.value !="" ){
		if (!ERFiles.test(document.data_photo.File.value))
			msg += "-Tipo de archivo no valido \n";
	}
	//valida Descripcion Nota	
	if(document.data_photo.ComentN.value == ""||document.data_photo.ComentN.value ==null)
		msg += "-introduzca un breve descripción de la Nota \n";	

	//valida el Día de la nota
	if(document.data_photo.Day.selectedIndex == 0||document.data_photo.Month.selectedIndex == 0||document.data_photo.Year.selectedIndex == 0)
		msg += "-introduzca la fecha de la nota \n";
		
	//Validación Final
	if(msg != ""){
		alert("Campos incorrectos, por las siguintes razones:\n"+msg);
		return false;
	}
	else {
		return true;
	}
 }


function ValidateFormRegData(){
	
	msg = "";
	
	//En caso de Introducir Archivo
	//valida Titulo	
	if(document.data_photo.Title.value == ""||document.data_photo.Title.value ==null)
		msg += "-introduzca el Titulo de la Nota \n";
	
	//Archivos permitidos
	if(document.data_photo.File.value == ""||document.data_photo.File.value ==null)
	msg += "-introduzca un archivo al reportaje \n";
	ERFiles=/.jpg|.jpeg|.gif/i;

	//En caso de Adjuntar Archivo
	if(document.data_photo.File.value !="" ){
		if (!ERFiles.test(document.data_photo.File.value))
			msg += "-Tipo de archivo no valido \n";
	}

	//valida Comentario Nota	
	if(document.data_photo.ComentN.value == ""||document.data_photo.ComentN.value ==null)
		msg += "-introduzca un breve descripción de la Nota \n";	
		//valida el Día de la nota
	if(document.data_photo.Day.selectedIndex == 0||document.data_photo.Month.selectedIndex == 0||document.data_photo.Year.selectedIndex == 0)
		msg += "-introduzca la fecha de la nota \n";
		
	//Validación Final
	if(msg != ""){
		alert("Campos incorrectos, por las siguintes razones:\n"+msg);
		//ShowLoadingBox('loadingFileBox');
		return false;
	}
	else {
		ShowLoadingBox('loadingFileBox');
		return true;
	}
 }


function ValidateFormReg(){
	
	
	msg = "";
	var pattern = /[\d!/#\(\)\\%&\$"=¡¿,;\.:_\+\{\}\[\]\^\?¨~`\|°¬<>@\*´\'\-]/;
	var patternCity = /[\d!/#\(\)\\%&\$"=¡¿,;:_\+\{\}\[\]\^\?¨~`\|°¬<>@\*´\-]/;
	
	//valida Nombre
	if(document.data.name.value == "" || document.data.name.value ==null)
		msg += "-Por favor introduzca su Nombre\n";
	if(document.data.name.value.search(pattern) != (-1))
		msg += "-Por favor, recuerde que su nombre solo debe llevar letras, sin números o caracteres especiales\n"

	//valida Apellido
	if(document.data.first_name.value == "" || document.data.first_name.value ==null)
		msg += "-Por favor introduzca su Apellido\n";
	if(document.data.first_name.value.search(pattern) != (-1))
		msg += "-Por favor, recuerde que su Apellido solo debe llevar letras, sin números o caracteres especiales\n"

	//valida Ciudad
	if(document.data.user_locality.value.search(patternCity) != (-1))
		msg += "-Por favor, recuerde que la Cuidad solo debe llevar letras, sin números o caracteres especiales\n"

	//valida Email
	var emailID=document.data.email;
	if ((emailID.value==null)||(emailID.value==""))
		msg += "-Insertar Email por favor\n";
	else if(echeck(emailID.value)==false){
		emailID.value=""
		msg += "-El correo electrónico  no es válido\n";
	}

	//valida Contraseña
	if(document.data.password.value == "" || document.data.password.value ==null)
		msg += "-Por favor introduzca su Contraseña\n";
	if(document.data.confirm_password.value == "" || document.data.confirm_password.value ==null)
		msg += "-Por favor confirme su Contraseña\n";
	
	//valida Codigo Postal	
	if(!ValidateNo(document.data.user_postal_code.value,"1234567890 "))
		msg += "-Por favor sólo numeros en (Codigo Postal:)\n";
		
	if(document.data.disclaimer.checked==false)
		msg += "-Acepte los terminos y condiciones\n";
		
	//Validación Final
	if(msg != ""){
		alert("Campos incorrectos, por las siguintes razones:\n"+msg);
		//ShowLoadingBox('loadingFileBox');
		return false;
	}
	else {
		return true;
	}
 }

//Deshabilitar o ahabilitar los Estados dependiendo de el País

function deshabilitar(){ 
	if (document.data_video.Country.selectedIndex!=0){
		document.data_video.Estate.disabled = true;
		document.data_video.Estate.value = "";
	}
	else{
		document.data_video.Estate.disabled = false;
	}
	
	if (document.data_photo.Country.selectedIndex!=0){
		document.data_photo.Estate.disabled = true;
		document.data_photo.Estate.value = "";
	}
	else{
		document.data_photo.Estate.disabled = false;
	}	
}

function deshabilitarmin(){ 
	if (document.data.country.selectedIndex!=0){
		document.data.state.disabled =true;
		/*document.data.Estate2.disabled =false;*/
	}
	else{
		document.data.state.disabled=false;
		/*document.data.Estate2.disabled=true;*/
	}
	
}


//Permite escribir Sólo 
function validaNum(evento) {
	var Tecla;
	var bolReg=false;
	if (strExplorador.indexOf("Explorer",0) != -1) {
		Tecla = evento.keyCode;
	} else {
		Tecla=evento.which;
	}
	if ((Tecla > 47) && (Tecla < 58)) {
		bolReg=true;
	}
	if (strExplorador.indexOf("Explorer",0) != -1) {
		if (!bolReg) {
		   evento.keyCode = "";
		}
	}
	return bolReg;
}
/*Esta variable indica que explorador es*/
var strExplorador;
strExplorador = navigator.appName;



//Funcion que reduce el tamaño de una cadena
function reducirCadena(cadena,largo,remplaso)
	{
	var remplaso = (remplaso == null) ? "..." : remplaso;	
	var temp=cadena;
	if(temp.length > largo ){
		temp=temp.substring(0,largo-2);
		temp +=remplaso;
		
		}
	return temp;
	}
	

//Funcion Que espera a que se cargue el documento, necesario para utilizar el DOM
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
     //if (oldonload) {
        oldonload();
     //}
      func();
    }
  }
}

//Header para Tv y Novelas

function head(galeria)
{
	var href = (galeria == null) ? href='href="mec.html"' : href='href="'+galeria+'"';
	
	Print('<div id="cabezal_arriba"><img src="img/cabezal_tv_novelas.jpg" width="890" height="103"/></div>');
	
	Print('<div id="menu_principal"><img src="img/m1.jpg" width="44" height="30" /><a href="index.html"><img src="img/m2.jpg" width="125" height="30" border="0" /></a><a href="galeria.php"><img src="img/m4.jpg" width="124" height="30" border="0" /></a><a href="ganadores01.html"><img src="img/m5.jpg" width="125" height="30" border="0" /></a><a href="contactanos.html"><img src="img/m6.jpg" width="128" height="30" border="0" /></a>')
	
		Print(' <div id="logo_promocion"><a '+href+' ><img src="img/logo_promocion.gif" width="180" height="131" border="0px" /></a></div>')
	
	Print('</div>');
	
}



