function RefreshTotal() {
//	var price1 = document.all price.value * document.num.value;
//  var price2 = document.form1.price2.value;
	
	price1=document.all.prodprice.value;
	num1=document.all.prodnum.value;
	discount=document.all.discount.value;
	document.all.prodtotal.value = eval(price1) * eval(num1) - eval(discount)*eval(num1) ;

//	if(price2.length == 0)
//		document.form1.total.value = parseInt(price1);
//	else
//		document.form1.total.value = parseInt(price1) + parseInt(price2);
//   return true;
}
function GetProdName() {
//	var price1 = document.all price.value * document.num.value;
//  var price2 = document.form1.price2.value;
	
	
	document.all.prodcontent.value = document.all.prodname.value;

//	if(price2.length == 0)
//		document.form1.total.value = parseInt(price1);
//	else
//		document.form1.total.value = parseInt(price1) + parseInt(price2);
//   return true;
}

function check_null(value, name) {
	if(value.length == 0) return name + "尚未填寫!\n";
    return "";
}

function check_telephonenumber(number, name) {	
	var error = false;
    if(number.length <= 0)
        return "您的" + name + "還沒填!\n";
    for(idx=0;idx<number.length;idx++) {	
    	if(!(( number.charAt(idx) >= '0' && number.charAt(idx) <= '9') || (number.charAt(idx) == '-'))) {	
    		error = true;
            break;
        }
    }
    if(error == true) return "您的" + name + "只能是數字及'-'等符號,其他的符號都不能使用!\n";
    return "";
}

function check_email(email, name) {	
	var len = email.length;
	if(len == 0)
       return name + "電子信箱欄不可以空白!\n";
	for(var i=0;i<len;i++) {  	
   		var c = email.charAt(i);
      	if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
         	return name + "電子郵件地址只能是數字,英文字母及'-','_'等符號,其他的符號都不能使用!\n";
   	}
   	if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(len-1)))
      	return name + "電子郵件地址不合法!\n";
   	if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,len).indexOf("@")!=-1))
      	return name + "電子郵件地址不合法!\n";
   	if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(len-1)))
      	return name + "電子郵件地址不完全!\n";
   	return "";
}

function CheckOrderInfo() {	
	var thisForm = document.form1;
  	var Str = "";

	if(thisForm.item1.selectedIndex == 0 && thisForm.item2.selectedIndex == 0) {
		alert("您沒有選擇任何商品");
		return false;
	}
	
	if((thisForm.item1.selectedIndex != 0 && document.form1.count1.value == "") || 
	   (thisForm.item2.selectedIndex != 0 && document.form1.count2.value == "")) {
		alert("請填入商品購買數量");
		return false;	
	}
	
  	Str += check_null(thisForm.name.value, "訂購人姓名");
  	Str += check_telephonenumber(thisForm.cellphone.value, "行動電話");
  	Str += check_email(thisForm.email.value, "您的");
  	Str += check_null(thisForm.zipcode.value, "郵遞區號");
  	Str += check_null(thisForm.dest_address.value, "送貨地址");
  	Str += check_null(thisForm.invoice_title.value, "發票抬頭");
 	Str += check_null(thisForm.companyid.value, "統一編號");

  	if(Str != '') {
  		alert(Str);
    	return false;
	}
	return true;
}

