var mastrMenuCollection=new Array();
var mastrSubMenuCollection=new Array();
//<<<css used by table control
var CssMouseHoverTextCell="ELLISMouseHoverTEXTCELL";
var CssMouseHoverDDCell="ELLISMouseHoverDDCELL";
var CssMouseHoveMenuItem="ELLISMouseHoverMenuItem";
var CssMouseHoveGroupName="ELLISMouseHoverGroupName";
var CssMouseHoverUnderLine="ELLISMouseHoverUnderLineTEXTCELL";
var CssMouseHoverMenuItem_HavingSubMenu="ELLISMouseHoverMenuItem_HavingSubMenu";
//<<<global variables used by control..mainly to store class names
var mstrClassName;
var mstrDDClass;
var mstrOpenMenuCell;
var mobjClosePreviousSelected=null;
//<<for Record Mouse move class names
var mstrRecordClassName;
var mstrRecordDDClass;
var mobjSelectedDDImgCell=null;
//<<<array used to store selected item
var mastrSelected=new Array();
mastrSelected[0]=null;
mastrSelected[1]=null;
mastrSelected[2]=null;
mastrSelected[3]=null;
mastrSelected[4]=null;
//<<<array to store group name
var mastrGroupName=new Array();
mastrGroupName[0]=null;
mastrGroupName[1]=null;
//<<<to check seelcted record 
var objSubmition=false;
var strRecordSelected="NO";

//<<<to trim the text..commonm function
function trim(str)
{return str.replace(/^\s*|\s*$/g,"");}

//window.document.captureEvents(Event.CLICK);	
document.onclick=fnCloseWebIuTableControlMenu;
//<<<to set all css classes of control item
function fnLoadCssForControl(strCssMouseHoverTextCell, strCssMouseHoverDDCell, strCssMouseHoveMenuItem,strCssMouseHoveGroupName,strCssMouseHoverUnderLine, strCssMouseHoverMenuItem_HavingSubMenu)
{
	if (trim(strCssMouseHoverTextCell) != "")
	{	CssMouseHoverTextCell = strCssMouseHoverTextCell}
	
	if (trim(strCssMouseHoverDDCell) != "")
	{	CssMouseHoverDDCell = strCssMouseHoverDDCell}
	
	if (trim(strCssMouseHoveMenuItem)!="")
	{	CssMouseHoveMenuItem=strCssMouseHoveMenuItem}
	
	if (trim(strCssMouseHoveGroupName)!="")
	{	CssMouseHoveGroupName=strCssMouseHoveGroupName}
	
	if (trim(strCssMouseHoverUnderLine)!="")
	{	CssMouseHoverUnderLine=strCssMouseHoverUnderLine}
	
	if (trim(strCssMouseHoverMenuItem_HavingSubMenu)!="")
	{	CssMouseHoverMenuItem_HavingSubMenu=strCssMouseHoverMenuItem_HavingSubMenu}
}
//<<close menu obj
function fnCloseMe(obj)
{
	obj.style.display='none';	//<<<hide current item
	fnClosePreviousSection();//<<close previous menu item	
	fnSetOriginalStyleOnPreviousSelection();	//<<<set original styles to previous menu item
	mobjSelectedDDImgCell=null;	//<<<set object null for previoous item
}

//*********below section is to hide and unhide the header drop img but right now, hide function  is off
//<<<dont delete this function ..can be usefull in future..
//<<to show and hide drop down image of control main header 
function fnControlHeaderMouseOver(objcell,objimg,objDDcell)//<<<very imprortant function to hide ..unhide
{	//<<Not in use...img remains Unhide
	//objimg.style.visibility="visible";	
}
function fnControlHeaderMouseOut(objcell,objimg,objDDcell)
{
	if (mstrOpenMenuCell==objDDcell.id)
	{
		mobjClosePreviousSelected=objimg;
		return;
	}
	//<<not in Use...img remains Unhide...very imprortant function 
	//objimg.style.visibility="hidden"; 
}
//<<<<<XXX

//<<for header menu..<<<to show the menu for header of a column having common containt..like..sort and group
function fnShowMenu(objmenu,objControl,objThis)
{	
	var strHide;
	var objBody;
	var strInsideBody;
	
	mobjSelectedDDImgCell=null;//fnCloseAllMenu();//return;
		//<<set visible true or false
		if (objmenu.style.display=='none')
		{		
			//<<store in array
			fnStoreMenuInArray(objmenu.id);				
			fnCloseAllMenu();
			strHide='no';
			objmenu.style.display='block';	
		}
		else if (objmenu.style.display=='block')
		{	strHide='yes';
			objmenu.style.display='none';
		}
	//<<<check if menu is direct in menu tag..manu should me in body tag ..to get coorect location
		 strInsideBody = objmenu.getAttribute("INSIDE_BODY");
		if (strInsideBody == "yes")
		{	
			fnSetLocation(objControl.id,objmenu);
			if (strHide=='no')
			{	objmenu.style.display='block';
			}
			else
			{	objmenu.style.display='none';	}
			
			fnClosePreviousSection();				
			fnSetOriginalStyleOnPreviousSelection();				
			mstrOpenMenuCell=objControl.id;				
			return;
		}
		//<<append the item to body tag,nessarry to get location
		 objBody=document.getElementsByTagName("body")[0];
		
		//objColorPicker.style.width='150px';
		//objColorPicker.style.height='150px';
		objBody.appendChild(objmenu); 
		
		objmenu.setAttribute("INSIDE_BODY","yes");

		objmenu.style.position='absolute';

		fnSetLocation(objControl.id,objmenu);
		
		objmenu.style.zIndex='215';
		//objmenu.style.display='block';
		//<<store control id in string
		fnClosePreviousSection();
		fnSetOriginalStyleOnPreviousSelection();
		mstrOpenMenuCell=objControl.id;
}
//<<to set the location of item for column header <<<used by above function called "fnShowMenu()"
function fnSetLocation(strLocationToFit,divTest)
{
	var objTemp;
	var lngLeftPos;
	var lngTopPos;
	var lngWidth;
	var objTextCell;
	lngLeftPos = 0;
	lngTopPos = 0;

	//<<get object
	objAttachecControl = fnGetObject(strLocationToFit);

	objTextCell = fnGetObject(strLocationToFit.replace("_DDIMGCELL",""));	

	objTemp = objAttachecControl;
	lngLeftPos=objTemp.offsetLeft;
	lngWidth=objTemp.offsetWidth;
	//<<<Set location
	do 
	{
		objTemp = objTemp.offsetParent;
		//lngLeftPos += objTemp.offsetLeft;		
		//lngTopPos += objTemp.offsetTop;	 //for nonscrollable parent div aor form
		lngLeftPos += objTemp.offsetLeft -objTemp.scrollLeft;		
		lngTopPos += objTemp.offsetTop-objTemp.scrollTop; ///for scrollable parent div or form

	} while(objTemp.tagName != "BODY");


	lngLeftPos=lngLeftPos+lngWidth-divTest.offsetWidth;

		
	if (fnOpera()==true || fnSafari()==true)
	{	
		
		lngTopPos -= objAttachecControl.offsetParent.scrollTop;	
		lngTopPos = lngTopPos+9;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight - 3 );
		lngLeftPos = lngLeftPos;
	}
	else
	{
		lngTopPos -= objAttachecControl.parentNode.scrollTop;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight -1 );
	}

	divTest.style.left = lngLeftPos;
	
	//<<to change location of menu
	if (divTest.offsetWidth>objTextCell.offsetWidth+objAttachecControl.offsetWidth)
	{
		//divTest.style.left = lngLeftPos + divTest.offsetWidth - objAttachecControl.offsetWidth - objTextCell.offsetWidth;
		//divTest.style.left =( lngLeftPos + objAttachecControl.offsetWidth + objTextCell.offsetWidth) - divTest.offsetWidth ;
	}
	divTest.style.zIndex='105';
	
	divTest.style.display = 'block';
	
	//divTest.style.display = 'table-row';
	/*try
	{	divTest.focus();		}
	catch (e){}*/
	blnDisplay = true;
}
//****for column and row menu
//*******
//****
////<<<<<<<,XXXXXX
//<<to show and hide drop down image , for column header
function fnShowDropDownMenu(objcell,objimg,objDDcell)
{	
	//alert('ramesh');
	//<<check menu is already open
	if (mobjSelectedDDImgCell!=null)
	{	
		//<<menu is not of same row
		if (mobjSelectedDDImgCell.id!=objDDcell.id)
		{	
			mstrRecordClassName=objcell.className;
			mstrRecordDDClass=objDDcell.className;
			objcell.className=CssMouseHoverUnderLine;
			return;
		}
	}
	//*****menu is not open
	mstrRecordClassName=objcell.className;
	mstrRecordDDClass=objDDcell.className;
	//<<save class name
	//mstrClassName=objcell.className;
	//mstrDDClass=objDDcell.className;
	objimg.style.visibility="visible";
	//change the css to selected css
	objcell.className=CssMouseHoverTextCell;
	objDDcell.className=CssMouseHoverDDCell;
	//mstrRecordClassName
	//<<store cell and original css
}
function fnHideDropDownMenu(objcell,objimg,objDDcell)
{	
	if (mobjSelectedDDImgCell!=null)
	{	if (mobjSelectedDDImgCell.id==objDDcell.id)
		{return;
		}
	}
		
	objimg.style.visibility="hidden";
	//<<change css to original one
	//objcell.className=mstrClassName;
	//objDDcell.className=mstrDDClass;
	objcell.className=mstrRecordClassName;
	objDDcell.className=mstrRecordDDClass;
	
}
//<<<<<<function to set the menu items disabled and enabled according to the rights provided in textfields
function fnSetMenuAccordingToRights(objMenu)
	{
			var strRightsOfSelectedRow;
			var intMenuCount;
			var intMenuCount
			var objRightsTextField;
			var objSelectedRow;
			var strSelectedRow;
			var strRows_Rights;
			var astrRows;
			var intC;
			var strTemp;
			var aobjMenuItems;
			var strTempMenu;

			strRightsOfSelectedRow = '';
			//<<<GET textfields having rights ids
			objRightsTextField = fnGetObject('control_rights');
			objSelectedRow = fnGetObject('control_rowid');
			
			if (objRightsTextField==null)
			{
				//alert("For developers - Please Add two textBoxes named 'control_rowid' , 'control_rowid_colid' and 'control_rights' to use this control effectively");
				return;
			}
			if (objSelectedRow==null)
			{
				//alert("For developers - Please Add two textBoxes named 'control_rowid' , 'control_rowid_colid' and 'control_rights' to use this control effectively");
				return;
			}
			//<<<example:::	SC10_SITE_ST1~VIEW_DETAIL@SC11_SITE_ST1~EDIT~VIEW_DETAIL
			strSelectedRow = objSelectedRow.value;
			strRows_Rights = objRightsTextField.value;
			//alert('strSelectedRow' + strSelectedRow);
			//alert('strRows_Rights' + strRows_Rights);
			///<<split rows with rights
				astrRows = strRows_Rights.split('@');
				
				for (intC=0; intC < astrRows.length ;intC++ )
				{	
					//<<find selected rows rights
					strTemp = astrRows[intC];
					//alert('strTemp' + strTemp);
					var astrTemp1 = strTemp.split('~');
					var strText = astrTemp1[0];
					if (strText == strSelectedRow)
					{		strRightsOfSelectedRow = strTemp;
							break;
					}
					/*if (strTemp.indexOf(strSelectedRow)!=-1)
					{
							///astrRightsOfSelectedRow=strTemp.split('~');
							strRightsOfSelectedRow=strTemp;
							break;
					}*/
				}
				//<<cut the row id
				//alert(strRightsOfSelectedRow);
				strRightsOfSelectedRow = strRightsOfSelectedRow.replace(strSelectedRow,'')
				strRightsOfSelectedRow = '~' + strRightsOfSelectedRow + '~'
				strRightsOfSelectedRow = strRightsOfSelectedRow.replace('~~','~')
				//<<find out menus items
				aobjMenuItems = objMenu.getElementsByTagName('a');

				if (aobjMenuItems != null)
				{//<<for each menu item
					for (intMenuCount = 0; intMenuCount < aobjMenuItems.length ;intMenuCount++ )
					{		
							//<<get item id
							strTempMenu = aobjMenuItems[intMenuCount].getAttribute('ITEMID');

							//alert(strTempMenu);
							//alert(strRightsOfSelectedRow);

							if (strRightsOfSelectedRow.indexOf(strTempMenu)!=-1)
							{									
								if (aobjMenuItems[intMenuCount].disabled != true)
								{
									aobjMenuItems[intMenuCount].disabled = true;
									aobjMenuItems[intMenuCount].onclick = function(){return false;}

									//alert(aobjMenuItems[intMenuCount].style.color);
									aobjMenuItems[intMenuCount].setAttribute("CLR",aobjMenuItems[intMenuCount].style.color);
									//aobjMenuItems[intMenuCount].style.textDecoration='line-through';
									aobjMenuItems[intMenuCount].style.color='gray';
								}								
							}
							else
							{	
								if (aobjMenuItems[intMenuCount].disabled != false)
								{
									aobjMenuItems[intMenuCount].disabled = false;
									aobjMenuItems[intMenuCount].onclick = null;
									aobjMenuItems[intMenuCount].style.color = aobjMenuItems[intMenuCount].getAttribute("CLR");
									//aobjMenuItems[intMenuCount].style.textDecoration='underline';
								}
							}
					}
				}
	}

//<<show options menu under column-row  items
function fnShowColumnMenu(objmenu,objControl,objThis)
{	
	//alert(objControl);
	//alert(objThis);
	var objTempImg;	
	var strShow="NO";
	var strHide;
	var strInsideBody;
	//alert(objmenu);
	//<<get drom down image object
	objTempImg=fnGetObject(objThis.id + '_IMG');
	if (mobjSelectedDDImgCell != null)	
		{
			if (mobjSelectedDDImgCell.id==objControl.id)	
			{return;}
			else
			{	objTempImg.style.visibility="visible";
				//change the css to selected css
				objThis.className = CssMouseHoverTextCell;
				objControl.className = CssMouseHoverDDCell;
			}
		}
		
		fnSetOriginalStyleOnPreviousSelection();
		mastrSelected[0]=objThis;
		mastrSelected[1]=objControl;
		mastrSelected[2]=mstrRecordClassName;
		mastrSelected[3]=mstrRecordDDClass;
		//objTempImg=document.all[objThis.id + '_IMG'];
		if (objTempImg!=null)
		{mastrSelected[4]=objTempImg;	}

	//<<if menu is selected
	//if (mobjSelectedDDImgCell!=null)
	//{//<<if menu is of same column
	//	if (mobjSelectedDDImgCell.id==objControl.id)
	//	{	return;	}
	//}
		strColId=objThis.getAttribute("COLID");
		strRowId=objThis.getAttribute("ROWID");		
		fnSetSelectedData(strRowId,strColId);
		
		//<<set visible true or false
		//alert('before');
			fnSetMenuAccordingToRights(objmenu);
		//alert('after');
		//<<store in array
		fnStoreMenuInArray(objmenu.id);
		fnCloseAllMenu();
		strHide='no';
		objmenu.style.display='block';
		
		strInsideBody=objmenu.getAttribute("INSIDE_BODY");

		if (strInsideBody=="yes")
		{	
			fnSetColumnMenuLocation(objControl.id,objmenu);
			/*if (strHide=='no')
			{	objmenu.style.display='block';	}
			else
			{	objmenu.style.display='none';	}
			//<<save the control in array
			//fnSetOriginalStyleOnSelection();
			//mastrSelected[1]=objControl;
			///mastrSelected[0]=objThis;*/			
			fnClosePreviousSection();
			mobjSelectedDDImgCell=objControl;
			return;
		}
		
		//<<<move menu inside body tag
		fnMoveObjectDirectUnderBodyTag(objmenu);
		///****OLD CODE***before using****fnMoveObjectDirectUnderBodyTag////
		/*//<<append color picker to body tag
		var objBody=document.getElementsByTagName("body")[0];
		//objColorPicker.style.width='150px';
		//objColorPicker.style.height='150px';
		objmenu.style.position='absolute';
		objBody.appendChild(objmenu);
		objmenu.setAttribute("INSIDE_BODY","yes");*/
		//<<set location of color picker
		fnSetColumnMenuLocation(objControl.id,objmenu);
		objmenu.style.zIndex='210';
		//<<save the control in array
		//fnSetOriginalStyleOnSelection();
		//mastrSelected[1]=objControl;
		//mastrSelected[0]=objThis;
		fnClosePreviousSection();
		mobjSelectedDDImgCell=objControl;

}
function fnIE()
{
	var detect;
	try
	{	detect = navigator.userAgent.toLowerCase();			}
	catch (e){	}
	if (checkIt(detect,'msie')) 
		{	return true;	}
	return false;

}
function fnOpera()
{	var detect;
	try
	{	detect = navigator.userAgent.toLowerCase();			}
	catch (e){	}
	if (checkIt(detect,'opera')) 
		{	return true;	}
	return false;
}
function fnSafari()
{	var detect;
	try
	{	detect = navigator.userAgent.toLowerCase();			}
	catch (e){	}
	if (checkIt(detect,'safari')) 
		{	return true;	}
	return false;
}
function fnMozilla()
{	var detect;
	try
	{	detect = navigator.userAgent.toLowerCase();			}
	catch (e){	}
	
	if (checkIt(detect,'mozilla')) 
		{	return true;	}
	return false;
}

//<<<set location for item ..used by above function called "fnShowColumnMenu"
function fnSetColumnMenuLocation(strLocationToFit,divTest)
{	
	//alert('jsControlMenu');
	var intMenuLocation;
	var intWindowHeight;
	var objTemp;
	var lngLeftPos;
	var lngTopPos;
	
	lngLeftPos = 0;
	lngTopPos = 0;
	objAttachecControl = fnGetObject(strLocationToFit);
	objTextCell = fnGetObject(strLocationToFit.replace("_DDIMGCELL",""));

	objTemp = objAttachecControl;
	lngLeftPos=objTemp.offsetLeft;
	lngTopPos=objTemp.offsetTop;
	lngWidth=objTemp.offsetWidth;
	
	do 
	{
		//alert(objTemp.offsetParent.offsetTop);
		objTemp = objTemp.offsetParent;
		//lngLeftPos += objTemp.offsetLeft;		
		//lngTopPos += objTemp.offsetTop; 
		lngLeftPos += objTemp.offsetLeft -objTemp.scrollLeft;//for nonscrollable parent div aor form
		lngTopPos += objTemp.offsetTop-objTemp.scrollTop; ///for scrollable parent div or form
	} while(objTemp.tagName != "BODY");

 	lngLeftPos=lngLeftPos+lngWidth-divTest.offsetWidth;

	if (fnSafari()==true)
	{	
		//alert('safariiiiiiiii');
		lngTopPos -= objAttachecControl.offsetParent.scrollTop;
		lngTopPos =lngTopPos+11;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight -3) ;	
		if(objSubmition==true)
			{divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight -10);}
	}
	else if (fnOpera()==true)
	{	
		lngTopPos -= objAttachecControl.offsetParent.scrollTop;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight - 3) ;	
		lngLeftPos=lngLeftPos-5;
	}
	else
	{	
		lngTopPos -= objAttachecControl.parentNode.scrollTop;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight - 1) ;			
	}	
	

	divTest.style.display = 'block';
	divTest.style.left = lngLeftPos;
	//alert('top::' + divTest.style.top + '  left::' + divTest.style.left);

	//<<<for change the horizontal align
	if (divTest.offsetWidth > objTextCell.offsetWidth+objAttachecControl.offsetWidth)
	{
		divTest.style.left = lngLeftPos + divTest.offsetWidth - objAttachecControl.offsetWidth - objTextCell.offsetWidth;
	}
	//<<<for change the Vertical align...menu will come upside 
	//<<<get window's height and menu height 
	intWindowHeight=getWindowHeight();
	intMenuLocation=parseInt(divTest.style.top) + parseInt(divTest.offsetHeight);
	if (intMenuLocation>=intWindowHeight)
	{
		divTest.style.top = parseInt(divTest.style.top) - parseInt(divTest.offsetHeight) - parseInt(objAttachecControl.offsetHeight) + 2;
	}
	//<<<to change the location ...menu will come right side
	if (parseInt(divTest.style.top) < 0)
	{	
		divTest.style.top =lngTopPos/2;
		divTest.style.left = parseInt(divTest.style.left) + parseInt(objTextCell.offsetWidth) + parseInt(objAttachecControl.offsetWidth);
	}
	//<<<for horizontal alignment...menu will appears left side
	intTotalLocation=parseInt(divTest.style.left) + parseInt(divTest.offsetWidth)
	windowWidth=getWindowWidth();
	windowHeight=getWindowHeight();
	if (intTotalLocation > windowWidth)
	{
		divTest.style.left = parseInt(lngLeftPos) - parseInt(divTest.offsetWidth)  + parseInt(objAttachecControl.offsetWidth);// - parseInt(objLocationToFit.offsetWidth) -25 ;// - objTextCell.offsetWidth;
	}
	//<<<menu will cover half area of control
	if (parseInt(divTest.style.left)<=0)
	{
		divTest.style.top =lngTopPos/2;
		divTest.style.left = parseInt(divTest.style.left) + parseInt(divTest.offsetWidth) + (parseInt(objTextCell.offsetWidth)/2);
	}
	//<<<if menu is still not clear
	
	if (parseInt(divTest.style.top)<=0 || parseInt(divTest.style.left)<=0 || (parseInt(divTest.style.left)+ parseInt(divTest.offsetWidth))>=windowWidth || (parseInt(divTest.style.top)+ parseInt(divTest.offsetHeight))>=windowHeight)
	{		
		try
			{
				/*var scr_w = screen.availWidth;
				var scr_h = screen.availHeight;
				window.resizeTo(scr_w, scr_h);
				window.moveTo(0, 0);*/
			}
			catch (e){	}
	}
	
	divTest.style.zIndex='999';
	//divTest.style.display = 'block';
	//divTest.focus();
	blnDisplay = true;
	//fnPopUp(divTest);
	
}
//<<gives popup window on click of btn..not in use
function fnPopUp(objToPutInPopUp)
{
	var putHere;
	var oPopup = window.createPopup();
	var intPopUpWidth;
	var intPopUpHeight;
	var intXLocation;
	var intYlocation;

	intPopUpWidth=parseInt(objToPutInPopUp.offsetWidth);
	intPopUpHeight=parseInt(objToPutInPopUp.offsetHeight);
	intXLocation=parseInt(objToPutInPopUp.style.top)
	intYlocation=parseInt(objToPutInPopUp.style.left)
	oPopupBody = oPopup.document.body;
	oPopupBody.innerHTML = objToPutInPopUp.innerHTML;
	oPopupBody.style.backgroundColor = "#ffff66";
	oPopupBody.style.border = "1 solid black";
	oPopupBody.style.fontSize = "12px";
	oPopupBody.style.fontFamily = "Courier New";
	putHere=fnGetObject('putHere');
	objToPutInPopUp.style.display='none';
	oPopup.show(intXLocation, intYlocation,intPopUpWidth+20 ,intPopUpHeight , putHere);
}

//***to store the slected row and column id in textfield
function fnSetSelectedData(strRowId,strColId)
{
	var objRowtxt;
	var objColtxt;
	var strError;

		objRowtxt=fnGetObject('control_rowid');
		objColtxt=fnGetObject('control_rowid_colid');

		if (objRowtxt==null)
		{	strError="YES";	}

		if (objColtxt==null)
		{	strError="YES";	}

		if (strError=="YES")
		{
			//alert("For developers - Please Add two textBoxes named 'control_rowid' , 'control_rowid_colid' and 'control_rights' to use this control effectively");
			return;
		}

		objRowtxt.value=strRowId;
		objColtxt.value=strColId;	

	strError="NO";
	objRowtxt=null;
	objColtxt=null;
}
//<<store menu in array
function fnStoreMenuInArray(strMenuId)
{
	var intC;
	var strFound;
	strFound="NO";
	for (intC=0; intC < mastrMenuCollection.length; intC++)
	{
		if (mastrMenuCollection[intC]==strMenuId)
		{
			strFound="YES";
		}
	}
	if (strFound=="NO")
	{
		mastrMenuCollection[mastrMenuCollection.length]=strMenuId;
	}
	strFound="NO";
}

//**********************
//<<close alll menu
function fnCloseAllMenu()
{
	/*try
	{	
		var strClickedId= window.event.srcElement.id;
		var strControlId=document.all['control_Web_Iu_Table_ID'].value;
			if (strClickedId.indexOf(strControlId)!=-1)
			{return;}
	}
	catch(e)
	{
		alert("For developers - Please Add two textBoxes named 'control_rowid' , 'control_rowid_colid' and 'control_rights' to use this control effectively");
		return;
	}*/
	var intC;
	var objMenu;
	for (intC=0; intC < mastrMenuCollection.length; intC++)
	{
		objMenu = document.getElementById(mastrMenuCollection[intC]);	
		objMenu.style.display='none';
	}
	fnClosePreviousSection();
	///fnSetOriginalStyleOnPreviousSelection();
}
//<<<to close menu ..used by scollbars of page or other items
function fnCloseControlMenuForScrollBar()
{
	try	{
		fnCloseControlAllMenu();
	}
	catch(e){}
	mobjSelectedDDImgCell = null;
	return;
}
//<<close menu for application body click
function fnCloseWebIuTableControlMenu(e)
{
	var strSubMenu;
	var objTemp;
	var strClickedId;
	var strControlId;

	try
	{	
		if (fnIE() == true)
		{
			strClickedId = window.event.srcElement.id;
		}
		else
		{
		//	alert( "jsControlMenu.js : fnCloseWebIuTableControlMenu " + String( e.target.id ) );
			strClickedId = String( e.target.id );
		}		
		
		strControlId = fnGetObject('control_Web_Iu_Table_ID').value;		
		if (strClickedId.indexOf(strControlId) != -1)	{return;}
	}
	catch(e)
	{	//alert("For developers - Please Add two textBoxes named 'control_rowid' , 'control_rowid_colid' and 'control_rights' to use this control effectively");
		return;
	}

	//<<<to check whether the click event on the menu options which have his own sub menu.
	//<<<..thats case menu could not close
		 objTemp = null;
		if (fnIE() == true)
		{
			objTemp = fnGetObject[window.event.srcElement.id];
		}
		else
		{
			objTemp = fnGetObject[e.target.id];
		}
	
	if (objTemp != null || objTemp != undefined)
	{	 strSubMenu = objTemp.getAttribute('SUB_MENU')
		if (strSubMenu != null && strSubMenu != '')	{return;}
	}

	fnCloseControlAllMenu();
	mobjSelectedDDImgCell = null;
	return;
}

//<<<to close the menu on click on other items of comtrol which doesnt have any menu
function fnCloseMenuForNonMenuCells()
	{
		fnCloseControlAllMenu();
		mobjSelectedDDImgCell=null;
		return;
	}

//,,Mouse move on Each group item 
function fnGroupNameMouseOver(objImgCell,objTextCell)
{
	//<<stor classname is string
	mstrClassName=objTextCell.className;
	//<<change class 
	objTextCell.className=CssMouseHoveGroupName;
}
function fnGroupNameMouseOut(objImgCell,objTextCell)
{	//<<cghange class in original

	objTextCell.className=mstrClassName;
	//alert('g2')
	//mastrGroupName[0]=objTextCell;
	//mastrGroupName[1]=mstrClassName;
}
//<<to expand and collapse the group data
function fnExpandAndCollapsed(objImgCell,objGroup,objGroupName)
{	
		var objImg;
		var strExpandImg;
		var strCollapseImg;
		var blnExpanded;
		//<<close all menus
		fnCloseAllMenu();
		//var objBlankCell;
		//<<create img tab
		var imgTag=document.createElement("img");
		imgTag.setAttribute("width","20px");
		imgTag.setAttribute("height","20px");

		strExpandImg=objImgCell.getAttribute("EXPANDIMG") + "";
		if (strExpandImg==null){strExpandImage='';}

		strCollapseImg=objImgCell.getAttribute("COLLAPSEDIMG") + "";
		if (strCollapseImg==null){strCollapseImg='';}

		objImg=document.getElementById(objGroup.id + "_IMG");
		
		//<<<for new structure of grouped data		
		try		
			{	//alert('try');
				blnExpanded=fnExpandAndCollapsed_ForNewStructuredGroupData(objGroup);
			
			}
		catch (e)
			{	//alert('catch');
			return;	}
		if (blnExpanded==true)	
		{	objImg.setAttribute("src",strExpandImg);
			objGroupName.className=mstrClassName;	
		}
		else{	
			objImg.setAttribute("src",strCollapseImg);
			objGroupName.className=mstrClassName;	
		}
		return;

		/////XXXXXX<<<for old structure of grouped data..not in use>>>>>
			if (objGroup.style.display=='none')
			{
				imgTag.setAttribute("src",strExpandImg);
				//objGroup.style.display="block";
				fnShowObjectBasedOnBrowser(objGroup);
				//<<change to original style
				objGroupName.className=mstrClassName;
			}
			else 
			{
				imgTag.setAttribute("src",strCollapseImg);
				objGroup.style.display='none';
				//<<change to original style
				objGroupName.className=mstrClassName;
			}
		objImgCell.innerHTML="";
		objImgCell.appendChild(imgTag);
		//<<set original style to group
		//fnResetGroupNameStyle()
		//alert('enf of fn');
}

	
//<<<for new style grouped data...called from older function called "fnExpandAndCollapsed()"
function fnExpandAndCollapsed_ForNewStructuredGroupData(objGroupedParentRow)
{
	//alert('fnExpandAndCollapsed_ForNewStructuredGroupData');
	var strChildPattern;
	var intTotalChilds;
	var strParentId;
	var strChildId;
	var intCount;
	var objChildData;
	var blnExpand;
	strParentId = objGroupedParentRow.id;
	strChildPattern = objGroupedParentRow.getAttribute("GROUPCHILDPATTERN") + "";
	intTotalChilds = objGroupedParentRow.getAttribute("GROUPCHILD") + "";
	intTotalChilds = parseInt(intTotalChilds);

		for (intCount=1; intCount <= intTotalChilds ; intCount++)
		{
			try
			{
				strChildId = strParentId + strChildPattern + intCount;
				objChildData = document.getElementById(strChildId);
				if (objChildData.style.display=='' || objChildData.style.display=='block' || objChildData.style.display=='table-row')
					{	
						objChildData.style.display='none';	blnExpand=false;
					}
				else
					{	
						//objChildData.style.display='block';
						fnShowObjectBasedOnBrowser(objChildData);
						//objChildData.style.display='table-row';
						blnExpand=true;
					}
			}
			catch (e){	}
			
		}
		return blnExpand;
}
//<<to reset the style of group item
function fnResetGroupNameStyle()
{
	if (mastrGroupName[0]==null)
	{return;
	}
	mastrGroupName[0].className = mastrGroupName[1];
}
//**********to off the variable used by previous selected items..Very important
function fnClosePreviousSection()
{	
	if (mobjClosePreviousSelected == null)
	{	return;	
	}
	//alert(mobjClosePreviousSelected.style.visibility);
	//<<<img remains same
	//mobjClosePreviousSelected.style.visibility="hidden";	
	mobjClosePreviousSelected = null;	
	mstrOpenMenuCell = null;	
}
//<<for remmove style on selected record
function fnSetOriginalStyleOnPreviousSelection()
{
	if (mastrSelected[0]==null)
	{return;}
	if (mastrSelected[4]==null)
	{return;}//alert(mastrSelected[0].id);
			mastrSelected[0].className = mastrSelected[2];
			mastrSelected[1].className = mastrSelected[3];
			mastrSelected[4].style.visibility = "hidden";

			mastrSelected[0] = null;
			mastrSelected[1] = null;
			mastrSelected[2] = null;
			mastrSelected[3] = null;
			//mastrSelected[4]=null;
			//mobjSelectedDDImgCell=null;
}
//<<<to close all menus..very usefull 
function fnCloseControlAllMenu() 
{
	try
	{
		fnSetOriginalStyleOnPreviousSelection();
		fnClosePreviousSection();
		fnCloseAllMenu();
	}
	catch(e){}

}

//<<on document click
if (window.Event)	document.captureEvents(Event.MOUSEUP);

	function fnCloseWindow(blnReturnValue)
	{
		this.returnValue = blnReturnValue;
		window.close();
	}			
	function nocontextmenu() 
	{
		event.cancelBubble = true, event.returnValue = false;
		return false;
	} 
	function norightclick(e) 
	{
		fnSetOriginalStyleOnPreviousSelection();
		fnClosePreviousSection();
		fnCloseAllMenu();
	}
//<<<usefull for no right click ,no context menu and other things
//document.oncontextmenu = nocontextmenu;
//document.onmousedown = norightclick;
//document.onmouseup = norightclick;

//<<<to mouse mouve on items
function fnMOver( objFirstCell)
{
	objFirstCell.className=CssMouseHoverUnderLine;
}
function fnMout( objFirstCell)
{

	objFirstCell.className = 'EllisCellText';
}
//<<for mouse move on record to make underline of first cell
function fnUnderLineFirstCell(objFirstCell)
{
	//<<if menu in opend of same cell
	if (mobjSelectedDDImgCell != null)
	{	if (mobjSelectedDDImgCell.id == (objFirstCell.id + '_DDIMGCELL'))	{return;}	
	}
	objFirstCell.className = CssMouseHoverUnderLine;
}
function fnRemoveUnderLineFirstCell(objFirstCell)
{
	//<<if menu in opend of same cell
	if (mobjSelectedDDImgCell != null)
	{	if (mobjSelectedDDImgCell.id == (objFirstCell.id + '_DDIMGCELL'))	{return;}	
	}

	objFirstCell.className = 'EllisCellText';
}

///////////**************//////////////
///////////**************//////////////
///////////**************//////////////
//<<for header menu mouse move
function fnHeaderMenuMouseOver(objCell)
{
	//<<<check it menu item is disabled because of rights
	try
	{
		objLnk = objCell.getElementsByTagName("a")[0];		
		if (objLnk.disabled == true){	return;	}
	}
	catch (e)
	{
	}
	//<<store classname is string
	mstrClassName = objCell.className;
	//<<change class 
	objCell.className = CssMouseHoveMenuItem;
	
	prShowSubMenu(objCell);
	
}
	
function fnHeaderMenuMouseOut(objCell)
{	
	try
	{	objLnk=objCell.getElementsByTagName("a")[0];		
		if (objLnk.disabled==true){	return;	}
	}
	catch (e){	}
	//<<change class in original

	objCell.className = mstrClassName;

	//prHideSubMenu(objCell);
}
///////////**************//////////////
///////////**************//////////////
///////////**************//////////////

//////************************///////
///<<<code to show and hide sub menu of parent menus
	function prShowSubMenu(objMenuTextCell)
	{	
		var strSubMenuId;
		var strSelfMenuId;
		strSubMenuId=null;
		strSelfMenuId=null;		
		
		if (objMenuTextCell==null || objMenuTextCell=='')
		{
			objMenuTextCell=fnGetObject[objMenuTextCell];	
		}
		if (objMenuTextCell!=null)
		{	
			strSubMenuId = objMenuTextCell.getAttribute('SUB_MENU');	
			strSelfMenuId = objMenuTextCell.getAttribute('SELF_MENU');
	
			//<<<if sub menu is not exists...only close unnecessary sub menu..
			if (strSubMenuId==null || strSubMenuId=='')
			{	//alert('no menu');//<<<close all visible sub menus
				fnHideUnnecessarySubMenus(strSelfMenuId);		
			}
			//if sub menu exists
			if (strSubMenuId!=null)
			{	
				//objMenu=document.getElementById(strSubMenuId);
				objMenu=fnGetObject(strSubMenuId);					
				if (objMenu!=null)
				{
					fnSetMenuAccordingToRights(objMenu);

					if (objMenu.style.display=='none')
					{						
						//<<<close all visible sub menus					
						fnHideUnnecessarySubMenus(strSelfMenuId);					
						//<<move the menu under body tag
						fnMoveObjectDirectUnderBodyTag(objMenu);					
						//<<<set location of menu and show
						fnSetAndShowSubMenuLocation(objMenuTextCell,objMenu);					
						//<<<store current visible menu id in global menu array
						fnStoreMenuInArray(objMenu.id);					
						//<<<store sub menu ids in global sub menu id collection
						fnStoreIdInSubMenuGlobalArrayCollection(objMenu.id);					
					}						
					//<<<change the css file of item having sub menu
					objMenuTextCell.className = CssMouseHoverMenuItem_HavingSubMenu;
				}
			}
		}

	}
	///>>>>NOT IN USE...to hide sub menus
	function prHideSubMenu(objMenuTextCell)
	{
		var strSubMenuId;
		if (objMenuTextCell == null || objMenuTextCell == '')
		{	objMenuTextCell = fnGetObject[objMenuTextCell];	}

		if (objMenuTextCell != null)
		{
				strSubMenuId = objMenuTextCell.getAttribute('SUB_MENU');
				if (strSubMenuId != null)
				{
					objMenu = fnGetObject[strSubMenuId];
					if (objMenu != null)
					{
						objMenu.style.display='none';
						//<<<store menu in array collecting all menus
						//fnStoreMenuInArray(objMenu.id)
					}
				}
		}
	}
	//<<to set location of sub menus
	function fnSetAndShowSubMenuLocation(objLocationToFit,divMenu)
	{	var objTemp;
		var intTotalLocation;
		var windowWidth;
		var lngLeftPos;
		var lngTopPos;
		var strParentTag;
		lngLeftPos = 0;
		lngTopPos = 0;
		objTemp = objLocationToFit;
		lngLeftPos=objTemp.offsetLeft;
		lngTopPos=objTemp.offsetTop+ objTemp.scrollTop;//+objTemp.offsetParent.offsetTop;
		lngWidth=objTemp.offsetWidth;
		do 
		{
			objTemp = objTemp.offsetParent;
			//lngLeftPos += objTemp.offsetLeft;		
			//lngTopPos += objTemp.offsetTop; 
			lngLeftPos += objTemp.offsetLeft - objTemp.scrollLeft;//for nonscrollable parent div aor form
			lngTopPos += objTemp.offsetTop - objTemp.scrollTop; ///for scrollable parent div or form
			strParentTag=objTemp.tagName.toUpperCase();		//<<<get parent tag name
		} while(strParentTag != "BODY");
		//lngLeftPos=lngLeftPos+lngWidth-divMenu.offsetWidth;
		lngLeftPos=lngLeftPos+lngWidth;

		/*if (fnSafari()==true)
		{	

		/*lngTopPos -= objAttachecControl.offsetParent.scrollTop;
		lngTopPos =lngTopPos+8;
		divTest.style.top = (lngTopPos + objAttachecControl.offsetHeight - 3) ;	
		//lngTopPos=lngTopPos-5;
		//lngLeftPos=lngLeftPos-5;
		}*/
		divMenu.style.position='absolute';
		divMenu.style.zIndex='1215';
		divMenu.style.display = 'block';
		
		divMenu.style.top =lngTopPos+divMenu.offsetParent.offsetTop -1;//-100;
		divMenu.style.left = lngLeftPos;
		
		//<<<for horizontal alignment...menu will come left side
		intTotalLocation=parseInt(divMenu.style.left) + parseInt(divMenu.offsetWidth)
		windowWidth=getWindowWidth();
		if (intTotalLocation > windowWidth)
		{
			divMenu.style.left = parseInt(lngLeftPos) - parseInt(divMenu.offsetWidth) - parseInt(objLocationToFit.offsetWidth) -25 ;// - objTextCell.offsetWidth;
		}
		if (parseInt(divMenu.style.left)<=0)
		{divMenu.style.left = parseInt(lngLeftPos) -  (parseInt(objLocationToFit.offsetWidth)/2);
		}
		try
		{	divMenu.focus();	}
		catch (e)	{	}

		blnDisplay = true;
	}
//<<<move object from original position to as body tag child
function fnMoveObjectDirectUnderBodyTag(objToMove)
{
		var objBody;
		var strParentName;
		if (objToMove==null)
		{return false;}
		//<<<check whether object is already inside body tag
		strInsideBody=objToMove.getAttribute("INSIDE_BODY");
		if (strInsideBody=="yes")
		{return true;}
		//<<check parent tag
		strParentName=objToMove.tagName.toUpperCase();
		if (strParentName == "BODY")
		{return true;}
		//<<get body tag
		objBody=document.getElementsByTagName("body")[0];
		if (objBody==null)
		{return false;}
		//<<append object under menu tag
		objBody.appendChild(objToMove);
		//<<<set attibute that object is under body tag
		objToMove.setAttribute("INSIDE_BODY","yes");
		return true;
}
//<<<to store sub menu id in global array collection
function fnStoreIdInSubMenuGlobalArrayCollection(strSubMenuId)
{	var intC;
	var strFound;
	strFound="NO";
	for (intC=0;intC<mastrSubMenuCollection.length; intC++)
	{
		if (mastrSubMenuCollection[intC]==strSubMenuId)
		{	strFound="YES";	}
	}
	if (strFound=="NO")
	{		mastrSubMenuCollection[mastrSubMenuCollection.length]=strSubMenuId;	}
	strFound="NO";
}
//<<<close all sub menus...except current open menu and its parent menus
function fnHideUnnecessarySubMenus(strTargetIdToCheck)
{	var strCurrentMenu;
	var intC;
	var objMenu;
	var strMenuId;
	//<<<get current menu id

	strCurrentMenu=strTargetIdToCheck + '_OPTIONMENU';
	//<<<through each menu is

	for (intC=0;intC<mastrSubMenuCollection.length; intC++)
	{
		strMenuId=mastrSubMenuCollection[intC];
		if (strMenuId.indexOf(strTargetIdToCheck)>=0)
		{
			if (strMenuId!=strCurrentMenu)
			{
				objMenu=fnGetObject(strMenuId);			
				objMenu.style.display='none';			
			}
		}
	}//fnClosePreviousSection();///fnSetOriginalStyleOnPreviousSelection();
}

////<<<<TO SET THE MINIMUM SIZE OF FORM
function fnsetWidth(objForm)
{
	var intWindowWidth,intWindowHeight;
	var intFormWidth,intFormHeight;
	try
	{
		intWindowWidth=getWindowWidth();		//<<<Get window width
		intWindowHeight=getWindowHeight();		//<<<Get window Height
		intFormWidth=objForm.offsetWidth;		//<<<get form width		
		intFormHeight=objForm.offsetHeight;		//<<<get form Height
		//alert('window :: Width: ' + intWindowWidth + ' :: Height : ' + intWindowHeight);
		//alert('Form :: Width: ' + intFormWidth + ' :: Height : ' + intFormHeight);
		if (intFormWidth > intWindowWidth )
		{		try	{	
				//alert(intFormHeight);
				//alert(intWindowHeight);
				window.resizeTo(intFormWidth + 150,intFormHeight * 8);		}
			catch(e){}
			//window.moveTo(0, 0);	
		}
	}
	catch(e){}
			/*var scr_w = screen.availWidth;
			var scr_h = screen.availHeight;
			window.resizeTo(scr_w, scr_h);
			window.moveTo(0, 0);*/

}
function getWindowWidth() 
{
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}
function getWindowHeight() 
{
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;;
			}
		}
	}
	return windowHeight;
}
//<<<<<FUNCTIONS FOR MENUS OF GROUP PAGES....
function fnMouseOverForGroupMenuthis(objCell)
{
		///<<stor classname is string
		mstrClassName=objCell.className;
		//<<change class 
		objCell.className=CssMouseHoveMenuItem;			
}
function fnMouseOutForGroupMenuthis(objCell)
{
		//<<cghange class in original		
		objCell.className=mstrClassName;
		//prHideSubMenu(objCell);
}
//<<<for browsers...not in use
function fnDetectBrowser(strId)
{
	var mybrowser = navigator.appName;
	var robj;
	if (mybrowser.indexOf('Netscape') != -1)
	   {
			robj = document.getElementById(strId);
			return robj;	
		}
	 else
		{
		 	robj = document.getElementById(strId);
			return robj;
		}	
}

///<<<to get object for all browsers
function fnGetObject(strID)
{
	try
	{
		var obj;
		obj = null;
		//<<<<common function for almost all browsers
		obj = document.getElementById(strID);
		if (obj != null){	return obj;	}

		//<<<<if getelement by id doesnt work
		obj = document.getElementById( strID );

		if (obj != null){	return obj;	}	
	}
	catch (e)
	{
	}
}

//<<<this function is used  to show the object in replace of display='block'		
		function fnShowObjectBasedOnBrowser(obj)
		{
			var browser;
			var detect;
			if (obj==null) return;

			try
			{	detect = navigator.userAgent.toLowerCase();
			}
			catch (e){	}
			
			if (checkIt(detect,'safari'))
			{
				//browser = "Safari";	
				obj.style.display='table-row';
			}
			else if (checkIt(detect,'msie')) 
			{
				//browser = "Internet Explorer";
				obj.style.display='block';
			}
			else if (checkIt(detect,'opera')) 
			{
				//browser = "Opera"
				obj.style.display='table-row';
			}
			else 
			{
				//browser = "Mozilla";
				obj.style.display='table-row';
			}
		}
		
		function checkIt(detect,string)
		{
			place = detect.indexOf(string) + 1;
			return place;
		}
		
       function fnSayImSubmition()
	   {
			 objSubmition=true;
	   }
