/**
 * Sets/unsets the pointer in browse mode
 *
 * @param   object   the table row
 * @param   object   the color to use for this row
 */
function Set_Pointer(objRow, objClassName)
{
    if (typeof(objRow.style) == 'undefined' || typeof(objRow.cells) == 'undefined') {
        return false;
    }
	var row_cells_cnt = objRow.cells.length;
    for (var c = 0; c < row_cells_cnt; c++) {
        objRow.cells[c].className = objClassName;
    }

    return true;
} // end of the 'Set_Pointer()' function


/**
 * Check/Uncheck/Invert selection on checkbox
 *
 * @param   string   the type of action
 */
function Check_Action(strAct) {
	var obj_len = document.getElementsByName("chkSelectedRow[]").length;
	switch(strAct) {
	case "All":
		for(i=0;i<obj_len;i++) {
			document.getElementsByName("chkSelectedRow[]")[i].checked = true;
		}
		break;
	case "Not":
		for(i=0;i<obj_len;i++) {
			document.getElementsByName("chkSelectedRow[]")[i].checked = false;
		}
		break;
	case "Inv":
		for(i=0;i<obj_len;i++) {
			document.getElementsByName("chkSelectedRow[]")[i].checked = !document.getElementsByName("chkSelectedRow[]")[i].checked;
		}
		break;
	}
} // end of the 'Check_Action()' function

/**
 * Check/Uncheck checkbox on corresponding table row
 *
 * @param   integer   the corresponding table row
 */
function Check_Row(i) {
	document.getElementsByName("chkSelectedRow[]")[i].checked = !document.getElementsByName("chkSelectedRow[]")[i].checked;
} // end of the 'Check_Row()' function

/**
 * Check at least one row is selected
 *
 * @param   string   the type of action
 *
 * @return  boolean  whether pointer is set or not
 */
function Check_Selected() {
	var obj_len = document.getElementsByName("chkSelectedRow[]").length;

	for (i=0;i<obj_len;i++) {
		if (document.getElementsByName("chkSelectedRow[]")[i].checked == true) { return true; }
	}
	alert("Error !\nCheck at least\none row before action.");
	return false;
}

/**
 * Check whether the obj Value is blank
 *
 * @param   string   the object
 * @param   string   message to show
 *
 * @return  boolean  whether obj value is empty or not
 *
 * Usage:
 */
function Is_Email_Valid(sEmail){
	var MailAddrPattern = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	var arMatch = sEmail.match(MailAddrPattern);
	if(arMatch==null)
		return false;
	else
		return true;
}

/**
 * Check whether the obj Value is blank
 *
 * @param   string   the object
 * @param   string   message to show
 *
 * @return  boolean  whether obj value is empty or not
 *
 * Usage: onkeypress="javascript:NumberOnly(event.which)"
 *
 * Note: 8 = Backspace, 9 = Tab, 13 = Enter, 48...57 = 0...9, 190 = .
*              0 = Tab (NS only)
 */
function Number_Only(k){
	return (k==8 || k==0 || k==13 || (k>=48 && k<=57) || k==46 || k==190);
}

function trim(text) {
  // Erase blank in the most left and most right sections of a string
  var i,j;
  for(i=0; text.charAt(i)==' ' && i<text.length; i++){}
  if(i==text.length) return ''
  for(j=text.length-1; text.charAt(j)==' ' && j>-1; j--){}
  return text.substring(i,j+1);
}
