/*globals $$, window, document, location , ,dojo,dijit,setTimeout,console*/


var portlet_with_empty_content,browserType,displaySignInfo1,checkUniqueOmnitureCookie,clearSelectedCell,formOmnitureCode, gridProduct,gridProductFamily,gridProductLine,displayProductLinesByFamily, displayProductByLine,displayProductLinks, getSelectedProductFamily, replaceAll, hidePane, getproductLineByFamily, resetPane,getSelectedProductLine,alignText,getProductByLine,showPane,widgetHeight,baseHeight,gridProductStore,productItem;

"use strict";

dojo.requireLocalization("dojoc.productselector","locale_ps",null,"en,en-us,zh,zh-cn,ROOT,jp,ar-ar,ar-xr,cs-cz,de-de,es-es,es-la,es-xl,hu-hu,fr-fr,he-il,id-id,it-it,ja-jp,ko-kr,nl-nl,pl-pl,pt-br,ru-ru,sv-se,th-th,tr-tr,uk-ua,vi-vn,zh-tw");
this.i18n=dojo.i18n.getLocalization("dojoc.productselector","locale_ps",this.lang);

var gridLayoutFamily = [{ 
		name: this.i18n.gridproductFamilyheader,
		field: "name",
		headerClasses: "gridhead",
		cellClasses: "gridcell",
		width:"192px",		
		noresize:"true",
		formatter:alignText
}];
var gridLayoutLine = [{
		name: this.i18n.gridproductLineheader,
		field: "name",
		headerClasses: "gridhead",
		cellClasses: "gridcell",
		width:"192px",
		noresize:"true",
		formatter:alignText
}];
var gridLayoutProduct = [{
		name: this.i18n.gridproductproductheader,
		field: "name",
		headerClasses: "gridhead",
		cellClasses: "gridcell",
		width:"192px",
		noresize:"true",
		formatter:alignText
}];
var gridLayoutProductLinks = [{
		name: this.i18n.gridproductlinksheader,
		field: "name",
		headerClasses: "gridhead",
		width:"192px",
		noresize:"true",
		formatter:alignText
}];

var selectedLevel = 1;
var mouseout = 0;

//method which displays the final set of pages
function alignText(value) {

	value+= "&nbsp;&nbsp;<font class='support_widget_arrow'>&gt;</font>";	
	return value;

}
//method called when the close link is clicked

function close()
{	
	document.getElementById("mod-quick-browse-overlay").style.display="none";			
	
	if(document.getElementById("blog-name")!=null)
	{
		document.getElementById("blog-name").style.display="block";				
	}
	
	dojo.query(".mod-quick-browse-overlay-backdrop").style("display","none");
	//alert("closing");
	
	
}

//method called when the Start over link is clicked
function startOver() {
    var grid, jsonStore, status, locale, gotItems,i;
    if(widgetType != null) {
    
console.log("start over called on load");    	
    	
    	if(widgetType == "nooverlay" || widgetType == "overlay"){
		widgetHeight = document.getElementById("support-browse4ps").offsetHeight-26;
		console.log("start over called on load: "+widgetHeight);  
		//dojo.byId('scroller').scrollRight = '290';
		document.getElementById("productFamilyGrid").style.visibility = "visible";
		
		grid = dijit.byId("gridProductFamily");
		//setting the initial height of the widget	
		baseHeight = 256;

		if(widgetType == "overlay"){
			dojo.byId('scroller').style.overflow = "hidden";
			dojo.byId('scroller').style.height = 225 + widgetHeight +'px';
		}
		
		dojo.byId('rootDiv').style.height = widgetHeight + baseHeight + 'px';		
		
		//alert("after JS error");
		status='active';
		locale = javeLocale;

		//code to call the server side and form the productLine.JSON file
		jsonStore = new dojo.data.ItemFileReadStore({
		    url: "/p/ProductSelectionServlet/productselection?level=1&locale=" + locale + "&status=" + status
		});

		gotItems = function(items, request){
		    console.log("Number of items loaded: " + items.length);
		if (items.length === 0) {
			document.getElementById("pswidget").style.display = "none";
			document.getElementById("widgeterrorspace").style.display = "block";
		    } 	
		};

		grid.setStore(jsonStore);		
		grid.store.fetch({serverQuery: {start: 0,count: 1},onComplete: gotItems});
		grid.startup(); 	


		if(document.getElementById("defaultloading") != null){
			document.getElementById("defaultloading").style.display = "none"; 
		}		
		
		if(document.getElementById("mod-quick-browse") != null){
			document.getElementById("mod-quick-browse").style.display = "block"; 
		}	
		
		if(document.getElementById("mod-box-737-bottom") != null){
			document.getElementById("mod-box-737-bottom").style.display = "block"; 
		}
		
		if(document.getElementById("mod-quick-browse-box-inner") != null){
					document.getElementById("mod-quick-browse-box-inner").style.display = "block"; 
		}
		console.log("visibility: "+document.getElementById("productFamilyGrid").style.visibility);

		//clearSelectedCell(grid,1);
		
		dojo.byId("splitContainer").style.width = "681px";		
		
    	}
    }
}
//method called when the Start over link is clicked
function startOverAgain() {


    var grid, jsonStore, status, locale;
	//alert("startOverAgain");    
    	document.getElementById("productFamilyGrid").style.visibility = "visible";

	//reset the second pane
	document.getElementById("loadMessageForProductLine").style.display = "none";		
	//document.getElementById("productLineGrid").style.display = "none";	
	document.getElementById("productLineGrid").style.visibility = "hidden";
	document.getElementById("loadTextForproductLine").style.display = "block";
		
	//reset the third pane	
   	document.getElementById("loadTextForProduct").style.display = "none";   	
   	//document.getElementById("productGrid").style.display = "none";
   	document.getElementById("productGrid").style.visibility = "hidden";
   	document.getElementById("loadMessageForProduct").style.display = "none";	
   	document.getElementById("loadEmptyTextForProduct").style.display = "block";
	
	
	//hide the last pane
	hidePane("pane4");
	//alert(widgetType);
	//console.log("widgetType=" + widgetType);
	
	if(widgetType === "nooverlay")
	{		
		dojo.byId('rootDiv').style.height = widgetHeight + baseHeight +'px';
		dojo.byId('rootDiv').style.overflow = "hidden";
	}
	
	   
		
	//hiding the start over
	document.getElementById("supportstartover").style.visibility = "hidden";
	
	grid = dijit.byId("gridProductFamily");
	
	//code to check whether the eois is selected or not
    if (dojo.byId("eoisproducts").checked) {
		status='active';
		locale=javeLocale;
		
		//code to call the server side and form the productLine.JSON file
        jsonStore = new dojo.data.ItemFileReadStore({
            url: "/p/ProductSelectionServlet/productselection?level=1&locale=" + locale + "&status=" + status
        });
        
		grid.setStore(jsonStore);		
		grid.startup(); 
	}
	
	document.getElementById("activeproducts").checked = true;
	document.getElementById("eoisproducts").checked = false;	
	
	if(widgetType === "nooverlay")
	{		
		document.getElementById("defaultloading").style.display = "none"; 
	}
	
	clearSelectedCell(grid,0);   	 	
   	
   	selectedLevel = 1;
   	
   	
   	if(widgetType === "nooverlay")
	{		
		dojo.byId("scroller").style.width = "681px";
	}
   	

}
//method called when - onclick of the product Family cell
function displayProductLinesByFamily(e) {


    var selectedValue, selectedEOISFlagValue, selectedActiveFlagValue;

	selectedValue = gridProductFamily.store.getValue(gridProductFamily.getItem(e.rowIndex),"id");
	selectedEOISFlagValue = gridProductFamily.store.getValue(gridProductFamily.getItem(e.rowIndex),"EOISFlag");
	selectedActiveFlagValue = gridProductFamily.store.getValue(gridProductFamily.getItem(e.rowIndex),"ActiveFlag");
	
	console.log("selected product Family selectedValue:"+selectedValue);
	console.log("selected product Family selectedEOISFlagValue:"+selectedEOISFlagValue);
	console.log("selected product Family selectedActiveFlagValue:"+selectedActiveFlagValue);
		
	getproductLineByFamily(selectedValue,selectedEOISFlagValue,selectedActiveFlagValue);
}
//method called to display the product Line based on product Family
function getproductLineByFamily(productFamily, selectedEOISFlagValue, selectedActiveFlagValue) {
    var grid, status, locale, jsonStore, gotItems;
	
	//alert("product family clicked");
	grid = dijit.byId("gridProductLine");
	
	//reset the third pane
	resetPane("loadTextForProduct");
	
	
	//document.getElementById("productGrid").style.display = "none";
	document.getElementById("productGrid").style.visibility = "hidden";
	document.getElementById("loadMessageForProduct").style.display = "none";
	document.getElementById("loadEmptyTextForProduct").style.display = "none";
	
	document.getElementById("productLineGrid").style.visibility = "visible";
	document.getElementById("loadTextForproductLine").style.display = "none";
	document.getElementById("loadMessageForProductLine").style.display = "none";
	
	//hide the last pane
	hidePane("pane4");
	
	
	//code to check whether the eois is selected or not
	status='active';
	locale=javeLocale;
    		
	//code to check whether the eois is selected or not
    if (dojo.byId("eoisproducts").checked) {
		status="eois";
	}	
        
    if ((status == "active" && selectedActiveFlagValue == "Y") || (status == "eois" && selectedEOISFlagValue == "Y")) {
	
	//code to call the server side and form the productLine.JSON file
        jsonStore = new dojo.data.ItemFileReadStore({
            url: "/p/ProductSelectionServlet/productselection?level=2&parentid=" + productFamily + "&status=" + status + "&locale=" + locale
        });

		gotItems = function(items, request){
		    console.log("Number of items loaded: " + items.length);
            if (items.length === 0) {
			clearSelectedCell(grid,1);
				
			document.getElementById("loadTextForproductLine").style.display = "none";
			//document.getElementById("productLineGrid").style.display = "none";		
			document.getElementById("productLineGrid").style.visibility = "hidden";
			document.getElementById("loadMessageForProductLine").style.display = "block";
		    }
            else {
			document.getElementById("loadTextForproductLine").style.display = "none";
			document.getElementById("loadMessageForProductLine").style.display = "none";		
			//document.getElementById("productLineGrid").style.display = "block";
			
			if(document.getElementById("productLineGrid").style.visibility != "visible"){			                    
	                    	
				document.getElementById("productLineGrid").style.visibility = "visible";			                 
                        }
			clearSelectedCell(grid,1);		    
		    }
		};		
		
	grid.setStore(jsonStore);	
        grid.store.fetch({serverQuery: {start: 0,count: 1},onComplete: gotItems});

        // Call startup, in order to render the grid:
        grid.startup();       

    }
	    
    else {
  
        clearSelectedCell(grid,1);
	
	document.getElementById("loadTextForproductLine").style.display = "none";
	//document.getElementById("productLineGrid").style.display = "none";		
	document.getElementById("productLineGrid").style.visibility = "hidden";
	document.getElementById("loadMessageForProductLine").style.display = "block";
	
    }		
        
        //document.getElementById("pane2").style.left = "0px";
        document.getElementById("supportstartover").style.visibility = "visible";
	

	document.getElementById("loadEmptyTextForProduct").style.display = "none";
	document.getElementById("loadMessageForProduct").style.display = "none";
	//document.getElementById("productGrid").style.display = "none";		
	document.getElementById("productGrid").style.visibility = "hidden";
	document.getElementById("loadTextForProduct").style.display = "block";	
	//sliding the component
	//slideComponent("pane2");
	
	selectedLevel = 2;
	if(widgetType == "nooverlay"){
	dojo.byId('rootDiv').style.height = widgetHeight + baseHeight + 'px';
	}
		
}
//method called when - onclick of the product Line cell
function displayProductByLine(e) {	

    var selectedValue, selectedValueEOISFlag, selectedValueActiveFlag;

	selectedValue = gridProductLine.store.getValue(gridProductLine.getItem(e.rowIndex),"id");
	selectedValueEOISFlag = gridProductLine.store.getValue(gridProductLine.getItem(e.rowIndex),"EOISFlag");
	selectedValueActiveFlag = gridProductLine.store.getValue(gridProductLine.getItem(e.rowIndex),"ActiveFlag");	
	
	console.log("selected product Line selectedValue:"+selectedValue);	
	console.log("selected product Line selectedValueEOISFlag:"+selectedValueEOISFlag);
	console.log("selected product Line selectedValueActiveFlag:"+selectedValueActiveFlag);
	
	//hidePane("pane4");
	
    if (selectedValue !== -1 && selectedValue !== "") {
		getProductByLine(selectedValue,e,selectedValueEOISFlag,selectedValueActiveFlag);
	}
	
}
//method called to display the product based on product Line
function getProductByLine(productLine, e, selectedValueEOISFlag, selectedValueActiveFlag) {
	
    var grid, status, locale, jsonStore, gotItems;
	
	grid = dijit.byId("gridProduct");	
	
	document.getElementById("productGrid").style.visibility = "visible";
	document.getElementById("loadTextForProduct").style.display = "none";
	document.getElementById("loadEmptyTextForProduct").style.display = "none";   				   				
	document.getElementById("loadMessageForProduct").style.display = "none";	
	
	//code to check whether the eois is selected or not
	status='active';
	locale=javeLocale;
	
	//hiding the fourth pane if shown to the user
	hidePane("pane4");
	
    if (dojo.byId("eoisproducts").checked) {
        status = 'eois';
	}
	
    if ((status == "active" && selectedValueActiveFlag == "Y") || (status == "eois" && selectedValueEOISFlag == "Y")) {

        //code to call the server side and form the productLine.JSON file
        jsonStore = new dojo.data.ItemFileReadStore({
            url: "/p/ProductSelectionServlet/productselection?level=3&parentid=" + productLine + "&status=" + status + "&locale=" + locale
        });		
		
	gotItems = function(items, request){
	    console.log("Number of items loaded: " + items.length);
        if (items.length === 0) {	
				
		clearSelectedCell(grid,2);		
		
		document.getElementById("loadTextForProduct").style.display = "none";
		document.getElementById("loadEmptyTextForProduct").style.display = "none";   				   			
		//document.getElementById("productGrid").style.display = "none";
		document.getElementById("productGrid").style.visibility = "hidden";
		document.getElementById("loadMessageForProduct").style.display = "block";
            }
            else {
            
		document.getElementById("loadTextForProduct").style.display = "none";
		document.getElementById("loadEmptyTextForProduct").style.display = "none";   			
		document.getElementById("loadMessageForProduct").style.display = "none";   			
		//document.getElementById("productGrid").style.display = "block";
		
		if(document.getElementById("productGrid").style.visibility != "visible"){			                    	                    	
			document.getElementById("productGrid").style.visibility = "visible";			                                    
		}
		clearSelectedCell(grid,2);		    
	    }
	};		
		
	grid.setStore(jsonStore);				
		
	grid.store.fetch({serverQuery: {start: 0,count: 1},onComplete: gotItems});		
	grid.startup();		
		
	}
    else {
		clearSelectedCell(grid,2);		
		
		document.getElementById("loadTextForProduct").style.display = "none";
		document.getElementById("loadEmptyTextForProduct").style.display = "none";   				   			
		//document.getElementById("productGrid").style.display = "none";
		document.getElementById("productGrid").style.visibility = "hidden";
		document.getElementById("loadMessageForProduct").style.display = "block";

	}
	
	//document.getElementById("pane3").style.left = "259px";	
	
			
	//sliding the component
	//slideComponent("pane3");	
	
	selectedLevel = 3;
	if(widgetType == "nooverlay"){
		dojo.byId('rootDiv').style.height = widgetHeight + baseHeight + 'px';
	}

}
//method called when - onclick of the product cell
function displayProductLinks(e) {

    var selectedProductFamilyShortName,selectedProductShortName,gridProductFamilyStore, selectedProductFamily, selectedProductLine,selectedProductFamilyId, selectedProductLineId, selectedProductValue, selectedValue, panel4InnerText, linkExistFlag, supportURL,supportHighlightsURL,supportCategorysURL, warrantyURL, langCode, downloadInd, linkURL, finalOmnitureCode,offsetHeight,linksHeaderHeight,locale,i,supportURLFlag,categoryLinkValue,categoryShortNameValue;
	
	dojo.query(".dojoxGridCellFocus").removeClass("dojoxGridCellFocus");
	//alert("Calling displayProductLinks");
	productItem = gridProduct.getItem(e.rowIndex);
	gridProductStore = gridProduct.store;
	selectedValue = gridProductStore.getValue(productItem,"id");
	
	categoryLinkValue = gridProductStore.getValue(productItem, "CategoryLinks");
	categoryShortNameValue = gridProductStore.getValue(productItem, "CategoryShortNames");	
	
	var shortNameList = new Array();	
	shortNameList = getCatList(categoryLinkValue,categoryShortNameValue);	
	console.log("short name list"+shortNameList);
	
	locale=javeLocale;	
	supportURLFlag = false;
	
	//getting the selected product family and line
	selectedProductFamily = getSelectedProductFamily("name");	
    selectedProductFamilyShortName = getSelectedProductFamily("shortName");	
    selectedProductShortName = gridProductStore.getValue(productItem,"shortName");	
	selectedProductLine = getSelectedProductLine("name");		
	selectedProductValue = gridProductStore.getValue(productItem,"name");	
	
	//getting the selected product family and line ids
	selectedProductFamilyId = getSelectedProductFamily("id");	
	selectedProductLineId = getSelectedProductLine("id");		
	
	console.log("selected product family id:"+selectedProductFamilyId);
	console.log("selected product line id:"+selectedProductLineId);	
	
	gridProductFamilyStore = gridProductFamily.store;
	
	dojo.byId("pane4").innerHTML = "";
	
	panel4InnerText = "";	
	
	dojo.requireLocalization("dojoc.productselector","locale_ps",null,"en,en-us,zh,zh-cn,ROOT,jp,ar-ar,ar-xr,cs-cz,de-de,es-es,es-la,es-xl,hu-hu,fr-fr,he-il,id-id,it-it,ja-jp,ko-kr,nl-nl,pl-pl,pt-br,ru-ru,sv-se,th-th,tr-tr,uk-ua,vi-vn,zh-tw");
	this.i18n=dojo.i18n.getLocalization("dojoc.productselector","locale_ps",this.lang);
	linkExistFlag = false;
	
	//re-direct to the highlights page based on the productfamily and product selected.
	if(widgetType=="overlay"){
	
		//Link level Omniture tracking.		
		waTrackAsLink('support_links','o','wa_custom06=nav:product_selector:product_click&wa_eCustom26=nav:product_selector:product_click&wa_events=se_cust05');
	
		//re-direct to the respective highlights page.
		window.location.href ="/p/"+locale+"/support/highlights/" + selectedProductFamilyShortName + "/" + selectedProductShortName;
		
		
	}
	// Check if the locale exists in languageList.xml and set the flag
	else{	
		
			for(i=0;i<strLangArray.length;i++){					
	
				if(javeLocale == strLangArray[i])
				{		
					supportURLFlag = true;					
	
				}	
			}		
	}     
	
	/*if the locale exists in languageList.xml construct 
	the highlights page URL else retrieve from PHD DB*/
	
	if(supportURLFlag)
	{
		console.log("inside the support URL flag..."+locale);
		supportHighlightsURL = "/p/"+locale+"/support/highlights/" + selectedProductFamilyShortName + "/" + selectedProductShortName;
		supportCategorysURL = "/p/"+locale+"/support/category/" + selectedProductFamilyShortName + "/" + selectedProductShortName;
		
	}
	
	supportURL = gridProductStore.getValue(productItem, "supportURL");
	
	
	console.log("supportURL is: "+ supportURL);
        panel4InnerText += "<div id= 'productlinksheader' class='listhead'>"+this.i18n.gridproductlinksheader+"</div>";
        panel4InnerText += "<div class='support-productlinkarea'><h4 class='support-linkh4header'>" + gridProductStore.getValue(productItem, "name") + "</h4><ul class='support-ul'>";                
        console.log("supportURL=" + supportURL);
		
		
	if(supportURLFlag)
	{	    
		finalOmnitureCode = formOmnitureCode(selectedProductFamily, selectedProductLine, selectedProductValue, "se_cust08", "support:prod_sel_supp_link");
		panel4InnerText += "<li class='support-li'><a onClick=\""+finalOmnitureCode+"\" title=\"" + this.i18n.productlinksproduct + "\" href='" + supportHighlightsURL + "'>"+this.i18n.productlinksproduct+"</a></li>";
		
		
		for(var l=0;l<shortNameList.length;l++){
			//var tmp = supportCategorysURL+"/"+shortNameList[l];
			var tmpResourceBundle = populateResourceBundleValue(shortNameList[l]);
			
			panel4InnerText += "<li class='support-li'><a onClick=\""+finalOmnitureCode+"\" title=\"" +tmpResourceBundle  + "\" href='" + supportCategorysURL+"/"+shortNameList[l] + "'>"+tmpResourceBundle+"</a></li>";
						
		}
		
		
		console.log("selected product:"+selectedValue);		
		linkExistFlag = true;
	}	

	downloadInd = gridProductStore.getValue(productItem, "downloadInd");
	langCode = gridProductStore.getValue(productItem, "langCode");
	console.log("downloadInd=" + downloadInd);
    if (downloadInd && downloadInd === "Y") {
        finalOmnitureCode = formOmnitureCode(selectedProductFamily, selectedProductLine, selectedProductValue, "se_cust02", "support:prod_sel_driver_link");
	    
	    linkURL = "http://downloadcenter.intel.com/Product_Filter.aspx?ProductID=" + selectedValue + "&lang="+langCode+ "&FamilyId="+selectedProductFamilyId+ "&LineId="+selectedProductLineId;	    
	    panel4InnerText += "<li class='support-li'><a onClick=\""+finalOmnitureCode+"\" href='" + linkURL + "'>"+this.i18n.productlinksdownloaddriver+"</a></li>";
	    linkExistFlag = true;
	}	
	
	warrantyURL = getSelectedProductFamily("warrantyURL");

	console.log("warranty URL "+warrantyURL);
	
    if (warrantyURL) {
        finalOmnitureCode = formOmnitureCode(selectedProductFamily, selectedProductLine, selectedProductValue, "se_cust03", "support:prod_sel_warranty_link");

	    //console.log("final Warranty URL is "+warrantyURL);
	    panel4InnerText += "<li class='support-li'><a onClick=\""+finalOmnitureCode+"\" href='" + warrantyURL + "'>"+this.i18n.productlinksWarranty+"</a></li>";
	    linkExistFlag = true;
	}
	
	panel4InnerText += "</ul></div>";
	
	dojo.byId("pane4").innerHTML  = panel4InnerText;
	
	if(widgetType != "overlay"){
	    if (linkExistFlag) {		
		showPane("pane4");		
		dojo.byId('scroller').scrollLeft = '290';
		dojo.byId('rootDiv').style.height = widgetHeight + baseHeight + 20 +'px';		
		document.getElementById("pane4").style.display = "block";				
		//sliding the component		
			if (browserType !== 'ie') {
				//document.getElementById("pane4").style.left = "518px";							
				//slideComponent("pane4");		   
			}		
	    }
	
    	    else {
		hidePane("pane4");
		dojo.byId('rootDiv').style.height = widgetHeight + baseHeight + 'px';
	    }
	    
	    selectedLevel = 4;
	    offsetHeight = document.getElementById("productlinksheader").offsetHeight;
	    linksHeaderHeight = offsetHeight-23;	
	    document.getElementById("productlinksheader").style.height = 15 + linksHeaderHeight + "px";
	}
	
	
}

//method to get the resource bundle value
		function populateResourceBundleValue(shortNameList)
		{
		if(shortNameList=="doc_guide")
		{
			return this.i18n.categorylinkscategory_doc_guide;
		}
		if(shortNameList=="rsrc_util")
		{
			return this.i18n.categorylinkscategory_resource_utilities;
		}
		if(shortNameList=="find_part_svc_wrnty")
		{
			return this.i18n.categorylinkscategory_parts;
		}
		if(shortNameList=="enhc_perf_mntain")
		{
			return this.i18n.categorylinkscategory_performance;
		}
		if(shortNameList=="trblsht")
		{
			return this.i18n.categorylinkscategory_troubleshooting;
		}
		if(shortNameList=="instl_confg")
		{
			return this.i18n.categorylinkscategory_install;
		}
		if(shortNameList=="rsrch_invsgt")
		{
			return this.i18n.categorylinkscategory_research;
		}
		if(shortNameList=="suprt_from_cmmty")
		{
			return this.i18n.categorylinkscategory_support_community;
		}
		if(shortNameList=="drv_dwnld")
		{
			return this.i18n.categorylinkscategory_driver_download;
		}
		
		}

//method to form the list of valid category URL to be shown
function getCatList(categoryLinkValue,categoryShortNameValue){
	
	//categoryLinkValue = "11706=Y;11704=N;11708=;11709=N;11710=N;11711=N";
	//categoryShortNameValue = "11706=doc_guide;11704=rsrc_util;11708=rsrch_invsgt;11709=instl_config;11710=trblsht;11711=enhc_perf_maintain";
	
	console.log("link should be shown for"+categoryLinkValue);
	console.log("corresponding short names are for"+categoryShortNameValue);
	
	var categoryShortName = new Array();
	var counter = 0;
	
	var catLinkValueList = categoryLinkValue.split(";");
	var catShortNameValueList = categoryShortNameValue.split(";");
	
	var shortNameArray = {};
		
	for(var j=0;j<catShortNameValueList.length;j++){
	
		var catShortNameValue = catShortNameValueList[j];
		var shortName = catShortNameValue.split("=");
		
		shortNameArray[shortName[0]] = shortName[1]
		console.log("short names are"+shortName[1]);	
	}

	console.log("final short name array is"+shortNameArray);

	for(var i=0;i<catLinkValueList.length;i++){
	
		var LinkValue = catLinkValueList[i];
		var catLinks = LinkValue.split("=");
		
		console.log("details are "+catLinks[1] +"and "+catLinks[0]);
		
		if(catLinks[1] == "Y"){			
			console.log("category for which the link should be displayed is"+catLinks[0]);
			console.log("category for which the link should be displayed is"+shortNameArray[catLinks[0]]);
			
			categoryShortName[counter] = shortNameArray[catLinks[0]];
			counter++;
		}	
	}
	
	console.log(categoryShortName);
	
	return categoryShortName;
}

//method called to hide a pane
function showPane(pane) {
    dojo.byId("splitContainer").style.width = "697px";
    dojo.byId("scroller").style.width = "679px";
    dojo.byId(pane).sizeMin = "227px";
    dojo.byId(pane).sizeShare = "227px";
    dojo.byId(pane).style.width = "227px";
}
//method called to show a pane
function hidePane(pane) {
    dojo.byId(pane).innerHTML = "";
    dojo.byId("splitContainer").style.width = "681px";
    dojo.byId(pane).sizeMin = "0";
    dojo.byId(pane).sizeShare = "0";
    dojo.byId(pane).style.width = "0";
}
//method called to reset the pane
function resetPane(divTagName) {
    document.getElementById(divTagName).style.display = "block";
	
}
//method called when the check box for the discontinued products is checked or unchecked
function showDiscontinuedProducts() {

    var status, locale, jsonStore, grid, productFamily, productLine, productFamilyEOISFlag, productFamilyActiveFlag, productLineEOISFlag, productLineActiveFlag, gotItems;

    //hiding the last pane
    hidePane("pane4");

    //calling startoveragain method to reset all the panes
    //startOverAgain();	
    status = 'active';
    locale = javeLocale;

    //code to check whether the eois is selected or not
    if (dojo.byId("eoisproducts").checked) {
        status = 'eois';
    }

    if (selectedLevel === 1) {
        //code to call the server side and form the productLine.JSON file
        jsonStore = new dojo.data.ItemFileReadStore({
            url: "/p/ProductSelectionServlet/productselection?level=1&locale=" + locale + "&status=" + status
        });
        grid = dijit.byId("gridProductFamily");
        grid.setStore(jsonStore);
        
        grid.startup(); 

	clearSelectedCell(grid,1);
		
    }	

    if (selectedLevel === 2) {
        productFamily = getSelectedProductFamily("id");
        productFamilyEOISFlag = getSelectedProductFamily("EOISFlag");
        productFamilyActiveFlag = getSelectedProductFamily("ActiveFlag");

        console.log("product family name :" + productFamily);
        console.log("product family productFamilyEOISFlag :" + productFamilyEOISFlag);
        console.log("product family productFamilyActiveFlag :" + productFamilyActiveFlag);

        grid = dijit.byId("gridProductLine");

        if ((status == "active" && productFamilyActiveFlag == "Y") || (status == "eois" && productFamilyEOISFlag == "Y")) {
        
            document.getElementById("productLineGrid").style.visibility = "visible";
            document.getElementById("loadTextForproductLine").style.display = "none";
            document.getElementById("loadMessageForProductLine").style.display = "none";

            jsonStore = new dojo.data.ItemFileReadStore({
                url: "/p/ProductSelectionServlet/productselection?level=2&parentid=" + productFamily + "&status=" + status + "&locale=" + locale
            });

            gotItems = function (items, request) {
                console.log("Number of items loaded: " + items.length);
                if (items.length === 0) {
                    console.log("data not available for this status.");

                    clearSelectedCell(grid,1);

                    //document.getElementById("productLineGrid").style.display = "none";
                    document.getElementById("productLineGrid").style.visibility = "hidden";
                    document.getElementById("loadTextForproductLine").style.display = "none";
                    document.getElementById("loadMessageForProductLine").style.display = "block";

                }
                else {
                    document.getElementById("loadTextForproductLine").style.display = "none";
                    document.getElementById("loadMessageForProductLine").style.display = "none";
                    //document.getElementById("productLineGrid").style.display = "block";
                    
                    if(document.getElementById("productLineGrid").style.visibility != "visible"){                    
                    	
                    	document.getElementById("productLineGrid").style.visibility = "visible";
                    
                    }

                    clearSelectedCell(grid,1);
                }
            };            
            
            grid.setStore(jsonStore);
            grid.store.fetch({serverQuery: {start: 0,count: 1},onComplete: gotItems});                      
            grid.startup(); 
            
        }
        else {
            console.log("data not available for this status.");

            clearSelectedCell(grid,1);

            //document.getElementById("productLineGrid").style.display = "none";
            document.getElementById("productLineGrid").style.visibility = "hidden";
            document.getElementById("loadTextForproductLine").style.display = "none";
            document.getElementById("loadMessageForProductLine").style.display = "block";
        }

    }

    if (selectedLevel === 3 || selectedLevel === 4) {
        productLine = getSelectedProductLine("id");
        productLineEOISFlag = getSelectedProductLine("EOISFlag");
        productLineActiveFlag = getSelectedProductLine("ActiveFlag");

        console.log("product family name :" + productLine);
        console.log("product family productFamilyEOISFlag :" + productLineEOISFlag);
        console.log("product family productFamilyActiveFlag :" + productLineActiveFlag);

        grid = dijit.byId("gridProduct");

        if ((status == "active" && productLineActiveFlag == "Y") || (status == "eois" && productLineEOISFlag == "Y")) {


		document.getElementById("productGrid").style.visibility = "visible";
		document.getElementById("loadTextForProduct").style.display = "none";
		document.getElementById("loadEmptyTextForProduct").style.display = "none";   				   				
		document.getElementById("loadMessageForProduct").style.display = "none";

            	jsonStore = new dojo.data.ItemFileReadStore({
                	url: "/p/ProductSelectionServlet/productselection?level=3&parentid=" + productLine + "&status=" + status + "&locale=" + locale
            	});


		gotItems = function(items, request){
	   	 console.log("Number of items loaded: " + items.length);
        	if (items.length === 0) {	
				
			clearSelectedCell(grid,2);		
		
			document.getElementById("loadTextForProduct").style.display = "none";
			document.getElementById("loadEmptyTextForProduct").style.display = "none";   				   			
			//document.getElementById("productGrid").style.display = "none";
			document.getElementById("productGrid").style.visibility = "hidden";
			document.getElementById("loadMessageForProduct").style.display = "block";
            	}
            	else {
            
			document.getElementById("loadTextForProduct").style.display = "none";
			document.getElementById("loadEmptyTextForProduct").style.display = "none";   			
			document.getElementById("loadMessageForProduct").style.display = "none";   			
			//document.getElementById("productGrid").style.display = "block";
		
			if(document.getElementById("productGrid").style.visibility != "visible"){			                    	                    	
				document.getElementById("productGrid").style.visibility = "visible";			                                    
			}
			clearSelectedCell(grid,2);		    
	    	}
		};		
		
		grid.setStore(jsonStore);				
		
		grid.store.fetch({serverQuery: {start: 0,count: 1},onComplete: gotItems});		
		grid.startup();	
 
        }
        else {

   		console.log("data not available for this status.");
   			
   		clearSelectedCell(grid,2);
   			
   		document.getElementById("loadTextForProduct").style.display = "none";
   		document.getElementById("loadEmptyTextForProduct").style.display = "none";   			
   		//document.getElementById("productGrid").style.display = "none";
   		document.getElementById("productGrid").style.visibility = "hidden";
   		document.getElementById("loadMessageForProduct").style.display = "block";
   		
   		}		
	}
}
//method to get the selected product family
function getSelectedProductFamily(attr) {
    var retutnValue, items, value;

    retutnValue = "";
    items = gridProductFamily.selection.getSelected();

    if (items.length) {
        // Iterate through the list of selected items.
        // The current item is available in the variable
        // "selectedItem" within the following function:
        dojo.forEach(items, function (selectedItem) {
        	
            if (selectedItem !== null) {
                // Iterate through the list of attributes of each item.
                // The current attribute is available in the variable
                // "attribute" within the following function:
                dojo.forEach(gridProductFamily.store.getAttributes(selectedItem), function (attribute) {
                    // Get the value of the current attribute:
                   value = gridProductFamily.store.getValues(selectedItem, attribute);
                    if (attribute === attr) {
                        retutnValue = value;
                    }

                }); // end forEach
            } // end if
        }); // end forEach
    } // end if
    return retutnValue;
}
//method to get the selected product Line
function getSelectedProductLine(attr) {
    var retutnValue, items, value;

    retutnValue = "";
    items = gridProductLine.selection.getSelected();
    console.log("item is " + items.length);

    if (items.length) {
        // Iterate through the list of selected items.
        // The current item is available in the variable
        // "selectedItem" within the following function:
        dojo.forEach(items, function (selectedItem) {
            if (selectedItem !== null) {
                // Iterate through the list of attributes of each item.
                // The current attribute is available in the variable
                // "attribute" within the following function:
                dojo.forEach(gridProductLine.store.getAttributes(selectedItem), function (attribute) {
                    // Get the value of the current attribute:
                    value = gridProductLine.store.getValues(selectedItem, attribute);
                    if (attribute === attr) {
                        retutnValue = value;
                    }

                }); // end forEach
            } // end if
        }); // end forEach
    } // end if
    return retutnValue;
}
//method which forms the omniture string
function formOmnitureCode(productFamily, productLine, Product, event, waiid) {
    var returnStr, familyStr, lineStr, prod, pagename, urlParameters, friendlyURL, urlval, loopcnt, corefriendlyURLarray, corefriendlyURL, urlpartsarray, localecode, linksecondparam;

    familyStr = "" + productFamily;
    lineStr = "" + productLine;
    prod = "" + Product;

    familyStr = replaceAll(familyStr, "&reg;", "");
    lineStr = replaceAll(lineStr, "&reg;", "");
    prod = replaceAll(prod, "&reg;", "");

    pagename = location.href;
    urlval = "";
    urlParameters = pagename.split('?');
    friendlyURL = urlParameters[0];
    corefriendlyURLarray = friendlyURL.split('/p/');
    corefriendlyURL = corefriendlyURLarray[1];
    urlpartsarray = corefriendlyURL.split('/');
    localecode = urlpartsarray[0];

	for (loopcnt=1;loopcnt<urlpartsarray.length;loopcnt=loopcnt+1){
		urlval = urlval+ urlpartsarray[loopcnt];
        if((urlval.match("#"+"$")=="#")||(urlval.match("/"+"$")=="/")){
			
			var len = urlval.length;
			urlval=urlval.substring(0,len-1);   	     
	   }
	       	if (loopcnt +1 <= urlpartsarray.length-1) {
		 	urlval = urlval;	       	
	       }
	}
	
	linksecondparam = urlval+":links";    

    //waiid = replaceAll(waiid, "::PAGE_NAME::", urlval + ":");
    //alert(waiid);
    if (familyStr !== "" && familyStr.length > 99) {
        familyStr = familyStr.substring(0, 99);
    }
    if (lineStr !== "" && lineStr.length > 99) {
        lineStr = lineStr.substring(0, 99);
    }
    if (prod !== "" && prod.length > 99) {
        prod = prod.substring(0, 99);
    }
    returnStr = "waCustomLink (this,'" + urlval + ":links','o','wa_custom42=" + familyStr + "&wa_eCustom42=" + familyStr + "&wa_custom43=" + lineStr + "&wa_eCustom43=" + lineStr + "&wa_custom45=" + localecode + "&wa_eCustom45=" + localecode + "&wa_custom44=" + prod + "&wa_eCustom44=" + prod + "&wa_events=" + event + "&wa_iid=" + waiid + "');";

    return returnStr;
}
//which replaces all the occurences of the string
function replaceAll( str, from, to ) {

    var idx = str.indexOf( from );

    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}
//method which does the sliding
function slideComponent(pane) {
    var slidePane2, slidePane3, slidePane4, slideDuration;

    slideDuration = 750;
    slidePane2 = {
        node: "pane2",
        duration: slideDuration,
        top: (dojo.coords("pane2").t).toString(),
        left: (dojo.coords("pane2").l + 259).toString(),
        unit: "px"
    };

    slidePane3 = {
        node: "pane3",
        duration: slideDuration,
        top: (dojo.coords("pane3").t).toString(),
        left: (dojo.coords("pane3").l + 259).toString(),
        unit: "px"
    };

    slidePane4 = {
        node: "pane4",
        duration: slideDuration,
        top: (dojo.coords("pane4").t).toString(),
        left: (dojo.coords("pane4").l + 259).toString(),
        unit: "px"
    };
    if (pane === "pane2") {
        dojo.query("#" + pane + " .dojoxGridScrollbox").addClass("noscroll");
        dojo.fx.slideTo(slidePane2).play();
    }
    else if (pane === "pane3") {
        dojo.query("#" + pane + " .dojoxGridScrollbox").addClass("noscroll");
        dojo.fx.slideTo(slidePane3).play();
    }
    else if (pane === "pane4") {
        dojo.query("#" + pane + " .support-productlinkarea").addClass("noscroll");
        dojo.fx.slideTo(slidePane4).play();
    }
    setTimeout('addScroll(\"' + pane + '\")', slideDuration);
}
//method which removes the slide at the run time
function addScroll(pane) {
    if (pane === "pane2") {
        dojo.query("#" + pane + " .dojoxGridScrollbox").removeClass("noscroll");
    }
    else if (pane === "pane3") {
        dojo.query("#" + pane + " .dojoxGridScrollbox").removeClass("noscroll");
    }
    else if (pane === "pane4") {
        dojo.query("#" + pane + " .support-productlinkarea").removeClass("noscroll");
    }

}
//function to clear the selected cell value
function clearSelectedCell(grid,level){

    var prevSelectedValue;
    
    dojo.query(".dojoxGridCellFocus").removeClass("dojoxGridCellFocus");
    
    if(grid.selection != null){   

    	prevSelectedValue = grid.selection.selectedIndex;
    	console.log("prevSelectedValue " + prevSelectedValue);

    	if (prevSelectedValue != -1) {
    	    console.log("selected product family index " + grid.selection.selectedIndex);
    	    //grid.focus.focusHeader();
    	    grid.selection.deselect(grid.selection.selectedIndex);        
    	    grid.scrollToRow(0);
    	    grid.focus.focusHeader();  	    
    	    
    	}    	    	
    	   	
    	//getting the focus back to the grid
    	if(level == 1)
    	{
    		console.log("reverting the focus back for the level"+level); 
    		var gridToFocus1 = dijit.byId("gridProductFamily");
    		gridToFocus1.focus.focusGrid();
    	}
    	if(level == 2)
    	{
    		console.log("reverting the focus back for the level"+level); 
    		var gridToFocus2 = dijit.byId("gridProductLine");
    		gridToFocus2.focus.focusGrid();
    	}
    	if(level == 3)
    	{
    		console.log("reverting the focus back for the level"+level); 
    		var gridToFocus3 = dijit.byId("gridProduct");
    		gridToFocus3.focus.focusGrid();
    	}
    	    
    }
           
}

//method which sets the text displayed for the passed locale
function setTextBasedOnLocale(locale) {
    var name;
    dojo.requireLocalization("dojoc.productselector", "locale_ps");
    name = dojo.i18n.getLocalization("dojoc.productselector", "locale_ps");

    //alert(name.findproduct);
    document.getElementById("support-browse4ps").innerHTML = name.findproduct;
}
//method which converts the java/browser locale to dojo locale
function convertJavaBrowserLocaleToDojoLocale(locale) {
    var formattedLocale;

    return formattedLocale;
}


function productSelectorKeyPress(e) {
    
    if(e.keyCode == 38 || e.keyCode == 40) // Up & Down Arrows
    {	
	dojo.query(".dojoxGridCellFocus").addClass("psKeyUpDown");		
	dojo.query(".dojoxGridCellOver").removeClass("psMouseOver");	
	dojo.query(".dojoxGridCellOver").removeClass("dojoxGridCellOver");
	dojo.query(".dojoxGridCellOver").addClass("defaultcell");
	dojo.query(".dojoxGridCellFocus").removeClass("psMouseOver");	
    }	
}

function productSelectorCellMouseOver(e) {

    if(mouseout == 1){    	
    	
    	dojo.query(".dojoxGridCellOver").addClass("psMouseOver");    
    	dojo.query(".dojoxGridCellOver").removeClass("psKeyUpDown");
    	dojo.query(".psMouseOut").removeClass("psKeyUpDown"); 
    	dojo.query(".dojoxGridCellOver").removeClass("psMouseOut");
    	mouseout = 0;
    }
}

function productSelectorCellMouseOut(e) {
     
    dojo.query(".dojoxGridCell").removeClass("psMouseOver");
    dojo.query(".dojoxGridCellFocus").addClass("psMouseOut");
    mouseout = 1;
}



