function ltrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(j, s.length);
}
function rtrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}
function trim(s){
	// Quita los espacios del principio y del final
	return ltrim(rtrim(s));
}

function utf8_encode(s){
  return unescape( encodeURIComponent( s ) );
}

function utf8_decode(s){
  return decodeURIComponent( escape( s ) );
}


function select_innerHTML(objeto,innerHTML){
    objeto.innerHTML = ""
    var selTemp = document.createElement("micoxselect")
    var opt;
    selTemp.id="micoxselect1"
    document.body.appendChild(selTemp)
    selTemp = document.getElementById("micoxselect1")
    selTemp.style.display="none"
    if(innerHTML.indexOf("<option")<0){
        innerHTML = "<option>" + innerHTML + "</option>"
    }
    innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span")
    selTemp.innerHTML = innerHTML
      
    
    for(var i=0;i<selTemp.childNodes.length;i++){
  var spantemp = selTemp.childNodes[i];
  
        if(spantemp.tagName){     
            opt = document.createElement("OPTION")
    
   if(document.all){ //IE
    objeto.add(opt)
   }else{
    objeto.appendChild(opt)
   }       
    
   //getting attributes
   for(var j=0; j<spantemp.attributes.length ; j++){
    var attrName = spantemp.attributes[j].nodeName;
    var attrVal = spantemp.attributes[j].nodeValue;
    if(attrVal){
     try{
      opt.setAttribute(attrName,attrVal);
      opt.setAttributeNode(spantemp.attributes[j].cloneNode(true));
     }catch(e){}
    }
   }
   //getting styles
   if(spantemp.style){
    for(var y in spantemp.style){
     try{opt.style[y] = spantemp.style[y];}catch(e){}
    }
   }
   //value and text
   opt.value = spantemp.getAttribute("value")
   opt.text = spantemp.innerHTML
   //IE
   opt.selected = spantemp.getAttribute('selected');
   opt.className = spantemp.className;
  } 
 }    
 document.body.removeChild(selTemp)
 selTemp = null
}




function doSearch(form){

	var paramaters;
	var lang    = document.getElementById('lang').value;
	var country = document.getElementById('country').value;
	var county  = document.getElementById('county').value;


	// Pick up the form data.
	// first, let's check if there's any reference...

	ref = document.getElementById('reference').value;
	
	

	if(form == 'global'){
		fzone = document.getElementById('zone').value;
		if (fzone == "0"){
			fcity = "0";
			fneighbor = "0";
		}else{
			fcity = document.getElementById('global_city').value;
			if(fcity == "0"){
				fneighbor= "0";
			}else{
				fneighbor= document.getElementById('global_neighbor').value;
			}
		}

		minsup   = document.getElementById('global_minsup').value;
		maxsup   = document.getElementById('global_maxsup').value;
		habs     = document.getElementById('global_habs').value;
		terraza  = document.getElementById('global_terraza').value;
		estado 	 = document.getElementById('status').value;
	}else{
		fzone 	= "0";
		fcity 	= "74";
		estado  = document.getElementById('local_status').value;
		fneighbor = document.getElementById('local_neighbor').value;
	}
	

	eval("minprice = document.getElementById('"+ form +"_lprice').value");
	if(trim(minprice) == ""){
		minprice = "0";	
	}


	eval("maxprice = document.getElementById('"+ form +"_hprice').value");
	if(trim(maxprice) == ""){
		maxprice = "0";	
	}

/*	if(trim(document.getElementById(form +'_type').value) == ""){
		tipo = "0";	
	}else{
		tipo = "";
		for (i=0; i<document.getElementById(form +'_type').options.length; i++){
			if(eval("document.getElementById('"+form +"_type').options[i].selected")){
				tipo += ","+ document.getElementById(form +'_type').options[i].value;
			}
		}
		tipo = tipo.substring(1);
	} */

	tipo = document.getElementById(form +'_type').value;
	subtipo =  document.getElementById(form +'_subtype').value;
	

	parameters = 'form='+ form +'&lang='+ lang +'&country='+ country +'&county='+ county + '&zone='+ fzone + '&city='+ fcity +'&status='+ estado;
	parameters+= '&neighbor='+ fneighbor +'&hprice='+ maxprice +'&lprice='+ minprice +'&tipo='+ tipo +'&subtipo='+ subtipo +'&reference='+ ref;

	if (form == "global"){
		parameters+= '&minsup='+ minsup +'&maxsup='+ maxsup +'&habs='+ habs +'&terraza='+ terraza;
	}

	document.location.href= 'search.asp?'+ parameters;
}

function addUser() {
	var xmlhttp=false; //Clear our fetching variable

	new_login   = document.getElementById("login").value;
	new_passwd  = document.getElementById("passwd").value;
	new_name    = document.getElementById("name").value;
	new_surname = document.getElementById("surname").value;
	new_type = document.getElementById("type").value;


	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();
	}

	var file = '/admin/addUser.asp?login='+ new_login +'&passwd=' + new_passwd + '&name=' + new_name + '&surname=' + new_surname +'&type=' + new_type;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById("login").value = "";
			document.getElementById("passwd").value = "";
			document.getElementById("name").value = "";
			document.getElementById("surname").value = "";
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}

function delUser(id){
	var xmlhttp=false; //Clear our fetching variable

	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();
	}

	var file = '/admin/delUser.asp?id='+ id;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}

function editUser(id){
	document.getElementById('addRow').style.visibility = 'hidden';

	e_login   = trim(document.getElementById('login_'+ id).innerHTML);
	e_passwd  = trim(document.getElementById('passwd_'+ id).innerHTML);
	e_name    = trim(document.getElementById('name_'+ id).innerHTML);
	e_surname = trim(document.getElementById('surname_'+ id).innerHTML);

	document.getElementById('login_'+ id).innerHTML  = "<input type='text' id='ulogin' value='"+ e_login +"'>";
	document.getElementById('passwd_'+ id).innerHTML = "<input type='text' id='upasswd' value='"+ e_passwd +"'>";
	document.getElementById('name_'+ id).innerHTML	 = "<input type='text' id='uname' value='"+ e_name +"'>";
	document.getElementById('surname_'+ id).innerHTML= "<input type='text' id='usurname' value='"+ e_surname +"' />";
	document.getElementById('actions_'+ id).innerHTML= "<img class='action_button' src='/images/save.png' alt='Save' title='Save' onclick='javascript:updateUser(\"" + id + "\");' />";

}

function updateUser(id){
	var xmlhttp=false; //Clear our fetching variable

	u_login   = document.getElementById("ulogin").value;
	u_passwd  = document.getElementById("upasswd").value;
	u_name    = document.getElementById("uname").value;
	u_surname = document.getElementById("usurname").value;

	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();
	}

	var file = '/admin/updateUser.asp?id='+ id +'&login='+ u_login +'&passwd=' + u_passwd + '&name=' + u_name + '&surname=' + u_surname;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}

function chooseOptions(field,value){
	var xmlhttp=false; //Clear our fetching variable

	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();
	}

//	var file = '/admin/chooseOptions.asp?field='+ field +'&valor=' + value;
//	xmlhttp.open('GET', file, true);


        var file = '/admin/chooseOptions.asp';
        var parameters = 'field='+ field +'&valor=' + value;
        xmlhttp.open('POST', file , true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-Length",parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");



	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			switch (field){
				case "fzone":
					select_innerHTML(document.getElementById('fcity'),content);
					break;
				case "fcity":
					select_innerHTML(document.getElementById('fneighbor'),content);
					break;				
				case "acounty":
					select_innerHTML(document.getElementById('acounty'),content);
					select_innerHTML(document.getElementById('azone'),'<option>Ninguno disponible</option>');
					select_innerHTML(document.getElementById('acity'),'<option>Ninguno disponible</option>');
					select_innerHTML(document.getElementById('aneighbor'),'<option>Ninguno disponible</option>');
					document.getElementById('acounty').selectedIndex = 23;
					chooseOptions("azone",24);
					break;
				case "azone":
					select_innerHTML(document.getElementById('azone'),content);
					select_innerHTML(document.getElementById('acity'),'<option>Ninguno disponible</option>');
					select_innerHTML(document.getElementById('aneighbor'),'<option>Ninguno disponible</option>');
					break;
				case "acity":
					select_innerHTML(document.getElementById('acity'),content);
					select_innerHTML(document.getElementById('aneighbor'),'<option>Ninguno disponible</option>');
					break;
				case "aneighbor":
					select_innerHTML(document.getElementById('aneighbor'),content);
					break;
				// New options
				case "zone":
					select_innerHTML(document.getElementById('ciudad'),content);
					break;
				case "ciudad":
					select_innerHTML(document.getElementById('barrio'),content);
					break;				
				case "barrio":
					select_innerHTML(document.getElementById('barrio'),content);
					break;
			}
		}
	}
	xmlhttp.send(parameters);
	return;	
}

function adminSearch(place){
	document.getElementById('loading-gif').style.display = 'inline';

	var xmlhttp=false; //Clear our fetching variable

	zona = document.getElementById("fzone").value;
	if(trim(zona) == ""){
		zona = "0";
	}

	ciudad = document.getElementById("fcity").value;
	if(trim(ciudad) == ""){
		ciudad = "0";
	}

	barrio = document.getElementById("fneighbor").value;
	if(trim(barrio) == ""){
		barrio = "0";
	}

	tipo = document.getElementById("ftype").value;
	if(trim(tipo) == ""){
		tipo = "0";
	}

	if(place == "pref_profile"){
		preciomin = document.getElementById("minprice").value;
		preciomax = document.getElementById("maxprice").value;
		if (trim(preciomin) == ""){
			preciomin = 0;
		}
		if (trim(preciomax) == ""){
			preciomax = 0;
		}

		params = '&minpvp='+ preciomin +'&maxpvp='+ preciomax;
	}else{
		fhabitaciones = document.getElementById("frooms").value;
		fsuperficie   = document.getElementById("fsurface").value;
		fterrasses    = document.getElementById("terrazes").value;
		carrer	   = document.getElementById("streetID").value;
		showpub    = document.getElementById("show_published").checked;
		shownotpub = document.getElementById("show_not_published").checked;
		params = '&sp='+ showpub +'&snp='+ shownotpub +'&habs='+ trim(fhabitaciones) +'&superficie='+ trim(fsuperficie) +'&terrasses='+ fterrasses +'&calle='+ carrer;
	}

	estado = document.getElementById('status').value;

	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();
	}

	var file = '/admin/search.asp?zone='+ zona +'&city=' + ciudad +'&neighbor='+ barrio +'&tipo='+ tipo +'&place='+ place +'&status='+ estado + params;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if(place == ""){
				document.getElementById('results').innerHTML = "<fieldset style='text-align: left;'><legend>Resultados de la búsqueda</legend><table width='100%'>"+ content +"</table></fieldset>";
			}else{
				document.getElementById('results').innerHTML = "<table width='96%'>"+ content + "</table>";
			}
			document.getElementById('loading-gif').style.display = 'none';
		}
	}
	xmlhttp.send(null);
	return;	
}

function searchByRef(){
	var ref = trim(document.getElementById('search_ref').value);
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/search.asp?reference='+ ref +'&place=undefined';

	xmlhttp.open('GET',file, true);

	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('results').innerHTML = "<fieldset><legend>Resultados de la búsqueda</legend><table width='100%'>"+ content +"</table></fieldset>";
		}
	}
	xmlhttp.send(null);
	return;	
}


function newProperty(){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/newProperty.asp';
	var parameters = '';
	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	

	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('results').innerHTML = "<fieldset><legend class='titulo'>Nuevo inmueble:</legend>"+ content +"</fieldset>";
		}
	}	
	xmlhttp.send(parameters);
	return;	
}


function loadProperty(id){
	document.getElementById('results').innerHTML = "";

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/details.asp';
	var parameters = 'id='+ id;
	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	

	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('results').innerHTML = "<fieldset><legend class='titulo'>Detalles del inmueble:</legend>"+ content +"</fieldset>";
		}
	}	
	xmlhttp.send(parameters);
	return;	
}


function saveChanges(id,force){

	if ( force == null) {
		force = false;
	}

	pub	    = document.getElementById('published').checked;
	zona        = document.getElementById('zone').value;

	indice	    = document.getElementById('status_inmueble').selectedIndex;
	estado      = document.getElementById('status_inmueble').options[indice].value;

	ciutat      = document.getElementById('ciudad').value;
	barriada    = document.getElementById('barrio').value;
//	tipov       = document.getElementById('tipo').value;
	pvp         = document.getElementById('precio').value;
	antic       = document.getElementById('antiguedad').value;
	rooms       = document.getElementById('nhabitaciones').value;
	supsolar    = document.getElementById('sup_solar').value;
	suputil     = document.getElementById('sup_util').value;
	supconst    = document.getElementById('sup_const').value;	
	floors      = document.getElementById('plantas').value;
	terraces    = document.getElementById('terrazas').value;
	supterrazas = document.getElementById('sup_terrazas').value;
	salones     = document.getElementById('salas').value;
	comedores   = document.getElementById('comedor').value;
	gastoscom   = document.getElementById('gastos_com').value;
	cocinas     = document.getElementById('cocina').value;
	lavabos     = document.getElementById('banyos').value;
	aseoss      = document.getElementById('aseos').value;
	garagec     = document.getElementById('garage_c').value;
	garaged     = document.getElementById('garage_d').value;


// 	Nuevos campos añadidos (calle, puert, numero, piso, etc)
	carrer	    = document.getElementById('calle').value;

	if(trim(carrer) == ""){
		alert("Debe introducir el nombre de la calle del inmueble.");
		return;
	}

	nombre	    = document.getElementById('num_calle').value;
	escala	    = document.getElementById('escalera').value;
	pis	    = document.getElementById('piso').value;
	porta	    = document.getElementById('puerta').value;

	subtipus    = document.getElementById('subtipo').value;


	if(id != "new"){
		anuncio_txt = document.getElementById('anuncio').value;
	}else{
		anuncio_txt = "";
	}
	


	var press = "";
	for(i=0;i<document.getElementsByName('check_press').length;i++){
		if(document.getElementsByName('check_press')[i].checked){
			press+= ','+ document.getElementsByName('check_press')[i].value;
		}
	}
	press = press.substring(1);

	//Picking up Languages
	var comments = "";
	langs_number = document.getElementById('nlangs').value;
	for(i=1;i<=langs_number;i++){
		text  = document.getElementById('comment_'+ i).value;
		lcode = document.getElementById('comment_'+ i).name;
		comments+= "&comment_"+ lcode +"="+ encodeURIComponent(text.replace('\n', '<br />\n'));
	}

	//Is there any image?
	if(document.getElementsByName('def_image').length >= 1){
		for(i=0; i<document.getElementsByName('def_image').length; i++){
			if (document.getElementsByName('def_image')[i].checked){
					defImage = document.getElementsByName('def_image')[i].value;
			}
		}
		if(window.defImage === undefined){
			// If none of them was checked then the first is checked
			defImage = document.getElementsByName('def_image')[0].value;
		}
	}else{
		defImage = "null";
	}

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var parameters = 'id='+ encodeURIComponent(id);
	parameters+= '&calle='+ carrer;
	parameters+= '&num='+ nombre;
	parameters+= '&escalera='+ escala;
	parameters+= '&piso='+ pis;
	parameters+= '&puerta='+ porta;
	parameters+= '&subtipo='+ subtipus;
	parameters+= '&ciudad='+ encodeURIComponent(ciutat);
	parameters+= '&barrio='+ encodeURIComponent(barriada);
//	parameters+= '&tipo='+ encodeURIComponent(tipov);
	parameters+= '&precio='+ encodeURIComponent(pvp);
	parameters+= '&edad='+ encodeURIComponent(antic);
	parameters+= '&habitaciones='+ encodeURIComponent(rooms);
	parameters+= '&supsolar='+ encodeURIComponent(supsolar);
	parameters+= '&suputil='+ encodeURIComponent(suputil);
	parameters+= '&supconst='+ encodeURIComponent(supconst);
	parameters+= '&plantas='+ encodeURIComponent(floors);
	parameters+= '&terrazas='+ encodeURIComponent(terraces);
	parameters+= '&supterrazas='+ encodeURIComponent(supterrazas);
	parameters+= '&salas='+ encodeURIComponent(salones);
	parameters+= '&comedor='+ encodeURIComponent(comedores);
	parameters+= '&gastoscom='+ encodeURIComponent(gastoscom);
	parameters+= '&cocina='+ encodeURIComponent(cocinas);
	parameters+= '&banyos='+ encodeURIComponent(lavabos);
	parameters+= '&aseos='+ encodeURIComponent(aseoss);
	parameters+= '&garage_c='+ encodeURIComponent(garagec);
	parameters+= '&garage_d='+ encodeURIComponent(garaged);
	parameters+= '&published='+ encodeURIComponent(pub);
	parameters+= '&defImage='+ encodeURIComponent(defImage);
	parameters+= '&press='+ encodeURIComponent(press);
	parameters+= '&anuncio='+ encodeURIComponent(anuncio_txt);
	parameters+= '&forzar='+ force;
	parameters+= '&status='+ estado;
	parameters+= comments;


	var file = '/admin/saveProperty.asp';

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if (content.indexOf(":") < 0)  {
				// TOT OK!
				alert("Datos guardados");
				if(id == "new"){
					loadProperty(content);
				}else{
					loadProperty(id);
				}
				document.getElementById("disableScreen").style.display = 'none';
				setSelectsDisplay("inline");
			}else{
				// Tenim duplicats
				if (trim(content.substring(4)) != "") {
					list4Ref(content.substring(4));
				} 

				/*if(confirm(content + "\n¿Está seguro de continuar?")){
					saveChanges(id,"true");
				} */
			}
		}
	}
	xmlhttp.send(parameters);
	return;	
}


function sendAds(press){
	document.getElementById('mail_'+press).src = "/images/loading.gif";
	document.getElementById('mail_'+press).className = "";
	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/sendAds.asp?press='+ press;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('mail_'+press).src = "/images/success.png";
		}
	}
	xmlhttp.send(null);
	return;	
}


function delProperty(id){
	if (confirm("¿Está seguro de querer borrar este elemento?")){
		var xmlhttp=false; //Clear our fetching variable
		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();
		}
		var file = '/admin/delProperty.asp?id='+ id;

		xmlhttp.open('GET', file, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var content = xmlhttp.responseText;
				adminSearch();
			}
		}
		xmlhttp.send(null);
	}
	return;	
}



function pickFiles(id,ftype){
	document.getElementById('property_files').innerHTML = "";

	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/pickFiles.asp';
	var parameters = 'id='+ encodeURIComponent(id);
	    parameters+= '&filetype='+ encodeURIComponent(ftype);

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if(ftype == "imagenes"){
				document.getElementById('property_files').innerHTML = content;
			}else{
				document.getElementById('property_docs').innerHTML = content;
			}
		}
	}
	xmlhttp.send(parameters);
	return;	
}

function delFile(fileID,inmuID){
	document.getElementById('property_files').innerHTML = "";

	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/delFile.asp?id='+ fileID;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			pickFiles(inmuID,'imagenes');
			pickFiles(inmuID,'docs');
		}
	}
	xmlhttp.send(null);
	return;	
}

function pickSublevels(level,parent_id){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/pickSublevels.asp?level='+ level +'&id='+ parent_id;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById(level +'_'+ parent_id).innerHTML = content;
		}
	}
	xmlhttp.send(null);
	return;	
}


function addElement(type,value){
	switch (type){
		case "country":
			parent_element = 'null';
			break;
		case "county":
			if(document.getElementById('acountry').value == ""){
				alert('Debe seleccionar primero el país al que quiere agregar la región.');
				return;
			}else{
				parent_element = document.getElementById('acountry').value;
			}
			break;
		case "zone":
			if(document.getElementById('acounty').value == ""){
				alert('Debe seleccionar primero la región a la que quiere agregar la zona.');
				return;
			}else{
				parent_element = document.getElementById('acounty').value;
			}
			break;
		case "city":
			if(document.getElementById('azone').value == ""){
				alert('Debe seleccionar primero la zona a la que quiere agregar la ciudad.');
				return;
			}else{
				parent_element = document.getElementById('azone').value;
			}
			break;
		case "neighbor":
			if(document.getElementById('acity').value == ""){
				alert('Debe seleccionar primero la ciudad a la que quiere agregar el barrio.');
				return;
			}else{
				parent_element = document.getElementById('acity').value;
			}
			break;
	}

	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/addLevel.asp?level='+ type +'&parent='+ parent_element +'&nlevel='+ value;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('n'+ type).value = '';
			chooseOptions('a'+type,parent_element);
		}
	}
	xmlhttp.send(null);
	return;	
}


function delElement(type){
	if ((document.getElementById('a'+ type).value == "")||(document.getElementById('a'+ type).value == "0")){
		alert("Por favor seleccione un elemento del a lista.");
		return;
	}else{
		if(!confirm("ATENCIÓN! Está a punto de eliminar el elemento "+ document.getElementById('a'+ type).options[document.getElementById('a'+ type).selectedIndex].text + " y todos los elementos que éste contiene.\nDesea continuar?")){
			return;
		}
		switch (type){
			case "country":
				parent_element = 'null';
				break;
			case "county":
				parent_element = document.getElementById('acountry').value;
				break;
			case "zone":
				parent_element = document.getElementById('acounty').value;
				break;
			case "city":
				parent_element = document.getElementById('azone').value;
				break;
			case "neighbor":
				parent_element = document.getElementById('acity').value;
				break;
		}

		var xmlhttp=false; //Clear our fetching variable
		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();
		}
		var file = '/admin/delLevel.asp?type='+ type +'&level='+ document.getElementById('a'+ type).value;
		xmlhttp.open('GET', file, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var content = xmlhttp.responseText;

				chooseOptions('a'+type,parent_element);
			}
		}
		xmlhttp.send(null);
		return;	
	}
}

function auth(){
	usuario = document.getElementById('authuser').value;
	passwd  = document.getElementById('authpass').value;


	var xmlhttp=false; //Clear our fetching variable
	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();
	}


	var file = '/admin/login.asp';
	var parameters = 'user='+ encodeURIComponent(usuario) + '&pass=' + encodeURIComponent(passwd);

	xmlhttp.open('POST', file, true);

        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	

	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			switch (content){
				case "KO":
					alert("Usuario y/o contraseña incorrectos.");
					break;
				case "OK":
					window.location.href = "admin.asp?opt=properties";
			}
		}
	}
	xmlhttp.send(parameters);
	return;	

}

function saveType(id){
	eval("name_es = document.getElementById('type_"+ id + "_es').value");
	eval("name_en = document.getElementById('type_"+ id + "_en').value");
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/saveType.asp?id='+ id +'&nes='+ encodeURIComponent(name_es) + '&nen='+ encodeURIComponent(name_en);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}

function saveSubType(id){
	eval("name_es = document.getElementById('type_"+ id + "_es').value");
	eval("name_en = document.getElementById('type_"+ id + "_en').value");
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/saveSubType.asp?id='+ id +'&nes='+ encodeURIComponent(name_es) + '&nen='+ encodeURIComponent(name_en);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}


function delType(id){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/delType.asp?id='+ id;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();			
		}
	}
	xmlhttp.send(null);
	return;	
}


function delSubType(id){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/delSubType.asp?id='+ id;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();			
		}
	}
	xmlhttp.send(null);
	return;	
}

function addType(){
	tipoes = document.getElementById('newType_es').value;
	tipoen = document.getElementById('newType_en').value;
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/addType.asp?nes='+ encodeURIComponent(tipoes) + "&nen="+ encodeURIComponent(tipoen);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();			
		}
	}
	xmlhttp.send(null);
	return;	
}


function addSubType(){
	subtipoes   = document.getElementById('newSubType_es').value;
	subtipoen   = document.getElementById('newSubType_en').value;
	subtipoTipo = document.getElementById('newSubType_type').value;

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/addSubType.asp?nes='+ encodeURIComponent(subtipoes) + "&nen="+ encodeURIComponent(subtipoen) + '&type='+ encodeURIComponent(subtipoTipo);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();			
		}
	}
	xmlhttp.send(null);
	return;	
}


function delPress(id){
	if(confirm("¿Está seguro de que desea eliminar este medio de prensa?")){
		var xmlhttp=false; //Clear our fetching variable
		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();
		}
	
		var file = '/admin/delPress.asp?id='+ id;
	
		xmlhttp.open('GET', file, true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var content = xmlhttp.responseText;
				window.location.reload();			
			}
		}
		xmlhttp.send(null);
		return;
	}else{
		return;
	}
}


function addPress(){
	press_name    = document.getElementById('press_name').value;
	press_address = document.getElementById('press_address').value;
	press_contact = document.getElementById('press_contact').value;
	press_phone   = document.getElementById('press_phone').value;
	press_fax     =	document.getElementById('press_fax').value;
	press_email   = document.getElementById('press_email').value;
//	press_method  = document.getElementById('press_method').value;
	press_method  = "";	

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/addPress.asp?name='+ encodeURIComponent(press_name) +'&address='+ encodeURIComponent(press_address);
	    file+= '&contact='+ press_contact +'&phone='+ encodeURIComponent(press_phone) +'&fax='+ encodeURIComponent(press_fax);
	    file+= '&email='+ encodeURIComponent(press_email) +'&method='+ encodeURIComponent(press_method);
//	alert(file);
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
//			alert(content);
			window.location.reload();			
		}
	}
	xmlhttp.send(null);
	return;	
}

function searchByPress(id){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/searchByPress.asp?pressID='+ encodeURIComponent(id);
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('inmu-list-'+ id).innerHTML = "<table width='730'>"+ content +"</table>";
		}
	}
	xmlhttp.send(null);
	return;	
}

function deleteSuscription(inmu,press){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/delSuscription.asp?pressID='+ press + '&inmu='+ inmu;
	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			searchByPress(press);
		}
	}
	xmlhttp.send(null);
	return;	
}


function savePress(id){

	eval("press_address = document.getElementById('"+ id +"_address').value");
	eval("press_contact = document.getElementById('"+ id +"_contact').value");
	eval("press_phone   = document.getElementById('"+ id +"_phone').value");
	eval("press_fax     = document.getElementById('"+ id +"_fax').value");
	eval("press_email   = document.getElementById('"+ id +"_email').value");
//	eval("press_method  = document.getElementById('"+ id +"_method').value");

	press_method = "";

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/savePress.asp?id='+ encodeURIComponent(id) +'&address='+ encodeURIComponent(press_address);
	    file+= '&contact='+ press_contact +'&phone='+ encodeURIComponent(press_phone) +'&fax='+ encodeURIComponent(press_fax);
	    file+= '&email='+ encodeURIComponent(press_email) +'&method='+ encodeURIComponent(press_method);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.location.reload();
		}
	}
	xmlhttp.send(null);
	return;	
}

function showSchedule(udate,user){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/schedule.asp?date='+ encodeURIComponent(udate) + "&user="+ user;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('calendar_panel').innerHTML = content;
			document.getElementById('schedule').scrollTop = 200;
		}
	}
	xmlhttp.send(null);
	return;	
}


function showhidePropertylink(id){
	eval("valor = document.getElementById('type_"+ id + "').value");
	if(valor != "Visita"){
		eval("document.getElementById('property_"+ id + "').disabled = true");
	}else{
		eval("document.getElementById('property_"+ id + "').disabled = false");
	}
}


function addTask(user,udate,utime){
	str_hora = utime.split(':');

	reference = document.getElementById("original_ref").value;

		var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/viewTask.asp?ref='+ reference + '&dia='+ udate + '&hora='+ utime +'&user='+ user;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			eval("document.getElementById('task_"+ utime +"').innerHTML = content");
		}
	}
	xmlhttp.send(null);
	return;
}

function saveTask(user,udate,utime,force){
	
	if (force == null){
		force = 0;
	}

	eval("titulo = document.getElementById('title_"+ utime +"').value");
	eval("tipo   = document.getElementById('type_"+ utime +"').value");
	eval("hora   = document.getElementById('hour_"+ utime +"').value");
	eval("desc   = document.getElementById('desc_"+ utime +"').value");
	eval("ref    = document.getElementById('property_"+ utime +"').value");
	eval("cliente= document.getElementById('client_id_"+ utime +"').value");
	eval("cliente_str= document.getElementById('client_name_"+ utime +"').value");
	eval("tlf    = document.getElementById('phone_"+ utime +"').value");
	eval("viacap  = document.getElementById('captacion_"+ utime +"').value");
	eval("newcustomer = document.getElementById('isnewcustomer_"+ utime +"').value");

/*	if (trim(ref)!= ""){
		titulo = "Ref. "+ ref +" - "+ titulo;
	} */

	if ((tipo != "Personal") & (ref == "")){
		alert("Es necesario introducir una referencia de inmueble.");
		eval("document.getElementById('property_"+ utime +"').focus()");
		return;
		
	}


	if ((tipo == "Visita") & (trim(tlf) == "")){
		alert("Es necesario introducir el teléfono del cliente");
		eval("document.getElementById('phone_"+ utime +"').focus()");
		return;
		
	}	

	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/saveTask.asp';
	var parameters = 'title=' + encodeURIComponent(titulo);
	    parameters+= '&user='+ encodeURIComponent(user) +'&date='+ encodeURIComponent(udate);
	    parameters+= '&time='+ encodeURIComponent(hora) +'&length=0.5&reference='+ encodeURIComponent(ref);
	    parameters+= '&description='+ encodeURIComponent(desc) +'&type='+ encodeURIComponent(tipo);
	    parameters+= '&force='+ force +'&cliente='+ cliente +'&telefono=' + encodeURIComponent(tlf) +'&cliente_name=' + encodeURIComponent(cliente_str) +'&captadovia='+ viacap +'&isnewcustomer='+ newcustomer;

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if (trim(content) == "KO"){
				if(confirm("Ya hay un usuario o más con visitas programadas ese inmueble ese día.\nEstá seguro de que quiere seguir?")){
					saveTask(user,udate,utime,'1');
				}else{
					return;
				}
			}else{
				showSchedule(udate,user);
			}
		}
	}
	xmlhttp.send(parameters);
	return;	
}

function showTask(id,utime){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/showTask.asp?id='+ id;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			eval("document.getElementById('task_"+ id +"').innerHTML = content");
		}
	}
	xmlhttp.send(null);
	return;	
}

function checkTaskType(id){
	if (document.getElementById('type_'+ id).value == 'Captación') {
		document.getElementById('title_'+ id).value = "";
		document.getElementById('property_'+ id).value = "Captación";
		document.getElementById('title_'+ id).readOnly = false;
	}else{
		document.getElementById('title_'+ id).readOnly = true;
	}
}

function returnBack(task_id,task_name,task_starttime){
	html_text = "<a href='#' style='color: #FFFFFF; font-weight: bold; text-decoration: none;' onclick=\"javascript:showTask('"+ task_id +"','"+ task_starttime +"')\"><i>"+ task_starttime +" - "+ task_name +"</i></a>";
	eval("document.getElementById('task_"+ task_id +"').innerHTML = html_text");
}

function updateTask(taskID,user,udate,utime){
	eval("titulo = document.getElementById('title_"+ taskID +"').value");
	eval("tipo   = document.getElementById('type_"+ taskID +"').value");
	eval("hora   = document.getElementById('hour_"+ taskID +"').value");
	eval("desc   = document.getElementById('desc_"+ taskID +"').value");
	eval("ref    = document.getElementById('property_"+ taskID +"').value");
	eval("cliente= document.getElementById('client_id_"+ taskID +"').value");	
	eval("cliente_str= document.getElementById('client_name_"+ taskID +"').value");	
	eval("tlf    = document.getElementById('phone_"+ taskID +"').value");

        if ((trim(tipo) == "Visita") & (trim(ref) == " ")){
                alert("Es necesario introducir una referencia de inmueble.");
                eval("document.getElementById('property_"+ taskID +"').focus()");
                return;

        }


/*      if (trim(ref)!= ""){
		titulo = "Ref. "+ ref +" - "+ titulo;
	} */


	var xmlhttp=false; //Clear our fetching variable
	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();
	}
	var file = '/admin/saveTask.asp';
	var parameters = 'id=' + encodeURIComponent(taskID);
	    parameters+= '&title=' + encodeURIComponent(titulo);
	    parameters+= '&date='+ encodeURIComponent(udate);
	    parameters+= '&time='+ encodeURIComponent(hora) +'&length=0.5&reference='+ ref +'&cliente_name='+ encodeURIComponent(cliente_str);
	    parameters+= '&description='+ encodeURIComponent(desc) +'&type='+ encodeURIComponent(tipo) +'&cliente='+ cliente +'&telefono=' + encodeURIComponent(tlf);

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;	
			showSchedule(udate,user);
		}
	}
	xmlhttp.send(parameters);
	return;	
}


function delTask(id,user,udate){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/delTask.asp?id='+ id;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			showSchedule(udate,user);
		}
	}
	xmlhttp.send(null);
	return;	
}

var actual_size = 0;

function slideDiv(id,content){
	text = content;
	if(actual_size < 250){
		actual_size += 20;
		eval("document.getElementById('"+ id +"').style.height = '"+ actual_size +"px';");
		setTimeout("slideDiv('"+ id +"',text);",5);
	}else{
		eval("document.getElementById('"+ id +"').innerHTML = content");
	}
}


function searchCustomer(){
	fsurname = document.getElementById('search_surname1').value;
	ssurname = document.getElementById('search_surname2').value;
	name = document.getElementById('search_name').value;

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/searchCustomer.asp?name='+encodeURIComponent(name) +'&surname1='+ encodeURIComponent(fsurname) +'&surname2='+ encodeURIComponent(ssurname);

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('search_results').innerHTML = content;
		}
	}
	xmlhttp.send(null);
	return;	
}

function showCustomer(customerID){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/showCustomer.asp?cid='+ customerID;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('customer_file').innerHTML = '';
			document.getElementById('customer_file').style.display= 'block';
			slideDiv('customer_file',content);
		}
	}
	xmlhttp.send(null);
	return;	
}

function delCustomer(id) {
	if(confirm("Está seguro de querer eliminar este cliente?")) {
		var xmlhttp=false; //Clear our fetching variable
		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();
		}

		var file = '/admin/delCustomer.asp';
		var parameters = 'userID='+ id;
		xmlhttp.open('POST', file, true);
		xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlhttp.setRequestHeader("Content-length", parameters.length);
		xmlhttp.setRequestHeader("Connection", "close");
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var content = xmlhttp.responseText;
				window.location.reload();
				/*
				document.getElementById('customer_file').style.display='none';
				document.getElementById('customer_file').innerHTML='';
				actual_size=0; */
			}
		}
		xmlhttp.send(parameters);
		return;
	}

}


function saveCustomerData(id){
	name     = document.getElementById('name_'+ id).value;
	fsurname = document.getElementById('fsurname_'+ id).value;
	ssurname = document.getElementById('ssurname_'+ id).value;
	fphone   = document.getElementById('fphone_'+ id).value;
	sphone   = document.getElementById('sphone_'+ id).value;
	fax	 = document.getElementById('fax_'+ id).value;
	email    = document.getElementById('email_'+ id).value;
	address  = document.getElementById('address_'+ id).value;
	pobox	 = document.getElementById('pc_'+ id).value;
	proc	 = document.getElementById('procedencia_'+ id).value;


	if(id != "new"){
		suscription = document.getElementById('suscribed_'+id).checked;
		comercial= document.getElementById('rcomercial_'+ id).value;
	}else{
		suscription = true;
		comercial = "";
	}

	if(suscription){
		suscription = "on"
	}else{
		suscription = "off"
	}


	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/saveCustomerData.asp?';

	var parameters = 'cid='+ id + '&name='+ encodeURIComponent(name) + '&fsurname='+ encodeURIComponent(fsurname) +'&ssurname='+ encodeURIComponent(ssurname);
	parameters+= '&fphone='+ encodeURIComponent(fphone) + '&sphone='+ encodeURIComponent(sphone) + '&fax='+ encodeURIComponent(fax) +'&proc='+  encodeURIComponent(proc)+'&comercial='+  encodeURIComponent(comercial);
	parameters+= '&email='+ encodeURIComponent(email) + '&address='+ encodeURIComponent(address) + '&pobox='+ encodeURIComponent(pobox) + '&suscribed='+ encodeURIComponent(suscription);

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if(id == 'new'){
				window.location.reload();
			}else{
				document.getElementById('customer_file').innerHTML = '';
				document.getElementById('customer_file').style.height = '0px';
				document.getElementById('customer_file').style.display = 'none';
			       	actual_size=0;
			}
		}
	}
	xmlhttp.send(parameters);
	return;	
}

function linkSearch2User(customerID){
	nombre = document.getElementById("profile_name").value;
	
	if(trim(nombre) == ""){
		alert("Debe asignar un nombre a la búsqueda.\nPor ejemplo: 'Piso en Palma'");
		document.getElementById("profile_name").focus();
		return;
	}

	zona = document.getElementById("fzone").value;
	if(trim(zona) == ""){
		zona = "0";
	}

	ciudad = document.getElementById("fcity").value;
	if(trim(ciudad) == ""){
		ciudad = "0";
	}

	barrio = document.getElementById("fneighbor").value;
	if(trim(barrio) == ""){
		barrio = "0";
	}

	tipo = document.getElementById("ftype").value;
	if(trim(tipo) == ""){
		tipo = "0";
		subtipo = "0";
	}else{
	//	subtipo = document.getElementById('fsubtype').value;
	//	if(trim(subtipo) == ""){
	//		subtipo = "0";
	//	}
		if (trim(tipo).indexOf("-") > 0){
			tmp = tipo.split("-");
			tipo = tmp[1];
			subtipo = 0;	
		}
	}


	preciomin = document.getElementById("minprice").value;
	preciomax = document.getElementById("maxprice").value;
	habs      = document.getElementById("rooms").value;
	if (trim(preciomin) == ""){
		preciomin = 0;
	}
	if (trim(preciomax) == ""){
		preciomax = 0;
	}

	estado = document.getElementById("status").value;

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/linkSearch2User.asp?customer='+ customerID +'&name='+ nombre;
	params = '&zone='+ zona +'&city='+ ciudad +'&neighborhood='+ barrio +'&ptype='+ tipo +'&psubtype='+ subtipo +'&maxprice='+ preciomax +'&minprice='+ preciomin +'&habitaciones='+ habs +'&status='+ estado ;

//	alert(estado);

	xmlhttp.open('GET', file + params, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.opener.showCustomer(customerID);
			window.close();
		}
	}
	xmlhttp.send(null);
	return;		
}

function deleteUserPref(idPref,customerID){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/delUserPref.asp?id='+ idPref ;

	xmlhttp.open('GET', file , true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			window.opener.showCustomer(customerID);
			window.close();
		}
	}
	xmlhttp.send(null);
	return;		
}

function sendPromoMail(customer){
	if (customer != ""){
		document.getElementById('mail_action').innerHTML = "<span style='vertical-align: middle;'>Enviando e-mail...</span> <img style='vertical-align: middle;' src='/images/loading.gif' alt='Trying to send the e-mail...' title='loading...' />";
	}else{
		if(!confirm('Este proceso enviará un correo a todos los clientes existentes en la base de datos.\n¿Está seguro de que quiere continuar?')){
			return;		
		}
		document.getElementById('mailbombing').innerHTML = "<span style='vertical-align: middle;'>Enviando correos...</span> <img style='vertical-align: middle;' src='/images/loading.gif' alt='Trying to send the e-mail...' title='loading...' />"
	}

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/mailSending.asp?customerid='+ customer;

	xmlhttp.open('GET', file, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if (customer != ""){
				document.getElementById('mail_action').innerHTML = "<span style='vertical-align: middle;'>E-mail enviado con éxito!</span> <img style='vertical-align: middle;' src='/images/success.png' alt='E-mail enviado con éxito' title='Exito' />";
			}else{
				document.getElementById('mailbombing').innerHTML = "<span style='vertical-align: middle;'>Proceso realizado!</span> <img style='vertical-align: middle;' src='/images/success.png' alt='E-mail enviado con éxito' title='Exito' />";
			}
		}
	}
	xmlhttp.send(null);
	return;		
}

function saveAction() {
	inmuID = document.getElementById('inmu_id').value;
	client = document.getElementById('cliente').value;
	phone  = document.getElementById('tlf').value;
	data   = document.getElementById('fecha').value;
	accio  = document.getElementById('accion').value;
	coment = document.getElementById('comentarios').value;
	agent  = document.getElementById('comercial-agent').value;



        var xmlhttp=false; //Clear our fetching variable
        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();
        }

        var parameters = 'id='+ encodeURIComponent(inmuID);
        parameters+= '&cliente='+ encodeURIComponent(client);
        parameters+= '&fecha='+ encodeURIComponent(data);
        parameters+= '&accion='+ encodeURIComponent(accio);
        parameters+= '&comentario='+ encodeURIComponent(coment);
	parameters+= '&agent='+ encodeURIComponent(agent);
	parameters+= '&phone='+ encodeURIComponent(phone);

        var file = '/admin/saveAction.asp';

        xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");
        xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4) {
                        var content = xmlhttp.responseText;
			showContent(inmuID);
                }
        }
        xmlhttp.send(parameters);
        return;
	
}


function showContent(id){
	document.getElementById('property_info').innerHTML = "";
	if (document.getElementById('s1').className == 'solapa_activa'){
		page = 'property.asp';
	}else{
		if (document.getElementById('s2').className == 'solapa_activa'){
			page = 'int_property.asp';
		}else{
			page = 'traspasos.asp';
		}
	}

	
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var file = '/admin/'+ page ;

	parameters = 'id='+ id;
	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById('property_info').innerHTML = content;
		}
	}
	xmlhttp.send(parameters);
	return;		
}


function viewAD(id){
	window.open('editAD.asp?id='+ id,'','width=300, height=200, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no');
	return;		
}


function contact(reference) {
	window.open('triasemail.asp?ref='+ reference,'','width=500, height=400, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no');
	return;
}


function saveIntChanges(id){
	honoraris   = document.getElementById('honorarios').value;
	comer       = document.getElementById('comercial').value;
	captadr     = document.getElementById('captador').value;
	comisio     = document.getElementById('comision').value;
	propietario = document.getElementById('propietari').value;
	contacto    = document.getElementById('contacte').value;
	mail	    = document.getElementById('correu-e').value;
	comments_txt= document.getElementById('comments').value;


	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	var parameters = 'id='+ encodeURIComponent(id);
	parameters+= '&honorarios='+ encodeURIComponent(honoraris);
	parameters+= '&comercial='+ encodeURIComponent(comer);
	parameters+= '&captador='+ encodeURIComponent(captadr);
	parameters+= '&comision='+ encodeURIComponent(comisio);
	parameters+= '&propietari='+ encodeURIComponent(propietario);
	parameters+= '&contacto='+ encodeURIComponent(contacto);
	parameters+= '&comments='+ encodeURIComponent(comments_txt);
	parameters+= '&correo='+ encodeURIComponent(mail);

	var file = '/admin/saveIntData.asp';

	xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			alert("Datos guardados");
		}
	}
	xmlhttp.send(parameters);
	return;	
}

function showZoneSelects(area,zone_id){
	if (zone_id != 0){
		if (document.getElementById('zone_area').innerHTML.indexOf('-') > 0){

			indice = document.getElementById('city').selectedIndex;
			content = document.getElementById('zone_area').innerHTML.substring(0,document.getElementById('zone_area').innerHTML.indexOf('-'));
			document.getElementById('zone_area').innerHTML = content;
		}else{
			if(document.getElementById('zone_area').innerHTML != "&nbsp;"){
				indice = document.getElementById('city').selectedIndex;
			}
		}

		var xmlhttp=false; //Clear our fetching variable
		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();
		}
	
		var file = '/admin/returnselect.asp?area='+ area +'&zone='+ zone_id ;
	
		xmlhttp.open('GET', file , true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				var content = xmlhttp.responseText;

				if(area == "zone"){
					indice = document.getElementById('zone').selectedIndex;
					document.getElementById('zone_area').innerHTML = content;
					document.getElementById('zone').selectedIndex = indice;
				}else{
					if (indice == "undefined"){
						indice = document.getElementById('city').selectedIndex;
					}

					document.getElementById('zone_area').innerHTML = document.getElementById('zone_area').innerHTML +" - "+ content;
					document.getElementById('city').selectedIndex = indice;
				}	
			}
		}
		xmlhttp.send(null);		
		return;
	}else{
		if (document.getElementById('zone_area').innerHTML.indexOf('-') > 0){
			content = document.getElementById('zone_area').innerHTML.substring(0,document.getElementById('zone_area').innerHTML.indexOf('-'));
			document.getElementById('zone_area').innerHTML = content;
		}else{
			document.getElementById('zone_area').innerHTML = "&nbsp;";		
		}
	}
}


function loadImage(tmp){
	carpeta = document.getElementById('folder').value;
	img = document.getElementById('current').value;
	

	max = document.getElementById('maximg').value;

	if(tmp == "next"){
		eval("goal ="+ img +"+ 1");
	}else{
		eval("goal ="+ img +"- 1");
	}

	if(goal<1){
		goal = max;
	}else if(goal>max){
		goal = 1;
	}

	file = document.getElementById('img-'+ goal).alt;
	document.getElementById('bigImage').src= '/files/'+ carpeta +"/"+ file;
	document.getElementById('current').value = goal;
}

function showMoneyFields(which){
	switch (which){	
		case "null":
			document.getElementById('moneyFields').innerHTML = "&nbsp;";
			break;
		case ">=":
			document.getElementById('moneyFields').innerHTML = "<input type='text' name='price' value='' />";
			break;		
		case "<=":
			document.getElementById('moneyFields').innerHTML = "<input type='text' name='price' value='' />";
			break;		
		case "btw":
			document.getElementById('moneyFields').innerHTML = "<input type='text' name='lprice' value='' /> y <input type='text' name='hprice' value='' />";
			break;
	}
}


function exportar(){
	sql = document.getElementById('sql_string').value;
	obj = document.getElementById('objetivo').value;
	window.open('relational.asp?goal_fld='+ obj +'&envio=Buscar&export=1&sql_query='+ sql,'','width=300, height=200, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=yes');
	return;			
}


function loadTest(src){
	var W3CDOM = (document.createElement && document.getElementsByTagName);
	if (!W3CDOM) return;	
	img = new Image();
	img.src = src;
	document.getElementById('bigImage').appendChild(img);
}


function printAgenda(){
	fecha  = document.getElementById("print_date").value;
	agente = document.getElementById("print_goal").value;
	//inmuinfo = document.getElementById("propinfo").checked;
	//clieinfo = document.getElementById("customerinfo").checked;
	for(i=0;i<document.getElementsByName("documentType").length;i++){
		if(document.getElementsByName("documentType")[i].checked){
			docType = document.getElementsByName("documentType")[i].value;
		}
	}
	
	switch (docType){
		case "agentes":
			file = "printagenda.asp";
			break;		
		case "clientes":
			file = "printagenda2.asp";
			break;		
	}

//	window.open(file +'?agente='+ agente +'&fecha='+ fecha +'&includeprop='+ inmuinfo +'&includecustomer='+ clieinfo ,'','width=800, height=600, location=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes');
	window.open(file +'?agente='+ agente +'&fecha='+ fecha ,'','width=800, height=600, location=no, toolbar=no, menubar=no, scrollbars=yes, resizable=yes');
}

function chooseStreets(city,field){
	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	file = 'streetChooser.asp?city='+ city;

	xmlhttp.open('GET', file , true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			document.getElementById(field).innerHTML = "<select id='calle'>"+ content +"</select>";
		}
	}
	xmlhttp.send(null);
	return;				
}

function makeSuggestion(obj,tecla,time){
	var RETRN = 13;
	var TAB   = 9;
	var ESC   = 27;
	var DEL   = 8;
	var SHFT  = 16;
	var CTRL  = 17;
	var ALT   = 18;

	var xmlhttp=false; //Clear our fetching variable
	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();
	}


	switch (tecla){
		case ESC:
			obj.value = "";
			break;
		case SHFT:
			return;
			break;			
		case CTRL:
			return;
			break;			
		case ALT:
			return;
			break;			
		case TAB:
			return;
			break;			
		default:
			currentString = obj.value;
			var file = '/admin/suggest.asp?expression='+ currentString;

			xmlhttp.open('GET', file , true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					var content = xmlhttp.responseText; 
					if (content!="No hay sugerencias"){
						clientes = content.split("|");
						html = "";
						for (i=0;i<clientes.length;i++) {
							tmp = clientes[i].split("-");
							html+= "<a href='#' onclick='document.getElementById(\"client_id_"+ time +"\").value="+ tmp[0] +";document.getElementById(\"client_name_"+ time +"\").value=\""+ tmp[1] +"\"; document.getElementById(\"suggestions-"+ time +"\").innerHTML=\"\";document.getElementById(\"suggestions-"+ time +"\").style.display=\"none\";'>"+ tmp[1] +"</a><br/>";
						}
					}else{
						html = content;
					}
					
					
					if (document.getElementById('suggestions-'+ time)){
						document.getElementById('suggestions-'+ time).style.display="block";
						document.getElementById('suggestions-'+ time).innerHTML = html;
					}else{
						obj.parentNode.innerHTML+="<div id='suggestions-"+ time +"' style='width:375px; float:left; z-index:100; padding-left: 2px;line-height: 1.5; position:absolute; border: 1px #000000 solid; background-color: #FFFFFF;'>"+ html +"</div>";
					}
				}
			}
			xmlhttp.send(null);
			return;			
	}
}



function streetSelector(ciudad){
	window.open('streetSelector.asp?city='+ ciudad,'test','width=450, height=250, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no,screenX=200,screenY=200,left=200,top=200');
	return;
}

function customerSelector(utime){
	window.open('customerSelector.asp?time='+ utime,'test','width=200, height=350, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no,screenX=200,screenY=200,left=200,top=200');
	return;
}

function checkReference(input,id){
	ref = trim(input);

	var xmlhttp=false; //Clear our fetching variable
	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();
	}


	file = '/admin/checkReference.asp?ref='+ ref;

	xmlhttp.open('GET', file , true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if (content.indexOf("ATENC") >= 0) {
				alert(content);
			}else{	
				//alert("-->"+ content +"<--");
				//alert(id);
				document.getElementById('title_'+ id).value = trim(content);
			}
		}
	}
	xmlhttp.send(null);
	return;				
}


function list4Ref(reflist){

	var xmlhttp=false; //Clear our fetching variable
	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();
	}

	file = '/admin/list4Ref.asp?list='+ reflist;

	xmlhttp.open('GET', file , true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var content = xmlhttp.responseText;
			if (content != "") {
				setSelectsDisplay('none');
				document.getElementById("disableScreen").style.display = "block";
				document.getElementById("floatdiv").innerHTML = content;
			}
		}
	}
	xmlhttp.send(null);
	return;				

}


function setSelectsDisplay(display){
	for(i=0; i<document.getElementsByTagName('select').length; i++){
		document.getElementsByTagName('select')[i].style.display = display;
	}
}

function blankForm(){
	for(i=0; i<document.getElementsByTagName('input').length; i++){
		if(document.getElementsByTagName('input')[i].type == "text"){
			document.getElementsByTagName('input')[i].value = "";
		}
	}
}



function reschedule(task){
	window.open('reschedule.asp?id='+ task,'','width=650, height=350, location=no, toolbar=no, menubar=no, scrollbars=no, resizable=no');
}


function pickStreets(city){
        var xmlhttp=false; //Clear our fetching variable
        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();
        }

        var file = '/admin/pickStreets.asp';

        parameters = 'city='+ city;
        xmlhttp.open('POST', file, true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.setRequestHeader("Content-length", parameters.length);
        xmlhttp.setRequestHeader("Connection", "close");
        xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4) {
                        var content = xmlhttp.responseText;
			document.getElementById('streetSpan').innerHTML = content;
                }
        }
        xmlhttp.send(parameters);
        return;

}
