//*************************************************************************************************************
//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 

//	if (document.getElementById(getCookie("MainMenu")) != null)
//		//alert('MainMenu not null')
//	
//	
//		document.getElementById(getCookie("MainMenu")).parentNode.style.backgroundImage ="url(inc/image/selectTab.jpg)";
//		document.getElementById(getCookie("MainMenu")).style.color='Ivory'

//		var xyz=document.getElementById(getCookie("MainMenu")).parentNode.id
//		//alert(xyz)
//		
//		document.getElementById(xyz).previousSibling.style.backgroundImage="url(inc/image/xplch.jpg)";
//		document.getElementById(xyz).nextSibling.style.backgroundImage="url(inc/image/xprch.jpg)";
//		
//		
//		//------------------------------------------------------------
//		
//    if (getCookie("SubMenu")=='NULL' || getCookie("SubMenu")==null)
//    return 
//    
//	if (document.getElementById(getCookie("SubMenu")) != null)
//		document.getElementById(getCookie("SubMenu")).parentNode.style.background='#c7ddfe'
//		
//		if (getCookie("IsReload")==null || getCookie("IsReload") ==0)
//        {
//            //document.location.reload();toji commented on 25-nov-2008
//            document.cookie="IsReload=1"
//            
//        }
//		else if (getCookie("CndIsReload")==null || getCookie("CndIsReload") ==0)
//        {
//            //document.location.reload();toji commented on 25-nov-2008
//            document.cookie="CndIsReload=1"
//            
//        }
}


//---added by Rafees--------------------
var glvar;
//--------------------------------------

function OnNewPageLoadCND() 
{
    //alert(getCookie("MainMenu"))
    //alert(glvar);
    
    if (getCookie("MainMenu")=='NULL' || getCookie("MainMenu")==null)
    return 

	if (document.getElementById(getCookie("MainMenu")) != null)
	{
		document.getElementById(getCookie("MainMenu")).parentNode.style.backgroundImage ="url(../inc/image/selectTab.jpg)";
		document.getElementById(getCookie("MainMenu")).style.color='Ivory'

		var xyz=document.getElementById(getCookie("MainMenu")).parentNode.id
		
		if (glvar==2)
		{
		    document.getElementById(xyz).previousSibling.style.backgroundImage="url(../inc/image/xprch.jpg)";
		    document.getElementById(xyz).nextSibling.style.backgroundImage="url(../inc/image/xplch.jpg)";
		}
		else
		{
		    document.getElementById(xyz).previousSibling.style.backgroundImage="url(../inc/image/xplch.jpg)";
		    document.getElementById(xyz).nextSibling.style.backgroundImage="url(../inc/image/xprch.jpg)";
		}
	}	
		
}

//
//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"
}


//----------------------------------------------------------------------------------//
//--------------------------Added by Rafees ----------------------------------------//
//----------------------------------------------------------------------------------//
function ontabfocus(obj,sv,path)
{
        document.getElementById(obj).style.backgroundImage="url("+ path +"/image/selectTab.jpg)";
        document.getElementById(obj).style.color="#fffff0"
        if (sv==2)
        {
       document.getElementById(obj).previousSibling.style.backgroundImage="url("+ path +"/image/xprch.jpg)";
		document.getElementById(obj).nextSibling.style.backgroundImage="url("+ path +"/image/xplch.jpg)";
		}
		else
		{
		document.getElementById(obj).previousSibling.style.backgroundImage="url("+ path +"/image/xplch.jpg)";
		document.getElementById(obj).nextSibling.style.backgroundImage="url("+ path +"/image/xprch.jpg)";
		}

}
function onoutfocus(obj,sv,path)
{
    if (QueryString('_hmId')!=null && QueryString('_hmId') != '')
    {
       //if query string contains the id of HeaderLink(the link in the header menu on which we click)
       //then i ckeck whether the id(elements) parents id = to the obj parmater, if so i exit the if 
        if (document.getElementById(QueryString('_hmId')).parentElement.id == obj)
            {
            return;
            }
    
    }
    
        document.getElementById(obj).style.backgroundImage="url("+ path +"/image/tabImg.jpg)";
        if (sv==2)
        {
        document.getElementById(obj).previousSibling.style.backgroundImage="url("+ path +"/image/xprc.jpg)";
		document.getElementById(obj).nextSibling.style.backgroundImage="url("+ path +"/image/xplc.jpg)";
		}
		else
		{
		document.getElementById(obj).previousSibling.style.backgroundImage="url("+ path +"/image/xplc.jpg)";
		document.getElementById(obj).nextSibling.style.backgroundImage="url("+ path +"/image/xprc.jpg)";
		}
		
		//OnNewPageLoad() 

}




function ontabfocusCND(obj,sv)
{
        glvar=sv;
        document.getElementById(obj.id).style.backgroundImage="url(../inc/image/selectTab.jpg)";
        if (sv==2)
        {
       document.getElementById(obj.id).previousSibling.style.backgroundImage="url(../inc/image/xprch.jpg)";
		document.getElementById(obj.id).nextSibling.style.backgroundImage="url(../inc/image/xplch.jpg)";
		}
		else
		{
		document.getElementById(obj.id).previousSibling.style.backgroundImage="url(../inc/image/xplch.jpg)";
		document.getElementById(obj.id).nextSibling.style.backgroundImage="url(../inc/image/xprch.jpg)";
		}

}
function onoutfocusCND(obj,sv)
{
        document.getElementById(obj.id).style.backgroundImage="url(../inc/image/tabImg.jpg)";
        if (sv==2)
        {
        document.getElementById(obj.id).previousSibling.style.backgroundImage="url(../inc/image/xprc.jpg)";
		document.getElementById(obj.id).nextSibling.style.backgroundImage="url(../inc/image/xplc.jpg)";
		}
		else
		{
		document.getElementById(obj.id).previousSibling.style.backgroundImage="url(../inc/image/xplc.jpg)";
		document.getElementById(obj.id).nextSibling.style.backgroundImage="url(../inc/image/xprc.jpg)";
		}
		
		OnNewPageLoadCND() 

}
//----------------------------------------------------------------------------------//
