// ###########################################################################
// #																	     #
// #  plp.js																 #
// #																	     #
// ###########################################################################

function ValidateKeywordSearch(theform, cid, plpver, categid, prodid)
{
	var j, key;
	var searchstring;
	var isapiurl;
	var sUrl;
	
	searchstring = trim(theform.ctlSearchCatalog_searchbox.value);
	isapiurl = theform.hdnIsapiKeywordSearchUrl.value;
	isapikwallurl = theform.hdnIsapiKeywordSearchAllUrl.value;
	
	if (searchstring.length == 0)
	{
		alert('Please enter a search term.');
		theform.ctlSearchCatalog_searchbox.value = '';
		theform.ctlSearchCatalog_searchbox.focus();
		return;
	}
	
	if (searchstring.length < 2)
	{
		alert('Please enter at least two characters.');
		theform.ctlSearchCatalog_searchbox.value = trim(theform.ctlSearchCatalog_searchbox.value);
		theform.ctlSearchCatalog_searchbox.focus();
		return;
	}
	
	if (theform.key.length > 1)
	{
		for (j=0; j < theform.key.length; j++){		
			if (theform.key[j].checked==true){
				key = theform.key[j].value;
				break;
			}	
		}		
	}
	else
	{
		key = 'all';
	}
	
	var cboSearchType = theform.ddlSearchType;
	var sSchType = cboSearchType.item (cboSearchType.selectedIndex).value;
  
  	if (key == 'all'){
		if (isapikwallurl=='')
			sUrl = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&key=all' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;
		else
			sUrl = isapikwallurl + '&plpver=' + plpver + '&key=all' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;
	}
	else if (key == 'category')
	{
		if (isapiurl=='')
			sUrl = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&key=category' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;		
		else
			sUrl = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&key=category' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;
	}
	else if (key == 'product')
	{
		if (isapiurl=='')
			sUrl = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&key=product' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;
		else
			sUrl = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&key=product' + '&keycateg=' + theform.hdnKeyCateg.value + '&keyprod=' + theform.hdnKeyProd.value + '&SchType=' + sSchType;
	}
	var skeyword;
	if (window.encodeURIComponent)
		skeyword = encodeURIComponent(theform.ctlSearchCatalog_searchbox.value);
	else if (window.escape)
		skeyword = escape(theform.ctlSearchCatalog_searchbox.value);
    
    //sUrl = sUrl + "&keyword=" + encodeURI(theform.ctlSearchCatalog_searchbox.value);
    sUrl = sUrl + "&keyword=" + skeyword;
    
    document.location.href = sUrl;
}

function SubmitViewItemsPage(form){
	//alert(form.action);
	var sBackToName;
	 
	sBackToName = form.hdnBackToName.value;
	if (window.encodeURIComponent)
	   sBackToName = encodeURIComponent(sBackToName);
	else if (window.escape)
		sBackToName = escape(sBackToName);

	if (form.hdnIsapiViewItemsUrl.value==''){
		strPath = "ViewItems.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
	                                  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	                                  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value  + 
	                                  "&forward=" + form.hdnForward.value + "&backtoname=" + sBackToName;
	}else{
		/*strPath = form.hdnIsapiViewItemsUrl.value + "cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
	                                  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	                                  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value  + 
	                                  "&forward=" + form.hdnForward.value + "&backtoname=" + sBackToName;
		*/
		strPath = form.hdnIsapiViewItemsUrl.value + "&plpver=" + form.hdnPlpVer.value + 
									  "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	                                  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value  + 
	                                  "&forward=" + form.hdnForward.value + "&backtoname=" + sBackToName;
	}
	
	
	//alert(form.action);
	//form.submit();
	window.location = strPath;
	return true;	
}

function SubmitGroupDetailPage(form){
	//alert(form.action);
	var isapiurl;
	
	isapiurl = form.hdnIsapiGroupDetailUrl.value;
	if (isapiurl==''){
		strPath = "GroupDetail.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
			      "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
				  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&grpid=" + form.hdnGroupID.value;		
	}else{
		/*strPath = isapiurl + "cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
				  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
				  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&grpid=" + form.hdnGroupID.value;
		*/
		strPath = isapiurl + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
				  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
				  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value;
	}

	//alert(form.action);
	//form.submit();
	window.location = strPath;
	return true;	
}

function AdvSearchDropdownPage(form){
	//alert(form.action);
	var sBackToName;
	var isapiurl; 
	 
	isapiurl = form.hdnIsapiAdvancedSearchResultsUrl.value;
	
	sBackToName = form.hdnBackToName.value;
	if (window.encodeURIComponent)
	   sBackToName = encodeURIComponent(sBackToName);
	else if (window.escape)
		sBackToName = escape(sBackToName);
		
	if (isapiurl==''){
		strPath = "AdvancedSearchResults.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
	          "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	          "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
	          "&backtoname=" + sBackToName;
	}else{
		/*strPath = isapiurl + "cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
	          "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	          "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
	          "&backtoname=" + sBackToName;	
	    */
	    strPath = isapiurl +  "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
	          "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1" + 
	          "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
	          "&backtoname=" + sBackToName;	
	}	
	
	//alert(form.action);
	//form.submit();
	window.location = strPath;
	return true;	
}

function KeywordSearchDropdownPage(form){
	//alert(form.action);
	var isapiurl;
	
	isapiurl = form.hdnIsapiKeywordResultsUrl.value;
	if (isapiurl.indexOf('/internal/',0) > -1)
		isapiurl='';
			  
	if (isapiurl==""){
		strPath = "KeywordSearchResults.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
				"&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
				"&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
				"&keyword=" + form.hdnKeyword.value + "&key=" + form.hdnKey.value + "&keycateg=" + form.hdnKeyCateg.value +
				"&keyprod=" + form.hdnKeyProd.value + "&SchType=" + form.hdnSearchType.value;	
	}else{
		/*strPath = isapiurl + "&cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
			  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
			  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
			  "&keyword=" + form.hdnKeyword.value + "&key=" + form.hdnKey.value + "&keycateg=" + form.hdnKeyCateg.value +
			  "&keyprod=" + form.hdnKeyProd.value;
		*/
		strPath = isapiurl + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + 
			  "&prodid=" + form.hdnProdID.value  + "&pagesize=" + form.drpdnItemsPerPage.value  + "&pagenum=1"  + 
			  "&sortid=" + form.hdnSortID.value + "&sortorder=" + form.hdnSortOrder.value + "&filter=" + form.hdnFilter.value + 
			  "&keyword=" + form.hdnKeyword.value + "&key=" + form.hdnKey.value + "&keycateg=" + form.hdnKeyCateg.value +
			  "&keyprod=" + form.hdnKeyProd.value + "&SchType=" + form.hdnSearchType.value;
	}

	//alert(form.action);
	//form.submit();
	window.location = strPath;
	return true;	
}

function drpdnImageList_OnChange(form){
	var isapiurl;
	
	isapiurl = form.hdnIsapiBrowserUrl.value;
	
	if (form.drpdnImageList.value!='0'){
		if (isapiurl==''){
			strPath = "ImageBrowser.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value  + "&itemid=" + form.hdnItemID.value  + "&assetid="  + form.drpdnImageList.value + "&qlty=" + form.hdnQuality.value + "&size=" + form.hdnSize.value + "&mode=" + form.hdnMode.value;	
		}else{
			//strPath = isapiurl + "cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value  + "&itemid=" + form.hdnItemID.value  + "&assetid="  + form.drpdnImageList.value + "&qlty=" + form.hdnQuality.value + "&size=" + form.hdnSize.value + "&mode=" + form.hdnMode.value;		
			strPath = isapiurl + "&plpver=" + form.hdnPlpVer.value + "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value  + "&itemid=" + form.hdnItemID.value  + "&assetid="  + form.drpdnImageList.value + "&qlty=" + form.hdnQuality.value + "&size=" + form.hdnSize.value + "&mode=" + form.hdnMode.value;		
		}
		
		window.location = strPath;
		return true;	
	}else{
		return false;	
	}
}

function IsAnyItemChecked(form){
	var is_ItemChecked = false; 
	var is_Capabilities = false;
	
	form.hdnProductIDs.value='';
	
	var chkItemGroup=eval(form.chkItemGroup);
	
	if (chkItemGroup)
	{
		//check if chkItemGroup is an array or a single object
		if (form.chkItemGroup.length > 1){
			for (i=0; i < form.chkItemGroup.length; i++){
				if (form.chkItemGroup[i].checked){
					is_ItemChecked = true;
					//build ProductIDs
					form.hdnProductIDs.value = form.hdnProductIDs.value + form.hdnProductIDGroup[i].value + ',';
					//BEGIN 2.5 *********
					if (form.hdnCapabilitiesFlag[i].value=="True"){
					   is_Capabilities = true;
					   form.chkItemGroup[i].checked=false;
					}
					//END 2.5 *********
				}
			}
		}else{
			if (form.chkItemGroup.checked){
				is_ItemChecked = true;
				form.hdnProductIDs.value = form.hdnProductIDGroup.value;
				//BEGIN 2.5 *********
				if (form.hdnCapabilitiesFlag.value=="True"){
					is_Capabilities = true;
					form.chkItemGroup.checked=false;
				}
				//END 2.5 *********
			}		
		}
			
		if (is_ItemChecked == false){		
			alert('You must select at least one product');
			return false;
		}
		else{
		    if(is_Capabilities == true)
		    {
				alert("A capabilities item cannot be added to the shopping cart.");
				return false;
		    }
		    else
		    {
				form.submit();
				return true;
			}		
		}
	}
	else
	{
		alert('You must select at least one item.');
		return false;
	}
}


function IsAnyItemChecked_TEST(form){
	var is_ItemChecked = false; 
	
	okay = false;
	if (okay == false){
		alert('You must complete all required fields before adding any items to the cart.');
		return false;
	}else{
		return true;
	}			
}

function ValidateItemSelection(form,type,cid,plpver,categid,prodid,origin){
//function ValidateItemSelection(form){
	var nCount;
	var itemids='';
	var prodids='';
	var i;
	var prevpage='';
	nCount = 0;
	
	//check if chkItemGroup is an array or a single object
	var chkItemGroup=eval(form.chkItemGroup);
	
	if (chkItemGroup)
	{
		if (form.chkItemGroup.length > 1){
			for (i=0; i < form.chkItemGroup.length; i++){
				if (form.chkItemGroup[i].checked){
					itemids = itemids + form.chkItemGroup[i].value + '+';
					prodids = prodids + form.hdnProductIDGroup[i].value + '+';
					nCount = nCount + 1;
				}
			}
		}else{
			if (form.chkItemGroup.checked){
				itemids = itemids + form.chkItemGroup.value + '+';
				prodids = prodids + form.hdnProductIDGroup.value + '+';
				nCount = nCount + 1;
			}
		}
	}
	
	if (type=='compare'){
		if ((nCount > 1) && (nCount <= 5)){	
			//alert('CompareItems.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&itemids=' + itemids);
			//alert(form.hdnIsapiCompareItemsUrl.value);
			if (form.hdnIsapiCompareItemsUrl.value==''){
				window.location = "CompareItems.aspx?cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin;
			}else{
				//window.location = form.hdnIsapiCompareItemsUrl.value + "cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin;
				window.location = form.hdnIsapiCompareItemsUrl.value + "&plpver=" + plpver + "&categid=" + categid + "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin;
			}
			
			return true;
		}else{
			alert('Please select between 2 and 5 items.');
			return false;		
		}
	}else if (type=='request'){
		if ((nCount >= 1) && (nCount <= 5)){	
			prevpage = document.URL;			
			if (origin=='keyword'){
				if (prevpage.indexOf('keyword=')==-1){
					prevpage = prevpage + '&keyword=' + form.hdnKeyword.value;
				}
			}
			
			//SetCookie('plp_previous_page', prevpage);	
			
			// this is for ISAPI version of Request Information originating from View Items, KW and Group Detail
			// when ISAPI is true, cookie saved via javascript is not recognized by Readcookie() from code-behind
			if (window.encodeURIComponent)
				prevpage = encodeURIComponent(prevpage);
			else if (window.escape)
				prevpage = escape(prevpage);	
			
			if (form.hdnIsapiRequestInfoUrl.value==''){
				window.location = "RequestInformation.aspx?cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
			                      "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin + 
			                      "&prevpage=" + prevpage;
			}else{
				/*window.location = form.hdnIsapiRequestInfoUrl.value + "cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
			                      "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin + 
			                      "&prevpage=" + prevpage;
			    */
			    window.location = form.hdnIsapiRequestInfoUrl.value + "&plpver=" + plpver + "&categid=" + categid + 
			                      "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin + 
			                      "&prevpage=" + prevpage;
			}
			return true;

			/*			
			if (form.hdnIsapiRequestInfoUrl.value==''){
				form.action = "RequestInformation.aspx?cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
			                      "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin;
			}else{
				form.action = form.hdnIsapiRequestInfoUrl.value + "cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
			                      "&prodid=" + prodid + "&prodids=" + prodids + "&itemids=" + itemids + "&origin=" + origin;
			}			
			form.submit();
					
			return true;			
			*/
            
		}else{
			if (origin=='compare'){
				alert('Please select at least one item.');
			}else{
				alert('Please select between 1 and 5 items.');
			}
			return false;		
		}
	}
}

function ValidateProductSelection(form,type,cid,plpver,categid,prodid,origin){
	var nCount;
	var prodids='';
	var prevpage='';
	nCount = 0;
		
	//check if chkProdGroup is an array or a single object
	if (form.chkProdGroup.length > 1){
		for (i=0; i < form.chkProdGroup.length; i++){
			if (form.chkProdGroup[i].checked){
				prodids = prodids + form.chkProdGroup[i].value + '+';
				nCount = nCount + 1;
			}
		}
	}else{
		//alert('here2');
		if (form.chkProdGroup.checked){
			prodids = prodids + form.chkProdGroup.value + '+';
			nCount = nCount + 1;
		}
	}
	
	if ((nCount >= 1) && (nCount <= 5)){	
		if (type=='request'){
			prevpage = document.URL;			
			if (origin=='keyword'){
				if (prevpage.indexOf('keyword=')==-1){
					prevpage = prevpage + '&keyword=' + form.hdnKeyword.value;
				}
			}
			//SetCookie('plp_previous_page', prevpage);
			
			// this is for ISAPI version of Request Information originating from View Items, KW and Group Detail
			// when ISAPI is true, cookie saved via javascript is not recognized by Readcookie() from code-behind
			if (window.encodeURIComponent)
				prevpage = encodeURIComponent(prevpage);
			else if (window.escape)
				prevpage = escape(prevpage);				

			if (form.hdnIsapiRequestInfoUrl.value==''){
				window.location = "RequestInformation.aspx?cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
					              "&prodid=" + prodid + "&prodids=" + prodids + "&origin=" + origin +  "&itemids=" + 
			                      "&prevpage=" + prevpage;
			}else{
				/*window.location = form.hdnIsapiRequestInfoUrl.value + "cid=" + cid + "&plpver=" + plpver + "&categid=" + categid + 
					              "&prodid=" + prodid + "&prodids=" + prodids + "&origin=" + origin +  "&itemids=" + 
			                      "&prevpage=" + prevpage;
				*/
				window.location = form.hdnIsapiRequestInfoUrl.value + "&plpver=" + plpver + "&categid=" + categid + 
					              "&prodid=" + prodid + "&prodids=" + prodids + "&origin=" + origin +  "&itemids=" + 
			                      "&prevpage=" + prevpage;
			}

		}		
		return true;
	}
	else{
		alert('Please select up to five products.');
		return false;		
	}
}

function IsNumeric(strCheck) {
    var cnt = 0, c;
    
    strCheck = strCheck.replace(/(\d),(\d)/g, '$1$2');
    for ( cnt = 0; cnt < strCheck.length; cnt++  ) {
      c = strCheck.charAt(cnt);
        if ( c < "0" || c > "9" ) {
            return false;
        }
    } return true;
}

function IsInteger(strCheck) {
	//checks for positive and negative integers
    var cnt = 0, c;
    
	strCheck = strCheck.replace(/(\d),(\d)/g, '$1$2');
    for ( cnt = 0; cnt < strCheck.length; cnt++  ) {
      c = strCheck.charAt(cnt);
		if (((c == "+") || (c == "-")) && (cnt==0)) {
			//do nothing
        }else if ( c < "0" || c > "9" ) {
            return false;
        }
    } return true;
}

function ValidateExpressOrder(form){
	var isapiurl;
    isapiurl = form.hdnIsapiExpressUrl.value;
    
	if ((form.txtItem1.value=='') && (form.txtItem2.value=='') &&
	    (form.txtItem3.value=='') && (form.txtItem4.value=='') &&
	    (form.txtItem5.value=='') && (form.txtItem6.value=='')){
	    
	    alert('Please enter an Item ID.');
	    return false;
	}else if (((!form.txtItem1.value=='') && (!IsNumeric(form.txtQty1.value))) || 
	    ((!form.txtItem2.value=='') && (!IsNumeric(form.txtQty2.value))) || 
	    ((!form.txtItem3.value=='') && (!IsNumeric(form.txtQty3.value))) || 
	    ((!form.txtItem4.value=='') && (!IsNumeric(form.txtQty4.value))) || 
	    ((!form.txtItem5.value=='') && (!IsNumeric(form.txtQty5.value))) ||
	    ((!form.txtItem6.value=='') && (!IsNumeric(form.txtQty6.value)))){
	    
		alert('Please enter whole integers for quantity.');
		return false;
	}else if (((!form.txtItem1.value=='') && (form.txtQty1.value<=0)) || 
	          ((!form.txtItem2.value=='') && (form.txtQty2.value<=0)) || 
			  ((!form.txtItem3.value=='') && (form.txtQty3.value<=0)) || 
			  ((!form.txtItem4.value=='') && (form.txtQty4.value<=0)) ||
			  ((!form.txtItem5.value=='') && (form.txtQty5.value<=0)) ||
			  ((!form.txtItem6.value=='') && (form.txtQty6.value<=0))){
			  
		alert('Please enter a positive value for quantity.');
		return false;
	}
	
	if (isapiurl==''){
		form.action = "ExpressOrdering.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + 
		  		      "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + "&action=additems";
	}else{
		//form.action = isapiurl + "cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + 
		//  		      "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + "&action=additems";
		form.action = isapiurl + "&plpver=" + form.hdnPlpVer.value + 
		  		      "&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + "&action=additems";
	}	

	form.submit();
	return true;
}

function ValidateOrderQty(obj, hdnMinOrderQty, prodid, itemid, carttype, seqid){
	var okay;
	var minorder;
	
	//get the minimum order qty
	minorder = hdnMinOrderQty.value;
	
	if(IsNumeric(obj.value)){
		//check if order qty is at least min order qty
		if(parseInt(obj.value) < parseInt(minorder)){
			okay = false;
			alert('Order quantity should be at least ' + minorder + ".");
		}
	}else{
		okay = false;
		alert('Please enter a numeric value.');
	}
	
	if(okay==false){
		obj.value = minorder;
		return false;
	}else{
		return true;
	}
}

function ChangeListPrice(theform, obj, prodid, itemid, carttype, seqid, attrid, priceplus, origlistprice){
	var pricelabel = document.getElementById("lbl_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid);
	var labelMessage = document.getElementById("lbl_Message_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid);
	var dprice, dorigprice, newprice, prevprice;
	var pricelabel;
	var attrvalueid;
	var i;
	var objListBox;

	pricelabelvalue = pricelabel.childNodes.item(0).nodeValue;
	
  	if (pricelabelvalue=='QUOTE'){
		labelMessage.style.display = 'none';		// do not display the message for revised price		
	}else{
		dorigprice = pricelabel.childNodes.item(0).nodeValue.substring(1);		
		dorigprice = dorigprice.replace(/(\d),(\d)/g, '$1$2');
		dorigprice = parseFloat(dorigprice);			
		
		if(obj.type=='checkbox'){
			dprice = priceplus;
			dprice = dprice.replace(/(\d),(\d)/g, '$1$2');
			dprice = parseFloat(dprice.substring(1));
			
			if (obj.checked == true){
				newprice = dorigprice + dprice;
			}else{
				newprice = dorigprice - dprice;
			}		
		
			//round off to 2 decimal places
			newprice = (Math.round(newprice*100))/100;
			
			newprice = newprice.toString();
			if (newprice.indexOf(".") < 0){
				newprice = newprice + ".00";
			}
			
			if (newprice.substring(newprice.indexOf(".") + 1).length == 1){
				newprice = newprice + "0";
			}

			//change the List Price
			pricelabel.childNodes.item(0).nodeValue = '$' + newprice;    
		
			//display message
			if (newprice != origlistprice){
				labelMessage.childNodes.item(0).nodeValue = 'Revised price includes options selected below.';    					
			}else{
				labelMessage.childNodes.item(0).nodeValue = '';    					
			}	
					
		}else if(obj.type=='select-multiple'){
			if (theform["hdnListBoxAttrHasPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value=='yes'){
				newprice = dorigprice;
				
				objListBox = theform["listbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid];
				
				for (i=0; i < objListBox.options.length; i++){
					attrvalueid = objListBox.options[i].value;
					if (attrvalueid != '0'){					
						if (objListBox.options[i].selected==true){
							//if not previously selected, then add
							if (theform["hdnListBoxPrevSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value == 'no'){
								//add the price increment
								dprice = theform["hdnListBoxPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value;
								dprice = dprice.replace(/(\d),(\d)/g, '$1$2');
								dprice = parseFloat(dprice.substring(1));	
								newprice = newprice + dprice;
								
								theform["hdnListBoxPrevSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value = 'yes';
							}
						}else{
							//if previously selected, then minus
							if (theform["hdnListBoxPrevSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value == 'yes'){
								dprice = theform["hdnListBoxPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value;
								dprice = dprice.replace(/(\d),(\d)/g, '$1$2');
								dprice = parseFloat(dprice.substring(1));	
								newprice = newprice - dprice;
								
								theform["hdnListBoxPrevSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value = 'no';
							}			
						}
					}
				}	
				
				
				//round off to 2 decimal places
				newprice = (Math.round(newprice*100))/100;
				
				newprice = newprice.toString();
				if (newprice.indexOf(".") < 0){
					newprice = newprice + ".00";
				}				
				
				if (newprice.substring(newprice.indexOf(".") + 1).length == 1){
					newprice = newprice + "0";
				}

				//change the List Price
				pricelabel.childNodes.item(0).nodeValue = '$' + newprice;    
			
				//display message
				if (newprice != origlistprice){
					labelMessage.childNodes.item(0).nodeValue = 'Revised price includes options selected below.';    					
				}else{
					labelMessage.childNodes.item(0).nodeValue = '';    					
				}					
			}	
							
		}else if(obj.type=='radio'){
			if (theform["hdnRadioAttrHasPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value=='yes'){
				dprice = priceplus;
				dprice = dprice.replace(/(\d),(\d)/g, '$1$2');
				dprice = parseFloat(dprice.substring(1));	
				
				prevprice = theform["hdnRadioPrevPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value;
				prevprice = prevprice.replace(/(\d),(\d)/g, '$1$2');
				prevprice = parseFloat(prevprice.substring(1));	
				
				newprice = dorigprice + dprice - prevprice;
				
				theform["hdnRadioPrevPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value = priceplus;
				
				//round off to 2 decimal places
				newprice = (Math.round(newprice*100))/100;
				
				newprice = newprice.toString();
				if (newprice.indexOf(".") < 0){
					newprice = newprice + ".00";
				}

				if (newprice.substring(newprice.indexOf(".") + 1).length == 1){
					newprice = newprice + "0";
				}
				
				//change the List Price
				pricelabel.childNodes.item(0).nodeValue = '$' + newprice;    
			
				//display message
				if (newprice != origlistprice){
					labelMessage.childNodes.item(0).nodeValue = 'Revised price includes options selected below.';    					
				}else{
					labelMessage.childNodes.item(0).nodeValue = '';    					
				}	
			}
			
		}else if(obj.type=='select-one'){
			newprice = dorigprice;
			
			if (theform["hdnDrpdnAttrHasPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value=='yes'){				
				attrvalueid = theform["drpdn_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value;
				
				if (attrvalueid != '0'){
					dprice = theform["hdnDrpdnPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrvalueid_" + attrvalueid].value;
					dprice = dprice.replace(/(\d),(\d)/g, '$1$2');
					dprice = parseFloat(dprice.substring(1));	
				}else{
					dprice = 0;	
				}
				
				prevprice = theform["hdnDrpdnPrevPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value;
				prevprice = prevprice.replace(/(\d),(\d)/g, '$1$2');
				prevprice = parseFloat(prevprice.substring(1));	
				
				if ((dprice > 0) || (prevprice > 0)){
					newprice = dorigprice + dprice - prevprice;
						
					theform["hdnDrpdnPrevPricePlus_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value = '$' + dprice;				
					
					//round off to 2 decimal places
					newprice = (Math.round(newprice*100))/100;
					
					newprice = newprice.toString();
					if (newprice.indexOf(".") < 0){
						newprice = newprice + ".00";
					}

					if (newprice.substring(newprice.indexOf(".") + 1).length == 1){
						newprice = newprice + "0";
					}

					//change the List Price
					pricelabel.childNodes.item(0).nodeValue = '$' + newprice;    
				}		
			}
			
			//display message
			if (newprice != origlistprice){
				labelMessage.childNodes.item(0).nodeValue = 'Revised price includes options selected below.';    					
			}else{
				labelMessage.childNodes.item(0).nodeValue = '';    					
			}	
		}		
	}
}

function ValidateRequiredFields(form, action){
	var isapiurl;
	
	// Call ValidateBuyerDefinedValues first
	if (ValidateBuyerDefinedValues(form)){  
		// for each hdnBuyerRequiredFlag, check the value
		// if YES, get the hdnIsValueSelected_<prodid>_<itemid>_<carttype>_<seqid>_<attrid>
	
		var thevalue, prodid, itemid, carttype, seqid, attrid, reqdflag;
		var arr, okay;
		var isMoreThanOneAttr;
		
		okay=true;
		isMoreThanOneAttr = false;
		for (i=0; i < form.hdnBuyerRequiredFlag.length; i++){
			isMoreThanOneAttr = true;
		
			thevalue = form.hdnBuyerRequiredFlag[i].value;
			arr = thevalue.split("|");
			
			prodid = arr[0];
			itemid = arr[1];
			carttype = arr[2];
			seqid = arr[3];
			attrid = arr[4];
			reqdflag = arr[5];
					
			if (reqdflag=='yes'){
				//check isSelected hidden
				if (form["hdnIsValueSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_" + attrid].value=='no'){
					okay=false;
					break;
				}
			}
		}
		
		if (isMoreThanOneAttr == false){		
			//check for single hdnBuyerRequiredFlag
			thevalue = form.hdnBuyerRequiredFlag.value;
			arr = thevalue.split("|");
			
			prodid = arr[0];
			itemid = arr[1];
			carttype = arr[2];
			seqid = arr[3];
			attrid = arr[4];
			reqdflag = arr[5];
					
			if (reqdflag=='yes'){
				//check isSelected hidden
				if (form["hdnIsValueSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_" + attrid].value=='no'){
					okay=false;
				}
			}			
		}
		
	
		if (okay==false){
			if (action=='rfi'){
				alert('Please complete all required fields.');
			}else{
				alert('You must complete all required fields before adding any items to the cart.');
			}
			return false;
		}else{	
			if (action=='rfi'){
				return true;				
			}else{
				if (action=='changeoptions'){
					isapiurl = form.hdnIsapiChangeOptionsUrl.value;	
					if (isapiurl==''){
						form.action = "ChangeOptions.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + 
							"&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + 
							"&itemids=" + form.hdnItemIDs.value + "&qtys=" + form.hdnQtys.value + 
							"&type=" + form.hdnCartType.value + "&prodids=" + form.hdnProdIDs.value +
							"&sid=" + form.hdnSID.value + "&uid=" + form.hdnUID.value + "&cart_itemid=" + form.hdnCartItemID.value + 
							"&plpurl=" + form.hdnPlpUrl.value + "&action=" + action;	
					}else{
						form.action = isapiurl + "&plpver=" + form.hdnPlpVer.value + 
							"&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + 
							"&itemids=" + form.hdnItemIDs.value + "&qtys=" + form.hdnQtys.value + 
							"&type=" + form.hdnCartType.value + "&prodids=" + form.hdnProdIDs.value +
							"&sid=" + form.hdnSID.value + "&uid=" + form.hdnUID.value + "&cart_itemid=" + form.hdnCartItemID.value + 
							"&plpurl=" + form.hdnPlpUrl.value + "&action=" + action;						
					}
				}else{
					isapiurl = form.hdnIsapiAdditionaOptionsUrl.value;
					if (isapiurl==''){
						form.action = "AdditionalOptions.aspx?cid=" + form.hdnCID.value + "&plpver=" + form.hdnPlpVer.value + 
									"&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + 
									"&itemids=" + form.hdnItemIDs.value + "&qtys=" + form.hdnQtys.value + 
									"&type=" + form.hdnCartType.value + "&prodids=" + form.hdnProdIDs.value + "&action=" + action;						
					}else{
						form.action = isapiurl + "&plpver=" + form.hdnPlpVer.value + 
									"&categid=" + form.hdnCategID.value + "&prodid=" + form.hdnProdID.value + 
									"&itemids=" + form.hdnItemIDs.value + "&qtys=" + form.hdnQtys.value + 
									"&type=" + form.hdnCartType.value + "&prodids=" + form.hdnProdIDs.value + "&action=" + action;											
					}

				}
				form.submit();			
				return true;				
			}
		}	
	}else{		
		return false;
	}
}

function ValidateBuyerDefinedValues(form){
	var thevalue, prodid, itemid, carttype, seqid, attrid, displaytype;
	var arr, okay;	
	var attrvalueid, buyerdefidx;
    //  BEGIN 2.5 *********
    var isNumeric,valMin, valMax;
    //  END 2.5 *********
	okay=true;
	if (form.hdnIsBuyerDefPresent.value=='true'){
		if(form.hdnBuyerDefinedFlag.length > 1){
			for (i=0; i < form.hdnBuyerDefinedFlag.length; i++){		
				thevalue = form.hdnBuyerDefinedFlag[i].value;
				arr = thevalue.split("|");
					
				prodid = arr[0];
				itemid = arr[1];
				carttype = arr[2];
				seqid = arr[3];
				attrid = arr[4];
				displaytype = arr[5];
				//  BEGIN 2.5 *********
				if((displaytype=='chk') || (displaytype=='radio')){
					displaytype='edtOption';
			    }
                 isNumeric= arr[6];
                 valMin= arr[7];
                 valMax= arr[8];
    
                if (arr[9] != 'memo')
                {
					if (!CheckBuyerDefinedValuesByDisplayType(form, prodid, itemid, carttype, seqid, attrid, displaytype, isNumeric, valMin, valMax)){
						okay=false; break;
					}
				 }
				//  END 2.5 *********
			}
		}else{		
			thevalue = form.hdnBuyerDefinedFlag.value;
			arr = thevalue.split("|");
				
			prodid = arr[0];
			itemid = arr[1];
			carttype = arr[2];
			seqid = arr[3];
			attrid = arr[4];
			displaytype = arr[5];
			if((displaytype=='chk') || (displaytype=='radio')){
				displaytype='edtOption';
			}
		    //  BEGIN 2.5 *********
               isNumeric= arr[6];
               valMin= arr[7];
               valMax= arr[8];
               if (arr[9] != 'memo')
               {
				if (!CheckBuyerDefinedValuesByDisplayType(form, prodid, itemid, carttype, seqid, attrid, displaytype, isNumeric, valMin, valMax)){
			    		okay=false;
				}
			   }
		   //  END 2.5 *********	   
		}
	}	
	
	if (okay==false){
		//alert('Please complete buyer-defined values.');
		return false;
	}else{
		return true;
	}				
}

//Ron:
//We may need to replace 2.0 by this version. 
function CheckBuyerDefinedValuesByDisplayType(form, prodid, itemid, carttype, seqid, attrid, displaytype, isNumeric, valMin, valMax){
//---------------------------------------------
// loop through the appropriate items.
// check if buyer-defined control is selected.
// if yes, check for the appropraite editbox.
//---------------------------------------------	
	var okay,checkMinMax;
	var i, j, k;
    
    checkMinMax=false;
	if((displaytype=='chk') || (displaytype=='radio')){

		// this covers checkbox, imagecheckbox, radio, image radio, range, link select
		k=0;
		for (j=0; j < form[displaytype + '_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].length; j++){		
			if (form[displaytype + "_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][j].checked==true){
				// get the value, check if it contains ~buyerdefined~
				attrvalueid = form[displaytype + "_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][j].value;
	
				buyerdefidx = attrvalueid.indexOf("~buyerdefined~");
				if (buyerdefidx > 1){
					// check the editbox
					if(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].length==undefined)
					{
						if (trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value)==''){
							okay=false;
							break; 
						}
						else
						{
						    if ((isNumeric == "yes")||(isNumeric == "yes_i"))
						    {
								if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value), valMin, valMax,isNumeric))
								{
								okay=false;
								checkMinMax=true;
								break; 
								}
							}
						}
					}
					else
					{
						if (trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'][k].value)==''){
							okay=false;
							break; 
						}
						else
						{
						    if ((isNumeric == "yes")||(isNumeric == "yes_i"))
						    {
								if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'][k].value), valMin, valMax,isNumeric))
								{
								okay=false;
								checkMinMax=true;
								break; 
								}
							}
						}
						k=k + 1;
					}							
				}
			}
			else
			{
				attrvalueid = form[displaytype + "_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][j].value;
				buyerdefidx = attrvalueid.indexOf("~buyerdefined~");
				if (buyerdefidx > 1){
				 k=k + 1;
				}
			}
		}
	}else if(displaytype=='listbox'){
		for (j=0; j < form['listbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].options.length; j++){		
			if (form["listbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].options[j].selected==true){
				// get the value, check if it contains ~buyerdefined~
				attrvalueid = form["listbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].options[j].value;
				
				buyerdefidx = attrvalueid.indexOf("~buyerdefined~");
				if (buyerdefidx > 1){
					// check the editbox
					if (trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value)==''){
						okay=false;
						break; 
					}
					else
					{
						if ((isNumeric == "yes")||(isNumeric == "yes_i"))
						{
							if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value), valMin, valMax,isNumeric))
							{
							okay=false;
							checkMinMax=true;
							break; 
							}
						}
					}
				}
			}
		}
	}else if(displaytype=='drpdn'){
		// get the value, check if it contains ~buyerdefined~
		attrvalueid = form["drpdn_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].options[form["drpdn_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].selectedIndex].value;
		
		buyerdefidx = attrvalueid.indexOf("~buyerdefined~");
		if (buyerdefidx > 1){
			// check the editbox
			if (trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value)==''){
				okay=false;
			}
			else
			{
				if ((isNumeric == "yes")||(isNumeric == "yes_i"))
				{
					if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value), valMin, valMax,isNumeric))
					{
					okay=false;
					checkMinMax=true;
					}
				}
			}
		}
	}else if(displaytype=='edt'){
	    if(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].length==undefined)
	    {
			if (!trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].value)==''){
				if ((isNumeric == "yes")||(isNumeric == "yes_i"))
				{
					if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].value), valMin, valMax,isNumeric))
						{
							okay=false;
							checkMinMax=true;
						}
				}
			}
	    
	    }
	    else
	    {
			for (j=0; j < form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid].length; j++){		
				if (!trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid][j].value)==''){
					if ((isNumeric == "yes")||(isNumeric == "yes_i"))
				    {
						if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid][j].value), valMin, valMax,isNumeric))
						{
							okay=false;
							checkMinMax=true;
							break; 
						}
					}
				}
			}
		}
	}else if(displaytype=='edtOption'){
	    if(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].length==undefined)
	    {
			if (!trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value)==''){
				if ((isNumeric == "yes")||(isNumeric == "yes_i"))
				{
					if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].value), valMin, valMax,isNumeric))
						{
							okay=false;
							checkMinMax=true;
						}
				}
			}
	    
	    }
	    else
	    {
			for (j=0; j < form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].length; j++){		
				if (!trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid+ '_buyerdefined'][j].value)==''){
					if ((isNumeric == "yes")||(isNumeric == "yes_i"))
				    {
						if (!CheckMinAndMax(trim(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid+ '_buyerdefined'][j].value), valMin, valMax,isNumeric))
						{
							okay=false;
							checkMinMax=true;
							break; 
						}
					}	
				}
			}
		}
	}
	
	if (okay==false){
	    if (checkMinMax==true)
	        if (isNumeric == "yes")
				 alert('Entry is outside of the specified Min/Max Range.\n Please re-enter a numeric value within the range [' + valMin + ', ' + valMax + '].');
	        else
	             alert('Entry is outside of the specified Min/Max Range.\n Please re-enter a integer value within the range [' + valMin + ', ' + valMax + '].');
	    else
			alert('Please complete buyer-defined values.');
		
		if(displaytype=='edt'){
			if(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid ].length==undefined)
			{
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid ].focus();
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid ].select();
			}
			else
			{
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid ][j].focus();
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid ][j].select();
			}	
		}
		else{		
			if(form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].length==undefined)
			{
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].focus();
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'].select();
			}
			else
			{
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'][k].focus();
				form['editbox_' + prodid + '_' + itemid + '_' + carttype + '_'  + seqid + '_attrid_' + attrid + '_buyerdefined'][k].select();
			}
		}
		return false;
	}else{
		return true;
	}								
}

function SetIsValueSelected(obj, form, prodid, itemid, carttype, seqid, attrid){
	var isSet;
		
	isSet = false;
	if(obj.type=='checkbox'){
		if(form["chk_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length > 1){
			for (i=0; i < form["chk_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length; i++){
				if (form["chk_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][i].checked==true){
					isSet = true;
					break;
				}
			}	
		}else{
			if (form["chk_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].checked==true){
				isSet = true;				
			}		
		}	

    }else if(obj.type=='radio'){
		if(form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length > 1){		
			for (i=0; i < form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length; i++){
				if (form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][i].checked==true){
					if(form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][i].value=='0'){
						isSet = false;
					}else{
						isSet = true;
					}
					break;				
				}
			}	
		}else{
			if (form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].checked==true){
				if(form["radio_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value=='0'){
					isSet = false;
				}else{
					isSet = true;
				}
			}			
		}
		
    }else if(obj.type=='select-one'){
		if (obj.value=='0'){
			isSet = false;
		}else{
			isSet = true;
		}
		
    }else if(obj.type=='select-multiple'){
		for (i=0; i < obj.options.length; i++){
			if (obj.options[i].selected==true){
				if (obj.options[i].value!='0'){
					//other than No Preference is selected
					isSet = true;
					break;
				}
			}
		}
     }else if(obj.type=='text'){
		if(form["editbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length > 1){				
			for (i=0; i < form["editbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length; i++){
				if (trim(form["editbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][i].value)!=''){
					isSet = true;
					break;
				}
			}	
		}else{
			if (trim(form["editbox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value)!=''){
				isSet = true;
			}
		}
		
    }else if(obj.type=='textarea'){
    	if(form["memobox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length > 1){				
			for (i=0; i < form["memobox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].length; i++){
				if (trim(form["memobox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid][i].value)!=''){
					isSet = true;
					break;
				}
			}	
		}else{
			if (trim(form["memobox_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_attrid_" + attrid].value)!=''){
				isSet = true;
			}		
		}
    }

   	if (isSet==false){
		form["hdnIsValueSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_" + attrid].value = 'no';
	}else{
		form["hdnIsValueSelected_" + prodid + "_" + itemid + "_" + carttype + "_" + seqid + "_" + attrid].value = 'yes';
	}
}

function ValidateAdvSearchForm(theform, cid, plpver, categid, prodid, srchaction, displayresults){
	var isSelected, isDataTypeOkay, isRangeOkay, attrid, displaytype, datatype;
	var sBackToName;
	var isapiurl;
	
	if (displayresults=='1'){
		isapiurl = theform.hdnIsapiAdvancedSearchResultsUrl.value;
	}else{
		isapiurl = theform.hdnIsapiAdvancedSearchUrl.value;
	}	
	
	isSelected = false;
	if (theform.hdnAttrIDs.length > 1){
		for (i=0; i < theform.hdnAttrIDs.length; i++){
			attrid = theform.hdnAttrIDs[i].value;
			displaytype = theform.hdnAttrTypes[i].value;
			datatype = theform.hdnDataTypes[i].value;
			
			isSelected = IsItemSelected(theform, displaytype, attrid);					
			if (isSelected==true){
				break;
			}
		}			
	}else{
		attrid = theform.hdnAttrIDs.value;
		displaytype = theform.hdnAttrTypes.value;
		datatype = theform.hdnDataTypes.value;
			
		isSelected = IsItemSelected(theform, displaytype, attrid);
	}

	if (isSelected==true)
	{	
		if (theform.hdnAttrIDs.length > 1)
		{
			for (i=0; i < theform.hdnAttrIDs.length; i++)
			{
				attrid = theform.hdnAttrIDs[i].value;
				displaytype = theform.hdnAttrTypes[i].value;
				datatype = theform.hdnDataTypes[i].value;
				//validate entries based on data type
                //alert (datatype + ' ' + displaytype);
				isDataTypeOkay = ValidateDataType(theform, datatype, displaytype, attrid);
				if (isDataTypeOkay==false){
					return false;
					break;	
				}
				
				//check for value within available range
				isRangeOkay = ValidateRange(theform, datatype, displaytype, attrid);
				if (isRangeOkay==false){
					return false;
					break;	
				}
			}		
		}else{
			attrid = theform.hdnAttrIDs.value;
			displaytype = theform.hdnAttrTypes.value;
			datatype = theform.hdnDataTypes.value;
			
			//validate entries based on data type
			isDataTypeOkay = ValidateDataType(theform, datatype, displaytype, attrid);
			if (isDataTypeOkay==false){
				return false;
			}									
			
			//check for value within available range
			isRangeOkay = ValidateRange(theform, datatype, displaytype, attrid);
			if (isRangeOkay==false){
				return false;
			}		
		}
	}else{
		if (srchaction=='add'){
			alert('Please enter search input.');
		}else{
			alert('Please enter at least one search criteria.');
		}
		return false; 
	}
	
	sBackToName = theform.hdnBackToName.value;
	if (window.encodeURIComponent)
	   sBackToName = encodeURIComponent(sBackToName);
	else if (window.escape)
		sBackToName = escape(sBackToName);
		
	if (isapiurl==''){
		theform.action = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + 
	                                    prodid + '&action=' + srchaction + '&forward=' + theform.hdnForward.value +
	                                    '&backtoname=' + sBackToName;		
	}else{
		theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + 
	                                    prodid + '&action=' + srchaction + '&forward=' + theform.hdnForward.value +
	                                    '&backtoname=' + sBackToName;				
	}

	//alert('theform.action: ' + theform.action);
	theform.submit();
	return true;	
}

function IsItemSelected(theform, displaytype, attrid){
	var j;
	
	if (displaytype=='chk'){
	    if(theform["chk_" + "attrid_" + attrid].length==undefined)
	    {
		    if (theform["chk_" + "attrid_" + attrid].checked==true){
				return true;
			}
		}
		else
		{
			for (j=0; j < theform["chk_" + "attrid_" + attrid].length; j++){
				if (theform["chk_" + "attrid_" + attrid][j].checked==true){
					return true;
				}
			}
		}	
	}else if (displaytype=='radio'){
	    if (theform["radio_" + "attrid_" + attrid].length==undefined)
	    {
			if (theform["radio_" + "attrid_" + attrid].checked==true){
				if (theform["radio_" + "attrid_" + attrid].value != '0'){
					return true
				}
			}
		}
		else
		{
			for (j=0; j < theform["radio_" + "attrid_" + attrid].length; j++){
				if (theform["radio_" + "attrid_" + attrid][j].checked==true){
					if (theform["radio_" + "attrid_" + attrid][j].value != '0'){
						return true
					}
				}
			}
		}	
	}else if (displaytype=='bool_radio'){
	    if(theform["bool_radio_" + "attrid_" + attrid].length==undefined)
	    {
			if (theform["bool_radio_" + "attrid_" + attrid].checked==true){
				if (theform["bool_radio_" + "attrid_" + attrid].value != '0'){
					return true;
				}
			}
		}
		else
		{
			for (j=0; j < theform["bool_radio_" + "attrid_" + attrid].length; j++){
				if (theform["bool_radio_" + "attrid_" + attrid][j].checked==true){
					if (theform["bool_radio_" + "attrid_" + attrid][j].value != '0'){
						return true;
					}
				}
			}
		}			
	}else if (displaytype=='drpdn'){
		if (theform["drpdn_" + "attrid_" + attrid].value!='0'){
			return true;
		}
	}else if (displaytype=='listbox'){
	 	for (j=0; j < theform["listbox_" + "attrid_" + attrid].options.length; j++){
			if (theform["listbox_" + "attrid_" + attrid].options[j].selected==true){
				if (theform["listbox_" + "attrid_" + attrid].options[j].value!='0'){
					//other than No Preference is selected
					return true;
				}
			}
		}
	}else if (displaytype=='editbox'){
		//alert("editbox_" + "attrid_" + attrid + ' is : ' + theform["editbox_" + "attrid_" + attrid].value);
		if (trim(theform["editbox_" + "attrid_" + attrid].value)!=''){
			return true;			
		}
	}else if (displaytype=='drpdn_range'){
		//alert("editbox_" + "attrid_" + attrid + ' is : ' + theform["editbox_" + "attrid_" + attrid].value);
		if (trim(theform["editbox_" + "attrid_" + attrid].value)!=''){
			return true;
		}
	}else if (displaytype=='memobox'){
		if (trim(theform["memobox_" + "attrid_" + attrid].value)!=''){
			return true;
		}
	}else if (displaytype=='range'){
		if ((trim(theform["range_" + "attrid_" + attrid + "_from"].value)!='') || (trim(theform["range_" + "attrid_" + attrid + "_to"].value)!='')){
			return true;
		}
	}
	
	return false;
}

function ValidateDataType(theform, datatype, displaytype, attrid){

	if (datatype=='10'){
		//check if integer
		if (displaytype=='editbox'){
			//alert('here1');
			if (!IsInteger(trim(theform["editbox_" + "attrid_" + attrid].value))){
				alert('Search input must be an integer.');
				theform["editbox_" + "attrid_" + attrid].focus();
				return false; 
			}else{
				theform["editbox_" + "attrid_" + attrid].value = theform["editbox_" + "attrid_" + attrid].value.replace(/(\d),(\d)/g, '$1$2');
			}
		}else if (displaytype=='drpdn_range'){
			//alert('here2');
			if (!IsInteger(trim(theform["editbox_" + "attrid_" + attrid].value))){
				alert('Search input must be an integer.');
				theform["editbox_" + "attrid_" + attrid].focus();
				return false; 
			}else{
				theform["editbox_" + "attrid_" + attrid].value = theform["editbox_" + "attrid_" + attrid].value.replace(/(\d),(\d)/g, '$1$2');
			}
		}else if (displaytype=='memobox'){
			//alert('here3');
			if (!IsInteger(trim(theform["memobox_" + "attrid_" + attrid].value))){
				alert('Search input must be an integer.');
				theform["memobox_" + "attrid_" + attrid].focus();
				return false; 
			}else{
				theform["memobox_" + "attrid_" + attrid].value = theform["memobox_" + "attrid_" + attrid].value.replace(/(\d),(\d)/g, '$1$2');
			}
		}else if (displaytype=='range'){
			//alert('here4');
			if (!IsInteger(trim(theform["range_" + "attrid_" + attrid + "_from"].value))){
				//alert('try1');
				alert('Search input must be an integer.');
				theform["range_" + "attrid_" + attrid + "_from"].focus();
				return false; 
			}else if (!IsInteger(trim(theform["range_" + "attrid_" + attrid + "_to"].value))){
				//alert('try2');
				alert('Search input must be an integer.');
				theform["range_" + "attrid_" + attrid + "_to"].focus();
				return false; 
			}else{
				theform["range_" + "attrid_" + attrid + "_from"].value = theform["range_" + "attrid_" + attrid + "_from"].value.replace(/(\d),(\d)/g, '$1$2');
				theform["range_" + "attrid_" + attrid + "_to"].value = theform["range_" + "attrid_" + attrid + "_to"].value.replace(/(\d),(\d)/g, '$1$2');
			}
		}
	}else if (datatype=='14'){
		//check if numeric
		if (displaytype=='editbox'){
			//alert('here5');
			if (trim(theform["editbox_" + "attrid_" + attrid].value)!=''){
				if (isNaN(trim(theform["editbox_" + "attrid_" + attrid].value))){
					alert('Search input must be numeric.');
					theform["editbox_" + "attrid_" + attrid].focus();
					return false; 
				}						
			}
		}else if (displaytype=='drpdn_range'){
			//alert('here6');
			//alert('value is : ' + trim(theform["editbox_" + "attrid_" + attrid].value));
			if (trim(theform["editbox_" + "attrid_" + attrid].value)!=''){
				if (isNaN(trim(theform["editbox_" + "attrid_" + attrid].value))){
					alert('Search input must be numeric.');
					theform["editbox_" + "attrid_" + attrid].focus();
					return false; 
				}
			}
		}else if (displaytype=='memobox'){
			//alert('here7');
			if (trim(theform["memobox_" + "attrid_" + attrid].value)!=''){
				if (isNaN(trim(theform["memobox_" + "attrid_" + attrid].value))){
					alert('Search input must be numeric.');
					theform["memobox_" + "attrid_" + attrid].focus();
					return false; 
				}
			}
		}else if (displaytype=='range'){
			//alert('here8');
			if ((trim(theform["range_" + "attrid_" + attrid + "_from"].value)!='') || (trim(theform["range_" + "attrid_" + attrid + "_to"].value)!='')){
				if (isNaN(trim(theform["range_" + "attrid_" + attrid + "_from"].value))){
					alert('Search input must be numeric.');
					theform["range_" + "attrid_" + attrid + "_from"].focus();
					return false; 
				}else if (isNaN(trim(theform["range_" + "attrid_" + attrid + "_to"].value))){
					alert('Search input must be numeric.');
					theform["range_" + "attrid_" + attrid + "_to"].focus();
					return false; 
				}					
			}
		}
	}
	return true;
}

function ValidateRange(theform, datatype, displaytype, attrid){
	if (displaytype=='drpdn_range'){
		//alert('here9');			
		if (trim(theform["editbox_" + "attrid_" + attrid].value)!=''){
			if ((theform["hdn_range_" + "attrid_" + attrid + "_min"].value=='infinitymin') && (theform["hdn_range_" + "attrid_" + attrid + "_max"].value=='infinitymax')){
				// do nothing
			}else if ((theform["hdn_range_" + "attrid_" + attrid + "_max"].value=='infinitymax') && (theform["hdn_range_" + "attrid_" + attrid + "_min"].value!='infinitymin')){
				if (parseFloat(theform["editbox_" + "attrid_" + attrid].value) < parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_min"].value)){
					//validate the min entry
					alert('Search input must be within available range.');
					theform["editbox_" + "attrid_" + attrid].focus();
					return false; 
				}
			}else if ((theform["hdn_range_" + "attrid_" + attrid + "_min"].value=='infinitymin') && (theform["hdn_range_" + "attrid_" + attrid + "_max"].value!='infinitymax')){
				if (parseFloat(theform["editbox_" + "attrid_" + attrid].value) > parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_max"].value)){
					//validate the max entry
					alert('Search input must be within available range.');
					theform["editbox_" + "attrid_" + attrid].focus();
					return false; 
				}				
			}else if ((parseFloat(theform["editbox_" + "attrid_" + attrid].value) < parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_min"].value)) || 
				(parseFloat(theform["editbox_" + "attrid_" + attrid].value) > parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_max"].value))){
					alert('Search input must be within available range.');
					theform["editbox_" + "attrid_" + attrid].focus();
					return false; 
			}				
		}	
	}else if (displaytype=='range'){
		//alert('here10');
		if ((trim(theform["range_" + "attrid_" + attrid + "_from"].value)!='') || (trim(theform["range_" + "attrid_" + attrid + "_to"].value)!='')){
			if ((theform["hdn_range_" + "attrid_" + attrid + "_min"].value=='infinitymin') && (theform["hdn_range_" + "attrid_" + attrid + "_max"].value=='infinitymax')){
				// do nothing
			}else if ((theform["hdn_range_" + "attrid_" + attrid + "_max"].value=='infinitymax') && (theform["hdn_range_" + "attrid_" + attrid + "_min"].value!='infinitymin')){
				if (parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value) < parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_min"].value)){
					//alert('me1');
					//validate the min entry
					alert('Search input must be within available range.');
					theform["range_" + "attrid_" + attrid + "_from"].focus();
					return false; 
				}else if ((parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value)) < (parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value))){
					//check if to is greater than from
					alert('Minimum value must be less than maximum value.');
					theform["range_" + "attrid_" + attrid + "_from"].focus();
					return false; 
				}
			}else if ((theform["hdn_range_" + "attrid_" + attrid + "_min"].value=='infinitymin') && (theform["hdn_range_" + "attrid_" + attrid + "_max"].value!='infinitymax')){
				if (parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value) > parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_max"].value)){
					//alert('me1');
					//validate the max entry
					alert('Search input must be within available range.');
					theform["range_" + "attrid_" + attrid + "_to"].focus();
					return false; 
				}else if ((parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value)) < (parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value))){
					//check if to is greater than from
					alert('Minimum value must be less than maximum value.');
					theform["range_" + "attrid_" + attrid + "_from"].focus();
					return false; 
				}						
			}else if ((parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value) < parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_min"].value)) || 
				(parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value) > parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_max"].value))){
					//alert('me1');
					alert('Search input must be within available range.');
					theform["range_" + "attrid_" + attrid + "_from"].focus();
					return false; 
			}else if ((parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value) < parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_min"].value)) || 
				(parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value) > parseFloat(theform["hdn_range_" + "attrid_" + attrid + "_max"].value))){
					//alert('me2');
					alert('Search input must be within available range.');
					theform["range_" + "attrid_" + attrid + "_to"].focus();
					return false; 
			}else if ((parseFloat(theform["range_" + "attrid_" + attrid + "_to"].value)) < (parseFloat(theform["range_" + "attrid_" + attrid + "_from"].value))){
				//check if to is greater than from
				//alert('me3');
				alert('Minimum value must be less than maximum value.');
				theform["range_" + "attrid_" + attrid + "_from"].focus();
				return false; 
			}							
		}				
	}	
	return true;
}

function FilterByProductByType(theform, cid, plpver, categid, obj, keyword, keycateg, keyprod, backtoname,searchType){
	var prodid, strPath;
	var sBackToName;
	
	prodid = obj.value;
	if (prodid != '0'){
		if (keyword==''){	 
			sBackToName = backtoname;
			if (window.encodeURIComponent)
				sBackToName = encodeURIComponent(sBackToName);
			else if (window.escape)
				sBackToName = escape(sBackToName);
		
			isapiurl = theform.hdnIsapiAdvancedSearchResultsUrl.value;
					  
			if (isapiurl==''){
				strPath = 'AdvancedSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			          '&SchType=' + searchType + '&backtoname=' + sBackToName;					
			}else{
				strPath = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			          '&SchType=' + searchType + '&backtoname=' + sBackToName;							
			}			

		}else{
			isapiurl = theform.hdnIsapiKeywordResultsUrl.value;
			
			if (isapiurl.indexOf('/internal/',0) > -1)
			isapiurl='';
			  
			if (isapiurl==''){
				strPath = 'KeywordSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			           '&keyword=' + keyword + '&key=product' + '&keycateg=' + keycateg + '&keyprod=' + prodid + '&SchType=' + searchType;				
			}else{
				strPath = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			           '&keyword=' + keyword + '&key=product' + '&keycateg=' + keycateg + '&keyprod=' + prodid + '&SchType=' + searchType;			
			}
		}
		window.location = strPath;	
		return true;	
	}else{
		return false;	
	}
}

function FilterByProduct(theform, cid, plpver, categid, obj, keyword, keycateg, keyprod, backtoname){
	var prodid, strPath;
	var sBackToName;
	
	prodid = obj.value;

	if (prodid != '0'){
		if (keyword==''){	 
			sBackToName = backtoname;
			if (window.encodeURIComponent)
				sBackToName = encodeURIComponent(sBackToName);
			else if (window.escape)
				sBackToName = escape(sBackToName);
		
			isapiurl = theform.hdnIsapiAdvancedSearchResultsUrl.value;
			
			if (isapiurl==''){
				strPath = 'AdvancedSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			          '&backtoname=' + sBackToName;					
			}else{
				strPath = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			          '&backtoname=' + sBackToName;								
			}			

		}else{
			isapiurl = theform.hdnIsapiKeywordResultsUrl.value;
			
			if (isapiurl.indexOf('/internal/',0) > -1)
			isapiurl='';
			
			if (isapiurl==''){
				strPath = 'KeywordSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			           '&keyword=' + keyword + '&key=product' + '&keycateg=' + keycateg + '&keyprod=' + prodid;				
			}else{
				strPath = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + '&filter=1' + 
			           '&keyword=' + keyword + '&key=product' + '&keycateg=' + keycateg + '&keyprod=' + prodid;			
			}
		}
		window.location = strPath;	
		return true;	
	}else{
		return false;	
	}
}


function SubmitAdvSearchViewItems(theform, cid, plpver, categid, prodid){
	var isapiurl;
	
	//alert('theform.hdnCriteria.value: ' + theform.hdnCriteria.value);
	
	//SetCookie('adv_srch_criteria', theform.hdnCriteria.value);
	
	isapiurl = theform.hdnIsapiAdvancedSearchResultsUrl.value;
	sBackToName = theform.hdnBackToName.value;
	if (window.encodeURIComponent)
		sBackToName = encodeURIComponent(sBackToName);
	else if (window.escape)
		sBackToName = escape(sBackToName);
				
	if (isapiurl==''){
		theform.action = 'AdvancedSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
	                      '&backtoname=' + sBackToName;	
	                     
		//theform.action = 'AdvancedSearchResults.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid;
	}else{
		theform.action = isapiurl + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
	                     '&backtoname=' + sBackToName;	
	    
	    //theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid;
	}

	theform.submit();
}

function SubmitAdvancedSearchForm(theform, cid, plpver, categid, prodid, attrid, attrvalid, srchaction){
	var sBackToName;
	var isapiurl;

	if (srchaction=='clear'){
		attrid = theform.drpdnAvailCriteriaList.value;
	}

	isapiurl = theform.hdnIsapiAdvancedSearchUrl.value;
	sBackToName = theform.hdnBackToName.value;
	if (window.encodeURIComponent)
		sBackToName = encodeURIComponent(sBackToName);
	else if (window.escape)
		sBackToName = escape(sBackToName);
					
	if (srchaction=='removeall'){
		if (confirm('Remove all criteria?')) {
			if (isapiurl==''){
				theform.action = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
								      '&attid=' + attrid + '&attvalid=' + attrvalid + '&forward=' + theform.hdnForward.value +
								      '&backtoname=' + sBackToName;					
			}else{
				theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
								      '&attid=' + attrid + '&attvalid=' + attrvalid + '&forward=' + theform.hdnForward.value +
								      '&backtoname=' + sBackToName;									
			}
			theform.submit();
		}
	}else{
		if (isapiurl==''){
			theform.action = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
						      '&attid=' + attrid + '&attvalid=' + attrvalid + '&action=' + srchaction + 
						      '&forward=' + theform.hdnForward.value + '&backtoname=' + sBackToName;			
		}else{
			theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
						      '&attid=' + attrid + '&attvalid=' + attrvalid + '&action=' + srchaction + 
						      '&forward=' + theform.hdnForward.value + '&backtoname=' + sBackToName;	
		}

		theform.submit();
	}	
}

//For 2.5
function SubmitAdvanced4SearchForm(theform, cid, plpver, categid, prodid, attrid, attrvalid, srchaction){
	var sBackToName;
	var isapiurl;

	if (srchaction=='clear'){
	    if (confirm('Are you sure that you want to clear your entire search path? \n All choices will be removed.')) {
			isapiurl = theform.hdnIsapiAdvancedSearchUrl.value;
			sBackToName = theform.hdnBackToName.value;
			if (window.encodeURIComponent)
				sBackToName = encodeURIComponent(sBackToName);
			else if (window.escape)
				sBackToName = escape(sBackToName);
							
			if (srchaction=='removeall'){
				if (confirm('Remove all criteria?')) {
					if (isapiurl==''){
						theform.action = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
											'&attid=' + attrid + '&attvalid=' + attrvalid + '&forward=' + theform.hdnForward.value +
											'&backtoname=' + sBackToName;					
					}else{
						theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
											'&attid=' + attrid + '&attvalid=' + attrvalid + '&forward=' + theform.hdnForward.value +
											'&backtoname=' + sBackToName;									
					}
					theform.submit();
				}
			}else{
				if (isapiurl==''){
					theform.action = theform.action + '?cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
									'&attid=' + attrid + '&attvalid=' + attrvalid + '&action=' + srchaction + 
									'&forward=' + theform.hdnForward.value + '&backtoname=' + sBackToName;			
				}else{
					theform.action = isapiurl + 'cid=' + cid + '&plpver=' + plpver + '&categid=' + categid + '&prodid=' + prodid + 
									'&attid=' + attrid + '&attvalid=' + attrvalid + '&action=' + srchaction + 
									'&forward=' + theform.hdnForward.value + '&backtoname=' + sBackToName;	
				}

				theform.submit();
			}
		}
	}	
}

function CancelChangeOptions(theform){
	if (confirm('Cancel Changes?')) {
		theform.action = theform.hdnOolBuyerUrl.value;
		theform.submit();
	}
}

function ModeSelected(theform, mode){	     
	var isapiurl;
	
	isapiurl = theform.hdnIsapiBrowserUrl.value;	 
	if (isapiurl==''){
		theform.action = theform.action + '?cid=' + theform.hdnCID.value + '&plpver=' + theform.hdnPlpVer.value + '&categid=' + 
		                  theform.hdnCategID.value + '&prodid=' + theform.hdnProdID.value + '&itemid=' + theform.hdnItemID.value +
		                  '&assetid=' + theform.hdnAssetID.value + '&qlty=' + theform.hdnQuality.value + 
		                  '&size=' + theform.hdnSize.value + '&mode=' + mode;
	}else{
		theform.action = isapiurl + 'cid=' + theform.hdnCID.value + '&plpver=' + theform.hdnPlpVer.value + '&categid=' + 
		                  theform.hdnCategID.value + '&prodid=' + theform.hdnProdID.value + '&itemid=' + theform.hdnItemID.value +
		                  '&assetid=' + theform.hdnAssetID.value + '&qlty=' + theform.hdnQuality.value + 
		                  '&size=' + theform.hdnSize.value + '&mode=' + mode;
	}

	theform.submit();
}

/*function CadViewSelected(theform){	      
	theform.action = 'CadViewer.aspx?cid=' + theform.hdnCID.value + '&plpver=' + theform.hdnPlpVer.value + '&categid=' + 
		                  theform.hdnCategID.value + '&prodid=' + theform.hdnProdID.value + '&itemid=' + theform.hdnItemID.value + 
		                  '&origin=' + theform.hdnOrigin.value + '&by=' + theform.hdnBy.value + '&filter=' + theform.hdnFilter.value + 
		                  '&assetid=' + theform.hdnAssetID.value + '&cadid=' + theform.hdnCadID.value +
		                  '&cadview=' + theform.hdnCadViewSelected.value; 
		                  
	//theform.hdnCadViewSelected.value = cadview;       
	//theform.submit();
	
	window.location = theform.action;	
	return true;	
}*/

function CadViewSelected(theform, cid, plpver, categid, prodid, itemid, origin, by, filter, assetid, cadid, cadview){	      
	var isapiurl;
	
	isapiurl=theform.hdnIsapiCadViewerUrl.value;
	
	if (isapiurl==''){
		theform.action = 'CadViewer.aspx?cid=' + cid + '&plpver=' + plpver + '&categid=' + 
		                  categid + '&prodid=' + prodid + '&itemid=' + itemid + '&origin=' + origin + 
		                  '&by=' + by + '&filter=' + filter + '&assetid=' + assetid + '&cadid=' + cadid +
		                  '&cadview=' + cadview; 
	}else{
		theform.action = isapiurl + '&plpver=' + plpver + '&categid=' + 
		                  categid + '&prodid=' + prodid + '&itemid=' + itemid + '&origin=' + origin + 
		                  '&by=' + by + '&filter=' + filter + '&assetid=' + assetid + '&cadid=' + cadid +
		                  '&cadview=' + cadview; 
	}	
		                  
	//theform.hdnCadViewSelected.value = cadview;       
	//theform.submit();
	
	window.location = theform.action;	
	return true;	
}

function ValidateDownload(theform){
	if (theform.drpdnCadFormats.value=='0'){
		alert('Please select a format to download.');
		return false;
	}else{
		theform.hdnCadFormat.value=theform.drpdnCadFormats.value;
		return true;
	}
}

function ValidateRequestInfo(theform){
   if (theform.hdnAttributesShown.value=='yes'){
		if (ValidateRequiredFields(theform, 'rfi')){
			return ValidateRequestInfoForm(theform);
		}else{
			return false;
		}
	}else{
		return ValidateRequestInfoForm(theform);
	}
}

function ValidateRequestInfoForm(theform){
	if (theform.txtName.value==''){
		alert('Please enter your name.');
		theform.txtName.focus();
		return false;
	}else if (theform.txtEmail.value==''){
		alert('Please enter your email address.');
		theform.txtEmail.focus();
		return false;		
	}else{
		return(CheckEmailAddress(theform.txtEmail));
	}
	return true; 
}

function ValidateEmailPageForm(theform){
    if (theform.txtEmailTo.value==''){
		alert("Please enter recipient's email address.");
		theform.txtEmailTo.focus();
		return false;
	}else if (theform.txtEmailFrom.value==''){
		alert('Please enter your email address.');
		theform.txtEmailFrom.focus();
		return false;		
	}else{
		//check email from
		if (CheckEmailAddress(theform.txtEmailFrom)){
			//check multiple email to
			if (CheckMultEmailAddress(theform.txtEmailTo, 5) != true){
				return false;
			}
		}else{			
			return false;
		}
	}
	return true; 
}

function CheckEmailAddress(oEmail){
   if (IsEmailAddress(oEmail.value)==false){
     alert("Please enter only validly formatted email address.");
     oEmail.focus();
     return false;
   }
   return true;
}

function CheckMultEmailAddress(oEmail, max){
	var arrEmailTo;
	
	arrEmailTo = oEmail.value.split(";");
	if (arrEmailTo.length > max){
		alert("You can only enter up to 5 email addresses.");
		return false;
	}else{
		//check each email add
		for (i=0; i <= arrEmailTo.length-1; i++){
			if (IsEmailAddress(arrEmailTo[i]) != true){
				alert("Please enter only validly formatted email address");
				oEmail.focus();
				return false;
			}
		}
	}
	return true;
}

function IsEmailAddress(sTxt)
    {	  
    var sExclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
    var sCheck=/@[\w\-]+\./;
    var sCheckEnd=/\.[a-zA-Z]{2,6}$/;
       
    if (((sTxt.search(sExclude) != -1)||(sTxt.search(sCheck)) == -1)||(sTxt.search(sCheckEnd) == -1))
    {				
	   return false;
    }
        
    //var arr;
    //arr=sTxt.split(".");
    //if (arr[arr.length-1].length > 4)
    //      return false;        
    return true;
}

function trim(str){
    return ltrim(rtrim(str));
  }
  
function ltrim(str){
    while (str.charAt(0)==' '){str=str.substring(1);}
    return str;
}

function rtrim(str){
    while (str.charAt(str.length-1)==' '){str=str.substring(0,str.length-1);}
    return str;
}

function SavePrevPageToCookie() {
	var prevpage;
	
	prevpage = document.URL;
//	SetCookie('plp_previous_page', prevpage);
}

function SubmitToRequestInfo(theform, action){
	theform.action = action;
	
	theform.submit();
}


// BEGIN 2.5 *********
function GetAttachFile()
{
   var strReturn;
   strReturn = window.showModalDialog('http://localhost/thomastechnology/FileAttachment','','scrollbars: yes; resizable: Yes; dialogWidth: 420px; dialogHeight: 380px; help: no;');
}

function CheckMinAndMax(piValue, piMin, piMax,piCheckMinAndMax)
{
   if (piCheckMinAndMax=="yes")
   {
	   if(!IsNumeric(piValue))
       return false;
   }
   if (piCheckMinAndMax=="yes_i")
   {
	   if(!IsInteger(piValue))
       return false;
   }
  // if(!IsNumber(piMax))
  //     return false; 
  //  if(!IsNumber(piMax))
  //     return false;          
       
   if (piMin == "~" && piMax == "~")
   {
   
   }
   else if (piMin == "~" && piMax != "~")
   {
      if (parseFloat(piValue) > parseFloat(piMax))
       return false;
   }
   else if (piMin != "~" && piMax == "~")
   {
       if (parseFloat(piValue) < parseFloat(piMin))
       return false;
   }
   else
   {
      if ( (parseFloat(piValue) > parseFloat(piMax)) || (parseFloat(piValue) < parseFloat(piMin)))
      return false;
   }
   return true;
}

function IsNumber(piValue)
{
    if (IsInteger(piValue))
		return true;
    else
    {
		if (IsNumeric(piValue))
			return true;
		else
			return false;
    }
}

// End  2.5 *********