var err_msg="";
function message(txt,objid){
	$('html, body').scrollTop(0);
	var obj=document.getElementById(objid);
	obj.innerHTML=txt;
}
function antenterAddBookmark(pType){
	var _locationHref  = (WEB_SITE_HREF == "") ? window.location.href : WEB_SITE_HREF;
	var _title = (WEB_SITE_TITLE == "") ? document.title : WEB_SITE_TITLE;
	var _href;	

	switch (pType) {

		case 'FACEBOOK':
			_href = "http://www.facebook.com/sharer.php?u="+ _locationHref;
			break;
		case 'GOOGLE':
			_href = "http://www.google.com/bookmarks/mark?op=add&bkmk="+ _locationHref + "&title=" + _title;
			break;
		case 'PLURK':
			id = "";
			_locationHref = encodeURIComponent(_locationHref+"?media=plurk");
			_title = encodeURIComponent(_title);
			id = encodeURIComponent(id);
			_href = "http://www.plurk.com/?qualifier=shares&status=".concat(_locationHref).concat(' ').concat('(').concat(_title).concat(')').concat(' ').concat('(').concat(id).concat(')');
			break;
		case 'TWITTER':
			id = "";
			_locationHref = encodeURIComponent(_locationHref+"?media=twitter");
			_title = encodeURIComponent(_title);
			id = encodeURIComponent(id);			
			_href = "http://twitter.com/home/?status=" + _title + " " + _locationHref + " " + id;
			break;
	}
	
	window.open( _href , "_blank" );
}
function isnull(id,txt,type,minlen,maxlen){
	type=arguments[2]||0;
	minlen=arguments[3]||0;
	maxlen=arguments[4]||0;
	var my_value=$.trim($('#'+id).val());
	my_value=my_value.replace(/(^[\s　]*)|([\s　]*$)/g,"");
	if(my_value=="" && minlen>0){
		err_msg=txt+' is empty!!';
		return false;
	}
	if(type==1 ){
		if (isNaN(my_value) ){
		    err_msg+=txt+' must be a number!!'
		    return false
	    }
	}
	if(type==2)
	{
	 var pattern =/^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;   
     if(!pattern.test(my_value)){ 
		err_msg=txt+'must be Chinese!!';
		return false;
	 }
	}
	
	if(type==3)
	{
	 var pattern =/^([\u4E00-\u9FA5]|[\uFE30-\uFFA0])*$/gi;   
     if(pattern.test(my_value)){ 
		err_msg=txt+' can\'t be Chinese!!';
		return false;
	 }
	}	
	
    if(maxlen>0 && minlen>0){
		if(my_value.length>maxlen || my_value.length<minlen){
		  err_msg=txt+' text length must be between '+minlen+' to '+maxlen+' !!';
		  return false;
		}
	}	
	if(maxlen>0){
		if(my_value.length>maxlen){
		  err_msg=txt+' text length must be less than '+maxlen+'!!';
		  return false;
		}
	}	
	if(minlen>0){
		if(my_value.length<minlen){
		  err_msg=txt+' text length must be greater than '+minlen+'!!';
		  return false;
		}
	}

	return true;
}
function ischecked(name,txt,maxnum){
	maxnum=arguments[2]||0;
	var obj=$("input[name="+name+"]");
	var num=0;
	for(i=0;i<obj.length;i++)
	{
		if(obj.get(i).checked){
			num++;
		}
	}
	if(num==0)
	{
		  err_msg=' please select '+txt+'!!';
		  return false;	
	}
	if(maxnum>0)
	{
	    if(num>maxnum)
	    {
		  err_msg=txt+' can olny choose '+maxnum+'!!';
		  return false;	
	    }
	}
	return true;
}
function isemail(id){
	var my_value=$.trim($('#'+id).val());
	my_value=my_value.replace(/(^[\s　]*)|([\s　]*$)/g,"");
	if(my_value==""){
		err_msg='Please enter Email!!';
		return false;
	}
	var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z]{2,4})+$/;
	if (!re.test(my_value)){
		err_msg="Please enter a vaild Email format";
		return false;
	}
	return true;		
}
function istel(id){
	var my_value=$.trim($('#'+id).val());
	my_value=my_value.replace(/(^[\s　]*)|([\s　]*$)/g,"");
	if(my_value==""){
		err_msg='Please enter tel!!';
		return false;
	}
		var re = /^([0-9]{2,3}-)?[0-9]{8,10}(#[0-9]{1,4})?$/;
	if (!re.test(my_value)){
		err_msg+="Please enter a vaild tel format";
		return false;
	}	
	return true;	
}
function ismobile(id){
	var my_value=$.trim($('#'+id).val());
	my_value=my_value.replace(/(^[\s　]*)|([\s　]*$)/g,"");
	if(my_value==""){
		err_msg='Please enter mobile number!!';
		return false;
	}
	var re = /^09[0-9]{8}$/;
	if (!re.test(my_value)){
		err_msg="Please enter a vaild mobile number format";
		return false;
	}
   return true;	
}
function isennum(id,txt) {
	var my_value=$.trim($('#'+id).val());
	my_value=my_value.replace(/(^[\s　]*)|([\s　]*$)/g,"");
    var re = /^\w+$/;
    if (!re.test(my_value)) {
        err_msg = txt+" Enter only alphanumeric and _ case";
        return false;
    }
    return true;
}
function isselect(id,key){
	var my_value=$.trim($('#'+id).val());
	if(my_value==""){
		err_msg='please select '+key+'!!';
		return false;
	}
 return true;
}
function isVaildDate(str,txt){   
		var str=$.trim($('#'+id).val());
       var re = new RegExp("^([0-9]{4})[.-]{1}([0-9]{1,2})[.-]{1}([0-9]{1,2})$");   
       var strDataValue;   
       var infoValidation = true;   
          
       if ((strDataValue = re.exec(str)) != null){   
              var i;   
              i = parseFloat(strDataValue[1]);   
              if (i <= 0 || i > 9999){ // 年   
                     infoValidation = false;   
              }   
              i = parseFloat(strDataValue[2]);   
              if (i <= 0 || i > 12){ // 月   
                     infoValidation = false;   
              }   
              i = parseFloat(strDataValue[3]);   
              if (i <= 0 || i > 31){ // 日   
                     infoValidation = false;   
              }   
       }else{   
              infoValidation = false;   
       }   
  
       if (!infoValidation){   
              err_msg =txt+' format must be YYYY-MM-DD ';   
       }   
       return infoValidation;   
}
function isdate(yy, mm, dd,txt) {
    var arg_intYear=$.trim($('#'+yy).val());
    var arg_intMonth=$.trim($('#'+mm).val());
    var arg_intDay = $.trim($('#' + dd).val());
    if (arg_intDay != "" && arg_intMonth != "" && arg_intDay != "") {
        //月數從0開始，所以要將參數減一
        var objDate = new Date(arg_intYear, arg_intMonth - 1, arg_intDay);
        //檢查月份是否小於12大於1
        if ((parseInt(arg_intMonth) > 12) || (parseInt(arg_intMonth) < 1)) {
            err_msg = arg_intYear + '/' + arg_intMonth + '/' + arg_intDay + txt + ' is not vaild month format';
            return false;
        }
        else {
            //如果objDate日數進位不等於傳入的arg_intDay，代表天數格式錯誤，另外月份進位也代表日期格式錯誤
            if ((parseInt(arg_intDay) != parseInt(objDate.getDate())) || (parseInt(arg_intMonth) != parseInt((objDate.getMonth() + 1)))) {
                err_msg = arg_intYear + '/' + arg_intMonth + '/' + arg_intDay + txt + ' is not vaild days format';
                return false;
            }
            else {
                err_msg = arg_intYear + '/' + arg_intMonth + '/' + arg_intDay + txt + ' is not vaild date formate';
                return true;
            }
        }
    }else{
		err_msg = "请选择 "+ txt;
		return false;
	}
    return true;
}
function checkPassword(pw1,pw2){
	var my_value1=$.trim($('#'+pw1).val());
	var my_value2=$.trim($('#'+pw2).val());
	if(my_value1!=my_value2){
		err_msg='not the same as password and confirm password';
		return false;
	}
 return true;
}
