var win = null;

function fnOpenDatePicker(strForm, strField) {
	var intWidth = 204;
	var intHeight = 168;
	var intLeft = (screen.availWidth - intWidth) / 2;
	var intTop = (screen.availHeight - intHeight) / 2;
	var strFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, left=" + intLeft + ", top=" + intTop + ", width=" + intWidth + ", height=" + intHeight + "";
	var strUrl = "/date_picker.php?hdnForm=" + strForm + "&hdnField=" + strField;

	win = window.open(strUrl, "DatePicker", strFeatures, true);
	win.focus();
} //fnOpenDatePicker

function fnOpenHelpWindow(lngItemID) {
	var intWidth = 300;
	var intHeight = 220;
	var intLeft = (screen.availWidth - intWidth) / 2;
	var intTop = (screen.availHeight - intHeight) / 2;
	var strFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, left=" + intLeft + ", top=" + intTop + ", width=" + intWidth + ", height=" + intHeight + "";
	var strUrl = "/help.php?hdnItemID=" + lngItemID;

	win = window.open(strUrl, "HelpWindow", strFeatures, true);
	win.focus();
} //fnOpenHelpWindow

function fnOpenPrintWindow(strUrl) {
	var intWidth = 600;
	var intHeight = 500;
	var intLeft = (screen.availWidth - intWidth) / 2;
	var intTop = (screen.availHeight - intHeight) / 2;
	var strFeatures = "toolbar=no, location=no, directories=no, status=yes, menubar=yes, scrollbars=yes, resizable=yes, left=" + intLeft + ", top=" + intTop + ", width=" + intWidth + ", height=" + intHeight + "";

	win = window.open(strUrl, "PrintWindow", strFeatures, true);
	win.focus();
} //fnOpenPrintWindow

function fnShowTnC() {
	var intWidth = 600;
	var intHeight = 500;
	var intLeft = (screen.availWidth - intWidth) / 2;
	var intTop = (screen.availHeight - intHeight) / 2;
	var strFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, left=" + intLeft + ", top=" + intTop + ", width=" + intWidth + ", height=" + intHeight + "";

	win = window.open("t_n_c.php", "TnCWindow", strFeatures, true);
	win.focus();
} //fnShowTnC

function fnPriceBreakdown(strRefNo) {
	var intWidth = 500;
	var intHeight = 250;
	var intLeft = (screen.availWidth - intWidth) / 2;
	var intTop = (screen.availHeight - intHeight) / 2;
	var strFeatures = "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, left=" + intLeft + ", top=" + intTop + ", width=" + intWidth + ", height=" + intHeight + "";

	win = window.open("/dq_price_breakdown.php?hdnRefNo=" + strRefNo, "PriceWindow", strFeatures, true);
	win.focus();
} //fnPriceBreakdown

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 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

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;
} //fnAddRemoveSelectBox

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 nothing
	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 fnSelectBoxData(objSelect, objField) {
	var strTmp = "";
	for (var i = (objSelect.options.length - 1); i >= 0; i--) {
		if (strTmp != "") strTmp += ",";
		strTmp += objSelect.options[i].value
	} //end for
	
	objField.value = strTmp;
} //fnSelectBoxData

function fnAreYouSure(objForm, strMessage) {
	if (confirm(strMessage)) {
		if (confirm("Please confirm again?")) {
			objForm.submit();
		} //end if
	} //end if
} //fnAreYouSure

var objOldID = objOldImage = null;
function fnShowElement(objNewID, objNewImage){
	if (objOldID != null) { //close down old section
		objOldID.style.display = "none";
		objOldImage.src = "/images/icon_break_down.gif";
	} //end if

	//close the same section down 
	if (objNewID == objOldID) {
		objNewID.style.display = "none";
		objOldImage.src = "/images/icon_break_down.gif";
		objNewID = null;
	} else { //open the correct one up
		objNewID.style.display = "";
		objNewImage.src = "/images/icon_break_up.gif";
	} //end if
	
	//save result
	objOldID = objNewID;
	objOldImage = objNewImage;
} //fnShowElement


var objOldNote = null;
function fnAddNote(objNewNote){
	if (objOldNote != null) { //close down old section
		objOldNote.style.display = "none";
	} //end if

	//close the same section down 
	if (objNewNote == objOldNote) {
		objNewNote.style.display = "none";
		objNewNote = null;
	} else { //open the correct one up
		objNewNote.style.display = "";
	} //end if
	
	//save result
	objOldNote = objNewNote;
} //fnAddNote

function fnHappyWithQuote() {
	var frm = document.frmSummary;
	
	if (!frm.ckbTnC.checked) {
		alert("You must agree with the Terms and Conditions.");
	} else {
		frm.btnSubmit.value=' Happy With Quote ';	
		frm.submit();
	} //end if
} //fnHappyWithQuote

function fnDoBlink() {
	var aryBlink = document.all.tags("blink");
	
	for (var i = 0; i < aryBlink.length; i++) {
		aryBlink[i].style.visibility = (aryBlink[i].style.visibility == "") ? "hidden" : "" ;
	} //end for
} //fnDoBlink

function fnStartBlink() {
	if (document.all) {
		setInterval("fnDoBlink()", 1000);
	} //end if
} //fnStartBlink
