function getContent(Option)
{

	var childNodeArray = document.getElementById('ContentContainer').childNodes;

	for (var i=0; i<childNodeArray.length; i++) {
		
		if(childNodeArray[i].tagName == "DIV")
		{

			/* by default make sure all contact options are hidden */
			childNodeArray[i].style.display='none';
		
		}
	
	}

	/* display the option selected */
	document.getElementById(Option).style.display='block';

}

function FormViewOnly(Container)
{
	alert(Container)

	for(var i = 0 ; i <  document.Container.elements.length ; i++){
		/* document.Container.elements[i].disabled = true */
		document.Container.elements[i].readOnly = true;
	}
	/*
	if (this.value == 'expand')
	{
		this.value='collapse';
	}
	else
	{
		this.value='expand';
	}
	*/

}

function enableDisablAll(o){

		var buttonElement = document.getElementById('buttonarea');
		if (buttonElement != null)
		{
			// Element Exists.
			document.getElementById('buttonarea').style.display='block';
		}

		if (o.value == 'Submit')
		{
			var d = true;
			var submitElement = document.getElementById('submitbutton');
			if (submitElement != null)
			{
				// Element Exists.
				document.getElementById('submitbutton').value='Confirm';
				document.getElementById('returnbutton').value='Return';
			}
			alert('Please review your request and select "Confirm"')
		}
		else
		{
			var d = false;
			var submitElement = document.getElementById('submitbutton');
			if (submitElement != null)
			{
				// Element Exists.
				document.getElementById('submitbutton').value='Submit';
				document.getElementById('returnbutton').value='Cancel';
			}
		}

		var t=document.getElementById('formoptions');
		if(t != null)
		{
			var f=t.getElementsByTagName('input');
			for(var i=0;i<f.length;i++){

				f[i].readOnly=d;
			}
			var f=t.getElementsByTagName('textarea');
			for(var i=0;i<f.length;i++){

				f[i].readOnly=d;
			}
		}
}



function CheckEmptyInput(intMarkInvalid,intMarkValid,elmToCheck)
{

	elmCheck			= document.getElementById(elmToCheck);
	var intMarkInvalid	= intMarkInvalid;
	var intMarkValid	= intMarkValid;
	
	if(elmCheck.value !== '')
	{
		if(intMarkValid == '1')
		{
			elmCheck.setAttribute('class', 'valid_input');
			elmCheck.setAttribute('className', 'valid_input');
		}
		else
		{
			elmCheck.setAttribute('class', 'reset');
			elmCheck.setAttribute('className', 'reset');
		}
	}
	else
	{
		if(intMarkInvalid == '1')
		{
			elmCheck.setAttribute('class', 'invalid_input');
			elmCheck.setAttribute('className', 'invalid_input');
		}
		else
		{
			elmCheck.setAttribute('class', 'reset');
			elmCheck.setAttribute('className', 'reset');
		}
	}
}

function enableDisableCart(o){
		var message = null;
		var buttonElement = document.getElementById('buttonarea');
		divElm = document.getElementById('formoptions');

		if (buttonElement != null)
		{
			// Element Exists.
			document.getElementById('buttonarea').style.display='block';
		}

		if (o.value == 'Submit')
		{
			divElm.setAttribute('class', 'ReadOnlyForm');
			divElm.setAttribute('className', 'ReadOnlyForm');

			var submitElement = document.getElementById('submitbutton');
			if (submitElement != null)
			{
				// Element Exists.
				document.getElementById('submitbutton').value='Confirm';
				document.getElementById('returnbutton').value='Return';
			}
			message = 'Please review your request and select "Confirm"';
		}
		else
		{
			divElm.setAttribute('class', 'EditableForm');
			divElm.setAttribute('className', 'EditableForm');

			var submitElement = document.getElementById('submitbutton');
			if (submitElement != null)
			{
				// Element Exists.
				document.getElementById('submitbutton').value='Submit';
				document.getElementById('returnbutton').value='Cancel';
			}
		}

		return message;
}


/* function to make POST/Ajax requests */
function makePOSTRequest(url, parameters) {

  http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		// http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
  } else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
  }
  if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
  }
  
  http_request.onreadystatechange = alertContents;
  http_request.open('POST', url, true);
  http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  http_request.setRequestHeader("Content-length", parameters.length);
  http_request.setRequestHeader("Connection", "close");
  http_request.send(parameters);
}


/* Handle the response from the POST request */
function alertContents() 
{
  if (http_request.readyState == 4) 
  {
	 if (http_request.status == 200) 
	 {
		result = http_request.responseText;
		if(result == "pass")
		{
			// Hide the submit button etc.
			document.getElementById('buttonarea').style.display='none';
			alert("Thank you, your request has been completed.");
		}
		else
		{
			// Display the details of the error
			alert(result);
		}
	 } 
	 else 
	 {
		alert('There was a problem with the request.');
	 }
  }
}



//Browser Support Code
function PageSections(id,mixBaseURL)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	try
	{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} 
	catch (e)
	{
		// Internet Explorer Browsers
		try
		{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch (e)
			{
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
	{
		if(ajaxRequest.readyState == 4)
		{
			var oResults = jQuery.json.decode(ajaxRequest.responseText);
			var PageContent = document.getElementById('PageContent');
			PageContent.innerHTML = oResults[0];
		}
	}
	ajaxRequest.open("GET", mixBaseURL + "/content_edit_sequence_ajax.php?intPageId=" + id, true);
	ajaxRequest.send(null); 
}



function MoveListItem(lstbxFrom,lstbxTo)
{
 var varFromBox = document.getElementById(lstbxFrom);
 var varToBox = document.getElementById(lstbxTo); 
 if ((varFromBox != null) && (varToBox != null)) 
 { 
  if(varFromBox.length < 1) 
  {
   alert('There are no items in the source ListBox');
   return false;
  }
  if(varFromBox.options.selectedIndex == -1) // when no Item is selected the index will be -1

  {
   alert('Please select an Item to move');
   return false;
  }
  while ( varFromBox.options.selectedIndex >= 0 ) 
  { 
   var newOption = new Option(); // Create a new instance of ListItem 

   newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text; 
   newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value; 
   varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox

   varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox 

  } 
 }
 return false; 
}



function Move(el,Direction)
{

	var idx = el.selectedIndex

	if (idx==-1)
	{
		alert("You must first select the item to reorder.")
	}
	else
	{

		var nxidx = idx+( Direction? -1 : 1)
		if (nxidx<0) nxidx = el.length-1
		if (nxidx>=el.length) nxidx = 0
		var oldVal = el[idx].value
		var oldText = el[idx].text
		el[idx].value = el[nxidx].value
		el[idx].text = el[nxidx].text
		el[nxidx].value = oldVal
		el[nxidx].text = oldText
		el.selectedIndex = nxidx

	}

}



function SecurityCodeValidate(formid,strCodeOne,strCodeTwo,mixBaseURL)
{

	var ajaxRequest;  // The variable that makes Ajax possible!
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}

	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4)
		{
			var oResults= jQuery.json.decode(ajaxRequest.responseText);
			if(oResults[0] == 'pass')
			{
				document.getElementById(formid).submit();
			}
			else
			{
				var mixResult = oResults[0];
				alert(mixResult);
				enableDisablAll(document.getElementById('returnbutton'));

			}
		}
	}
	ajaxRequest.open("GET", mixBaseURL + "/security_ajax_validate.php?strCodeOne=" + strCodeOne + "&strCodeTwo=" + strCodeTwo, true);
	ajaxRequest.send(null);

}

/*
function SetHeight();

Description:
Sets the height of the main div to the browser window height.
Additionally, if the browser window is resized manually by client the function is called again to re-adjust the div.
*/
function getScrollXY()
{
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' )
	{
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} 
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	/* return [ scrOfX, scrOfY ]; */
	return scrOfY;
}



function SetHeight()
{
	var myWidth = 0, myHeight = 0;


	/*
	Code below kills ie8.

	if (document.all)
	{
		cW=document.body.offsetWidth
		cH=document.body.offsetHeight
		window.resizeTo(500,500)
		barsW=500-document.body.offsetWidth
		barsH=500-document.body.offsetHeight
		myWidth=barsW+cW
		myHeight=barsH+cH
		window.resizeTo(wW,wH)
	}
	else 
	*/

	if( typeof( window.innerWidth ) == 'number' )
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScrollHeight = document.documentElement.scrollHeight;
		/* alert('detected:' + myScrollHeight + ', ' + myHeight ); */
		if(myScrollHeight>myHeight)
		{
			/* alert(myScrollHeight + '>' + myHeight); */
			/* by default we get the resolution, but if the page has scrolls the page should be larger. */
			myHeight = myScrollHeight;
		}
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	else
	{
		myWidth=window.outerWidth
		myHeight=window.outerHeight
	}
	/* document.getElementById("body_table").style.width = myWidth+"px"; */
	/* 40px is the height of the footer links area, which needs to be subtracted from the overall height to avoid scroll overflow. */
	newHeight = myHeight-40;
	document.getElementById("body_div").style.height = newHeight+"px";
	/*
		Debugging...
		window.alert( 'Width = ' + myWidth );
		window.alert( 'Height = ' + myHeight );
	*/
}



	// australianBusinessNumber(): Checks whether an ABN is valid
	function australianBusinessNumber(mixABN)
	{
		// SEE: http://www.ato.gov.au/businesses/content.asp?doc=/content/13187.htm&pc=001/003/021/002/001&mnu=610&mfp=001/003&st=&cy=1
		// Define Digit Weights
		var arrWeights	= new Array(11);
		arrWeights[0]	= 10;
		arrWeights[1]	= 1;
		arrWeights[2]	= 3;
		arrWeights[3]	= 5;
		arrWeights[4]	= 7;
		arrWeights[5]	= 9;
		arrWeights[6]	= 11;
		arrWeights[7]	= 13;
		arrWeights[8]	= 15;
		arrWeights[9]	= 17;
		arrWeights[10]	= 19;
		
		// Ensure that the ABN is of decent length
		var strABN	= String(mixABN).replace(/\s/g, '');
		if (strABN.length != 11)
		{
			return false;
		}
		
		// Perform the calculation
		var arrDigits	= strABN.toArray();

		// 1. Subtract 1 from the first (left) digit to give a new eleven digit number
		arrDigits[0]	= parseInt(arrDigits[0]) - 1;
		
		// 2. Multiply each of the digits in this new number by its weighting factor
		// 3. Sum the resulting 11 products
		var intSum	= 0;
		for (i = 0; i < 11; i++)
		{
			arrDigits[i]	= parseInt(arrDigits[i]) * arrWeights[i];
			intSum			+= arrDigits[i];
		}
		
		// 4. Divide the total by 89, noting the remainder
		var intQuotient		= intSum / 89;
		var intRemainder	= intSum % 89;
		
		// 5. If the remainder is zero the number is valid
		return (intRemainder === 0) ? true : false;
	}

	// australianCompanyNumber(): Checks whether an ACN is valid
	function australianCompanyNumber(mixACN)
	{
		// SEE: http://www.asic.gov.au/asic/asic.nsf/byheadline/Australian+Company+Number+(ACN)+Check+Digit?opendocument
		// Define Digit Weights
		var arrWeights	= new Array(8);
		arrWeights[0]	= 8;
		arrWeights[1]	= 7;
		arrWeights[2]	= 6;
		arrWeights[3]	= 5;
		arrWeights[4]	= 4;
		arrWeights[5]	= 3;
		arrWeights[6]	= 2;
		arrWeights[7]	= 1;
		
		// Ensure that the ACN is of decent length
		var strACN	= String(mixACN).replace(/\s/g, '');
		if (strACN.length != 9)
		{
			return false;
		}
		
		// Perform the calculation
		var arrDigits	= strACN.toArray();
		
		// 1. Apply weighting to digits 1 to 8
		// 2. Sum the Products
		var intSum	= 0;
		for (i = 0; i < 8; i++)
		{
			arrDigits[i]	= parseInt(arrDigits[i]) * arrWeights[i];
			intSum			+= arrDigits[i];
		}
		
		// 3. Divide by 10 to obtain remainder (aka intSum mod 10)
		var intQuotient		= intSum / 10;
		var intRemainder	= intSum % 10;
		
		// 4. Subtract the remainder from 10
		var intDifference	= 10 - intRemainder;
		
		// 5. If the difference equals the check digit (digit 9), then it is valid
		return (intDifference == parseInt(arrDigits[8])) ? true : false;
	}


	function CartAlertPopup()
	{


		var elmPopup = document.getElementById('CartMessageBox');

		
		elmPopup.style.width			= "400px";
		elmPopup.style.height			= "250px";
		elmPopup.style.zIndex			= "11";

		var HalfWidth					= window.innerWidth/2;
		var HalfHeight					= window.innerHeight/2;

		var HalfOffsetWidth				= elmPopup.offsetWidth/2;
		var HalfOffsetHeight			= elmPopup.offsetHeight/2;

		var WindowScrollX				= window.scrollX;
		var WindowScrollY				= window.scrollY;

		var WidthMinusOffsetWidth		= HalfWidth-HalfOffsetWidth;
		var HeightMinusOffsetHeight		= HalfHeight-HalfOffsetHeight;


		//var intLeft					= (((window.innerWidth / 2) - (elmPopup.offsetWidth / 2)) + window.scrollX) + "px";
		//var intTop					= (((window.innerHeight / 2) - (elmPopup.offsetHeight / 2)) + window.scrollY) + "px";
		var intLeft						= WidthMinusOffsetWidth+WindowScrollX;
		var intTop						= HeightMinusOffsetHeight+WindowScrollY;

		// center the popup
		elmPopup.style.left				= intLeft + "px";
		elmPopup.style.top				= intTop + "px";

		
		elmPopup.style.position			= 'absolute';
		elmPopup.style.display			= "block";


	}

	function CartAlertError(Error)
	{

		alert("Please complete the following fields: \n" + Error);

	}
