// JavaScript Document
 function getAjax(){
  var ajax=false; 
  try { 
   ajax = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (e) { 
   try { 
    ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
   } catch (E) { 
    ajax = false; 
   } 
  }
  if (!ajax && typeof XMLHttpRequest!='undefined') { 
   ajax = new XMLHttpRequest(); 
      if (ajax.overrideMimeType) 
			 {
       ajax.overrideMimeType('text/xml');
	   }
  } 
  return ajax;
 }
 
 function show(pro,objID){
  var objdiary = document.getElementById(objID);
  var pro;
      pro +="?"+Math.random();
  var ajaxFri = getAjax();   
  ajaxFri.open("GET", pro, true); 
  ajaxFri.onreadystatechange = function() { 
   if (ajaxFri.readyState == 4 && ajaxFri.status == 200) { 
    var text = ajaxFri.responseText; 
    if(text!=0){
     objdiary.innerHTML=text;
    }
   } 
  } 
    ajaxFri.send(null); 
 }

 
function reduceQuantity(code,p){
    var cartQty=code+"cartQty";
	var	qty = parseInt(document.getElementById(cartQty).value);
	if(qty>1){
		qty--;
		document.getElementById(cartQty).value = qty;
		changePrice(code,p);
	}
}

function increaseQuantity(code,p){
    var cartQty=code+"cartQty";
	var qty = parseInt(document.getElementById(cartQty).value);
	if(qty<999){
		qty++;
		document.getElementById(cartQty).value = qty;
		changePrice(code,p);
	}
}

function changePrice(code,p){
    var priceText=code+"priceText";
    var cartAmount=code+"cartAmount";
    var cartQty=code+"cartQty";
    var allPrice=code+"allPrice";
    var allQty=code+"allQty";
    var allAmount=code+"allAmount";
	var cartAmount=code+"cartAmount";
    
	var price = p;
	var qty = parseInt(document.getElementById(cartQty).value);
	if(qty==0||qty==null){
		document.getElementById(cartAmount).value = price;
		document.getElementById(cartQty).value=1;
		document.getElementById(allPrice).innderHTML = price;
		document.getElementById(allQty).innerHTML = 1;
		document.getElementById(allAmount).innerHTML = price;
	}
	if(qty>=1){
	   	
		if(qty>=2&&qty<5){
		price=(p*0.99).toFixed(2); 
		}
		if(qty>=5&&qty<10){
		price=(p*0.97).toFixed(2);	
		}
		if(qty>=10){
		price=(p*0.95).toFixed(2);	
		}
		document.getElementById(cartAmount).value = price;
        document.getElementById(priceText).innerHTML = price;
        document.getElementById(allPrice).innerHTML = price;
        document.getElementById(allQty).innerHTML = qty;
		document.getElementById(allAmount).innerHTML = (price*qty).toFixed(2);	
	}
}
