// JavaScript Document

function nuevoAjax(){
var xmlhttp=false;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}

function cargarContenido()
{
	var t1, contenedor;
	contenedor = document.getElementById('cambia');
	t1 = document.getElementById('Provincias_ID').value;
	ajax=nuevoAjax();
	contenedor.innerHTML = '<p style="text-align:center;"><img src="/imagenes/esperando.gif"/></p>';
	ajax.open("GET", "/javascript/cambia_localidad.php?t1="+t1,true);
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
			contenedor.innerHTML = ajax.responseText
		}
	}
	ajax.send(null)
}
function submitform()
{
	if(document.presupuesto.onsubmit())
	{
    	document.presupuesto.submit();
    }
}


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 YY_checkform() { //v4.66
//copyright (c)1998,2002 Yaromat.com
  var args = YY_checkform.arguments; var myDot=true; var myV=''; var myErr='';var addErr=false;var myReq;
  for (var i=1; i<args.length;i=i+4){
    if (args[i+1].charAt(0)=='#'){myReq=true; args[i+1]=args[i+1].substring(1);}else{myReq=false}
    var myObj = MM_findObj(args[i].replace(/\[\d+\]/ig,""));
    myV=myObj.value;
    if (myObj.type=='text'||myObj.type=='password'||myObj.type=='hidden'){
      if (myReq&&myObj.value.length==0){addErr=true}
      if ((myV.length>0)&&(args[i+2]==1)){ //fromto
        var myMa=args[i+1].split('_');if(isNaN(myV)||myV<myMa[0]/1||myV > myMa[1]/1){addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==2)){
          var rx=new RegExp("^[\\w\.=-]+@[\\w\\.-]+\\.[a-z]{2,4}$");if(!rx.test(myV))addErr=true;
      } else if ((myV.length>0)&&(args[i+2]==3)){ // date
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);
        if(myAt){
          var myD=(myAt[myMa[1]])?myAt[myMa[1]]:1; var myM=myAt[myMa[2]]-1; var myY=myAt[myMa[3]];
          var myDate=new Date(myY,myM,myD);
          if(myDate.getFullYear()!=myY||myDate.getDate()!=myD||myDate.getMonth()!=myM){addErr=true};
        }else{addErr=true}
      } else if ((myV.length>0)&&(args[i+2]==4)){ // time
        var myMa=args[i+1].split("#"); var myAt=myV.match(myMa[0]);if(!myAt){addErr=true}
      } else if (myV.length>0&&args[i+2]==5){ // check this 2
            var myObj1 = MM_findObj(args[i+1].replace(/\[\d+\]/ig,""));
            if(myObj1.length)myObj1=myObj1[args[i+1].replace(/(.*\[)|(\].*)/ig,"")];
            if(!myObj1.checked){addErr=true}
      } else if (myV.length>0&&args[i+2]==6){ // the same
            var myObj1 = MM_findObj(args[i+1]);
            if(myV!=myObj1.value){addErr=true}
      }
    } else
    if (!myObj.type&&myObj.length>0&&myObj[0].type=='radio'){
          var myTest = args[i].match(/(.*)\[(\d+)\].*/i);
          var myObj1=(myObj.length>1)?myObj[myTest[2]]:myObj;
      if (args[i+2]==1&&myObj1&&myObj1.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
      if (args[i+2]==2){
        var myDot=false;
        for(var j=0;j<myObj.length;j++){myDot=myDot||myObj[j].checked}
        if(!myDot){myErr+='* ' +args[i+3]+'\n'}
      }
    } else if (myObj.type=='checkbox'){
      if(args[i+2]==1&&myObj.checked==false){addErr=true}
      if(args[i+2]==2&&myObj.checked&&MM_findObj(args[i+1]).value.length/1==0){addErr=true}
    } else if (myObj.type=='select-one'||myObj.type=='select-multiple'){
      if(args[i+2]==1&&myObj.selectedIndex/1==0){addErr=true}
    }else if (myObj.type=='textarea'){
      if(myV.length<args[i+1]){addErr=true}
    }
    if (addErr){myErr+='* '+args[i+3]+'\n'; addErr=false}
  }
  if (myErr!=''){alert('La información requerida esta incompleta o contiene errores:\n\n'+myErr)}
  document.MM_returnValue = (myErr=='');
}

function FormuContac(){
	var c, nombre, apellidos, asunto, email, mensaje, IDIOMA;
	c = document.getElementById('resultado');
	nombre = document.getElementById('nombre').value;
	apellidos=document.getElementById('apellidos').value;
	asunto=document.getElementById('asunto').value;
	email=document.getElementById('email').value;
	mensaje=document.getElementById('mensaje').value;
	IDIOMA = document.getElementById('IDIOMA').value;
	ajax=nuevoAjax();
	c.innerHTML = '<p style="text-align:center;"><img src="/imagenes/esperando.gif"/></p>'; 
	ajax.open("GET", "/javascript/envia_contac.php?nombre="+nombre+"&apellidos="+apellidos+"&asunto="+asunto+"&email="+email+"&mensaje="+mensaje+"&IDIOMA="+IDIOMA,true);
	ajax.onreadystatechange=function() {
	if (ajax.readyState==4) {
	c.innerHTML = ajax.responseText
	}
	borrarCamposFormuContac()	
	}
	ajax.send(null)
}


function borrarCamposFormuContac(){
	document.getElementById('nombre').value="";
	document.getElementById('apellidos').value="";
	document.getElementById('asunto').value="";
	document.getElementById('email').value="";
	document.getElementById('mensaje').value="";
	document.getElementById('nombre').focus();
}
function cambiaraction()
{		
	var Provincias_ID, Localidad, Tipoinmueble;
	Provincias_ID=document.getElementById('Provincias_ID').value;
	Localidad=document.getElementById('Localidad').value;
	Tipoinmueble=document.getElementById('Tipoinmueble').value;	
	if(Provincias_ID==1 && Localidad== 10)
	{
		if(Tipoinmueble==1)
		{
			document.presupuesto.action = "/promociones/La-Torre-tipo-I.html"
		}
		else if(Tipoinmueble==2)
		{
			document.presupuesto.action = "/promociones/La-Torre-tipo-II.html"
		}
		else
		{
			document.presupuesto.action = "/promociones/La-Torre-tipo-III.html"
		}		
	}
	else if(Provincias_ID==1 && Localidad== 11)
	{
		if(Tipoinmueble==1)
		{
			document.presupuesto.action = "/promociones/Anfora-tipo-I.html"
		}
		else if(Tipoinmueble==2)
		{
			document.presupuesto.action = "/promociones/Anfora-tipo-II.html"
		}
		else
		{
			document.presupuesto.action = "/promociones/Anfora-tipo-III.html"
		}		

	}
	else if(Provincias_ID==2 && Localidad== 15)
	{
		if(Tipoinmueble==1)
		{
			document.presupuesto.action = "/promociones/Compte-tipo-I.html"
		}
		else if(Tipoinmueble==2)
		{
			document.presupuesto.action = "/promociones/Compte-tipo-II.html"
		}
		else
		{
			document.presupuesto.action = "/promociones/Compte-tipo-III.html"
		}		

	}
	else if(Provincias_ID==3 && Localidad== 20)
	{
		if(Tipoinmueble==1)
		{
			document.presupuesto.action = "/promociones/Noa-tipo-I.html"
		}
		else if(Tipoinmueble==2)
		{
			document.presupuesto.action = "/promociones/Noa-tipo-II.html"
		}
		else
		{
			document.presupuesto.action = "/promociones/Noa-tipo-III.html"
		}		

	}
}
function navejavas() {
	URL = new String;
	directorio = new Object;
	var x = 0;
	var final = 0;
	var salida = "<div class=\"navejavas\"><a href=/>Apartamento-directo</a> » ";		
	URL = location.href;
	URL = URL.slice(8,URL.length);
	Cortarinicio = URL.indexOf("/");
	URL = URL.slice(Cortarinicio+1,URL.length)
	
	s = URL.lastIndexOf(".");
	p = URL.lastIndexOf("/") + 1;
	nombrepag = URL.substring(s, p); 
  	while(!final){
    	Cortarinicio = URL.indexOf("/");
    	if (Cortarinicio != -1){
      	directorio[x] = URL.slice(0,Cortarinicio)
      	URL = URL.slice(Cortarinicio+1,URL.length);
    	} else {
      	final = 1;
    }
    x++;
  }
  for(var i in directorio){
    salida += "<a href=\"";
    for(y=1;y<x-i;y++){
      salida += "../";
    }
    salida += directorio[i] + "/\">" + directorio[i].replace(/\+/g," ") + "</a> » ";
  }
  document.write(salida);
  document.write("</div>");
}

