/*-----------------------------------------------------------------------------------------------
*
*		File:						/Data/javascript/common.js
*		Created by:			Matthew Olney
*		Creation Date:	Friday, 11 August 2005
*		Modified by: 		Matthew Olney
*		Modified Date:	Sunday, 21 January 2007
*
*------------------------------------------------------------------------------------------------
*------------------------------------------------------------------------------------------------
*
*			Change Control:
*------------------------------------------------------------------------------------------------
*			<Who>					<When>				<What>
*------------------------------------------------------------------------------------------------
* 1.
*	2.
* 3.
*	4.
* 5.
*------------------------------------------------------------------------------------------------
*------------------------------------------------------------------------------------------------
*
*		Description:
*		Promotion:		N/A
*		Start Date:		N/A
*		End Date:			N/A
*
*------------------------------------------------------------------------------------------------*/

function ToggleGroup(sForm, sValue, sAccept, sElement, sType) {
	var aAccept = sAccept.split(',');
	var aElement = sElement.split(',');

	var bDisable = true;

	for (var i = 0; i < aAccept.length; i++) {
		if (aAccept[i].toString() == sValue.toString()) {
			bDisable = false;
		}
	}

	if (sType == 'I'){
		
		for (i = 0; i < aElement.length; i++) {
			document[sForm][aElement[i]].disabled = bDisable;

			if (bDisable) {
				document[sForm][aElement[i]].checked = false;
			}
		}
	} else if (sType == 'A') {
		for (i = 0; i < aElement.length; i++) {
			document[sForm][aElement[i]].disabled = bDisable;
			document[sForm][aElement[i]].checked = !bDisable;
		}
	}	else if (sType == 'D') {
		var sDisplay = 'none'

		if (!bDisable) {
			var sDisplay = 'block'
		}

		for (i = 0; i < aElement.length; i++) {
			document.getElementById(aElement[i]).style.display = sDisplay;
		}
	}	else if (sType == 'V') {
		var sDisplay = 'hidden';

		if (!bDisable) {
			var sDisplay = 'visible';
		}

		for (i = 0; i < aElement.length; i++) {
			document.getElementById(aElement[i]).style.visibility = sDisplay;
		}
	}	else if (sType == 'N') {
		var sDisplay = 'none';

		for (i = 0; i < aElement.length; i++) {
			document.getElementById(aElement[i]).style.display = sDisplay;
		}
	}	
}

function GetGroupValue(oGroup) {
	for (var i = 0; i < oGroup.length; i++) {
		var sValue = "";

		if (oGroup[i].checked) {
			sValue = oGroup[i].value;
			break;
		}
	}

	return sValue;
}

function BookmarkPage() {
	var sURL = document.location
	var sTitle = document.title
	
	if (window.external) {
		window.external.AddFavorite(sURL, sTitle);
	} else {
		alert("Sorry, your browser doesn't support this feature.");
	}
}

function PrintPage() {
	
	var sPage = location.pathname;
	if (sPage.indexOf("cart.hts") != -1 || sPage.indexOf("checkout.hts") != -1 || sPage.indexOf("accessories.hts") != -1) {
		if (confirm("To print ht.com.au correctly, please set your printer's page orientation \rto landscape and enable printing of background images in your browser \rbefore continuing.")) {
			window.print();
		}
	}
	else {
		window.print();
	}
}

function ReferPage(sReferrer, sTitle, sLink) {
	var sFormattedTitle = sTitle.replace('|', '>');
	var sURL = sLink + '?referrer=' + escape(sReferrer) + '&title=' + escape(sFormattedTitle);
	document.location = sURL;
}

function OpenWindow(sTitle, sURL, nWidth, nHeight, sScroll) {
	var nLeft = (screen.width - nWidth) / 2;
	var nTop = (screen.height - nHeight) / 2;
	var sConfigure = 'height=' + nHeight + ',width=' + nWidth + ',top=' + nTop + ',left=' + nLeft + ',resizable=no,scrollbars=' + sScroll + ',toolbar=no,menubar=no';

	window.open(sURL, sTitle, sConfigure);
}

function ParentWindow(sURL, oChild) {
	
	if (window.opener) {
		opener.window.location = sURL;
		oChild.blur();
	}
	else {
		document.location = sURL;
	}
}

function ConfirmDelete(sURL, sMsg) {
		if(confirm(sMsg)) {
				document.location = sURL;
		}
}

function KeywordSearch(oForm, tInput, sInput) {
	if(oForm[tInput].value == "Product Search" || oForm[tInput].value == "") {
		if(oForm[sInput].selectedIndex == 0 || oForm[sInput].selectedIndex == 1) {
			oForm[tInput].value = "No keyword entered";
		} else {
			oForm[tInput].value = "";
		}
	}
		
		oForm.submit();
}

function MaxLength(oInput) {
	var sMaxLength=oInput.getAttribute? parseInt(oInput.getAttribute("maxlength")) : ""
	
	if (oInput.getAttribute && oInput.value.length > sMaxLength) {
		oInput.value = oInput.value.substring(0, sMaxLength)
	}
}

function CreateFlash(classid, width, height, movie, quality, flashvars) {
	
	document.write('<object classid="' + classid + '" width="' + width + '" height="' + height + '">');
	document.write('<param name="movie" value="' + movie + '">');
	document.write('<param name="quality" value="' + quality + '" />');
	document.write('<param name="FlashVars" value="' + flashvars + '" />');
	document.write('<embed src="' + movie + '" quality="' + quality + '" FlashVars="' + flashvars + '" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + width + '" height="' + height + '"></embed></object></div>');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

