// JavaScript Document



function precio() {

	var myConn = new XHConn();

	id = $('#id_operacion').get(0)[$('#id_operacion').get(0).selectedIndex].value;

	if (!myConn) {

		alert("Su navegador no soporta AJAX");

	}

	var postResponse = function (oXML) {

		$('#cont_precio').get(0).innerHTML = oXML.responseText;

		//OcultarCargando();

	};

	//MostrarCargando();

	datasend = 'idOperacion='+id;

	datasend = ReplaceAll(datasend," ","+");

	myConn.connect("ajax/combo.php?a=p","POST", datasend, postResponse);

}

function estado() {

	var myConn = new XHConn();

	id = $('#id_pais').get(0)[$('#id_pais').get(0).selectedIndex].value;

	if (!myConn) {

		alert("Su navegador no soporta AJAX");

	}

	var postResponse = function (oXML) {

		$('#cont_estado').get(0).innerHTML = oXML.responseText;

		ciudade();

		//OcultarCargando();

	};

	//MostrarCargando();

	datasend = 'idPais='+id;

	datasend = ReplaceAll(datasend," ","+");

	myConn.connect("ajax/combo.php?a=e","POST", datasend, postResponse);

}

function ciudade() {

	var myConn = new XHConn();

	id = $('#id_estado').get(0)[$('#id_estado').get(0).selectedIndex].value;

	if (!myConn) {

		alert("Su navegador no soporta AJAX");

	}

	var postResponse = function (oXML) {

		$('#cont_ciudad').get(0).innerHTML = oXML.responseText;

		zonas();

		//OcultarCargando();

	};

	//MostrarCargando();

	datasend = 'idCiudad='+id;

	datasend = ReplaceAll(datasend," ","+");

	myConn.connect("ajax/combo.php?a=c","POST", datasend, postResponse);

}

function zonas() {

	var myConn = new XHConn();

	id = $('#id_ciudad').get(0)[$('#id_ciudad').get(0).selectedIndex].value;

	if (!myConn) {

		alert("Su navegador no soporta AJAX");

	}

	var postResponse = function (oXML) {

		$('#cont_zona').get(0).innerHTML = oXML.responseText;

		//OcultarCargando();

	};

	//MostrarCargando();

	datasend = 'idZona='+id;

	datasend = ReplaceAll(datasend," ","+");

	myConn.connect("ajax/combo.php?a=z","POST", datasend, postResponse);

}

function init(clip){

	$('#todo').css("visibility","visible");

	if (clip) {

		$('#wrap').show('clip', {}, 3000);

	}

}

function effect_contact(lang){

	var mensaje;

	

	if (lang == 'es'){

		mensaje = "Su consulta ha sido enviada con exito!!.<br />Recibira respuesta a la  brevedad.";

	}

	else{

		mensaje = "Your question has been sent successfully!!.<br />You will receive a response soon.";

	}

	

	$("#contacto").flip({ direction: 'lr',

								color: 'transparent',

							  	onEnd: function(){$("#contacto").html("<p style='padding:20px'><b>"+mensaje+"</b></p>") }

						});

}

function error_contact(lang){

	var mensaje;

	

	if (lang == 'es'){

		mensaje = "Ocurrio un error durante la operacion, por favor intente nuevamente.<br />Muchas gracias.";

	}

	else{

		mensaje = "An error occurred during the operation, please try again.";

	}

	

	$("#contacto").flip({ direction: 'lr',

								color: 'transparent',

							  	onEnd: function(){$("#contacto").html("<p style='padding:20px'><b>"+mensaje+"</b></p>") }

						});

}
function ingresar(form){
	var datasend = 'action=log&usuario='+form.usuario.value+'&clave='+form.clave.value;	
	$.ajax({
		data:datasend,
		type:'GET',
		url:'http://puntasunrise.com/ajax.php',
		beforeSend: function(){ $('.login').css('background-image','');},
		success: function(responseText){effect_login(JSON.parse(responseText),form.lang.value);}
	})	
}
function effect_login(mensaje,lang){
	if (mensaje.estado == 'ok'){
		$("#login").flip({ direction: 'lr',
								color: 'transparent',
							  	onEnd: function(){
										$('#login').attr('class','bv-'+lang);
										$("#login").html("<p style='font-size:22px;padding-top:90px;'><b>"+mensaje.bienvenida+"</b></p>") 
										}
						});	
	}
	else{
		//$('#err_message').html(mensaje.bienvenida);	
		fade_message('login',mensaje.bienvenida);
	}
}


function ver_tipo(id_tipo,action,container){
	load_content(container,'');
	
	var datasend = "action="+action+"&tipo="+id_tipo+"&container="+container;
	$.ajax({
		type: "GET",
		url: 'http://puntasunrise.com/ajax/ajax_home.php',
		data: datasend,
		error: function(errorSended){ ajax_error(errorSended); },
		//error: function(errorSended){ window.document.location = window.document.location; },
		beforeSend: function() {  },
		success: function(responseText){ load_content(container,responseText); },
		complete: function() {  }
	});	
}

function load_content(div_response,content){
	$("#"+div_response+" .htmlContent").html(content);
}

function ajax_error(errorSended) {
	alert(errorSended.responseText+' - '+errorSended.statusText);
}
function ficha_home(id_propiedad,Lang){
	$(".centered").fadeIn("slow");
	$("#fade_sim").fadeIn("slow");
	
	var datasend = "ajax=true&action=ficha&id_propiedad="+id_propiedad+"&lang="+Lang;
	$.ajax({
		type: "GET",
		url: 'http://puntasunrise.com/ajax/ajax_listado.php',
		data: datasend,
		error: function(errorSended){ ajax_error(errorSended); },
		beforeSend: function() { mostrar_cargando(); },
		success: function(responseText){ load_content_home('main_popsim',responseText); },
		complete: function() { ocultar_cargando(); }
	});	
}

function load_content_home(div_response,content){
	$("#popsimul").fadeIn("slow");
	$('#'+div_response).html(content);
	if(div_response != 'form_content') {
		initTb();
	}
}

function closeProp(){
	$(".centered").fadeOut("slow");
	$("#popsimul").fadeOut("slow");
	$("#fade_sim").fadeOut("slow");
}
function mostrar_cargando(){
	$('#cargando').css('display','block');	
}
function ocultar_cargando(){
	$('#cargando').css('display','none');
}
/*
function ajax_error(errorSended) {
	alert(errorSended);
}
*/
function registrarse(action,form){
	var datasend = "ajax=true&action="+action;
	$.ajax({
		type: "GET",
		url: 'http://puntasunrise.com/ajax.php',
		data: datasend,
		error: function(errorSended){ ajax_error(errorSended); },
		beforeSend: function() { mostrar_cargando(); },
		success: function(responseText){ load_content_home('form_content',responseText); },
		complete: function() { eff_form_reg(action); }
	});	
}
function logout() {
	var datasend = "ajax=true&action=logout";
	$.ajax({
		type: "GET",
		url: 'http://puntasunrise.com/ajax.php',
		data: datasend,
		error: function(errorSended){ ajax_error(errorSended); },
		success: function(responseText){ window.document.location = window.document.location; }
	});	
}
function lang(idiomaCorto) {
	var datasend = "ajax=true&action=lang&lang="+idiomaCorto;
	$.ajax({
		type: "GET",
		url: 'http://puntasunrise.com/ajax.php',
		data: datasend,
		beforeSend: function() { mostrar_cargando(); },
		error: function(errorSended){ ajax_error(errorSended); },
		success: function(responseText){ reload_page(); }
	});	
}
function eff_form_reg(action,mensaje,lang){
	if (action == 'registrado'){	
		mensaje = JSON.parse(mensaje)
		if(mensaje.estado == 'ok') {
			$("#form_reg").flip({ direction: 'lr',
								color: '#000',
								onEnd: function(){ end_eff_form_reg(mensaje.bienvenida,lang) }
	
						});
		}
		else {
			$("#form_content").html("<p style='padding:20px'><b>"+mensaje.bienvenida+"</b></p> 	<a href=\"javascript:registrarse('form_reg','')\">Intentar nuevamente</a>");
			if ( $("#login") ){	
				fade_message('login',mensaje.bienvenida);
			}
		}
	}
	else {
		$("#form_reg").css('display','block');
		$("#form_reg").show("fold", {}, 1000);
		ocultar_cargando();
	}
}
function fade_message(div,content){
	if ( $("#"+div) ){
		$("#"+div).append('<div id="dinamico">'+content+'</div>');
		$("#dinamico").fadeOut(8000,function(){$("#dinamico").remove()});	
	}	
}
function end_eff_form_reg(mensaje,lang){
	$("#form_content").html("<p style='padding:20px'><b>Bienvenido "+mensaje+".</b></p>");
	$("#form_reg").fadeOut(5000,function(){effect_login_reg(mensaje,lang)});
	reload_page();
}
function effect_login_reg(mensaje,lang){
	if ( $("#login") ){						
						$("#login").flip({ direction: 'lr',
								color: 'transparent',
							  	onEnd: function(){
											$('#login').attr('class','bv-'+lang);
											$("#login").html("<p style='font-size:22px;padding-top:90px;'><b>"+mensaje+"</b></p>");
										}
						});	
	}
	//reload_page();
}
function reload_page(){
	ocultar_cargando();
	window.document.location = window.document.location;
}
function hide_form(form){
	$('#'+form).html('');
	$('#form_reg').css('display','none');
}

function buscar() {
	window.document.location = 'http://puntasunrise.com/search/'+$("#search").val();
}