// JavaScript Document
function MM_swapImgRestore() { //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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.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];}}
}

function MM_findObj(n, d) { //v4.01
  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;
}

function MM_swapImage() { //v3.0
  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 esFecha(dia,mes,ano){
	var num_dias;
	if(parseInt(mes)>=1 && parseInt(mes)<=12){
		switch(parseInt(mes)){
			case 1 : num_dias=31; break;
			case 2 : num_dias=((ano % 4)==0) ? 29 : 28; break;
			case 3 : num_dias=31; break;
			case 4 : num_dias=30; break;
			case 5 : num_dias=31; break;
			case 6 : num_dias=30; break;
			case 7 : num_dias=31; break;
			case 8 : num_dias=31; break;
			case 9 : num_dias=30; break;
			case 10 : num_dias=31; break; 
			case 11 : num_dias=30; break;
			case 12 : num_dias=31; break;
			default : num_dias=31; 
		}
		if(parseInt(dia)<=num_dias){
			return true;
		}
		else{
			return false;
		}
	}
	else{
		return false;
	}
}

var monthDays=new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function isLeapYear (year) { 
	if ( year < 0) { return (year +1) % 4 == 0; }
	if ( year < 1582 ) { return year % 4 == 0; }
	if ( year % 4 != 0 ) { return false; }
	if ( year % 100 != 0 ) { return true; }
	if ( year % 400 != 0 ) { return false; }
	if ( year % 3200 != 0 ) { return true; }
	return false; 
} 

function actualizarFecha2(){
	day = window.document.getElementById("diaSalida").value;
	anyo_mes = window.document.getElementById("mesSalida").value;	
	alist = anyo_mes.split("-");
	year  = alist[0];
	month = alist[1]-1; 	
	
	mesActual = Number(month);
	
	if( month==1  ){
		if( isLeapYear( year ) ){
			ultimoDia = 29;							   				
		}else{
			ultimoDia = 28;
		}
	}else{
		ultimoDia = monthDays[month];
	}		
	
	if( ultimoDia-1==day ){
		endate = new Date( year, Number(mesActual)+1, 1 );
	}else if( ultimoDia==day ){
		endate = new Date( year, Number(mesActual)+1, 2 );			
	}else{
		endate = new Date( year, mesActual, ( Number(day)+2  ) );				
	}	

	window.document.getElementById("diaVuelta").value = endate.getDate();
	window.document.getElementById("mesVuelta").value = endate.getFullYear()+"-"+(Number(endate.getMonth())+1);	
}

function ventanaCobertura( idCobertura, idIdioma, pID ){ 
	url  = "pop_cobertura.php?pIDCobertura="+idCobertura;
	url = url+"&pIDIdioma="+idIdioma;
	url = url+"&pID="+pID;	
	ventana = window.open(url,'Budget','left=600,top=200,width=400,height=350,scrollbars=yes,toolbar=no,resizable=yes');
	ventana.focus();
}

function popupTerminos( pagina ){ 
	url  = pagina;
	ventana = window.open(url,'Budget','left=600,top=200,width=250,height=300,scrollbars=yes,toolbar=no,resizable=yes');
	ventana.focus();
}

function popupVersionImprimible( pagina ){ 
	url  = '../mail/reserva_budget.php?pID='+pagina;
	ventana = window.open(url,'Budget','menubar=yes,left=250,top=150,width=600,height=550,scrollbars=yes,toolbar=no,resizable=yes');
	ventana.focus();
}

function registrarPromocion( id ){	
	document.frmReserva.idPromocion.value = id;
	document.frmReserva.doAction.value = "reservar";
	document.frmReserva.submit();	
}

function onCompra()
{
	var objWindow=window.open("http://www.vehiculosa1.com/content/pop_comprainmediata.php","compra","top=50,left=50,width=460,height=635,resizable=no,scrollbars=no");
	objWindow.focus();
}

/****************STRIPES ***************/

/*------------------------------------------------------------------
// this function is need to work around 
// a bug in IE related to element attributes
------------------------------------------------------------------*/

function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    // the flag we'll use to keep track of 
    // whether the current row is odd or even
    var even = false;
  
    // if arguments are provided to specify the colours
    // of the even & odd rows, then use the them;
    // otherwise use the following defaults:
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#eee";
  
    // obtain a reference to the desired table
    // if no such table exists, abort
    var table = document.getElementById(id);
    if (! table) { return; }
    
    // by definition, tables can have more than one tbody
    // element, so we'll have to get the list of child
    // &lt;tbody&gt;s 
    var tbodies = table.getElementsByTagName("tbody");

    // and iterate through them...
    for (var h = 0; h < tbodies.length; h++) {
    
     // find all the &lt;tr&gt; elements... 
      var trs = tbodies[h].getElementsByTagName("tr");
      
      // ... and iterate through them
      for (var i = 0; i < trs.length; i++) {

	    // avoid rows that have a class attribute
        // or backgroundColor style
	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
         // get all the cells in this row...
          var tds = trs[i].getElementsByTagName("td");
        
          // and iterate through them...
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

            // avoid cells that have a class attribute
            // or backgroundColor style
	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;
              
            }
          }
        }
        // flip from odd to even, or vice-versa
        even =  ! even;
      }
    }
  }





