// JavaScript Document
function selAll(){ //v.0.1
	var optall = MM_findObj('selall');
	var optmls = MM_findObj('mlscities');
      for (var intLoop=0; intLoop < optmls.length; intLoop++) {
		  if (optall.checked == true) {
			  optmls[intLoop].selected = true;
		  } else {
			  optmls[intLoop].selected = false;
		  }
	  }
}
function clearChck (){ //0.1
	var optall = MM_findObj('selall');
	if (optall.checked == true){
		optall.checked = false;
	}
}
function swapIMA(imaid) { //v0.1
	var s,y,ab; s=MM_findObj(imaid);
	y = MM_findObj('mainImage');
	ab = s.src;
	s.src = y.src;
	y.src = ab;
}
function chClass(id1, cl1) { //v0.1
	did1=MM_findObj(id1);did1.className=cl1;
}

function swapVis(div1, div2) { //v0.1
	div1id=MM_findObj(div1);div2id=MM_findObj(div2);
	div2id.style.display='none';
	div1id.style.display='inline';
}
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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
function pReqChange() {
    if (req.readyState == 4) {
        if (req.status == 200) {
			if (req.responseText.indexOf('invalid') == -1) {
				var cim; var prm;
				var xmld = req.responseXML;
				var xmld2= xmld.getElementsByTagName('gzone');
				var cim = MM_findObj(nfi);
				var prm =  MM_findObj(ty1);
				var v1,v2=0;var i = 0;
				var j = cim.options.length;
				for (i=0;i<j;i++){cim.options[cim.options.length -1]= null;}
				for (j=0;j<xmld2[0].childNodes.length;j++) 
				  {v1 = xmld2[0].childNodes[j].firstChild.nodeValue;
				   v2 = xmld2[0].childNodes[j].getAttribute("idval");
				   cim.options[j] = new Option(v1,v2);
				   if (typeof(dval)=="object")
						  {
						  for (k=0;k<dval.length;k++)
					 			 {

								 if (v2==dval[k])
								 		{
								 			cim.options[j].selected =true;

								 	 	}
							   }
					   	}
				   else
					    {
								if (v2==dval){cim.options[j].selected =true;}
						  }
				   }
	 			document.getElementById(ty1+"_img").src = urlP + 'assets/topimg/spacer.gif'; 
				if (nfi== (pref + 'city')){MM_findObj(nfi).disabled=false;}else{loadXMLDoc(nfi,1);}
		   cim.disabled=false;
		  } else {
            alert("There was a problem retrieving the XML data:\n" +
                req.statusText);
        } 
     }
 	}
}

var req;
var ty1,pref,ty_otro,ava,nfi,dval,urlP=null;
var q,ial=0;

function loadXMLDoc(ty,ty2,ty3) {
	urlP = uPath;
	ial=ty2;ava=ty3;newty=ty;ty1=ty;
	pref = MM_findObj('prefijo').value;
	switch (ty){
		case 'mlszone':
		case 'hotzone':
		case 'beachzone':
		case 'resalezone':
		case 'golfzone':
		case 'investzone':
		case 'comerzone':
		case 'fraczone':
		case 'preprozone':
		case 'inlandzone':
		case 'plotzone':
			ty_otro="zone";
			nfi = pref + 'city';
			dval= city_mls;
			break;
		case 'mlsgzone':
		case 'hotgzone':
		case 'beachgzone':
		case 'resalegzone':
		case 'golfgzone':
		case 'investgzone':
		case 'comergzone':
		case 'fracgzone':
		case 'preprogzone':
		case 'inlandgzone':
		case 'plotgzone':
			ty_otro="gzone";
			nfi = pref + 'zone';
			dval= zone_mls;
			break;
		case 'mlscountry':
		case 'hotcountry':
		case 'beachcountry':
		case 'resalecountry':
		case 'golfcountry':
		case 'investcountry':
		case 'comercountry':
		case 'fraccountry':
		case 'preprocountry':
		case 'inlandcountry':
		case 'plotcountry':
			ty_otro="country";
			nfi = pref + 'gzone';
			dval= gzone_mls;
			break;
		case 'newdevcountry':
			ty_otro='ndcountry';	
			nfi = 'newdevgzone';
			dval=gzone_mls;
			break;
		case 'newdevgzone':
			ty_otro='ndgzone';	
			nfi = 'newdevzone';
			dval=zone_mls;
			break;
		case 'newdevzone':
			ty_otro='ndzone';	
			nfi = 'newdevcity';
			dval=city_mls;
			break;
	}
	url = urlP + "include/inc_files/getValue.php?type=" + escape(ty_otro) + "&lang=" + lang + "&all=" + ial + "&provid=";
	pval = MM_findObj(ty).value;
	MM_findObj(nfi).disabled=true;
	MM_findObj(ty + '_img').src = urlP + 'assets/imavar/spin2.gif';
    if (window.XMLHttpRequest) {//XMLHttpRequest
        req = new XMLHttpRequest();
        req.onreadystatechange = pReqChange;
        req.open("GET", url + escape(pval)+"&newty="+escape(newty), true);
        req.send(null);
    } else if (window.ActiveXObject) {//IE/Windows
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = pReqChange;
            req.open("GET", url + escape(pval)+"&newty="+escape(newty), true);
            req.send();
        	}
		}
}
function add_comment(unique)
		{ 	var form_add = "form_add";
			if (isNaN(unique)){form_add='';}
			if(this.document.getElementById(form_add + unique).style.display=='none'){
				this.document.getElementById(form_add + unique).style.display='inline';
			}else{
				this.document.getElementById(form_add + unique).style.display='none';
			}
		}
 function CreateBookmarkLink(tit,urlF) {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(tit, urlF,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( urlF, tit); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
 }
 
 function show_faq(unique)
 { 	
	var answer = "answer";
	if (isNaN(unique)){answer='';}
	if(this.document.getElementById(answer + unique).style.display=='none')
	{
			this.document.getElementById(answer + unique).style.display='inline';
	}
	else
	{
			this.document.getElementById(answer + unique).style.display='none';
	}
 }
 
function show_faqs(unique)
{ 	
	var faq = "faq";

	if (isNaN(unique))
	{
		faq='';
	}
	
	for(i=1;i<=5;i++)
	{
		if(i == unique)
		{
				this.document.getElementById(faq + i).style.display='inline';
		}
		else
		{
				this.document.getElementById(faq + i).style.display='none';
		}
	}
}