/************************************************/
/** JavaScript functions for:                  **/
/**    -- Quick Product Search                 **/
/**                                            **/
/** Created 9/20/2006                          **/
/**                                            **/
/************************************************/

var QPSDisplayType = "table-row";
//Conditional Compilation code 
/*@cc_on
	QPSDisplayType = "block";		
@*/

var NAQPS = 
{
	SwitchTab:
	{
		Brand:function()
		{
			document.getElementById(QuickSearchIDStart + "SearchTable").style.backgroundColor = "rgb(51,51,102)";
			if (document.getElementById(QuickSearchIDStart + "btnFindIt").src.indexOf("es-MX") != -1)
			{
				document.getElementById(QuickSearchIDStart + "btnFindIt").src = jsAppRootPath + "/DesktopModules/ETGAMS/search/images/RedFindIt.es-MX.gif";
			}
			else
			{
				document.getElementById(QuickSearchIDStart + "btnFindIt").src = jsAppRootPath + "/DesktopModules/ETGAMS/search/images/RedFindIt.gif";
			}
			NAQPS.SwitchProdType.Brand();
		},
		Category:function()
		{
			document.getElementById(QuickSearchIDStart + "SearchTable").style.backgroundColor = "rgb(204,51,51)";
			if (document.getElementById(QuickSearchIDStart + "btnFindIt").src.indexOf("es-MX") != -1)
			{
				document.getElementById(QuickSearchIDStart + "btnFindIt").src = jsAppRootPath + "/DesktopModules/ETGAMS/search/images/BlueFindIt.es-MX.gif";
			}
			else
			{
				document.getElementById(QuickSearchIDStart + "btnFindIt").src = jsAppRootPath + "/DesktopModules/ETGAMS/search/images/BlueFindIt.gif";
			}
			NAQPS.SwitchProdType.Category();
		}
	},
	SwitchProdType: 
	{
		Brand:function()
		{
			NAQPS.elementEvents.resetBrandSearch();
			document.getElementById(QuickSearchIDStart + "qpsTabTypeChoice").value = "Brand";
			NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboBrandProduct");
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop1"); //cboCategory
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop2"); //cboSubCategory
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop3"); //cboProduct
			NAQPS.elementDisplay.elOn(QuickSearchIDStart + "Drop4"); //cboBrand
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop5"); //cboBrandProduct
		},
		Category:function()
		{
			NAQPS.elementEvents.resetCategorySearch();
			document.getElementById(QuickSearchIDStart + "qpsTabTypeChoice").value = "resCategory";
			NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboSubCategory");
			NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboProduct");
			NAQPS.elementDisplay.elOn(QuickSearchIDStart + "Drop1"); //cboCategory
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop2"); //cboSubCategory
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop3"); //cboProduct
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop4"); //cboBrand
			NAQPS.elementDisplay.elOff(QuickSearchIDStart + "Drop5"); //cboBrandProduct		
		}
	},
	elementDisplay:
	{
		// NAQPS.elementDisplay.elOn
		elOn:function(elementID)
		{
			document.getElementById(elementID).style.display = QPSDisplayType;
		},
		// NAQPS.elementDisplay.elOff
		elOff:function(elementID)
		{
			document.getElementById(elementID).style.display = "none";
		}	
	},
	elementEvents:
	{
		resetDropDown:function(elementID)
		{
			document.getElementById(elementID).options[0].selected = true;
			document.getElementById(elementID).selectedIndex = 0;
			document.getElementById(elementID + "Selected").value = document.getElementById(elementID).value;
			
		},
		resetBrandSearch:function()
		{
			document.getElementById(QuickSearchIDStart + "cboBrand").options[0].selected = true;
			document.getElementById(QuickSearchIDStart + "cboBrand").selectedIndex = 0;
			document.getElementById(QuickSearchIDStart + "cboBrandSelected").value = document.getElementById(QuickSearchIDStart + "cboBrand").value;
			
			document.getElementById(QuickSearchIDStart + "cboBrandProduct").options[0].selected = true;
			document.getElementById(QuickSearchIDStart + "cboBrandProduct").selectedIndex = 0;
			document.getElementById(QuickSearchIDStart + "cboBrandProductSelected").value = document.getElementById(QuickSearchIDStart + "cboBrandProduct").value;
		},
		resetCategorySearch:function()
		{
			document.getElementById(QuickSearchIDStart + "cboCategory").options[0].selected = true;
			document.getElementById(QuickSearchIDStart + "cboCategory").selectedIndex = 0;
			document.getElementById(QuickSearchIDStart + "cboCategorySelected").value = document.getElementById(QuickSearchIDStart + "cboCategory").value;

			document.getElementById(QuickSearchIDStart + "cboSubCategory").options[0].selected = true;
			document.getElementById(QuickSearchIDStart + "cboSubCategory").selectedIndex = 0;
			document.getElementById(QuickSearchIDStart + "cboSubCategorySelected").value = document.getElementById(QuickSearchIDStart + "cboSubCategory").value;

			document.getElementById(QuickSearchIDStart + "cboProduct").options[0].selected = true;
			document.getElementById(QuickSearchIDStart + "cboProduct").selectedIndex = 0;
			document.getElementById(QuickSearchIDStart + "cboProductSelected").value = document.getElementById(QuickSearchIDStart + "cboProduct").value;
		},
		clearDropDown:function(elementID)
		{
			var i = document.getElementById(elementID).length - 1;
			while (i > 0)
			{
				document.getElementById(elementID).remove(i);
				i--;
			}
			// following line works in IE only
			/*@cc_on 
				dropdown_menu_hack(document.getElementById(elementID)); 
			@*/	
			NAQPS.elementEvents.resetDropDown(elementID);
		}
	},
	GetDropDownData:function(elementID, itemValue)
	{
		if (itemValue != -1)
		{
			var fullElementID = QuickSearchIDStart + elementID;
			var parentID = null;
			var sendAJAXrequest = true;
			
			switch(elementID)
			{
				case "cboCategory":
					document.getElementById(QuickSearchIDStart + "cboCategorySelected").value = document.getElementById(QuickSearchIDStart + "cboCategory").value;
					NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboSubCategory");
					document.getElementById(QuickSearchIDStart + "Drop2").style.display = "none";
					NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboProduct");
					document.getElementById(QuickSearchIDStart + "Drop3").style.display = "none";
					childID = "cboSubCategory";
					break;
				case "cboSubCategory":
					document.getElementById(QuickSearchIDStart + "cboSubCategorySelected").value = document.getElementById(QuickSearchIDStart + "cboSubCategory").value;
					NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboProduct");
					document.getElementById(QuickSearchIDStart + "Drop3").style.display = "none";
					childID = "cboProduct";
					break;
				case "cboProduct":
					document.getElementById(QuickSearchIDStart + "cboProductSelected").value = document.getElementById(QuickSearchIDStart + "cboProduct").value;
					sendAJAXrequest = false;
					break;
				case "cboBrand":
					document.getElementById(QuickSearchIDStart + "cboBrandSelected").value = document.getElementById(QuickSearchIDStart + "cboBrand").value;
					NAQPS.elementEvents.clearDropDown(QuickSearchIDStart + "cboBrandProduct");
					document.getElementById(QuickSearchIDStart + "Drop5").style.display = "none";
					childID = "cboBrandProduct";
					break;
				case "cboBrandProduct":
					document.getElementById(QuickSearchIDStart + "cboBrandProductSelected").value = document.getElementById(QuickSearchIDStart + "cboBrandProduct").value;
					sendAJAXrequest = false;
					break;
				default:
					break;
			}
			
			if(sendAJAXrequest)
			{
				//Cache buster
				var cachebuster = new Date() * 1;
				 
				var backEndURL = jsAppRootPath + "/desktopmodules/etgams/search/QuickSearchBackEnd.aspx"+ "?elementID=" + childID + "&itemValue=" + itemValue + "&jsPortalID=" + jsPortalID + "&cachebuster=" + cachebuster;
				//var backEndURL = "qpstestbackend.asp?elementID=" + childID;
				//alert(backEndURL);
				//call NobleAJAX function
				NobleAJAX(backEndURL, childID, itemValue);
			}
		}		
	}
}

/***********************************/
/***********************************/
/***********************************/

var QPSListManager = 
{
	CreateDropDownList:function(elementID, txt)
	{
		if (txt.length > 0)
		{
			var aNewList = txt.parseJSON();
			var fullElementID = QuickSearchIDStart + elementID;
			var elOptNew = null;
			
			switch(elementID)
			{
				//sub-category items
				case "cboSubCategory":
					if (aNewList['subcat'].length > 0)
					{
						for (var i=0; i < aNewList['subcat'].length; i++)
						{
					//Conditional Compilation code 
					/*@cc_on
						/*@if (@_IE)
							elOptNew = document.createElement("<option value=\"" + aNewList['subcat'][i]['value'] + "\" />");
							elOptNew.text = aNewList['subcat'][i]['name'];
						@else @*/
							var elOptNew = document.createElement('option');
							elOptNew.text = aNewList['subcat'][i]['name'].unescapeHTML();
							elOptNew.value = aNewList['subcat'][i]['value'];
						/*@end
					@*/
							try
							{
							document.getElementById(QuickSearchIDStart + "cboSubCategory").add(elOptNew, null); // standards compliant; doesn't work in IE
							} catch(ex) {
							document.getElementById(QuickSearchIDStart + "cboSubCategory").add(elOptNew); // IE only
							}
						}
					// following line works in IE only
					/*@cc_on 
						dropdown_menu_hack(document.getElementById(QuickSearchIDStart + "cboSubCategory")); 
					@*/
						document.getElementById(QuickSearchIDStart + "Drop2").style.display = QPSDisplayType;
						
					}
					
					//product items
					if (aNewList['products'].length == 0)
					{
						break;		
					}
				
				case "cboProduct":
					if (aNewList['products'].length > 0)
					{
						for (var i=0; i < aNewList['products'].length; i++)
						{
					//Conditional Compilation code 
					/*@cc_on
						/*@if (@_IE)
							elOptNew = document.createElement("<option value=\"" + aNewList['products'][i]['value'] + "\" />");
							elOptNew.text = aNewList['products'][i]['name'];
						@else @*/
							var elOptNew = document.createElement('option');
							elOptNew.text = aNewList['products'][i]['name'].unescapeHTML();
							elOptNew.value = aNewList['products'][i]['value'];
						/*@end
					@*/
							try
							{
							document.getElementById(QuickSearchIDStart + "cboProduct").add(elOptNew, null); // standards compliant; doesn't work in IE
							} catch(ex) {
							document.getElementById(QuickSearchIDStart + "cboProduct").add(elOptNew); // IE only
							}
						}
					// following line works in IE only
					/*@cc_on 
						dropdown_menu_hack(document.getElementById(QuickSearchIDStart + "cboProduct")); 
					@*/
						document.getElementById(QuickSearchIDStart + "Drop3").style.display = QPSDisplayType;
					}
					break;
					
				case "cboBrandProduct":
					if (aNewList['products'].length > 0)
					{
						for (var i=0; i < aNewList['products'].length; i++)
						{
					//Conditional Compilation code 
					/*@cc_on
						/*@if (@_IE)
							elOptNew = document.createElement("<option value=\"" + aNewList['products'][i]['value'] + "\" />");
							elOptNew.text = aNewList['products'][i]['name'];
						@else @*/
							var elOptNew = document.createElement('option');
							elOptNew.text = aNewList['products'][i]['name'].unescapeHTML();
							elOptNew.value = aNewList['products'][i]['value'];
						/*@end
					@*/
							try
							{
							document.getElementById(QuickSearchIDStart + "cboBrandProduct").add(elOptNew, null); // standards compliant; doesn't work in IE
							} catch(ex) {
							document.getElementById(QuickSearchIDStart + "cboBrandProduct").add(elOptNew); // IE only
							}
						}
					// following line works in IE only
					/*@cc_on 
						dropdown_menu_hack(document.getElementById(QuickSearchIDStart + "cboBrandProduct")); 
					@*/
						document.getElementById(QuickSearchIDStart + "Drop5").style.display = QPSDisplayType;
					}
					break;

				default:
					break;
			}			
		}
	}
}










