function ShowPrivacyPopup(popupURL) 
{
  // open the popup window
  
    var popup = window.open(popupURL,"PrivacyPolicy",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=600,height=525,left=175,top=0');
  // set the opener if it's not already set.  it's set automatically
  // in netscape 3.0+ and ie 3.0+.
  if( navigator.appName.substring(0,8) == "Netscape" ) {
    popup.location = popupURL;
  }
}

function SetHover(elem, mClass) {

//alert (elem.className);
elem.className = mClass;
}

function ShowBirdCamPopup(popupURL) 
{
  // open the popup window
  
    var popup = window.open(popupURL,"BirdCam",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=325,height=435,left=175,top=50');
  // set the opener if it's not already set.  it's set automatically
  // in netscape 3.0+ and ie 3.0+.
  if( navigator.appName.substring(0,8) == "Netscape" ) {
    popup.location = popupURL;
  }
}

function ShowReminderPopup(popupURL) 
{
  // open the popup window
  
    var popup = window.open(popupURL,"Reminder",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=445,height=495,left=275,top=25');
  // set the opener if it's not already set.  it's set automatically
  // in netscape 3.0+ and ie 3.0+.
  if( navigator.appName.substring(0,8) == "Netscape" ) {
    popup.location = popupURL;
  }
}

function ShowPopup(popupURL, pleft, ptop, pwidth, pheight) 
{
  // open the popup window
  
var popup = window.open(popupURL,"PopUp",'toolbar=0, location=0,directories=0, status=0,menubar=0,scrollbars=1,resizable=1, width=' + (pwidth + 50) + ', height=' + (pheight + 70) + ', left=' + pleft + ', top=' + ptop);
  // set the opener if it's not already set.  it's set automatically
  // in netscape 3.0+ and ie 3.0+.
  
  if (window.focus) {popup.focus()}
  
  popup.window.resizeTo(pwidth + 50, pheight + 150)
  
  if( navigator.appName.substring(0,8) == "Netscape" ) {
    popup.location = popupURL;
  }
}


// AJAX - does ActiveX with IE, otherwise its standards compliant malarkey
function getHTTPObject()
{
	var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
	}
@else
	xmlhttp = false;
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	} return xmlhttp;
}

var http = getHTTPObject();


function handleError() {
	return true;
}



function getStockLevel(sjCodes)
{

	window.onerror = handleError;
//	var slI = document.getElementById('Debug');

	
	
  if(http && document.getElementById)
  {

	http.open("GET", "http://www.sillyjokes.co.uk/stock-level-line.php?Codes=" + sjCodes, true);
	http.onreadystatechange = function()
		{
			if (http.readyState == 4)
			{
				var ResultList = new Array();
				ResultList = http.responseText.split('|');
				for (i=0;i<ResultList.length-1;i=i+2)
				{
					var slInsert = document.getElementById('StockLevel-' + ResultList[i]);
					if (slInsert != null)
					{
						if (ResultList[i+1] == '0') {
						//	slInsert.innerHTML = "Sorry, none in stock";
							slInsert.innerHTML = "<B>Out of stock</B>";
						} else {
							if (slInsert.type == 'select-one') {
								// ResultList[i]      -  First bit of code
								// ResultList[i + 1]  -  Last code + qty, seperated by ' '
		
								a = ResultList[i+1].split(' ');
								// Debug Here
							//	slI.innerHTML = "<P>http://www.sillyjokes.co.uk/stock-level-line.php?Codes=" + sjCodes + "<BR>" + http.responseText + "</P>";
								
								
  								for (x = 0; x < a.length; x++){
  									b = a[x].split('=');
  									for (y = 0; y < slInsert.length; y++){
  										if (slInsert.options[y].value == b[0]) {
  											if (b[1] == '0') {
  												slInsert.options[y].text =   slInsert.options[y].text.replace(' - Out of stock','')  + ' - Out of stock';
   												slInsert.options[y].style.color = 'red';
   											} else {
  												slInsert.options[y].text =   slInsert.options[y].text.replace(' - Out of stock','')  + ' - ' + b[1] + ' in stock';
  												slInsert.options[y].style.color = 'black';
  											}
  										}
  									}	
  								} 		
    						 } else {
   					
    						//	slInsert.innerHTML = "<B>" + ResultList[i+1] +  " in stock</B>, ready for immediate dispatch.";
    							slInsert.innerHTML = "<B>" + ResultList[i+1] +  " in stock</B>";
							}
						}
					}

					var slInsert = document.getElementById('StockLevelShort-' + ResultList[i]);
					if (slInsert != null)
					{
						if (ResultList[i+1] == '0') {
					//		slInsert.innerHTML = "Sorry, none in stock";
							slInsert.innerHTML = "<B>Out of stock</B>";
						} else {
							slInsert.innerHTML = "<B>" + ResultList[i+1] +  " in stock.</B>";
						}
					}
				}
			}
		}
	http.send(null);

  } 
	return false;
}

function ResizeShopBox(sjCodes, cW) 
{


	var Widest = 0;
	var aWidth = 0;
	
	var ResultList = new Array();
	
	ResultList =sjCodes.split("|")
	for (i=0;i<ResultList.length;i=i+1)
		{
			if (ResultList[i] != "") {
					
				var ssBox = document.getElementById('ShoppingBox-' + ResultList[i]);
				if (ssBox != null)	{
					if (ssBox.scrollWidth > Widest) {
						Widest = ssBox.scrollWidth;
					}
				}
			}
		}

	for (i=0;i<ResultList.length;i=i+1)
		{
			if (ResultList[i] != "") {
					
				var ssBox = document.getElementById('ShoppingBox-' + ResultList[i]);
				if (ssBox != null)	{
					ssBox.setAttribute("width", Widest); 
				}
				
			}
		}

	
	aWidth = ContentWidth.scrollWidth - cW - Widest;
	
	// aWidth less than 140 then change the page format.
	
	for (i=0;i<ResultList.length;i=i+1)
		{
			if (ResultList[i] != "") {
					
				var stBreak = document.getElementById('TableBreak-' + ResultList[i]);
				if (stBreak != null)	{
					if (aWidth < 145) {
						stBreak.innerHTML = "<BR CLEAR=ALL>";
					} else {
						stBreak.innerHTML = ""; 
					}
				}
				
			}
		}
	//	pausecomp(1000);
}

function pausecomp(millis) 
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); } 
while(curDate-date < millis);
} 