// JavaScript Document

jQuery(document).ready(function() {

	jQuery("#ajaxMapsColorbox").colorbox({
		opacity: 0.85,
		iframe:true,
		innerWidth:670,
		innerHeight:520,
		close:"Fermer",
		title:"Placez le pointeur rouge au-dessus de votre bien",
		href: function(){ return ("googlemaps.php?lat="+$("#lat").val()+"&lng="+$("#lng").val());}
		});
	
	$(".submit_button").hover(
	  function () {
		  $(this).css({"background-color":"#E85656", "border-color":"#E85656"});
		  return false;
	  },
	   function () {
   		  $(this).css({"background-color":"#1A70FB", "border-color":"#1A70FB"});
		  return false;
	  }	  
	  
	);
	
	$("#Auth_Error").hide();
	$("#loading_span").hide();
	$("input[type=checkbox], input[type=radio]").prettyCheckboxes({display: 'inline'});

});



function region_change(n)
{
	if (n==1 || n==11)
		num=1;
	else
		num=n;
		
	$("#region" + num + "_loading").html('<img src="includes/images/loading.gif">');
	var region=$("#region" + num + "  option:selected").text();
	dataString = 'region' + num + '='+ region;
	$.ajax
	({
		type: "POST",
		url: "ajax_city.php",
		data: dataString,
		cache: false,
		success: function(html)
		{
			if (n == 1)
			{
				$("#region2").html($("#reg2_select").html() + html);
				$("#city").html($("#city_select").html());
			}
			else
				$("#city").html($("#city_select").html() + html);
			
			$("#region"+ num + "_loading").html('');
		}
	});
}


function city_change()
{
	var city=$("#city option:selected").text();
	var zip=$("#city option:selected").attr("zip");
	var lat=$("#city option:selected").attr("lat");
	var lng=$("#city option:selected").attr("lng");	
	$("#address_div").html(zip + " " +city);
	$("#zip").val(zip);
	$("#lat").val(lat);
	$("#lng").val(lng);
	if (typeof map != 'undefined' && typeof marker != 'undefined')
	{
		var newLatlng = new google.maps.LatLng(lat,lng);
		map.setCenter(newLatlng);
		marker.setPosition(newLatlng);
	}
}


function manage_tocontact()
{
	radio_subscribe=$('#subscribe');
	radio_login=$('#login');
	if (radio_subscribe.is(':checked'))
	{
		$('#subscribe_table').show();
		$('#login_table').hide();
	}
	else if (radio_login.is(':checked'))
	{
		$('#subscribe_table').hide();
		$('#login_table').show();
	}
	else
	{
		$('#subscribe_table').hide();
		$('#login_table').hide();	
	}
}

function initialize_infobulles()
{
	$('#info_video, #info_plan , #info_photo, #info_new').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		fade: 250 
	});
}

function user_login()
{
	$("#loading_span").show();
	$("#Auth_Error").hide();
	var login=$("#Realtor_login").val();
	var password=$("#Realtor_password").val();
	dataString = 'realtor_login=' + login + '&realtor_password='+ password + '&user=login';
	$.ajax
	({
	type: "POST",
	url: "ajax_user.php",
	data: dataString,
	cache: false,
	success: function(html)
	{
		$("#loading_span").hide();
		if (html.indexOf('<B>')!== -1)	
		{
			$("#Auth_Error").hide();
			$("#bonjour").hide();
			$("#form_search_simple").html(html);
			parent.$.colorbox.close();
		}
		else if (html.indexOf('no')!== -1)	
			$("#Auth_Error").show();		
	}
	});
}

function user_reminder()
{
	var email=$("#e_mail").val();
	dataString = 'realtor_email=' + email + '&user=reminder';
	$.ajax
	({
	type: "POST",
	url: "ajax_user.php",
	data: dataString,
	cache: false,
	success: function(html)
	{
		$("#message").html(html);
		if (html.indexOf('<B>')!== -1)	
		{
			$("#form_reminder").hide();
		}
	}
	});
}

function alert_delete(id)
{
	dataString = 'code=' + id;
	$.ajax
	({
	type: "POST",
	url: "ajax_user.php",
	data: dataString,
	cache: false,
	success: function(html)
	{
		$("#alert-" + id).html(html);
	}
	});
}
