String.prototype.trim = function()
{
	if(this==null || this=="")
		return ""
		
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function GetAppRoot()
{
	return "/"
}

function IsDigit(cCheck){
	return (('0'<=cCheck) && (cCheck<='9')); 
}

function IsAlpha(cCheck){
	return ((('a'<=cCheck) && (cCheck<='z')) || (('A'<=cCheck) && (cCheck<='Z'))) 
}


function dfHTMLToTextBox(str)
{
	str=str.trim()
	if(str=="")
		return ""
		
	str=str.replace(/&gt;/g,">")
	str=str.replace(/&lt;/g,">")
	str=str.replace(/&quot;/g,"\"")
	str=str.replace(/&amp;/g,"&")	
	
	return str
}

function LoadNewPage(url){
	window.location.href=url;
}

function LoadNewPageInTop(url){
	window.top.location.href=url;
}

function OpenNewWindow(url,width,height)
{
	if(typeof(width)=="undefined")
		width=500
	if(typeof(height)=="undefined")
		height=300
		
	var left=(screen.availWidth-width)/2
	var top=(screen.availHeight-height)/2
	
	var newwin = window.open(url,"","location=no scrollbars=yes channelmode=no menubar=no status=yes resizable=1 left="+left+" top="+top+" width="+width+" height="+height);
	newwin.focus();
	
	//return newwin
}


function ShowDialog(url, width, height ,sCallBackFunc) {
	if(width == null){
		width = 800
	}
	if(height == null){
		height = 600
	}
	var newwin = showModalDialog(url, window, "dialogWidth:" + width + "px;dialogHeight:" + height + "px;help:no;scroll:no;status:no");
	//return newwin
	if(sCallBackFunc != null){
		eval(sCallBackFunc + "('" + newwin + "')")
	}	
}


function CloseWindow(){
	window.close();
}

function RefreshWindow(){
	window.location.reload();
}


function getSelectedId(objCurrentForm,id,sWarn){
	if(!isNaN(parseInt(id))){
		var selectedId =parseInt(id);
	}
	else{
		var selectedId =parseInt(objCurrentForm.KeyValue.value);

	}

	if(isNaN(selectedId)){
		alert(sWarn);
		return -1001;	
	}
	else{
		return  selectedId;
	}
}

function Add(sDealPage){
	LoadNewPage(sDealPage)
}

function Edit(sDealPage,sKeyFld,objForm,id,sWarn,sBackUrl){
	var id = getSelectedId (objForm,id,sWarn);
	if(id > 0){
		if (sDealPage.indexOf("?") < 0 ){
			sDealPage += "?"
		}
		var url = sDealPage  + sKeyFld + "=" + id;
		url += "&nextUrl=" + sBackUrl; 
		return LoadNewPage(url) 
	}
}

function SaveAndExit(objForm){
	objForm.exit.value = 1;
	objForm.submit();
	
}

function DelBySubmit(objForm,id,sWarn,sConfirm,iSubmitType){
	if(iSubmitType == null || iSubmitType == ""){
		iSubmitType = 2
	}
	var id = getSelectedId (objForm,id,sWarn);
	if( id > 0){
		if(confirm(sConfirm)){
			objForm.submitType.value = iSubmitType;
			objForm.submit();
		}
	}
	
}

function mfGetDaysInMonth(mo, yr)
{
	if (mo == 2)
		return 28 + IsLeapYear(yr);
	else
		return 30 + ((mo + (mo > 7)) % 2);
}

function IsLeapYear(yr)
{
	if ((yr % 4 == 0) && (yr % 100 != 0) || (yr % 400 == 0))
		return 1;
	else
		return 0;
}

function changeDay(sElementY,sElementM,sElementD){
	var objY = document.getElementById(sElementY);
	var objM = document.getElementById(sElementM);
	var objD = document.getElementById(sElementD);
	var iSelected = objD.value;

	var iDay = mfGetDaysInMonth(parseInt(objM.value),parseInt(objY.value));

	var objDiv = document.getElementById("_DIV_SELECT_" + sElementD);
	
	var objTxt = document.getElementById("_TXT_" + sElementD);
	var objHiddenInput = document.getElementById(sElementD);	

	var objTbl = objDiv.children(0)

	var iItemCount = objTbl.rows.length - 1
	for(m=iItemCount;m >= 0;m--){
		objTbl.deleteRow(m)
	}
	if( iSelected > iDay){
		iSelected = iDay;
	}

	for(m=1;m<iDay + 1;m++){
		var objTr = objTbl.insertRow();
		oTr.className= "listboxUnSelItem"
		var objTd = objTr.insertCell();
		objTd.innerHTML = m;
	
		
		var objTd = objTr.insertCell();
		objTd.innerHTML = m;
		objTd.style.display = "none"
		
	}
	objTbl.rows[iSelected -1].className= "listboxSelItem"
	objTxt.value = iSelected;
	objHiddenInput.value = iSelected;
}

//Js For UI_select [Begin]

var popDivId = null;
var iMaxHeight=180

function HidePopDiv(){
	if( null != popDivId){
		var btnId = event.srcElement.id;
		var selectBoxId = btnId.substring(8);
		if(popDivId != "_DIV_SELECT_" + selectBoxId ){
			var objPopDiv = document.getElementById(popDivId);
			objPopDiv.style.display = "none";
			window.document.detachEvent("onclick",HidePopDiv)
			popDivId = null
		}
	}

}

function clickBtn(){
	HidePopDiv();
	var btnId = event.srcElement.id;
	var selectBoxId = btnId.substring(8);
	
	var objDiv = document.getElementById("_DIV_SELECT_" + selectBoxId);
	var objTxt = document.getElementById("_TXT_" + selectBoxId);
	var objHiddenInput = document.getElementById(selectBoxId);

	var sDispStatus = objDiv.style.display;	
	with(objDiv.style){

		if(sDispStatus == ""){
			display = "none";
			popDivId = null
			window.document.detachEvent("onclick",HidePopDiv)
		}
		else{
			display = "";
			var iDivTop,iDivLeft;

			iDivTop = objTxt.offsetTop;
			iDivLeft = objTxt.offsetLeft		
			objParent = objTxt.offsetParent; 



		
			while(objParent.tagName.toUpperCase() != "BODY"){
				if(objParent.tagName.toUpperCase()=="DIV" && objParent.id=="con")
				{
					break
				}
				iDivTop += objParent.offsetTop;
				iDivLeft += objParent.offsetLeft;
				
				objParent = objParent.offsetParent;
			}

			iDivTop += objTxt.offsetHeight;

			width = objTxt.offsetWidth;
			pixelTop = iDivTop;
			pixelLeft = iDivLeft

			if(objDiv.offsetHeight >iMaxHeight){
				height = iMaxHeight
			}	
			overflow="auto"	

			objDiv.focus()
			popDivId = "_DIV_SELECT_" + selectBoxId
			window.document.attachEvent("onclick",HidePopDiv)
		}

	}

}

function onmouseoverTbl(){
	var oTd = event.srcElement;

	if(oTd.tagName.toUpperCase() !="TD"){
		return;
	} 
	oTr = oTd.parentElement;
	oTbl = oTr.parentElement;
	if(oTbl.tagName.toUpperCase()!="TABLE"){
		oTbl = oTbl.parentElement
	}

	for(m=0;m<oTbl.rows.length;m++){
		oTbl.rows[m].className= "listboxUnSelItem"
	}

	oTr.className="listboxSelItem"
}

function onclickTbl(){
	var oTd = event.srcElement;

	if(oTd.tagName.toUpperCase() !="TD"){
		return;
	} 
	oTr = oTd.parentElement;
	oTbl = oTr.parentElement;
	if(oTbl.tagName.toUpperCase()!="TABLE"){
		oTbl = oTbl.parentElement
	}
	var val=oTr.cells(0).innerText
	var key=oTr.cells(1).innerText
	
	var hiddenInputId = popDivId.substring(12)

	var objHiddenInput = document.getElementById(hiddenInputId)
	var objTxt = document.getElementById("_TXT_" + hiddenInputId);
	
	//var objChange = document.getElementById("_CHANGE_" + hiddenInputId);
	if(objHiddenInput.value != val){
		objHiddenInput.value = val
		objTxt.value = key;
	
		var objDiv = document.getElementById("_DIV_SELECT_" + hiddenInputId);
		var onchangeItem = objDiv.onchange;
		if(onchangeItem != "undefined"){
			eval(onchangeItem)
		}
	
	}



}
//Js For UI_select [End]


function CheckNeedValue(formName ,warnMsg){
	if(typeof(warnMsg)== "undefined")
	{
		warnMsg = "Please enter all items which need value.";
	}
	var objHiddenInput = eval("document." + formName + ".needValueItems");
	var sItems = objHiddenInput.value;
	if (sItems ==""){
		return true;
	} 

	var arrItem = sItems.split(",");
	for(i=0;i<arrItem.length;i++){
		sItemValue = eval("document." + formName + "." + arrItem[i] + ".value");
		if (sItemValue==""){
			alert(warnMsg);
			eval("document." + formName + "." + arrItem[i] + ".focus()")
			return false
		}

	}

	return true;
}

function CheckNueric(formName){

	return true;
	var objHiddenInput = eval(formName + ".nuericItems");
	var sItems = objHiddenInput.value;
	var arrItem = sItems.split(",");
	for(i=0;i<arrItem.length;i++){
		sItemValue = eval("document." + formName + "." + arrItem[i] + ".value");
		if (!Js_IsNueric(sItemValue)){
			alert("Only numeric value is valid.");
			eval("document." + formName + "." + arrItem[i] + ".focus()")
			return false
		}
	}
	return true;
}

function CheckEmail(){
	return true;
}

function CheckPhone(){
	/*
	var iKeyCode =event.keyCode;
	if(iKeyCode > 47 && iKeyCode < 58 || iKeyCode == 45|| iKeyCode == 59){
	}
	else{
		alert("Telphone no. is invalid.")
		return false;
	}
	*/
	return true;
}

function CheckInteger(){
	var iKeyCode =event.keyCode;
	if(iKeyCode > 47 && iKeyCode < 58 ){
	}
	else{
		alert("Please enter a integer.")
		return false;
	}
}

function CheckNumber(){
	var iKeyCode =event.keyCode;
	if(iKeyCode > 47 && iKeyCode < 58 || iKeyCode == 46 ){
	}
	else{
		alert("Please enter a number.")
		return false;
	}
}

function SubmitForm(formName){
	if(CheckNeedValue(formName) && CheckNueric(CheckNueric)){
		eval("document." + formName + ".submit()")
	}		
}

function UpdateExit(formName){
	eval("document." + formName + ".exit.value = 1")
}

function SubmitToHiddenFrame(formName){
	if (!CheckNeedValue('_LoginForm0')){
		return;
	}
	//alert(CheckTextAreaLength())
	if(!CheckTextAreaLength()){
		return;
	}
	var objHiddenDiv = document.getElementById("HiddenDiv")
	objHiddenDiv.style.display = "none";
	var objForm = eval("document." + formName);
	objForm.target = "hiddenFrame";
	//objForm.target = "_blank";
	objForm.submit();
	if(objForm.user_pwd){
		objForm.user_pwd.value = "";
	}
	objForm.msg.value = "";
}

function CheckEmail(email){
 if(email.length!=0){
    if (email.charAt(0)=="." || email.charAt(0)=="@"|| email.indexOf('@', 0) == -1 || email.indexOf('.', 0) == -1 
		|| email.lastIndexOf("@") ==email.length-1 ||  email.lastIndexOf(".")==email.length-1){
      alert("Email is invalid.");
      return false;
    }
 }
 else{
   alert("Please enter email.");
   return false;
 }
 return true;
} 

function Logoff(url){
	top.location.href = url;
	return;
}


function CheckTextAreaLength(){

	var arrForm = document.forms;
	for(j=0;j<arrForm.length;j++){
		var oForm = arrForm[j]
		for(i=0;i<oForm.length;i++){
			var obj = oForm[i];
			if(obj.tagName){
				if(obj.tagName.toUpperCase() == "TEXTAREA"){
					var iMaxlength = parseInt(oForm("_maxlength"+ obj.name).value);

					var sInput = new String(obj.value);
					//alert(sInput.length)
					//alert(iMaxlength);
					//alert(sInput.length > iMaxlength)
					if(sInput.length > iMaxlength){
						alert("It is excced the max length.");
						obj.focus();
						return false;
					}
				}
			}
		}	
	}

	return true

}

function UntrueJs(){

}

function GoPrint(){  
	if (window.print) {
		window.print() ;  
	} else {
		var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";  
	}
}



scrWaitBodyFocus=null;
scrWaitBodyContext=null;
function LockScreenToWait(msg)
{
	if (scrWaitBodyFocus==null && scrWaitBodyContext==null){
		scrWaitBodyFocus = document.body.onfocus+'';
		scrWaitBodyContext = document.body.oncontextmenu+'';
		document.body.onfocus = LockScreenToWait;
		document.body.oncontextmenu = CancelClick;
	}
	var div = document.all["divScreenWaiting"];
	if (div+''=="undefined"){
		div = document.createElement("DIV");
		div.setAttribute("id","divScreenWaiting");
		div.className = "messageBox";
		div.style.padding = 10;
		div.style.paddingLeft = 30;
		div.style.paddingRight = 30;
		div.innerHTML = msg;
		document.body.appendChild(div);
	}
	var x =(document.body.clientWidth-div.offsetWidth)/2;
	var y = (document.body.clientHeight-div.offsetHeight)/2;
	div.style.pixelLeft = x;
	div.style.pixelTop = y;
	div.style.visibility = "visible";
	div.onclick = CancelClick;
	if(typeof(msg)!="undefined")
		div.innerHTML = msg;
		
	div.setCapture();

}

function UnlockScreenWait()
{
	var div = document.all["divScreenWaiting"];
	if (div+''=="undefined")
		return;
	div.style.visibility = "hidden";
	document.body.onfocus = scrWaitBodyFocus;
	document.body.oncontextmenu = scrWaitBodyContext;
	scrWaitBodyFocus = null;
	scrWaitBodyContext = null;
	document.releaseCapture();
}

function CancelClick()
{
	var elem = event.srcElement;
	if (elem.className=='messageBox'){
		UnlockScreenWait();
		event.cancelBubble = false;
		return false;
	}
	return false;
}



function refreshHiddenFrame(url)
{
	
	url = url.toLowerCase();
	var curUrl = top.hideFrame.location.href;
	var curPageName = curUrl.substr(curUrl.lastIndexOf("/")+1);

	if (curPageName != ""){
		curPageName = curPageName.toLowerCase();	
	}
	if(curPageName!=url)
	{
		top.hideFrame.location  = url;
	}
}

function showQueryDiv(){
	Querybox0.showBox();
}


function getIEVersion()
{
	var s=window.clientInformation.userAgent
	
	var reg=/.+; MSIE( \d.\d+);?/ig
	if(reg.test(s))
		return parseFloat(RegExp.$1)
}


function GetTop(obj)
{
	var objTop    = obj.offsetTop;
	var objParent = obj.offsetParent;
	while (objParent.tagName.toUpperCase() != "BODY")
	{
	
		objTop   += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}
	
	return objTop
}

function GetLeft(obj)
{
	var objLeft   = obj.offsetLeft;
	var objParent = obj.offsetParent;
	while (objParent.tagName.toUpperCase() != "BODY")
	{
		objLeft  += objParent.offsetLeft;
	
		objParent = objParent.offsetParent;
	}
    	return objLeft;
}

function GetzIndex(obj)
{
	var zIndex=0
	var objParent = obj.offsetParent;
	while(objParent.tagName.toUpperCase()!="BODY")
	{
		zIndex+=objParent.style.zIndex
		objParent=objParent.parentElement		
	}
	
	return zIndex
}

function rectCrossrect(rect1,rect2)
{
	if(rect1.pt1.y>rect2.pt2.y
		|| rect1.pt2.y<rect2.pt1.y
		|| rect2.pt1.x>rect1.pt2.x
		|| rect2.pt2.x<rect1.pt1.x)
		return false
	return true

}

function point(x,y)
{
	this.x=x
	this.y=y
}

function rect(left, top,width,height)
{
	this.pt1=new point(left,top)
	this.pt2=new point(left+width,top+height)
}


var m_hideElementArray=new Array()
function hideElement(elmID,objRef,m_winDocAll)
{
	if(null==objRef ||
		objRef.style.display=="none")
		return
	
	var objRefLeft=GetLeft(objRef)
	var objRefTop=GetTop(objRef)
	var rectRef=new rect(objRefLeft,objRefTop,objRef.offsetWidth,objRef.offsetHeight)
	
	for (i = 0; i < m_winDocAll.tags(elmID).length; i++)
	{
		var obj = m_winDocAll.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;

		var objLeft=GetLeft(obj)
		var objTop=GetTop(obj)
				
		var rectObj=new rect(objLeft,objTop,obj.offsetWidth,obj.offsetHeight)
		if(rectCrossrect(rectRef,rectObj))
		{
			obj.style.visibility = "hidden";
			m_hideElementArray[m_hideElementArray.length]=obj
			
			//m_hideElementArray.push(obj)
		}
	}
}


function showElement()
{		
	var iLen=m_hideElementArray.length
	for(var i=0;i<iLen;i++)
	{
		var obj=m_hideElementArray[i]
		obj.style.visibility = ""
	}
	m_hideElementArray=null
	m_hideElementArray=new Array()
}


function viewMsg(str){

	var objHiddenDiv = document.getElementById("HiddenDiv")
	var objContentDiv = document.getElementById("_HiddenDivContent")
	
	var objLink = event.srcElement;
	var sInner = "\n"
	sInner += objLink.parentNode.all("detail_msg").value
	sInner += "\n"
	
	objContentDiv.innerText = sInner;

	var iDivTop,iDivLeft;

	iDivTop = objLink.offsetTop;
	iDivLeft = objLink.offsetLeft		
	objParent = objLink.offsetParent; 

	while(objParent.tagName.toUpperCase() != "BODY"){
		iDivTop += objParent.offsetTop;
		iDivLeft += objParent.offsetLeft;
		
		objParent = objParent.offsetParent;
	}	
	with(objHiddenDiv.style){

		if(iDivLeft + 370 > document.body.clientWidth){
			pixelLeft = iDivLeft - 370
		}
		else{
			pixelLeft = iDivLeft
		}
		

		pixelTop = iDivTop
		display = "";
	}	
	
}

function SelectAll(name){
	var arrElement = document.getElementsByName(name);
	if (typeof(arrElement) != "undefined"){
		
		var bAllElementIsChecked = true;

		for(x=0;x<arrElement.length;x++){
			if(!arrElement[x].checked){
				bAllElementIsChecked = false;
			}
		}	
		
		for(x=0;x<arrElement.length;x++){
			
			if(arrElement[x].checked == bAllElementIsChecked){
				arrElement[x].click();
			}
		}
	}
}

function GetRadioValueByName(sElement){
	var arrElement = document.getElementsByName(sElement);
	if (typeof(arrElement) != "undefined"){
		for(x=0;x<arrElement.length;x++){
			if(arrElement[x].checked){
				return arrElement[x].value;
			}
		}				
	}
	
	return null;
}


function global_edit(objCurrentForm,id ,sUrl ,sWarn){
	if(id == null){
		var selectedId = getSelectedId(objCurrentForm,id,sWarn);
	}
	else{
		var selectedId  = id;
	}
	if( selectedId > 0 || selectedId == -1){
		sUrl += selectedId;
		LoadNewPage(sUrl);
	}
}

function global_del(objCurrentForm,id ,sUrl ,sWarn ,sConfirmDelC){
	var selectedId = getSelectedId(objCurrentForm,id,sWarn);
	if( selectedId > 0){
		if(confirm(sConfirmDelC)){
			sUrl += selectedId;
			LoadNewPage(sUrl);
		}
	}
}


