//order_addinfo
function usertype_onclick(value){
	if (value==0)
	{
		document.getElementById("div_user_name").style.display  = "";
	}else{
		document.getElementById("div_user_name").style.display  = "none";
	}
}
function getname_onchange(obj){
	if(obj.id=='pm_shipping_id'){
		document.getElementById("pm_shipping_name").value = obj.options[obj.selectedIndex].text;
	}else if(obj.id="pm_payment_id"){
		document.getElementById("pm_payment_name").value  = obj.options[obj.selectedIndex].text;
	}
}
function check(){
	var ids=Array('order_sn','consignee','address','tel');
	var msgs=Array('订单号不能为空！','收货人姓名不能为空！','收货地址不能为空！','电话不能为空！');
	var types=Array('STRING','STRING','STRING','STRING','STRING');
	if(!checkSubmit(ids,msgs,types)){
		return false;
	}
	//费用长度
	//不能为空的consignee 60,tel 20,address 255
	//可以为空的mobile 20,zipcode 10,email 60,sign_building  120,inv_content 120,inv_payee  120
  //长度判断
  var lentype="LENGTH";
  var lenids= new Array('user_name','consignee','tel','address','mobile','zipcode','email','sign_building','inv_content','inv_payee','shipping_fee','insure_fee','pay_fee','product_final_amount');
  var lenmsgs= new Array('会员名称输入太长！','收货人输入的太长!','电话输入太长!','收货人地址输入太长！','手机输入太长！','邮编输入太长!','Email输入太长!','标志性建筑输入太长!','发票内容输入太长!','发票单位输入太长!','配送费用输入太长','保价费用输入太长','支付费用输入太长','商品总金额(最终价)输入太长');
	var lens=new Array('60','60','20','255','20','10','60','120','120','120','10','10','10','10');
	if(!checkPublic(lentype,lenids,lenmsgs,lens)){return false;}

	if(isNull('email'))
	{
		if(!checkIsEmail("email")){
			alert("Email格式不正确！");
			document.getElementById("email").focus();
			return false;
		}
	}
	if(isNull('mobile'))
	{
		if(!checkIsNumber("mobile")){
			alert("你的手机不合法！");
			document.getElementById("mobile").focus();
			return false;
		}
	}
	if(isNull('zipcode'))
	{
		if(!checkIsNumber("zipcode")){
			alert("你的邮编号不合法！");
			document.getElementById("zipcode").focus();
			return false;
		}
	}
	if(!checkIsNumber('tel')){
		alert("你的电话号码不合法！");
		document.getElementById("tel").focus();
		return false;
	}
	if(document.getElementById("pm_shipping_id").value==-1){
		alert("请选择配送方式！");
		document.getElementById("pm_shipping_id").focus();
		return false;
	}
	if(document.getElementById("pm_payment_id").value==-1){
		alert("请选择支付方式！");
		document.getElementById("pm_payment_id").focus();
		return false;
	}
	if(!checkFee())return false;

	return true;
}
function checkFee(){
	if(!isNum("shipping_fee")){
		alert("配送费用必须为数字");
		document.getElementById("shipping_fee").focus();
		return false;
	}
	if(!isNum("insure_fee")){
		alert("保价费用必须为数字");
		document.getElementById("insure_fee").focus();
		return false;
	}
	if(!isNum("pay_fee")){
		alert("支付费用必须为数字");			
		document.getElementById("pay_fee").focus();
		return false;
	}
	if(!isNum("product_final_amount")){
		document.getElementById("product_final_amount").focus();
		alert("商品总金额(最终价)必须为数字");			
		return false;
	}
	return true;
}
function formatNumber(flt) { 
	if(parseFloat(flt) == flt) 
		return Math.round(flt * 100) / 100; 
	else 
		return 0; 
} 
function order_amount_sum(){
	//if(!checkFee())return false;
	var a=0.00;
	//a+= formatNumber(document.getElementById("shipping_fee").value);
	//a+= formatNumber(document.getElementById("insure_fee").value);
	//a+= formatNumber(document.getElementById("pay_fee").value);
	a+= formatNumber(document.getElementById("product_final_amount").value);
	document.getElementById("order_amount").value = formatNumber(a);
}

//order_addproduct
function frmsubmit(type){
	if(document.getElementById("pm_order_id").value=='88888888'){
		document.getElementById("act").value = "product_list";
		return false;
	}
	document.getElementById("act").value = type;
	var count=document.getElementsByName("order_count[]");
	return check_count(count);
}
//修改订购数量js验证
function change(value,list_price,final_price,id)
{
	var count=document.getElementsByName("order_count[]");//取得所有商品的订购数量
	var temp=false;
	temp=check_count(count,value,list_price,final_price,id);
	if(!temp)//如果输入有误的话，value值即订购数就改为1，并通过notice方法将其值更换为1.
	{
		value=1;
	}
		var array=new Array('product_amount','product_amount2');
		//求商品的总金额
		for(var k=0;k<array.length;k++)
		{
			if(array[k]=='product_amount')
				var price=list_price;
			if(array[k]=='product_amount2')
				var price=final_price;
			document.getElementById(array[k]+'['+id+']').value=value*price;//根据订购数修改单个
			var o=document.getElementsByName(array[k]+'[]');
			var count=0;
			for(var i=0;i<o.length;i++)
			{
				//alert(o[i].value);
				count=parseFloat(count)+parseFloat(o[i].value);
			}
			//取精度
			var length=count.toString().length;
			var tempStr=count.toString();
			var count_complete=getStrPrice(length,tempStr);
			document.getElementById(array[k]).value=count_complete;
		}
		//alert(temp);
		//return temp;
}
function change_money(pm_product_id)
{
	var count=document.getElementsByName("pm_product_id[]");
	for(var i=0;i<count.length;i++)
	{
		if(pm_product_id==count[i].value){
			document.getElementsByName('money[]')[i].value=document.getElementsByName('final_price[]')[i].value * document.getElementsByName('order_count[]')[i].value;
		}
	}
}
function all_change_money()
{
	var count=document.getElementsByName("pm_product_id[]");
	for(var i=0;i<count.length;i++)
	{
		document.getElementsByName('money[]')[i].value=document.getElementsByName('final_price[]')[i].value * document.getElementsByName('order_count[]')[i].value;
	}
}
function check_count(count,value,list_price,final_price,id){
	//添加订单订购数限制
	for(var i=0;i<count.length;i++)
	{
		if(Len(count[i].value)>5){
			alert("订购数输入过长！");
			notice(count[i],value,list_price,final_price,id);
			return false;
		}
		if(isNaN(count[i].value.trim())){
			alert("请输入数字！");
			notice(count[i],value,list_price,final_price,id);
			return false;
		}
		if(count[i].value.trim()==0||count[i].value.trim()==""||count[i].value.trim()==null)
		{
			alert("订购数输入不合法！");
			notice(count[i],value,list_price,final_price,id);
			return false;
		}
	}
	return true;
}
function notice(count,value,list_price,final_price,id){
	//将输入错误的数据改为1，就将单个商品总金额还原为订购数为1的价格。
	count.value=1;
	document.getElementById('product_amount['+id+']').value=list_price;
	document.getElementById('product_amount2['+id+']').value=final_price;
	count.focus();	
}
function Len(str){
	//测试输入的字符长度。
    var i,sum;
    sum=0;
	for(i=0;i<str.length;i++){
		if ((str.charCodeAt(i)>=0) && (str.charCodeAt(i)<=255)){
			sum=sum+1;
		}else{
            sum=sum+2;
		}
    }
    return sum;
}
/**获取一个经过处理后的商品价格
 *length  商品价格的字符串的长度
 *str     商品价格的字符串
 *返回    字符串的商品价格
 */
function getStrPrice(length,tempStr)
{
	var str = '';
	for(var i=1; i<=length; i++)
	{
		var temp = tempStr.toString().substring(i-1,i);
		str = tempStr.toString();
		if(temp == '.')
		{
			str = tempStr.toString().substr(0,i+1) + '0';
			break;
		}
	}
	return str;
}
//order_orderquery   order_shipment
function order_query(){
	
	if(checkStrLen('ORDER_SN',20)==false){
		alert("订单号输入过长！");
		return false;
	}	
	if(checkStrLen('USER_NAME',10)==false){
		alert("会员名称输入过长！");
		return false;
	}	
	if(checkStrLen('CONSIGNEE',60)==false){
		alert("收货人名称输入过长！");
		return false;
	}	
	if(checkStrLen('INVOICE_NO',50)==false){
		alert("发货单号输入过长！");
		return false;	
	}	
	return true;	
}
// order_product_lack
function order_query2(){
	if(checkStrLen('PRODUCT_NAME',20)==false){
		alert("商品名称输入过长！");
		return false;	
	}
	return true;		
}


//判断格式
function checkform(){
	if(document.getElementById('flag').value=="same"){
		if(!isNull('user_name')){
			alert("请填写您的姓名！");
			document.getElementById('user_name').focus();
			return false;	
		}
		if(!isNull('birthday')){
			alert("请填写您的出生年月日！");
			document.getElementById('birthday').focus();
			return false;	
		}
		if(!isNull('user_zipcode')){
			alert("请填写您的邮政编码！");
			document.getElementById('user_zipcode').focus();
			return false;	
		}
		if(isNull('user_zipcode')){
			if(!isNum('user_zipcode')){
				alert("邮政编码请输入数字！");
				document.getElementById('user_zipcode').focus();
				return false;
			}		
		}
		if(!isNull('user_address')){
			alert("请填写您的详细地址！");
			document.getElementById('user_address').focus();
			return false;
		}
		if(isNull('user_mobile_phone')){
			if(!isNum('user_mobile_phone')){
				alert("移动电话请输入数字！");
				document.getElementById('user_mobile_phone').focus();
				return false;
			}		
		}
	}
	if(document.getElementById('flag').value=="diffent"){
		if(!isNull('consignee')){
			alert("请填写您的姓名！");
			document.getElementById('consignee').focus();
			return false;	
		}
		if(!isNull('zipcode')){
			alert("请填写您的邮政编码！");
			document.getElementById('zipcode').focus();
			return false;	
		}
		if(isNull('zipcode')){
			if(!isNum('zipcode')){
				alert("邮政编码请输入数字！");
				document.getElementById('zipcode').focus();
				return false;
			}		
		}
		if(!isNull('address')){
			alert("请填写您的详细地址！");
			document.getElementById('address').focus();
			return false;
		}
		if(isNull('mobile_phone')){
			if(!isNum('mobile_phone')){
				alert("移动电话请输入数字！");
				document.getElementById('mobile_phone').focus();
				return false;
			}		
		}
	}
}