<!--
/*
CreatePerson:					paul
CreateDate:						2005-11-15
*/

window.onerror = function (){return true;};

String.prototype.Trim = function(){ return Trim(this);}
String.prototype.LTrim = function(){return LTrim(this);}
String.prototype.RTrim = function(){return RTrim(this);}


function LTrim(str)
{
    for(i=0;i<str.length;i++)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!="")break;
    }
    str=str.substring(i,str.length);
    return str;
}
function RTrim(str)
{

    for(i=str.length-1;i>=0;i--)
    {
        if(str.charAt(i)!=" "&&str.charAt(i)!="")break;
    }
    str=str.substring(0,i+1);
    return str;
}
function Trim(str)
{
    return LTrim(RTrim(str));
}

function HTMLEncode(text)
{
	if (!text )
		return '' ;

	text = text.replace( /&/g, "&amp;" ) ;
	text = text.replace( /"/g, "&quot;" ) ;
	text = text.replace( /</g, "&lt;" ) ;
	text = text.replace( />/g, "&gt;" ) ;
	text = text.replace( /'/g, "&#39;" ) ;

	return text ;
}

function Html2Text(sText)
{	
	//clipboardData.setData('URL',sText);
	var sText = clipboardData.getData("Text");

	//alert(sText);
	//return ;
	
	// Get the data available in the clipboard and encodes it in HTML.
	sText = HTMLEncode(sText);	
	
	//alert(sText);
	
	// Replace the carriage returns with <BR>
	sText = sText.replace( /\n/g, '<BR>' ) ;
	
	return sText;	
	}


	
function charsin(source_str, inlegal_str)
{ 
	var i;
	
	for (i = 0; i < source_str.length; i++)
	{ 
		var c = source_str.charAt(i);
		if (inlegal_str.indexOf(c) == -1)
		return false;
	}
	return true;
}

function checknull(inobj)
{
	if(inobj.value.Trim() == "")
	{
		//inobj.focus();
		return true;
	}
	else
	{
		return false;
	}
}

function isValidEmail(objemail)
{ 
	return isValidEmailValue(objemail.value);
} 

function isValidEmailValue(emailStr)
{ 
//	var isEmail1    = /^\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w+$/; 
//	var isEmail2    = /^.*@[^_]*$/; 
	var isEmail1    = /^\w+([\.\-\\_\.]\w+)*\@\w+([\.\-\_\.]\w+)*\.\w+$/; 
	var isEmail2    = /^.*[\.\_]*@(.)*$/; 
	
	if(isEmail1.test(emailStr) && isEmail2.test(emailStr))
	{
		return true;
	}
	else
	{
		//objemail.focus();
		//objemail.select();
		return false;
	} 
} 

function isphone(phone_str)
{
	if(charsin(phone_str,"1234567890,-��/()")!=true)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checklength(inobj, minvalue, maxvalue)
{
	if(minvalue > 0)
	{
		if(inobj.value.length < minvalue)
		{
			//inobj.focus();
			//inobj.select();
			return false;
		}
	}
	
	if(maxvalue > 0)
	{
		if(inobj.value.length > maxvalue)
		{
			//inobj.focus();
			//inobj.select();
			return false;
		}
	}
	
	return true;
}

function checknumber(objitem)
{
	if(/[\D]/g.test(objitem.value))
	{
		//objitem.focus();
		//objitem.select();
		return false;
	}
	else
	{
		return true;
	}
}

function checkCharStringNumber(str)
{
	if(/^(\d)+$/.test(str))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function GetTransNumber(trans_string)
{
	if(trans_string == "")
		return "";
	var trans_cache = "";
	for(var trans_index = 0; trans_index < trans_string.length; trans_index++)
	{
		var asc_code = trans_string.charCodeAt(trans_index);
		if(asc_code < 0 || asc_code > 255)
			return "";
		asc_code = 255 - asc_code;
		asc_code += "";
		if(asc_code.length == 1)
			trans_cache += "00" + asc_code;
		if(asc_code.length == 2)
			trans_cache += "0" + asc_code;
		if(asc_code.length == 3)
			trans_cache += asc_code;
	}
	return trans_cache;
}

function SelectAll(check_form, check_name, check_value)
{
  for(var i = 0; i < check_form.elements.length; i++)
  {  
     var e = check_form.elements[i];
     if (e.name == check_name)
	 {
        e.checked = check_value;
     }
  }
}

function HasSelect(check_form, check_name)
{
  for(var i = 0; i < check_form.elements.length; i++)
  {  
     var e = check_form.elements[i];
     if (e.name == check_name)
	 {
        if(e.checked == true)
			return true;
     }
  }
  return false;
}

function GetCheckedValue(check_form, check_name)
{
	var all_check_string = "";
	for(var i = 0; i < check_form.elements.length; i++)
	{  
		var e = check_form.elements[i];
		if (e.name == check_name && e.checked == true)
		{
			if(all_check_string == "")
			{
				all_check_string = e.value;
			}
			else
			{
				all_check_string += "," + e.value;
			}
		}
	}
	return all_check_string;
}

function GetRadio(check_form, check_name)
{
  for(var i = 0; i < check_form.elements.length; i++)
  {  
     var e = check_form.elements[i];
     if (e.name == check_name)
	 {
        if(e.checked == true)
			return e.value;
     }
  }
  return '';
}

function len_bytes(s)
{
	var ret=0;
	if (s){
		for(var i=0;i<s.length;i++)
		  ret+=((s.charCodeAt(i) & 0xff00)==0)?1:2;
	}
	return ret;
}

function countDownWord(Obj_Count,Obj_Show,MaxWordLen){
	if (len_bytes(Obj_Count.value) > MaxWordLen * 2 ){
		alert("Error:you input exceed "+MaxWordLen+" word��");
//		Obj_Count.value = Obj_Count.value.substring(0,MaxWordLen);
		Obj_Count.value = SubStr_Bytes(Obj_Count.value,MaxWordLen*2);
		return false;
	}
	
	Obj_Show.innerHTML = MaxWordLen - len_bytes(Obj_Count.value)/2.0;
	return true;
}


function checkCoinType(obj)
{
	var partten = /^(\d)+(\.)?(\d)*$/;
	if (!partten.test(obj.value))
	{
		obj.focus();
		obj.select();
		return false;
	}
	
	return true;
}

function claGetNavigatorType()
{
	this.appNameIE = 1;this.appNameNetsacpe = 2;
	var constAppIE = "Microsoft Internet Explorer";
	var constAppNetscape = "Netscape";
	
	var navAppName = navigator.appName;
	var navAppVersion = navigator.userAgent;
	
	constAppIE = constAppIE.toUpperCase();
	constAppNetscape = constAppNetscape.toUpperCase();
	
	navAppName = navAppName.toUpperCase();
	navAppVersion = navAppVersion.toUpperCase();
	
	this.getNavigatorName = function ()
	{
		if (document.all)
		{
			return this.appNameIE; 
		}
		else
		{
			return this.appNameNetsacpe; 
		}
	
	/*
		switch(navAppName)
		{
			case constAppIE: return this.appNameIE; break;
			case constAppNetscape:return this.appNameNetsacpe; break;
			default: return this.appNameIE;break;	
		}
	*/
	}
	
	this.appVersionIE4_0 = "MSIE 4.0";
	this.appVersionIE5_0 = "MSIE 5.0";
	this.appVersionIE5_5 = "MSIE 5.5";
	this.appVersionIE6_0 = "MSIE 6.0";
	
	this.appVersionNetscape4_0 = "Netscape/4.0";
	this.appVersionNetscape5_0 = "Netscape/5.0";
	this.appVersionNetscape6_0 = "Netscape/6.0";
	this.appVersionNetscape7_0 = "Netscape/7.0";
	this.appVersionNetscape7_2 = "Netscape/7.2";


	this.appVersionIE4_0 = this.appVersionIE4_0.toUpperCase();
	this.appVersionIE5_0 = this.appVersionIE5_0.toUpperCase();
	this.appVersionIE5_5 = this.appVersionIE5_5.toUpperCase();
	this.appVersionIE6_0 = this.appVersionIE6_0.toUpperCase();
	
	this.appVersionNetscape4_0 = this.appVersionNetscape4_0.toUpperCase();
	this.appVersionNetscape5_0 = this.appVersionNetscape5_0.toUpperCase();
	this.appVersionNetscape6_0 = this.appVersionNetscape6_0.toUpperCase();
	this.appVersionNetscape7_0 = this.appVersionNetscape7_0.toUpperCase();
	this.appVersionNetscape7_2 = this.appVersionNetscape7_2.toUpperCase();
	
	this.getNavigatorVersion = function ()
	{
		var tempVersion = "";
		
		//IE
		if (navAppVersion.indexOf("MSIE") >= 0)
		{
			var tempIndex = navAppVersion.indexOf("MSIE");
			tempVersion = navAppVersion.substring(tempIndex,tempIndex + 8);
		
		
		}//Netscape
		else if (navAppVersion.indexOf("NETSCAPE") >= 0)
		{
			var tempIndex = navAppVersion.indexOf("NETSCAPE");
			tempVersion = navAppVersion.substring(tempIndex,tempIndex + 12);
		}
		
		switch(tempVersion)
		{
			case this.appVersionIE4_0:return this.appVersionIE4_0;break;
			case this.appVersionIE5_0:return this.appVersionIE5_0;break;
			case this.appVersionIE5_5:return this.appVersionIE5_5;break;
			case this.appVersionIE6_0:return this.appVersionIE6_0;break;

			case this.appVersionNetscape4_0:return this.appVersionNetscape4_0;break;
			case this.appVersionNetscape5_0:return this.appVersionNetscape5_0;break;
			case this.appVersionNetscape6_0:return this.appVersionNetscape6_0;break;
			case this.appVersionNetscape7_0:return this.appVersionNetscape7_0;break;
			case this.appVersionNetscape7_2:return this.appVersionNetscape7_2;break;
			
			default:return this.appVersionIE5_0;break;
		}

	}
}

//IE browse xml DownLoad//
function xmlIEDataLoad(xmlFilePath,bIsAsync)
{
	var xmldom = new ActiveXObject("Microsoft.XMLDOM");
	xmldom.async = bIsAsync;
	xmldom.load(xmlFilePath)
	var xmlTopNode = xmldom.documentElement;
	
	return xmlTopNode;
}

//Netscape browse xml DownLoad//
function getResponsePageData(xmlFilePath,bIsAsync)
{
	var http_request = new XMLHttpRequest();
	http_request.overrideMimeType("text/xml"); 
	http_request.open("GET", xmlFilePath, bIsAsync);
	http_request.send(null);
	return http_request.responseText;
}

function xmlNetscapeDataLoad(xmlFilePath,bIsAsync)
{
/*
	var DOMdoc = new DOMParser();
	DOMdoc.async = bIsAsync;
	var DOMdoc = DOM.parseFromString(xmlFilePath,"text/xml"); 
	return DOMdoc.documentElement;
*/	

	var http_request = new XMLHttpRequest();
	http_request.open("GET", xmlFilePath, bIsAsync);
	http_request.send(null);
	return http_request.responseXML.documentElement;

	/*
	var xmldom = document.implementation.createDocument("","",null);
//	xmldom.async = bIsAsync;
	xmldom.load(xmlFilePath);
	
	var xmlTopNode = xmldom.documentElement;
	return xmldom;
	//return xmlTopNode;
	*/
	
}

function xmlDataLoad(xmlFilePath,bIsAsync)
{
	if (xmlFilePath == null)
	{
		return null;
	}
	if (xmlFilePath == "")
		return null;
	if (xmlFilePath.length <= 0)
		return null;
		
	var objGetNavigatorType = new claGetNavigatorType();
	var tempNavigatorName = objGetNavigatorType.getNavigatorName();

	if (tempNavigatorName == objGetNavigatorType.appNameIE)
	{
		return xmlIEDataLoad(xmlFilePath,bIsAsync);
	}

	if (tempNavigatorName == objGetNavigatorType.appNameNetsacpe)
	{
		return xmlNetscapeDataLoad(xmlFilePath,bIsAsync);
	}
	
}

function getTagPostion(objTaget)
{
	var objTag = objTaget;
	this.tagTop = objTag.offsetTop;
	this.tagLeft = objTag.offsetLeft;
	
	while (objTag = objTag.offsetParent)
	{
		if (objTag.tagName.toUpperCase() == "BODY")
		{
			break;
		}
		else
		{
			this.tagTop += objTag.offsetTop;
			this.tagLeft += objTag.offsetLeft;
		}
	}
}

function getGrayColorHexRGB(hexRgb,RgbLabel)
{
	hexRgb = "0x" + hexRgb;
	var iRgbValue = parseInt(hexRgb);
	
	RgbLabel = RgbLabel.toUpperCase();
	switch(RgbLabel)
	{
		case "R":
					iRgbValue = iRgbValue * 0.3;
					break;
		case "G":
					iRgbValue = iRgbValue * 0.59;
					break;
		case "B":
					iRgbValue = iRgbValue * 0.11;
					break;
		default:
					iRgbValue = iRgbValue * 1.0;
					break;
	}

	return iRgbValue;
}

function getGrayColor(oldColor)
{	
	oldColor = oldColor.replace(/\s+/,"");// replace space//

	if ( (oldColor.indexOf("#") >= 0) && (oldColor.length == 7)) 
	{
		var iGgbValue = parseInt(
									getGrayColorHexRGB(oldColor.substring(1,3),"R") + 
									getGrayColorHexRGB(oldColor.substring(3,5),"G") + 
									getGrayColorHexRGB(oldColor.substring(5,7),"B")
								);
								
		var sGgbValue = iGgbValue.toString(16);
		sGgbValue = (sGgbValue.length <= 1) ? ("0" + sGgbValue) : sGgbValue;

		return "#" + sGgbValue + sGgbValue + sGgbValue;
	}
	else
	{
		return oldColor;
	}
}

//darg Event//
function drag(o){
	o.onmousedown=function(a){
		var d=document;if(!a)a=window.event;
		var x=a.layerX?a.layerX:a.offsetX,y=a.layerY?a.layerY:a.offsetY;
		
		
		/*
		if(o.setCapture)
			o.setCapture();
		else if(window.captureEvents)
			window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
		*/

		o.onmousemove=function(a){
			if(!a)a=window.event;
			if(!a.pageX)a.pageX=a.clientX;
			if(!a.pageY)a.pageY=a.clientY;
			var tx=a.pageX-x,ty=a.pageY-y;
			o.style.left=tx;
			o.style.top=ty;
		};

		o.onmouseup=function(){
			/*
			if(o.releaseCapture)
				o.releaseCapture();
			else if(window.captureEvents)
				window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
			*/
			
			o.onmousemove=null;
			o.onmouseup=null;
		};
	};
}

//--------------------- paul -----------------------------------------------//

//-->



