// JavaScript Documentvar xmlhttp

function centerPopup(){

//alert('centerPopup');
//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function loadPopup(){
	//loads popup only if it is disabled
//	alert('loadpopup');
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}


function disablePopup1(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
		//location.reload(false);
	}
	
	//window.location.reload();
}

function savePopupDetails(nhcode,nhname,lpuname,lpucode)
{
	
	xmlhttp=GetXmlHttpObject();
	
		if (xmlhttp==null)
		{
			
		}
		

		
		var url="../scripts/SetCookie.asp";
		url=url+"?nhname="+ nhname;
		url=url+"&nhcode=" + nhcode;
		url=url+"&lpuname=" + lpuname;
		url=url+"&lpucode=" + lpucode;
		xmlhttp.onreadystatechange=stateChangedSaveCookies;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
		
		//interval 30 seconds to allow cookies to save to local machine
		setTimeout('GetNewpage()',4000);
		
		setTimeout('PageAnchor'(),5000);
//		window.location.hash="PLINK";
		
}



function getVote(int,qid)
{
	
//qid = document.question.QID.value;	
//alert("int="  + int);
//alert("qid="  + qid);

xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="scripts/poll_vote.asp";
url=url+"?vote="+int;
url=url+"&sid="+Math.random();
url=url+"&QID="+qid;
//alert(url);
xmlhttp.onreadystatechange=stateChangedPoll;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChangedPoll()
{
  if (xmlhttp.readyState==4)
  {
  document.getElementById("userpoll").innerHTML=xmlhttp.responseText;
  }
}

function stateChangedSaveCookies()
{
	//alert('readyState'+ xmlhttp.readyState)
	if (xmlhttp.readyState==4 )
		  {
	  	document.getElementById("contactArea").innerHTML=xmlhttp.responseText;
		  }
		centerPopup();
		loadPopup();
}

function tt(PID,mycGroup)
{
alert('test');
xmlhttp3=GetXmlHttpObject();
		
		
		if (xmlhttp3==null)
		{
		alert ("Your browser does not support AJAX!");
	  	return;
		}
		
		$(PID).fadeOut("fast");
		
		var url="priorityvoting.asp";
		url=url+"?mycGroup="+ mycGroup;
		url=url+"&PID="+ PID;
		xmlhttp3.onreadystatechange=stateChangedVote(PID);
		xmlhttp3.open("GET",url,true);
		xmlhttp3.send(null);
	    $(PID).fadeIn();
		
	
	
}

function GetNewpage()
{
	// Reload INDEX.ASP once data retrieved for neighbourhood	
	document.location.reload(true);
	
	//window.location.hash="#neigh";
	//setTimeout('PageAnchor()',3000);
	
	window.location.hash="PLINK";
}

function PageAnchor()
{
	
			window.location.hash="PLINK";
	
	
}


function getNeighbourhood(name)
{

	xmlhttp1=GetXmlHttpObject();

	if (xmlhttp1==null)
	{
		alert ("Your browser does not support AJAX!");
	  	return;
	}

	var url="../scripts/nhpostcode.asp";
	url=url+"?nh="+name;
	
	xmlhttp1.onreadystatechange=stateChangednh;
	xmlhttp1.open("GET",url,true);
	xmlhttp1.send(null);

}

function showNeighbourhood(varCode)
{
	//alert('welcome'+varCode)

		xmlhttp1=GetXmlHttpObject();

	if (xmlhttp1==null)
	{
		alert ("Your browser does not support AJAX!");
	  	return;
	}

	var url="scripts/nhpostcode.asp";

	url=url+"?nh="+varCode;
	url=url+"&sid="+Math.random();

	xmlhttp1.onreadystatechange=stateChangednh;
	xmlhttp1.open("GET",url,true);

}

function showCustomer(str)
{


xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
	var url="../scripts/postcode-process.asp";
	url=url+"?q="+str;
	url=url+"&sid="+Math.random();
// alert(url);
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}

function stateChanged()
{
//alert(xmlhttp.readyState);
if (xmlhttp.readyState==4)
  {
  
  document.getElementById("contactArea").innerHTML=xmlhttp.responseText;

	centerPopup();
	loadPopup();
  }
}

function stateChangednh()
{

	
	if (xmlhttp1.readyState==4)
	  {
	  	document.getElementById("contactArea").innerHTML=xmlhttp1.responseText;

	  }
		
		centerPopup();
		loadPopup();
}


function stateChangedVote(PID)
{

	if (xmlhttp3.readyState==4 || xmlhttp3.readyState==0)
	  {

	  	document.getElementById(PID).innerHTML=xmlhttp3.responseText;
		alert(document.getElementById(PID));
	  }
}


function yoursaycontent(messagecontent,nhn)
{
	
//	alert(nhn);
	//
		xmlhttp5=GetXmlHttpObject();

	if (xmlhttp5==null)
	{
		alert ("Your browser does not support AJAX!");
	  	return;
	}

	var url="../scripts/sendEmail.asp";
	
	url=url+"?messagecontent="+messagecontent;
//url=url+"?q="+str;
url=url+"&nhn="+nhn;
//	alert(url);
	xmlhttp5.onreadystatechange=stateChangedYourSay;
	//alert(url)
	xmlhttp5.open("GET",url,true);
	xmlhttp5.send(null);
}


function stateChangedYourSay()
{

//alert(xmlhttp5.readyState);
	if (xmlhttp5.readyState==4 || xmlhttp5.readyState==0)
	  {

	  	document.getElementById("your_say_middle").innerHTML=xmlhttp5.responseText;
	//	alert(xmlhttp5.responseText);
	  }
}


function stateChangedClosePopup()
{
	//alert('readystate'+ xmlhttp2.readyState);
	
	if (xmlhttp2.readyState==4)
	  {
//	  	document.getElementById("contactArea").innerHTML=xmlhttp2.responseText;
//		alert('Response Element' + xmlhttp1.responseText);
	  }
		///disablePopup();
//		centerPopup();
//		loadPopup();
}




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;
}


