
//送出後將所有按鈕 disable
//最後會將有被disabled 的INPUT TEXT 打開
function submitonce(theform){
  if (document.all||document.getElementById){
    for (i=0;i<theform.length;i++){
      	var tempobj=theform.elements[i]
        	if(tempobj.type.toLowerCase()=="submit")
  	tempobj.disabled=true
	if(tempobj.type.toLowerCase()=="reset")
  	tempobj.disabled=true
	if(tempobj.type.toLowerCase()=="button")
  	tempobj.disabled=true
  	if(tempobj.type.toLowerCase()=="text")
  	tempobj.disabled=false
    }
  }
}

//字串是否為數字
function ValidInt(obj){
	
	var string = obj.value;
	//if(ValidatorTrim(string).length > 0){

		var rx = new RegExp("[0-9]{0,20}$");
    		var matches = rx.exec(string);
    		if(matches != null && string != matches[0]){
			alert("您必須輸入數字!");
			obj.value="";
			obj.focus();
    			return false;
    		}
    		
    	var num = parseInt(string, 10);
    	
    	
    	if(num == 0) {
    		alert("您必須輸入數字不可為0!");
		obj.value="";
		obj.focus();
    		return false;
    			
    	}	
    		 
    	//}
    	return true;
}
function ValidIntZero(obj){
	
	var string = obj.value;
	//if(ValidatorTrim(string).length > 0){

		var rx = new RegExp("[0-9]{0,20}$");
    		var matches = rx.exec(string);
    		if(matches != null && string != matches[0]){
			alert("您必須輸入數字!");
			obj.value="";
			obj.focus();
    			return false;
    		}

    	return true;
}
//輸入的數字第一個不可為0
function ValidZero(string){
	var num = parseInt(string, 10);
    	if(num == 0) return true;
    	else false;	

}	

//檢查郵件格式
function checkmail(myEmail) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myEmail)){
return (false)
}
return (true)
}

//字串去空白
function ValidatorTrim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

//開新視窗,並 focus 到新視窗
var newwin; 
function popup(url,width,height)
{	
	newwin=window.open(url,"Win","RESIZABLE=yes, SCROLLBARS=yes, WIDTH=" + width + ", HEIGHT=" + height + ", TOOLBAR=no,menubar=no,status=no ,alwaysRaised ");
    	newwin.focus();
}
//如開啟的新視窗未關閉則focus到新視窗
function focuswin(){
	
	if(!newwin) return;
	if(!newwin.closed){
		newwin.focus();
		//window.blur();
	} 
}

//將日期轉換成timestamp 的數字 date type 必須是 Y-m-d
function date_to_timestamp(op){
	var  m, exp;
	var yearFirstExp = new RegExp("^\\s*((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})\\s*$");
        m = op.match(yearFirstExp);
        var day, month, year;
        if (m != null && (m[2].length == 4)) {
            day = m[6];
            month = m[5];
            year = (m[2].length == 4) ? m[2] : GetFullYear(parseInt(m[3], 10))
        }
        else {
            				
            var yearLastExp = new RegExp("^\\s*(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))\\s*$");
            m = op.match(yearLastExp);
            if (m == null) {
                return null;
            }
                day = m[1];
                month = m[3];
            year = (m[5].length == 4) ? m[5] : GetFullYear(parseInt(m[6], 10))
        }
        month -= 1;
        //alert(year+"-"+month+"-"+day);
        var date = new Date(year, month, day);
        
        return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate()) ? date.valueOf() : null;
        
}


//產品搜尋
function submitcon_prod_search_form(obj){
	if(confirm("Are you sure?")){
		
		if(Vali_Search_Data(obj)) return true;
		else return false;
		
	}else return false;
}
function Vali_Search_Data(obj){
	
	
	if(ValidatorTrim(obj.s_name.value).length == 0){
		alert("please input your product!");
	    	obj.s_name.focus();
	    	return false;
	}
	
	submitonce(obj);
	return true;
}
//登入新產品
function submitcon_new_prod_login_form(obj){
	if(confirm("Are you sure?")){
		
		if(Vali_New_Prod_Login_Data(obj)) return true;
		else return false;
		
	}else return false;
}
function Vali_New_Prod_Login_Data(obj){
	
	
	if(ValidatorTrim(obj.new_prod_passwd.value).length == 0){
		alert("please input your login password!");
	    	obj.new_prod_passwd.focus();
	    	return false;
	}
	
	submitonce(obj);
	return true;
}

//連絡我們
function submitcon_contact_form(obj){
	
	if(confirm("send ?")){
		
		if(Vali_Contact_Data(obj)) return true;
		else return false;
		
	}else return false;
}
function Vali_Contact_Data(obj){
	
	
	if(ValidatorTrim(obj.contact_name.value).length == 0){
		alert("please input your name!");
		obj.contact_name.focus();
		return false;
	}
	
	if(ValidatorTrim(obj.contact_tel.value).length == 0){
		alert("please input your telephone!");
		obj.contact_tel.focus();
		return false;
	}
	if(ValidatorTrim(obj.contact_email.value).length == 0 || obj.contact_email.value.indexOf('@',0)==-1 || obj.contact_email.value.indexOf(".",obj.contact_email.value.indexOf('@',0))==-1){
		alert("please input your E-Mail!");
		obj.contact_email.focus();
		return false;
	}
	if(ValidatorTrim(obj.contact_subj.value).length == 0){
		alert("please input subject!");
		obj.contact_subj.focus();
		return false;
	}
	if(ValidatorTrim(obj.contact_body.value).length == 0){
		alert("please input others!");
		obj.contact_body.focus();
		return false;
	}
	
	submitonce(obj);
	return true;
}
function submitcon_service_form(obj){
	if(confirm("Are you sure?")){
		
		if(Vali_Service_Data(obj)) return true;
		else return false;
		
	}else return false;
}
function Vali_Service_Data(obj){
	if(ValidatorTrim(obj.service_name.value).length == 0){
		alert("You must input name!");
		obj.service_name.focus();
		return false;
	}
	if(ValidatorTrim(obj.service_tel.value).length == 0){
		alert("You must input telephone!");
		obj.service_tel.focus();
		return false;
	}
	if(ValidatorTrim(obj.service_email.value).length == 0 || obj.service_email.value.indexOf('@',0)==-1 || obj.service_email.value.indexOf(".",obj.service_email.value.indexOf('@',0))==-1){
		alert("You  input E-mail failure!");
		obj.service_email.focus();
		return false;
	}
	if(ValidatorTrim(obj.service_subj.value).length == 0){
		alert("You must input subject!");
		obj.service_subj.focus();
		return false;
	}
	if(ValidatorTrim(obj.service_body.value).length == 0){
		alert("You must input mail body!");
		obj.service_body.focus();
		return false;
	}
	
	submitonce(obj);
	return true;
}

