function openWindow(URL, winName, width, height) { 
	window.open(URL, winName, 'height=' + height + ',width=' + width + ',top = ' + (screen.availHeight - height) / 2 + ', left = ' + (screen.availWidth - width) / 2 + ', resizable=yes,status=no,toolbar=no,menubar=no,location=no, scrollbars=yes')
}

function openForm(strLeaveTrans) {
				
		var strHeight = 550
		var strWidth = 700
		var strTop = (screen.height - 550) / 2
		var strLeft = (screen.width - 700) / 2
		var strFeatures = 'height=' + strHeight + ', width=' + strWidth + ', top=' + strTop + ', left=' + strLeft + ', status=no, toolbar=no, menubar=no, location=no, resizable=no, scrollbars = yes'
		var strWindowName = 'LeaveRequestDetails'
		var strURL = 'viewApprovedLeaveRequest.asp?LeaveTransid=' + strLeaveTransid
		
		
		window.open(strURL, strWindowName, strFeatures)
}

function goToPage(sURL) {
	if((document.body.modulename == 'CreatePO' || document.body.modulename == 'EditPO' || document.body.modulename == 'CreateEC' || document.body.modulename == 'EditEC') && isFormModified) {
		if (!confirm('You are about to leave the form and all the modification will be loss. Are you sure to continue ?')){
			return
		}
	}
	window.location = sURL
}
	

function isDate(strDate) {
	
	
	var rexNumber = /^\-?\d+$/;
    
	var intCentYear = 30;
	
	var arrDate = strDate.split('/');

	
	if (arrDate.length != 3) return false
	
	if (!arrDate[0]) return  false
	
	if (!rexNumber.exec(arrDate[0])) return false
	
	if (!arrDate[1]) return false
	
	if (!rexNumber.exec(arrDate[1])) false
	
	if (!arrDate[2]) return false
	
	if (!rexNumber.exec(arrDate[2])) return false

	

	var dt_date = new Date();
	
	dt_date.setDate(1);

	
	if (arrDate[0] < 1 || arrDate[0] > 12) return false
	
	dt_date.setMonth(arrDate[0]-1);
	 
	
	if (arrDate[2] < 100) arrDate[2] = Number(arrDate[2]) + (arrDate[2] < intCentYear ? 2000 : 1900);
	
	dt_date.setFullYear(arrDate[2]);

	
	var dt_numdays = new Date(arrDate[2], arrDate[0], 0);
	
	dt_date.setDate(arrDate[1]);
	
	if (dt_date.getMonth() != (arrDate[0]-1)) return false

	

	return true

}

// Compare two datetime
// Done by Lewis @ 6 Jun 2003
// Compart two date time
//
// @param boolean blnCanEqual => false if largedate must greater than smalldate
//						 => true if largedate must greater than or equal smalldate
function CompareDateTime(SmallDate,LargeDate){
	var sdate, ldate;
	sdate='2004-01-01 '+Trim(SmallDate.value) + ":00";
	ldate ='2004-01-01 '+Trim(LargeDate.value) + ":00";
	alert (sdate);
	
	if (isDateTime(sdate))
		alert ('aaa')
	else
		alert ('bbb');	
	if (isBlank(SmallDate) || isBlank(LargeDate)) return true;
	if ( isDateTime(SmallDate) && isDateTime(LargeDate))
  		if (ToDateTime(LargeDate)>ToDateTime(SmallDate)) return true;
	return false;  
}

//----------------------------------------------------------------
// Done by Lewis @ 5 Jun 2003
// isDateTime(DateTimeString)
// Returns true if Datetime string is a correct YYYY-MM-DD HH:mm:ss format
//--------------------------------------------------------------
function isDateTime(strDateTime)
{
	
	if (strDateTime.length == 19){
		var strDate = strDateTime.substr(0,10);
		var strTime = strDateTime.substr(11,8);
	}
	else if(strDateTime.length == 16){
		var strDate = strDateTime.substr(0,10);
		var strTime = strDateTime.substr(11,5);
		strTime = strTime + ':00';
	}
	else return false;
	
	return (isDateYmd(strDate) && isTimeHms(strTime));
}

function ToDateTime(DateValue)
{
	var vsec;
	if (DateValue.length == 16)
		vsec = '00';
	else
		vsec = DateValue.substr(17,2);
	
	var humDate = new Date(Date.UTC(
		stripLeadingZeroes(DateValue.substr(0,4)),
		stripLeadingZeroes(DateValue.substr(5,2))-1,
		stripLeadingZeroes(DateValue.substr(8,2)),
		stripLeadingZeroes(DateValue.substr(11,2)),
		stripLeadingZeroes(DateValue.substr(14,2)),
		stripLeadingZeroes(vsec)
	));
	return (humDate.getTime()/1000.0) ;
}

//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}