﻿/* --------------------------------------------------------------------------------
 * Client Name: WLS
 * Project Name: Website Redesign 
 * Module: Web
 * Name: Common.js
 * Purpose: Common Javascript functions of WLS 
 *                   
 * Author: MHA
 * Language: Javascript
 * --------------------------------------------------------------------------------
 *  Change History:
 *  version: 1.0    MHA  01/18/08
 *  version: 1.1    MAZ  10/08/09 added getCookie,getLoginId,hideEditorsPanel function 
 *  Description: Initial Development
 * -------------------------------------------------------------------------------- */
 

 
  function hidePopup(outSideClickCtrlID)
  {
       var outsideControl = document.getElementById(outSideClickCtrlID);
       outsideControl.click();
  }
 
 
 function getCookie(name)
 {
       var cookies = document.cookie;
	   if (cookies.indexOf(name) != -1)
	   {
	        var startpos = cookies.indexOf(name)+name.length+1;
		    var endpos = cookies.indexOf(";",startpos)-1;
		    if (endpos == -2) endpos = cookies.length;		
		    return unescape(cookies.substring(startpos,endpos));
	   }
	   else
	   {
	        return false; // the cookie couldn't be found! it was never set before, or it expired.
	   }
 }
 
 function getLoginId()
 {
       var loggedCookie = getCookie("ecm");
       if (loggedCookie)
       {
           var name = "user_Id";
           var startpos = loggedCookie.indexOf(name)+name.length+2;
           var endpos = loggedCookie.indexOf("&",startpos);
           return unescape(loggedCookie.substring(startpos,endpos));
       }
       else 
           return false;
 }
 
 function hideEditorsPanel() 	
 {
 	   anchors = document.getElementsByTagName('a'); 	
	   for (var i = 0; i < anchors.length; i++) 
	   {
	       var aClass = anchors[i].className;
		   if ((aClass) && (aClass == "EktronEditorsMenuMarker")) 
		   {
		       if(!(getLoginId()>0))
		       {		  	    
		  	       anchors[i].parentNode.removeChild(anchors[i]);
		       }
		   }		 	
 	   }
 }
