// JavaScript Document
function mostrarCriteriosUsuario(usuario) {
	url = "/servlet/co.com.pragma.m2.servlet.demanda.MostrarCriteriosUsuario?usuario=" + usuario;			
	try {
		if(xmlHttp){
			if(xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
				xmlHttp.open("POST",url,false);				
				xmlHttp.onreadystatechange = actualizarCriterios;
				xmlHttp.send(null);
			}
		}
	} catch(e ){
		var errores = document.getElementById("errores");
		errores.innerHTML = "ERROR " + e.toString();
		url= null;
	}
}

function actualizarCriterios(){
	var cargar = false;
	if (xmlHttp.readyState == 4 ) {
		if(xmlHttp.status == 200){
			var divCriterios = document.getElementById("criteriosBusqueda");
			divCriterios.innerHTML = xmlHttp.responseText;
		} else {
			var errores = document.getElementById("errores");
			errores.innerHTML = parseErrorCode("Ocurrio un error: "+xmlHttp.status+" "+xmlHttp.responseText);
		}   
	}
	url= null;
}

function cargarTiposInmueble(forma){
	if(forma.idCiudad.value != -1){
		url = "/servlet/co.com.pragma.m2.servlet.demanda.MostrarTiposInmuebleCriterios?usuario=" + forma.usuario.value +"&idCiudad=" + forma.idCiudad.value;	
		try {
			if(xmlHttp){
				if(xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
					xmlHttp.open("POST",url,false);	
					xmlHttp.onreadystatechange = actualizarTiposInmueble;
					xmlHttp.send(null);
				}
			}
		} catch(e ){
			var errores = document.getElementById("errores");
			errores.innerHTML = "ERROR " + e.toString();
			url= null;
		}
		forma.idTipoInmueble.disabled = false;
	}
}

function actualizarTiposInmueble(){
	var cargar = false;
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200){
			var divTiposInmueble = document.getElementById("divTiposInmueble");
			divTiposInmueble.innerHTML = xmlHttp.responseText;
		} else {
			var errores = document.getElementById("errores");
			errores.innerHTML = parseErrorCode("Ocurrio un error: "+xmlHttp.status+" "+xmlHttp.responseText);
		}   
	}
	url= null;
}

function cargarZonas(forma){
	if(forma.idTipoInmueble.value != "-1") {
		url = "/servlet/co.com.pragma.m2.servlet.demanda.MostrarZonasCriterios?usuario=" + forma.usuario.value +"&idCiudad=" + forma.idCiudad.value + "&idTipoInmueble=" + forma.idTipoInmueble.value;	
		try {
			if(xmlHttp){
				if(xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
					xmlHttp.open("POST",url,false);				
					xmlHttp.onreadystatechange = actualizarZonas;
					xmlHttp.send(null);
				}
			}
		} catch(e ){
			var errores = document.getElementById("errores");
			errores.innerHTML = "ERROR " + e.toString();
			url= null;
		}
	}
}
function actualizarZonas(){
	var cargar = false;
	if (xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200){
			var divZonas = document.getElementById("divZonas");
			divZonas.innerHTML = xmlHttp.responseText;
		} else {
			var errores = document.getElementById("errores");
			errores.innerHTML = parseErrorCode("Ocurrio un error: "+xmlHttp.status+" "+xmlHttp.responseText);
		}   
	}
	url= null;
}

function deshabilitarZonasUsuario(forma) {
	if (forma.idCiudad[forma.idCiudad.selectedIndex].value == 1) {
		forma.idZona.disabled = false;
	}
	else {
			forma.idZona.disabled = true;
	}
}

function validarBusquedaBasicaIIUsuario(laForma) {
	_campoError = null;
	_errores = "";
	validarLista(laForma.idCiudad, "Ciudad")
	validarLista(laForma.idTipoInmueble, "Tipo Inmueble")
	if (laForma.idCiudad[laForma.idCiudad.selectedIndex].value == 1) {
		validarLista(laForma.idZona, "Zona")
	}
	if (laForma.idTipoNegocio[0].checked) {
		laForma.seVende.value = 'S';
	}
	if (laForma.idTipoNegocio[1].checked) {
		laForma.seArrienda.value = 'S';
	}
	if (_errores != "") {
		alert("Por favor verifique la siguiente información: \n\n" + _errores)
		_campoError.focus()
		return false;
	}
	return true;
}

function mailto(usuario, to, subject, body, bcc, name, phone, address, idInmueble, idFuente) {

           __left = ((screen.width-500)/2)
           __top  = ((screen.height-470)/2)

			window.open("/servlet/co.com.pragma.m2.servlet.Base?PJR_TEMPLATE_NAME=/licenciamiento/" + usuario + "/mailTo.pjr.html&to=" +
           escape(to) +
	
	(bcc ? "&bcc=" + escape(bcc) : "") +

           (subject ? "&subject=" + escape(subject) : "") +

           (body ? "&body=" + escape(subject) : "") +

           (name ? "&name=" + escape(name) : "") +

           (phone ? "&phone=" + escape(phone) : "") +

           (address ? "&address=" + escape(address) : "") +

           (idInmueble ? "&idInmueble=" + escape(idInmueble) : "") +

           (idFuente ? "&idFuente=" + escape(idFuente) : "") +

           "&x=" + Math.random(),"Login",

           "scrollbars=auto,width=350,height=570,top=" + __top +

           ",left=" + __left,true);
}

function mailto_TB(usuario, to, subject, body, bcc, name, phone, address, idInmueble, idFuente) {
	tb_show("", "/servlet/co.com.pragma.m2.servlet.Base?PJR_TEMPLATE_NAME=/licenciamiento/" + usuario + "/mailTo.pjr.html&to=" + escape(to) +
		   (bcc ? "&bcc=" + escape(bcc) : "") +
           (subject ? "&subject=" + escape(subject) : "") +
           (body ? "&body=" + escape(subject) : "") +
           (name ? "&name=" + escape(name) : "") +
           (phone ? "&phone=" + escape(phone) : "") +
           (address ? "&address=" + escape(address) : "") +
           (idInmueble ? "&idInmueble=" + escape(idInmueble) : "") +
           (idFuente ? "&idFuente=" + escape(idFuente) : "") +
           "&x=" + Math.random() + "&KeepThis=true&TB_iframe=true&height=570&width=350", null);
           __left = ((screen.width-500)/2)
           __top  = ((screen.height-470)/2)

}


function validarBusquedaCodigoEntidad(forma) {

	_campoError = null;

	_errores = "";

	validarCampo(forma.idInmueble, "Codigo Inmueble");

	if (_errores != "") {

		alert("Por favor verifique la siguiente información: \n\n" + _errores)

		_campoError.focus()

		return false;

	}

}

function validarDatosInmuebleConsignacion(laForma) {

	_campoError = null;

	_errores = "";

	var url = "";

	validarLista(laForma.idTipoInmueble, "Tipo de Inmueble")

	if (!laForma.tipoNegocio[0].checked && !laForma.tipoNegocio[1].checked && !laForma.tipoNegocio[2].checked) {

		_errores += "\n        Tipo de Negocio\n";

		_campoError = laForma.tipoNegocio[0];

	}

	if (laForma.tipoNegocio[2].checked) {

		laForma.seVende.value="S";

		laForma.seArrienda.value="S";

	}

	if (laForma.tipoNegocio[0].checked) {

		laForma.seVende.value="S";

	}

	if (laForma.tipoNegocio[1].checked) {

		laForma.seArrienda.value="S";

	}

	if (_errores != "") {

		alert("Por favor verifique la siguiente información: \n\n" + _errores)

		_campoError.focus()

		return false;

	}

	return true;

}

function validarFormaPublicacion(forma) {

	_campoError = null;

	_errores = "";

	validarCampo(forma.FIRST_NAME_PERSONA, "Nombre", 2)

	validarCampo(forma.LAST_NAME_PERSONA, "Apellido", 2)

	validarCampo(forma.ID, "Doc. de Identidad ó NIT", 6)

	validarCampo(forma.HOMEPHONE, "Teléfono", 7)

	validarCampo(forma.ADDRESS_PERSONA, "Dirección", 5)

	validarLista(forma.PROFESION, "Profesión")

	validarCampo(forma.CITY, "Ciudad", 3)

	validarCampo(forma.COUNTRY, "País")

	validarLogin(forma.loginId)

	validarCampo(forma.PASSWORD, "Clave")

	validarCampo(forma.PASSWORDCONFIRMATION, "Confirmación de la clave")

	forma.loginId.value = forma.loginId.value.toLowerCase();

	if (forma.PASSWORD.value != forma.PASSWORDCONFIRMATION.value) {

		forma.PASSWORD.value = ""

		forma.PASSWORDCONFIRMATION.value = ""

		_errores += "        Clave\n"

		if (_campoError ==  null) {

			_campoError = forma.PASSWORD

		}

	}

	validarEmail(forma)

	if (_errores != "") {

		alert("Por favor verifique la siguiente información: \n\n" + _errores)
		//_campoError.focus()
		return false;

	}

	return true;
}

function validarFormaPublicacion2(forma) {

	_campoError = null;

	_errores = "";

	validarCampo(forma.FIRST_NAME_PERSONA, "Nombre", 2)

	validarCampo(forma.LAST_NAME_PERSONA, "Apellido", 2)

	validarCampo(forma.ID, "Doc. de Identidad ó NIT", 6)

	validarCampo(forma.HOMEPHONE, "Teléfono", 7)

	validarCampo(forma.ADDRESS_PERSONA, "Dirección", 5)

	validarLista(forma.PROFESION, "Profesión")

	//validarCampo(forma.CITY, "Ciudad", 3)
	forma.CITY.value = forma.CITY_LIST[forma.CITY_LIST.selectedIndex].value;
	if (forma.CITY_LIST[forma.CITY_LIST.selectedIndex].value == -1) {
		_errores += "\n\tCiudad";
	} else if(forma.CITY_LIST[forma.CITY_LIST.selectedIndex].value == "Otra"){
		if(validarCampo(forma.OTRA, "Ciudad")){
			forma.CITY.value = forma.OTRA.value;
		}
	}

	validarCampo(forma.COUNTRY, "País")

	validarLogin(forma.loginId)

	validarCampo(forma.PASSWORD, "Clave")

	validarCampo(forma.PASSWORDCONFIRMATION, "Confirmación de la clave")

	forma.loginId.value = forma.loginId.value.toLowerCase();

	if (forma.PASSWORD.value != forma.PASSWORDCONFIRMATION.value) {

		forma.PASSWORD.value = ""

		forma.PASSWORDCONFIRMATION.value = ""

		_errores += "        Clave\n"

		if (_campoError ==  null) {

			_campoError = forma.PASSWORD

		}

	}

	validarEmail(forma)

	if (_errores != "") {

		alert("Por favor verifique la siguiente información: \n\n" + _errores)
		//_campoError.focus()
		return false;

	}

	return true;
}


function mostrarAyudaZonas(usuario) {
 	window.open('/licenciamiento/'+usuario+'/ayudaSectores.html','popUpAyudaZonasJimenezNassar','width=350,height=350');

}

function mostrarAyudaFiltros(usuario) {

	window.open('/licenciamiento/'+usuario+'/ayudaFiltrarInmuebles.html','popUpFiltrarInmueblesJimenezNassar','width=350,height=350');

}

function goSector(idSector) {
	var forma = document.laForma;
	mWindow = window.open("/servlet/co.com.pragma.m2.servlet.demanda.MasDatosBusquedaUsuario?idSector=" + idSector + "&usuario=" + 		forma.usuario.value, "masDatosBusqueda","location=no,menubar=no,resizable=no,toolbar=no,scrollbars=no,top=1,width=350,height=255");
}

function goSector2(idSector,idZona,idCiudad) {
	var forma = document.laForma;
	mWindow = window.open("/servlet/co.com.pragma.m2.servlet.demanda.MasDatosBusquedaUsuario?idSector="  + idSector + "&idZona=" + idZona + "&idCiudad=" + idCiudad + "&usuario=" + forma.usuario.value, "masDatosBusqueda","location=no,menubar=no,resizable=no,toolbar=no,scrollbars=no,top=1,width=350,height=255");
}

function mostrarInmuebleDestacado(usuario) {
	url = "/servlet/co.com.pragma.m2.servlet.demanda.MostrarInmuebleDestacadoUsuario?usuario=" + usuario;			
	try {
		if(xmlHttp){
			if(xmlHttp.readyState == 0 || xmlHttp.readyState == 4) {
				xmlHttp.open("POST",url,false);				
				xmlHttp.onreadystatechange = actualizarInmuebleDestacado;
				xmlHttp.send(null);
			}
			//terminar asincronismo para gernerar el div en mozilla no borrar codigos alert(xmlHttp.status);
			//alert(xmlHttp.responseText);
			var divDestacado = document.getElementById("divDestacado");
			divDestacado.innerHTML = xmlHttp.responseText;
		}
	} catch(e ){
		var errores = document.getElementById("errores");
		errores.innerHTML = "ERROR " + e.toString();
		url= null;
	}
}

function actualizarInmuebleDestacado(){
	var cargar = false;
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 1) {
		if(xmlHttp.status == 200){
			var divDestacado = document.getElementById("divDestacado");
			divDestacado.innerHTML = xmlHttp.responseText;
		} else {
			var errores = document.getElementById("errores");
			errores.innerHTML = parseErrorCode("Ocurrio un error: "+xmlHttp.status+" "+xmlHttp.responseText);
		}   
	}
	url= null;
}

function contactoNegocios(usuario, ptl, to) {

	__left = ((screen.width-500)/2)

	__top  = ((screen.height-470)/2)

   window.open("/servlet/co.com.pragma.m2.servlet.Base?PJR_TEMPLATE_NAME=/licenciamiento/"+usuario+"/contacto.html&to=" + to + "&usuario=" + usuario + "&ptl=" + ptl, "contacto",

   	"scrollbars=no,width=400,height=500,top=" + __top +

   	",left=" + __left,true);

}

function deshabilitarZonasUsuario2(forma) {
	if (forma.idCiudad[forma.idCiudad.selectedIndex].value == 1) {
		forma.idSector.disabled = false;
	}
	else {
			forma.idSector.disabled = true;
	}
}


var re = new RegExp("[A-Z]|[0-9]|[a-z]|[-,_]")

function RotatePhotoViewer(iDelta) {
	intPhotoViewer += iDelta;
	while(intPhotoViewer < 1)  intPhotoViewer += nroFotos;
	while(intPhotoViewer > nroFotos) intPhotoViewer -= nroFotos;
	LoadPhotoViewer();
}
		
function SetPhotoViewer(iIndex) {
	intPhotoViewer = iIndex;
	LoadPhotoViewer();
}

function LoadPhotoViewer() {
	if(document.images)
		document.images['imgInmueble'].src = imagesInmuebles[intPhotoViewer-1];

	if(document.all)
		document.all('countFotos').innerHTML = '' + intPhotoViewer;
	else if(document.getElementById)
		document.getElementById('countFotos').innerHTML = '' + intPhotoViewer;
}

function rotateImage(numero) {

	var swap = imagesInmuebles[numero - 1];
	document.images['imgInmueble'].src = urlFoto + imagesInmuebles[numero - 1] + "_l.jpg";
	document.images['fotoInmueble_' + numero + '_m'].src = urlFoto + imagesInmuebles[0] + "_m.jpg";
	imagesInmuebles[numero - 1] = imagesInmuebles[0];
	imagesInmuebles[0] = swap;

}

function habilitarOtra(forma) {
	if(forma.CITY_LIST[forma.CITY_LIST.selectedIndex].value == "Otra") {
		forma.OTRA.disabled = false;
	} else {
		forma.OTRA.disabled = true;
		forma.OTRA.value = "";
	}
}


function mostrarInmuebleUsuario(idInmueble, usuario) {
	window.location = '/servlet/co.com.pragma.m2.servlet.demanda.MostrarInmuebleGeneralUsuario?idInmueble=' + escape(idInmueble) + '&MostrarResultadosBusqueda=yes&usuario=' + usuario;
}

function mostrarInmuebleGrupo(idInmueble, usuario) {
	window.location = '/servlet/co.com.pragma.m2.servlet.demanda.MostrarInmuebleGeneralGrupo?idInmueble=' + escape(idInmueble) + '&MostrarResultadosBusqueda=yes&usuario=' + usuario;
}
