function trim(str) {
	var l = str.length
		
	for (var i = 0; i < l; i++)
		if (str.substr(i, 1) != ' ') break;
		
	for (var j = l - 1; j > 0; j--)
		if (str.substr(j, 1) != ' ') break;
			
	return str.substr(i, j-i+1);
}

function isEmpty(objField, strName) {
	if (trim(objField.value) == '') {
		alert(strName + ' is required.');
		objField.focus();
		try{objField.select();}catch(e){}
		return true;
	}
	
	return false;
}

function isError(boolCondition, objField, strName){
	if(boolCondition){
		alert('Invalid ' + strName);
		objField.focus();
		try{objField.select();}catch(e){}
		return true;
	}
	return false;
}

function getValue(radioName) {
	var obj = document.all[radioName];
	
	for (var i=0; i < obj.length; i++) {
		if (obj[i].checked) return obj[i].value;
	}
	
	return '';
}

function compareDate(date1, date2) {
	switch(true) {
		case date1 < date2 : return -1;
		case date1 > date2 : return 1;
		default: return 0;
	}
}

function openWindow(url, name, width, height, attr) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	
	if (attr == null) attr = '';
	if (attr != '') attr += ',';

	window.open(url, name, attr + 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);
}

function openWindow2(url, name, width, height, attr) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	
	if (attr == null) attr = '';
	if (attr != '') attr += ',';

	window.open(url, name, attr + 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ', scrollbars=yes resizable=yes');
}


function MoveToCenter(){
	var X = Math.round((screen.width - document.body.clientWidth) / 2);
	var Y = Math.round((screen.height - document.body.clientHeight) / 4);
	
	if(X < 0) X = 0;
	
	if(Y < 0)	Y = 0;
	if(window.dialogLeft){
		window.dialogLeft = X + 'px';
		window.dialogTop = Y + 'px';
	}else{
		window.moveTo(X, Y);
	}
	window.focus();
}

function getCookie(key) {
	var arrCookie = document.cookie.split(';');
	
	for (var i=0; i < arrCookie.length; i++) {
		var pair = arrCookie[i].split('=');
		if (pair[0] == key) return pair[1];
	}
	
	return '';
}

function getWidth() {
	var width = screen.width;
	if (width <= 800) width = 760;
	if (width >= 1024) width = 1024;
	
	return width;
}

function isAlphaNumeric(text) {
	var reg = /[^A-Za-z0-9]/;
	return !reg.test(text);
}

function checkEnter(e){
	var characterCode
	if(e && e.which){
		e = e
		characterCode = e.which
	}
	else{
		e = event
		characterCode = e.keyCode
	}	 
	if(characterCode == 13){
 		document.forms[0].submit()
 		return false
	}
return true
}