/*For Index Page*/
function ChangeCategoryMenu(categoryNumId)
{
	//alert(categoryNumId);
	if(categoryNumId==0){return false;}
	ChangeMainBanner(categoryNumId);
	//ChangeDropDown(categoryNumId);
	$.get(js_web_url+"index.php?main_page=popup_search&categories_id="+categoryNumId, function(data){
																												
       eval(data);
	 
//判断下级栏目的类型   
	try{
		dropDownData = eval("dataBrand");
		nextLevel="Brand";
		//
	}catch(e)
    {
		try{
		    dropDownData = eval("dataSeries");
		    nextLevel="Series";	
		}catch(e){
			 try{
		         dropDownData = eval("dataModel");
		         nextLevel="Model";	
	     	 }catch(e){
				 try{
					 dropDownData = eval("dataProductType");
					 nextLevel="ProductType";	
				 }catch(e){                  
					 try{
						 dropDownData = eval("dataSubCategoryType");
						 nextLevel="SubCategoryType";	
					 }catch(e){                  
					     nextLevel="NoSubCategory";	//没有子目录
					 }
				 }

	     	 }
		}
	}
	switch(nextLevel){
		case "Brand":
		    ClearDropDown('Level1Sel','Select a brand');
		   	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level1Sel")[0].disabled=false; 
					$("#Level1Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level1Sel").show();
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			$("#Level4Sel").show();
			ClearDropDown('Level2Sel','Select a Series');
			ClearDropDown('Level3Sel','Select a Model');
			ClearDropDown('Level4Sel','Select a ProductType');
			
		break;
		case "Series":
		    ClearDropDown('Level1Sel','Select a Series');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level1Sel")[0].disabled=false; 
					$("#Level1Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level1Sel").show();
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			ClearDropDown('Level2Sel','Select a Model');
			ClearDropDown('Level3Sel','Select a ProductType');
			$("#Level4Sel").hide();
			
		break;
		case "Model":
		    ClearDropDown('Level1Sel','Select a Model');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level1Sel")[0].disabled=false; 
					$("#Level1Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			ClearDropDown('Level2Sel','Select a ProductType');
			$("#Level1Sel").show();
			$("#Level2Sel").show();
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
		break;		
		case "ProductType":
		    ClearDropDown('Level1Sel','Select a ProductType');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level1Sel")[0].disabled=false; 
					$("#Level1Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level1Sel").show();
			$("#Level2Sel").hide();
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
		break;
		case "SubCategoryType"://SubCategoryType
		    ClearDropDown('Level1Sel','Select a Sub Category');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level1Sel")[0].disabled=false; 
					$("#Level1Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level1Sel").show();
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			$("#Level4Sel").show();
			ClearDropDown('Level2Sel','Select a Series');
			ClearDropDown('Level3Sel','Select a Model');
			ClearDropDown('Level4Sel','Select a ProductType');
		break;
       default: //如果没有 数据 说明没有子栏目
	        $("#Level1Sel").hide();
	   		$("#Level2Sel").hide();
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
    }
    data=null;
	
  // alert(nextLevel);

     });//end get function

}


function ChangeLevel1(categoryNumId){ 
    if(categoryNumId==0){return false;}
	$.get(js_web_url+"index.php?main_page=popup_search&categories_id="+categoryNumId, function(data){
       eval(data);
//判断下级栏目的类型  
// 该栏目下 可能的栏目类型有：  Series,model ,ProductType,subCategoryType,
	try{
		dropDownData = eval("dataSeries");
		nextLevel="Series";	
	}catch(e){
		 try{
			 dropDownData = eval("dataModel");
			 nextLevel="Model";	
		 }catch(e){
			 try{
				 dropDownData = eval("dataProductType");
				 nextLevel="ProductType";	
			 }catch(e){                  
				 try{
					 dropDownData = eval("dataSubCategoryType");
					 nextLevel="SubCategoryType";	
				 }catch(e){                  
					 nextLevel="NoSubCategory";	//没有子目录
				 }
			 }

		 }
	}

	switch(nextLevel){
		case "Series":
		    ClearDropDown('Level2Sel','Select a Series');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level2Sel")[0].disabled=false; 
					$("#Level2Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			$("#Level4Sel").show();
			ClearDropDown('Level3Sel','Select a Model');
			ClearDropDown('Level4Sel','Select a ProductType');
			
		break;
		case "Model":
		//少了 series 这一栏目 则隐藏第4个
		    ClearDropDown('Level2Sel','Select a Model');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level2Sel")[0].disabled=false; 
					$("#Level2Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			ClearDropDown('Level3Sel','Select a ProductType');
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			$("#Level4Sel").hide();
		break;		
		case "ProductType":
		//少了 series ptype 则 隐藏2个
		    ClearDropDown('Level2Sel','Select a ProductType');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level2Sel")[0].disabled=false; 
					$("#Level2Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level2Sel").show();
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
		break;
		case "SubCategoryType"://SubCategoryType
		    ClearDropDown('Level1Sel','Select a Sub Category');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level2Sel")[0].disabled=false; 
					$("#Level2Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level2Sel").show();
			$("#Level3Sel").show();
			$("#Level4Sel").show();
			ClearDropDown('Level2Sel','Select a Series');
			ClearDropDown('Level3Sel','Select a Model');
			ClearDropDown('Level4Sel','Select a ProductType');
		break;
       default: //如果没有 数据 说明没有子栏目
	        $("#Level2Sel").hide();
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
    }
    data=null;
	
  // alert(nextLevel);

     });//end get function	
}


function ChangeLevel2(categoryNumId){ 
    if(categoryNumId==0){return false;}
	$.get(js_web_url+"index.php?main_page=popup_search&categories_id="+categoryNumId, function(data){
       eval(data);
//判断下级栏目的类型  
// 该栏目下 可能的栏目类型有：  model ,ProductType,subCategoryType,
	 try{
		 dropDownData = eval("dataModel");
		 nextLevel="Model";	
	 }catch(e){
		 try{
			 dropDownData = eval("dataProductType");
			 nextLevel="ProductType";	
		 }catch(e){                  
			 try{
				 dropDownData = eval("dataSubCategoryType");
				 nextLevel="SubCategoryType";	
			 }catch(e){                  
				 nextLevel="NoSubCategory";	//没有子目录
			 }
		 }

	 }


	switch(nextLevel){
		case "Model":
		    ClearDropDown('Level3Sel','Select a Model');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level3Sel")[0].disabled=false; 
					$("#Level3Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			ClearDropDown('Level4Sel','Select a ProductType');
			$("#Level3Sel").show();
			$("#Level4Sel").show();
		break;		
		case "ProductType":
		//少了 series ptype 则 隐藏1个
		    ClearDropDown('Level3Sel','Select a ProductType');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level3Sel")[0].disabled=false; 
					$("#Level3Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level3Sel").show();
			$("#Level4Sel").hide();
		break;
		case "SubCategoryType"://SubCategoryType
		    ClearDropDown('Level3Sel','Select a Sub Category');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level3Sel")[0].disabled=false; 
					$("#Level3Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level3Sel").show();
			$("#Level4Sel").show();
			ClearDropDown('Level4Sel','Select a ProductType');
		break;
       default: //如果没有 数据 说明没有子栏目
			$("#Level3Sel").hide();
			$("#Level4Sel").hide();
    }
    data=null;
	
  // alert(nextLevel);

     });//end get function	
}

function ChangeLevel3(categoryNumId){ 
	if(categoryNumId==0){return false;}
	$.get(js_web_url+"index.php?main_page=popup_search&categories_id="+categoryNumId, function(data){
       eval(data);
//判断下级栏目的类型  
// 该栏目下 可能的栏目类型有：  ProductType,subCategoryType,
	 try{
		 dropDownData = eval("dataProductType");
		 nextLevel="ProductType";	
	 }catch(e){                  
		 try{
			 dropDownData = eval("dataSubCategoryType");
			 nextLevel="SubCategoryType";	
		 }catch(e){                  
			 nextLevel="NoSubCategory";	//没有子目录
		 }
	 }



	switch(nextLevel){
		case "ProductType":
		//少了 series ptype 则 隐藏1个
		    ClearDropDown('Level4Sel','Select a ProductType');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level4Sel")[0].disabled=false; 
					$("#Level4Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level4Sel").show();
		break;
		case "SubCategoryType"://SubCategoryType
		    ClearDropDown('Level4Sel','Select a Sub Category');
		  	for(i = 0; i < dropDownData.length; i++)
	     	{
				if(dropDownData[i].name != "" && dropDownData[i].value != "")
				{
					$("#Level4Sel")[0].disabled=false; 
					$("#Level4Sel")[0].options.add(new Option(dropDownData[i].name,dropDownData[i].value));
				}
		    }
			$("#Level4Sel").show();
		break;
       default: //如果没有 数据 说明没有子栏目
			$("#Level4Sel").hide();
    }
    data=null;
	
  // alert(nextLevel);

     });//end get function	
}

function ChangeLevel4(){
	}


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 2: //AV
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddav_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 44: //CELL
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddcp_dec_01_2010.jpg" width="370" height="268" /></a>';				
				break;
			case 46: //DV
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_dddv_dec_01_2010.jpg" width="370" height="268" /></a>';				
				break;
			case 16: //GAME
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddgame_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 6: //INK
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddink_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 22: //MP3
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddmp3_generic.jpg" width="370" height="268" /></a>';				
				break;
			case 48: //PC
			case 48:
				divBanner.innerHTML = '<a href="http://vip.mazentop.com:8026/zc_644/index.php?main_page=product_info&cPath=2_10&products_id=13"><img border="0" src="http://images.eforcity.com/cdn/efc/ad/banner/idx_ddpc_dec_01_2010_v2.jpg" width="370" height="268" /></a>';				
				break;			
			default:
				break;
		}
		divBanner.style.display = "block";
	}
}

/*End For Index Page*/


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;
}

function ClearDropDown(sel,text)
{
  var sel = document.getElementById(sel);
	if(sel != null)
	{
		sel.options.length = 0;
		sel.options.add(new Option(text,"0"));
	}
}

function quick_search_submit(){
	var cpath;
 if($("#CategoryMenuSel").css("display")!="none"){
	  if($("#CategoryMenuSel").val()!=0){
		 cpath=$("#CategoryMenuSel").val();   
	  }
 }
  if($("#Level1Sel").css("display")!="none"){
	  if($("#Level1Sel").val()!=0){
		 cpath=$("#Level1Sel").val();   
	  }
 }
  if($("#Level2Sel").css("display")!="none"){
	  if($("#Level2Sel").val()!=0){
		 cpath=$("#Level2Sel").val();   
	  }
 }
  if($("#Level3Sel").css("display")!="none"){
	  if($("#Level3Sel").val()!=0){
		 cpath=$("#Level3Sel").val();   
	  }
 }
  if($("#Level4Sel").css("display")!="none"){
	  if($("#Level4Sel").val()!=0){
		 cpath=$("#Level4Sel").val();   
	  }
 }
 if( cpath>0){
  window.location.href=js_web_url+"index.php?main_page=index&cPath="+cpath;
 }

	
}


