function show_pro(type){
	loading_products_gif();
	count       = 0;
	send_products_select_model    = document.getElementById('products_select_model').value;
	send_products_select_model = parseInt(send_products_select_model);
	/*
	switch (send_products_select_model){
		case 1:
			model_count = 2;
			break;
		case 2:
			model_count = 3;
			break;
		case 3:
		    
			model_count = 5;
			break;
	}*/
	model_count = document.getElementById('products_pic_count').value; //產品數量
	model_count = parseInt(model_count);
	send_total_count = document.getElementById('total_count').value;
	document.getElementById('show_pro').style.width  = "230px";
	document.getElementById('show_pro').style.height = "100px";		
	send_root    = document.getElementById('product_root').value;
	send_url     = document.getElementById('product_url').value;
	send_target  = document.getElementById('product_target').value;
	
	if (type == 'down'){
		count = document.getElementById('pic_count').value;
		count = parseInt(count) + model_count;
		//alert(count +"----" + send_total_count)
		if (count >= send_total_count){
			//alert(count +"----" + send_total_count);
			count = count - model_count;
		}
		document.getElementById('pic_count').value = count;
	}if (type == 'up'){
		count = document.getElementById('pic_count').value;
		count = parseInt(count) - model_count;
		//alert(count +"----" + send_total_count)
		if (count < 0){
			count = count + model_count;
		}
		document.getElementById('pic_count').value = count;	
	}
	
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	send_url = ReplaceAll(send_url,"/","!");
	switch (send_products_select_model){
		case 1:
			url = send_root + '/M_products/show_pro1/'+count + "/" + send_url + "/" + send_target + "/" + model_count + "/" + new Date().getTime();
			break;
		case 2:
			url = send_root + '/M_products/show_pro2/'+count + "/" + send_url + "/" + send_target + "/" + model_count + "/" + new Date().getTime();
			break;
		case 3:
			url = send_root + '/M_products/show_pro3/'+count + "/" + send_url + "/" + send_target + "/" + model_count + "/" + new Date().getTime();
			break;
	}	
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('show_pro').innerHTML = xmlhttp.responseText;
					document.getElementById('show_pro').style.width  = "";
					document.getElementById('show_pro').style.height = "";	
				}
			}
		};
	xmlhttp.send();
	return false;
}

function load_products_count(){
	send_root    = document.getElementById('product_root').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;

	url = send_root + '/M_products/load_products_count/' + new Date().getTime();
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('total_count').value = xmlhttp.responseText;
					load_products_up();
				}
			}
		};
	xmlhttp.send();
	return false;
}

function load_products(products_select_model,root,url,count,target){
	html_object = "<input id=\"total_count\" type=\"hidden\" value= />";
	html_object = html_object + "<input id=\"product_root\"    type=\"hidden\"   value=" + root   + " />";
	html_object  = html_object + "<input id=\"product_url\"     type=\"hidden\"   value=" + url    + " />";
	html_object = html_object + "<input id=\"product_target\"  type=\"hidden\"   value=" + target + " />";
	html_object = html_object + "<input id=\"products_select_model\" type=\"hidden\" value="+products_select_model+" />";
	html_object = html_object + "<input id=\"products_pic_count\" type=\"hidden\" value="+count+" />";

	html_object = html_object + "<input id=\"pic_count\"       type=\"hidden\"   value=0 />";
	document.getElementById('allProductsScript').innerHTML = html_object;
	loading_products_gif();
	load_products_count();
	
}



function load_products_up(){
	
	send_root    = document.getElementById('product_root').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	send_products_select_model    = document.getElementById('products_select_model').value;
	send_products_select_model = parseInt(send_products_select_model);
	switch (send_products_select_model){
		case 1:
			url = send_root + '/M_products/load_procuts_up1/' + new Date().getTime();
			break;
		case 2:
			url = send_root + '/M_products/load_procuts_up2/' + new Date().getTime();
			break;
		case 3:
			url = send_root + '/M_products/load_procuts_up3/' + new Date().getTime();
			break;
	}	
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('show_pro_up').innerHTML = xmlhttp.responseText;
					load_products_down();
				}
			}
		};
	xmlhttp.send();
	return false;
}

function load_products_down(){
	send_root    = document.getElementById('product_root').value;
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;
	send_products_select_model    = document.getElementById('products_select_model').value;
	send_products_select_model = parseInt(send_products_select_model);
	switch (send_products_select_model){
		case 1:
			url = send_root + '/M_products/load_procuts_down1/' + new Date().getTime();
			break;
		case 2:
			url = send_root + '/M_products/load_procuts_down2/' + new Date().getTime();
			break;
		case 3:
			url = send_root + '/M_products/load_procuts_down3/' + new Date().getTime();
			break;
	}	
	
	xmlhttp.open('GET',url,true);
	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState == 4){
				if (xmlhttp.status == 200) {
					document.getElementById('show_pro_down').innerHTML = xmlhttp.responseText;
					show_pro('');
				}
			}
		};
	xmlhttp.send();
	return false;
}

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

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