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);
	
	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_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 = _Web_Url + '/index.php/M_model/M_products/show_pro1/' + new Date().getTime();
			break;
		case 2:
			url = _Web_Url + '/index.php/M_model/M_products/show_pro2/' + new Date().getTime();
			break;
		case 3:
			url = _Web_Url + '/index.php/M_model/M_products/show_pro3/' + 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.open('POST',url,true);
	xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	xmlhttp.send("count="+count+"&send_url="+send_url+"&send_target="+send_target+"&model_count="+model_count);
	return false;
}

function load_products_count(){
	var xmlhttp;
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url;

	url = _Web_Url + '/index.php/M_model/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(select_model,url,count,target){
	var bgObj   = document.createElement("input"); 
	bgObj.id    = "total_count";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 
	
	var bgObj   = document.createElement("input"); 
	bgObj.value = url;
	bgObj.id    = "product_url";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 
	
	var bgObj   = document.createElement("input"); 
	bgObj.value = target;
	bgObj.id    = "product_target";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 

	var bgObj   = document.createElement("input"); 
	bgObj.value = select_model;
	bgObj.id    = "products_select_model";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 

	var bgObj   = document.createElement("input"); 
	bgObj.value = count;
	bgObj.id    = "products_pic_count";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 
	
	var bgObj   = document.createElement("input"); 
	bgObj.value = 0;
	  bgObj.id    = "pic_count";
	bgObj.type  = "hidden";
	document.body.appendChild(bgObj); 


	loading_products_gif();
	load_products_count();
}



function load_products_up(){
	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 = _Web_Url + '/index.php/M_model/M_products/load_procuts_up1/' + new Date().getTime();
			break;
		case 2:
			url = _Web_Url + '/index.php/M_model/M_products/load_procuts_up2/' + new Date().getTime();
			break;
		case 3:
			url = _Web_Url + '/index.php/M_model/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(){
	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 = _Web_Url + '/index.php/M_model/M_products/load_procuts_down1/' + new Date().getTime();
			break;
		case 2:
			url = _Web_Url + '/index.php/M_model/M_products/load_procuts_down2/' + new Date().getTime();
			break;
		case 3:
			url = _Web_Url + '/index.php/M_model/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(){
	document.getElementById('show_pro').innerHTML    = "<div style=\"width:100%\" align=\"center\"><img src=\""+_Web_Url+"/system/media/model_img/M_products/loading.gif\" width=\"50\" height=\"50\"/></div>";	
}
