

 var highlightedColor = "#BBD7FF"; //"#BFBFBF";
 var currentColor = "#E8F2F9"; //#DFDFDF; #dbeaf5;

function changeBgColor(obj) 
{
 	obj.style.backgroundColor = highlightedColor;
}

function restoreBgColor(obj) 
{
 	obj.style.backgroundColor = currentColor;
}

function changeMainMenuBgColor(obj) 
{
//alert("change");
	obj.style.background="url('../images/orange_blue_mouseOver.PNG') blue no-repeat";
}

function restoreMainMenuBgColor(obj) 
{
	obj.style.background="url('../images/orange_blue_inactive.PNG') blue no-repeat";
}

function showTable(id)
{
	document.getElementById(id).style.visibility='visible';
}
function hideTable(id)
{
	document.getElementById(id).style.visibility='hidden';
}

function onMainMenuClick(n)
{
//alert('onMainMenuClick '+n);

	n=parseInt(n);
/*	for(i=parseInt(n)-1;i>0;i--)
	{
		hideTable("SM"+i);
	}
*/
	for(i=1;i<=2;i++)
	{
		hideTable("SM"+i);
	}

	if (n > 0)
	{
		showTable("SM"+n);
	}
}

function radioChangedShowOnYes(obj, id1, id2, id3, id4, id5, id6)
{
	// if 'true' is checked, disply element 'id1'.  Else hide it.
		
    var dataValue = getCheckedValue(obj);
 //alert('radio value='+dataValue);
 	if (dataValue == "")
 	{
 		alert('this is not checked');
 		return;
 	}

	var element;
	if (dataValue == 1)
	{
		//alert('show '+ id1);

		showTR(id1);
		showTR(id2);
		showTR(id3);
		showTR(id4);
		showTR(id5);
		showTR(id6);
	}
	else
	{
		//alert('hide '+ id1);
		hideTR(id1);
		hideTR(id2);
		hideTR(id3);
		hideTR(id4);
		hideTR(id5);
		hideTR(id6);
	}		
}

function radioChangedShowAndHideTR(obj, showId1, showId2, showId3, hideId1, hideId2, hideId3)
{
	// if 'true' is checked, disply element 'showId1'.  Else hide it.
		
    var dataValue = getCheckedValue(obj);
 	//alert('radio value='+dataValue);
 	if (dataValue == "")
 	{
 		//alert('this is not checked');
 		return;
 	}
 	
	var element;
	if (dataValue == 1)
	{
		//alert('show '+ showId1);

		showTR(showId1);
		showTR(showId2);
		showTR(showId3);

		hideTR(hideId1);
		hideTR(hideId2);
		hideTR(hideId3);
	}
	else
	{
		//alert('hide '+ showId1);
		hideTR(showId1);
		hideTR(showId2);
		hideTR(showId3);
		
		showTR(hideId1);
		showTR(hideId2);
		showTR(hideId3);
	}		
}


function getCheckedValue(radioObj) 
{
	if(!radioObj)
	{
		return "";
	}
	
	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		if(radioObj.checked)
		{
			return radioObj.value;
		}
		else
		{
			return "";
		}
	}
	
	for(var i = 0; i < radioLength; i++) 
	{
		if(radioObj[i].checked) 
		{
			return radioObj[i].value;
		}
	}
	return "";
}


var listFormName = 'fListForm';
var listName = 'fList';
var checkboxName = 'chk';
var disabledCheckboxName = 'no-chk';

function checkAllCheckbox() 
{
	var idPrefix = listFormName + ':' + listName;
	var selAll = document.getElementById(idPrefix + ':checkAll');
	var startRow = 0;

	// alert('ele id = ' +idPrefix + '_' + startRow + ":" + checkboxName);

	var obj = document.getElementById(idPrefix + '_' + startRow + ":" + checkboxName);
	var disabledObj = document.getElementById(idPrefix + '_' + startRow + ":" + disabledCheckboxName);
	startRow++;


	for(obj; obj != null || disabledObj != null; startRow++) 
	{
		if (selAll.checked == true) 
		{
             if (obj != null)
             {
             	obj.checked = true;
             }
			// alert('check... ' +idPrefix + '_' + startRow + ":" + checkboxName);
     	}
     	else 
		{
			// alert('uncheck... ' +idPrefix + '_' + startRow + ":" + checkboxName);
             if (obj != null)
             {
             	obj.checked = false;
             }
         }
	     		
		// obj.disabled=false;
        obj = document.getElementById(idPrefix + '_' + startRow + ":" + checkboxName);
	 	disabledObj = document.getElementById(idPrefix + '_' + startRow + ":" + disabledCheckboxName);
	 	// alert('obj... ' + obj);
	 	// alert('disabledObj... ' + disabledObj);
    }
}

var editorFormName = 'formEditor';

function onDropDownChange(obj, otherTextId)
{
//	alert('obj.selectedIndex = '+obj.selectedIndex);
//	alert('otherTextId = '+otherTextId);
	if (obj.selectedIndex < 0)
	{
		return;
	}
    		
    var dataValue = obj.options[obj.selectedIndex].value;
//	alert('value = '+dataValue);
	var textObj = document.getElementById(editorFormName + ":" + otherTextId);
	if (dataValue < 0 )
	{
//	alert('set '+otherTextId + ' visible');
		textObj.style.visibility='visible';
	}
	else
	{
//	alert('set '+otherTextId + ' hidden');
		textObj.value='';
		textObj.style.visibility='hidden';
	}
}

function onDropDownChangeShowOnOtherTR(obj, id1)
{
//	alert('obj.selectedIndex = '+obj.selectedIndex);
//	alert('id1 = '+id1);
	if (obj.selectedIndex < 0)
	{
		return;
	}
    		
    var dataValue = obj.options[obj.selectedIndex].value;
//	alert('value = '+dataValue);
	if (dataValue < 0 )
	{
//	alert('show '+id1);
		showTR(id1);
	}
	else
	{
//	alert('hide '+id1);
		hideTR(id1);
	}
}

function reportTypeDropDownChange(obj, id1, promoRateId1, promoRateId2, promoRateId3, promoRateId4)
{
//	alert('obj.selectedIndex = '+obj.selectedIndex);
//	alert('id1 = '+id1);
	if (obj.selectedIndex < 0)
	{
		return;
	}
    		
    var dataValue = obj.options[obj.selectedIndex].value;
//	alert('value = '+dataValue);
	var element = document.getElementById(id1);
	var promoRateObj1 = document.getElementById(editorFormName + ":" + promoRateId1);
	var promoRateObj2 = document.getElementById(editorFormName + ":" + promoRateId2);
	var promoRateObj3 = document.getElementById(editorFormName + ":" + promoRateId3);
	var promoRateObj4 = document.getElementById(editorFormName + ":" + promoRateId4);
//		alert('promoRateObj1 '+ promoRateObj1);
	if (dataValue == 1)
	{
//		alert('show '+ element);
		if (element && element.style)
		{
			element.style.display = '';
		}		
	}
	else
	{
//		alert('hide '+ id1);
		if (element && element.style)
		{
			element.style.display = 'none';
		}		
	}
	
	if (dataValue == 2)	
	{
//	alert('set '+otherTextId + ' visible');
		if (promoRateObj1 && promoRateObj1.style)
		{
			promoRateObj1.style.visibility='visible';
		}
		if (promoRateObj2 && promoRateObj2.style)
		{
			promoRateObj2.style.visibility='visible';
		}
		if (promoRateObj3 && promoRateObj3.style)
		{
			promoRateObj3.style.visibility='visible';
		}
		if (promoRateObj4 && promoRateObj4.style)
		{
			promoRateObj4.style.visibility='visible';
		}
	}
	else
	{
//	alert('hidden promoRateObj ');
		if (promoRateObj1 && promoRateObj1.style)
		{
			promoRateObj1.style.visibility='hidden';
		}
		if (promoRateObj2 && promoRateObj2.style)
		{
			promoRateObj2.style.visibility='hidden';
		}
		if (promoRateObj3 && promoRateObj3.style)
		{
			promoRateObj3.style.visibility='hidden';
		}
		if (promoRateObj4 && promoRateObj4.style)
		{
			promoRateObj4.style.visibility='hidden';
		}
	}
				
}

function onCheckBoxChangeShowTR(obj, itemValue, id1) 
{
	if(obj && obj.value == itemValue)
	{
		if (obj.checked == true)
		{
			showTR(id1);
		}
		else 
		{
			hideTR(id1);
		}
	}
}

/*
function onEmpSettingCheckBoxChangeShowHideTR(obj, id1, idOther) 
{
	if (obj.value == 1)
	{
		if(obj && obj.checked == true)
		{
			showTR(id1);
		}
		else 
		{
			hideTR(id1);
		}
	}
	else if (obj.value == -1)
	{
		if(obj && obj.checked == true)
		{
			showTR(idOther);
		}
		else 
		{
			hideTR(idOther);
		}
	}		
}
*/

function showTR(id1) 
{
//	alert('show '+id1);
	var element = document.getElementById(id1);
	if (element && element.style)
	{
		element.style.display = '';
	}
}

function hideTR(id1) 
{
	var element = document.getElementById(id1);
//	alert('hide '+id1);
	if (element && element.style)
	{
		element.style.display = 'none';
	}
}

function checkboxIsSelected(checkboxGroup, boxValue) 
{
	// Go through all the check boxes. If the checkbox with value 'boxValue' is checked,
   	// return true.  else return false;
   	var retCode = false;
   	//alert('checkboxIsSelected checkboxGroup='+checkboxGroup +'length='+checkboxGroup.length);
   	if (checkboxGroup[0]) 
   	{ // if the button group is an array (one check box is not an array)
   		//alert('this is a array');
      	for (var i=0; i<checkboxGroup.length; i++) 
      	{
      		//alert('i = '+ i);
         	if (checkboxGroup[i].checked) 
         	{
      			//alert('this is checked. value='+checkboxGroup[i].value);
            	if (checkboxGroup[i].value == boxValue)
            	{
            		return true;
            	}
         	}
      	}
   	} 
   	else 
   	{ // There is only one check box (it's not an array)
   		//alert(' this is not a array');
      	if (checkboxGroup.checked) 
      	{ // if the one check box is checked
      		//alert('this is checked. value='+checkboxGroup.value);
         	if (checkboxGroup.value == boxValue)
         	{
         		retCode = true;
         	}
      	}
   	}
   	
   	return retCode;
} 
    
function checkBoxGroupChangeShowTR(checkboxGroup, boxValue, showId1) 
{
	//alert('checkBoxGroupChangeShowHideTR boxValue='+boxValue+' id='+showId1);
	if (checkboxIsSelected(checkboxGroup, boxValue))
	{
		//alert('show '+showId1);
		showTR(showId1);
	}
	else 
	{
		//alert('hide '+showId1);
		hideTR(showId1);
	}		
}

function radioIsSelected(radioGroup, itemValue) 
{
   	// Go through all the radio buttons. If the radio with value 'itemValue' is checked,
   	// return 1.  if no radio button is checked, return 0.  Else return 2.
   	var retCode = 0;
   	var itemChecked = false;
   	//alert('radioIsSelected radioGroup='+radioGroup +'length='+radioGroup.length);
   	if (radioGroup[0]) 
   	{ // if the button group is an array (one radio is not an array)
   		//alert('this is a array');
      	for (var i=0; i<radioGroup.length; i++) 
      	{
      		//alert('i = '+ i);
         	if (radioGroup[i].checked) 
         	{
         		itemChecked = true;
      			//alert('this is checked. value='+radioGroup[i].value);
            	if (radioGroup[i].value == itemValue)
            	{
            		return 1;
            	}
         	}
      	}
   	} 
   	else 
   	{ // There is only one radio (it's not an array)
   		//alert(' this is not a array');
      	if (radioGroup.checked) 
      	{ // if the one radio is checked
      		itemChecked = true;
      		//alert('this is checked. value='+radioGroup.value);
         	if (radioGroup.value == itemValue)
         	{
         		return 1;
         	}
      	}
   	}
   
	if (itemChecked)
   	{
   		retCode = 2;
   	}
   	
   	return retCode;
} 

function radioGroupShowHideTR(radioGroup, itemValue, showId1, showId2, showId3, hideId1, hideId2, hideId3) 
{
	//alert('radioGroupShowHideTR GroupLenght='+radioGroup.length+'itemValue='+itemValue+' id='+showId1);
	var radioCode = radioIsSelected(radioGroup, itemValue);
	if (radioCode == 1)
	{ // the radio with itemValue is checked.
		//alert('show '+showId1);
		showTR(showId1);
		showTR(showId2);
		showTR(showId3);
		
		hideTR(hideId1);
		hideTR(hideId2);
		hideTR(hideId3);		
	}
	else if (radioCode == 2)
	{ // the radio with itemValue is NOT checked.  But some other radios are.
		//alert('hide '+showId1);
		hideTR(showId1);
		hideTR(showId2);
		hideTR(showId3);

		showTR(hideId1);
		showTR(hideId2);
		showTR(hideId3);
	}		
	else 
	{ // no radio is checked.  Hide all.
		//alert('hide all');
		hideTR(showId1);
		hideTR(showId2);
		hideTR(showId3);
		
		hideTR(hideId1);
		hideTR(hideId2);
		hideTR(hideId3);		
	}	
}

function radioGroupShowTR(radioGroup, itemValue, showId1, showId2, showId3, showId4, showId5, showId6) 
{
	//alert('radioGroupShowTR GroupLenght='+radioGroup.length+' itemValue='+itemValue+' id='+showId1);
	var radioCode = radioIsSelected(radioGroup, itemValue);
	//alert('radioGroupShowTR radioCode='+radioCode);
	if (radioCode == 1)
	{ // the radio with itemValue is checked.
		//alert('show '+showId1);
		showTR(showId1);
		showTR(showId2);
		showTR(showId3);
		showTR(showId4);
		showTR(showId5);
		showTR(showId6);		
	}		
	else 
	{  	// no radio is checked.  Hide all.
		// Or the radio with itemValue is NOT checked.  But some other radios are.
		//alert('hide all');
		hideTR(showId1);
		hideTR(showId2);
		hideTR(showId3);		
		hideTR(showId4);
		hideTR(showId5);
		hideTR(showId6);		
	}	
}
