// Welcome Scroll
$(function()
{$('.welcome-scroll').jScrollPane();});


// Slideshow and Contact Panel

$(document).ready(function() 
{
    $('#slideshow').cycle(
	{
		fx: 'scrollHorz',
		speed: '400', 
		timeout: 4000,
		next:   '#next', 
		prev:   '#prev',
		after: function() 
		{
			$('#caption').html( $(this).children()[0].title );
			$('#location').html( $(this).children()[0].id );

		}
	});
	
	$('#contact-us').click(function()
	{$('#panel').slideToggle('fast');});
	
});

            


// Search Form

$(function()
{
        $('#country').chainSelect('#region','/index.php/site/chained-select',
        { 
                before:function (target)
                { 
                        //$("#loading").css("display","block");
                        //$(target).css("display","none");
                },
                after:function (target)
                { 
                        //$("#loading").css("display","none");
                        //$(target).css("display","inline");
                }
        });
        $('#region').chainSelect('#city','/index.php/site/chained-select',
        { 
                before:function (target) 
                { 
                        //$("#loading").css("display","block");
                        //$(target).css("display","none");
                },
                after:function (target) 
                { 
                        //$("#loading").css("display","none");
                        //$(target).css("display","inline");
                }
        });
});

// Cookie Favorite

function setCookie(c_name,value,expiredays)
{
if (document.cookie && document.cookie != ""){
	var old_data = document.cookie.split("; ");
	for (i=0; i<old_data.length; i++){
		Cname = old_data[i].split("=")[0];
		Cvalue = old_data[i].split("=")[1];
		if (Cname==c_name){
			var Nvalue = Cvalue.split("|");
			for (v=0; v<Nvalue.length; v++) {
			  Hvalue = Nvalue[v];
			  if (Hvalue == value) {
			  	prop_exists = true;
			  	alert("Property already saved as a Favorite");
			  } else {
			  	prop_exists = false;
			  }
			  if (v==(Nvalue.length-1) && prop_exists == false){
				document.cookie = c_name+ "=" + Cvalue+"|"+value;
				alert("Property added to Favorites");
				location.reload(true);
				return;
			  };
			}			
			return;
		}
		if (i==(old_data.length-1)) {
			//start new cookie
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+expiredays);
			document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
	    	alert("Favorites list created");	
			location.reload(true);
			return;
		}
	}
}
}

// Contact Form

function blankInput(orgValue,newValue)
{

if(orgValue==newValue)
	return "";
else
	return newValue;
}
function sendForm()
{if($("#email").val()=="" || $("#contact").val()=="" || $("#phone").val()=="" || $("#people").val()=="" || $("#date_from").val()=="" || $("#date_to").val()=="" || $("#property").val()=="" || $("#budget").val()=="" || $("#message").val()=="")
{alert('Have you filled in all the boxes?'); return;}

$.post("/cgi-sys/formmail.pl",
   {  recipient: $("#recipient").val(), subject: $("#subject").val(), contact: $("#contact").val(), phone: $("#phone").val(), email: $("#email").val(), nbr_person: $("#people").val(), date_from: $("#date_from").val(), date_to: $("#date_to").val(), property: $("#property").val(), budget: $("#budget").val(), message: $("#message").val() },
   function(data){
     $("#mailform").remove();
		 $("#contactform").append("<p>Thank you for your enquiry, we will respond shortly.</p>");
   }
 );
}
