var d = document;
var isIEx = (d.all);
var isN4 = (d.layers);
var isN6 = (d.getElementById && !(document.all));

// Allow for NS4 font-size difference
var strFontSize;
if(isN4){
	strFontSize = "x-small";
}else{
	strFontSize = "10px";
}

/***************************************************************************
* confirmCategory(): Confirm whether user wants to add/update record without assigning a category.
***************************************************************************/
function confirmCategory(obj) {
	if (obj.Category_List.value.length == 0) {
		if (!confirm('You left the Category field blank.\nAre you sure you don\'t want to assign a category to this product?')) {
		return false;
		}
	}
}

// ####### BEGIN Search functions #######
function alertFillField() {
	alert("Please enter your search criteria in the search field.");
}

function submitQuery(strAllAny, strSearch) { // Determine whether search is on all words or any words.

var checkAll = false;
	if (strAllAny == true) {
		var checkAll = true;
	}
	if(strSearch != "") { // Strip illegal characters
		var regExpIllegalChars = /[!,@#%$^&*()+'"=]*/g;
		var regExpStripSpace = /\s+/g;
		var strLegal = strSearch;
		
		strLegal = strSearch.replace(regExpIllegalChars, "");

		while(strLegal.substring(0,1) == " ") {
			strLegal = strLegal.substring(1,strLegal.length);
		}

		while(strLegal.substring(strLegal.length-1,strLegal.length) == " ") {
			strLegal = strLegal.substring(0,strLegal.length-1);
		}

		strNoSpace = strLegal.replace (regExpStripSpace, " " );

		if(strNoSpace != "") {
			strArray = strNoSpace.split(" ");
		  for (i=0, strKeyword=""; i < strArray.length; i++) {
				strKeyword += "word" + i + "=" + strArray[i] + "&";
			}
			strQueryString = "checkAll=" + checkAll + "&" + strKeyword.substr(0, strKeyword.length - 1) + "&search=" + strNoSpace;
			location.href = "result.asp?" + strQueryString;
		}
		else {
			alertFillField();
			d.formSearch.elements[0].value = "";
			d.formSearch.elements[0].focus();
		}
	}
	else {
		alertFillField();
		d.formSearch.elements[0].focus();
	}
}
// ####### END Search functions #######

/*
function TrimStr(obj, fieldName) {
	if(obj.value.length > 255) {
		alert("You must limit the number of characters in the \"" + fieldName + "\" field to 255.\n\n** This field will now be trimmed to the maximum allowable length!");
		obj.value = obj.value.substr(0,255);
		return false;
	}
}
*/
/* TrimStr: Alert user if input has too many chars */
function TrimStr(obj, fieldName) {
	if(obj.value.length > 255) {
		alert("You must limit the number of characters in the \"" + fieldName + "\" field to 255.\n\nPlease shorten your entry by " + (obj.value.length - 255) + " characters.");
		obj.focus();
		return false;
	}else{
		return true; // Explicitly return true since multiple functions are firing during onsubmit.
	}
}


function Open_Window(page,width,height,sb,l,t) {
		window.open(page,'w1','width=' + width + ',height=' + height + ',resizable=1,status=0,scrollbars=' + sb + ',toolbar=no,left=' + l + ',top=' + t + '');
}

function IsFieldEmpty(str) {
	while(str.substring(0,1) == " ") {
		str = str.substring(1,str.length);
	}
	while(str.substring(str.length-1,str.length) == " ") {
		str = str.substring(0,str.length-1);
	}
	if (str == "") {
		alert("Please enter a keyword.");
		return false;
	}else{
		return true;
}
}

// Strip front/back white space
function StripSpace(obj){
	while(obj.value.substring(0,1) == " ") {
		obj.value = obj.value.substring(1,obj.value.length);
	}
	while(obj.value.substring(obj.value.length-1,obj.value.length) == " ") {
		obj.value = obj.value.substring(0,obj.value.length-1);
	}
}

// Verify brochure request form
function Verify(obj, strArray){
	arrForm = eval(strArray); // Transform string into array
	flgError = false;
	strError = "";
	// Strip spaces
	for(i = 0; i < arrForm.length; i++){
		StripSpace(arrForm[i][0]);
		if(arrForm[i][0].value == ""){
			strError = strError + "- " + arrForm[i][1] + "\n";
		}
	}
	if(strError != ""){
		alert("Please fill in the following required fields:\n\n" + strError);
		return false;
	}else{
		return true; // Explicitly return true since multiple functions are firing during onsubmit.
	}
}

/* openWindow: Open a new window */
function openWindow(url, w, h, sb, l, t) {
	window.open(url,'w1','width=' + w + ',height=' + h + ',resizable=1,status=0,scrollbars=' + sb + ',toolbar=no,left=' + l + ',top=' + t + '');
}

function RefreshParent(strPage) {
  top.opener.location = strPage;
  self.close();
}
