﻿// JScript File

// Cookie code

    /*
       name - name of the cookie
       value - value of the cookie
       [expires] - expiration date of the cookie
         (defaults to end of current session)
       [path] - path for which the cookie is valid
         (defaults to path of calling document)
       [domain] - domain for which the cookie is valid
         (defaults to domain of calling document)
       [secure] - Boolean value indicating if the cookie transmission requires
         a secure transmission
       * an argument defaults when it is assigned null as a placeholder
       * a null placeholder is not required for trailing omitted arguments
    */

    function setCookie(name, value, expires, path, domain, secure) {
      var curCookie = name + "=" + escape(value) +
          ((expires) ? "; expires=" + expires.toGMTString() : "") +
          ((path) ? "; path=" + path : "") +
          ((domain) ? "; domain=" + domain : "") +
          ((secure) ? "; secure" : "");
      document.cookie = curCookie;
    }


    /*
      name - name of the desired cookie
      return string containing value of specified cookie or null
      if cookie does not exist
    */

    function getCookieNew(name) {
        //alert("into getCookieNew"); 
      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));
    }


    /*
       name - name of the cookie
       [path] - path of the cookie (must be same as path used to create cookie)
       [domain] - domain of the cookie (must be same as domain used to
         create cookie)
       path and domain default if assigned null or omitted if no explicit
         argument proceeds
    */

    function deleteCookie(name, path, domain) {
      //alert("in delete");
      if (getCookieNew(name)) {
        document.cookie = name + "=" +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
      }
    }

    // date - any instance of the Date object
    // * hand all instances of the Date object to this function for "repairs"

    function fixDate(date) {
      var base = new Date(0);
      var skew = base.getTime();
      if (skew > 0)
        date.setTime(date.getTime() - skew);
    }
    

function closeMenu(menus){

	document.getElementById('subMenu1').style.display = "none";
	document.getElementById('subMenu2').style.display = "none";
}

function setUpMenu(){

	tempMenuId = getCookieNew('menuId');
	if(tempMenuId != null){
		menuid = tempMenuId.replace('menu', '');
		menuid = menuid.substring(0, menuid.indexOf(':'));
		//alert('subMenu'+menuid);
		menuOpenClose('subMenu'+menuid);
		menuClick(tempMenuId);
		
	}
}


function menuClick(menuId){

	//alert(menuId + " subMenu1img");
	//clearMenu();
	
	/*if(menuId == "Menu0" || menuId == "menu0")
	{
	document.getElementById(menuId).style.color = 'red';
	//document.getElementById(menuId).className = 'testjsclass';
	document.getElementById(menuId).onmouseover = 'this.style.color=red';
	document.getElementById(menuId).onmouseout = 'this.style.color=red';
	document.getElementById(menuId).style.fontWeight = 'bold';
	}
	else
	{*/
	//document.getElementById(menuId).style.color = '#cada2a';
	document.getElementById(menuId).className = 'selected';

	//document.getElementById(menuId).onmouseover = 'this.style.color=#cada2a';
	//document.getElementById(menuId).onmouseout = 'this.style.color=#cada2a';
	//document.getElementById(menuId).style.fontWeight = 'bold';
	//}
	
	
	//document.getElementById(menuId).class = 'test';
	
	deleteCookie('menuId', '/');
	//set cookie
	//document.cookie = 'menuId = ' + menuId + ';';
	setCookie('menuId', menuId, null, '/');
	//alert("cookie value : " + getCookieNew('menuId'));
	
}
	
function menuOpenClose(menuId){

    //alert(menuId);
	//alert(document.getElementById(menuId).style.display);
	if(document.getElementById(menuId).style.display == "block")
	{
		tempMenuId = getCookieNew('menuId');
		if(tempMenuId == null)
		{
			document.getElementById(menuId).style.display = "none";
			document.getElementById(menuId + "img").src = '../Images/picture-library/brown-arrow-right.gif';
		}
		else
		{
			document.getElementById(menuId).style.display = "none";
			document.getElementById(menuId + "img").src = '../Images/picture-library/brown-arrow-right.gif';
		}
	}
	else if(document.getElementById(menuId).style.display == "none" || document.getElementById(menuId).style.display == "")
	{			
		document.getElementById(menuId).style.display = "block";
		document.getElementById(menuId + "img").src = '../Images/picture-library/blue-arrow-down.gif';
	}
}

function closeAllBut(subMenuId, count){
	//update i<=2; with the total number of submenus
	for(i =1; i<=count; i++){
		if('subMenu'+i != subMenuId){
			document.getElementById('subMenu' + i).style.display = "none";
			document.getElementById("subMenu" + i + "img").src = '../Images/picture-library/brown-arrow-right.gif';
		}
	}
}


