﻿
var sTextoError="Campo Obligatorio";

//Función para abrir un pop-up
function FNpopup(p_url,p_id,p_ancho,p_alto,p_carac){
   
    car="width="+p_ancho+",height="+p_alto+",left="+((screen.width/2)-(parseInt(p_ancho)/2))+",top="+((screen.height/2)-(parseInt(p_alto)/2))+","+p_carac
	window.open(p_url,p_id,car)
}


function ValidarInput ( idControl, idHiddenError )
{
    if (document.getElementById( idControl ).value.length == 0 )
    {
        document.getElementById( idControl ).value=sTextoError;
        document.getElementById(idControl).className="error"; 
        document.getElementById(idHiddenError).value ="1";
        return false;      
    }
    else 
     {
        document.getElementById(idControl).className="";
        document.getElementById(idHiddenError).value ="0";
        return true;
        
     }        
}

function ValidarInputCodigoPostal ( idControl, idHiddenError )
{
    if ((document.getElementById( idControl ).value.length == 0 ) || (document.getElementById( idControl ).value.length < 5 ))
    {
        document.getElementById( idControl ).value=sTextoError;
        document.getElementById(idControl).className="error"; 
        document.getElementById(idHiddenError).value ="1";
        return false;      
    }
    else 
     {
        document.getElementById(idControl).className="";
        document.getElementById(idHiddenError).value ="0";
        return true;
        
     }        
}


function LimpiarInput ( idControl, idHiddenError )
{
  if (document.getElementById(idHiddenError).value == "1")
         {
            document.getElementById( idControl ).value="";
            document.getElementById(idControl).className="";  
            document.getElementById(idHiddenError).value="0";              
         }        
}

function ValidarInputMail ( idControl, idHiddenError )
{
//debugger;
    if (document.getElementById( idControl ).value.length == 0 )
    {
        document.getElementById( idControl ).value=sTextoError;
        document.getElementById(idControl).className="error";  
        document.getElementById(idHiddenError).value ="1";
    }
    else if ( esMailValor(document.getElementById( idControl ).value) )
         {   
                document.getElementById(idControl).className=""; 
                document.getElementById(idHiddenError).value ="0";  
                return true;     
         }
         else
         {
                document.getElementById(idControl).className="error";  
                document.getElementById(idHiddenError).value ="1";
                return false;
         }   
    
}

function LimitarCaracteresSoloNumeros( obj, e ) 
{ 
    //Para IE
    if ( e.which == null || e.which == "undefined" )
        var ultimoCaracter = e.keyCode;
    //Para FireFox
    else
        var ultimoCaracter = e.which;
       
    if ( (ultimoCaracter >=48 && ultimoCaracter <=57) || (ultimoCaracter==0) || (ultimoCaracter==8))   
        return true;
    else
        return false;
          
}


function esMailValor( mail)
{

    var correcto = true ;
                      
    reMail = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
                  
    if ( mail !="" )
    {
        if (reMail.test( mail ))
        { 
            correcto= true ;
        }
        else
            correcto= false ;
    }
    else
   {
         correcto= false ;
    }    
   
   return correcto;  
}

function esNumero (Campo)
{
        var cCampo = document.getElementById( Campo );
        if (isNumeric(cCampo.value))
        {
            return true;
        }
        else
        {
            event.returnValue = null;
            return false;
        }
         
}

function habilitarContactoTelefono ()
{
//debugger;
//Vemos si el campo esta checkeado:
if (document.getElementById ("chkContacto").checked)
{
    //Lo habilitamos
    document.getElementById ("txtTelefono").disabled=false;
    document.getElementById ("cmbHorarios").disabled=false;
}
else
{
    //Desahilitamos
    document.getElementById ("txtTelefono").disabled=true;
    document.getElementById ("cmbHorarios").disabled=true;
}
}

function ValidarCheckPoliticaPrivacidad()
{
    //Validamos la politica de privacidad:
    if (!document.getElementById ("chkAcepto").checked)
    {
        //Cambiamos los mensajes:
        document.getElementById ("spnPoliticaTextoOK").style.display="none";
        document.getElementById ("spnPoliticaTextoKO").style.display="block";
        document.getElementById ("divPoliticaPrivacidad").className="aceptar-politica-on";
        
        return false;
    }
    else
    {
        //Cambiamos los mensajes:
        document.getElementById ("spnPoliticaTextoOK").style.display="block";
        document.getElementById ("spnPoliticaTextoKO").style.display="none";
        document.getElementById ("divPoliticaPrivacidad").className="aceptar-politica-off";
        return true;
    }
}


function Validar()
{
    var formularioCorrecto=true;

    //1.Validamos nombre:
    if (!ValidarInput ( "txtNombre", "hdnErrorNombre" )) formularioCorrecto = false;

    //2.Validamos nombre:
    if (!ValidarInput ( "txtApellidos", "hdnErrorApellidos" )) formularioCorrecto = false;

    //3.Validamos mail:
    if (!ValidarInputMail ( "txtMail", "hdnErrorMail" )) formularioCorrecto = false;

    //4.Validamos codigo postal:
    if (!ValidarInputCodigoPostal ( "txtCodigoPostal", "hdnErrorCodigoPostal" )) formularioCorrecto = false;

    //5.Validamos nombre:
    if (!ValidarInput ( "txtAsunto", "hdnErrorAsunto" )) formularioCorrecto = false;
    
    //6.Validamos check contacto por telefono y familia:
    if (document.getElementById ("chkContacto").checked)
    {
        if (!ValidarInput("txtTelefono", "hdnErrorTelefono"))formularioCorrecto = false;
    }
    
    //7.Validamos check:
    if (!ValidarCheck())formularioCorrecto = false;
       

}

function LimpiarFormulario()
{
    document.getElementById("txtNombre").value="";
    document.getElementById("hdnErrorNombre").value="0";
    document.getElementById("txtApellidos").value="";
    document.getElementById("hdnErrorApellidos").value="0";
    document.getElementById("txtMail").value="";
    document.getElementById("hdnErrorMail").value="0";
    document.getElementById("txtCodigoPostal").value="";
    document.getElementById("hdnErrorCodigoPostal").value="0";
    document.getElementById("txtAsunto").value="";
    document.getElementById("hdnErrorAsunto").value="0";
    document.getElementById("chkContacto").checked = false;
    document.getElementById("txtTelefono").value="";
    document.getElementById("hdnErrorTelefono").value="0";
    document.getElementById("chkAcepto").checked=false;
    
    
    
    

}

function Ocultar()
{
LimpiarFormulario();
document.getElementById("divMensaje").style.display="none";
document.getElementById("frmContacto").style.display="block";

}


//FLASH:
// Control Clase de ejecución de archivos ShockWave Flash
// (c)2006 The Mad Pixel Factory --- http://www.madpixel.es

obj_swf=function(){
	this.salida_div=false
	this.trace=false
	this.codificarFlashVars=false
}
obj_swf.prototype.FNtrace=function(){
	this.trace=true
	return true
}
obj_swf.prototype.FNcodificarFlashVars=function(){
	this.codificarFlashVars=true
	return true
}
obj_swf.prototype.FNid_salida=function(p_id_salida){
	if(typeof(p_id_salida)!="undefined"){
		if(document.getElementById(p_id_salida)){
			this.salida_div=true
			this.obj_div=document.getElementById(p_id_salida)
		}
	}
}
obj_swf.prototype.FNborrar=function(){
	delete this
}
obj_swf.prototype.FNgfx_swf=function(){
	//Comprueba parametros básicos
	if(typeof(this.classid)=='undefined'){this.classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
	if(typeof(this.codebase)=='undefined'){this.codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'}
	if(typeof(this.quality)=='undefined'){this.quality='high'}
	if(typeof(this.type)=='undefined'){this.type='application/x-shockwave-flash'}
	if(typeof(this.pluginspage)=='undefined'){this.pluginspage='http://www.macromedia.com/go/getflashplayer'}
	if(typeof(this.swliveconnect)=='undefined'){this.swliveconnect="true"}
	if(typeof(this.allowscriptaccess)=='undefined'){this.allowscriptaccess="true"}
	if(typeof(this.id)=='undefined'){var nId=Math.round(Math.random()*100);this.id='swf'+nId}
	//--
	//Crea arrays de contenido
	this.a_object_propios=new Array()
	this.a_comunes=new Array()
	this.a_object_variables=new Array()
	this.a_embed_propios=new Array()
	this.a_embed_variables=new Array()
	//--
	
	//Revisa contenido adquirido
	for(parametros in this){
		var cNomParametro=parametros.toLowerCase()
		var cValorParametro=eval("this."+parametros)
		if(typeof(cValorParametro)=="string"){
			switch (cNomParametro){
				case "classid":
				case "codebase":
				case "onafterupdate":
				case "onbeforeupdate":
				case "onblur":
				case "oncellchange":
				case "onclick":
				case "ondblClick":
				case "ondrag":
				case "ondragend":
				case "ondragenter":
				case "ondragleave":
				case "ondragover":
				case "ondrop":
				case "onfinish":
				case "onfocus":
				case "onhelp":
				case "onmousedown":
				case "onmouseup":
				case "onmouseover":
				case "onmousemove":
				case "onmouseout":
				case "onkeypress":
				case "onkeydown":
				case "onkeyup":
				case "onload":
				case "onlosecapture":
				case "onpropertychange":
				case "onreadystatechange":
				case "onrowsdelete":
				case "onrowenter":
				case "onrowexit":
				case "onrowsinserted":
				case "onstart":
				case "onscroll":
				case "onbeforeeditfocus":
				case "onactivate":
				case "onbeforedeactivate":
				case "ondeactivate":
				case "type":
					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "width":
				case "height":
				case "align":
					this.a_comunes.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "type":
				case "pluginspage":
				case "allowscriptaccess":
				case "width":
				case "height":
				case "align":
				case "vspace": 
				
				case "play": 
				case "menu":
				case "loop":
				
				case "hspace":
				case "class":
				case "title":
				
				case "salign":
				case "scale":
				case "allowFullScreen":
				
				case "devicefont":
				case "accesskey":
				case "swliveconnect":
				case "tabindex":
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
				case "id":
//					this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_object_propios.push( 'name'+'="'+cValorParametro+'"'  )
					this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
					this.a_embed_propios.push('name'+'="'+cValorParametro+'"' )
					break;
				case "movie":
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_propios.push('src'+'="'+cValorParametro+'"' )
					break;
				case "flashvars":
					//Revision el contenido de FlashVars para evitar problemas de comillas y caracteres especiales
					if(cValorParametro.indexOf('"')!=-1 || cValorParametro.indexOf("'")!=-1 || this.codificarFlashVars){
						//cValorParametro=escape(cValorParametro)
					}
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					//--
					break;
				default :
					this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
					this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
					break;
	
			}
		}
	}
	//--
	
	this.a_object_propios=this.a_object_propios.join(" ")
	this.a_comunes=this.a_comunes.join(" ")
	this.a_embed_propios=this.a_embed_propios.join(" ")
	this.a_object_variables=this.a_object_variables.join("\n")
	this.a_embed_variables=this.a_embed_variables.join(" ")
	
	
	//Genera salida
	cad=''
	cad+=('<object '+this.a_object_propios+' '+this.a_comunes+' >'+'\n')
	cad+=(''+this.a_object_variables +'\n')
	cad+=('<embed '+this.a_embed_propios+' '+this.a_comunes+' '+this.a_embed_variables+'></embed>'+'\n')
	cad+=('</object>'+'\n')
	
	if(this.salida_div){
		this.obj_div.innerHTML=cad //Salida a etiqueta ID
	}else{
		document.write(cad) //Escritura directa sobre HTML
	}
	//--
	
	if(this.trace){alert(cad)}
	
}

//Funcion de modificación de alto del un archivo swf identificado con una ID
FNcambioAltoSWF=function(p_id,p_alto){
	document.getElementById(p_id).height=p_alto
//	document.getElementById(p_id).width=762
}
//--
    

