// JScript File

function Trimming(pStrCadena)
{
	while(pStrCadena.charAt(0)==' ')
		pStrCadena=pStrCadena.substring(1,pStrCadena.length);
	while(pStrCadena.charAt(pStrCadena.length-1)==' ')
		pStrCadena=pStrCadena.substring(0,pStrCadena.length-1);
	return pStrCadena;
}

function f_solo_letras(evt){
    var nav4 = window.Event ? true : false;
    var key = nav4 ? evt.which : evt.keyCode; 
	return ((key >= 65 && key <= 90) || (key >= 97 && key <= 122) || key == 32 || key == 241 || key == 209);
}

function f_IsMaxLength(pObjControl, pIntMaxLenght){
	if (pObjControl.value.length>pIntMaxLenght)
		pObjControl.value=pObjControl.value.substring(0,pIntMaxLenght);
}

function LoadCalendar()
{
	var objEarlyDateEx3 = new Date();
	objEarlyDateEx3.setMonth(objEarlyDateEx3.getMonth());
	var objLateDateEx3 = new Date();
	objLateDateEx3.setMonth(objLateDateEx3.getMonth() + 12);
	
	var objFecSalCot = document.getElementById('ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaRecojoAuto');
	objFecSalCot.DateChooser = new DateChooser();
	objFecSalCot.DateChooser.setXOffset(-87);
	objFecSalCot.DateChooser.setYOffset(18);
	objFecSalCot.DateChooser.setEarliestDate(objEarlyDateEx3);
	objFecSalCot.DateChooser.setLatestDate(objLateDateEx3);
	objFecSalCot.DateChooser.setStartDate(objEarlyDateEx3);
    objFecSalCot.DateChooser.setUpdateField('ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaRecojoAuto', 'd/m/Y');
	events.add(document.getElementById('imgFecIni'), 'click', objFecSalCot.DateChooser.display);
	
	var objFecRetCot = document.getElementById('ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaDevolucionAuto');
	objFecRetCot.DateChooser = new DateChooser();
	objFecRetCot.DateChooser.setXOffset(-87);
	objFecRetCot.DateChooser.setYOffset(18);
	objFecRetCot.DateChooser.setEarliestDate(objEarlyDateEx3);
	objFecRetCot.DateChooser.setLatestDate(objLateDateEx3);
	objEarlyDateEx3.setDate(objEarlyDateEx3.getDate()+7);
	objFecRetCot.DateChooser.setStartDate(objEarlyDateEx3);
    objFecRetCot.DateChooser.setUpdateField('ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaDevolucionAuto', 'd/m/Y');
    events.add(document.getElementById('imgFecFin'), 'click', objFecRetCot.DateChooser.display);
	return true;
}


function f_OnKeyDown_fecha(pObjTextBox){
	var strCadena = pObjTextBox.value;
	if(strCadena.length==2){
		pObjTextBox.value+="/";
	}
	else if(strCadena.length==5){
		pObjTextBox.value+="/20";
	}
}

function f_OnKeyUp_fecha(pObjTextBox){
	var strCadena = pObjTextBox.value;
	if(strCadena.length==2){
		pObjTextBox.value+="/";
	}
	else if(strCadena.length==5){
		pObjTextBox.value+="/20";
	}
}

function f_solo_numeros_fecha(evt){ 
    var nav4 = window.Event ? true : false;
	var key = nav4 ? evt.which : evt.keyCode; 
	return (key <= 13 || (key >= 48 && key <= 57) || key==47);
}

function f_IsMaxLength(pObjControl, pIntMaxLenght){
	if (pObjControl.value.length>pIntMaxLenght)
		pObjControl.value=pObjControl.value.substring(0,pIntMaxLenght);
}

function f_valida_car_rent(){
    var strNomUsu =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtNombres").value);
    var strMail =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtmail").value);
    var strTelefono =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtTelefono").value);
    var strTipoAuto =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_cbTipoAuto").value);
    var strCiuRecojo =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiudadRecojo").value);
    var strCiuDev =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiudadDevolucion").value);
    var strCiuDestino =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiuDestino").value);
    var strDiaRecojo =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaRecojoAuto").value);
    var strDiaDev =  Trimming(document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaDevolucionAuto").value);    
    
    
    if(strNomUsu==""){
        alert("Ingrese su nombre y apellidos.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtNombres").focus();
        return false;
    }
    else if(strMail==""){
        alert("Ingrese E-Mail.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtmail").focus();        
        return false;
    }
    else if(strTelefono==""){
        alert("Ingrese Numero de Telefono");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtTelefono").focus();
        return false;       
    }
    else if(parseInt(strTipoAuto)==0||parseInt(strTipoAuto)==9){
        alert("Seleccione un tipo de auto.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_cbTipoAuto").focus();
        return false;
    }
    else if(!f_selecciona_seguro()){
        alert("Seleccione un seguro.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_rbTodos").focus();
        return false;
    }
    else if(strCiuRecojo==""){
        alert("Ingrese la ciudad de recojo de auto.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiudadRecojo").focus();
        return false;
    }
    else if(strCiuDev==""){
        alert("Ingrese la ciudad de devolución del auto.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiudadDevolucion").focus();
        return false;
    }
    else if(strCiuDestino==""){
        alert("Ingrese la ciudad de destino.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtCiuDestino").focus();
        return false;
    }
    else if(strDiaRecojo==""){
        alert("Ingrese la fecha de recojo.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaRecojoAuto").focus();
        return false;
    }
    else if(strDiaDev==""){
        alert("Ingrese la fecha de devolución.");
        document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_txtDiaDevolucionAuto").focus();
        return false;
    }            
    else return true;
}

function f_selecciona_seguro(){
    var bolTodos =  document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_rbTodos").checked;
    var bolGPS =  document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_rbGPS").checked;
    var bolCDW =  document.getElementById("ctl00_ContentPlaceHolder1_Alquiler_auto1_rbCDW").checked;
    if(bolTodos==false&&bolGPS==false&&bolCDW==false)
        return false
    else
        return true;
}