function removeSep(tf) {
	var value, sep, i, result;
	if (arguments[0] == null) return '';
	value = tf.value;
	if (arguments[1] == null) sep = ','; else sep = arguments[1].substr(0, 1);
	result = '';
	for (i=0; i < value.length; i++) {
		if (value.substr(i, 1) != sep) result += value.substr(i, 1);
	}
	tf.value = result;
}

function trimString(string) {
	if (string==null || string.length<1) return "";
	var start; start=0;
	var end; end = string.length-1;
	while ((start<=end) && (string.charAt(start)==" " || string.charCodeAt(start)==13 || string.charCodeAt(start)==10)) start++;
	while ((end>start) && (string.charAt(end)==" " || string.charCodeAt(end)==13 || string.charCodeAt(end)==10)) end--;
	if (start>end) return "";
	return string.slice(start,end+1);
}

function maxLength(tf, len) {
	if (tf.value.length>len) tf.value = tf.value.substr(0,len);
}

function displayWindow(url, name, width, height) {
	var _left, _top;
	var newWin, feature;
	if (document.all) {
		_left = (screen.width - width)/2;
		_top = (screen.height - height)/2;
	} else {
		_left = (800 - width)/2;
		_top = (600 - height)/2;
	}
	feature = 'width=' + width + ',height=' + height + ',left=' + _left + ',top=' + _top;
	if (width >= 500 && height >= 300) feature += ',resizable=yes, location=no, menubar=no, scrollbars=yes,status=no, toolbar=no';
	else feature += ',resizable=no, location=no, menubar=no, scrollbars=yes, status=no, toolbar=no';
	newWin = window.open(url, name, feature);
	if (newWin) {
		newWin.focus();
		return newWin;
	}
	else return null;
}

function selectMenu(menu, value, isValue) {
	var i;
	if (isValue) {
		for (i=0; i<menu.options.length; i++) {
			if (menu.options[i].value == value) {
				menu.options[i].selected = true;
				break;
			}
		}
	}
	else {
		for (i=0; i<menu.options.length; i++) {
			if (menu.options[i].text == value) {
				menu.options[i].selected = true;
				break;
			}
		}
	}
}

function addMenuToMenu(srcobj, desobj, not_added) {
	// If options[i].value == not_added, then isn't added, this is defaul
	var j, k, bIns;
	bIns=false;
	if (srcobj.selectedIndex == -1) return false;

	for (k=0; k<srcobj.options.length; k++) {
		if ((srcobj.options[k].selected==true) && (srcobj.options[k].value != not_added)) {
			for (j=0; j<desobj.options.length; j++) {
				if (srcobj.options[k].value == desobj.options[j].value) {
					bIns=true;
					break;
				}
			}
			if (bIns==true) {
				bIns = false;
				continue;
			}
			desobj.options.length += 1;
			for (j=desobj.options.length-1; j>0; j--) {
				desobj.options[j] = new Option(desobj.options[j-1].text, desobj.options[j-1].value);
			}
			desobj.options[0] = new Option(srcobj.options[k].text, srcobj.options[k].value);
		}
	}
	return true;
}

function addTextToMenu(value, text, desobj, column) {
	// If options[i].value == not_added, then isn't added, this is defaul
	var i,j,tmp;
	if (value==null || text==null) return false;
	if (column != 2) {
		tmp = value.toLowerCase();
		for (i=0; i<desobj.options.length; i++) {
			if (desobj.options[i].value.toLowerCase() == tmp) return false;
		}
	}
	else {
		tmp = text.toLowerCase();
		for (i=0; i<desobj.options.length; i++) {
			if (desobj.options[i].text.toLowerCase() == tmp) return false;
		}
	}
	desobj.options.length += 1;
	for (j=desobj.options.length-1; j>0; j--) {
		desobj.options[j] = new Option(desobj.options[j-1].text, desobj.options[j-1].value);
	}
	desobj.options[0] = new Option(text, value);
	desobj.selectedIndex = 0;
	return true;
}

function removeMenu(obj, not_removed) {
	// If options[i].value == not_removed, then isn't added, this is defaul
	var i, k;
	i = 0;
	if (obj.selectedIndex==-1) return false;
	while (i<obj.options.length) {
		if ((obj.options[i].selected == true) && (obj.options[i].value != not_removed)) {
			for (k=i; k<obj.options.length-1; k++) {
				obj.options[k] = new Option(obj.options[k+1].text, obj.options[k+1].value);
				if (obj.options[k+1].selected) obj.options[k].selected = obj.options[k+1].selected;
				else i++;
			}
			obj.options.length -= 1;
		}
		else i++;
	}
}
function inputFloat(tf, allowNeg) {
	if (tf.value == "") return true;
	var i, c, state, value;
	state	= 'H';
	value	= '';
	for (i=0; i<tf.value.length; i++) {
		c	= tf.value.charAt(i);
		if (c == '-') {
			if (i==0 && allowNeg==true) value += c;
		}
		else if (c == '.') {
			if (state == 'H') {
				value	+= c;
				state	= 'T';
			}
		}
		else if (c >= '0' && c <= '9') {
			value += c;
		}
	}
	if (value.length>0 && value.charAt(0) == '.') value = '0' + value;
	if (tf.value != value) tf.value	= value;
}

function inputInt(tf, allowNeg) {
	if (tf.value == "") return true;
	var i, c, value;
	value	= '';
	for (i=0; i<tf.value.length; i++) {
		c	= tf.value.charAt(i);
		if (c == '-') {
			if (i==0 && allowNeg==true) value += c;
		}
		else if (c >= '0' && c <= '9') {
			value += c;
		}
	}
	if (tf.value != value) tf.value	= value;
}

function myParseInt(value) {
	if (value==null || value=='') return parseInt('');
	var i; i=0;
	while (i<value.length) {
		if (value.substr(i,1)=='0') i++;
		else break;
	}
	if (i<value.length) return parseInt(value.substr(i));
	else return parseInt(value);
}
function openLink(URL){
//	window.open(URL,'_parent',);
	window.open(URL,'mainFrame');
}
function openNew(URL, windowname){
	window.open(URL,windowname);
}

function checkPage(){
	strKeyword = document.frmSearch.txtKeyword.value
    strFrom = document.frmSearch.txtFrom.value
    strTo = document.frmSearch.txtTo.value
    
	if (isempty(strKeyword) ==true) {
		alert("Keyword can not empty. Please re-enter this field.");
		document.frmSearch.txtKeyword.focus();
		return false;
	} 
	if (isempty(strFrom)==false) {
		if (isdate(strFrom) == false) {
			alert("From date is invalid. Please re-enter this field")
			document.frmSearch.txtFrom.focus()
			return false 
		}	
	}
	if (isempty(strTo)==false) {
		if (isdate(strTo) == false) {
			alert("To date is invalid. Please re-enter this field")
			document.frmSearch.txtTo.focus()
			return false 
		}	
	}
	if ((isempty(strFrom)==false) && (isempty(strTo)==true)) {
    	alert("Please enter To date field")
		document.frmSearch.txtTo.focus()
		return false 
	}
	if ((isempty(strFrom)==true) && (isempty(strTo)==false)) {
    	alert("Please enter From date field")
		document.frmSearch.txtFrom.focus()
		return false 
	}
	
	if ((isempty(strTo)==false) && (isempty(strFrom)==false)) {
	    if (_checkdatefromto(strFrom + "-" + strTo) == false){
	        alert("From date field and To date field are invalid. Please check these fields.");
	        return false;
	    }
	}
	document.frmSearch.submit() ;
}