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 IsModern() {
    return (document.getElementById) ? true : false;
} //IsModern

function IsIe() {
    return (document.all) ? true : false;
} //IsIe

function IsMac() {
  return (navigator.platform.toLowerCase().indexOf("mac") != -1) ? true : false;
} //IsMax


// Returns an element from the document given its name
// For modern browses this uses getElementById; 
//    for older IEs it uses document.all; 
//    for older NS it uses document.layers (although this may not always work in the same way...)
function GetElementInDocument(strName) {    
    if (IsModern()) {
        var lngReturn = document.getElementById(strName);
        if (lngReturn == null) {
            var lngElements = document.getElementsByName(strName);
            if (lngElements.length > 0) {
                lngReturn = lngElements[0];
            } //end if
        } //end if
        
        return lngReturn;
    } else if (IsIe()) {
        return document.all[strName];
    } else {
        return document.layers[strName];
    } //end if
} //GetElementInDocument

function GetTagByName(strTagName, strFormName) {
    if (!IsIe())  {
        return document.getElementsByName(strFormName);
    } else {
        var aryObject = new Array();
        var aryElements = document.getElementsByTagName(strTagName);
        
        for (var i = 0; i < aryElements.length; i++)   {
            if (aryElements[i].name == strFormName)  {
                aryObject.push(aryElements[i]);
            } //end if
        } //end for

        return aryObject;
    } //end if
} //GetTagByName

function fnEnterKeyPressed(objEvent, objField) {
	var objForm = document.frmSearch;

	if (objEvent.keyCode != 13) {
		return true;
	} //end if

	if (objField.id == "txtKeyword") {
		fnCheckSearchText(objField);
	} else if (objField.id == "txtQty") {
		fnCheckQtyText(objField);
	} //end if
		
	if ((objField.id != "txtKeyword") && (objField.id != "txtQty")){
		objForm.submit();
	} //end if
		
	return false;	
} //fnEnterKeyPressed

function fnSearchButtonClicked() {
	var objForm = document.frmSearch;

	if (objForm.txtKeyword != null) {
		return fnCheckSearchText(objForm.txtKeyword);
	} //end if
} //fnSearchButtonClicked

function fnAddButtonClicked(id) {
	
	var objForm = eval("document.frmItem" + id);

	if (objForm.txtQty != null) {
		return fnCheckQtyText(objForm.txtQty,id);
	} //end if
} //fnAddButtonClicked

function fnCheckSearchText(objField) {
	var objForm = document.frmSearch;

	var strData = fnValidate(fnTrim(objField.value)); 
	objField.value = strData; 

	if (strData.length < 2) { 
		alert("Please enter a search term of two or more characters."); 
		return false;
	} else {
		objForm.submit();
		return false;
	} //end if
} //fnCheckSearchText

function fnCheckQtyText(objField, id) {
	var objForm = eval("document.frmItem" + id);
	//alert(objForm.value);

	var strData = fnValidate(fnTrim(objField.value), "Numbers"); 
	objField.value = strData; 

	if (strData.length < 1) { 
		alert("Please enter a valid Qty.");
		return false;
	} else if (strData == 0) {
		alert("Please Qty value can not be 0.");
		return false;
	} else {
		objForm.submit();
		return false;
	} //end if
} //fnCheckQtyText

function fnValidate(strData, strWhich) {
	var strTmpData = "";
	var strChars = "";
	
	if (strWhich == "Numbers") {
		strChars = "0123456789";
	} else {
		strChars = "abcdefghijklmnopqrstuvwxyz0123456789_. ";
	} //end if

	for (var i = 0; i < strData.length; i++) {
		var strLetter = strData.charAt(i).toLowerCase();
		if (strChars.indexOf(strLetter) != -1) {
			strTmpData = strTmpData + strData.charAt(i);
		} //end if
	} //end for

	if (strTmpData != strData) {
		alert("Invalid characters are being removed and your request will continue.");
	} //end if
	
	return strTmpData;
} //fnValidate

function fnTrim(strData) {
	var intStart = 0, intEnd = strData.length - 1;
	
	while(strData.charAt(intStart) == " ") intStart++;
	while(strData.charAt(intEnd) == " ") intEnd--;
	
	if	(intStart > intEnd) {
		return "";
	} else {
		return strData.substring(intStart, intEnd + 1);
	} //end if
} //fnTrim

function fnLimit(objField, intMaxLength) {
	if (objField.value.length == (intMaxLength * 1)) return false;
} //fnLimit

function fnCount(objField, strTag, intMaxLength) { 
	if (objField.value.length > (intMaxLength * 1)) objField.value = objField.value.substring(0, (intMaxLength * 1));
	if (document.all) {
		document.getElementById(strTag).innerText = intMaxLength - objField.value.length;
	} else {
		document.getElementById(strTag).textContent = intMaxLength - objField.value.length;
	} //end if
} //fnCount

function fnShowImage(sImageFile, sAlt, iWidth, iHeight) {
	var objWin;
	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("<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 + "\" title=\"" + sAlt + "\" />"); 
		objWin.document.write("</body>");
	objWin.document.write("</html>");
	objWin.document.close();
	objWin.focus();
} //fnShowImage

function fnBasket(strID, strMode) {
	var objForm = document.frmBakset;
	var blnRun = true;

	if (strMode == "Empty Basket") {
		if (!confirm("Are you sure?" + strMode)) {
			blnRun = false;
		}
	} else if (strMode == "Save Basket") {
		
	} else {		
		eval("objForm.txtQty.value = objForm.txtQty" + strID + ".value");
	}

	if (blnRun) {
		objForm.hdnItemID.value = strID;
		objForm.btnSubmit.value = strMode;
		objForm.submit();	
	} //end if
} //fnUpdateBasket
