// Array de dias que corresponden a cada mes del ano en orden
var DiasPorMes=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

var locCodeHolder;
var mesEntrada;
var mesSalida;

d = new Date();
var Hoy=new Date();

function MM_SIR() { //v3.0
    var i,x,a=document.MM_sr; 
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
    x.src=x.oSrc;
}

function MM_FO(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_FO(n,d.layers[i].document); return x;
}

function MM_SI() { 
    var i,j=0,x,a=MM_SI.arguments; 
    document.MM_sr=new Array; 
    for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_FO(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**
 * @method add_days
 * @param {Object} date1 yyyyMMdd
 * @param {Object} days
 * Incrementa a la fecha actual el nÃºmero de dÃ­as indicado.
 */
function add_days(date1, days){
	var d1 = new Date(date1.substring(0, 4), date1.substring(4, 6) * 1 - 1, date1.substring(6, 8))
	/* Incremento los dias */
	d1.setDate(d1.getDate() + days);
	/* Saco en string */
	var month = (d1.getMonth() + 1).toString();
	var day = d1.getDate().toString();
	/* Anado 0 si solo tiene un digito */
	if (month.length == 1) {
		month = "0" + month;
	}
	if (day.length == 1) {
		day = "0" + day;
	}
	return d1.getFullYear().toString() + month + day;
}
					 	 
function DatetoStringDate(date){
	var x = date.getFullYear().toString()+(date.getMonth()+1).toString()+date.getDate().toString()
	return x
}

function StringDatetoDate(date){
	var d = new Date(date.substring(0,4),date.substring(4,6),date.substring(6,8))
	return d
}

/**
 * @method getYearStringDate
 * @param {Object} sdate yyyyMMdd
 * Devuelve en formato String el ano de la fecha.
 */
function getYearStringDate(sdate){
	return sdate.substring(0,4)
}

/**
 * @method getMonthStringDate
 * @param {Object} sdate yyyyMMdd
 * Devuelve en formato String el mes de la fecha.
 */
function getMonthStringDate(sdate){
	return sdate.substring(4,6)
}

/**
 * @method getDayStringDate
 * @param {Object} sdate yyyyMMdd
 * Devuelve en formato String el dia de la fecha.
 */
function getDayStringDate(sdate){
	var d = sdate.substring(6,8)
	if(d.length==1){
		return "0"+d
	}
	else
	{
	   return d
	}
}

/**
 * @method saberUrl
 * Devuelve la url dependiendo de el proveedor de coches.
 * @param {Object} valor
 */
function saberUrl(valor)
{              
    url   = document.location.href;
    prov  = document.location.href;
    parte = url.split('?');
    partes = url.split('/');
    ext   = parte[parte.length-1];
    urlDispo = partes[partes.length-1];
    
    if(valor == "" || valor == "undefined")
    {
        if(ext=="prov=AVIS")
        {
           document.CarSearchForm.car[1].checked = true;
        }
        else
        {
           document.CarSearchForm.car[0].checked = true;
        }
    }
             
    if(valor == "EUROPCAR")
    {
        if(urlDispo != "disponibilidad.do")
        {                   
            if(ext == "prov=AVIS")
            {
               urlDir = parte[parte.length-2];
            }
            else
            {
               urlDir = ext;
            }
        }
        else
        {
           urlDir = "http://"+partes[partes.length-4]+"/"+partes[partes.length-3]+"/"+partes[partes.length-2]+"/alquiler-coches.do";
        }
        location.href = urlDir;     
    }
    else
    {           
       if(valor== "AVIS")
       {
           if(urlDispo != "disponibilidad.do")
           {
               if(ext == "prov=AVIS")
               {
                 urlDir = parte[parte.length-2]+"?"+ext;
               }
               else
               {
                 urlDir = ext+"?prov=AVIS";
               }
           }
           else
           {
             urlDir = "http://"+partes[partes.length-4]+"/"+partes[partes.length-3]+"/"+partes[partes.length-2]+"/alquiler-coches.do?prov=AVIS";              
           }
           location.href = urlDir;
       }
    }                 
}

function Trim(cad)
{
   var aux="";
   var i,lg = cad.length;
   for (;lg>0 && cad.charAt(lg-1)==' ';lg--);
   for (i=0;i<lg && cad.charAt(i)==' ';i++);
   for (;i<lg;i++)
       aux = aux + cad.charAt(i);
   return aux;
}

function QuitarAcentos(st) {
   st = st.replace(/'?'/g,"A");
   st = st.replace(/'?'/g,"A");
   st = st.replace(/'?'/g,"A");
   st = st.replace(/'?'/g,"A");
   st = st.replace(/'?'/g,"A");
   
   st = st.replace(/'?'/g,"E");
   st = st.replace(/'?'/g,"E");
   st = st.replace(/'?'/g,"E");
   st = st.replace(/'?'/g,"E");
   
   st = st.replace(/'?'/g,"I");
   st = st.replace(/'?'/g,"I");
   st = st.replace(/'?'/g,"I");
   st = st.replace(/'?'/g,"I");
   
   st = st.replace(/'?'/g,"O");
   st = st.replace(/'?'/g,"O");
   st = st.replace(/'?'/g,"O");
   st = st.replace(/'?'/g,"O");
   st = st.replace(/'?'/g,"O");
   
   st = st.replace(/'?'/g,"U");
   st = st.replace(/'?'/g,"U");
   st = st.replace(/'?'/g,"U");
   st = st.replace(/'?'/g,"U");
   
   st = st.replace(/'?'/g,"C");
   
   //Minusculas
   st = st.replace(/'?'/g,"a");
   st = st.replace(/'?'/g,"a");
   st = st.replace(/'?'/g,"a");
   st = st.replace(/'?'/g,"a");
   st = st.replace(/'?'/g,"a");
   
   st = st.replace(/'?'/g,"e");
   st = st.replace(/'?'/g,"e");
   st = st.replace(/'?'/g,"e");
   st = st.replace(/'?'/g,"e");
   
   st = st.replace(/'?'/g,"i");
   st = st.replace(/'?'/g,"i");
   st = st.replace(/'?'/g,"i");
   st = st.replace(/'?'/g,"i");
   
   st = st.replace(/'?'/g,"o");
   st = st.replace(/'?'/g,"o");
   st = st.replace(/'?'/g,"o");
   st = st.replace(/'?'/g,"o");
   st = st.replace(/'?'/g,"o");
   
   st = st.replace(/'?'/g,"u");
   st = st.replace(/'?'/g,"u");
   st = st.replace(/'?'/g,"u");
   st = st.replace(/'?'/g,"u");
   
   st = st.replace(/'?'/g,"c");
   
   //Quitamos comillas simples
   st = st.replace(/'/g,"?");

   return st;
}

function Location(url, elementcode, elementname){
    locCodeHolder = elementcode;
    locDescHolder = elementname;
    window.open(url,'Aeropuertos', 'resizable=yes,toolbars=no,scrollbars=yes,screenX=0,screenY=0,width=633,height=550');
}
               
function setLocationCode(code) {
	locCodeHolder.value = code;
}

function setLocationDesc(name) {
	locDescHolder.value = name;
}

function getHora(sdate){
	return sdate.substring(0,2);
}

function getMinutos(sdate){
	return sdate.substring(2,4);
}   
