/*
	Program ID : cl_checkbox.js
	Description:
*/

/**
*   alternate check and uncheck state for specify object's parent;

*   @param object;
*   @return null.
*/
function changeChkStyle(obj){
	try{
	if(obj.checked){
		while(obj.tagName != "TR")	obj = obj.parentNode;
		temp=obj.className.split(" ");		
		obj.className = temp[0]+" row_checked";
//alert(obj.className);
	}
	else{
		while(obj.tagName != "TR")	obj = obj.parentNode;
		temp=obj.className.split(" ");
		obj.className = temp[0];
	//alert(obj.className);
	}
	}catch(e){}
}

/**
*   alternate select and unselect all special controls in specify form and change style;

*   @param object p_obj the current control;
*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function changeAll(p_obj,p_form,p_name) {
	if(p_obj.checked)
		chkAll(p_form,p_name);
	else 
		clsAll(p_form,p_name);
	
}

/**
*   select all  special controls in specify form  and change style;

*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function chkAll(p_form,p_name) {
	var frm = eval("document."+p_form);
	for(i=0;i<frm.elements.length;i++) {
	   if(frm.elements[i].name==p_name) {
			frm.elements[i].checked = true;
			changeChkStyle(frm.elements[i]);
		}
	}
}

/**
*   unselect all  special controls in specify form and change style ;

*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function clsAll(p_form,p_name) {
	var frm = eval("document."+p_form);
	for(i=0;i<frm.elements.length;i++) {
	   if(frm.elements[i].name==p_name) {
			frm.elements[i].checked = false;
			changeChkStyle(frm.elements[i]);
		}
	}
}

/**
*   select or unselect all special controls in specify form;

*   @param bool p_check if select 
*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function changeAll_1(p_check,p_form,p_name) {
	if(p_check)
		chkAll_1(p_form,p_name);
	else 
		clsAll_1(p_form,p_name);
}

/**
*   select all  special controls in specify form;

*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function chkAll_1(p_form,p_name) {
	var frm = eval("document."+p_form);
	for(i=0;i<frm.elements.length;i++) {
	   if(frm.elements[i].name==p_name) {
			frm.elements[i].checked = true;
		}
	}
}

/**
*   unselect all  special controls in specify form ;

*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return null.
*/
function clsAll_1(p_form,p_name) {
	var frm = eval("document."+p_form);
	for(i=0;i<frm.elements.length;i++) {
	   if(frm.elements[i].name==p_name) {
			frm.elements[i].checked = false;
		}
	}
}


/**
*   check if any control was selected in a form  ;

*   @param string p_form specify form;
*   @param string p_name name of the control,such as "Chk[]";
*   @return bool
*/
function chkSel(p_form,p_name) {
	var frm = eval("document."+p_form);
   var chk = false;
   for(var i=0;i<frm.elements.length;i++)  {
   	obj = frm.elements[i];
   	if(obj.name==p_name) {
   		if(obj.checked) {
   			chk = true;
   			break;
   		}
   	}
   }
	return chk;
}
function mouseOut(obj,p_form,p_id){
	try{
		var checkbox = eval("document."+p_form+"."+p_id);
		if(checkbox.checked) return false;
	} catch(e) {}
	obj.className = "TrUnChecked";
	return false;
}
function tr_mouseOut(obj,p_id){
	try{
		var checkbox = document.getElementById(p_id);
		if(checkbox.checked || obj.className=="row_operate" || obj.className=="row_invalid") return false;
	} catch(e) {}
	obj.className = "row_normal";
	return false;
}
function tr_mouseOver(obj,p_id){
	try{
		var checkbox = document.getElementById(p_id);
		if(checkbox.checked || obj.className=="row_operate" || obj.className=="row_invalid") return false;
	} catch(e) {}
	obj.className = "row_hover";
	return false;
}
var temp_color = "";

/**
*   change backgroundColor to "#ffffcc" when onMouseOver  ;

*   @param object p_obj specify object;
*   @return null
*/
function onMouseOverAction(p_obj){
	temp_color = p_obj.style.backgroundColor;
	p_obj.style.backgroundColor = "#ffffcc";
}

/**
*   revert normal backgroundColor when onMouseOut  ;

*   @param object p_obj specify object;
*   @return null
*/
function onMouseOutAction(p_obj){
	p_obj.style.backgroundColor = temp_color;
} 
