//显示chain信息
function product_ad_list_ajax(){
	delete xmlhttp ;
	var xmlhttp;
	if (xmlhttp==null || typeof(xmlhttp)!="object"){
		try{
			xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e){
			try{
				xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
			}catch(e){
				try{
					xmlhttp= new XMLHttpRequest();
				}catch(e){}
			}
		}
	}
	xmlhttp.onreadystatechange=function(){
		var i=0;
		if (4==xmlhttp.readyState){
			if (200==xmlhttp.status){
				var return_value=xmlhttp.responseText;
				if (return_value != null & return_value != ""){
					document.getElementById("div_content_chain").innerHTML = unescape(escape(return_value));
				}
			}
		delete xmlhttp ; 
		xmlhttp=null;
		CollectGarbage;
		}
	}
	xmlhttp.open("post", "/ajax_product_chain_list.php", true);
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded;text/xml;charset=utf-8");
	xmlhttp.send("act=list");
}
product_ad_list_ajax();

////////////////////////////////////////////////////////////////////////////////////////////////////
//显示默认FREE的chain
function default_select_chain(){
	delete xmlhttp ;
	var xmlhttp;
	if (xmlhttp==null || typeof(xmlhttp)!="object"){
		try{
			xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
		}catch(e){
			try{
				xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
			}catch(e){
				try{
					xmlhttp= new XMLHttpRequest();
				}catch(e){}
			}
		}
	}
	xmlhttp.onreadystatechange=function(){
		var i=0;
		if (4==xmlhttp.readyState){
			if (200==xmlhttp.status){
				var return_value=xmlhttp.responseText;
				if (return_value != null & return_value != ""){
					var data_arr=return_value.split("|||");
					var str_obj	 = data_arr[0];
					var price	 = data_arr[1];
					 select_chain(document.getElementById(str_obj), price);
				}
			}
		delete xmlhttp ; 
		xmlhttp=null;
		CollectGarbage;
		}
	}
	xmlhttp.open("post", "/ajax_product_chain_list.php", true);
	xmlhttp.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded;text/xml;charset=utf-8");
	xmlhttp.send("act=free");
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//选择chain时处理事件
//str_obj为chain内容的对象，price为chain的价格
function select_chain(str_obj, price){
		//将选中的chain内容显示在右边区域
		document.getElementById("choice_content").innerHTML=unescape(escape(str_obj.innerHTML));
		//提出产品的价格
		var product_price = document.frm_cart.price.value;
		product_price = cTrim(product_price.split("-")[0],0);
		if ( ! isNumber(product_price) ) product_price = 0;
		var total_price,total_eur_price;
		total_price = parseFloat(product_price) + parseFloat(price); //产品价格总和 = 产品价格 + chain价格
		total_eur_price = parseFloat(total_price) * 0.72; //欧元价格
		total_price = total_price.toFixed(2);
		document.getElementById("total_price_txt").innerHTML = "US$"+total_price;
		document.frm_cart.total_price.value = total_price;
		document.frm_cart.cancel_yes.value = "";
		
		document.getElementById("total_eur_price_txt").innerHTML = "( EUR " + total_eur_price.toFixed(2) + " )";//显示欧元价格
}
////////////////////////////////////////////////////////////////////////////////////////////////////
//选择chain时处理事件
//str_obj为chain内容的对象，price为chain的价格
function select_chain_change(){
	if ( document.frm_cart.cancel_yes.value != "yes" ){
		select_chain(document.getElementById('chain_td_'+document.frm_cart.chain_id.value), document.frm_cart.chain_Txt_Price.value);
	}else{
		//提出产品的价格
		var product_price = document.frm_cart.price.value;
		product_price = cTrim(product_price.split("-")[0],0);
		if ( ! isNumber(product_price) ) product_price = 0;
		document.getElementById("total_price_txt").innerHTML = "US$"+product_price;
		document.frm_cart.total_price.value = "";	
		var total_eur_price = parseFloat(product_price) * 0.72; //欧元价格
		document.getElementById("total_eur_price_txt").innerHTML = "( EUR " + total_eur_price.toFixed(2) + " )";//显示欧元价格
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//判断是否为数字
function isNumber(oNum) { 
	if(!oNum) return false; 
	var strP=/^\d+(\.\d+)?$/; 
	if(!strP.test(oNum)) return false; 
	try{ 
		if(parseFloat(oNum)!=oNum) return false; 
	} catch(ex) { 
		return false; 
	} 
	return true; 
}
//JS去掉前后空格函数
function cTrim(sInputString,iType){
	var sTmpStr = ' ';
	var i = -1;
	if(iType == 0 || iType == 1)
	{
		while(sTmpStr == ' '){
			++i;
			sTmpStr = sInputString.substr(i,1);
		}
		sInputString = sInputString.substring(i);
	}
	
	if(iType == 0 || iType == 2)
	{
		sTmpStr = ' ';
		i = sInputString.length;
		while(sTmpStr == ' '){
		--i;
		sTmpStr = sInputString.substr(i,1);
		}
		sInputString = sInputString.substring(0,i+1);
	}
	return sInputString;
}

