var OID ="";
var LID ="";
var MP ="";

var useEfSch = false;
var searchByYsOnly = 0;
var html = '';
var c = '';

function SearchRedirectPage() {
	var stxt = document.getElementById("SearchBoxQueryTbx").value;

	if(stxt == "")
	{
		alert("You must input Search textbox");
		return false;
	}
	else
	{
		var isEfSchReady = true;
		if(searchByYsOnly == 1) {
			isEfSchReady = false;
		}
		var f = document.forms["SearchBoxFrm"];
		var divv = document.getElementById("TestImageDiv");
		divv.innerHTML = "";
		divv.innerHTML = "<img id=\"CSCheck\" onerror=\"SearchRedirectPage1(false);\" src=\"http://search.eforcity.com/ClientSearchHtml/images/spacer.gif\" onload=\"SearchRedirectPage1(true);\" />";

		if(useEfSch == true && isEfSchReady == true) {

			if(typeof(OID) == 'undefined')
			{
				f.oid = "";
			}
			else
			{
				f.oid = OID;
			}

			if(typeof(LID) == 'undefined')
			{
				f.lid = "";
			}
			else
			{
				f.lid = LID;
			}

			if(typeof(MP) == 'undefined')
			{
				f.mp = "";
			}
			else
			{
				f.mp = MP;
			}

			f.action = "http://www.eforcity.com/efsearch2.html";
		}
		else {
			f.action = "http://search.store.yahoo.com/cgi-bin/nsearch";
		}
		return true;
	}
}
function SearchRedirectPage1(result) {
	useEfSch = result;
}

function popup(name,url,w,h)
{
    mywindow = window.open (url,name,"location=0,status=0,scrollbars=1,width="+w+",height="+h);
}

var persisteduls=new Object();
var ddtreemenu=new Object();

ddtreemenu.closefolder="http://images.eforcity.com/cdn/efc/template/common/dotline_plus.jpg"; //set image path to "closed" folder image
ddtreemenu.openfolder="http://images.eforcity.com/cdn/efc/template/common/dotline_subtract.jpg"; //set image path to "open" folder image

ddtreemenu.createTree=function(treeid, enablepersist, persistdays)
{
    var rootnode=document.getElementById(treeid);
    if(rootnode!=undefined)
    {
    var ultags=document.getElementById(treeid).getElementsByTagName("ul");//get all url gar in parent div

    if (typeof persisteduls[treeid]=="undefined") //get cookie arry of treeid containted.
        persisteduls[treeid]=(enablepersist==true && ddtreemenu.getCookie(treeid)!="")? ddtreemenu.getCookie(treeid).split(",") : "";

    for (var i=0; i<ultags.length; i++)
    {//build subtree in div tree.
        ddtreemenu.buildSubTree(treeid, ultags[i], i);
        if(ddtreemenu.openhref && ddtreemenu.openhref.length>0)
        {
			try
			{
			   if(ultags[i].parentNode.childNodes[0].innerHTML.toLowerCase().match(ddtreemenu.openhref.toLowerCase()))
					call:ultags[i].parentNode.onclick(null);
			}
			catch (err)
			{
			}
        }
    }

    if (enablepersist==true)
    { //if enable persist feature
        var durationdays=(typeof persistdays=="undefined")? 1 : parseInt(persistdays);
        ddtreemenu.dotask(window, function(){ddtreemenu.rememberstate(treeid, durationdays)}, "unload"); //save opened UL indexes on body unload
    }
    }
}



ddtreemenu.buildSubTree=function(treeid, ulelement, index)
{
    ulelement.parentNode.className="submenu";//set super parent node className="submenu";
    if (typeof persisteduls[treeid]=="object")
    { //if cookie exists (persisteduls[treeid] is an array versus "" string)
        if (ddtreemenu.searcharray(persisteduls[treeid], index))
        {
        ulelement.setAttribute("rel", "open");
        ulelement.style.display="block";
        ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")";
        }
        else
        ulelement.setAttribute("rel", "closed");
    } //end cookie persist code

    else if (ulelement.getAttribute("rel")==null || ulelement.getAttribute("rel")==false) //if no cookie and UL has NO rel attribute explicted added by user
        ulelement.setAttribute("rel", "closed");
    else if (ulelement.getAttribute("rel")=="open") //else if no cookie and this UL has an explicit rel value of "open"
        ddtreemenu.expandSubTree(treeid, ulelement); //expand this UL plus all parent ULs (so the most inner UL is revealed!)

    ulelement.parentNode.onclick=function(e)
    {
        var submenu=this.getElementsByTagName("ul")[0];
        if (submenu.getAttribute("rel")=="closed")
        {
            //alert(submenu.innerHTML);
            submenu.style.display="block";
            submenu.setAttribute("rel", "open");
            ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")";
        }
        else if (submenu.getAttribute("rel")=="open")
        {
            //alert(submenu.innerHTML);
            submenu.style.display="none";
            submenu.setAttribute("rel", "closed");
            ulelement.parentNode.style.backgroundImage="url("+ddtreemenu.closefolder+")";
        }
        else
        {
            alert("Error!!");
        }
        ddtreemenu.preventpropagate(e);
    }

    ulelement.onclick=function(e)
    {
        ddtreemenu.preventpropagate(e);
    }
}



ddtreemenu.expandSubTree=function(treeid, ulelement){ //expand a UL element and any of its parent ULs
var rootnode=document.getElementById(treeid);
var currentnode=ulelement;
currentnode.style.display="block";
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")";
while (currentnode!=rootnode){
if (currentnode.tagName=="UL"){ //if parent node is a UL, expand it too
currentnode.style.display="block";
currentnode.setAttribute("rel", "open"); //indicate it's open
currentnode.parentNode.style.backgroundImage="url("+ddtreemenu.openfolder+")";
}
currentnode=currentnode.parentNode;
}
}



ddtreemenu.flatten=function(treeid, action){ //expand or contract all UL elements
var rootnode=document.getElementById(treeid);
if(rootnode!=undefined)
{
var ultags=rootnode.getElementsByTagName("ul");
for (var i=0; i<ultags.length; i++){
ultags[i].style.display=(action=="expand")? "block" : "none";
var relvalue=(action=="expand")? "open" : "closed";
ultags[i].setAttribute("rel", relvalue);
ultags[i].parentNode.style.backgroundImage=(action=="expand")? "url("+ddtreemenu.openfolder+")" : "url("+ddtreemenu.closefolder+")";
}
}
}


ddtreemenu.rememberstate=function(treeid, durationdays){ //store index of opened ULs relative to other ULs in Tree into cookie
var ultags=document.getElementById(treeid).getElementsByTagName("ul");
var openuls=new Array();
for (var i=0; i<ultags.length; i++){
if (ultags[i].getAttribute("rel")=="open");
openuls[openuls.length]=i; //save the index of the opened UL (relative to the entire list of ULs) as an array element
}
if (openuls.length==0) //if there are no opened ULs to save/persist
openuls[0]="none open"; //set array value to string to simply indicate all ULs should persist with state being closed
ddtreemenu.setCookie(treeid, openuls.join(","), durationdays); //populate cookie with value treeid=1,2,3 etc (where 1,2... are the indexes of the opened ULs)
}





////A few utility functions below//////////////////////

ddtreemenu.getCookie=function(Name){ //get cookie value
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1]; //return its value
return "";
}




ddtreemenu.setCookie=function(name, value, days){ //set cookei value
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=expireDate.setDate(expireDate.getDate()+parseInt(days))
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}



ddtreemenu.searcharray=function(thearray, value){ //searches an array for the entered value. If found, delete value from array
var isfound=false;
for (var i=0; i<thearray.length; i++){
if (thearray[i]==value){
isfound=true;
thearray.shift(); //delete this element from array for efficiency sake
break;
}
}
return isfound;
}




ddtreemenu.preventpropagate=function(e)
{ //prevent action from bubbling upwards
    if(e===null) return;
    if(typeof e!="undefined")
        e.stopPropagation();
    else
        event.cancelBubble=true;
}



ddtreemenu.dotask=function(target, functionref, tasktype){ //assign a function to execute to an event handler (ie: onunload)
var tasktype=(window.addEventListener)? tasktype : "on"+tasktype;
alert(tasktype);
if (target.addEventListener)
target.addEventListener(tasktype, functionref, false);
else if (target.attachEvent)
target.attachEvent(tasktype, functionref);
}


function verifySingup(f,emailid) {
  var msg;
  var empty_fields = "";
  var errors = "";
  var error_msg = "";

  var re = new RegExp(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/);

  var email = document.getElementById(emailid);

  if(email!=undefined)
  {
      if ((email.value == null) || (email.value == "") || isblank(email.value)) {
        error_msg = "* Your email field is empty.";
        empty_fields += "\n      " + error_msg;
      }
      else if (!email.value.match(re)) {
      //else if (f.email.value.indexOf("@")==-1) {
        error_msg = "* Your email address is invalid";
        empty_fields += "\n      " + error_msg;
      }
  }

  if (!empty_fields && !errors) {
    f.method = "POST";
    f.action = "http://jeapromo.com/EmailUnsubscribe/subscribe.aspx?branchId=1";
    return true;
  }
  msg  = "  Your request cannot continue. \n";
  msg += "  Please correct the following error(s) and re-submit:\n";
  msg += "_______________________________________________\n";

  if (empty_fields) {
    msg += empty_fields + "\n";
  }
  alert(msg);
  return false;
}
function isblank(s) {
  for(var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ')&&(c != '\n')&&(c != '\t')) {
      return false;
    }
  }
  return true;
}
function signUp() {
//  var f = document.getElementById('fSignUp');
    var f = document.forms['fSignUp'];

      if(verifySingup(f,'element-formsubscribe-email')) {
        f.submit();
      }
}

/*Drop Down Search Begin*/
var useEfQuickSearch = false;
var useEfSearchEngine = false;

function QuickSearchRedirect(result)
{
	useEfQuickSearch = result;
}
function SearchEngineRedirect(result)
{
	useEfSearchEngine = result;
}

function ParsePage(useEfParse,pageId,version)
{
	var url = "";
	if(useEfParse == true)
	{
		//url = "http://localhost/ClientDropDownSearchHtml/ParseXMLFile.aspx?pageID=" + pageId + "&version=" + version;
		//url = "http://64.183.97.131/WebSearchCatTest/ParseXMLFile.aspx?pageID=" + pageId + "&version=" + version;
		url = "http://search.eforcity.com/ClientDropDownSearchHtml/ParseXMLFile.aspx?pageID=" + pageId + "&version=" + version;
	}
	else
	{
		url = "http://search2.eforcity.com/ClientDropDownSearchHtml/ParseXMLFile.aspx?pageID=" + pageId + "&version=" + version;
	}

	var divPa = document.getElementById("divParse");
	if(divPa != null)
	{
		var script = document.createElement("script");
		script.src = url;
		script.type = "text/javascript";
		divPa.appendChild(script);
	}
}

function QuickSearchEngine(frm)
{
	if(frm != null)
	{
		frm.action = "http://www.eforcity.com/efsearch2.html";
	}
	return true;
}

function GetDropDownData(sel,text,varName,parameters,defaultVal,productTypeNumId,postfixId)
{
	if(sel == null)
	{
		return;
	}
	ClearDropDown(sel,"Loading...");

	var url = "";
	if(useEfQuickSearch == true)
	{
		//url = "http://localhost/ClientDropDownSearchHtml/DropDownSearchEngine.aspx?" + parameters;
		//url = "http://64.183.97.131/WebSearchCatTest/DropDownSearchEngine.aspx?" + parameters;
		url = "http://search.eforcity.com/ClientDropDownSearchHtml/DropDownSearchEngine.aspx?" + parameters;
	}
	else
	{
		url = "http://search2.eforcity.com/ClientDropDownSearchHtml/DropDownSearchEngine.aspx?" + parameters;
	}

	var divCat = document.getElementById("divCategory");
	if(divCat != null)
	{
		var script = document.createElement("script");
		script.src = url;
		script.type = "text/javascript";
		divCat.appendChild(script);

		if (!/*@cc_on!@*/0)
		{
			script.onload = function()
			{
				BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId);
			}
		}
		else
		{
			script.onreadystatechange = function()
			{
				if (script.readyState == 'loaded' || script.readyState == 'complete')
				{
					BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId);
				}
			}
		}
	}
}

function BindDropDown(sel,text,varName,defaultVal,productTypeNumId,postfixId)
{
	var dropDownData = null;
	var hasData = false;
	try
	{
		dropDownData = eval("data" + varName);
		hasData = true;
	}
	catch(e)
	{
		hasData = false;
	}

	ClearDropDown(sel,text);
	if(hasData == true)
	{
		if(sel != null && dropDownData != null)
		{
			if(dropDownData.length > 0 && dropDownData[0].name != "" && dropDownData[0].value != "")
			{
				if(varName == "Model")
				{
					sel.options.add(new Option("All models","0"));
				}
				else if(varName == "ProductType")
				{
					sel.options.add(new Option("All Products","0"));
				}
				else if(varName == "SubProductType")
				{
					sel.options.add(new Option("All Sub Products","0"));
				}
			}

			for(i = 0; i < dropDownData.length; i++)
			{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					sel.options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
			}
		}
		defaultVal = defaultVal == null ? 0 : defaultVal;
		SetDisabledByLength(sel);
		SetDefaultValue(sel,defaultVal);
		SetHiddenValue(productTypeNumId,postfixId);
	}
}

/*Page Load Inital Begin*/
function IndexPageLoad()
{
	InitalDropDown();
	ClearHiddenValue();
	var catSel = document.getElementById("CategoryMenuSel");
	if(catSel != null)
	{
		catSel.selectedIndex = 0;
	}
}
/*Page Load Inital End*/

/*For Index Page*/
function ChangeCategoryMenu(categoryNumId)
{
	ChangeDropDown(categoryNumId);

	var bdSel = document.getElementById("BrandSel");
	var ptSel = document.getElementById("ProductTypeSel");
	if(bdSel != null && ptSel != null)
	{
		if(categoryNumId > 0)
		{
			GetDropDownData(bdSel,"Select a brand","Brand","ro=Brand&cni=" + categoryNumId);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + categoryNumId);
		}
		else
		{
			ClearDropDown(bdSel,"Select a brand");
			SetDisabled(bdSel,true);
			ClearDropDown(ptSel,"Select a product type");
			SetDisabled(ptSel,true);
		}
	}
}
function ChangeDropDown(categoryNumId)
{
	if(categoryNumId > 0)
	{
		ChangeMainBanner(categoryNumId);
	}

	var categoryDiv = document.getElementById('CategoryDiv');
	var subProductTypeDiv = document.getElementById('SubProductTypeDiv');
	var lengthDiv = document.getElementById('LengthDiv');
	if(categoryDiv != null && subProductTypeDiv != null)
	{
		if(categoryNumId == 1 || categoryNumId == 8)
		{
			categoryDiv.style.display = "none";
			subProductTypeDiv.style.display = "block";
			if(categoryNumId == 1)
			{
				lengthDiv.style.display = "block";
			}
			else
			{
				lengthDiv.style.display = "none";
			}
		}
		else
		{
			categoryDiv.style.display = "block";
			subProductTypeDiv.style.display = "none";
			lengthDiv.style.display = "none";
		}
	}
	ClearDropDownValue();
	ClearHiddenValue();

	var divCat = document.getElementById("divCategory");
	if(divCat != null)
	{
		divCat.innerHTML = "";
	}
}
function ChangeMainBanner(categoryNumId)
{
	var divBannerMenu = getElementsByNameFixed("div","divBannerMenu");
	if(divBannerMenu != null)
	{
		for(i = 0; i < divBannerMenu.length; i++)
		{
			divBannerMenu[i].style.display = "none";
		}
		LoadBannerImage(categoryNumId);
	}
}
function LoadBannerImage(categoryNumId)
{
	var divBanner = document.getElementById("divBannerMenu" + categoryNumId);
	if(divBanner != null)
	{
		switch(parseInt(categoryNumId))
		{
			case 1:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/av-promo2-ef.html?int=efindxbanfsh08-av"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddav_nov.jpg" width="370" height="268" /></a>';
				break;
			case 2:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/cell-phone-accessories-promotion.html?int=efindxbanfsh01-cp"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddcellphone_nov.jpg" width="370" height="268" /></a>';
				break;
			case 3:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/dv-promo2-ef.html?int=efindxbanfsh03-dv"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_dddv_nov.jpg" width="370" height="268" /></a>';
				break;
			case 4:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/game-promo2-ef.html?int=efindxbanfsh06-game"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddgame_nov.jpg" width="370" height="268" /></a>';
				break;
			case 5:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/ink-promo2-ef.html?int=efindxbanfsh05-ink"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddink_nov.jpg" width="370" height="268" /></a>';
				break;
			case 6:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/mp3-promo2-ef.html?int=efindxbanfsh02-mp3"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddmp3_nov.jpg" width="370" height="268" /></a>';
				break;
			case 8:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/pc-promo2-ef.html?int=efindxbanfsh07-pc"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddpc_nov.jpg" width="370" height="268" /></a>';
				break;
			case 9:
				divBanner.innerHTML = '<a href="http://www.eforcity.com/pda-accessories-promotion.html?int=efindxbanfsh04-pda"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddpda_nov.jpg" width="370" height="268" /></a>';
				break;
			default:
				break;
		}
		divBanner.style.display = "block";
	}
}
function ClearDropDownValue()
{
	var srSel = document.getElementById("SeriesSel");
	var mdSel = document.getElementById("ModelSel");
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	ClearDropDown(srSel,"Select a series");
	SetDisabled(srSel,true);
	ClearDropDown(mdSel,"Select a model");
	SetDisabled(mdSel,true);
	ClearDropDown(sptSel,"Select a sub product type");
	SetDisabled(sptSel,true);
	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}
/*End For Index Page*/

function ChangeBrand(bni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && srSel!= null && mdSel != null && ptSel != null)
		{
			GetDropDownData(srSel,"Select a series","Series","ro=Series&cni=" + catSel.value + "&bni=" + bni + "&pni=" + ptSel.value);
			GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bni + "&pni=" + ptSel.value);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bni,ptSel.value);
		}
	}
}

function ChangeSeries(sni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && bdSel != null && mdSel != null && ptSel != null)
		{
			GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + sni + "&pni=" + ptSel.value,mdSel.value);
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + sni,ptSel.value);
		}
	}
}

function ChangeModel(mni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);

	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && bdSel != null && srSel!= null && ptSel != null)
		{
			GetDropDownData(ptSel,"Select a product type","ProductType","ro=ProductType&cni=" + catSel.value + "&bni=" + bdSel.value + "&sni=" + srSel.value + "&mni=" + mni,ptSel.value);
		}
	}
}

function ChangeProductType(pni,categoryNumId,productTypeNumId,postfixId)
{
	categoryNumId = categoryNumId == null ? 0 : categoryNumId;
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");

	if(categoryNumId == 0)
	{
		if(catSel != null)
		{
			//For Index Page
			if(catSel.value > 0 && bdSel != null && srSel!= null && mdSel != null && sptSel != null)
			{
				var bni = bdSel.value;
				var sni = srSel.value;
				var mni = mdSel.value;
				GetDropDownData(bdSel,"Select a brand","Brand","ro=Brand&cni=" + catSel.value + "&pni=" + pni,bni);
				GetDropDownData(srSel,"Select a series","Series","ro=Series&cni=" + catSel.value + "&bni=" + bni + "&pni=" + pni,sni);
				GetDropDownData(mdSel,"Select a model","Model","ro=Model&cni=" + catSel.value + "&bni=" + bni + "&sni=" + sni + "&pni=" + pni,mni);
				GetDropDownData(sptSel,"Select a sub product type","SubProductType","ro=SubProductType&cni=" + catSel.value + "&bni=" + bni + "&sni=" + sni + "&mni=" + mni + "&pni=" + pni);
			}
		}
	}

	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}

function ChangeSubProductType(spni)
{
	var catSel = document.getElementById("CategoryMenuSel");
	var ptSel = document.getElementById("ProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	if(catSel != null)
	{
		//For Index Page
		if(catSel.value > 0 && ptSel != null && lenSel != null)
		{
			GetDropDownData(lenSel,"Select a length","Length","ro=Length&cni=" + catSel.value + "&pni=" + ptSel.value + "&spni=" + spni);
		}
	}
}

function SetHiddenValue(productTypeNumId,postfixId)
{
	productTypeNumId = productTypeNumId == null ? 0 : productTypeNumId;
	postfixId = postfixId == null ? "" : postfixId;

	var catSel = document.getElementById("CategoryMenuSel");
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	var lenHid = document.getElementById("LengthHid");
	var ptHid = document.getElementById("ProductTypeHid" + postfixId);
	if(catSel != null)
	{
		//For Index Page
		if(ptSel != null && sptSel != null && ptHid != null)
		{
			if(catSel.value != 1)
			{
				ptHid.value = sptSel.value == 0 ? ptSel.value : sptSel.value;
			}
			if(ptSel.selectedIndex <= 0)
			{
				ptHid.value = 0;
			}
		}
	}

	if(lenSel != null && lenHid != null)
	{
		lenHid.value = lenSel.selectedIndex > 0 ? lenSel.options[lenSel.selectedIndex].text : "";
	}
}

function InitalDropDown(postfixId)
{
	postfixId = postfixId == null ? "" : postfixId;

	var bdSel = document.getElementById("BrandSel" + postfixId);
	var srSel = document.getElementById("SeriesSel" + postfixId);
	var mdSel = document.getElementById("ModelSel" + postfixId);
	var ptSel = document.getElementById("ProductTypeSel" + postfixId);
	var sptSel = document.getElementById("SubProductTypeSel");
	var lenSel = document.getElementById("LengthSel");
	ClearDropDown(bdSel,"Select a brand");
	SetDisabled(bdSel,true);
	ClearDropDown(srSel,"Select a series");
	SetDisabled(srSel,true);
	ClearDropDown(mdSel,"Select a model");
	SetDisabled(mdSel,true);
	ClearDropDown(ptSel,"Select a product type");
	SetDisabled(ptSel,true);
	ClearDropDown(sptSel,"Select a sub product type");
	SetDisabled(sptSel,true);
	ClearDropDown(lenSel,"Select a length");
	SetDisabled(lenSel,true);
}

function ClearHiddenValue(postfixId)
{
	postfixId = postfixId == null ? "" : postfixId;

	var ptHid = document.getElementById("ProductTypeHid" + postfixId);
	var lenHid = document.getElementById("LengthHid");
	if(ptHid != null)
	{
		ptHid.value = "";
	}
	if(lenHid != null)
	{
		lenHid.value = "";
	}
}

function ClearDropDown(sel,text)
{
	if(sel != null)
	{
		sel.options.length = 0;
		sel.options.add(new Option(text,"0"));
	}
}

function SetDisabledByLength(sel)
{
	if(sel != null)
	{
		if(sel.length > 1)
		{
			sel.disabled = false;
		}
		else
		{
			sel.disabled = true;
		}
	}
}

function SetDisabled(sel,status)
{
	if(sel != null)
	{
		sel.disabled = status;
	}
}

function SetDefaultValue(sel,val)
{
	if(sel != null)
	{
		sel.value = val;
		if(sel.selectedIndex < 0)
		{
			sel.selectedIndex = 0;
		}
	}
}

function getElementsByNameFixed(tag,name)
{
	var elem = document.getElementsByTagName(tag);
	var count = 0;
	var elements = [];
	for(var i = 0; i < elem.length; i++)
	{
		if(elem[i].getAttribute("name") == name)
		{
			elements[count] = elem[i];
			count++;
		}
	}
	return elements;
}
/*Drop Down Search End*/

/*-- menu tree Begin--*/
var ddtreemenu = {};
ddtreemenu.openhref = '';
ddtreemenu.createTree = function () {return false;}

function toggleMenu(ele) {
	ele.toggleClass('select')
	    .parent('.nav-hasSon').toggleClass('nav-text-select')
							.next('ul').animate({height: 'toggle'}, 'fast');
}
function treeMenu(ele) {
	var ele = $('#'+ele+'');
	ele.find('li:has(ul)').find('.nav-text a')
					   .click(function (e) {
						   e.preventDefault();
						   this.blur();
						   var eleData = ele.NavFocusObj;
						   if(eleData && eleData != this && $(eleData).attr('class')=='select') {
							  toggleMenu($(ele.NavFocusObj));
						   }
						   ele.NavFocusObj = this;
						   toggleMenu($(this));
					   })
					  .parent('div.nav-text').addClass('nav-hasSon');
	ele.find('li:not(:has(ul))').find('.nav-text a').click(function () {
		$(this).addClass('select');
		ele.NavFocusObj = this;
	})
	//select current page
	if(ddtreemenu.openhref) {
		$('#'+ddtreemenu.openhref.replace(/(\s*)|(\s*$)/g,'')).find('.nav-text a').click();
	}
}
/*-- menu tree End--*/