//**************************************
//Autor: Ariel Bacher - José Luis Lasala
//**************************************

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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

function tmt_winOpen(u,id,f,df){
	if(eval(id)==null||eval(id+".closed")){
	eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
	else if(df){eval(id+".focus()");}
	else{eval(id+"=window.open('"+u+"','"+id+"','"+f+"')");eval(id+".focus()");}
}

function MM_displayStatusMsg(msgStr) { //v1.0
  status=msgStr;
  document.MM_returnValue = true;
}

function vacia_select(theForm) {
	theForm.elements[2].value = '';
	theForm.elements[3].value = '0';
	theForm.elements[4].length = 1;
	rellena_select(theForm, 0, 'Ningún Barrio disponible               ', '0', true);
}

function rellena_select(theForm, posicion, texto, valor, seleccionado) {
	theForm.elements[4].options[posicion] = new Option(texto, valor);
	theForm.elements[4].options[posicion].selected = seleccionado;
}

function cambio_operacion(theForm) {
	if(theForm.operacion[theForm.operacion.selectedIndex].value == 'alquiler') {
		//Coloco los valores de compra en ambos combos
		theForm.preciodde.length = 1;
		theForm.preciodde.options[0] = new Option('0 €', '0');
		theForm.preciodde.options[1] = new Option('80 €', '80');
		theForm.preciodde.options[2] = new Option('150 €', '150');
		theForm.preciodde.options[3] = new Option('200 €', '200');
		theForm.preciodde.options[4] = new Option('330 €', '330');
		theForm.preciodde.options[5] = new Option('450 €', '450');
		theForm.preciodde.options[6] = new Option('600 €', '600');
		theForm.preciodde.options[7] = new Option('750 €', '750');
		theForm.preciodde.options[8] = new Option('900 €', '900');
		theForm.preciodde.options[9] = new Option('1.200 €', '1200');
		theForm.preciodde.options[10] = new Option('2.400 €', '2400');

		theForm.preciohst.length = 1;	
		theForm.preciohst.options[0] = new Option('80 €', '80');
		theForm.preciohst.options[1] = new Option('150 €', '150');
		theForm.preciohst.options[2] = new Option('200 €', '200');
		theForm.preciohst.options[3] = new Option('330 €', '330');
		theForm.preciohst.options[4] = new Option('450 €', '450');
		theForm.preciohst.options[5] = new Option('600 €', '600');
		theForm.preciohst.options[6] = new Option('750 €', '750');
		theForm.preciohst.options[7] = new Option('900 €', '900');
		theForm.preciohst.options[8] = new Option('1.200 €', '1200');
		theForm.preciohst.options[9] = new Option('2.400 €', '2400');
		theForm.preciohst.options[10] = new Option('2.400 € ó +', 'null');
	} else {
		//Coloco los valores de alquiler en ambos combos
		theForm.preciodde.length = 1;	
		theForm.preciodde.options[0] = new Option('0 €', '0');
		theForm.preciodde.options[1] = new Option('12.000 €', '12000');
		theForm.preciodde.options[2] = new Option('18.000 €', '18000');
		theForm.preciodde.options[3] = new Option('30.000 €', '30000');
		theForm.preciodde.options[4] = new Option('60.000 €', '60000');
		theForm.preciodde.options[5] = new Option('90.000 €', '90000');
		theForm.preciodde.options[6] = new Option('120.000 €', '120000');
		theForm.preciodde.options[7] = new Option('150.000 €', '150000');
		theForm.preciodde.options[8] = new Option('180.000 €', '180000');
		theForm.preciodde.options[9] = new Option('210.000 €', '210000');
		theForm.preciodde.options[10] = new Option('240.000 €', '240000');
		theForm.preciodde.options[11] = new Option('270.000 €', '270000');
		theForm.preciodde.options[12] = new Option('300.000 €', '300000');
		theForm.preciodde.options[13] = new Option('330.000 €', '330000');
		theForm.preciodde.options[14] = new Option('360.000 €', '360000');
		theForm.preciodde.options[15] = new Option('450.000 €', '450000');
		theForm.preciodde.options[16] = new Option('540.000 €', '540000');
		theForm.preciodde.options[17] = new Option('660.000 €', '660000');

		theForm.preciohst.length = 1;
		theForm.preciohst.options[0] = new Option('12.000 €', '12000');
		theForm.preciohst.options[1] = new Option('18.000 €', '18000');
		theForm.preciohst.options[2] = new Option('30.000 €', '30000');
		theForm.preciohst.options[3] = new Option('60.000 €', '60000');
		theForm.preciohst.options[4] = new Option('90.000 €', '90000');
		theForm.preciohst.options[5] = new Option('120.000 €', '120000');
		theForm.preciohst.options[6] = new Option('150.000 €', '150000');
		theForm.preciohst.options[7] = new Option('180.000 €', '180000');
		theForm.preciohst.options[8] = new Option('210.000 €', '210000');
		theForm.preciohst.options[9] = new Option('240.000 €', '240000');
		theForm.preciohst.options[10] = new Option('270.000 €', '270000');
		theForm.preciohst.options[11] = new Option('300.000 €', '300000');
		theForm.preciohst.options[12] = new Option('330.000 €', '330000');
		theForm.preciohst.options[13] = new Option('360.000 €', '360000');
		theForm.preciohst.options[14] = new Option('450.000 €', '450000');
		theForm.preciohst.options[15] = new Option('540.000 €', '540000');
		theForm.preciohst.options[16] = new Option('660.000 €', '660000');
		theForm.preciohst.options[17] = new Option('660.000 € ó +' , 'null');
	}
}

function Validar_Buscador(theForm){
	if(theForm.provincia[theForm.provincia.selectedIndex].value == "0") {
		alert("Debe seleccionar la provincia!");
		theForm.provincia.focus();
		return (false);
	} 
	
	if(theForm.cod_ciudad.value == "0") {
		alert("Debe seleccionar la poblacion!");
		theForm.ciudad.focus();
		return (false);
	} 
	
	if(theForm.preciohst[theForm.preciohst.selectedIndex].value != "null") { //si no es NULL
		if(Number(theForm.preciohst[theForm.preciohst.selectedIndex].value) <= Number(theForm.preciodde[theForm.preciodde.selectedIndex].value)) {
			alert("Debe seleccionar un precio máximo mayor al mínimo!");
			theForm.preciohst.focus();
			return (false);
		} 
	} 
	
return (true);
}

function formatPta(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
		num = "0";
	num = Math.floor(num*100+0.50000000001);
	num = Math.floor(num/100).toString();

	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+'.'+
		num.substring(num.length-(4*i+3));
	return (num);
}

function PrecioPta(theForm) {
	desde_str = formatPta(Number(theForm.preciodde[theForm.preciodde.selectedIndex].value)*166.386);
	hasta_str = formatPta(Number(theForm.preciohst[theForm.preciohst.selectedIndex].value)*166.386);
	return ('Precio entre '+desde_str+' Pta. y '+hasta_str+' Pta.');
}

function SetPreciomax(theForm) {
	if (Number(theForm.preciohst[theForm.preciohst.selectedIndex].value) <= Number(theForm.preciodde[theForm.preciodde.selectedIndex].value)) {
		for(i=0; i<theForm.preciohst.length; i++) {
			//alert('Precio hasta:'+theForm.preciohst.options[i].value);
			if(Number(theForm.preciohst.options[i].value) > Number(theForm.preciodde[theForm.preciodde.selectedIndex].value)) {
				theForm.preciohst.options[i].selected = true;
				break;
			}
		}
	}
	return (PrecioPta(theForm));
}

function Validar_Contacto(theForm){
	if(theForm.nombre.value == "") {
		alert("Por favor, complete su nombre!");
		theForm.nombre.focus();
		return (false);
	} 
	
	if(theForm.domicilio.value == "") {
		alert("Por favor, complete su domicilio!");
		theForm.domicilio.focus();
		return (false);
	} 
	
	if(theForm.localidad.value == "") {
		alert("Por favor, complete su localidad!");
		theForm.localidad.focus();
		return (false);
	} 
	
	if(theForm.provincia.value == "") {
		alert("Por favor, complete su provincia!");
		theForm.provincia.focus();
		return (false);
	} 
	
	if((theForm.email.value == "") && (theForm.telefono.value == "")) {
		alert("Por favor, complete un teléfono o email para contactarlo!");
		theForm.telefono.focus();
		return (false);
	} 
	
	if(theForm.telefono.value != "") {
		var v_tel = new String(theForm.telefono.value);
		if((v_tel.length > 0) && (v_tel.length < 4)){
			alert("Por favor, complete un número de teléfono válido!");
			theForm.telefono.focus();
			theForm.telefono.select();
			return (false);
		}
		
		//teltxt = new String(theForm.telefono.value);
		//telnmb = new Number(teltxt);
		//alert(Number(teltxt));
		//alert(isNAN(telnmb));
		//if(isNAN(Number(telnmbr))) { //No ingresó sólo números
		//	alert("Sólo se admiten números en el teléfono!");
		//	theForm.telefono.focus();
		//	theForm.telefono.select();
		//	return (false);
		//}
	} 

	if(theForm.comentario.value == "") {
		alert("Por favor, complete su comentario!");
		theForm.comentario.focus();
		return (false);
	} 
	
return (true);
}

function Validar_Hipotecas(theForm){
	if(theForm.nombre.value == "") {
		alert("Por favor, complete su nombre!");
		theForm.nombre.focus();
		return (false);
	} 
	
	if(theForm.domicilio.value == "") {
		alert("Por favor, complete su domicilio!");
		theForm.domicilio.focus();
		return (false);
	} 
	
	if(theForm.localidad.value == "") {
		alert("Por favor, complete su localidad!");
		theForm.localidad.focus();
		return (false);
	} 
	
	if(theForm.provincia.value == "") {
		alert("Por favor, complete su provincia!");
		theForm.provincia.focus();
		return (false);
	} 
	
	if((theForm.email.value == "") && (theForm.telefono.value == "")) {
		alert("Por favor, complete un teléfono o email para contactarlo!");
		theForm.telefono.focus();
		return (false);
	} 
	
	if(theForm.telefono.value != "") {
		var v_tel = new String(theForm.telefono.value);
		if((v_tel.length > 0) && (v_tel.length < 4)){
			alert("Por favor, complete un número de teléfono válido!");
			theForm.telefono.focus();
			theForm.telefono.select();
			return (false);
		}
	} 

	if(theForm.monto.value == "") {
		alert("Por favor, complete el monto!");
		theForm.monto.focus();
		return (false);
	} 

	if(theForm.monto_op.value == "") {
		alert("Por favor, complete el monto de la operación!");
		theForm.monto_op.focus();
		return (false);
	} 
return (true);
}

//tmtC_winOpen
var newWin;
//tmtC_winOpenEnd
