$(window).load(function() {
  $("#countrynav, #homepage_countrynav").css("margin-top", "0");
  $("#propsearch form").css("position", "relative");
  $("#countrynav, #homepage_countrynav").hide();
})

$(document).ready(function() {
  $("a.countrynav,a.propsearch,a.homepage_countrynav,a.homepage_propsearch").click(function () {
    target = "div#" + $(this).attr("class");
    $("div.deck").hide();
    $(target).show();
    return false;
  });

  $('a[rel="nofollow"]').click(function() {
    window.open($(this).attr('href'));
    return false;
  });

  $("#copyright").html("Copyright &copy; DSR - <a href=\"http://www.davidstanleyredfern.com/\">Overseas Property</a> Investment Specialists");
});

// chat functions

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


var xmlHttp;
 
function showchatondelay()
{
		
  if( readCookie( 'chatClosed' )=='yes' ){//If cookie is alread set then chat is not displayed
		
		//alert( 'no Chat Section' );
		return;
		
  }else{
		
		//alert( 'Chat Section' );
		window.setTimeout("showchat()", 10000);
  }
  //window.setTimeout("showchat()", 10000);
}

function showchat()
{
  if(!window.pageYOffset)
  {
    //strict mode
		if(!(document.documentElement.scrollTop == 0))
		{
			document.getElementById('chatbox').style.top = 50 + document.documentElement.scrollTop; + "px";
			document.getElementById('chatbox').style.left = 50 + document.documentElement.scrollLeft; + "px";
		}
		//quirks mode
		else
		{
			document.getElementById('chatbox').style.top = 50 + document.body.scrollTop; + "px";
			document.getElementById('chatbox').style.left = 50 + document.body.scrollLeft; + "px";
		}
  }
  else
  {		
		document.getElementById('chatbox').style.top = 50 + window.pageYOffset + "px";
    document.getElementById('chatbox').style.left = 50 + window.pageXOffset + "px";
  }
  
  document.getElementById('chatbox').style.display = "block";
}

function clearchatcookie()
{ 
  xmlHttp=GetXmlHttpObject()
  if (xmlHttp==null)
  {
  alert ("Browser does not support HTTP Request")
  return
  } 
  var url = "/inc/clearchatcookie.php";
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
 xmlDoc=xmlHttp.responseXML;
 document.getElementById("feedback-comments").innerHTML= 
 xmlDoc.getElementsByTagName("comments")[0].childNodes[0].nodeValue + "&nbsp;<img src='/images/feedback/" + xmlDoc.getElementsByTagName("rating")[0].childNodes[0].nodeValue + ".gif' alt='" + xmlDoc.getElementsByTagName("rating")[0].childNodes[0].nodeValue + " star rating'>";
 document.getElementById("feedback-name").innerHTML= "From " +
 xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
 new Effect.Opacity('feedback-elements', { from: 0, to: 1 })
 rollingFeedback();
 }
} 

function GetXmlHttpObject()
{ 
  var objXMLHttp=null
  if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp;
}

function closechat()
{
  //clearchatcookie();
  document.getElementById('chatbox').style.display = "none";
  createCookie( 'chatClosed', 'yes', 0 );
  //alert( readCookie( 'chatClosed' ) );
}