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 swapToButton(thisIM,thisSRC){
var oversrc = "/graphics/cal/" + thisSRC + "on.jpg";
document.getElementById(thisIM).src=oversrc;

}
function swapBackButton(thisIM,thisSRC){
var oversrc = "/graphics/cal/" + thisSRC + "off.jpg";
document.getElementById(thisIM).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 = "&nbspRequired&nbsp";
return;
}

if(document.forms[0].password.value==""){
document.getElementById('passFail').innerHTML = "&nbsp<a href=/forgottenPassword.asp>Forgotten Password?</a>&nbsp";;
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 tryEnterCE(){

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 = "&nbspRequired&nbsp";
return;
}

if(document.forms[0].password.value==""){
document.getElementById('passFail').innerHTML = "&nbsp<a href=/forgottenPassword.asp>Forgotten Password?</a>&nbsp";;
return;
}

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/logInCE.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;
			} 
			if(xmlHttp.responseText=="4"){
            alert("You are not able to log-in to this website. \n\nAlthough you are a registered user of Foster websites, you are only able to log-in at the original website where you registered, and also any other websites we have added to your account profile on your behalf.\n\nIf you would also like access to this website, please contact us at marketing@foster-uk.com")
			} 
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }
   
   function logout() {
   var thisLot="1";
   
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/logOut.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);
}

// 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 siteSearchE(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="/searchResultsE.asp?kw=" + thisLot;
//}
//else {
//var url="/" + obj + "-searchResults.asp?kw=" + thisLot;
//}
document.location.href=url;
}
}

 function siteSearch2E(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="/searchResultsE.asp?kw=" + thisLot;
}
else {
var url="/" + obj + "-searchResults.asp?kw=" + thisLot;
}
document.location.href=url;
}
}

function newsMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnNews(id);
}

function popImage(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnImage(id);
}

function returnImage(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/working/returnImage.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=displayNews;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function returnNews(str)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/working/returnNews.asp";
url=url+"?id="+str;
//url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=displayNews;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function displayNews() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("newsHere").innerHTML=xmlHttp.responseText;
//resetAll();
}
else {
document.getElementById("newsHere").innerHTML="<br/><br/><br/><br/><center><img src=/graphics/common/loader.gif></center>";
}
}

function closeNews(){
document.getElementById('divThis').style.display='none';
document.getElementById('apDiv1').style.display='none';
document.body.scroll="yes";
}

function returnCal(mon)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  if(mon==13){
  returnCalAll();
  }
  else {
var url="/working/returnCal.asp";
url=url+"?mon="+mon;
xmlHttp.onreadystatechange=displayCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function returnCalAll()
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/working/returnCalAll.asp";
url=url+"?mon=13";
xmlHttp.onreadystatechange=displayCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function getYearAll()
{ 
var obj=document.forms[0].selectYear.value;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/working/returnCalAll.asp";
url=url+"?mon=13&year=" + obj;
xmlHttp.onreadystatechange=displayCal;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function displayCal() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("calHere").innerHTML=xmlHttp.responseText;
//resetAll();
}
else {
document.getElementById("calHere").innerHTML="<br/><br/><br/><br/><center><img src=/graphics/common/loader.gif></center>";
}
}

function calOver(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "calItemOn";
}

function calOut(thisId) {
var selected 
selected = document.getElementById(thisId);
selected.className = "calItem";
}

function ebMe(id){
document.getElementById('divThis').style.display='';
document.getElementById('apDiv1').style.display='';
document.body.scroll="no";
returnEvent(id);
}

function returnEvent(id)
{ 
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
var url="/working/returnEvent.asp";
url=url+"?id="+id;
xmlHttp.onreadystatechange=displayNews;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function addOutlook(obj) {
alert("If asked if you want to 'Save' or 'Open', please click [ Open ]\n\nThis event will automatically add to your electronic calendar");
document.location.href="/ics/" + obj + ".ics";

}

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 + "&icoun=" + encodeURIComponent(document.forms[0].icoun.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 + "&ityp=" + encodeURIComponent(document.forms[0].ityp.value);
thisLot = thisLot + "&isec=" + encodeURIComponent(document.forms[0].isec.value);
thisLot = thisLot + "&ioth=" + encodeURIComponent(document.forms[0].ioth.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('styp').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].ityp.value==""){
document.getElementById('styp').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";
//document.location.href=url+"?"+thisLot;
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 sendContactFormE(){

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 + "&icoun=" + encodeURIComponent(document.forms[0].icoun.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/sendMessageE.asp";
//document.location.href=url+"?"+thisLot;
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.');
         }
      }     
   }
   
   function registerMe(){
   
var canMail

document.location.href="#top";

if(document.forms[0].canMail.checked){
canMail="No";
}
else
{
canMail="Yes";
}

var thisLot;
thisLot =  "fnam=" + encodeURIComponent(document.forms[0].fnam.value);
thisLot = thisLot + "&snam=" + encodeURIComponent(document.forms[0].snam.value);
thisLot = thisLot + "&email=" + encodeURIComponent(document.forms[0].email.value);
thisLot = thisLot + "&telephone=" + encodeURIComponent(document.forms[0].telephone.value);
thisLot = thisLot + "&securityQuestion=" + encodeURIComponent(document.forms[0].securityQuestion.value);
thisLot = thisLot + "&securityAnswer=" + encodeURIComponent(document.forms[0].securityAnswer.value);
thisLot = thisLot + "&ipassword=" + encodeURIComponent(document.forms[0].ipassword.value);
thisLot = thisLot + "&company=" + encodeURIComponent(document.forms[0].company.value);
thisLot = thisLot + "&ad1=" + encodeURIComponent(document.forms[0].ad1.value);
thisLot = thisLot + "&ad2=" + encodeURIComponent(document.forms[0].ad2.value);
thisLot = thisLot + "&ad3=" + encodeURIComponent(document.forms[0].ad3.value);
thisLot = thisLot + "&ad4=" + encodeURIComponent(document.forms[0].ad4.value);
thisLot = thisLot + "&town=" + encodeURIComponent(document.forms[0].town.value);
thisLot = thisLot + "&county=" + encodeURIComponent(document.forms[0].county.value);
thisLot = thisLot + "&postcode=" + encodeURIComponent(document.forms[0].postcode.value);
thisLot = thisLot + "&country=" + encodeURIComponent(document.forms[0].country.value);
thisLot = thisLot + "&canMail=" + encodeURIComponent(canMail);
thisLot = thisLot + "&ityp=" + encodeURIComponent(document.forms[0].ityp.value);
thisLot = thisLot + "&isec=" + encodeURIComponent(document.forms[0].isec.value);
thisLot = thisLot + "&ioth=" + encodeURIComponent(document.forms[0].ioth.value);

//alert(thisLot);

var result = "&nbsp;Required&nbsp;";
document.getElementById('sfnam').innerHTML = "";
document.getElementById('ssnam').innerHTML = "";
document.getElementById('scom').innerHTML = "";
document.getElementById('semail').innerHTML = "";
document.getElementById('sque').innerHTML = "";
document.getElementById('sans').innerHTML = "";
document.getElementById('spas').innerHTML = "";
document.getElementById('stown').innerHTML = "";
document.getElementById('styp').innerHTML = "";

if(document.forms[0].fnam.value==""){
document.getElementById('sfnam').innerHTML = result;
return;
}
if(document.forms[0].snam.value==""){
document.getElementById('ssnam').innerHTML = result;
return;
}
if(document.forms[0].email.value==""){
document.getElementById('semail').innerHTML = result;
return;
}
if(document.forms[0].company.value==""){
document.getElementById('scom').innerHTML = result;
return;
}
if(document.forms[0].securityQuestion.value=="none"){
document.getElementById('sque').innerHTML = result;
return;
}
if(document.forms[0].securityAnswer.value==""){
document.getElementById('sans').innerHTML = result;
return;
}
if(document.forms[0].ipassword.value==""){
document.getElementById('spas').innerHTML = result;
return;
}
if(document.forms[0].town.value==""){
document.getElementById('stown').innerHTML = result;
return;
}
if(document.forms[0].ityp.value=="Not Specified"){
document.getElementById('styp').innerHTML = result;
return;
}


if (echeck(document.forms[0].email.value)==false){
return;
}


xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/registerMe.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 echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("You have entered an invalid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("You have entered an invalid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("You have entered an invalid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("You have entered an invalid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("You have entered an invalid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("You have entered an invalid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("You have entered an invalid email address")
		    return false
		 }
 		 return true					
	}
	
	function echeck2(str) {
		alert(str);
		
		var thisLot="id="+str;
		
		xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/checkName.asp";
//document.location.href=url+"?"+thisLot;
xmlHttp.onreadystatechange = showcando;
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 showcando() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
            if(xmlHttp.responseText=="1"){
				alert("The email address you specified is already in use by another account")
				return false;
			}
			else{
				
				return true;
			}
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }



// PASSWORD REMINDERS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function sendUserName(){

var thisAlert="&nbsp;Required&nbsp;"

//error checking........................................................................
var username = document.forms[0].myUsername.value;

// reset fields before alert.......................................................
document.getElementById("alert1").innerHTML = "";
//..........................................................................................

if(username==""){
document.getElementById("alert1").innerHTML = thisAlert;
}
else {
var thisLot;
thisLot = "username="+ encodeURIComponent(document.forms[0].myUsername.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//alert(thisLot);
var url="/working/questionMe.asp";
//document.location.href=url+"?"+thisLot; 
xmlHttp.onreadystatechange = stateChangedP;
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 sendAnswer(){

var thisAlert="&nbsp;Required&nbsp;"

//error checking........................................................................
var answer = document.forms[0].answer.value;

// reset fields before alert.......................................................
document.getElementById("alert1").innerHTML = "";
//..........................................................................................

if(answer==""){
document.getElementById("alert1").innerHTML = thisAlert;
}
else {
var thisLot;
thisLot = "answer=" + encodeURIComponent(document.forms[0].answer.value);
thisLot= thisLot + "&id=" + encodeURIComponent(document.forms[0].id.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//alert(thisLot);
var url="/working/passwordMe.asp";
//document.location.href=url+"?"+thisLot; 
xmlHttp.onreadystatechange = stateChangedP;
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 stateChangedP() { 
document.getElementById("passwordHere").innerHTML="<br/><br/><br/><br/><center><img src=/graphics/common/loader.gif></center>";
if (xmlHttp.readyState==4){ 
document.getElementById("passwordHere").innerHTML=xmlHttp.responseText;
}
else {
document.getElementById("passwordHere").innerHTML="<br/><br/><br/><br/><center><img src=/graphics/common/loader.gif></center>";
}
}


function doLogin(e){
var characterCode 
if(e && e.which){ 
e = e
characterCode = e.which
}
else{
e = event
characterCode = e.keyCode
}
if(characterCode == 13){
tryEnter();
return false 
}
else{
return true 
}
}

function getSite(obj){
document.location.href="/goto.asp?gt="+obj;
}

function delSavedPage(obj){
if (confirm('Are you sure you want to REMOVE this Saved Page?')) {
var thisLot;
thisLot =  "id=" + obj;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/delSavedPage.asp";
xmlHttp.onreadystatechange = goMyPage;
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);
}
else{
// return;
}
}

function delSavedProduct(obj){
if (confirm('Are you sure you want to REMOVE this Saved Product?')) {
var thisLot;
thisLot =  "id=" + obj;

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/working/delSavedProduct.asp";
xmlHttp.onreadystatechange = goMyPage;
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);
}
else{
// return;
}
}

function goMyPage() { 
if (xmlHttp.readyState==4){ 
document.location.href="/myPages.asp";
}
else {
// nothing ;
}
}

function updateProfile(){
var result = "&nbsp;Please confirm your password&nbsp;";
document.getElementById('pAlertHere').innerHTML = "";

if(document.forms[0].pUsername.value==""){
alert("You cannot have a blank USERNAME/EMAIL ADDRESS")
return;
}

if(document.forms[0].pAnswer.value==""){
alert("You cannot have a blank SECURITY ANSWER")
return;
}

if(document.forms[0].pCompany.value==""){
alert("You cannot have a blank COMPANY name")
return;
}

if(document.forms[0].pTelephone.value==""){
alert("You cannot have a blank TELEPHONE NUMBER")
return;
}

if(document.forms[0].pPassword2.value==""){
document.getElementById('pAlertHere').innerHTML = result;
return;
}

if(document.forms[0].pPassword1.value!=document.forms[0].pPassword2.value){
alert("Password does not match");
return;
}

var pcount = document.forms[0].pPassword2.value;
//if(pcount.length <8 || pcount.length > 12){
//alert("Password must be between 8 and 12 characters");
//return;
//}

for(var j=0; j<pcount.length; j++)
{
var alphaa = pcount.charAt(j);
var hh = alphaa.charCodeAt(0);
if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
{
}
else{
alert("Password may only contain letters and numbers");
return;
}
}

//if(pcount.match(/[\d\.]+/g)){
//nothing
//}else{
//alert("Password must contain a number");
//return;
//}

thisLot ="id=" + encodeURIComponent(document.forms[0].pId.value);
thisLot = thisLot + "&emailAddress=" + encodeURIComponent(document.forms[0].pUsername.value);
thisLot = thisLot + "&userPassword=" + encodeURIComponent(document.forms[0].pPassword2.value);
thisLot = thisLot + "&company=" + encodeURIComponent(document.forms[0].pCompany.value);
thisLot = thisLot + "&telephone=" + encodeURIComponent(document.forms[0].pTelephone.value);
thisLot = thisLot + "&securityQuestion=" + encodeURIComponent(document.forms[0].pQuestion.value);
thisLot = thisLot + "&securityAnswer=" + encodeURIComponent(document.forms[0].pAnswer.value);
thisLot = thisLot + "&canMail=" + encodeURIComponent(document.forms[0].pCanmail.value);

var url="/working/updateProfile.asp";
//document.location.href=url+"?"+thisLot;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
xmlHttp.onreadystatechange = profileUpdate;
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 profileUpdate() {
document.getElementById('pAlertHere').innerHTML = "Working...";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		 //alert("done");
document.getElementById('pAlertHere').innerHTML = "Update Complete";
         } else {
            alert("There was a problem with the request");
         }
      }   
   }
   
var thisID;

var xHere;
var iscreating=false;

function goPDF(obj){
		   if(iscreating==true){
		   alert("You are creating another PDF and cannot create/download at the same time. please be patient whilst this process completes")
	   }
	   else {

iscreating=true;
xHere="";
 xHere="pdfAlert"+obj;
 //alert(xHere);
document.getElementById(xHere).innerHTML = "<img src=/fosterPDF/loader.gif>";
thisLot = "id=" + obj;
thisID = obj;
var url="/working/pdfDo.asp";
//document.location.href=url+"?"+thisLot;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
xmlHttp.onreadystatechange = pdfUpdate;
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 pdfUpdate() {
//document.getElementById('pAlertHere').innerHTML = "Working...";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
			 //alert(thisID);
	//	 if(document.getElementById(xHere)){
document.getElementById(xHere).innerHTML = "<b><a href=# onClick=servePDF('" + thisID + "');>Click here to Download Now</a></b>";
iscreating=false;
xHere=""
		
//}
	 //alert("done");
		 //setTimeout("showPDF()",5000);
//document.location.href="/fosterPDF/download.asp?doc=Foster_Refrigerator_" + thisID + ".pdf";
         } else {
            document.write(xmlHttp.responseText);
         }
      }   
   }
   
   function servePDF(obj){
	  var xHere2 ="pdfAlert"+obj;
	   if(iscreating==true){
		   alert("You are creating another PDF and cannot download at the same time. please be patient whilst this process completes")
	   }
	   else {
document.getElementById(xHere2).innerHTML="";
document.location.href="/fosterPDF/download.asp?doc=Foster_Refrigerator_" + obj + ".pdf";
	   }
   }
   
   function goPDFR(obj){
 xHere="pdfAlert"+obj;
//if(getCookie('fosterRefrigerator')){
if(document.getElementById(xHere)){
document.getElementById(xHere).innerHTML = "<img src=/fosterPDF/loader.gif>";
}
if(document.getElementById('pdfAlert')){
document.getElementById('pdfAlert').innerHTML = "<img src=/fosterPDF/loader.gif>";
}
thisLot = "id=" + obj;
thisID = obj;
var url="/working/pdfDoR.asp";
//document.location.href=url+"?"+thisLot;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
xmlHttp.onreadystatechange = pdfUpdateR;
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);
//}
//else{
//alert("You must be a registered user and logged in to use this funtion\n\nTo register, click the link at the top of this page");
//}
}



function pdfUpdateR() {
//document.getElementById('pAlertHere').innerHTML = "Working...";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
			 if(document.getElementById('pdfAlert')){
document.getElementById('pdfAlert').innerHTML = "<b><a href=/fosterPDF/download.asp?doc=Foster_Refrigeration_System-" + thisID + ".pdf>Click here to Download Now</a></b>";
}
		 if(document.getElementById(xHere)){
document.getElementById(xHere).innerHTML = "<b><a href=/fosterPDF/download.asp?doc=Foster_Refrigeration_System-" + thisID + ".pdf>Click here to Download Now</a></b>";
}
		 //alert("done");
		 //setTimeout("showPDF()",5000);
//document.location.href="/fosterPDF/download.asp?doc=Foster_Refrigeration_System-" + thisID + ".pdf";
         } else {
            alert("There was a problem with the request");
         }
      }   
   }
   
   
   function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return true;
    }
  }
return false;
}



function alertNoGo(){
	alert("Registered users logged in to this website are able to:\n\n*Save specifications as Word or PDF files\n*Print specifications\n*Save JPG images of products\n*Save products to their Areas\n\nTo use these and many other functions, please register using the button in the title bar above.");
}
 
 
function spinGetModel2(obj){
var pageme;
var thisLot;
	
	
thisLot =  "pageId=nowt";



xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
  
var url="/spinMCL/" + obj +".asp";
xmlHttp.onreadystatechange = updateSpin;
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 updateSpin() {
      if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		 document.getElementById("360here").innerHTML=xmlHttp.responseText;
         } else {
            alert('There was a problem with the request.');
         }
      }     
   }
   
   function spinGetModel(obj,obj1,obj2){
	   document.location.href="/foster-360-product.asp?fi=" + obj + "&fw=" + obj1 + "&fh=" + obj2;  
   }
