//variable for tracking click event bubble for left navigation
var clicked=false;

/**************************************************************************
Description:   This function will recreate the flyout.

Parameters:    1. pControlid as the id of the Table Cell.
                2. pImageId as the id of the Image.
                3. pImagePath as URL of the Image to be displayed.
                
                
Return value:  None.

--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------

**************************************************************************/ 
function PersistMenu(pControlid,pImageId,pImagePath)
{
	var divMenu1;
	document.getElementById(pImageId).src = pImagePath;
	var DivRef = document.getElementById(pControlid.id);
	divMenu1 = document.getElementById(pControlid.id);
	divMenu1.style.visibility = "visible";	
}


/**************************************************************************
  Description:   This function will hide a the flyout corresponding to the table cell
                 and change the Image of channel.
  
  Parameters:    1. pControlid as the id of the Table Cell.
                 2. pImageId as the id of the Image.
                 3. pImagePath as URL of the Image to be displayed.
                 
                  
  Return value:  None.
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   
  **************************************************************************/ 
function HideMenu(pControlid,pImageId,pImagePath)
{
var str = pControlid.id.substring(5,9);
document.getElementById(pImageId).src = pImagePath;
var divMenu;
var IfrRef = document.getElementById('DivShim');

divMenu = document.getElementById("div" + str);	
divMenu.style.visibility = "hidden";	
IfrRef.style.display = "none";	
}

/**************************************************************************
Description:   This function will hide all the flyouts.

Parameters:    
                
                
Return value:  None.

--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------

**************************************************************************/ 
function HideAllMenu()
{
var Menucount;
var divControl;
var divMenu;
var IfrRef = document.getElementById('DivShim');
	
	for (Menucount = 1;Menucount <= document.getElementById("GNV1_hdnFlyOutCount").value ; Menucount++)
	{
		divControl = "divtd" + Menucount;
		divMenu = document.getElementById(divControl);
		divMenu.style.visibility = "hidden";	
	}
	IfrRef.style.display ="none";
}



/**************************************************************************
Description:   This function Opens the Dialog box for the Channel Structure

Parameters:    ControlID as the id of the Control
				strChannelPath the start path of the Chanel Heirarchy
                
Return value:  Void

--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------

**************************************************************************/
function showChannelSelector(Controlid,strChannelPath,strLanguageRootPath)

{			
var RetVal; 
RetVal = window.showModalDialog("/sc3/Dialogs/ChannelStructure.aspx?ChannelPath="+strChannelPath+"&LanguageRootPath="+strLanguageRootPath,"","dialogHeight: 450px; dialogWidth: 350px;");
populateValue(Controlid,RetVal);
window.event.returnValue = false;
return;
}

/**************************************************************************
  Description:   This function populates the value of the selected channel to the 
				text Box
  Parameters:    ControlID as the id of the Control
				 The ChannelPath to be populated in the string.
                  
  Return value:  Void
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   07/08/2009	     Infosys	           Added null handling for web accessibility
  **************************************************************************/
function populateValue(Controlid,message)
{
	if(message != undefined)
	{
			var elementsCount;
			elementsCount = document.forms('frmMain').elements.length;
			var i
			for(i = 0; i < elementsCount; i++ )
			{
				//Start - MOD - WCAG002
				if(document.forms('frmMain').elements[i] != null && document.forms('frmMain').elements[i].name != null)
				{
					if(document.forms('frmMain').elements[i].name.indexOf(Controlid) != -1  && document.forms('frmMain').elements[i].name.indexOf("txtChannelPath") != -1)
					{
						document.forms('frmMain').elements[i].value = message;
						break;
					}
				}
				//End - MOD - WCAG002
			}
	}
	return;
}

/**************************************************************************
  Description:   This Function is used
  
  Parameters:    ControlID as the id of the Control
				 The ChannelPath to be populated in the string.
                  
  Return value:  Void
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   
  **************************************************************************/
function fnCancel()
{
	window.close();
}



	
/**************************************************************************
Description:   This Function is used to make div style to block depending on condition
				and also aligns the div menu
	
Parameters:    pControlId -  will have the control id for which style has to
				be changed.
				pStyle - will have either >> or << value
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function LeftFlyOut_DivSetVisible(pState,pControlId)
{
	var DivRef = document.getElementById('divv'+pControlId.id.split('_')[1]);
	var tdr = pControlId;
	var pos = FindElementPosition(tdr.id);

	if(pState)
	{
		LeftFlyOut_HideAllMenu();	
		DivRef.style.top = pos[1];
		DivRef.style.left = tdr.offsetLeft + tdr.offsetWidth + pos[0];
		DivRef.style.width=pos[2];
		DivRef.style.display = "block";
		DivRef.style.visibility = "visible";		
	}
	else
	{
		DivRef.style.display = "none";
		DivRef.style.visibility="hidden";
	}
}

	
/**************************************************************************
Description:   This Function is used to make the menu to remain on mouse out
				or over	
	
Parameters:    pControlId -  The div menu id
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function LeftFlyOut_PersistMenu(pControlId)
{
	pControlId.style.visibility = "visible";
	pControlId.style.display="block";
}


/**************************************************************************
Description:   This Function is used to hide the current menu
	
Parameters:    pControlId -  the div menu id which is to be hidden
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
			
**************************************************************************/
function LeftFlyOut_HideMenu(pControlId)
{

	pControlId.style.visibility = "hidden";	
	pControlId.style.display = "none";
}

/**************************************************************************
Description:   This Function hides all the flyouts
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function LeftFlyOut_HideAllMenu()
{	
	var Menucount;
	var divControl;
	var divMenu;
		
	for(Menucount=0;;Menucount++)
	{
		divControl="divvtd"+Menucount;
		divMenu=document.getElementById(divControl);
		if(divMenu)
		{
			divMenu.style.visibility="hidden";
			divMenu.style.display="none";
		}
		else
		{
			break;
		}
	}
}

	
/**************************************************************************
Description:   This Function hides or shows all the flyouts
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function LeftFlyOut_ToggleAll(menuSwitch)
{
	var tbl,tN;

	tbl = document.getElementById("LeftFlyout1_tblNavigation");
	
	tN=tbl.getElementsByTagName("A");

	//make all the rows to be visible or invisible
	for(i=0;i<tN.length;i++){
		if (menuSwitch){
			if(tN[i].className=='clsminusmark'){
				tN[i].className='clsplusmark';
			}
		}else{
			if(tN[i].className=='clsplusmark'){
				tN[i].className='clsminusmark';
			}
		}
		switchNode(tN[i],menuSwitch);
	}
}

/**************************************************************************
Description:   This Function opens or closes a node
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function switchNode(b,menuSwitch) {


	var i,s,c,k,j,tN,hh,vv,w,tJ;
	
	if(clicked){
		clicked=false;
	}else
	{

	
		if(document.getElementById){
			if(b.parentNode && b.parentNode.parentNode){
				tR=b.parentNode.parentNode;
			}else{
				return;
			}
			
			//Close
			if(b.className=='clsminusmark'){
				menuSwitch=0;
				for(i=0;;i++){
					tN = document.getElementById(tR.id+'_'+i);
					if(tN){
						for(j=0;;j++){
							tJ = document.getElementById(tN.id+'_'+j);
							if(tJ){
								toggleVisibility(tJ,menuSwitch);
							}else{
								break;
							}
						}
						toggleVisibility(tN,menuSwitch);
					}else{
						break;
					}
				}
				toggleMark(b,menuSwitch)	
			//Open
			}else{
				menuSwitch=1;
				for(i=0;;i++){
					tN = document.getElementById(tR.id+'_'+i);
					if(tN){
						if(tN.innerHTML.indexOf('clsminusmark')>-1){
							for(j=0;;j++){
								tJ = document.getElementById(tN.id+'_'+j);
								if(tJ){
									toggleVisibility(tJ,menuSwitch);
								}else{
									break;
								}
							}
						}
						toggleVisibility(tN,menuSwitch);
					}else{
						break;
					}
				}
				toggleMark(b,menuSwitch)	
			}
					

		}
	}
}

/**************************************************************************
Description:   This Function hides or shows the node
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function toggleVisibility(tbltd,menuSwitch)
{
	if(tbltd.tagName=="TR"){
		if(menuSwitch){
			hh="block";
			vv="visible";
		}else{
			hh="none";
			vv="hidden";
		}
		tbltd.style.display=hh;
		tbltd.style.visibility=vv;
	}
}

/**************************************************************************
Description:   This Function hides or shows the expand mark
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function toggleMark(tbltd,menuSwitch){
	if(menuSwitch){
 		if(tbltd.className=='clsplusmark'){
			tbltd.className='clsminusmark';
		}else if(tbltd.className=='clsminusmark'){
			tbltd.className='clsplusmark';
		}
	}else{
 		if(tbltd.className=='clsplusmark'){
			tbltd.className='clsminusmark';
		}else if(tbltd.className=='clsminusmark'){
			tbltd.className='clsplusmark';
		}
	}
}

/**************************************************************************
Description:   This Function opens the selected node
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function opennode(selNode){

	var tbl,arrSpan,arrAnchor,arrTD;

	tbl = document.getElementById("LeftFlyout1_tblNavigation");

	arrSpan=tbl.getElementsByTagName("SPAN");
	arrAnchor=tbl.getElementsByTagName("A");

	if(arrSpan&&arrSpan.length){
		//make all the rows to be visible 
		for(i=0;i<arrSpan.length;i++){
			if(selNode.indexOf(arrSpan[i].title)>-1){
				switchNode(arrAnchor[i],1);
				arrAnchor[i].parentNode.className+='_Sel'
			}
		}
	}
}

/**************************************************************************
Description:   This Function open the clicked link
	
Parameters:    None
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function doLaunch(link){
	clicked=true;
	if(link != "")
	{
		window.location.replace(link);
	}
}

/**************************************************************************
  Description:  This function is used to display the image clicked 
				in a new dialog window of specific size.
				
  Parameters:   URL of the image
				 
                  
  Return value:  Void
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   
  **************************************************************************/
function renderimages(imageurl)
{
var pImgUrl = imageurl;
//window.showModalDialog("/sc3/Dialogs/ImageDetails.aspx?pImgUrl=" + pImgUrl,"", "dialogHeight:550px; dialogWidth:750px;status:no;help:no");
window.open("/sc3/Dialogs/ImageDetails.aspx?pImgUrl=" + pImgUrl,"", "height=550px; width=750px;status:no;help:no");
window.event.returnvalue=false;
}

/**************************************************************************
  Description:   This function is used to navigate the user to the 
				posting selected.
  Parameters:   Link as the URL of the Control
				 
                  
  Return value:  Void
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   
  **************************************************************************/
function DestinedPosting(link)	
{
	if(link != "")
	{
		window.navigate(link);
	}
}

/**************************************************************************
  Description:   This function is used to display posting 
  
  Parameters:   Control Id
				 
                  
  Return value:  Void
  
  --------------------------------------------------------------------------
  Modifications
  --------------------------------------------------------------------------
   Date              Revised By            Modification Details
   ---------         ----------            --------------------
   
  **************************************************************************/
function DisplayPostingOnChange(controlId)
{
	var elementsCount;
	elementsCount = document.forms('frmMain').elements.length;
	var i;
	var control;
	control = document.getElementById(controlId + "_PresentationModeControlsContainer_cmbChoosePostings");
	
	if (control)
	{
		if (control.value != "")
		{
			window.navigate(control.value);
		} 
	}
}

// The function returns the total offset position (left, top, width, height) 
// of an element, relative to the document. Should be called only after the 
// document body has been loaded.
function FindElementPosition(elementId)
{
	var el,temp;
	var a = new Array();
	
	x=0; y=0;w=0;h=0;
	
	el = document.getElementById(elementId);
	if(el.offsetParent){
		temp = el
		while(temp.offsetParent)
		{ //Looping parent elements to get the offset of them as well
			temp=temp.offsetParent; 
			x+=temp.offsetLeft
			y+=temp.offsetTop;
		}
	}
	x+=el.offsetLeft
	y+=el.offsetTop
	w=el.offsetWidth;
	h=el.offsetHeight;
		
	return [x,y,w,h]
	//Returning the x and y as an array
}

	
/**************************************************************************
Description:   This function gets a control by its id
	
Parameters:    name, value
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
07/21/2009	  Infosys		Changes for Web Accessibility	
**************************************************************************/
function getControl(controlId)
{
	var elementsCount;
	var i;
	elementsCount = document.forms('frmMain').elements.length;
	for(i = 0; i < elementsCount; i++ )
	{
		//Start - MOD - WCAG002
		if(document.forms('frmMain').elements[i] != null)
		{
			if(document.forms('frmMain').elements[i].name != null)
			{
				if(document.forms('frmMain').elements[i].name.indexOf(controlId) != -1)
				{
					return document.forms('frmMain').elements[i];
					break;
				}
			}
		}
		//End - MOD - WCAG002
	}
	return;
}

/**************************************************************************
Description:   This function opens the CMS browse window
	
Parameters:    control id
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function onClickBrowse(txtCtrlID)
{
	var retVal; 
	var strURL = getControl(txtCtrlID).value;
	var strDlgRet = window.showModalDialog("/sc3/cms/WebAuthor/Dialogs/InternalLinks/InternalLinks.aspx" + "?NRMODE=Unpublished&wbc_caller=IEModal", 
												strURL, "");
	if (strDlgRet != "Cancel")
	{
		getControl(txtCtrlID).value = strDlgRet;
	}
	window.event.returnValue = false;
	return;
}

/**************************************************************************
Description:   This function create a cookie
	
Parameters:    name, value
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function createCookie(name,value,days)
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

/**************************************************************************
Description:   This function reads a cookie
	
Parameters:    name, value
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/**************************************************************************
Description:   This function sets a cookie
	
Parameters:    name, value
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function eraseCookie(name)
{
	createCookie(name,"",-1);
}


/**************************************************************************
Description:   This function clears the Search text Box
	
Parameters:    status,textbox
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function srchfocus(status,btn){
		btn.value='';
}

/**************************************************************************
Description:   This function sets the Cookie for CTAC and AGTAC courses
	
Parameters:    course Name,Value, Days, classType
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function buyItem(courseName,value,days,classType){

	var oldcookieValue = readCookie(classType);

	var cookieValue = '['+courseName+','+value+'#'+days+']' + oldcookieValue;

	createCookie(classType,cookieValue,1);

}


/**************************************************************************
Description:   This function is the Key down handler for Enter
	
Parameters:    button Object
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function KeyDownHandler(btn){
       // process only the Enter key
       if (event.keyCode == 13)
       {
           // cancel the default submit
           event.returnValue=false;
           event.cancel = true;
           // submit the form by programmatically clicking the specified button
           btn.click();
       }
}


/**************************************************************************
Description:   This function encodes the URL
	
Parameters:    URL String
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
	
**************************************************************************/
function URLencode(sStr) 
{
    return escape(sStr).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

/**************************************************************************
Description:   This function opens up the Email Page to a Friend Popup
	
Parameters:    Popup "source", "width" of popup & "height" of popup, 
				"op1" & "op2" which are optional parameters used for the 
				popup window.
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date			Revised By			Modification Details
--------- 		----------			--------------------
8/10/2005		Juan F Carpio		Created Function for WR#66366
**************************************************************************/
function EmailPagePopup(source, width, height, op1, op2){

	var newWinParams = "width=" + width + ",height=" + height;

	//If the op1 parameter is sent, append it to the parameters variable.
	if(op1 != null)newWinParams += "," + op1;
	//If the op2 parameter is sent, append it to the parameters variable.
	if(op2 != null)newWinParams += "," + op2;
	
	newWin = window.open(source, null, newWinParams);

}

/**************************************************************************
Description:   This function selects the text in the Search text Box
	
Parameters:    status,textbox
			        
Return value:  Void
	
--------------------------------------------------------------------------
Modifications
--------------------------------------------------------------------------
Date              Revised By            Modification Details
---------         ----------            --------------------
02/22/2006        P.C. Nayak            WR#67219- Google Search	
**************************************************************************/
function selectfocus(status,textbox){
		textbox.select();
}