var win = null;

function fnForgotten() {
	var frm = document.frmLogin;

	frm.action = "/forgotten_password.php";
	frm.submit();
} //fnForgotten

function fnAddToBasket(lngID) {
	var frm = document.frmVersion;
	
	frm.hdnVersionID.value = lngID;
	frm.btnSubmit.value = "Buy";
	frm.submit();
} //fnAddToBasket

function fnCheckout(strOption) {
	var frm = document.frmCheckout;

	if ((strOption == "Shipping") || (strOption == "Billing")) {
		frm.action = "/checkout_change_address.php";
		frm.hdnMode.value = strOption;
		strOption = "";
	} //end if
	
	frm.btnSubmit.value = strOption;
	frm.submit();
} //fnCheckout 

function fnViewBasket(strOption) {
	var frm = document.frmViewBasket;
	
	if (strOption == "Empty Basket") {
		if (confirm("Are you sure?")) {
			frm.btnSubmit.value = strOption;
			frm.submit();
		} //end if
	} else {
		frm.btnSubmit.value = strOption;
		frm.submit();
	} //end if
} //fnViewBasket

function fnLimit() {
	var taObj = event.srcElement;
	if (taObj.value.length == (taObj.maxlength * 1)) return false;
} //fnLimit

function fnCount(visCnt) { 
	var taObj = event.srcElement;
	if (taObj.value.length > (taObj.maxlength * 1)) taObj.value = taObj.value.substring(0, (taObj.maxlength * 1));
	if (visCnt) visCnt.innerText = taObj.maxlength - taObj.value.length;
} //fnCount

function fnLabelWindow(sRepairNo) {
	var iWidth = 800;
	var iHeight = 600;
	var iLeft = (screen.availWidth - iWidth) / 2;
	var iTop = (screen.availHeight - iHeight) / 2;          
	var sFeatures = "toolbar=no, location=no, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, left=" + iLeft + ", top=" + iTop + ", width=" + iWidth + ", height=" + iHeight + "";

	win = window.open("/return_label.php?hdnRepairNo=" + sRepairNo, null, sFeatures, true);
	win.focus();
} //fnLabelWindow      

function fnShowWindow(sUrl, iWidth, iHeight) {
	var iLeft = (screen.availWidth - iWidth) / 2;
	var iTop = (screen.availHeight - iHeight) / 2;          
	var sFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, left=" + iLeft + ", top=" + iTop + ", width=" + iWidth + ", height=" + iHeight + "";

	win = window.open(sUrl, null, sFeatures, true);
	win.focus();
} //fnShowWindiow

function fnAddRemoveSelectBox(objFrom, objTo) {
	//Move from one box to the other box
	for (var i = 0; i < objFrom.length; i++) {
		if (objFrom.options[i].selected) {
			objTo.options[objTo.options.length] = new Option(objFrom.options[i].text, objFrom.options[i].value, false, false);
		} //end if
	} //end for
	
	//Delete selected option from the from box
	for (var i = (objFrom.options.length - 1); i >= 0; i--) {
		if (objFrom.options[i].selected) {
			objFrom.options[i] = null;
		} //end if
	} //end for
	
	//Do some sorting
	fnSortSelectBox(objFrom);
	fnSortSelectBox(objTo);
	
	//Unselect options
	objFrom.selectedIndex = -1;
	objTo.selectedIndex = -1;
} //fnAdd

function fnSortSelectBox(objForm) {
	var aryData = new Array();
	
	//If no data do nothing
	if (objForm.options == null) return;
	
	//Add data to array
	for (var i = 0; i < objForm.options.length; i++) {
		aryData[aryData.length] = new Option(objForm.options[i].text, objForm.options[i].value, objForm.options[i].defaultSelected, objForm.options[i].selected);
	} //end for
	
	//If no data do nothign
	if (aryData.length == 0) return;
	
	//Sort data
	aryData = aryData.sort(
						function fnCompare(a, b) {
							if ((a.text + "") < (b.text + "")) return -1;
							if ((a.text + "") > (b.text + "")) return 1;
							return 0;
						} //fnCompare
					);
					
	//use new sort data
	for (var i = 0; i < aryData.length; i++) {
		objForm.options[i] = new Option(aryData[i].text, aryData[i].value, aryData[i].defaultSelected, aryData[i].selected);
	} //end for
} //fnSortSelectBox
		
function fnShowImage(sImageFile, sAlt, iWidth, iHeight) {
	var objWin;
	var iLeft = (screen.availWidth - iWidth) / 2;
	var iTop = (screen.availHeight - iHeight) / 2;          
	
	if (iWidth > screen.availWidth) {
		iWidth = screen.availWidth;
	}
	
	if (iHeight > screen.availHeight) {
		iHeight = screen.availHeight;
	}
	
	objWin = window.open("", "newWindow", "width=" +iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop);
	objWin.document.open();
	objWin.document.write('<html>');
		objWin.document.write('<head>');
			objWin.document.write('<title>' + sAlt + '</title>');
		objWin.document.write('</head>');
		objWin.document.write('<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close()">'); 
			objWin.document.write('<img src=' + sImageFile + ' width=' + iWidth + ' height=' + iHeight + ' alt=' + sAlt + '>'); 
		objWin.document.write('</body>');
	objWin.document.write('</html>');
	objWin.document.close();
	objWin.focus();
} //fnShowImage

function fnShowMovie(sMovieFile, sTitle, sExt) {
	var objWin;
	var iWidth = 400; 
	var iHeight = 400;
	var iLeft = (screen.availWidth - iWidth) / 2;
	var iTop = (screen.availHeight - iHeight) / 2;          
	
	objWin = window.open("", "newWindow", "width=" +iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop);
	objWin.document.open();
		objWin.document.write(fnGetHeader(sTitle));
			if (sExt == "mpg") {
				objWin.document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="300" height="300" codebase="http://www.apple.com/qtactivex/qtplugin.cab#version=6,0,2,0">');
					objWin.document.write('<param name="controller" value="true">');
					objWin.document.write('<param name="type" value="video/mpeg">');
					objWin.document.write('<param name="autoplay" value="true">');
					objWin.document.write('<param name="target" value="myself">');
					objWin.document.write('<param name="src" value="' + sMovieFile + '">')
					objWin.document.write('<param name="pluginspage" value="http://www.apple.com/quicktime/download/indext.html">');
					objWin.document.write('<embed width="300" height="300" controller="true" target="myself" src="' + sMovieFile + '" type="video/quicktime" bgcolor="#000000" border="0" pluginspace="http://www.apple.com/quicktime/download/indext.html"></embed>');
				objWin.document.write('</object>');
			} else if (sExt == "wmv") {
				objWin.document.write('<object id="MediaPlayer" classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" align="baseline" border="0" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject" width="300" height="300">');
					objWin.document.write('<param name="FileName" value="' + sMovieFile + '">');
					objWin.document.write('<param name="ShowControls" value="1">');
					objWin.document.write('<param name="ShowPositionControls" value="0">');
					objWin.document.write('<param name="ShowAudioControls" value="1">');
					objWin.document.write('<param name="ShowTracker" value="1">');
					objWin.document.write('<param name="ShowDisplay" value="0">');
					objWin.document.write('<param name="ShowStatusBar" value="1">');
					objWin.document.write('<param name="AutoSize" value="0">');
					objWin.document.write('<param name="ShowGotoBar" value="0">');
					objWin.document.write('<param name="ShowCaptioning" value="0">');
					objWin.document.write('<param name="AutoStart" value="1">');
					objWin.document.write('<param name="AnimationAtStart" value="0">');
					objWin.document.write('<param name="TransparentAtStart" value="0">');
					objWin.document.write('<param name="AllowScan" value="1">');
					objWin.document.write('<param name="EnableContextMenu" value="1">');
					objWin.document.write('<param name="ClickToPlay" value="0">');
					objWin.document.write('<param name="InvokeURLs" value="1">');
					objWin.document.write('<param name="DefaultFrame" value="datawindow">');
					objWin.document.write('<!-- Embedded Microsoft Media Player Object for Netscape Navigator. -->');
					objWin.document.write('<embed src="' + sMovieFile + '" align="baseline" border="0" width="300" height="300" type="application/x-mplayer2" pluginspage="http://www.microsoft.com/isapi/redir.dll?prd=windows&amp;sbp=mediaplayer&amp;ar=media&amp;sba=plugin&amp;" name="MediaPlayer" showcontrols="1" showpositioncontrols="0" showaudiocontrols="1" showtracker="1" showdisplay="0" showstatusbar="1" autosize="0" showgotobar="0" showcaptioning="0" autostart="1" autorewind="0" animationatstart="0" transparentatstart="0" allowscan="1" enablecontextmenu="1" clicktoplay="0" invokeurls="1" defaultframe="datawindow"></embed>');
				objWin.document.write('</object>');			
			} //end if 
		objWin.document.write(fnGetFooter());
	objWin.document.close();
	objWin.focus();
} //fnShowMovie

function fnShowDealerMessage(sTitle, sMessage) {
	var objWin;
	var iWidth = 500; 
	var iHeight = 200;
	var iLeft = (screen.availWidth - iWidth) / 2;
	var iTop = (screen.availHeight - iHeight) / 2;          
	
	objWin = window.open("", "newWindow", "width=" +iWidth + ",height=" + iHeight + ",left=" + iLeft + ",top=" + iTop);
	objWin.document.open();
		objWin.document.write(fnGetHeader(sTitle));
			objWin.document.write(sMessage);
		objWin.document.write(fnGetFooter());
	objWin.document.close();
	objWin.focus();
} //fnShowDealerMessage

function fnGetHeader(sTitle) {
	var sTmp = "";
	
	sTmp += '<html>';
	sTmp += '<head>';
		sTmp += '<title>' + sTitle + '</title>';
		sTmp += '<link href="/styles/prolight.css" type="text/css" rel="stylesheet">';
	sTmp += '</head>';
	sTmp += '<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0">';
		sTmp += '<br>';
		sTmp += '<table align="center" width="80%" cellspacing="0" cellpadding="0" border="0">';
			sTmp += '<form action="" method="post" name="frmMovie">';
				sTmp += '<tr>'; 
					sTmp += '<td height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>'; 
					sTmp += '<td height="25" bgcolor="#EFEFEF" class="browseTitle">&nbsp;' + sTitle + '</td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td><img src="/images/blank.gif" width="1" height="10"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td align="center">';
	return sTmp;	
} //fnGetHeader

function fnGetFooter() {
	var sTmp = "";
	
					sTmp += '</td>';
				sTmp += '</tr>';
				sTmp += '<tr>'; 
					sTmp += '<td colspan="2" height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td><img src="/images/blank.gif" width="1" height="10"></td>';
				sTmp += '</tr>';					
				sTmp += '<tr>'; 
					sTmp += '<td height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>'; 
					sTmp += '<td height="25" bgcolor="#EFEFEF" align="center"><input type="button" name="btnClose" value=" Close " onclick="self.close()" class="submit"></td>';
				sTmp += '</tr>';
				sTmp += '<tr>';
					sTmp += '<td height="1" background="/images/dots.gif"><img src="/images/blank.gif" width="1" height="1"></td>';
				sTmp += '</tr>';
			sTmp += '</form>';								
		sTmp += '</table>';
	sTmp += '</body>';
	sTmp += '</html>';	
	
	return sTmp;	
} //fnGetFooter

function fnEditFaultProduct(lngID) {
	var frm = document.frmFaults;
	
	frm.action = "fault_item.php";
	frm.hdnReturnItemID.value = lngID;
	frm.submit();
} //fnEditFaultProduct

function fnClearField(vThisField){
	vThisField.value = "";
} //fnClearField

function fnOrder(lngID1, lngOrderID1, lngID2, lngOrderID2, strMode, frm) {
	if (strMode == "Up") {
		frm.hdnID1.value = lngID2;
		frm.hdnOrderID1.value = lngOrderID1;
		frm.hdnID2.value = lngID1;
		frm.hdnOrderID2.value = lngOrderID2;
	} else if (strMode == "Down") {
		frm.hdnID1.value = lngID1;
		frm.hdnOrderID1.value = lngOrderID2;
		frm.hdnID2.value = lngID2;
		frm.hdnOrderID2.value = lngOrderID1;
	} //end if
	
	frm.submit();
} //fnOrder
