function trim(str)   
{	
	var k=0;
	var m=0;
	for(i=0;i<str.length;i++)
	{
		if(str.charCodeAt(i)!=32)
		{
			k=i;
			break;  
		}
	}
	if(i==str.length)   {str=""; return(str);}
	for(i=str.length-1;i>-1;i--)
	{
		if(str.charCodeAt(i)!=32)
		{
			m=i;
			break;  
		}
	}
	str=str.substring(k,m+1);
	return(str);
} 

// Press F1 to show help doc.
document.onhelp = ShowFormHelpFile; 
function ShowFormHelpFile()
{
	var objHelpLink = document.all.helpLink;
	if (typeof(objHelpLink) != "undefined")
	{
		var strHelpLink=objHelpLink.innerText;     
		if (strHelpLink!="")
		window.open(strHelpLink);
		return false;
	}
	else
	{
		window.event.returnValue = false;
	}
}	
	
function ShowInfor(strtemp)
{
	mywindow = window.open("", "_blank", "top=100,left=70,width=400,height=300,toolbar=no,menubar=no,location=no,resizable=yes");
	mywindow.document.open();
	mywindow.document.writeln(strtemp);
	mywindow.document.close();
}

// Begin for search dropdownlist item.
var SearchKey = "";
var LastSearchTime = Date.parse(Date());
var IntervalLimit = 2000;    

function MatchSearchItem()
{
	var SourceElement;
	var CurrentTime;
	var ItemCount;
	
	SourceElement = event.srcElement;
	CurrentTime=Date.parse(Date());
	ItemCount = SourceElement.length;

	if(CurrentTime - LastSearchTime > IntervalLimit)
	{
		SearchKey = "";
	}
	LastSearchTime = CurrentTime;
	SearchKey = SearchKey + String.fromCharCode(window.event.keyCode); 
	
	for(i = 0; i < ItemCount; i++)
	{		
		var ItemText = SourceElement.options[i].text.toLowerCase();		
		var MatchedIndex = ItemText.indexOf(SearchKey);
		
		if (MatchedIndex == 0)
		{
			SourceElement.options[i].selected = true;
			// if next statement is remarked,this function will not run as wished, otherwise,  onchange event will not be fired.
			window.event.returnValue = false; 			
			return;
		}   
	} 
}
// End for search dropdownlist item.

//For Calendar [begin]
var sMon = new Array(12);
	sMon[0] = "Jan"
	sMon[1] = "Feb"
	sMon[2] = "Mar"
	sMon[3] = "Apr"
	sMon[4] = "May"
	sMon[5] = "Jun"
	sMon[6] = "Jul"
	sMon[7] = "Aug"
	sMon[8] = "Sep"
	sMon[9] = "Oct"
	sMon[10] = "Nov"
	sMon[11] = "Dec"

function calendar(t) 
{
	var strFullPath = window.location.toString();
	var sPath = "Js/calendar1.htm"; // Set default value
	if (strFullPath.indexOf("/Forms/") > 0)
		sPath = strFullPath.substr(0, strFullPath.indexOf("/Forms/")) + "/Forms/Public/Utility/calendar1.htm";

	var strDialogLeft = (event.clientX - 150).toString();
	var strDialogTop = (event.clientY - 150).toString();
	strFeatures = "status=no;dialogWidth=250px;dialogHeight=230px;center=yes;help=no;scroll=no";
	strFeatures = strFeatures + "dialogLeft:" + strDialogLeft + ";dialogTop:" + strDialogTop;
	//strFeatures = OPEN_CALENDAR_DIALOG;
	st = t.value;
	if (st != "")
		st = st.substring(6, 10) + "/" + st.substring(3, 5) + "/" + st.substring(0, 2);
	sDate = showModalDialog(sPath,st,strFeatures);
	t.value = formatDate(sDate, 0);
}

function calendarT(t, s) 
{
	var strFullPath = window.location.toString();
	var sPath = "Js/calendar1.htm"; // Set default value
	if (strFullPath.indexOf("/Forms/") > 0)
		sPath = strFullPath.substr(0, strFullPath.indexOf("/Forms/")) + "/Forms/Public/Utility/calendar1.htm";

	var strDialogLeft = (event.clientX - 150).toString();
	var strDialogTop = (event.clientY - 150).toString();
	strFeatures = "status=no;dialogWidth=250px;dialogHeight=230px;center=yes;help=no";
	strFeatures = strFeatures + "dialogLeft:" + strDialogLeft + ";dialogTop:" + strDialogTop;
	if (t.value == "")
	{
		st = s.value;
	}
	else
	{
		st = t.value;
	}
	sDate = showModalDialog(sPath,st,strFeatures);
	t.value = formatDate(sDate, 0);
}

function checkDate(t) 
{
	dDate = new Date(t.value);
	
	if (dDate == "NaN") {t.value = ""; return;}

	iYear = dDate.getFullYear()

	if ((iYear > 1899)&&(iYear < 1950)) 
	{
		sYear = "" + iYear + ""
		
		if (t.value.indexOf(sYear,1) == -1) 
		{
			iYear += 100
			sDate = (dDate.getMonth() + 1) + "/" + dDate.getDate() + "/" + iYear
			dDate = new Date(sDate)
		}
	}
	
	t.value = formatDate(dDate);
}

function formatDate(sDate) 
{
	var sScrap = "";
	var dScrap = new Date(sDate);
	
	if (dScrap == "NaN") return sScrap;
	
	iDay = dScrap.getDate();
	iMon = dScrap.getMonth()+1;
	iYea = dScrap.getFullYear();
	
        if (iDay<10) iDay="0"+iDay;
        if (iMon<10) iMon="0"+iMon;
        
        sScrap = iYea + "/" + iMon + "/" +iDay  ;
	
	return sScrap;
}

function KeyDate(objItem)
{
	if(objItem.readOnly==true)
		return;
	var strValue;
	var strOldValue = objItem.value;
   	//window.open("date.asp?Item="+strItemName,null,"titlebar=no,toolbar=no,resizable=no,Height=190px,Width=290px;status=no");
   	
   	calendar(objItem)
   	strValue=objItem.value;
   	objItem.value=strValue.substr(0,4)+strValue.substr(5,2)+strValue.substr(8,2);
   	if (objItem.value.length == 0)
   		objItem.value = strOldValue;
}

function KeyMonth(objItem)
{
	var strValue;
   	//window.open("date.asp?Item="+strItemName,null,"titlebar=no,toolbar=no,resizable=no,Height=190px,Width=290px;status=no");
   	
   	calendar(objItem)
   	strValue=objItem.value;
   	objItem.value=strValue.substr(0,4)+strValue.substr(5,2)
}
//For Calendar [end]

