function pro_menu_change(x,key){
	if (key ==1){
		document.getElementById('pro_menu_a_'+x).style.display = "none";
		document.getElementById('pro_menu_b_'+x).style.display = "";
	}else{
		document.getElementById('pro_menu_a_'+x).style.display = "";
		document.getElementById('pro_menu_b_'+x).style.display = "none";
	}
}

function class_count(){		
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	send_product_class_root = document.getElementById('product_class_root').value;
	var url;
	url = send_product_class_root + '/M_products_class/class_count/'+new Date().getTime();
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('product_class_total_counts').value =  xmlhttp.responseText;
					product_class_list();
				}
			}
		};
	xmlhttp.send();
	return false;
}

function product_class_list(){	
	send_product_class_select_model = document.getElementById('product_class_select_model').value;
	send_product_class_root         = document.getElementById('product_class_root').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var url;
	switch(parseInt(send_product_class_select_model)){
		case 1:
			url = send_product_class_root + '/M_products_class/product_class_list/'+new Date().getTime();
			break;
	}
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {			
					document.getElementById('product_total_class').innerHTML =  xmlhttp.responseText;
					ctrl_menu_class();
				}
			}
		};
	xmlhttp.send();
	return false;
}

function ctrl_menu_class(){
	counts = parseInt(document.getElementById('product_class_total_counts').value);
	for (i=1 ; i<=counts ; i++){
			document.getElementById('pro_class'+i).style.display = "none";
	}
	document.getElementById('pro_class1').style.display = "block";
}

function change_class(x){
	counts = parseInt(document.getElementById('product_class_total_counts').value);
	for (i=1 ; i<=counts ; i++){
			document.getElementById('pro_class'+i).style.display = "none";
	}
	document.getElementById('pro_class'+x).style.display = "block";
	return false;
}

function load_product_class(select_model,root){
	html_object = "<input id=\"product_class_root\" type=\"hidden\" value="+root+"/>";
	html_object = html_object + "<input id=\"product_class_total_counts\" type=\"hidden\" value=0 />";
	html_object = html_object + "<input id=\"product_class_select_model\" type=\"hidden\" value="+select_model+" />";
	document.getElementById('allProductsClassScript').innerHTML = html_object;
    class_count();
	loading_product_class_gif();
}

function add_class_click(number){  //累加點擊數
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	send_product_class_root = document.getElementById('product_class_root').value;
	var url;
	url = send_product_class_root + '/M_products_class/add_class_click/'+number+'/'+new Date().getTime();
	
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					//alert( xmlhttp.responseText);
					//document.getElementById('product_class_total_counts').value =  xmlhttp.responseText;
					//product_class_list();
				}
			}
		};
	xmlhttp.send();
	return false;
}


//---------連結窗口----------------------------
function show_product_class(class_number){
	  
  //----處理畫面不在products------------------------------	
  send_root = document.getElementById('product_class_root').value;
  try {
	  document.getElementById('product_page_url').value = document.getElementById('product_page_url').value;
  } catch(err) {
	  window.location = send_root + "products/class_number/class/"+class_number+"/";
  }		
  //--------------------------------------------------------
  
  document.getElementById('product_request_type').value = "class";       //接口(類別)
  document.getElementById('product_search').value = class_number;        //接口(輸入類別number)
  connect_product_page();                                                //送資料進產品主頁
  return false;
}


function loading_product_class_gif(){
	send_root = document.getElementById('product_class_root').value;
	send_root = ReplaceAll(send_root,"/index.php","");
	document.getElementById('product_total_class').innerHTML    = "<div style=\"width:100%\" align=\"center\"><img src=\""+send_root+"system/media/model_img/M_products_class/loading.gif\" width=\"50\" height=\"50\"/></div>";	
}

function ReplaceAll(strSource, strFind, strRepl) {   //取代的function 
    var str5 = new String(strSource);
    while (str5.indexOf(strFind) != -1) {
          str5=str5.replace(strFind, strRepl);
    }
   return str5;
}

