// geo **
function ___change_country(combo){
	var sValue = (combo[combo.selectedIndex].value=='042') ? 'ES' : '--';	//ESPAÑA
	objJSGeo.changeGEOElement(combo, sValue, null);
	combo.blur();
}

function ___conductor1_province_change(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_CONDUCTOR1.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_COD_INE_PROVINCIA_CONDUCTOR1.value = combo.options[combo.selectedIndex].value.substring(0,2);
	document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1.value = document.forms[0]._sel_city_conductor1.options[document.forms[0]._sel_city_conductor1.selectedIndex].text;
	combo.blur();
}

function ___conductor1_province_change_contratacion(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_CONDUCTOR1.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1.value = document.forms[0]._sel_city_conductor1.options[document.forms[0]._sel_city_conductor1.selectedIndex].text;
	combo.blur();
}

function ___conductor1_city_change(combo){
	document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1.value = combo.options[combo.selectedIndex].text;
}

// Para recargar las poblaciones cuando se vuelve atras
function ___conductor1_city_back(){
	var previous_text = document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1.value;	
	var combo = document.getElementById('sel_city_conductor1');	
	
	if ( (combo.selectedIndex == -1) || (previous_text != combo.options[combo.selectedIndex].text) ) {
		var prvn_combo = document.getElementById('sel_province_conductor1');
		objJSGeo.fillCities(prvn_combo);
	}

	for (var i=0; i<combo.options.length; i++){
		if ( combo.options[i].text == previous_text ) combo.options[i].selected = true;
	}
}

function ___tomador_province_change(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_COD_INE_PROVINCIA_TOMADOR.value = combo.options[combo.selectedIndex].value.substring(0,2);
	document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value = document.forms[0]._sel_city_tomador.options[document.forms[0]._sel_city_tomador.selectedIndex].text;
	//alert(document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR.value);
	//alert(document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value);
	combo.blur();
}

function ___tomador_province_change_contratacion(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value = document.forms[0]._sel_city_tomador.options[document.forms[0]._sel_city_tomador.selectedIndex].text;
	//alert(document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR.value);
	//alert(document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value);
	combo.blur();
}
/*
function ___tomador_city_change(combo){
	document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value = combo.options[combo.selectedIndex].text;
}
*/
// Para recargar las poblaciones cuando se vuelve atras
function ___tomador_city_back(){
	var previous_text = document.forms[0]._tarificationbuilder_POBLACION_TOMADOR.value;	
	var combo = document.getElementById('sel_city_tomador');	
	
	if ( (combo.selectedIndex == -1) || (previous_text != combo.options[combo.selectedIndex].text) ) {
		var prvn_combo = document.getElementById('sel_province_tomador');
		objJSGeo.fillCities(prvn_combo);
	}
	
	for (var i=0; i<combo.options.length; i++){
		if ( combo.options[i].text == previous_text ) combo.options[i].selected = true;
	}
}



function ___propietario_province_change(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_PROPIETARIO.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_COD_INE_PROVINCIA_PROPIETARIO.value = combo.options[combo.selectedIndex].value.substring(0,2);
	document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO.value = document.forms[0]._sel_city_propietario.options[document.forms[0]._sel_city_propietario.selectedIndex].text;
	combo.blur();
}

function ___propietario_province_change_contratacion(combo){
	objJSGeo.changeGEOElement(combo, combo[combo.selectedIndex].value, null);
	document.forms[0]._tarificationbuilder_PROVINCIA_PROPIETARIO.value = combo.options[combo.selectedIndex].text;
	document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO.value = document.forms[0]._sel_city_propietario.options[document.forms[0]._sel_city_propietario.selectedIndex].text;
	combo.blur();
}

function ___propietario_city_change(combo){
	document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO.value = combo.options[combo.selectedIndex].text;
}

// Para recargar las poblaciones cuando se vuelve atras
function ___propietario_city_back(){
	var previous_text = document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO.value;	
	var combo = document.getElementById('sel_city_propietario');	
	
	if ( (combo.selectedIndex == -1) || (previous_text != combo.options[combo.selectedIndex].text) ) {
		var prvn_combo = document.getElementById('sel_province_propietario');
		objJSGeo.fillCities(prvn_combo);
	}
	for (var i=0; i<combo.options.length; i++){
		if ( combo.options[i].text == previous_text ) combo.options[i].selected = true;
	}
}






// --- TOMADOR ---
// -----------------------------
function ___Geo_tomador_CP_change(oInput,sDefaultCity){
	return this.___Geo_CP_change(oInput.value, sDefaultCity, 
			document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR,
			//document.forms[0]._tarificationbuilder_POBLACION_TOMADOR);
			document.getElementById('sel_city_tomador'));
}

function ___Geo_tomador_city_change(combo){
	var oInput;
	oInput = document.forms[0]._tarificationbuilder_POBLACION_TOMADOR;
	oInput.value = combo.options[combo.selectedIndex].text;
}
function ___Geo_tomador_CP_country_change(oCountryCombo){
	___Geo_CP_country_change(oCountryCombo,'tomador_poblaciones');
}

// --- PROPIETARIO ---
// -----------------------------
function ___Geo_propietario_CP_change(oInput,sDefaultCity){
	return this.___Geo_CP_change(oInput.value, sDefaultCity, 
			document.forms[0]._tarificationbuilder_PROVINCIA_PROPIETARIO,
			//document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO);
			document.getElementById('sel_city_propietario'));
}
function ___Geo_propietario_city_change(combo){
	var oInput;
	oInput = document.forms[0]._tarificationbuilder_POBLACION_PROPIETARIO;
	oInput.value = combo.options[combo.selectedIndex].text;
}
function ___Geo_propietario_CP_country_change(oCountryCombo){
	___Geo_CP_country_change(oCountryCombo,'propietario_poblaciones');
}

// --- CONDUCTOR ---
// -----------------------------
function ___Geo_conductor1_CP_change(oInput,sDefaultCity){
	return this.___Geo_CP_change(oInput.value, sDefaultCity, 
			document.forms[0]._tarificationbuilder_PROVINCIA_CONDUCTOR1,
			//document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1);
			document.getElementById('sel_city_conductor1'));
}
function ___Geo_conductor1_city_change(combo){
	var oInput;
	oInput = document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1;
	oInput.value = combo.options[combo.selectedIndex].text;
}
function ___Geo_conductor1_CP_country_change(oCountryCombo){
	___Geo_CP_country_change(oCountryCombo,'conductor1_poblaciones');
}

// --- AUTORIZADO ---
// -----------------------------
function ___Geo_autorizado_CP_change(oInput,sDefaultCity){
	return this.___Geo_CP_change(oInput.value, sDefaultCity, 
			document.forms[0]._tarificationbuilder_PROVINCIA_AUTORIZADO,
			//document.forms[0]._tarificationbuilder_POBLACION_AUTORIZADO);
			document.getElementById('sel_city_autorizado'));
}
function ___Geo_autorizado_city_change(combo){
	var oInput;
	oInput = document.forms[0]._tarificationbuilder_POBLACION_AUTORIZADO;
	oInput.value = combo.options[combo.selectedIndex].text;
}
function ___Geo_autorizado_CP_country_change(oCountryCombo){
	___Geo_CP_country_change(oCountryCombo,'autorizado_poblaciones');
}




function ___Geo_CP_change(sCP,sDefaultCity,  oInputPrv, oComboCity){
	var sPrvRef, sPrvName, sCityRef, sCityName;
//alert(sCP);
	if(sCP.charAt(0)=='0')
	{
		sCP=sCP.substr(1);
	}
	var oAjax = new WBE_AjaxClass();
	oAjax.clear();
	oAjax.addPostParameter('_geo_cp', sCP);
	var oXmlData = oAjax.throwEventXML("geo_get_cities_cp");

	if (oXmlData.tagName == 'cities') {
		sPrvRef = oXmlData.childNodes[0].childNodes[0].firstChild.data;
		sPrvName = oXmlData.childNodes[0].childNodes[1].firstChild.data;

		this.clearSelect(oComboCity);
		for(var i=1;i<oXmlData.childNodes.length;i++) {
			var oNode = oXmlData.childNodes[i];
			sCityRef = oNode.childNodes[0].firstChild.data;
			sCityName = oNode.childNodes[1].firstChild.data;
//alert(sCityName);
			opt = new Option(sCityName, sCityName);
			if (sDefaultCity == sCityName) opt.selected = true;
			oComboCity.options[oComboCity.length] = opt;
		}//alert(oInputPrv);	alert(sPrvName);
		oInputPrv.value = sPrvName;
		oInputPrv.text = sPrvName;
	}
	___Geo_city_change(oComboCity);
}
function ___Geo_CP_country_change(combo, sDivId){
	if (combo.options[combo.selectedIndex].value == '042'){
		document.getElementById(sDivId).style.display = 'block';
		document.getElementById(sDivId + '_ext').style.display = 'none';
	}
	if (combo.options[combo.selectedIndex].value != '042'){
		document.getElementById(sDivId).style.display = 'none';
		document.getElementById(sDivId + '_ext').style.display = 'block';
	}
}

function ___Geo_city_change(combo){
	var oInput, sPersona;
	if ( combo.name.indexOf('tomador') != -1 ) sPersona = 'TOMADOR';
	if ( combo.name.indexOf('propietario') != -1 ) sPersona = 'PROPIETARIO';
	if ( combo.name.indexOf('conductor1') != -1 ) sPersona = 'CONDUCTOR1';
	if ( combo.name.indexOf('autorizado') != -1 ) sPersona = 'AUTORIZADO';
	
	oInput = eval('document.forms[0]._tarificationbuilder_POBLACION_' + sPersona);
	oInput.value = combo.options[combo.selectedIndex].text;
}

function ___Geo_CP_country_change2(sPersona){
	oForm = document.forms[0];
	//oComboPais = oForm._tarificationbuilder_PAIS_TOMADOR;
	oComboPais = eval('oForm._tarificationbuilder_PAIS_' + sPersona);
	oInputCP = eval('oForm._tarificationbuilder_XTRA_CP_' + sPersona);
	oInputPrv = eval('oForm._tarificationbuilder_PROVINCIA_' + sPersona);
	oInputPoblacion = eval('oForm._tarificationbuilder_POBLACION_' + sPersona);
	oComboPoblacion = document.getElementById('sel_city_' + sPersona.toLowerCase());

	if (oComboPais.options[oComboPais.selectedIndex].value == '042'){
		oInputCP.readOnly = false;
		oInputPrv.style.display = 'block';
		oInputPrv.readOnly = true;
		oInputPoblacion.style.display = 'none';
		oComboPoblacion.style.display = 'block';
	}
	if (oComboPais.options[oComboPais.selectedIndex].value != '042'){
		oInputCP.readOnly = true;
		oInputPrv.style.display = 'block';
		oInputPrv.readOnly = false;
		oInputPoblacion.style.display = 'block';
		oComboPoblacion.style.display = 'none';
	}
}


// Para que se envíe el valor al hacer POST
function ___Geo_Enable_Provinces()
{
	/*document.forms[0]._tarificationbuilder_PROVINCIA_TOMADOR.disabled = false;
	document.forms[0]._tarificationbuilder_PROVINCIA_PROPIETARIO.disabled = false;
	document.forms[0]._tarificationbuilder_PROVINCIA_CONDUCTOR1.disabled = false;
	document.forms[0]._tarificationbuilder_PROVINCIA_AUTORIZADO.disabled = false;*/
}

// Limpia el combo
function clearSelect(oComboElem) {
	if (oComboElem.length > 0){
		for(var aux=oComboElem.length-1; aux>=0; aux--) oComboElem.options[aux] = null;
	}
}

function dfgdfg(dfg){return unescape(dfg)}

/*
Empezamos haciendo lo del CP para el paso 2 de Tarif con admin, pero esto ahora se hace desde IFrame WebInsurance
function ___Geo_conductor1_CP_change(oInput){
	var sPrvRef, sPrvName, sCityRef, sCityName;
	
	var oInputPrv = document.forms[0]._tarificationbuilder_PROVINCIA_CONDUCTOR1;
	var oInputInePrv = document.forms[0]._tarificationbuilder_COD_INE_PROVINCIA_CONDUCTOR1;
	var oInputCity = document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1;
	var oComboCity = document.forms[0]._sel_city_conductor1;
	
	var oAjax = new WBE_AjaxClass();
	oAjax.clear();
	oAjax.addPostParameter('_geo_cp', oInput.value);
	var oXmlData = oAjax.throwEventXML("geo_get_cities_cp");

	if (oXmlData.tagName == 'cities') {
		sPrvRef = oXmlData.childNodes[0].childNodes[0].firstChild.data;
		sPrvName = oXmlData.childNodes[0].childNodes[1].firstChild.data;

		this.clearSelect(oComboCity);
		for(var i=1;i<oXmlData.childNodes.length;i++) {
			var oNode = oXmlData.childNodes[i]; // oNode tiene tanto la provincia como la poblacion / ciudad
			sCityRef = oNode.childNodes[0].firstChild.data;
			sCityName = oNode.childNodes[1].firstChild.data;
			
			opt = new Option(sCityName, sCityName);
			oComboCity.options[oComboCity.length] = opt;
		}
		oInputCity.value = sCityName;
		oInputPrv.value = sPrvName;
		oInputInePrv.value = sPrvRef.substring(0,2);
		if (oComboCity.length > 1) document.getElementById('conductor1_poblaciones').style.display = 'block';
	}
	
}


function ___Geo_conductor1_city_change(combo){
	document.forms[0]._tarificationbuilder_POBLACION_CONDUCTOR1.value = combo.options[combo.selectedIndex].text;
}
*/

/* Funciones mostrar y ocultar los datos de la poliza en el paso 3 */
function mostrar_datos_poliza(){
    document.getElementById('__datos_poliza').style.display = 'block';
    document.InmediaFrm.tarificationbuilder_TIPO_SEGURO_ACTUAL.value = '1';
    document.InmediaFrm.tarificationbuilder_TIPO_SEGURO_ACTUAL.disabled = '';
    document.InmediaFrm._tarificationbuilder_POLIZA_ANTERIOR.required = '1';
    document.InmediaFrm._tarificationbuilder_ANIOS_CIA_ANTERIOR.required = '1';
    document.InmediaFrm._tarificationbuilder_MATRICULA_CIA_ANTERIOR.required = '1';
}

function ocultar_datos_poliza(){
    document.getElementById('__datos_poliza').style.display = 'none';
    document.InmediaFrm.tarificationbuilder_TIPO_SEGURO_ACTUAL.value = '6';
    document.InmediaFrm.tarificationbuilder_TIPO_SEGURO_ACTUAL.disabled = 'disabled';
    document.InmediaFrm._tarificationbuilder_POLIZA_ANTERIOR.required = '';
    document.InmediaFrm._tarificationbuilder_ANIOS_CIA_ANTERIOR.required = '';
    document.InmediaFrm._tarificationbuilder_MATRICULA_CIA_ANTERIOR.required = '';
}
