// Input: one parameters
function _ISD_UI_List_clickHeader(ctrlChk)
{
	ctrlChk = _ISD_UI_EnsureObject(ctrlChk);
	if (ctrlChk)
	{
		var chkList = _ISD_UI_EnsureObject(ctrlChk.children);
		var chk = ('checkbox' == ctrlChk.type) ? ctrlChk : chkList.item[0]; 
		chk = _ISD_UI_EnsureObject(chk);
		if (chk)
		{
			var xState = chk.checked;
			var itemList = chk.form.elements;
			if(itemList.length)
			{
				for(i=0; i < itemList.length; i++)
				{
					if('checkbox' == itemList[i].type && !itemList[i].disabled && chk.id != itemList[i].id)
					{
						if(xState != itemList[i].checked)
							itemList[i].click();
					}
				}
			}
		}	
	}
}

function _ISD_UI_List_clickItem(ctrlChk, rowState)
{
	ctrlChk = _ISD_UI_EnsureObject(ctrlChk);
	if (ctrlChk)
	{
		var ctrlRow = _ISD_UI_getFirstParent(ctrlChk, "TR");
		if (ctrlRow)
			ctrlRow.className = (ctrlChk.checked) ? 'highligh_ListSytle' : ('Alternate' != rowState) ? 'tr_ListStyle' : 'atr_ListStyle'; // TODO: use rowState to choose the normal style properly
		
/*	var itemChecked = _ISD_UI_List_recordChecked(ctrlChk);	// resest check all 
		if (!itemChecked)
		{
			var chkParent = _ISD_UI_getParentCheckbox(ctrlChk);
			if (chkParent)
				chkParent.checked = false;
		}
*/			
	}
}

function _ISD_UI_List_apply(ctrlApply)
{
	var ret = false;
	
	var index = _ISD_UI_getIndex(ctrlApply);
	if (-1 != index) 
	{
		var ctrlFunc = ctrlApply.form.elements[index-1]; // check for a function
		if (ctrlFunc)
		{
			if ('' == ctrlFunc.value)
			{
				//alert('select a function !');	
				if ('- - Select - -' == ctrlFunc.options[0].text)
					alert('select function !');
				else
					alert('\u0625\u062E\u062A\u0631 \u0648\u0638\u064A\u0641\u0647 !'); 
				ctrlFunc.focus();
				
				return ret;
			}
		}

		var recordChecked = _ISD_UI_List_recordChecked(ctrlApply);
		if (!recordChecked)
		{
			//alert('select item !');	
			if ('- - Select - -' == ctrlFunc.options[0].text)
				alert('check item !'); 
			else
				alert('\u0625\u062E\u062A\u0631 \u0639\u0646\u0635\u0631 !'); 
		}
		else
			ret = true;
	}
	else
		alert('function list is not found !');	
	
	if (ret)
	{
		var str = '';
		if ('- - Select - -' == ctrlFunc.options[0].text)
			str = 'Are you sure ?'; 
		else
			str = '\u0647\u0644 \u0623\u0646\u062A \u0645\u062A\u0623\u0643\u062F ?';
		ret = confirm(str);		
		//ret = confirm("Are you sure ?");	
	}	
	return ret;	
}

function _ISD_UI_List_add(ctrlAdd)
{
	return true;	
}

function _ISD_UI_List_backToList(ctrlBackToList)
{
	return true;	
}

function _ISD_UI_List_recordChecked(ctrl)
{
	var ret = false;
	
	ctrl = _ISD_UI_EnsureObject(ctrl);
	if (ctrl)
	{
		var itemList = ctrl.form.elements;
		if(itemList.length)
		{
			for(i=0; i < itemList.length; i++)
			{
				if(!ret && 'checkbox' == itemList[i].type && !itemList[i].disabled && (-1 == itemList[i].name.indexOf("chkList")))
				{
					if(itemList[i].checked)
						ret = true;
				}
			}
		}
	}	
	return ret;
}

function _ISD_UI_getParentCheckbox(ctrl)
{
	var ret = null;
	var itemList = ctrl.form.elements;
	for(i=0; i < itemList.length; i++)
	{
		if (itemList[i].type == 'checkbox' && (-1 != itemList[i].name.indexOf("chkList")))
			return itemList[i];
	}
		
	return ret;
}

