﻿

//Carga de componentes Flash para las páginas *** bug IE7
//*******************************************************
//*******************************************************
function loadFlComp(strDesc,strDiv, strVar, strLink)
{
    // strDesc: Parametros completos de carga de Flash: ruta, tamaño...
    // strDiv:  Capa donde cargara el flash
    // blVar:   Variable Flash que recibirá parametros 
    // strLink: Ruta de enlace que se le pasa a la variable
    // Carga un único FLASH, pero puede recibir múltiples variables separadas por '$'

     var strWriteDIV;
     
     var arrParamList = strDesc.split("$");
     var so = new SWFObject(arrParamList[0],arrParamList[1],arrParamList[2],arrParamList[3],arrParamList[4],arrParamList[5]);
     so.addParam("wmode", "opaque");
     
     if(strVar.length > 1) {

            
          if (strVar.indexOf('$') != "-1")  
          {
                var arrVarList = strVar.split("$");
                var arrLinkList = strLink.split("$");
                for(i=0;i < arrVarList.length;i++)
                {
                    so.addVariable(arrVarList[i], arrLinkList[i]);
                }
          }
          else 
          {
            so.addVariable(strVar, strLink);
          }  
     }   
     
     so.write(strDiv);  
     so = ""; 
}
//*******************************************************
//*******************************************************


//OnClick y envío de links
//*******************************************************
//*******************************************************

function goToURL(strLink)
{
    if(strLink.length > 1 && strLink != '#') 
    {
        window.location.href = strLink;
    }    
}

//*******************************************************
//*******************************************************

//Precarga de las imagenes, recibe la ruta de la imagen
//*****************************************************
//*****************************************************
function preCargaImg() 
{ 
  var d=document; 
  if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preCargaImg.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//Control de rollOvers en imágenes
function MM_swapImgRestore() { 
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//Busquedas de objetos
function MM_findObj(n, d) { 
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//Control de imagen de cambio
function MM_swapImage() { 
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function ValidarPersonaNIF(source, arguments)
{
	var txtNIF = document.getElementById(source.controltovalidate);
    
	CompruebaNIF(source,arguments);
	
	
}

function CompruebaNIF(source, arguments)
{
  var digitos = "0123456789";
  var chequeo = arguments.Value.toUpperCase(); // pasar a mayúsculas
  var correcto = true;
  
  if (!/^[A-Za-z0-9]{9}$/.test(chequeo)){  // Son 9 dígitos? 
		//alert("Longitud incorrecta, un NIF consta de 9 digitos");
		arguments.IsValid = false;
		document.getElementById(source.controltovalidate).select();
		document.getElementById(source.controltovalidate).focus();
		return;
  }
  
  var numNIF;  
  if(isNaN(chequeo.substr(0,1)))
  {
	if (chequeo.substr(0,1)=='X')
	{
		numNIF=chequeo.substr(1,7)
	}
	else 
	    if (chequeo.substr(0,1)=='Y')
	    {		    	
		    numNIF='1'+ chequeo.substr(1,7)
	    }
	    else
	        if (chequeo.substr(0,1)=='Z')
	        {
	            numNIF='2'+ chequeo.substr(1,7)
	        }   
	        else
	        {
		        arguments.IsValid = false;
		        document.getElementById(source.controltovalidate).select();
		        document.getElementById(source.controltovalidate).focus();
		        return;
	        }
  }
  else
  {
	numNIF=chequeo.substr(0,8)
  }

  var asc=numNIF % 23;
  var letraTeoria;
  var letraPractica=chequeo.substr(8,1);
  switch(asc)
  {
		case 0:letraTeoria="T";break;
		case 1:letraTeoria="R";break;
		case 2:letraTeoria="W";break;
		case 3:letraTeoria="A";break;
		case 4:letraTeoria="G";break;
		case 5:letraTeoria="M";break;
		case 6:letraTeoria="Y";break;
		case 7:letraTeoria="F";break;
		case 8:letraTeoria="P";break;
		case 9:letraTeoria="D";break;
		case 10:letraTeoria="X";break;
		case 11:letraTeoria="B";break;
		case 12:letraTeoria="N";break;
		case 13:letraTeoria="J";break;
		case 14:letraTeoria="Z";break;
		case 15:letraTeoria="S";break;
		case 16:letraTeoria="Q";break;
		case 17:letraTeoria="V";break;
		case 18:letraTeoria="H";break;
		case 19:letraTeoria="L";break;
		case 20:letraTeoria="C";break;
		case 21:letraTeoria="K";break;
		case 22:letraTeoria="E";break;
		case 23:letraTeoria="T";break;			
  }
  
  if (letraTeoria != letraPractica)
  {
    //alert("La letra del NIF no es correcta, deberia ser la letra "+letraTeoria+".");
		arguments.IsValid = false;
		document.getElementById(source.controltovalidate).select();
		document.getElementById(source.controltovalidate).focus();
		return;
  }  

}

/* ------------------------------------------------ */
function validaCantidad (source, arguments)
{

    var txtbox = document.getElementById(source.controltovalidate);
    var cantidad = parseInt(txtbox.value);
    
    if ((cantidad<0) || (cantidad>6000))
        arguments.IsValid = false;
    else
        arguments.IsValid = true;
}

/* ---------------------------------------------------- */



function ocultarDiv (capa) 
{
    if(document.getElementById(capa)!=null) document.getElementById(capa).style.display = "none";

}

function mostrarDiv (capa) 
{
    if(document.getElementById(capa)!=null) document.getElementById(capa).style.display = "block";    
}

//*****************************************************
//*****************************************************

	function EsFechaMayor(strFechaA, strFechaB){
  
  if ((strFechaA == "")||(strFechaB == "")){
    return true;
  }

  arrValuesFechaA = strFechaA.split("/");
  iDayA = arrValuesFechaA[0];
  iMonthA = arrValuesFechaA[1];
  iYearA = arrValuesFechaA[2];

  arrValuesFechaB = strFechaB.split("/");
  iDayB = arrValuesFechaB[0];
  iMonthB = arrValuesFechaB[1];
  iYearB = arrValuesFechaB[2];

  var fechaA = new Date(iYearA, iMonthA, iDayA);  
  var fechaB = new Date(iYearB, iMonthB, iDayB); 
	var msegA = fechaA.getTime();
	var msegB = fechaB.getTime();
	var Diferencia = msegA - msegB;
	//alert(Diferencia);
	if (Diferencia <= 0) {
		return false;
	}else{
	  return true;
	}
}


	/*******************************************************/
	function ComprobarConFechaHoy(sender, args)
		{
			var strFecha=args.Value;
			var ahora = new Date();
			var ahora_formateado;
			args.IsValid = true;
			if(strFecha!=null)
			{
				ahora_formateado = (ahora.getDate()) + '/' +  (ahora.getMonth() + 1) + '/' +  (ahora.getFullYear());
				args.IsValid = EsFechaMayor(ahora_formateado, strFecha);
			}
		}
		
		/*******************************************/
		
function ComprobarConFechaNacimiento(sender, args)
		{
			var strFecha=args.Value;

			args.IsValid = true;
				
			if(document.getElementById("fechaAntiguedadCCC_salida")!=null)
			{
				strFechaNacimiento=document.getElementById("fechaAntiguedadCCC_salida").value;

				//alert(strFecha);
				//alert(strFechaNacimiento);
				args.IsValid = EsFechaMayor(strFecha,strFechaNacimiento);			
			}
		}	
	
	/*************************************************/
	
		function setFechaCalendario(vFecha, vIdCampoOculto)
	{
		var oTxtSalida = document.getElementById(vIdCampoOculto + "_salida");
		if (oTxtSalida != null)
		{
			var arrFecha = vFecha.split('/');		
			if (arrFecha[1].length == 1)
				arrFecha[1] = "0" + arrFecha[1];
			if (arrFecha[0].length == 1)
				arrFecha[0] = "0" + arrFecha[0];
			
			oTxtSalida.value = arrFecha[1] + "/" + arrFecha[0] + "/" + arrFecha[2];
		}
		
	}	
	

		
	
	