var secureurl = 'https://www.easylondonaccommodation.com/';

$(document).ready(function () {
							
	$('textarea').elastic();
							
	$(".updatenotes").live('submit' ,  function () {
		$(this).find(".successareanoteupdate").html('<img src="imgs/ajax.gif"/>');										 	
		prop_id = $(this).find('.updatenotesid').val();
		notes = $(this).find('.updatenotesnote').val();
		$(this).find(".successareanoteupdate").load(secureurl + 'libs/ajax/ajax.UpdateNotes.php', {'id': prop_id, 'note': notes});
		
		return false;
	});
							
	$('.getlink').click ( function () {
		
		$('#shortlink').dialog();
		$('#shortlink').focus();
		$('#shortlink').select();					
	});
							
	
	$(".propertyprev1").hover( function () {
		$(".propertyprev1").find(".propholdertext").stop(true, true);
		$(this).find(".propholdertext").slideDown(500);								
	});
	$(".propertyprev1").mouseleave( function () {
		$(this).find(".propholdertext").fadeOut();								
	});
	
	$("div[href]").click(function () {
        window.location = $(this).attr("href");
    });

							
	$(".addform").live('submit' ,  function () {
		$('.thequicksubmitbutton').hide();
		$(".messageadded").html('<img src="imgs/ajax.gif"/>');
		$.post("libs/ajax/ajax.SendPropertyEmail.php", $(".addform").serialize() , function(msg){ 																			
			$(".messageadded").html(msg);
			$('.thequicksubmitbutton').show();	

		}, 
		"html");
		return false;
	});
	
	$(".contactusformnotsecure").live('submit' ,  function () {
		$(".messagecontactarea").html('<br/><img src="imgs/ajax.gif"/>');
		$.post("libs/ajax/ajax.ContactForm.php", $(".contactusformnotsecure").serialize() , function(msg){ 																			
			$(".messagecontactarea").html(msg);
			if($(".messagecontactarea").text() == 'Your message has been successfully sent') {
				//$(".addform").slideUp(1000);
			}
		}, 
		"html");
		return false;
	});
	
	$(".contactusform").live('submit' ,  function () {
		$(".messagecontactarea").html('<br/><img src="imgs/ajax.gif"/>');
		$.post(secureurl + "libs/ajax/ajax.ContactForm.php", $(".contactusform").serialize() , function(msg){ 																			
			$(".messagecontactarea").html(msg);
			if($(".messagecontactarea").text() == 'Your message has been successfully sent') {
				//$(".addform").slideUp(1000);
			}
		}, 
		"html");
		return false;
	});
	
	
	
	
	$(".closesmallsubmit").live('click', function () {
		$(this).closest(".messagearea").slideUp('1000');			  
	})
	
	$( ".sendmessage" ).click(function() {
		pid = $(this).attr('title');
		$(".propertyidmessage").attr('value', pid);
		$(".messageadded").empty();							   
		if ($(".messagearea").html()) {
			messagearea = $(".messagearea").html();
		}
		else {
			messagearea = $("#messagearea").html();
		}
		
		$(".messagearea").slideUp(1000);
		$(".messagearea").empty();
		$(this).closest(".propertycat").append('<div class="messagearea" style="display: none;">' + messagearea + '</div>');
		$(".messagearea").slideDown(1000);
		return false;
	});
				
	var dates =  $("#date1, #date2").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "date1" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dates1 =  $("#dateanother1, #dateanother2").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "dateanother1" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates1.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dateline0 =  $("#ratedatefrom0, #ratedateto0").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom0" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline0.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dateline1 =  $("#ratedatefrom1, #ratedateto1").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom1" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline1.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dateline2 =  $("#ratedatefrom2, #ratedateto2").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom2" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline2.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dateline3 =  $("#ratedatefrom3, #ratedateto3").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom3" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline3.not( this ).datepicker( "option", option, date );
		}
	});
	var dateline4 =  $("#ratedatefrom4, #ratedateto4").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom4" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline4.not( this ).datepicker( "option", option, date );
		}
	});
	var dateline5 =  $("#ratedatefrom5, #ratedateto5").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom5" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline5.not( this ).datepicker( "option", option, date );
		}
	});
	var dateline6 =  $("#ratedatefrom6, #ratedateto6").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom6" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline6.not( this ).datepicker( "option", option, date );
		}
	});
	var dateline7 =  $("#ratedatefrom7, #ratedateto7").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom7" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline7.not( this ).datepicker( "option", option, date );
		}
	});
	
	var dateline8 =  $("#ratedatefrom8, #ratedateto8").datepicker({
		showButtonPanel: true,
		dateFormat: 'yy-mm-dd',
		onSelect: function( selectedDate ) {
			var option = this.id == "ratedatefrom8" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" ),
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dateline8.not( this ).datepicker( "option", option, date );
		}
	});
	


	
	$(".datechooser").datepicker({ dateFormat: 'yy-mm-dd'});
	
	$(".register").mouseover( function () {
		$(this).css('background', '#F0EEEE');									
	});
	
	$(".register").mouseout( function () {
		$(this).css('background', '#E8E8E8');									
	});


	$(".easysearch").autocomplete({
		source: "libs/ajax/ajax.GetCity.php",
		minLength: 1
	});
	
	
	$(".contactmessage").click ( function () {
		$("#popcontactarea").fadeIn('1000');
		$("#popcontact").fadeIn('1000');
		$('html, body').animate({scrollTop:0}, 'slow');		
		$(".messagecontactarea").html("<br/>");		
	});
				

	$("#londonflats").fadeIn(2000);


	$("#popback").click ( function () {
		$("#popback").hide();
		$("#poparea").hide();
	});
	
	$("#popcontact").click ( function () {
		$("#popcontact").hide();
		$("#popcontactarea").hide();
	});


	$(".smallinfoarea").click ( function () {
		$(".catareainfo").slideToggle();
	});

	$(".filteritem").mouseover (function () {
		$(this).css('background', '#f1f1f1');
	})
	$(".filteritem").mouseout(function () {
		$(this).css('background', 'white');
	})
	$(".propertycat").mouseover(function(){
	  $(this).css('background', '#f9f9f9');
	});
	  
	$(".propertycat").mouseout(function(){
	  $(this).css('background', '#FDFDFD');
	});

	$(".propertyprev").mouseover(function(){
	  $(this).css('background', '#f1f1f1');
	});
	  
	$(".propertyprev").mouseout(function(){
	  $(this).css('background', '#f9f9f9');
	});

	$("#dropsearch ul li").live('mouseover', function () {
		$(this).css('background','#f1f1f1');
	})
	$("#dropsearch ul li").live('mouseout', function () {
		$(this).css('background','white');
	})

	$(".centrallondon").click(function(e){
		topnum = e.pageY - 10;
		leftnum = e.pageX - 10;
		$(".holder2").css({ 'position':'absolute', 'top':topnum,'left':leftnum, 'display':'block'});
		$(".holder2").html('<ul><li class="head">Central London</li><li><a href="rentals/0/in-central-london/0/0/1/">Rentals</a></li><li><a href="flat-shares/0/in-central-london/0/0/1/">Flat Shares</a></li><li><a href="short-stays/0/in-central-london/0/0/1/">Holiday/Short Lets</a></li></ul>');
		setTimeout(dropholder, 6000);
    
	});
	$(".westlondon").click(function(e){
		topnum = e.pageY - 10;
		leftnum = e.pageX - 10;
		$(".holder2").css({ 'position':'absolute', 'top':topnum,'left':leftnum, 'display':'block'});
		$(".holder2").html('<ul><li class="head">West London</li><li><a href="rentals/0/in-west-london/0/0/1/">Rentals</a></li><li><a href="flat-shares/0/in-west-london/0/0/1/">Flat Shares</a></li><li><a href="short-stays/0/in-west-london/0/0/1/">Holiday/Short Lets</a></li></ul>');
	    setTimeout(dropholder, 6000);
	
	});
	$(".eastlondon").click(function(e){
		topnum = e.pageY - 10;
		leftnum = e.pageX - 10;
		$(".holder2").css({ 'position':'absolute', 'top':topnum,'left':leftnum, 'display':'block'});
		$(".holder2").html('<ul><li class="head">East London</li><li><a href="rentals/0/in-east-london/0/0/1/">Rentals</a></li><li><a href="flat-shares/0/in-east-london/0/0/1/">Flat Shares</a></li><li><a href="short-stays/0/in-east-london/0/0/1/">Holiday/Short Lets</a></li></ul>');
	    setTimeout(dropholder, 6000);
	
	});
	$(".northlondon").click(function(e){
		topnum = e.pageY - 10;
		leftnum = e.pageX - 10;
		$(".holder2").css({ 'position':'absolute', 'top':topnum,'left':leftnum, 'display':'block'});
		$(".holder2").html('<ul><li class="head">North London</li><li><a href="rentals/0/in-north-london/0/0/1/">Rentals</a></li><li><a href="flat-shares/0/in-north-london/0/0/1/">Flat Shares</a></li><li><a href="short-stays/0/in-north-london/0/0/1/">Holiday/Short Lets</a></li></ul>');
	    setTimeout(dropholder, 6000);
		
	
	});
	$(".southlondon").click(function(e){
		topnum = e.pageY - 10;
		leftnum = e.pageX - 10;
		$(".holder2").css({ 'position':'absolute', 'top':topnum,'left':leftnum, 'display':'block'});
		$(".holder2").html('<ul><li class="head">South London</li><li><a href="rentals/0/in-south-london/0/0/1/">Rentals</a></li><li><a href="flat-shares/0/in-south-london/0/0/1/">Flat Shares</a></li><li><a href="short-stays/0/in-south-london/0/0/1/">Holiday/Short Lets</a></li></ul>');
	    setTimeout(dropholder, 6000);
	
	});
	
	//homepage tab navig
	$(" .flat-shares").click ( function () {
		$(" .tabs li").removeClass ('on');	
		$(" .flat-shares").addClass ('on');
		getSearchArea ('Flat Shares');
		$(".tabs li.info").load('libs/ajax/ajax.GetAmount.php', {'type': 'Flat Shares'});
	} ) 
	$(" .rentals").click ( function () {
		$(" .tabs li").removeClass ('on');	
		$(" .rentals").addClass ('on');
		getSearchArea ('Rentals');
		$(".tabs li.info").load('libs/ajax/ajax.GetAmount.php', {'type': 'Rentals'});
	} ) 
	$(" .short-stays").click ( function () {
		$(" .tabs li").removeClass ('on');	
		$(" .short-stays").addClass ('on');
		getSearchArea ('Short Stays');
		$(".tabs li.info").load('libs/ajax/ajax.GetAmount.php', {'type': 'Short Stays'});
	} ) 

	$(".showalllocations").click ( function () {
		if ($(".showalllocations").attr('title')  != '') {
			
			$(".noshowloc").slideUp(1500);
			t = $(".showalllocations").attr('title');
			$(".showalllocations").text(t);
			$(".showalllocations").attr('title', '');
		}
		else {
			$(".noshowloc").slideDown(1500);
			t = $(".showalllocations").text();
			$(".showalllocations").text('Hide Areas');
			
			$(".showalllocations").attr('title', t);
			
		}
		
		
		
		
		
	});


})

function dropholder () {
	$(".holder2").css({ 'display':'none'});
}


function fade (div) {
	$("#myimage").hide();
	$("#myimage").fadeIn("slow");
}

function saveproperty(id, propid, url, type) {
	if (id == '') {
		$("#login").slideDown("slow");
		$('html, body').animate({scrollTop:0}, 'slow');
	}
	else if (type == 'category') {
		$("#saveproperty").load("libs/ajax/ajax.GetSavedCategory.php", { id: id, name: propid, url: url }, slidesave);
		setTimeout(slideout, 6000);
		$('html, body').animate({scrollTop:0}, 'slow');
	}
	else {
		$("#saveproperty").load("libs/ajax/ajax.GetSavedProperty.php", { id: id, propid: propid }, slidesave);
		setTimeout(slideout, 6000);
		$('html, body').animate({scrollTop:0}, 'slow');
	}
	
	function slidesave () {
		$("#saveproperty").slideDown(1000)	
	}
	function slideout () {
		$("#saveproperty").slideUp(1000)	
	}
}

function hidesave (id, propid)  {
	$("#saved" + id).load(secureurl + "libs/ajax/ajax.DeleteSaved.php", { id: id, propid: propid }, slideout);
	function slideout () {
		$("#saved" + id).fadeOut(1000)	
	}
}

function hideresults (id, user)  {
	$("#savedres" + id).load(secureurl + "libs/ajax/ajax.DeleteSavedResults.php", { id: id, user: user }, slideout);
	function slideout () {
		$("#savedres" + id).slideUp(1000)	
	}
}

function getRegisterForm(type) {
	if (type == 'user') {
		$("#agentlogin").slideUp("slow");
		$("#userlogin").slideDown("slow");
	}
	else if (type == 'agent') {
		$("#userlogin").slideUp("slow");
		$("#agentlogin").slideDown("slow");
	}
}
function changeHomeTab (tab) {
	document.getElementById('maphome').style.display = 'none';
	document.getElementById('searches').style.display = 'none';
	document.getElementById('agents').style.display = 'none';
	document.getElementById('agenttab').style.background = 'url(imgs/navigoffright.gif)';
	document.getElementById('searchtab').style.background = 'url(imgs/navigoff.gif)';
	document.getElementById('maptab').style.background = 'url(imgs/navigoffleft.gif)';
	document.getElementById('agentlink').style.color = 'grey';
	document.getElementById('searchlink').style.color = 'grey';
	document.getElementById('maplink').style.color = 'grey';
	if (tab == 'map') {
		$("#maphome").fadeIn('slow');
		document.getElementById('maptab').style.background = 'url(imgs/navigon.gif)';
		document.getElementById('maplink').style.color = 'black';
	}
	else if (tab == 'agents') {
		$("#agents").fadeIn('slow');
		document.getElementById('agenttab').style.background = 'url(imgs/navigon.gif)';
		document.getElementById('agentlink').style.color = 'black';
	}
	else if (tab == 'searches') {
		$("#searches").fadeIn('slow');
		document.getElementById('searchtab').style.background = 'url(imgs/navigon.gif)';
		document.getElementById('searchlink').style.color = 'black';
	}
}

function placeinput(str) {
		document.getElementById('area').value = str;
		document.getElementById('dropsearch').style.display = 'none';


}

function showContact (show, contact) {
	if (contact == 'Y') {
		$("#popcontact").fadeOut('1000');
		$("#popcontactarea").fadeOut('1000');
	}
	else if (show == 'Y') {
		$("#poparea").fadeIn('1000');
		$("#popback").fadeIn('1000');
		$('html, body').animate({scrollTop:0}, 'slow');
	}
	else {
		$("#popback").fadeOut('1000');
		$("#poparea").fadeOut('1000');
	}
	
}
//ajax coding

var xmlhttp;

function showCity(str, type) {
	if (str == '' || str == ' ') {
		document.getElementById('dropsearch').style.display = 'none';
	}
	else if (keycode1 == 40) {
		
		$("#dropsearch ul li:first").css('background', '#d9d9d9');
		$("#dropsearch ul li:first").focus();
	}
	else {
		document.getElementById("dropsearch").innerHTML= '<p style="padding: 10px; color: #333333; font-weight: 700;"><img style="float: left;" src="imgs/ajax.gif"> &nbsp; &nbsp; Gathering locations';
		$("#dropsearch").slideDown('slow');
		xmlhttp=GetXmlHttpObject();
		if (xmlhttp==null)  {
		  alert ("Browser does not support HTTP Request");
		  return;
		}
		var url="libs/ajax/ajax.GetCity.php";
		url=url+"?q="+str;
		url=url+"&type="+type;
		url=url+"&sid="+Math.random();
		xmlhttp.onreadystatechange= stateChanged;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
}

function stateChanged(){
	if (xmlhttp.readyState==4){
		document.getElementById("dropsearch").innerHTML=xmlhttp.responseText;
	}
	else {
		document.getElementById("dropsearch").innerHTML= '<p style="padding: 10px; color: #333333; font-weight: 700;"><img style="float: left;" src="imgs/ajax.gif"> &nbsp; &nbsp; Gathering results';
	}
}

function GetXmlHttpObject(){
	if (window.XMLHttpRequest) {
 	 	// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
  	}
	if (window.ActiveXObject) {
  		// code for IE6, IE5
 		return new ActiveXObject("Microsoft.XMLHTTP");
  	}
	return null;
}

//slider
var timerlen = 5;
var slideAniLen = 350;

var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();

function slidedown(objname){
		$("#"+objname).slideDown('1000');
}

function slideup(objname){
	$("#"+objname).slideUp('1000');
}

function deleteImg (img, id, imagename) {
	proceed = confirm('Are you sure you wish to delete this image');
	if (proceed == true) {
		$("#imagearea1").load(secureurl + "libs/ajax/ajax.DeleteImg.php", { imgid: img, id: id, name: imagename });
	}
}
function uploadimg () {
	$('html, body').animate({scrollTop:0}, 'slow');
	$("#popback").fadeIn('slow');	
	$("#poparea").css({"height": "300px" });
	$("#poparea").fadeIn('slow');
}

function closeme(type) {
	if (type == 'contact') {
		$("#contact").slideUp('6000');
	}
	else {
		$("#poparea").fadeOut('slow');
		$("#popback").fadeOut('slow');	
	}
}

function getSearchArea (type) {
	
	$('#replacesearch').fadeOut('fast', loadthis);
	
	function loadthis() {
		$('#replacesearch').show();	
		$('#replacesearch').html('<p style="text-align:center; margin-top:40px;"><img src="imgs/ajax.gif"></p>');
		$('#replacesearch').load("libs/ajax/ajax.GetSearchForm.php", { type: type }, showarea);
	}
	function showarea () {
		$('#replacesearch').fadeIn('slow');	
	}
}

function scrollTo(type){
	if (type == 'map') {
		$('html, body').animate({
		scrollTop: $("#maphead").offset().top
		}, 2000);
	
	}
	else {
		$('html, body').animate({
		scrollTop: $("#searchsub").offset().top
		}, 2000);
	}
}

function updateCalendar (id, date1, set) {	
	date2  =  "e" + date1;
	

	$('#blah1').load(secureurl + "libs/ajax/ajax.SetCalendarDate.php", { id: id, date: date1, action: set }, changecolour);
	function changecolour() {
		x = $('#blah1').html();
		if (x == 'red') {
			$('#' + date2).css({"background-color":"#FF1D2D",  'color': '#ffffff', "text-decoration":"line-through"});
		} 
		else {
			$('#' + date2).css({"background-color":"white", 'color': '#3C3C3C', "text-decoration":"none"});
		}
	}
}

function rateaddremove (type, id) {
	if (type == 'add') {
		y = $('#ratelevel').val();
		x = Number(y)+1;
		$('#rate' + x).show();
		$('#ratelevel').val(x);
	}
	else {
		$('#rate' + id).hide();
		$('#ratedatefrom' + id).val("");
		$('#ratedateto' + id).val("");
		$('#ratedesc' + id).val("");
		$('#rateweekly' + id).val("");
		$('#rateweekday' + id).val("");
		$('#ratedays' + id).val("");
		$('#rateweekend' + id).val("");
	} 
}


//add call amount for database
function addToCalls (id, userid) {
	$(".numberholder").html('<img style="border: 0px;" src="imgs/ajax.gif"/>');
	$(".numberholder").load("libs/ajax/ajax.AddCallsToProperty.php", { id: id, agents_id: userid });
}
