var xmlhttp;

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("displayHere").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

// Buttons and Divs

function buttonOver(thisId,thisIm){
var oversrc = "/graphics/" + thisIm + "On.jpg";
document.getElementById(thisId).src=oversrc;	
}

function buttonOut(thisId,thisIm){
var oversrc = "/graphics/" + thisIm + "Off.jpg";
document.getElementById(thisId).src=oversrc;	
}

function openDiv(thisId) {
	if(document.getElementById(thisId).style.display==""){
SlideClosed(thisId);
	}
	else{
document.getElementById(thisId).style.display="none";
SlideOpen(thisId);
}
}

function openDivOnly(thisId) {
	if(document.getElementById(thisId).style.display==""){
//nothing
	}
	else{
document.getElementById(thisId).style.display="none";
SlideOpen(thisId);
}
}


function openDivOnlyNews(thisId) {
	if(document.getElementById(thisId).style.display==""){
//nothing
	}
	else{
document.getElementById(thisId).style.display="none";
SlideOpen(thisId);
document.getElementById('newsScroller').style.height="130px";
}
}

function closeDivOnly(thisId) {
	if(document.getElementById(thisId).style.display==""){
SlideClosed(thisId);
	}
	else{
//nothing
}
}

// End -------------------------------------------------------

// Login functions

function tryEnter(){

var thisLot;
thisLot =  "userName=" + encodeURIComponent(document.forms[0].username.value);
thisLot = thisLot + "&passWord=" + encodeURIComponent(document.forms[0].password.value);
//alert(thisLot);

var result = "&nbspRequired&nbsp";
document.getElementById('userFail').innerHTML = "";
document.getElementById('passFail').innerHTML = "";

if(document.forms[0].username.value==""){
document.getElementById('userFail').innerHTML = result;
return;
}

if(document.forms[0].password.value==""){
document.getElementById('passFail').innerHTML = result;
return;
}

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/logIn.asp";
xmlHttp.onreadystatechange = alertContentsUser;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function alertContentsUser() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		 result = "&nbsp;Not Recognised&nbsp;"
            if(xmlHttp.responseText=="1"){
            document.getElementById('userFail').innerHTML = result;
			}
			if(xmlHttp.responseText=="2"){
            document.getElementById('passFail').innerHTML = result;
			} 
			if(xmlHttp.responseText=="3"){
			getUrl = location.href;
            document.location.href=getUrl;
			}           
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }

// End -------------------------------------------------------

function setHomepage(){
var id=1;
 if (confirm('Are you sure you want to update your homepage section(s)?\n\n')) {
	for (i=0; i<document.forms[0].elements.length; i++) { 
		el = document.forms[0].elements[i];
		if (el.type=="checkbox" && el.name.indexOf("hp")!=-1){
			if (el.checked) {
			id = id + "," + el.name.replace(/hp/, "");
			
}
		} 
	}
	updateHomepage(id);
	}
	
}




function updateHomepage(id){
var thisLot="id="+id;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  var url="/working/setHomepage.asp";
xmlHttp.onreadystatechange = refreshHomepage;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function refreshHomepage() {
      if (xmlHttp.readyState == 4) {
         
		 if (xmlHttp.status == 200) {		 
			getUrl = location.href;
            document.location.href=getUrl;
          
         } else {
            alert('There was a problem with the request.');
         }
      }  
	  }   
//----------------------------------------------------------------

var myTitle;

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function addFavourite(){
tt = myTitle;
var sX = findPosX(document.getElementById('favStart'));
var sY = findPosY(document.getElementById('favStart')); 
var obj = document.getElementById('favMove');
obj.innerHTML=tt;
obj.style.left=sX + "px";
obj.style.top=sY + "px";
obj.style.display="";
StartMove();
}

function StartMove(){
var obj = document.getElementById('favMove');
var sX = findPosX(obj);
var sY = findPosY(obj); 
var fX = findPosX(document.getElementById('favGoTo'));
var fY = findPosY(document.getElementById('favGoTo')); 
if(sX<fX){
pos=parseFloat(sX+((fX-sX)/10));
obj.style.left=pos + "px";
pos2=parseFloat(sY+((fY-sY)/10));
obj.style.left=pos + "px";
obj.style.top=pos2 + "px";
setTimeout("StartMove()",10);
}
if(sX>parseFloat(fX-20)){
obj.style.display="none";
obj.style.left="0px"
obj.style.top="0px"
}
}

function addToFavourite(){

var thisLot;
thisLot =  "pageId=" + encodeURIComponent(window.favId);
thisLot = thisLot + "&pageTitle=" + encodeURIComponent(window.favTitle);
thisLot = thisLot + "&pageWebsite=" + encodeURIComponent(window.favWeb);
//alert(thisLot);
myTitle=window.favTitle;


xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/addFavourite.asp";
xmlHttp.onreadystatechange = goFavourite;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function goFavourite() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            if(xmlHttp.responseText=="1"){
            alert("You must be a registered user and logged in to use this function");
			}
			if(xmlHttp.responseText=="2"){
            addFavourite();
			setTimeout("refreshPage()",500);
			}           
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }
   
   function refreshPage(){
   		getUrl = location.href;
        document.location.href=getUrl;		
}

function deleteFavourite(id){
var thisLot;
thisLot =  "pageId=" + encodeURIComponent(id);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/deleteFavourite.asp";
xmlHttp.onreadystatechange = goFavourite2;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function goFavourite2() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {      
			setTimeout("refreshPage()",500);    
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }
   
    function siteSearch(obj) {
var thisLot;
thisLot = document.forms[0].keyword.value;
if (thisLot==""){
alert("Please specify a keyword to search by");
}
else{
if(obj=="1"){
var url="/searchResults.asp?kw=" + thisLot;
}
else {
var url="/" + obj + "-searchResults.asp?kw=" + thisLot;
}
document.location.href=url;
}
}

 function siteSearch2(obj) {
var thisLot;
thisLot = document.forms[0].keyword2.value;
if (thisLot==""){
alert("Please specify a keyword to search by");
}
else{
if(obj=="1"){
var url="/searchResults.asp?kw=" + thisLot;
}
else {
var url="/" + obj + "-searchResults.asp?kw=" + thisLot;
}
document.location.href=url;
}
}

function sendContactForm(){

var thisLot;
thisLot =  "inam=" + encodeURIComponent(document.forms[0].inam.value);
thisLot = thisLot + "&icom=" + encodeURIComponent(document.forms[0].icom.value);
thisLot = thisLot + "&iadd=" + encodeURIComponent(document.forms[0].iadd.value);
thisLot = thisLot + "&itow=" + encodeURIComponent(document.forms[0].itow.value);
thisLot = thisLot + "&icou=" + encodeURIComponent(document.forms[0].icou.value);
thisLot = thisLot + "&ipos=" + encodeURIComponent(document.forms[0].ipos.value);
thisLot = thisLot + "&itel=" + encodeURIComponent(document.forms[0].itel.value);
thisLot = thisLot + "&ifax=" + encodeURIComponent(document.forms[0].ifax.value);
thisLot = thisLot + "&iema=" + encodeURIComponent(document.forms[0].iema.value);
thisLot = thisLot + "&imes=" + encodeURIComponent(document.forms[0].imes.value);
//alert(thisLot);

var result = "&nbspRequired&nbsp";
document.getElementById('snam').innerHTML = "";
document.getElementById('scom').innerHTML = "";
document.getElementById('sadd').innerHTML = "";
document.getElementById('stow').innerHTML = "";
document.getElementById('stel').innerHTML = "";
document.getElementById('sema').innerHTML = "";
document.getElementById('smes').innerHTML = "";

if(document.forms[0].inam.value==""){
document.getElementById('snam').innerHTML = result;
return;
}
if(document.forms[0].icom.value==""){
document.getElementById('scom').innerHTML = result;
return;
}
if(document.forms[0].iadd.value==""){
document.getElementById('sadd').innerHTML = result;
return;
}
if(document.forms[0].itow.value==""){
document.getElementById('stow').innerHTML = result;
return;
}
if(document.forms[0].itel.value==""){
document.getElementById('stel').innerHTML = result;
return;
}
if(document.forms[0].iema.value==""){
document.getElementById('sema').innerHTML = result;
return;
}
if(document.forms[0].imes.value==""){
document.getElementById('smes').innerHTML = result;
return;
}

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/sendMessage.asp";
xmlHttp.onreadystatechange = messageResponse;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}


function messageResponse() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            document.getElementById('thanksHere').innerHTML = xmlHttp.responseText;         
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }