
/**
 *  JS Page     : leftnav.js
 *  Author(s)    : Naveen Kumar
 *  Creation Date: Oct 25, 2008
 *  Functionality: This file is for highliting the secondary navigation.
 *  Dependencies : N/A
 *  Copyright    : P&G
 *  Modifications: <Author> <Date> <Description of Modification>
 */


/**
 *	Function : getDivOfURL()
 *	Purpose  : This function is used to get and match the current url with the left navigation.
  *	author	 : Naveen Kumar
 */

  function getDivOfURL(){
  	var selectedId;
   	var pageUrl=(document.getElementById("pageUrl")).value; 
 
	pageUrl=modifyUrl(pageUrl,"articleId"); // Removing the articleId from the page URL
	pageUrl=modifyUrl(pageUrl,"NFRP"); // Removing the NFRP from the page URL

  
 	var totalDiv1=(document.getElementById("totalDiv")).value;
 		for(k=1; k<=totalDiv1; k=k+1)
 		{
  			if(((document.getElementById(k)).getElementsByTagName('a')[0])!=null)
  			{
  				var myURL= (document.getElementById(k)).getElementsByTagName('a')[0].href;
				if(myURL!=null)
				{
					myURL=modifyUrl(myURL,'articleId'); // Removing the articleId from the secondary tab  URL
					myURL=modifyUrl(myURL,'NFRP'); // Removing the NFRP from the secondary tab URL
				}
	 			var lastStringOfMyUrl=getSubStringFromURL(myURL); // shorting the URL
				var lastStringOfPageUrl=getSubStringFromURL(pageUrl); //shorting the URL
				
					if(lastStringOfMyUrl==lastStringOfPageUrl) // mapping the URL If url match
					{
						(document.getElementById("selectedId")).value=k; // storing matching id
							changeBehavior(k); //calling main function
	   						(document.getElementById(k)).style.background="url('/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-expnddotline_pink.gif')     repeat-x bottom #4c1032";
							if((document.getElementById(k)).getElementsByTagName('a')[0]!=null)
							{
     							(document.getElementById(k)).getElementsByTagName('a')[0].style.color="#e73097";
							}
					}
			}

 
			var hiddenSubId=k+"_subDiv"; //working on tersary nav
			var totalSubDiv=(document.getElementById(hiddenSubId)).value; // Number of sub div 

			 for(j=1; j<=totalSubDiv; j=j+1)
			 {
 				var subDivId=k+"_"+j;
 				var myURL= (document.getElementById(subDivId)).getElementsByTagName('a')[0].href;
				myURL=modifyUrl(myURL,'articleId');
				myURL=modifyUrl(myURL,'NFRP');
				 var lastStringOfMyUrl=getSubStringFromURL(myURL);
 				 var lastStringOfPageUrl=getSubStringFromURL(pageUrl);
				
				if(lastStringOfMyUrl==lastStringOfPageUrl)
				{
					(document.getElementById("selectedId")).value=subDivId;
					 changeBehavior(k);// calling main function
   					(document.getElementById(subDivId)).style.background="url('/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-expnddotline_pink.gif')     repeat-x bottom #4c1032";
						if((document.getElementById(k)).getElementsByTagName('a')[0]!=null)
						{
    					 (document.getElementById(k)).getElementsByTagName('a')[0].style.color="#e73097";
     
						}
				}
  			}
	 }
 }// end of getDivOfURL method
  

 /**
 *	Function : changeBehavior()
 *	Purpose  : This function is the main method to change the behavior of Div.
  *	author	 : Naveen Kumar
 */
 
   
 	function changeBehavior(id) 
 	{
		var child=(document.getElementById(id+"_subDiv")).value; // number of subDiv
 		var totalDiv=(document.getElementById("totalDiv")).value;
		
		
		if(child!=0)
		{ //if number of subdiv not zero the expend the div
			 var imagePath = "/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-arrowdown-pink.gif";
    		 (document.getElementById(id)).getElementsByTagName('img')[0].src = imagePath; 
			(document.getElementById(id+"_link")).style.display = "block";
			
		}else{ // if zero then not expend
		     var imagePath = "/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-arrowright-pink.gif";
    		 (document.getElementById(id)).getElementsByTagName('img')[0].src = imagePath; 
			(document.getElementById(id+"_link")).style.display = "none";
		}
			
		// now close all othe div
 		 for(i=1; i<=totalDiv; i++)
 		 {
			if(i!=id)
			{ // except selected div
			(document.getElementById(i)).style.color="#ffffff";
			document.getElementById(i).style.background="url('/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-expnddotline_black.gif') repeat-x bottom #000000";
			var imagePath = "/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-arrow-white.gif";
				if(document.getElementById(i).getElementsByTagName('img')[0]!=null)
				{
				document.getElementById(i).getElementsByTagName('img')[0].src = imagePath; 
				}
			document.getElementById(i+"_link").style.display = "none";
			}
 		}
 	}
 // end of changeBehavior method
 
 
 /**
 *	Function : changeImageOnmouseOut()
 *	Purpose  : This function will work on mouse out on the all secondary nav.
  *	author	 : Naveen Kumar
 */
  function changeImageOnmouseOut(id) 
  {
	 var selectedId=document.getElementById("selectedId").value;
	 	if(id!=selectedId)
	 	{
	 	 document.getElementById(id).style.color="#ffffff";
		 document.getElementById(id).style.background="url('/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-expnddotline_black.gif') repeat-x bottom #000000";
	
			if(document.getElementById(id+"_link"))
			{
			 if((document.getElementById(id+"_link")).style.display == "none")
			 {
	  		  if((document.getElementById(id)).getElementsByTagName('a')[0]!=null)
	 		   {
       			 (document.getElementById(id)).getElementsByTagName('a')[0].style.color="#ffffff";
       			 var imagePath = "/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-arrow-white.gif";
     			 (document.getElementById(id)).getElementsByTagName('img')[0].src = imagePath; 
	      		 }
	 		}
   		 }
 	 }
 }
	 
 // end of changeImageOnmouseOut method	 
 
  /**
 *	Function : changeImageOnmouseOver()
 *	Purpose  : This function will work on mouse over on the all secondary nav.
  *	author	 : Naveen Kumar
 */
	  function changeImageOnmouseOver(id)
	   {
	 	 var selectedId=document.getElementById("selectedId").value;
		  if(id!=selectedId)
		  {
	  	 	document.getElementById(id).style.background="url('/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-expnddotline_pink.gif')     repeat-x bottom #4c1032";
	 	 	if(document.getElementById(id+"_link"))
	 	 	{
	 		  if((document.getElementById(id+"_link")).style.display == "none")
	 		  {
	 	  		 if((document.getElementById(id)).getElementsByTagName('a')[0]!=null)
	 	  		 {
       				 (document.getElementById(id)).getElementsByTagName('a')[0].style.color="#e73097";
       				 var imagePath = "/EukGlobal/core/images/common/secondaryNavigation/NAV-SECONDARY-arrowright-pink.gif";
     				(document.getElementById(id)).getElementsByTagName('img')[0].src = imagePath; 
				}
			}
		}
	 }
	}
	 
	//end of method 
	 
	 
	 
/**
 *	Function : modifyUrl()
 *	Purpose  : This function will be use to modify the url
  *	author	 : Naveen Kumar
 */
	 
   function modifyUrl(myURL,articleId)
   {
	   var stFirst=removeString(myURL,'?'); 
	   var st=getSubStringFromURL1(myURL,'?');
	   var finalst=divide_string(st,articleId);
		  if(finalst.charAt(0)=='&')
		  {
			finalst=finalst.substring(1,finalst.length);
		  }  
		  if(finalst!="")
		  {
	 		 if(stFirst!="")
	 		 {
			  finalst=stFirst+"?"+finalst;
	 	 	 }else
	 	 	 {
	  		 finalst=finalst;
	  		}
	 	   }else
	 	   {
	 		 finalst=stFirst;
	 		 }
	  return finalst;
   }
   
     //end of method 
     
     /**
 *	Function : divide_string()
 *	Purpose  : This function will be use to to divide the string.
  *	author	 : Naveen Kumar
 */
	 
   function divide_string(fullSt,removeSt)
 	{
 	if(fullSt==null)
 	{
 		fullSt="";
 
 }
	var col_array=fullSt.split("&");
	var finalSt="";
	var part_num=0;
	while (part_num < col_array.length)
 {
   var removeStrgFromArray=removeString(col_array[part_num],'=')
  if(removeSt!=removeStrgFromArray){
  finalSt=finalSt+"&"+col_array[part_num];
    }
  part_num+=1;
    }
return finalSt;
 }
function removeString(myURL,charIndex){
var newVar=myURL;
 if(myURL!=null){
  var lastForwardSlace=0;
	lastForwardSlace=myURL.indexOf(charIndex);
   newVar=myURL.substring(0,lastForwardSlace);
 }
    return newVar;
  }
   function getSubStringFromURL1(myURL,charIndex){
	var newVar=myURL;
   var lastForwardSlace=0;
    if(myURL!=null){
		lastForwardSlace=myURL.indexOf(charIndex);
		var lengthOfUrl=myURL.length;
		newVar=myURL.substring(lastForwardSlace+1,lengthOfUrl);
	}
  return newVar;
  }
  
  /**
 *	Function : getSubStringFromURL()
 *	Purpose  : This function is used to get the  last string from the url
  *	author	 : Naveen Kumar
 */
  
 function getSubStringFromURL(myURL)
 {
 	if(myURL!=null)
 	{
 		var lastForwardSlace=0;
 		lastForwardSlace=myURL.lastIndexOf('/');
 		var lengthOfUrl=myURL.length;
 		var lastString=myURL.substring(lastForwardSlace+1,lengthOfUrl);
 		return lastString;
 	}else{
 		return myURL;
 	}
 }
  // end of getSubStringFromURL method