//###########################################
//# 設定物件值	 			    			#
//# INPUT: 物件obj,值value		    		#
//# OUTPUT: boolean		            		#
//###########################################
function setValue(obj,value)
{
	var undefined;
	var result = false;
	if (obj==undefined) return;
	if (obj.type!=undefined) {	// obj is an object
		if (obj.type=="text" || obj.type=="password" || obj.type=="hidden" || obj.type=="textarea") {
			obj.value = value;
			result = true;
		}
		else if (obj.type=="select-one") {
		        for(var i=0 ; i<obj.options.length ; i++) {
			        if (obj.options[i].value==value) {
		                        obj.selectedIndex = i;
		                        result = true;
		        		break;
			        }
		        }
		}
		else if (obj.type=="checkbox" || obj.type=="radio") {
			if (obj.value==value) {
	                        obj.checked = true;
	                        result = true;
			}
			
			//append by Connie 2004/08/13
			if (obj.name=="salesmail"){
				if (value=="1") {
			          obj.checked = true;	
				}
				else
				{
				  obj.checked = false;
				}	
				result = true;
			}
		}
	} else if (obj.length!=undefined) {	// obj is an array
		for(var i=0 ; i<obj.length ; i++) {
			if (obj[i].type=="text" || obj[i].type=="password" || obj[i].type=="hidden" || obj.type=="textarea") {
				obj[i].value = value;
				result = true;
			}
			else if (obj[i].type=="select-one") {
			        for(var j=0 ; i<obj[i].options.length ; j++) {
				        if (obj[i].options[j].value==value) {
			                        obj[i].selectedIndex = j;
			                        result = true;
			        		break;
				        }
			        }
			}
			else if (obj[i].type=="checkbox" || obj[i].type=="radio") {
			        if (obj[i].value==value) {
			        	obj[i].checked = true;
			        	result = true;
			        }
		        }
		}
	}
	return result;
}

//###########################################
//# 檢查字串長度 			    #
//# INPUT: 字串                             #
//# OUTPUT: int			            #
//###########################################
function strLength(str)
{
   var len = 0;
   var agent = navigator.userAgent;
   if( agent.indexOf("MSIE") != -1) {	//IE
      for(var i=0 ; i<str.length ; i++) {
         if(str.charCodeAt(i) > 255) {
     	   len+=1;
         }
         len+=1;
      }
   }
   else {	//Netscape
      len = str.length;
   }
   return len;
}

//###########################################
//# 檢查字串中有幾個指定字元                #
//# INPUT: 字串                             #
//# OUTPUT: integer, 0表示未找到            #
//###########################################
function hasChar(str,ch)
{
   var chk_result = 0;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i) == ch)
     	chk_result ++;
   }
   return chk_result;
}

//###########################################
//# 檢查字串是否全為數字                    #
//# INPUT: 字串                             #
//# OUTPUT: boolean, true/false             #
//###########################################
function isNumber(str)
{
   var chk_result = true;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i)<"0" || str.charAt(i)>"9")
     	chk_result = false;
   }
   return chk_result;
}

//###########################################
//# 檢查字串是否全為英文字母                #
//# INPUT: 字串                             #
//# OUTPUT: boolean, true/false             #
//###########################################
function isLetter(str)
{
   var chk_result = true;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i).toLowerCase()<"a" || str.charAt(i).toLowerCase()>"z")
     	chk_result = false;
   }
   return chk_result;
}

//###########################################
//# 檢查字串是否全為英文字母                #
//# INPUT: 字串                             #
//# OUTPUT: boolean, true/false             #
//###########################################
function isLetter_lowcase(str)
{
   var chk_result = true;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i).toLowerCase()<"a" || str.charAt(i).toLowerCase()>"z")
             chk_result = false;
   }
   return chk_result;
}
//###########################################
//# 檢查字串是否全為英文字母                #
//# INPUT: 字串                             #
//# OUTPUT: boolean, true/false             #
//###########################################
function isLetter_uppercase(str)
{
   var chk_result = true;
   for(var i=0 ; i<str.length ; i++) {
      if(str.charAt(i).toLowerCase()<"a" || str.charAt(i).toLowerCase()>"z")
             chk_result = false;
   }
   return chk_result;
}
//###########################################
//# 去掉字串左右空白		            #
//# INPUT: 字串                             #
//# OUTPUT: string		            #
//###########################################
function trim(str)
{
   var result = "";
   for(var i=0 ; i<str.length ; i++) {
      if(str.charCodeAt(i) != 32 && str.charCodeAt(i) != 9)
     	result = result + str.charAt(i);
   }
   return result;
}

