var oGlobal= new Object();
var oImgMag = new Image();
var oImgMagOver = new Image();
var bfw_uid_hcl;
oImgMag.src="../images/magnifying_glass_blue.jpg";
oImgMagOver.src="../images/magnifying_glass_blue_1.jpg";

/*function callPage(oList) {
    var sValue = oList.options[oList.selectedIndex].value;
    // you may have to alter this depending on how you build your URL
   alert(sValue);
    }*/
/*function call()
{
alert("hi");
}
function GetDropDownValue(id)

        {

//alert("hi---");
            alert(document.getElementById(id).value);

        }*/
function tmover() 
{ 

//if(document.getElementById('task').value=="0")
//{
//alert(document.getElementById('task').value);
//alert(document.getElementById('ComboTopic').options[document.getElementById('ComboTopic').selectedIndex].value;
//document.getElementById('tagdiv').style.display = 'block';
//}
//else
//{

//}
}

function tmout() 
{ 
document.getElementById('tagdiv').style.display = 'none'; 
}
function HitPage(sTask)
{  
	document.forms[0].task.value = sTask;
	document.forms[0].submit();
}

	function changeColor(sCellId,oImg)
	{
		if(oGlobal.selectedCellId)
		{
			if(oGlobal.selectedCellId != sCellId)
			{
				var oPreviousSelectedCell = document.getElementById(oGlobal.selectedCellId);
				var oPreviousSelectedImg = document.getElementById(oGlobal.selectedImgId);
				oPreviousSelectedCell.className = "regularSubAsset";
				
				oPreviousSelectedImg.src="../images/magnifying_glass_blue.jpg";
			}
		}
		oGlobal.selectedCellId=sCellId;
		oGlobal.selectedImgId=oImg;
		var oCell = document.getElementById(sCellId);
		var oVarImg = document.getElementById(oImg);		
		oCell.className = "selectedSubAsset";
	}

  function ChangeImg(oImg)
  {
	var oVarImg = document.getElementById(oImg);
	oVarImg.src="../images/magnifying_glass_blue_1.jpg";
  }

  function toggleDiv(divid,sParentCellId){
	var oParentCell = null;
	
	if(oGlobal.selectedCellId)
	{
		oParentCell=document.getElementById(oGlobal.selectedCellId);
		delete oGlobal.selectedCellId;
	}
	
    var dividl=divid.substr(0,2);
	var i=0;
    if((document.getElementById(divid).style.display == 'none') || (document.getElementById(divid).style.display == '')){
	  while(document.getElementById(dividl+i))
	  {
		if(document.getElementById(dividl+i))
		{
	      document.getElementById(dividl+i+"_v").style.display = 'block';
		  document.getElementById(dividl+i).style.display = 'none';
		}
		i++;	
	  }
      document.getElementById(divid+"_v").style.display = 'none';
      document.getElementById(divid).style.display = 'block';
      
    }else{
      document.getElementById(divid).style.display = 'none';
      document.getElementById(divid+"_v").style.display = 'block';
      
      if(oParentCell)
		oParentCell.className = "regularSubAsset";
    }
  }

function colorC(obj)
{
	var oDivDSA1 = document.getElementById(obj);
	oDivDSA1.style.backgroundColor= "#A3C3D8";
	return false;
}

function colorR(obj)
{
	var oDivDSA1 = document.getElementById(obj);
	oDivDSA1.style.backgroundColor= "#D3E3ED";
	return false;
}


function SetFocus()
{
	var oTxtEmail = document.getElementById("txtEmail");
	if(oTxtEmail)
	{
		oTxtEmail.focus();
	}
}

// this function puts the dark screen over the entire page
function DarkenPage()
{
    var page_screen = document.getElementById('page_screen');
    
    page_screen.style.height = "430px";
    page_screen.style.width = "813px";
    page_screen.style.left = "16px";
    page_screen.style.display = 'block';
	document.getElementById('login').style.visibility='visible';
	
}

// this function removes the dark screen and the page is light again
function LightenPage()
{
    var page_screen = document.getElementById('page_screen');
	document.getElementById('login').style.visibility='hidden';
    page_screen.style.display = 'none';
}


function doPostBack(Task,TaskID)
{
//alert();
//alert(Task);
//alert(TaskID);
	document.forms[0].task.value = Task;
	document.forms[0].taskid.value = TaskID;
	document.forms[0].submit();
}

function doPostBackParentWithType(Task,TaskID,TopicName,Type)
{
	UpdateDivCSV();
	parent.document.forms[0].task.value = Task;
	parent.document.forms[0].taskid.value = TaskID;
	parent.document.forms[0].TopicName.value = TopicName;
	parent.document.forms[0].TopicType.value = Type;
	//parent.document.forms[0].CSVDivType.value = CSVDivType;
	//parent.document.forms[0].CSVDivTopic.value = CSVDivTopic;
	parent.document.forms[0].submit();
}

function doPostBackParent(Task,TaskID)
{
	parent.document.forms[0].task.value = Task;
	parent.document.forms[0].taskid.value = TaskID;
	parent.document.forms[0].submit();
}
function doDownload(FileNameWithPath)
{
	//var sTest = window.open("","Download",'menubar=yes,width=10,height=10,left=1024,top=768,resizable');
	var sTest = window.open(FileNameWithPath,"Download",'menubar=yes,width=400,height=400,left=10,top=10,resizable');
	sTest.location = FileNameWithPath;
}
function doOpenNewWindow(sFileName)
{
	window.open(sFileName, 'Preview', 'width=1000,height=530,left=8,top=5,status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes');
}

function findPos(obj) 
{
	//obj = document.getElementById("SELECTED_IMG_ID");
	
	if(obj)
	{
		var curleft = curtop = 0;
		if (obj.offsetParent) {
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			while (obj = obj.offsetParent) {
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		
		curtop -= 50;
		
		return curtop;
	}
}

function sstchur_SmartScroller_Scroll(sID)
{
	//alert(sID);
	obj = document.getElementById(sID);
	if(obj)
	{
		var y = findPos(obj);
		var x = 0;
		window.scrollTo(x, y);
	}
}

function doOpenMenu(sID)
{
	location.href = "JIT_TYPE.htm?"+sID;
}

function GetShowHideDivs()
{
	var sSubMenuCnt = document.forms[0].subMenuCnt.value;
	var sTempStr = "";
	
	for(i=0; i<sSubMenuCnt; i++)
	{
		if(document.getElementById("SUB_"+i))
		{
			if(document.getElementById("SUB_"+i).style.display == "block")
			{
				sTempStr += "~"+"SUB_"+i;
			}
		}
	}
	
	return sTempStr;
}


function doShowHide(sID, sMenu)
{
	
	if(sID == "")
	return;
	
	var e = document.getElementById(sID);
	var sSubMenuCnt = document.forms[0].subMenuCnt.value;
	
	if(e)
	{
		var sTemp = e.style.display;
	/*
		for(i=0; i<sSubMenuCnt; i++)
		{
			if(document.getElementById("SUB_"+i))
			{
				if(("SUB_"+i) == sID)
				{
					var sTemp = document.getElementById("SUB_"+i).style.display;
				}
				document.getElementById("SUB_"+i).style.display = "none";
				document.getElementById("SUB_"+i+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('SUB_"+i+"');\"><img src=\"images/bullet.jpg\" border=\"0\"></a>";
			}
		}
*/
		if(sTemp == "none")
		{
			e.style.display = "block";
			sHTML = "<a href=\"javascript:doShowHide('"+sID+"');\">";
			sHTML += "<img src=\"images/bulletdown.jpg\" id=\"BD\" border=\"0\"></a>";
			document.getElementById(sID+"_BULLET").innerHTML = sHTML;
			//alert(sHTML);
		}
		else
		{
			e.style.display = "none";
			document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bullet.jpg\" border=\"0\"></a>";	
		}
	}
	
	parent.document.forms[0].SelectedID.value = sID;
	parent.document.forms[0].SelectedMenu.value = sMenu;
	//sstchur_SmartScroller_Scroll(sID);
	UpdateDivCSV();
}


function doShowHide_NEW(sID, sMenu)
{
	
	var e = document.getElementById(sID);
	var sSubMenuCnt = document.forms[0].subMenuCnt.value;
	
	if(e)
	{
		/*
		for(i=0; i<sSubMenuCnt; i++)
		{
		
			if(document.getElementById("SUB_"+i))
			{
				if(("SUB_"+i) == sID)
				{
					var sTemp = document.getElementById("SUB_"+i).style.display;
				}
				
				document.getElementById("SUB_"+i).style.display = "none";
				document.getElementById("SUB_"+i+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('SUB_"+i+"');\"><img src=\"images/bullet.jpg\" border=\"0\"></a>";
			}
		}
		*/

		if(e.style.display == "none")
		{
			e.style.display = "block";
			document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bulletdown.jpg\" border=\"0\"></a>";
		}
		else
		{
			e.style.display = "none";
			document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bullet.jpg\" id=\"b2\" name=\"b2\" border=\"0\"></a>";	
		}
	}
	
	
	parent.document.forms[0].SelectedID.value = sID;
	parent.document.forms[0].SelectedMenu.value = sMenu;
	//sstchur_SmartScroller_Scroll(sID);
	//alert(sID);
	//InitialiseScrollbar();
	
	UpdateDivCSV();
	
}

function UpdateDivCSV()
{
	sTempCSV = GetShowHideDivs();
	
	if(document.forms[0].TabType.value == "Type")
	{
		parent.document.forms[0].CSVDivType.value = sTempCSV;
	}
	else
	{
		parent.document.forms[0].CSVDivTopic.value = sTempCSV;		
	}
}

function InitLeftFrame()
{
	//InitialiseScrollbar();
	sID = parent.document.forms[0].SelectedID.value;
	sMenu = parent.document.forms[0].SelectedMenu.value;
	//alert((sID + " - " + sMenu));
	//if(sID != "")
	//doShowHide(sID, sMenu);
	
	doHideSelectedDivs()
	
	//sArr = CSVDiv.split("~");
	//alert(sArr.length);
	sstchur_SmartScroller_Scroll('SELECTED_IMG_ID');
	
	
	//CHANGE for AdunctCentral
	//Check if the call is external
	//isExternalCall = document.forms[0].ExternalCall.value;
	sResource = document.forms[0].ExternalResource.value;
	if(sResource != "")
	{
		sResource = document.forms[0].ExternalResource.value;
		sDivID = document.getElementById(sResource).innerHTML;
		//alert(sDivID);
		//Collapse the selected menu
		doShowHide(sDivID);
		//Scroll till the selected menu
		sstchur_SmartScroller_Scroll('BD');
	}
	document.forms[0].ExternalResource.value = "";
	//END
}

function doHideSelectedDivs()
{
	//var CSVDiv = parent.document.forms[0].CSVDiv.value;
	if(document.forms[0].TabType.value == "Type")
	{
		CSVDiv = parent.document.forms[0].CSVDivType.value;
	}
	else
	{
		CSVDiv = parent.document.forms[0].CSVDivTopic.value;		
	}

	arrDiv = CSVDiv.split("~");
	if(arrDiv.length>1)
	{
		for(i=1; i<arrDiv.length; i++)
		{
			doShow(arrDiv[i]);
		}
	}
	
}

b1 = new Image(22,22);
b1.src="images/bullet.jpg";  

b2 = new Image(22,22);
b2.src="images/bullet.jpg";  

function doHide(sID)
{
	var e = document.getElementById(sID);
	
	e.style.display = "none";
	document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bullet.jpg\" id=\"b1\" name=\"b1\" border=\"0\"></a>";	
}

function doShow(sID)
{
	var e = document.getElementById(sID);
	
	e.style.display = "block";
	document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bullet.jpg\" id=\"b1\" name=\"b1\" border=\"0\"></a>";	
}

function doHighlight(sID)
{
	var e = document.getElementById(sID+"_BULLET");
	e.innerHTML = "<img src='images/bullet-black-topspace.jpg' >";
}

function doRemoveHighlight(sID)
{
	var e = document.getElementById(sID+"_BULLET");
	e.innerHTML = "&nbsp;";
}


function doDisplayData()
{
	/*
	var sQuery = location.search.substr(1);

	if(sQuery!="")
	{
		var sDesc = document.getElementById(sQuery+"_DESC").innerHTML;
	
		document.getElementById(sQuery+"_TD").innerHTML = sDesc;
		document.getElementById(sQuery+"_BULLET").innerHTML = "<img src='images/bullet-black-topspace.jpg' >";

		var arrID = sQuery.split("_");
		sID = arrID[0]+"_"+arrID[1];

		var sType = document.getElementById(sID+"_TYPE").innerHTML;
		document.getElementById("CONTENT_ID").innerHTML = ActivityData(sType, sDesc);

		document.getElementById(sID+"_BULLET").innerHTML = "<a href=\"javascript:doShowHide('"+sID+"');\"><img src=\"images/bulletdown.jpg\" border=\"0\"></a>";
		document.getElementById(sID).style.display = "block"
	}
	else
	{
		document.getElementById("CONTENT_ID").innerHTML = InitText();
	}
	
	if(document.getElementById("MeasureHeight").offsetHeight > 320 && document.getElementById("ImplementHeight").offsetHeight < document.getElementById("MeasureHeight").offsetHeight)
	{
		document.getElementById("ImplementHeight").style.height = document.getElementById("MeasureHeight").offsetHeight;
	}*/
}



/*
function sstchur_SmartScroller_GetCoords()
		{
			var scrollX, scrollY;
		      
			if (document.all)
			{
				if (!document.documentElement.scrollLeft)
					scrollX = document.body.scrollLeft;
				else
					scrollX = document.documentElement.scrollLeft;
		               
				if (!document.documentElement.scrollTop)
					scrollY = document.body.scrollTop;
				else
					scrollY = document.documentElement.scrollTop;
			}   
			else
			{
				scrollX = window.pageXOffset;
				scrollY = window.pageYOffset;
			}
		   
			parent.parent.HiddenFrame.document.forms[0].xCoordHolder.value = scrollX;
			parent.parent.HiddenFrame.document.forms[0].yCoordHolder.value = scrollY;
		}

		function sstchur_SmartScroller_Scroll()
		{
			//var x = parent.parent.HiddenFrame.document.forms[0].xCoordHolder.value;
			//var y = parent.parent.HiddenFrame.document.forms[0].yCoordHolder.value;
			//window.scrollTo(x, y);
			//alert("Y = "+y);
			
			obj = document.getElementById("SELECTED_IMG_ID");
			if(obj)
			{
				var y = findPos(obj);
				var x = 0;
				window.scrollTo(x, y);
			}
		}
				
		window.onload = sstchur_SmartScroller_Scroll;
		//window.onscroll = sstchur_SmartScroller_GetCoords;
		//window.onkeypress = sstchur_SmartScroller_GetCoords;
		//window.onclick = sstchur_SmartScroller_GetCoords;
				

		function findPos(obj) 
		{
			obj = document.getElementById("SELECTED_IMG_ID");
			
			
			if(obj)
			{
				var curleft = curtop = 0;
				if (obj.offsetParent) {
					curleft = obj.offsetLeft
					curtop = obj.offsetTop
					while (obj = obj.offsetParent) {
						curleft += obj.offsetLeft
						curtop += obj.offsetTop
					}
				}
				
				curtop -= 275;
				return curtop;
			}
		}
*/
function FormPanel_FireDefaultButton(event, target) 
{
    if ((event.keyCode == 13 || event.which == 13) && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == 'textarea'))) 
    {
    
    doPostBack(target,'');

    }
	return true;
}


function FormPanel_SubmitOnEnterKey(event, sFormName) 
{
    if ((event.keyCode == 13 || event.which == 13) && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == 'textarea'))) 
    {
		var oForm = document.getElementById(sFormName)
		if(oForm)
		{
			oForm.submit();
		}
		else
		{
			alert("Application error: object not found");
		}
    }
	return true;
}

function form_submit()
{
	// 
	var otxtEmail = document.getElementById("txtEmail");
	var otxtPwd = document.getElementById("txtPwd");
	var oEmailValidator = document.getElementById("emailValidator");
	var oPwdValidator = document.getElementById("pwdValidator");
	
	oEmailValidator.style.display = "none";
	
	if(otxtEmail.value.length == 0)
	{
		oEmailValidator.style.display = "";
		return false;
	}
	
	oPwdValidator.style.display = "none";
	if(otxtPwd.value.length == 0)
	{
		oPwdValidator.style.display = "";
		return false;
	}
	
	return true;
}

/** 
 * ShowCategory shows / hides category dropdown and hides category title table
 * @param {String}	sSubAsset is the table id
 * @param {String}	sSubAssetCat is the div id
 * @param {bool}	bShow set it to true when you want to show dropdown and vice versa to hide it
 */
function ShowCategory(sSubAsset, sSubAssetCat, bShow)
{
	// Get a reference to Category table and div
	var oSubAsset, oSubAssetCat;
	oSubAsset = document.getElementById(sSubAsset);
	oSubAssetCat = document.getElementById(sSubAssetCat);
	
	// Objects found then only show hide category table
	if(oSubAsset && oSubAssetCat)
	{
		oSubAsset.style.display = (bShow) ? "none" : "block";
		oSubAssetCat.style.display = (bShow) ? "block" : "none";
		// focus code commented as tabindex added
//		if(bShow)
//		{
//			setTimeout(function() {
//				document.getElementById(""+sSubAsset+"_test").focus();
//				//document.getElementById("s"+sSubAsset+"_test").focus();
//				//oSubAssetCat.focus();
//			},50);
//		}
//		else
//		{
//			setTimeout(function() {
//				document.getElementById(""+sSubAsset+"_test").focus();
//				//document.getElementById("s"+sSubAsset+"_test").focus();
//			},50);
//		}
		
		// get previous opened dropdown
		
		var oPrevSAsset = document.getElementById(oGlobal.sPreviousSAsset);
		var oPrevSAssetCat = document.getElementById(oGlobal.sPreviousSAssetCat);
		
		// current and previous asset id is not same then hide
		if(oGlobal.sPreviousSAsset != sSubAsset && oGlobal.sPreviousSAssetCat != sSubAssetCat)
		{
			// hide previous dropdown and display subasset
			if(oPrevSAsset && oPrevSAssetCat)
			{
				oPrevSAsset.style.display = "block";
				oPrevSAssetCat.style.display = "none";
			}
		}
		// store current category dropdown and subasset id
		oGlobal.sPreviousSAsset = sSubAsset;
		oGlobal.sPreviousSAssetCat = sSubAssetCat;
		
		// Deselect previous select Dropdown row, while hiding the category dropdown
		if(bShow == false)
		{
			if(oGlobal.sRowID)
			{
				SelectCategoryRow(oGlobal.sRowID, false);
				delete oGlobal.sRowID;
			}
		}
	}
	else
	{
		ShowJSError(enmErrorType.ObjectNotFound)
	}
}

/* Right Dropdown */

function ShowDrop(sSubAsset, sSubAssetCat, bShow)
{
	// Get a reference to Category table and div
	var oSubAsset, oSubAssetCat;
	oSubAsset = document.getElementById(sSubAsset);
	oSubAssetCat = document.getElementById(sSubAssetCat);
	
	// Objects found then only show hide category table
	if(oSubAsset && oSubAssetCat)
	{
		oSubAsset.style.display = (bShow) ? "none" : "block";
		oSubAssetCat.style.display = (bShow) ? "block" : "none";
		
		// get previous opened dropdown
		var oPrevSAsset = document.getElementById(oGlobal.sPreviousSAsset);
		var oPrevSAssetCat = document.getElementById(oGlobal.sPreviousSAssetCat);
		
		// current and previous asset id is not same then hide
		if(oGlobal.sPreviousSAsset != sSubAsset && oGlobal.sPreviousSAssetCat != sSubAssetCat)
		{
			// hide previous dropdown and display subasset
			if(oPrevSAsset && oPrevSAssetCat)
			{
				oPrevSAsset.style.display = "block";
				oPrevSAssetCat.style.display = "none";
			}
		}
		// store current category dropdown and subasset id
		oGlobal.sPreviousSAsset = sSubAsset;
		oGlobal.sPreviousSAssetCat = sSubAssetCat;
		
		// Deselect previous select Dropdown row, while hiding the category dropdown
		if(bShow == false)
		{
			if(oGlobal.sRowID)
			{
				SelectCategoryRow(oGlobal.sRowID, false);
				delete oGlobal.sRowID;
			}
		}
	}
	else
	{
		ShowJSError(enmErrorType.ObjectNotFound)
	}
}



/**
 * CategoryRollOver specifically handles mouseover and mouseout event of category dropdown rows. The function
 * changes the row background and the magnify glass image also.
 * @param {String} sRowID is the row id on which the event is triggered
 * @param {bool} bHover is used to know whether the event is mouseover or mouseout. Pass 1 / true to indicate 
 * the event is mouseover and pass 0 / false to indicate the event is mouseout
 */
function CategoryRollOver(sRowID, bHover)
{
	// Executes when mouseover event is triggered
	if(bHover)
	{
		// Selects current row
		SelectCategoryRow(sRowID, true);
	}
	// Executes when mouseout event is triggered
	else
	{
		// Deselect only when current row id doesnt match with previous selected row id
		if(sRowID != oGlobal.sRowID)
		{
			// deselect current row
			SelectCategoryRow(sRowID, false);
		}
	}
}

/**
 * SelectCategoryRow 
 * @param {String} sRowID is the row which is to be selected / deselected
 * @param {bool} bSelected is used for selecting / deselecting row. 0/false deselect and 1/true select.
 */
function SelectCategoryRow(sRow, bSelected)
{
	// Get references to these objects from the document
	var oRow, oTD, oImage;
	
	oRow = document.getElementById(sRow)
	oTD = (oRow) ? oRow.getElementsByTagName("td")[0] : null;
	oImage = (oTD) ? oTD.getElementsByTagName("img")[0] : null;
	
	// Object found then select or deselect row
	if(oRow && oTD)
	{
		oRow.style.backgroundColor = (bSelected) ? "#A3C3DA" : "";
		if(oImage)
		{
			if(oImage.className == "magdarkblue" || oImage.className == "magblue")
				oImage.className = (bSelected) ? "magdarkblue" : "magblue";
		}
		
		//if(oImage)
		//	oImage.src = (bSelected) ? "../images/magnifying_glass_blue_1.jpg" : "../images/magnifying_glass_blue.jpg";
	}
	else
	{
		ShowJSError(enmErrorType.ObjectNotFound)
	}
}

function ToggleMagGlass(sShowID, sHideID)
{
	//document.getElementById(sShowID).style.display = "";
	//document.getElementById(sHideID).style.display = "none";
}


/**
 * ShowInfoBubble displays information bubble and disables all the links in the page
 * by creating a transparent div. 
 * @param {object} event is the generic event object.
 * @iAssetID {number} is the SubAssetID
 * @iItemID {number} is the Dropdown item id
 */
function ShowInfoBubble(event, sRowID, sUID)
{
 
    
	/** @For Reference
	 *  img = saitemimg00;
	 *  tr = saitem00
	 */
	
	bfw_uid_hcl = sUID;
	
	document.getElementById("IBDiv").innerHTML="";
	
	// check is infobubble already open
	if(oGlobal.sInfoBubbleID)
	{
	
		// if yes then check current UID matches the opened infobubble
		if(sUID == oGlobal.sInfoBubbleID)
		{
		
			// if yes then hide the info bubble and return;
			HideInfoBubble("IBDiv");
			return;
		}
	}
	
	// store currently opened infobubble id in the global object to track which one is opened
	// note: global variable is deleted in hideinfobubble function
	oGlobal.sInfoBubbleID = sUID;
	
	var sRowID;


	//Animated Overview Asset info bubble then don't select any rows
	if(sRowID)
	{
	
		// If global rowid is null then no need to deselect any rows.
		if(oGlobal.sRowID)
		{
			// Deslect previous selected row only if current rowid and global rowid doesnt match
			if(sRowID != oGlobal.sRowID)
			{
				// pass previous selected row id and false to deselect previous row.
				SelectCategoryRow(oGlobal.sRowID, false);
			}
		}
		// store current row globally
		oGlobal.sRowID = sRowID;
		// Select current row
		SelectCategoryRow(sRowID, true);
	}
	
	
	// Show Loading div indicator to user
	ShowHideLoading(true);
	
	// Store position of the info bubble
	var iMouseX = event.clientX + document.documentElement.scrollLeft;
	
	oGlobal.iXPos = null;
	oGlobal.iYPos = null;
	oGlobal.sArrowID = null;
	oGlobal.iYPosArrow = null;
	oGlobal.iXPosArrow = null;
	//alert(iMouseX);
	
	if(iMouseX >= 35 && iMouseX <= 65)
	{
	//alert("in 1st");
	
		oGlobal.iXPos = 48;
		oGlobal.sArrowID = "lArrow";
		oGlobal.iXPosArrow = oGlobal.iXPos - 16;
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 19;
	}
	else if(iMouseX >= 300 && iMouseX <= 330)
	{
	
	//alert("in 2nd");
		oGlobal.iXPos = 480;
		oGlobal.sArrowID = "lArrow";
		oGlobal.iXPosArrow = oGlobal.iXPos - 16;
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 19;
	}
	else if(iMouseX >= 65 && iMouseX <= 200)
	{
	//alert("in 3rd");
		oGlobal.iXPos = 210;
		oGlobal.sArrowID = "lArrow";
		oGlobal.iXPosArrow = oGlobal.iXPos - 17;
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 19;
	}
	//Added on 19-Sep-08 by Nitu Sharma
	else if(iMouseX >= 201 && iMouseX <= 250)
	{
	//alert("in 3rd");
		oGlobal.iXPos = 210;
		oGlobal.sArrowID = "lArrow";
		oGlobal.iXPosArrow = oGlobal.iXPos - 17;
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 19;
	}
	else if(iMouseX >= 251 && iMouseX <= 300)
	{
	//alert("in new");
		oGlobal.iXPos = 275;
		oGlobal.sArrowID = "lArrow";
		oGlobal.iXPosArrow = oGlobal.iXPos - 17;
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 19;
	}
	else
	{
	
		//alert("in 4th");
		//This is for box alignment
		oGlobal.iXPos = 242;
		//This is for arrow
		oGlobal.sArrowID = "rArrow";
		//This is arrow position
		oGlobal.iXPosArrow = (oGlobal.iXPos  + 515);
		oGlobal.iYPosArrow = (event.clientY + document.documentElement.scrollTop) - 21;
	}
	
	var iPercentage = (event.clientY / document.documentElement.clientHeight) * 100;
	oGlobal.iYPos = (event.clientY - ((375 * iPercentage) / 100)) +  document.documentElement.scrollTop;
	
	//alert("iXPos = " + oGlobal.iXPos + "\r\nFloor iYPos = " + Math.floor(oGlobal.iYPos) + "\r\niYPos = " + oGlobal.iYPos)
	
	//alert(document.getElementById("hiddenFrame"));
	
	
	//var result = $.get("../xml/bfw_search_attributes_response.xml",parseXML);
	//alert("before request");
	//search_soap();
	var qrStr = window.location.search;
	LocalService.callQPCWS_PopUp("bfw_uid$"+bfw_uid_hcl.trim()+"$"+qrStr,parseXML,wsFail);
	
}

function HideInfoBubble(sInfoBubbleID)
{
	// delete this, as we don't need to track the opened info bubble
	// this gets created in ShoInfoBubble function.
	delete oGlobal.sInfoBubbleID;
	
	var oInfoBubble = document.getElementById(sInfoBubbleID);
	var oArrow = document.getElementById(oGlobal.sArrowID);
	
	if(oInfoBubble && oArrow)
	{
		oInfoBubble.style.display = "none";
		oArrow.style.display = "none";
	}
	else
	{
		ShowJSError(enmErrorType.ObjectNotFound)
	}
}

function ShowHideLoading(bShow)
{
//alert("in img");
	var oContainer = document.getElementById("loadingContainer");
	if(oContainer)
	{
	
		oContainer.style.display = (bShow) ? "block" : "none";
		oContainer.style.top = (120 + document.documentElement.scrollTop) + "px";
	}
}
/**/	

var enmErrorType = {
	ObjectNotFound : 1
}
function ShowJSError(iErrorType)
{
	var sError = "";
	
	switch(iErrorType)
	{
		case (enmErrorType.ObjectNotFound):
			sError = "Error: Object not found";
			break;
			
	}
	
	alert(sError);
}

function WindowOpen(sURL)
{
//alert(sURL);

	var iLeft = 0;
	var iTop = 0;
	var iWidth = screen.width - 17; 
	var iHeight = screen.height-160;
	
	// practice exercises
	if( sURL == "c0a8cc3e:e1e567113dd4d50d0-7eca" || 
		sURL == "c0a8cc3e:e1e567113dd4d50d0-7ecc" || 
		sURL == "c0a8cc3e:e1e567113dd4d50d0-7ecb")
	{
		iWidth = 620;
		//iHeight = 530;
		//iTop = 20;
		iLeft = (screen.width/2) - (620/2);
	}
	
	
	var sPath = "Player.aspx?uid="+sURL.trim();
	
	//+"name="+sName;
	var sWndParams = "width="+iWidth+",height="+iHeight+",left="+iLeft+",top="+iTop+",status=yes,toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes";
	var oWnd = window.open(sPath, "", sWndParams);
	if(oWnd)
		oWnd.focus();
}


function ReloadPlayer(sUID)
{
	var iLeft = 0;
	var iTop = 0;
	var iWidth = screen.width - 17; 
	var iHeight = screen.height-160;
	
	// practice exercises
	if( sUID == "c0a8cc3e:e1e567113dd4d50d0-7eca" || 
		sUID == "c0a8cc3e:e1e567113dd4d50d0-7ecc" || 
		sUID == "c0a8cc3e:e1e567113dd4d50d0-7ecb")
	{
		iWidth = 620;
		//iHeight = 530;
		//iTop = 20;
		iLeft = (screen.width/2) - (620/2);
	}
	
	var sPath = "Player.aspx?uid="+sUID.trim();
	location.href = sPath;
	return;
}

function ShowInternalPage(sSubAssetID, iPageNum, sItem)
{
	
	var oForm = document.getElementById("hiddenForm");
	var oSubAssetType = document.getElementById("SubAssetType");
	var oItem = document.getElementById("Item");
	var oPageNum = document.getElementById("PageNum");
	
	/*if(sSubAssetID == "101" && document.getElementById("txtSearch")) //SEARCH
	{
		sItem = document.getElementById("txtSearch").value;
	}*/
	
	var sQueryString =  "SubAssetType=" + sSubAssetID +
						"&Item=" + sItem +
						"&PageNum=" + iPageNum;
	//var sQueryString1 =  "SubAssetType=101" +"&Item=Writing" + "&PageNum=0";
	//alert(sQueryString);
	location.href = "search.aspx?"+sQueryString;
	/*
	oSubAssetType.value = sSubAssetID;
	oItem.value = escape(sItem);
	oPageNum.value = iPageNum;
	*/
	/*
	alert("sSubAssetID = " + sSubAssetID + 
	"\r\nsItemss = " + escape(sItem) + 
	"\r\noPageNum = " + 0);
	*/
	
	//oForm.action = "search.aspx";
	//oForm.method = "post";
	//oForm.submit();
}

function launchAsset(sUID)
{
	//WindowOpen(sUID);
	var sPath = "Player.aspx?uid="+sUID;
  window.open(sPath, "sWndName");
}

// sDummyDivID pass for items which has no drop down
//function KeyPress_InfoBubble(event, sRowID, sUID, iSection, sDummyDivID)
//{
//debugger;
//alert(sRowID);
//	var iKeyCode = (event.which) ?  event.which : event.keyCode;
//	
//	if(iKeyCode != 13)
//	{
//		return;
//	}
//	
//	// check is infobubble already open
//	if(oGlobal.sInfoBubbleID)
//	{
//		// if yes then check current UID matches the opened infobubble
//		if(sUID == oGlobal.sInfoBubbleID)
//		{
//			// if yes then hide the info bubble and return;
//			HideInfoBubble("IBDiv");
//			return;
//		}
//	}
//	
//	// store currently opened infobubble id in the global object to track which one is opened
//	// note: global variable is deleted in hideinfobubble function
//	oGlobal.sInfoBubbleID = sUID;
//	
//	var sRowID;
//	
//	// Animated Overview Asset info bubble then don't select any rows
//	if(sRowID)
//	{
//		// If global rowid is null then no need to deselect any rows.
//		if(oGlobal.sRowID)
//		{
//			// Deslect previous selected row only if current rowid and global rowid doesnt match
//			if(sRowID != oGlobal.sRowID)
//			{
//				// pass previous selected row id and false to deselect previous row.
//				SelectCategoryRow(oGlobal.sRowID, false);
//			}
//		}
//		// store current row globally
//		oGlobal.sRowID = sRowID;
//		// Select current row
//		SelectCategoryRow(sRowID, true);
//	}
//	
//	// Show Loading div indicator to user
//	ShowHideLoading(true);
//	
//	// Store position of the info bubble
//	var iMouseX = event.clientX + document.documentElement.scrollLeft;

//	oGlobal.iXPos = null;
//	oGlobal.iYPos = null;
//	oGlobal.sArrowID = null;
//	oGlobal.iYPosArrow = null;
//	oGlobal.iXPosArrow = null;
//	
//	var oDummyDiv = document.getElementById(sRowID + "_div")

//	var iNewTop, oSACat, oCategItemsDiv;
//	if(sRowID != null)
//	{
//		oSACat = oDummyDiv.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
//		oCategItemsDiv = oDummyDiv.parentNode.parentNode.parentNode.parentNode.parentNode;
//		iNewTop = (oSACat.offsetTop + oCategItemsDiv.offsetTop + oDummyDiv.offsetTop) - oCategItemsDiv.scrollTop;  
//	}
//	else
//	{
//		oDummyDiv = document.getElementById(sDummyDivID)
//		iNewTop = oDummyDiv.offsetTop;
//	}
//	
//	if(iSection == 0)
//	{
//		oGlobal.iXPos = 248;
//		oGlobal.sArrowID = "lArrow";
//		oGlobal.iXPosArrow = oGlobal.iXPos - 16;
//		oGlobal.iYPosArrow = (iNewTop) - 19;
//	}
//	else if(iSection == 1)
//	{
//		oGlobal.iXPos = 480;
//		oGlobal.sArrowID = "lArrow";
//		oGlobal.iXPosArrow = oGlobal.iXPos - 16;
//		oGlobal.iYPosArrow = (iNewTop) - 19;
//	}
//	else
//	{
//		oGlobal.iXPos = 40;
//		oGlobal.sArrowID = "rArrow";
//		oGlobal.iXPosArrow = (oGlobal.iXPos + 515) - 1;
//		oGlobal.iYPosArrow = (iNewTop) - 19;
//	}
//	
//	var iPercentage = (iNewTop / document.documentElement.clientHeight) * 100;
//	oGlobal.iYPos = (iNewTop - ((375 * iPercentage) / 100));
//	
//	//alert("iXPos = " + oGlobal.iXPos + "\r\nFloor iYPos = " + Math.floor(oGlobal.iYPos) + "\r\niYPos = " + oGlobal.iYPos)
//	
//	var oHiddenFrame = document.getElementById("hiddenFrame");
//	if(oHiddenFrame)
//	{
//		oHiddenFrame.src = "InfoBubble.aspx?data=" + sUID;
//	}
//}

//	function NextElement(sRowID)
//	{
//		alert(sRowID);
//		document.getElementById('sa11_test').style.display="block";
//		document.getElementById(sRowID).focus();
//		alert(sRowID);
//	}

function SetTabIndex(iTabIndex)
{
//alert(oGlobal.iTabIndex);
//KeyPress_InfoBubble
    oGlobal.iTabIndex = iTabIndex;
}
function ChangeTabIndex()
{
    var iTempTabIndex = oGlobal.iTabIndex;
    
    // access img
    document.getElementById("bubbleImg").tabIndex = iTempTabIndex+2;
    // access link
    document.getElementById("bubbleLink").tabIndex = iTempTabIndex+3;
    // access close img
    document.getElementById("imgClose").tabIndex = iTempTabIndex+4;
}

function IsFlashInstalled()
{
	var flashinstalled = 0;
	var flashversion = 0;
	MSDetect = "false";
	if (navigator.plugins && navigator.plugins.length)
	{
		x = navigator.plugins["Shockwave Flash"];
		if (x)
		{
			flashinstalled = 2;
			if (x.description)
			{
				y = x.description;
				flashversion = y.charAt(y.indexOf('.')-1);
			}
		}
		else
			flashinstalled = 1;
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			flashinstalled = 2;
			flashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			flashinstalled = 2;
		else
			flashinstalled = 1;
	}
	else
		MSDetect = "true";
		
	
	alert("flashinstalled = " + flashinstalled)
	alert("flashversion = " + flashversion)
}

function ShowInternalPage1(sItem,PageNum,sSubAssetID,node)
{
	//alert("hi");
	//var oForm = document.getElementById("hiddenForm");
	//var oSubAssetType = document.getElementById("SubAssetType");
	//var oItem = document.getElementById("Item");
	//var oPageNum = document.getElementById("PageNum");
	
	/*if(sSubAssetID == "101" && document.getElementById("txtSearch")) //SEARCH
	{
		sItem = document.getElementById("txtSearch").value;
	}*/
		//var oPageNum = document.getElementById("PageNum");
	var sQueryString =  "Item=" + sItem +"&PageNum="+PageNum+"&SubAssetType=" + sSubAssetID+"&node="+node ;

	//var sQueryString1 =  "SubAssetType=101" +"&Item=Writing" + "&PageNum=0";
	//alert(sQueryString);
	location.href = "search1.aspx?" + sQueryString;
	/*
	oSubAssetType.value = sSubAssetID;
	oItem.value = escape(sItem);
	oPageNum.value = iPageNum;
	*/
	/*
	alert("sSubAssetID = " + sSubAssetID + 
	"\r\nsItemss = " + escape(sItem) + 
	"\r\noPageNum = " + 0);
	*/
	
	//oForm.action = "search.aspx";
	//oForm.method = "post";
	//oForm.submit();
}


 

function parseXML(result)
{


     try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e)
    {
    alert(e.message);
    return;
    }
  }
    
    xmlDoc.async=false;
    xmlDoc.load("../xml/ImageMap.xml");
    var data = xmlDoc.getElementsByTagName('node');
    var imgattrname="";
    for(var i=0;i<data.length;i++)
        {
            
            var attrName = ''+data[i].getAttribute('bfw_uid'); 
            
            
            if(bfw_uid_hcl.trim() ==attrName.trim())
            {
                
                imgattrname = ''+data[i].getAttribute('url'); 
            }
        
          
        }
        
       var oHiddenFrame = document.getElementById("hiddenFrame");
      if(oHiddenFrame)
	{
	
	//window.open("http://localhost:1491/ReWritingPlus/aspx/InfoBubble.aspx?data=" + sUID);
	
    
     oHiddenFrame.src ="InfoBubble.aspx?data=" + bfw_uid_hcl;
   //oHiddenFrame.src="http://www.google.com";
	//var test=document.getElementById("oHiddenFrame");
	
	}  
    //result = result.replace(/imageText/g,imgattrname);
    document.getElementById("IBDiv").innerHTML = result;
    
}

function search_soap()
{
      
      LocalService.callQPCWS_PopUp("bfw_uid$"+bfw_uid_hcl,parseXML,wsFail);
        
 }


function wsFail(res)
{
    alert('Web service failed reason : ' + res);
}