/**
 * 小寫轉大寫程式，
 * @param where
 * @return
 */
function small2big(where){
	where.value=where.value.toUpperCase();
	return true;
}

/**
 * 檢查電話格式是否純數值
 * @param _cell
 * @return
 */
function check_number_format(_cell){							
        if(_cell.match(/^([0-9]|[\-])+$/g) && (_cell.length>9 && _cell.length<15)){
            return true;
        }else{
			return false;
		}
}

/**
* 檢查電話格式是否純數值
* @param _cell
* @return
*/
function isTel(str){											//檢查電話程式2
       var reg=/^([0-9]|[\-])+$/g ;
       if(str.length<10 || str.length>15){
        return false;
       }else{
         return reg.exec(str);
       }
}

/**
 * 檢查email格式
 * @param _email
 * @return
 */
function check_email_format(_email) {							
  err = '';
  i = 0;
  reg = new RegExp("^[a-zA-Z0-9\-\.\_]+\@[a-zA-Z0-9\-\.]+(\\.)+([a-zA-Z]{2,4})$","gi");
  if((_email.value == '') || (!reg.test(_email.value))) 
  {
	  return false;
  }
  	return true;
}

function check_vip_buy_form(form){
	if ( (form['point_type'][0].checked == true || form['point_type'][1].checked == true) ) {
		if(form['point_type'][0].checked == true) {
			if( (form['point'][0].checked == true || form['point'][1].checked == true || form['point'][2].checked == true || form['point'][3].checked == true) ) {
				if(document.getElementById('creditcard').checked)
					alert('銀行認證提醒:\n\n親愛的客戶您好：為確保您的交易安全，即日起部份發卡銀行會要求您註冊網路刷卡安全驗証，\n以確保您的卡片不會遭到盜刷，您僅需透過一次安全驗證，未來即可使用於其他網路上刷卡服務。\n以下是需要進行「信用卡安全驗證」之行庫:\n\n‧中國信託商業銀行	‧新光銀行	‧日盛銀行\n‧國泰世華銀行		‧台新銀行	‧永豐銀行\n‧台灣中小企業銀行	‧第一銀行	‧土地銀行\n‧合作金庫銀行		‧彰化銀行	‧聯邦銀行\n');
				form.submit();
				return true;
			}
		}else if( (form['point_type'][1].checked == true) ) {
				if(document.getElementById('creditcard').checked)
					alert('銀行認證提醒:\n\n親愛的客戶您好：為確保您的交易安全，即日起部份發卡銀行會要求您註冊網路刷卡安全驗証，\n以確保您的卡片不會遭到盜刷，您僅需透過一次安全驗證，未來即可使用於其他網路上刷卡服務。\n以下是需要進行「信用卡安全驗證」之行庫:\n\n‧中國信託商業銀行	‧新光銀行	‧日盛銀行\n‧國泰世華銀行		‧台新銀行	‧永豐銀行\n‧台灣中小企業銀行	‧第一銀行	‧土地銀行\n‧合作金庫銀行		‧彰化銀行	‧聯邦銀行\n');
				form.submit();
				return true;
		}
		alert('您尚未選擇要買的加值項目 , 請先選擇一項欲購買的加值項目');
		return false;
	}
	alert('您尚未選擇要買的加值項目 , 請先選擇一項欲購買的加值項目');
	return false;
}


function alertAndToIndex() {
    alert('謝謝!您將導回至首頁');
    location.href='../index.php';
}

function countPrice(result , num , price)
{
	result.value=num*price;
}

function countTotalPrice(total_price , total_number)
{
	var sum=0;
	for(var i=0 ; i<total_number ; i++)
	{
		sum+=parseInt(document.purchase['price'+i].value);
	}
	total_price.value = sum;
}

function countpoint()									//對應personal_buy.php的計算點程式。
{
	var main_form=document.vip_buy_form;
	if(main_form['point_type'][0].checked) {
		if(main_form['point'][0].checked){				//第1個radiobutton 以秒計費型點卡
		    main_form["totalmoney1"].value =  main_form['point'][0].id;
		    main_form["totalmoney2"].value = 0;
			main_form['totalcount'].value = parseInt(main_form["totalmoney1"].value) + parseInt(main_form["totalmoney2"].value);
		}else if(main_form['point'][1].checked){		//第2個radiobutton 以秒計費型點卡
		    main_form["totalmoney1"].value = main_form['point'][1].id;
		    main_form["totalmoney2"].value = 0;
			main_form['totalcount'].value = parseInt(main_form["totalmoney1"].value) + parseInt(main_form["totalmoney2"].value);
		}else if(main_form['point'][2].checked){		//第3個radiobutton 以秒計費型點卡
		    main_form["totalmoney1"].value = main_form['point'][2].id;
		    main_form["totalmoney2"].value = 0;
			main_form['totalcount'].value = parseInt(main_form["totalmoney1"].value) + parseInt(main_form["totalmoney2"].value);
		}else {
			main_form['totalcount'].value=0;
		}
	}else if(main_form['point_type'][1].checked){		//500點 以次計費型點卡
	    main_form["totalmoney1"].value = 0;
	    main_form["totalmoney2"].value =  main_form['point'][3].id;
		main_form['totalcount'].value = parseInt(main_form["totalmoney1"].value) + parseInt(main_form["totalmoney2"].value);		
	}else {
		main_form['totalcount'].value= 0;
	}
		
}

function countmoney(islogin)
{
	//if(this.form["products_type[1]"].checked)this.form.totalmoney.value  = this.form.point1.value * this.form.amount1.value;
	if(islogin)
	{
		if( document.getElementById("products_type[1]").checked && document.getElementById("products_type[2]").checked )
		{
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value =  parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else if( document.getElementById("products_type[1]").checked && !document.getElementById("products_type[2]").checked)
		{
			//document.purchase.point2.value = 0;
			document.purchase.amount2.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value =  parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else if( document.getElementById("products_type[2]").checked && !document.getElementById("products_type[1]").checked)
		{
			document.purchase.point1.value = 0;
			document.purchase.amount1.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value =  parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else
		{
			document.purchase.point1.value = 0;
			document.purchase.amount1.value = 0;
			//document.purchase.point2.value = 0;
			document.purchase.amount2.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalcount.value =  parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
	}
	else
	{
		var sum=0;
		if( document.getElementById("products_type[1]").checked && document.getElementById("products_type[2]").checked )
		{
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value = parseInt(document.purchase.usertype_price.value) + parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else if( document.getElementById("products_type[1]").checked && !document.getElementById("products_type[2]").checked)
		{
			//document.purchase.point2.value = 0;
			document.purchase.amount2.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value = parseInt(document.purchase.usertype_price.value) + parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else if( document.getElementById("products_type[2]").checked && !document.getElementById("products_type[1]").checked)
		{
			document.purchase.point1.value = 0;
			document.purchase.amount1.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalmoney2.value = parseInt(document.purchase.point2.value) * parseInt(document.purchase.amount2.value);
			document.purchase.totalcount.value = parseInt(document.purchase.usertype_price.value) + parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
		else
		{
			document.purchase.point1.value = 0;
			document.purchase.amount1.value = 0;
			//document.purchase.point2.value = 0;
			document.purchase.amount2.value = 0;
			document.purchase.totalmoney1.value = parseInt(document.purchase.point1.value) * parseInt(document.purchase.amount1.value);
			document.purchase.totalcount.value = parseInt(document.purchase.usertype_price.value) + parseInt(document.purchase.totalmoney1.value) + parseInt(document.purchase.totalmoney2.value);
		}
	}
}

function pay_mod_select()
{
	/*
	switch (document.form_pay_mod.pay_mod.value) {
		case 0:
			location.href = "./vip_sales_buy-4_atm.php";
			break;
		case 1:
			location.href = "./vip_sales_buy-4_card.php";
			break;
	}*/
	
	if(document.form_pay_mod.pay_mod[0].checked){
		location.href = "./vip_sales_buy-4_atm.php?pay_mod=1";
	}else if(document.form_pay_mod.pay_mod[1].checked){
		location.href = "./vip_sales_buy-4_card.php?pay_mod=2";
	}
}	

/**
 * 列印本頁
 * @return
 */
function printthispage(){
	window.print();
}

function gen_area_code(_type , _city_code){				//接收傳入的城市碼 同步化電話的區碼。  配合資料表同時有對應區域碼之用的。
		if(_type == 'city')
			document.getElementById('userdata_phone').value = _city_code;
		if(_type == 'phone_code')
			document.getElementById('userdata_addr_city').value = _city_code;
}

function AddUpload(){
  up++;
  var images=document.getElementById('images');
  images.innerHTML+='圖 片 '+up+' <input type="file" name="pic[]" size="30"><br />';
}


function show_div(div_id) {
	// hide all the divs
	//document.getElementById('invoice_table_1').style.display = 'div_id';

	// show the requested div
	document.getElementById("invoice_table").style.display = div_id;
}

function show_tr(n, looptime , _name){ //依不同的案例產生不同的選單， n 指定的顯示原素編號  looptime 指定的檢查圈數，  elementname 指定的原素名
	var dis = "";
	var i;
	var	result = "";
	for (i = 1; i <= (looptime); i++) {
		if (i == n) {
			var dis = "";
		}
		else {
			var dis = "none";
		}
		result = _name+i;
		result = result+'';
		if(document.getElementById('_name + i') != null)
			document.getElementById('result').style.display = dis;
	}
}
 
function lock_msg(kururu) {
	if( kururu == '3939889' ) {
		return true;
	}
	else {
		alert('所有灰色功能將在未來完全開放、請耐心等候，\n如有任何不便盡請見諒，或來電客戶我們將為你直接服務謝謝!');
		return false;
	}

}

function count_satisfy_point() {					//計算律師評鑑總分。personal_lawyergrade.php
	var total_grade1 = 0;
	var total_grade2 = 0;
	var total_grade3 = 0;
	var total = 0;
	for( var i = 0 ; i <document.lawyer_satisfy['grade1'].length ; i++) {		//偵測radio box陣列的位數 來進行迴圈取值
		if(document.lawyer_satisfy['grade1'][i].checked)
			total_grade1 = document.lawyer_satisfy['grade1'][i].value;
	}
	for( var i = 0 ; i <document.lawyer_satisfy['grade2'].length ; i++) {		//偵測radio box陣列的位數 來進行迴圈取值
		if(document.lawyer_satisfy['grade2'][i].checked)
			total_grade2 = document.lawyer_satisfy['grade2'][i].value;
	}
	for( var i = 0 ; i <document.lawyer_satisfy['grade3'].length ; i++) {		//偵測radio box陣列的位數 來進行迴圈取值
		if(document.lawyer_satisfy['grade3'][i].checked)
			total_grade3 = document.lawyer_satisfy['grade3'][i].value;
	}
	total = parseInt(total_grade1) + parseInt(total_grade2) + parseInt(total_grade3);	//計算三個值的加總
	document.lawyer_satisfy['calculate_satisfy_point'].value = total;					//寫入頁面的總值input box
}

function check_form_personal_lawyergrade( radioname , numberofradio ) {
	var value1 = document.getElementById('case_type_selection').value;
	var value2 = document.getElementById('lawyer_selection').value;
	if( value1 == 0 ) {
		alert('請選擇此次諮詢的問題類型');
		return false;
	}
	if( value2 == 0 ) {
		alert('請選擇此次諮詢的律師');
		return false;
	}
	for( var ary_x = 0 ; ary_x <= parseInt(numberofradio) ; ary_x++ ) {						//設定三圍陣列，因為有三行Radio Button所以跑三次。
		for( var i = 0 ; i < document.getElementsByName(radioname+ary_x).length ; i++) {	//偵測radio box陣列的位數 來進行迴圈取值
			if(document.getElementsByName(radioname+ary_x)[i].checked) {
				break;
			}else if( i+1 == document.getElementsByName(radioname+ary_x).length ){
				alert('請針對此次的諮詢感想，幫律師打個分數喔! \n 共有三種評分類別 \n 請依照您對於這位律師的三種滿意程度投下您保貴的評鑑分數 \n 分數的程度由1分到5分  1分為很不滿意 ~ 5分為非常滿意 \n 1.律師的問題解決滿意程度 \n 2.律師的專業度 \n 3.律師的親和力 \n 您的 第' + ary_x + '評鑑類別需評分');
				return false;
			}			
		}	
	}
	if (confirm('確定要送出嗎?!')) {
		document.lawyer_satisfy.submit();
	}else 
		this.disabled='disabled';
		return false;
}

/**
 * 計算頁面中所有物件被點擊的總數，便於計算使用者是否有正確的選取頁面中所有的物件後才進送出表單之類的處理。
 *
*/
function check_form_objChecker( formname , numberofradio ) {

    var objForm = document.forms[formname];
    var objLen = objForm.length;
	var cc=0;
    for (var iCount = 0; iCount < objLen ; iCount++) {
            if (objForm.elements[iCount].type == "radio") {
                    if (objForm.elements[iCount].checked )
			cc+=1;
            }
    }
	alert(cc);
return false;
}

function saysomething(msgtosay , confirmthis , url) {
	if(confirmthis) {
		if(confirm(msgtosay))
			location.href=url;
		return false;
	} else {
		alert(msgtosay);
		return true;
	}
	return false;

}

/* 傳入確認訊息與表單ID即可 */
function submitandconfirmtheform(form , msg) {
	if (confirm(msg)) {
		this.getElementById(form).submit();
		return true;
	}
	else {
		return false;
	}
	return false;
}

//function check_lawyer_satisfy(form) {				//計算律師評鑑情況 。personal_lawyergrade.php
//	for(var i=0 ; i<document.getElementsByName('grade1').length ; i++) {
//		if(document.getElementsByName('grade1').item(i).checked == true) {
//			somethingchecked = true;
//		}
//	}
//	if(somethingchecked != true) {
//		alert('somethingnotchecked');
//	}
//}


/*

// 收貨人同購買人
function RecInfo(){
	var form1 = document.form1;
	form1.Receiver.value = form1.CusName.value;
	form1.RecTel.value = form1.InvTel.value;
	form1.RecMobile.value = form1.InvMobile.value;
	form1.RecZip.value = form1.InvZip.value;
	form1.RecAddress.value = form1.InvAddress.value;
	if($('ODVRECMAIL'))
		form1.ODVRECMAIL.value = form1.ODVINVMAIL.value;

	BnameSwitch();
}*/
