var temp_faction_option = new Array();
var cart_show_pn = ''; //购物车最后一笔产品名称
var mouseover_flag = false;
var hide_minicart_seconds = 10000;

function hide_subMenu(sub_id){
	if(mouseover_flag==false)
	$("#"+sub_id).hide();
}
function show_subMenu(sub_id){
	$("#"+sub_id).fadeIn('slow');
}

function trans_name(pn){
	cart_show_pn = pn;
}
function change_pic_random(img_id){
	var img_obj = document.getElementById(img_id);
	var randomnumber = Math.floor(Math.random()*3);
	if (randomnumber==1)
	{
		img_obj.setAttribute("src","/skin1/newsale/images/ad_t8gear.jpg");
	}
	else
	{
		//alert(randomnumber);
	}
}
function show_products(label_text){
	var locationed = window.location;
	if(locationed.toString().indexOf('catgory.php?cat=')>0){
		window.location = locationed.toString().substr(0,locationed.toString().indexOf('catgory.php?cat=')) 
			+ 'catgory.php?cat='+label_text;
	}
	else{
		window.location = locationed+'catgory.php?cat='+label_text;
	}
}
function minicart_showhide(status,divid){
	if (status=='over'){
		mouseover_flag=true;
	}
	else{
		mouseover_flag=false;
		setTimeout(function(){hide_subMenu(divid)},hide_minicart_seconds/2);
	}
}
function GetQueryString(name) { 
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r!=null) 
		return unescape(r[2]); 
	return null; 
}
function InitPage_PW(){
	var label_txt=GetQueryString('cat');
	var flag=0;
	//alert('*'+label_txt+'*');
	var label_obj=document.getElementById('navtag_ul').getElementsByTagName("a");
	for (var i=0;i<label_obj.length;i++ )
	{
		//alert('*'+label_obj[i].name+'*');
		if (label_obj[i].name==label_txt)
		{
			flag=1;
			label_obj[i].className="current";
			break;
		}		
	}
	if (flag==0)
		label_obj[0].className="current";
		
}
function InitPage(){
//	EvPNG.fix('div, ul, img, li, input, h2, a ,button ,span ,p');
	var locationed = window.location;
	//alert(locationed);
	//var location_Reg = /cat=(\w*\'*\.*\w*-)*(\w*\'*\.*w*)+/;
	//var array=location_Reg.exec(locationed);
	var array=GetQueryString('cat');
	//alert(array);
	//getMiniCart("cart_show","");
	if (array != null){
		var server_select = document.getElementById("server_option");
		var faction_select = document.getElementById("faction_option");
		var obj_select = document.getElementById("server_option").getElementsByTagName("option");
		//alert(obj_select.length);
		if (faction_select != null)
		{
			var obj_faction = document.getElementById("faction_option").getElementsByTagName("option");
		}
		//var result=(array[0].toString().replace('cat=','')).split('-');
		var result=array.split('-');
		//alert(result);
		
		if (array.substr(array.length-3,3) == 'All'){
			var faction_opt = document.getElementById("faction_option");
			if (temp_faction_option.length == 0){
				for (i=faction_opt.options.length-1;i>-1;i--){
					//alert(obj_faction.options[i].text);
					temp_faction_option[i] = faction_opt.options[i].text;
					//alert(temp_faction_option[i]);
				}
			}

			for (i=faction_opt.options.length;i>0;i--){
				faction_opt.options[i]=null;
			}

			faction_opt.options[1] = new Option('All','');
		}else if(faction_select != null){
			var faction_opt=document.getElementById('faction_option');
		}else{
		}

		var final_server='';
		var final_faction='';

		if (faction_select != null){
			
			for (var i=1;i<faction_opt.length ;i++ ){
				if (result.toString().indexOf(faction_opt[i].innerHTML)>0){
					//final_server=result.toString().replace(faction_opt[i].innerHTML,'').replace(/,/g,' ');
					final_server=array.replace(faction_opt[i].innerHTML,'');
					final_server=final_server.toString().substr(0,final_server.length-1);
					final_faction=faction_opt[i].innerHTML;
					//alert('*'+final_server+'*');
					break;
				}
			}
		}else{
			final_server=array;
			final_server=final_server.toString();
		}

		
		//alert(obj_select.length);
		for (var i=0;i<obj_select.length;i++ ){
			//alert('*'+obj_select[i].innerHTML.replace(/ /gim,'-')+'*');
			//alert(final_server);
			if (obj_select[i].innerHTML.replace(/ /gim,'-')==final_server || obj_select[i].innerHTML.replace(/ /gim,'-')==(final_server+'-')){
				server_select.selectedIndex=i;
				//alert(obj_select[i].innerHTML);
				break;
			}
		}
		if (faction_select != null)
		{
			for (var i=0;i<obj_faction.length;i++ )
			{
				if (obj_faction[i].innerHTML==final_faction){
					faction_select.selectedIndex=i;
					break;
				}
			}
		}
		
	}
}
function find_obj(){
	var obj_select = document.getElementById("server_option");
	var obj_faction = document.getElementById("faction_option");
	var objs_s_option = obj_select.getElementsByTagName("option");
	var objs_f_option = obj_faction.getElementsByTagName("option");
	//alert(obj_faction.options.length);
	if (temp_faction_option.length == 0)
	{
		for (i=obj_faction.options.length-1;i>-1;i--){
			//alert(obj_faction.options[i].text);
			temp_faction_option[i] = obj_faction.options[i].text;
			//alert(temp_faction_option[i]);
		}
	}
	//alert('*'+objs_s_option[obj_select.selectedIndex].innerHTML+'*');
	if (objs_s_option[obj_select.selectedIndex].innerHTML == 'Gaheris' || objs_s_option[obj_select.selectedIndex].innerHTML == 'Mordred'
		|| objs_s_option[obj_select.selectedIndex].innerHTML == 'Gaheris ' || objs_s_option[obj_select.selectedIndex].innerHTML == 'Mordred '){
		for (i=obj_select.options.length;i>0;i--){
			var faction_opt = 'faction_opt_'+i;
			obj_faction.options[i]=null;
		}

		obj_faction.options[1] = new Option('All','');
	}else if (obj_select[obj_select.selectedIndex].text=="Please select"){
		//alert(obj_faction.options.length);
		for (i=obj_faction.options.length;i>0;i--){
			//alert(obj_faction.options[i]);
			var faction_opt = 'faction_opt_'+i;
			obj_faction.options[i]=null;
		}
		for (var i=1;i<temp_faction_option.length;i++ ){
			//alert(temp_faction_option[i]);
			obj_faction.options[i]= new Option(temp_faction_option[i],'');
		}
	}
	else if (obj_faction[obj_faction.selectedIndex].text=="All" || obj_faction[obj_faction.selectedIndex].text=="Please select"){
		//alert(obj_faction.options.length);
		for (i=obj_faction.options.length;i>0;i--){
			//alert(obj_faction.options[i]);
			var faction_opt = 'faction_opt_'+i;
			obj_faction.options[i]=null;
		}
		for (var i=1;i<temp_faction_option.length;i++ ){
			//alert(temp_faction_option[i]);
			obj_faction.options[i]= new Option(temp_faction_option[i],'');
		}
	}
	else
	{
		if (obj_faction[obj_faction.selectedIndex].text!="Please select")
		next_page();
	}
}
function next_page(){
	var locationed = window.location;
	var server_select = document.getElementById("server_option");
	var faction_select = document.getElementById("faction_option");
	var select_server_no = server_select.selectedIndex;
	var select_faction_no = faction_select.selectedIndex;
	if ((server_select[select_server_no].text!="Please select") && (faction_select[select_faction_no].text!="Please select"))
	{
		/*
		if(window.location.toString().indexOf('catgory.php?cat=')>0){
			window.location = locationed.toString().substr(0,locationed.toString().indexOf('catgory.php?cat=')) 
				+ 'catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-')+'-'+faction_select[select_faction_no].text.replace(/ /g,'-');
		}
		else{
			window.location = locationed+'catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-')+
				'-'+faction_select[select_faction_no].text.replace(/ /g,'-');
		}
		*/
		window.location = locationed.toString().substr(0,locationed.toString().lastIndexOf('/')) + '/catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-')+'-'+faction_select[select_faction_no].text.replace(/ /g,'-');
	}
}
function server_next_page(){
	var locationed = window.location;
	var server_select = document.getElementById("server_option");
	var select_server_no = server_select.selectedIndex;
	if (server_select[select_server_no].text!="Please select")
	{	
		/*
		if(window.location.toString().indexOf('catgory.php?cat=')>0){
			window.location = locationed.toString().substr(0,locationed.toString().indexOf('catgory.php?cat=')) 
				+ 'catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-');
		}
		else{
			window.location = locationed+'catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-');
		}
		*/
			window.location = locationed.toString().substr(0,locationed.toString().lastIndexOf('/')) + '/catgory.php?cat='+server_select[select_server_no].text.replace(/ /g,'-');

	}
}
