/*
	Javascript Function :
		HTML object Related Functions
		
	Index :
		
		Check Box Functions :
			1. IsCheckBoxChecked(CheckBox)										- Check the checkbox status i.e. checked or not (for non-array checkbox)
			2. CheckBoxArray_All(FormName, CheckBox, thisStatus)				- Change all checkbox array to CHECKED / UNCHECKED
			3. CheckBoxArray_Count(FormName, CheckBoxName)						- Count how many checkbox is checked in the checkbox array
			4. getCheckBoxItem(FormName, CheckBoxName) 							- get checked item in list 
			
		Combo Box Functions :
			1. CountComboSelected(combobox)										- Count no. of selected items in combo box
			2. funUnSelectAll(combobox)											- Un-select all items in combo box
			3. funSelectAll(combobox)											- select all items in combobox
			
		Radio Button Functions :
			1. Clicked_Radio(RadioBtn)											- check whether one of the radio button array is clicked. if yes, return true
			
		Text Box Functions :
			1. highlight_textbox(thisField)										- highlight textbox
			2. copy_to_clipboard(thisField)										- copy content to clipboard
			
		Misc Functions :
			1. getTextAreaLine(thisObj)											- get content from Text area
			2. to_show_html_object(thisHTML_OBJ_NAME, thisTo_display)			- display or hidden the specified html object
			3. toggle_html_show_status(thisHTML_OBJ_NAME)						- toggle the html object display state. 
			4. set_html_content(thisHTML_OBJ_NAME, thisContent)					- assign content (i.e. string) to a specified html object
*/

/***********************************************************
 Combo Box Function
***********************************************************/
// Count no. of selected items in combo box
function CountComboSelected(combobox) {
	k = 0;
	for(i=0;i<combobox.length;i++) {
		if (combobox.options[i].selected) {
			k++;
		}
	}
	return k;
}

// Un-select all items in combo box
function funUnSelectAll(combobox) {
	combobox.selectedIndex = -1;
}

// select all items in combobox
function funSelectAll(combobox) {
	for(i=0;i<combobox.length;i++) {
		combobox.options[i].selected = true;
	}
}
/***********************************************************
 End of Combo Box Function
***********************************************************/



/***********************************************************
 Check Box Function
***********************************************************/
// Check the checkbox status i.e. checked or not (for non-array checkbox)
// Parameter : 	CheckBox - HTML checkbox object which is in array
function IsCheckBoxChecked(CheckBox) {	
	if (CheckBox.checked)
		return true;
	else
		return false;
}

// Change all checkbox array to CHECKED / UNCHECKED
// Parameter : 	FormName - the form name of the checkbox array placed in.
//				CheckBoxName - HTML checkbox object which is in array
//				status	- the changed status (true / false)
function CheckBoxArray_All(FormName, CheckBox, thisStatus) {
	myCheckboxArray = document.forms[FormName].elements[CheckBoxName];
	
	for(i=0;i<myCheckboxArray.length;i++) {
		myCheckboxArray[i].checked = thisStatus;
	}
}

// Count how many checkbox is checked in the checkbox array
// Parameter : 	FormName - the form name of the checkbox array placed in.
//				CheckBoxName - the checkbox name 
// example : CheckBoxArray_Count('frmCustomer', 'chkUser_ID[]')
function CheckBoxArray_Count(FormName, CheckBoxName) {
	count = 0;
	
	myCheckboxArray = document.forms[FormName].elements[CheckBoxName];
	
	if (!(myCheckboxArray.length >= 0)) {
		if (myCheckboxArray.checked) count++;
		return count;
	} else {
		//	If there is only one entry in the page, the CheckBox.length is undefined.
		for (i=0; i<myCheckboxArray.length; i++) { 
		    if (myCheckboxArray[i].checked) 
	    		count++;
		}	 
		return count;
	}
}

// get checked item in list 
// e.g. 1,2,3
function getCheckBoxItem(FormName, CheckBoxName) {
	myCheckboxArray = document.forms[FormName].elements[CheckBoxName];
	list ='';
	count=0;
	
	if (!(myCheckboxArray.length >= 0)) {
		if (myCheckboxArray.checked) 
			return myCheckboxArray.value;
	} else {	
		for (i=0; i<myCheckboxArray.length; i++) { 
		    if (myCheckboxArray[i].checked) 
	    		list = list + myCheckboxArray[i].value + ',';
		}		
		list = Left(list, (String(list).length-1));
		return list;
	}
}
/***********************************************************
 End of Check Box Function
***********************************************************/


/***********************************************************
 Radio Button Function
***********************************************************/
// check whether one of the radio button array is clicked. if yes, return true
function Clicked_Radio(RadioBtn) {
	for(var i=0; i<RadioBtn.length; i++) {
		if (RadioBtn[i].checked) {
			return true;
		}
	}
	return false;
}
/***********************************************************
 End of Radio Button Function
***********************************************************/


/***********************************************************
 Text Box Function
***********************************************************/
// highlight textbox
function highlight_textbox(thisField) {
	var tempval = eval("document."+thisField);
	tempval.focus();
	tempval.select();
}

// copy content to clipboard
function copy_to_clipboard(thisField) {
	var tempval = eval("document."+thisField);
	tempval.focus();
	tempval.select();
	therange=tempval.createTextRange();
	therange.execCommand("Copy");	
}
/***********************************************************
 End of Text Box Function
***********************************************************/


/***********************************************************
 Misc Function
***********************************************************/
// get content from Text area
function getTextAreaLine(thisObj) {
	var intLine = 0;

	with(thisObj){
		if (value.length <= 0) return intLine;
		for (var i=0; i < value.length; i++) {
			if (value.charCodeAt(i)==13) {
				intLine++;
			}		
		} 
		return intLine;
	}
}

// display or hidden the specified html object
// parameter : 	thisHTML_OBJ_NAME - html object name e.g. 'txtUsername'
//				thisTo_display - true / false (true - display object) (false - hidden object)
function to_show_html_object(thisHTML_OBJ_NAME, thisTo_display) {
	if(document.getElementById) {
		var el = document.getElementById(thisHTML_OBJ_NAME);
		if (thisTo_display)
			el.style.display = 'block';
		else
			el.style.display = 'none';
	}
}

// toggle the html object display state. 
// if current html object is "hidden" to user, then it will be "shown" to user.
function toggle_html_show_status(thisHTML_OBJ_NAME) {
	if(document.getElementById){
		var el = document.getElementById(thisHTML_OBJ_NAME);
		el.style.display = (el.style.display == 'none') ? 'block' : 'none'; 
	}	
}

// assign content (i.e. string) to a specified html object
function set_html_content(thisHTML_OBJ_NAME, thisContent) {
	document.getElementById(thisHTML_OBJ_NAME).innerHTML = thisContent;
}
/***********************************************************
 End of Misc Function
***********************************************************/
