// 16/07/2010

// ajax functions
function makeRequest(url,getTarget) 
{
	var httpRequest;

//	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
//		httpRequest = new XMLHttpRequest();
//		if (httpRequest.overrideMimeType) {
//			httpRequest.overrideMimeType('text/xml');
//			// See note below about this line
//		}
//	} 
//	else if (window.ActiveXObject) { // IE
//		try {
//			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
//			} 
//			catch (e) {
//					   try {
//							httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
//						   } 
//						 catch (e) {}
//					  }
//								   }
//
//	if (!httpRequest) {
//		alert('Giving up :( Cannot create an XMLHTTP instance');
//		return false;
//	}
	
	if (window.XMLHttpRequest)
  	{// code for IE7+, Firefox, Chrome, Opera, Safari
  		httpRequest = new XMLHttpRequest();
  	}
	else
  	{// code for IE6, IE5
  		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  	};
	
//	httpRequest.onreadystatechange = function() { alertContents(httpRequest,getTarget); };
	httpRequest.open('GET', url, false);
	httpRequest.send(null);
	document.getElementById(getTarget).value = httpRequest.responseText;
};

function alertContents(httpRequest, getTarget) 
{
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
			document.getElementById(getTarget).value = httpRequest.responseText;
			//alert(httpRequest.responseText);
		} else {
			alert('There was a problem with the request.');
		}
	}
};

// close pop up division
function close_pop_up(getDivision)
{
	with (parent.document.getElementById(getDivision))
	{
		style.visibility = 'hidden';
		style.width = '0px';
		style.top = '0px';
		style.height ='0px';
		style.left = '0px';
	};
};

// change the size of the page to fit the size of the browser window
function get_screen_height()
{
	var viewHeight;
	if (typeof(window.innerHeight) == 'number') 
	{ 
		//Non IE
		viewHeight = window.innerHeight; 
	}
	else
		if (document.documentElement && document.documentElement.clientHeight) 
		{ 
			//IE 6+ in 'standards compliant mode' 
			viewHeight = document.documentElement.clientHeight; 
		}
	if (viewHeight > 600)
	{
		document.getElementById('page_container_div').style.height = viewHeight - 20 + 'px';
		document.getElementById('page_content_div').style.height = viewHeight - 221 + 'px';	
		document.getElementById('page_menu_div').style.height = viewHeight - 221 + 'px';
		document.getElementById('page_footer_div').style.marginTop = viewHeight - 600 + 'px';		
		document.getElementById('page_main_div').style.top = 111 - viewHeight + 'px';
		document.getElementById('page_main_div').style.height = viewHeight - 119 + 'px';
		var productElement = document.getElementById('page_list_div_casualties')
		if (productElement != null)
		{
			document.getElementById('page_list_div_casualties').style.height = viewHeight - 360 + 'px';
			document.getElementById('page_main_div').style.overflowY = 'hidden';
		};
		var productElement = document.getElementById('page_list_div_cemeteries')
		if (productElement != null)
		{
			document.getElementById('page_list_div_cemeteries').style.height = viewHeight - 440 + 'px';
			document.getElementById('page_main_div').style.overflowY = 'hidden';
		};
		var productElement = document.getElementById('page_list_div_news')
		if (productElement != null)
		{
			document.getElementById('page_list_div_news').style.height = viewHeight - 250 + 'px';
			document.getElementById('page_main_div').style.overflowY = 'hidden';
		};
		var productElement = document.getElementById('page_list_div_foreign_war_graves_casualties')
		if (productElement != null)
		{
			document.getElementById('page_list_div_foreign_war_graves_casualties').style.height = viewHeight - 510 + 'px';
			document.getElementById('page_main_div').style.overflowY = 'hidden';
		};		
	};
};

// preload the menu images
var mImages = ['menu_0','menu_1','menu_2','menu_3','menu_4','menu_5','menu_6','menu_7','menu_8','menu_9','menu_10','menu_11','menu_12'];

function preloadImages() {
	var x, y;
	if (!document.pLoad) {
		document.pLoad = new Array(mImages.length);
		for (x = 0; x < mImages.length; x++) {
			document.pLoad[x] = new Array(2);
			for (y = 0; y < 2; y++) {
				document.pLoad[x][y] = new Image;
				switch(y) {
					case 0: document.pLoad[x][y].src = PathStr + 'images/' + mImages[x] + '.gif'; break;
					case 1: document.pLoad[x][y].src = PathStr + 'images/' + mImages[x] + '_mo.gif'; break;
				}
			}
		}
	}
};

function overImage(imgNum) {
	if (document.getElementById)
		document.getElementById(mImages[imgNum]).src = document.pLoad[imgNum][1].src;
};

function outImage(imgNum) {
	if (document.getElementById)
		document.getElementById(mImages[imgNum]).src = document.pLoad[imgNum][0].src;
};

// preload the blue menu images
var bmImages = ['menublue_0','menublue_1','menublue_2','menublue_3','menublue_4','menublue_5','menublue_6','menublue_7','menublue_8','menublue_9','menublue_10','menublue_11','menublue_12'];

function preloadImagesb() {
	var x, y;
	if (!document.pLoadB) {
		document.pLoadB = new Array(bmImages.length);
		for (x = 0; x < bmImages.length; x++) {
			document.pLoadB[x] = new Array(2);
			for (y = 0; y < 2; y++) {
				document.pLoadB[x][y] = new Image;
				switch(y) {
					case 0: document.pLoadB[x][y].src = PathStr + 'images/' + bmImages[x] + '.gif'; break;
					case 1: document.pLoadB[x][y].src = PathStr + 'images/' + bmImages[x] + '_mo.gif'; break;
				}
			}
		}
	}
};

function overImageb(imgNum) {
	if (document.getElementById)
		document.getElementById(bmImages[imgNum]).src = document.pLoadB[imgNum][1].src;
};

function outImageb(imgNum) {
	if (document.getElementById)
		document.getElementById(bmImages[imgNum]).src = document.pLoadB[imgNum][0].src;
};

// correct layout issues in IE6
function check_browser()
{
	if (navigator.userAgent.indexOf("MSIE 6.0") != -1)
	{
		document.getElementById('page_content_div').style.overflowX = 'hidden';
		document.getElementById('page_content_div').style.overflowY = 'hidden';
	};
};

// new code for popup window - 31/03/2009
function calcPopUpPos(newWinWidth, newWinHeight) 
{
	var viewHeight;
	var viewWidth;
	var newWinXY = new Array(2);
	if (typeof(window.innerHeight) == 'number') 
	{ 
		//Non IE
		viewHeight = window.innerHeight; 
		viewWidth = window.innerWidth; 
	}
	else
		if (document.documentElement && document.documentElement.clientHeight) 
		{ 
			//IE 6+ in 'standards compliant mode' 
			viewHeight = document.documentElement.clientHeight; 
			viewWidth = document.documentElement.clientWidth; 
		}
	newWinXY[0] = (viewWidth - newWinWidth) / 2;
	newWinXY[1] = (viewHeight - newWinHeight) / 2;
	return newWinXY;
};

// this is used to display the contact us page
function showPopUp(getPopUp, getWidth, getHeight, getDivision, getIframe, getContactType)
{
	document.getElementById(getDivision).innerHTML = "";
	document.getElementById(getDivision).innerHTML = "<iframe name='" + getIframe + "' id='" + getIframe + "' height='" + getHeight + "px' width='" + getWidth + "px' frameborder='0' scrolling='auto' src='" + getPopUp + ".asp?contactType=" + getContactType + "'></iframe>;";	

	var PopUpXY = calcPopUpPos(getWidth, getHeight);
	with (document.getElementById(getDivision))
	{
		style.left = PopUpXY[0] + 'px';
		style.top = PopUpXY[1] + parent.document.body.scrollTop + 'px';
		style.width = getWidth + 'px';
		style.height = getHeight + 'px';
		style.visibility = 'visible';
	};
	document.getElementById(getIframe).scrollTop = 0;
};

// this is used in the administration system to display the add pop-ups
function LoadPopUp(getPopUp, getWidth, getHeight, getDivision, getIframe)
{
	document.getElementById(getDivision).innerHTML = "<iframe name='" + getIframe + "' id='" + getIframe + "' height='" + getHeight + "px' width='" + getWidth + "px' frameborder='0' scrolling='auto' src='" + getPopUp + ".asp'></iframe>;";	
//	var PopUpXY = calcPopUpPos(getWidth, getHeight);
//	with (document.getElementById(getDivision))
//	{
//		style.left = PopUpXY[0] + 'px';
//		style.top = PopUpXY[1] + parent.document.body.scrollTop + 'px';
//		style.width = getWidth + 'px';
//		style.height = getHeight + 'px';
//		style.visibility = 'visible';
//	};
//	document.getElementById(getIframe).scrollTop = 0;
	
	openPopUp(getDivision, getWidth, getHeight, 0, getIframe);
};

// this is used in the administration system to display the edit pop-ups
function LoadEditPopUp(getPopUp, getWidth, getHeight, getDivision, getIframe, getReference)
{
	document.getElementById(getDivision).innerHTML = "<iframe name='" + getIframe + "' id='" + getIframe + "' height='" + getHeight + "px' width='" + getWidth + "px' frameborder='0' scrolling='auto' src='" + getPopUp + ".asp?from=" + getReference + "'></iframe>;";	
	openPopUp(getDivision, getWidth, getHeight, 0, getIframe);
};

function openPopUp(getDivision, getWidth, getHeight, getOffSet, getIframe)
{
	var PopUpXY = calcPopUpXY(getWidth,getHeight, getOffSet);
//	document.body.scrollTop = 0;
	with (document.getElementById(getDivision))
	{
		style.left = PopUpXY[0];
		style.top = PopUpXY[1] + parent.document.body.scrollTop;
		style.width = getWidth;
		style.height = getHeight;
		style.visibility = 'visible';
};
	document.getElementById(getIframe).scrollTop = 0;
};

function calcPopUpXY(newWinWidth, newWinHeight, offSet) 
{
  var newWinXY = new Array(2);
  newWinXY[0] = (((screen.availWidth - 10) - newWinWidth) / 2) + offSet;
  if (screen.availHeight > 800)
    scrnHeight = 800;
  else 
    scrnHeight = screen.availHeight;
  newWinXY[1] = (((scrnHeight - 30) - newWinHeight) / 2) + offSet;
  return newWinXY;
};


// tabs used in the administration system
function setupPage(tabNumber, tabNo) {
	for (x = 0; x < tabNo; x++) {
		if (x == tabNumber) {
			document.getElementById('tab' + x).className = 'leftTab';
			document.getElementById('href' + x).className = 'rightTab';
			document.getElementById('href' + x).style.color = '#323296';
		} else {
			document.getElementById('tab' + x).className = '';
			document.getElementById('href' + x).className = '';
			document.getElementById('href' + x).style.color = '#7C7E80';
		}
	}
};

function setupPageChild(tabNumber, tabNo) {
	for (x = 0; x < tabNo; x++) {
		if (x == tabNumber) {
			document.getElementById('tabChild' + x).className = 'leftTab';
			document.getElementById('hrefChild' + x).className = 'rightTab';
			document.getElementById('hrefChild' + x).style.color = '#323296';
		} else {
			document.getElementById('tabChild' + x).className = '';
			document.getElementById('hrefChild' + x).className = '';
			document.getElementById('hrefChild' + x).style.color = '#7C7E80';
		}
	}
};

// used to check if the value entered in a field is an unsigned integer
function isInteger(s) 
{
	return (s.toString().search(/^[0-9]+$/) == 0);
};