function swapClassName(objId, className1,className2) {
	if (document.getElementById(objId).className == className1)	{
		document.getElementById(objId).className = className2;
	} else {
    	document.getElementById(objId).className = className1;
	}
}

function ToggleNotes(){
	if (document.getElementById('add_notes').style.display == 'none')	{
		document.getElementById('add_notes').style.display = 'block';
		document.getElementById('notes_text_command').innerHTML='Hide Note'
	} else {
    	document.getElementById('add_notes').style.display = 'none';
		document.getElementById('notes_text_command').innerHTML='Add Note'
	}
}

function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}

function setbgColor(objId, newcolor) {
    	document.getElementById(objId).style.backgroundColor = newcolor
}

function setCursor(objId,type_cursor){
	document.getElementById(objId).style.cursor = type_cursor
}

function urlencode(message){
	var encoded = "";
	for (var i = 0; i < message.length; i++ ) {
		var ch = message.charAt(i);
		if (ch == " ") {
			encoded += "+";
		} else if (ch == "&") {
			encoded += "%26";
		} else if (ch == "+") {
			encoded += "%2B";
		} else {
			encoded += ch;
		}
	}
	return encoded;
}

function isNumber_old(str){
	if (str.length == 0) { return false;}
		for(i=0;i<str.length;i++ ) 
		{
			var ch = str.charAt(i);
			if ( ch!='1' && ch!='2' && ch!='3' && ch!='4' && ch!='5' && ch!='6' && ch!='7' && ch!='8' && ch!='9' && ch!='0' && ch!='.' ) 
			{
				return (false);
			}
	}
	return (true);
}

function isNumber(str,isDecimal,isAddressNo) {
	if (str.length == 0) { return false;}
		for(var i=0;i<str.length;i++ ) {
			var ch = str.charAt(i);
			if ( ch!='1' && ch!='2' && ch!='3' && ch!='4' && ch!='5' && ch!='6' && ch!='7' && ch!='8' && ch!='9' && ch!='0' ) {
				if ((isDecimal && ch == '.') || (isAddressNo && ch == '/' ) ) {

				} else {
					return (false);
				}
			}
	}
	return (true);
}

function Trim(TRIM_VALUE){
	if(TRIM_VALUE.length < 1){
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE==""){
		return "";
	}else{
		return TRIM_VALUE;
	}
}

function RTrim(VALUE){
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0){
		return"";
	}
	var iTemp = v_length -1;

	while(iTemp > -1){
		if(VALUE.charAt(iTemp) == w_space){

		} else{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

function LTrim(VALUE){
	var w_space = String.fromCharCode(32);
	if(v_length < 1){
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	var iTemp = 0;

	while(iTemp < v_length){
		if(VALUE.charAt(iTemp) == w_space){
		}else{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

function CheckInputBoxLength(ObjID ,ObjErr ,num_length ,is_blank ,is_correct) {
	document.getElementById(ObjID).className = 'inputbox';
	var ObjValue = Trim(document.getElementById(ObjID).value);
	if ( ObjValue.length < num_length) {
		if (is_blank && ObjValue.length == 0) {

		} else {
			document.getElementById(ObjID).className = 'inputbox_error';
			if (ObjErr == "ERR_USERNAME") {
				document.getElementById(ObjErr).innerHTML = "<span class=\"result_error\"><br>Username must contain at least six characters.</span>";
			} else if (ObjErr == "ERR_CURRENT_PASSWD") {
				document.getElementById(ObjErr).innerHTML = "<span class=\"result_error\"><br>Password must contain at least four characters.</span>";
			} else if (ObjErr == "ERR_NEW_PASSWD") {
				document.getElementById(ObjErr).innerHTML = "<span class=\"result_error\"><br>Password must contain at least four characters.</span>";
			}
			if ( is_correct == true){
				document.getElementById(ObjID).focus();
				document.getElementById(ObjID).select();
				is_correct = false;
			}
		}
	}
	return is_correct;
}

function CheckInputBoxPassMatch(ObjID1 ,ObjID2 ,ObjErr ,is_correct){
	document.getElementById(ObjID2).className = 'inputbox';
	var ObjValue1 = Trim(document.getElementById(ObjID1).value);
	var ObjValue2 = Trim(document.getElementById(ObjID2).value);
	if ( ObjValue1 != ObjValue2) {
		document.getElementById(ObjID2).className = 'inputbox_error';
		document.getElementById(ObjErr).innerHTML = "<span class=\"result_error\"><br>Password mismatch.</span>";
		if ( is_correct == true){
			document.getElementById(ObjID2).focus();
			document.getElementById(ObjID2).select();
			is_correct = false;
		}
	}
	return is_correct;
}

function CheckInputBoxValid(ObjID,value_id,is_correct){
	document.getElementById(ObjID).className = 'inputbox';
	if ( Trim(document.getElementById(ObjID).value) == '' || Trim(document.getElementById(ObjID).value) == value_id)  {
		document.getElementById(ObjID).className = 'inputbox_error';
		if ( is_correct == true){
			document.getElementById(ObjID).focus();
			document.getElementById(ObjID).select();
			is_correct = false;
		}
	}
	return is_correct;
}

function CheckDropDownValid(ObjID,value_id, is_correct){
	document.getElementById(ObjID).className = 'dropdown';
	if ( Trim(document.getElementById(ObjID).options[document.getElementById(ObjID).selectedIndex].value) == value_id)  {
		document.getElementById(ObjID).className = 'dropdown_error';
		if ( is_correct == true){
			document.getElementById(ObjID).focus();
			is_correct = false;
		}
	}
	return is_correct;
}

function CheckNumberInputBoxValid(ObjID,isDecimal,isAddressNo,is_correct){
	document.getElementById(ObjID).className = 'inputbox';
	if (! isNumber(Trim(document.getElementById(ObjID).value),isDecimal,isAddressNo))  {
		document.getElementById(ObjID).className = 'inputbox_error';
		if ( is_correct == true){
			document.getElementById(ObjID).focus();
			document.getElementById(ObjID).select();
			is_correct = false;
		}
	}
	return is_correct;
}

function CheckEmailValid(ObjID,is_blank,is_correct) {
	document.getElementById(ObjID).className = 'inputbox';
	var ObjValue = Trim(document.getElementById(ObjID).value);
	var b = /^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/;
	//if ( (ObjValue.indexOf(".") < 2) || (ObjValue.indexOf("@") < 1) )  {
	if (!b.test(ObjValue)) {
		if (!(ObjValue == '' && is_blank)) {
			document.getElementById(ObjID).className = 'inputbox_error';
			if ( is_correct == true){
				document.getElementById(ObjID).focus();
				document.getElementById(ObjID).select();
				is_correct = false;
			}
		}
	}
	return is_correct;
}

function CheckRadioBtnAndDetail(RadioID, DetailID, DetailValue, is_correct) {
	document.getElementById(DetailID).className = 'inputbox';
	if ( document.getElementById(RadioID).checked  == true && (Trim(document.getElementById(DetailID).value) == DetailValue || Trim(document.getElementById(DetailID).value) == '')) {
		document.getElementById(DetailID).className = 'inputbox_error';
		if ( is_correct == true){
			document.getElementById(DetailID).focus();
			document.getElementById(DetailID).select();
			is_correct = false;
		}
	}
	return is_correct;
}

function CheckDropDownAndDetail(DropDownID, DetailID, DropDownValue, DetailValue, is_correct){
	document.getElementById(DetailID).className = 'inputbox';
	if ( (Trim(document.getElementById(DropDownID).options[document.getElementById(DropDownID).selectedIndex].value) == DropDownValue) && (Trim(document.getElementById(DetailID).value) == DetailValue || Trim(document.getElementById(DetailID).value) == ''))  {
		document.getElementById(DetailID).className = 'inputbox_error';
		if ( is_correct == true){
			document.getElementById(DetailID).focus();
			document.getElementById(DetailID).select();
			is_correct = false;
		}
	}
	return is_correct;
}

function WindowPopup(url,pagename,width,height){
	var winLeft = (screen.width-width)/2;
	var winTop = (screen.height-(height+110))/2;
	window.open(url,pagename,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left=' + winLeft + ',top=' + winTop + ',width=' + width + ',height=' + height + '');
}

function WindowPopupPreview(url,pagename,width,height){
	var winLeft = (screen.width-width)/2;
	var winTop = (screen.height-(height+110))/2;
	window.open(url,pagename,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,left=' + winLeft + ',top=' + winTop + ',width=' + width + ',height=' + height + '');
}
