function CopyDetails()
{
	
	var checkbox_status = document.forms[0].elements['sameaddress'].checked
	
	if (checkbox_status)
	{
		document.forms[0].elements['sameaddress'].checked 	= checkbox_status;
		document.forms[0].elements['fname_bill'].value		= document.forms[0].elements['fname'].value;
		document.forms[0].elements['lname_bill'].value 		= document.forms[0].elements['lname'].value;
		document.forms[0].elements['address_bill'].value	= document.forms[0].elements['address'].value;
		document.forms[0].elements['suburb_bill'].value 	= document.forms[0].elements['suburb'].value;
		document.forms[0].elements['state_bill'].value 		= document.forms[0].elements['state'].value;
		document.forms[0].elements['country_bill'].value 	= document.forms[0].elements['country'].value;
		document.forms[0].elements['postcode_bill'].value 	= document.forms[0].elements['postcode'].value;
		document.forms[0].elements['phone_bill'].value 		= document.forms[0].elements['phone'].value;
	}
	else
	{
		document.forms[0].elements['sameaddress'].checked 	= checkbox_status;
		document.forms[0].elements['fname_bill'].value 		= '';
		document.forms[0].elements['lname_bill'].value 		= '';
		document.forms[0].elements['address_bill'].value 	= '';
		document.forms[0].elements['suburb_bill'].value 	= '';
		document.forms[0].elements['state_bill'].value 		= '';
		document.forms[0].elements['country_bill'].value 	= '';
		document.forms[0].elements['postcode_bill'].value 	= '';
		document.forms[0].elements['phone_bill'].value		= '';
	}
}

//Checks the number of characters in the nominated textbox against the specified limit
//field - the control to check
//countfield - the control to store the count
//maxlimit - the maximum number of characters permitted
function textCounter(field, countfield, maxlimit) 
{
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
    alert("Maximum limit of " + maxlimit + " characters has been exceeded. Information may be lost.");
  }
  else {
    countfield.value = maxlimit - field.value.length;
  }
}

// Swap Layer Fuction on Product Detail Page

var origWidth, origHeight;
if (document.layers) {
	origWidth = window.innerWidth; 
	origHeight = window.innerHeight;
	window.onresize = function() { if (window.innerWidth != origWidth || window.innerHeight != origHeight) history.go(0); }
}

var cur_lyr;

function swapLayers(lnk,id) {
	if (cur_lyr) hideLayer(cur_lyr);
	showLayer(id);
	cur_lyr = id;
}

function swapLayersAfter(lnk,id_h1,id_h2,id_s) {
	//if (cur_lyr) hideLayer(cur_lyr);
	showLayer(id_s);
	//cur_lyr = id_s;
	hideLayer(id_h1);
	hideLayer(id_h2);
	//var classe = color + '_box';
	//document.all['left_box'].className = classe;
	//classe = color + '_box_middle';
	//document.all['middle_box'].className = classe;
	//document.all['right_box'].className = classe;
}

function showLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = 'visible';
}

function hideLayer(id) {
	var lyr = getElemRefs(id);
	if (lyr && lyr.css) lyr.css.visibility = 'hidden';
}

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (documnet.all)? documnet.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}

function getLyrRef(lyr,doc) {
	if (document.layers) {
		var theLyr;
		for (var i=0; i<doc.layers.length; i++) {
			theLyr = doc.layers[i];
			if (theLyr.name == lyr) return theLyr;
			else if (theLyr.document.layers.length > 0)
			if ((theLyr = getLyrRef(lyr,theLyr.document)) != null)
				return theLyr;
			}
			return null;
	}
}

function init(id,lyr) {
	var lnk = getElemRefs(id);
	swapLayers(lnk,lyr);
}

// 21/10/07 BPB 
// Checks/unchecks all of the checkboxes (aspxCheckBoxID) based on the value of the 'Select All' checkbox (currBox)
function CheckAllCheckBoxes(aspxCheckBoxID, currBox)
{
	var theBox = (currBox.type == "checkbox") ? currBox : currBox.children.item[0];
	xState = theBox.checked;
	
		var reg = new RegExp( aspxCheckBoxID + "$" );
		var pageElements = document.getElementsByTagName("input");
		for(i = 0; i < pageElements.length; i++) {
				elm = pageElements[i];
				if (elm.type == 'checkbox')
				{
						if (reg.test(elm.name))
						{  
								elm.checked = xState;
						}
				}
		}
}

// 21/10/07 BPB 
// This checks if all checkboxes (aspxCheckBoxID) are checked
// It then flags the 'select all' checkbox (aspxCheckBoxAllID) accordingly 
// (i.e. if not all are checked the select all wont be selected anymore)
function AllChecked(aspxCheckBoxID, aspxCheckBoxAllID) 
{
	var bAllChecked = true;
	
	var reg = new RegExp( aspxCheckBoxID + "$" );
	var pageElements = document.getElementsByTagName("input");
	for(i = 0; i < pageElements.length; i++) 
	{
			elm = pageElements[i];
			if (elm.type == 'checkbox')
			{
				if (reg.test(elm.name) && !elm.checked)
				{
						bAllChecked = false;
				}
			}
	}

	//Switch the Select All checkbox depending on if all others are now checked or not
	reg = RegExp( aspxCheckBoxAllID + "$" );
	for(i = 0; i < pageElements.length; i++) 
	{
			elm = pageElements[i];
			if (elm.type == 'checkbox')
			{
					if (reg.test(elm.name))
					{
						elm.checked = bAllChecked;
					}
			}
	}
}
