//*************************************************************************************************************
//Program Name : HighlightMenus.js
//Description  : highlights the selected menus
//Company Name : Element K Middle East
//Developer    : Toji Abraham Mathew
//Date Created : 8 August 2006
//Revised On   : 9, 10, 10-Oct, 
//*************************************************************************************************************

//
//This function is used to read the cookie.
//name parameter is the name of the cookie.
//
function getCookie(name) { 
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end)); 
}

//
//return the queryString.
//paramName parameter is the paramater in the querystring collection for which we need to get the value.
//
function QueryString(paramName) 
{
    var gotValue = false
    var queryStrs = window.location.search.substring(1);
    var vars = queryStrs.split("&");
    for (var i=0;i<vars.length;i++)
    {
        var varValue = vars[i].split("=");
        if (varValue[0].toUpperCase() == paramName.toUpperCase()) 
        {
            gotValue = true
            return varValue[1];
        }
    } 
    if (gotValue == false)
        {return ""}
}


//
//this function is used to highlight Top menus(main menus).
//Atag parameter should be set with the id of the selected menu. The id is stored in a cookie
//usually "this" keyword is passed from client as the parameter in Atag
//
function link_onclick(Atag) {
	document.cookie="MainMenu=" + Atag.id
	//alert(getCookie(ttt + "MainMenu"))
}


//
//this function is used to highlight side menus(sub menus).
//Atag parameter should be set with the id of the selected menu. The id is stored in a cookie
//usually "this" keyword is passed from client as the parameter in Atag
//
function SubMnuLink_onclick(Atag) {
//alert('hello')
	document.cookie="SubMenu=" + Atag.id 
	
}

//
//this function is used to highlight Top menus(main menus) as well as side menus(sub menus), when the Top menu is clicked.
//usually "this" keyword is passed for Atag parameter and the clientId of the submenu is passed as refTag
//both ids are stored in a cookie
//
function Main_SubMnuLink_onclick(Atag, refTag) {
	document.cookie="MainMenu="+Atag.id
	document.cookie="SubMenu="+refTag
}

//
//while clicking on a menu, the page will be redirected to the Src page.
//When loading the Src page the page will understand the previosly selected menus from the cookies and highlight them.
//
function OnNewPageLoad() 
{
    //alert(getCookie("MainMenu"))
    
    if (getCookie("MainMenu")=='NULL' || getCookie("MainMenu")==null)
    return //alert('MainMenu is None')

	if (document.getElementById(getCookie("MainMenu")) != null)
		//alert('MainMenu not null')
		//document.getElementById(getCookie("MainMenu")).parentNode.style.color='black'
		//document.getElementById(getCookie("MainMenu")).parentElement.style.background= '#ddecfe' // '#F1F1F1'
		
		//document.getElementById(getCookie("MainMenu")).parentElement.style.backgroundImage="url('..\Image\tabimg.jpg')" 
		
		//--------------------for tab selection---------------------
		//document.getElementById(getCookie("MainMenu")).parentNode.style.background= 'white' //'#F1F1F1'
		//alert(document.getElementById(getCookie("MainMenu")).parentNode.style.background)
	    //document.getElementById(getCookie("MainMenu")).parentNode.style.Height='50'
		//document.getElementById(getCookie("MainMenu")).parentElement.style.borderTop='1 solid black'
		//document.getElementById(getCookie("MainMenu")).parentElement.style.borderLeft='1 solid black'
		//document.getElementById(getCookie("MainMenu")).parentElement.style.borderRight='1 solid black'
		
		//document.getElementById(getCookie("MainMenu")).parentNode.style.borderBottom='5 solid white' //#F1F1F1'  //#F1F1F1
		
		document.getElementById(getCookie("MainMenu")).parentNode.style.borderBottomColor='white' //#F1F1F1'  //#F1F1F1
		document.getElementById(getCookie("MainMenu")).parentNode.style.borderBottomStyle='Solid'
		document.getElementById(getCookie("MainMenu")).parentNode.style.borderBottomWidth='5'
		
		var xyz=document.getElementById(getCookie("MainMenu")).parentNode.id
		//alert(xyz)
		
		document.getElementById(xyz).previousSibling.style.borderBottomColor='white' //#F1F1F1  //#F1F1F1
		document.getElementById(xyz).previousSibling.style.borderBottomStyle='Solid'
		document.getElementById(xyz).previousSibling.style.borderWidth='5'
		
		document.getElementById(xyz).nextSibling.style.borderBottomColor='white' //#F1F1F1'  //#F1F1F1
		document.getElementById(xyz).nextSibling.style.borderBottomStyle='Solid'
		document.getElementById(xyz).nextSibling.style.borderBottomWidth='5'
		
		//------------------------------------------------------------
		
    if (getCookie("SubMenu")=='NULL' || getCookie("SubMenu")==null)
    return //alert('SubMenu is None')
    
	if (document.getElementById(getCookie("SubMenu")) != null)
		document.getElementById(getCookie("SubMenu")).parentNode.style.background='#c7ddfe'
		
		if (getCookie("IsReload")==null || getCookie("IsReload") ==0)
        {
            document.location.reload();
            document.cookie="IsReload=1"
            
        }
		if (getCookie("CndIsReload")==null || getCookie("CndIsReload") ==0)
        {
            document.location.reload();
            document.cookie="CndIsReload=1"
            
        }
}

//
//By default when closing the browser the cookies will be lost,
//but some cases we need to clear the cookie.(eg: while clicking the logout link)
//i am giving a default value as 'NULL' as part of clearing the cookies
//
function clearCookies()
{
document.cookie="MainMenu=NULL"
	document.cookie="SubMenu=NULL"
}
