<!--

/*
 * cmtools.js
 * Helper JavaScript Librairy for CoreMetrics Tagging
 *
 */
    ////////////////////////////   
    // CoreMetrics Configuration Parameters
    ////////////////////////////    
    var cm_ClientID = "90271139"; // This Parameter should content Coremetrics ClientID for the Site/Country
	cm_JSFPCookieDomain = "www.inoa.com.sg";  // This Parameter should contain the target production domain name. Ex : www.loreal-pro.fr
    
    ////////////////////////////   
    // CMTools Configuration Parameters
    ////////////////////////////      
    var CoreCM_CallDefaultTagging = true; // This parameter should be set to false, when coremetrics tagging is performed directly within the pages (either using Shared Webbox, or using explicit Coremetrics function calls). When using the "Automated implementation" with the tagging plan defined in the CMTools.js file, it should be set to true
    var CoreCM_Hosts = "www.inoa.com.sg"; // This parameter is used to identify whether we are on the Production site, or in integration or  validation
        // We can add severals url  Ex :  wwww.lorealpro.fr;loreal-pro.fr
        // This parameter is used to automaticaly call cmSetProduction() when on the domain name is in the CoreCM_Hosts
        // IMPORTANT NOTE : on L'Oreal Coremetrics Implementation rolled out in 2009, no test Environnement will be setup by Coremetrics
        // THUS : it is not Mandatory to call cmSetProduction()
    var CoreCM_PageIdWithGet = true; // Page Id is constructed with Querystring parameters or not
    
    ////////////////////////////   
    // Internal Variables
    ////////////////////////////    
    var CoreCM_Url = document.URL;                  //     http://www.cmtest.local/index.html?Param=toto
    var CoreCM_PathName = window.location.pathname; //    /index.html
  
  
    ////////////////////////////   
    // Main Function Call
    ////////////////////////////    
    CoreCM_Main();
      
   //Main function of CoreMetrics
    function CoreCM_Main(){         
         CoreCM_SetProduction();   
         if (CoreCM_CallDefaultTagging)
         {
            CoreCM_SetTagging();
         }            
    }


   //Set the CoreMetrics tagging function
    function CoreCM_SetTagging(){
         
      if(CoreCM_Url.indexOf('inoa') !=-1){
			
			
			if(CoreCM_Url.indexOf('page=dispatch') !=-1)
				{
					//alert(CoreCM_GetVarFromGet2("page"));
					//cmCreatePageviewTag(CoreCM_GetVarFromGet2("page"), "INOA",  null, null);
					cmCreatePageviewTag("dispatch", "INOA_SG",  null, null);
				}
				else if (CoreCM_Url.indexOf('page=intro') !=-1)
				{
					cmCreatePageviewTag("intro", "INOA_SG",  null, null);
				}
				else if (CoreCM_Url.indexOf('page=home') !=-1)
				{
					cmCreatePageviewTag("home", "INOA_SG",  null, null);
				}
		}
			////////////////////////////
      //End CoreMetrics Tagging
      ////////////////////////////
      
    }
    
    
    
    //Set the default CoreMetrics tagging function
    function CoreCM_SetDefaultTagging(){
    
      if(CoreCM_PageIdWithGet){
            cmCreatePageviewTag(CoreCM_getPageIDWithGet(), CoreCM_getCategoryIDFromPath(), null, null);
         }
         else{
            cmCreatePageviewTag(null, null, null, null);
         }
    }


    //Url of the current Page (With the Get Parameters)
    function CoreCM_getPageIDWithGet(){
    
      var strUrlRacine = window.location.pathname; //  _fr/_fr/default.aspx
      var strUrlGet = window.location.href;        //    http://wwwMonDomain.com/ fr/_fr/default.aspx?GetParams
      
      
      // eliminates everything before "?"
    	var tempIndex1 = strUrlGet.indexOf("?");
    	if (tempIndex1 != -1) {
    		strUrlGet = strUrlGet.substr(tempIndex1, strUrlGet.length);
    	}
    	else{
        strUrlGet= "";
      } 
      
      // eliminates the first "/" of strUrlRacine
    	var tempIndex2 = strUrlGet.indexOf("/");
    	if (tempIndex2 != 0) {
    		strUrlRacine = strUrlRacine.substr(1, strUrlRacine.length);
    	}

      return strUrlRacine + strUrlGet;
    }


    //Give the GategoryID of the page
    function CoreCM_getCategoryIDFromPath(){
    
      var strUrlRacine = window.location.pathname; //  _fr/_fr/default.aspx
      
      // Keep everything before the last "/"
    	var tempIndex1 = strUrlRacine.lastIndexOf("/");
    	if (tempIndex1 != -1) {
    		strUrlRacine = strUrlRacine.substr(0, tempIndex1 + 1);
    	}
             
      // the following path should be customized to match the naming standard of the CDF CategoryID used with the ASPNetGenerator Console Tool (Export CDF)
      return strUrlRacine.replace("ContentManagerData/Sites/aspnet/","");
    }



    // Get the Category of the product (using the CategoryCode in the GET parameters)
    // Keep everything after the last "^"
    //Permet de recuperer la Categorie de Produit de la page en cours (En recuperant le CategoryCode dans le GET)
    //Recuperation de la partie la plus  droite de "^"
    function CoreCM_GetCatalogCategoryCodeFromGet(nomVariable)
    {
      var CatalogCategoryCode = CoreCM_GetVarFromGet(nomVariable);
      
      // Keep everything after the last "^"
    	var tempIndex1 = CatalogCategoryCode.lastIndexOf("^");
    	if (tempIndex1 != -1) {
    		CatalogCategoryCode = CatalogCategoryCode.substr(tempIndex1+1, CatalogCategoryCode.length);
    	}
    	
    	if (CatalogCategoryCode==null) CatalogCategoryCode = "";
    	return CatalogCategoryCode;
    }

     
     
     
    // Get the title of the current page
    // Remove everything after the first separator (ex : "-")       
    //Permet de recuperer la valeur du Title de la page   
    //Recupere toute la partie  gauche du separateur
    //Si Separator=""  ou null on retourne toute le titre
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromTitle(separator)
    {
       var Elem = document.title;
       if ((Elem=="") || (Elem==null)) return "";
       else{
             if ((separator=="") || (separator==null)) return Elem;
             else{
                  // Remove everything after the first separator (ex : "-")
                	var tempIndex1 = Elem.indexOf(separator);
                	if (tempIndex1 != -1) {
                		Elem = Elem.substr(0, tempIndex1);
                	}
                  return CoreCM_TrimAll(Elem);
             }
       }
     }   
	 
	  // Get the title of the current page
    // Remove everything before the first separator (ex : "-")       
    //Permet de recuperer la valeur du Title de la page   
    //Recupere toute la partie  droite du separateur
    //Si Separator=""  ou null on retourne toute le titre
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromTitleRight(separator)
    {
       var Elem = document.title;
       if ((Elem=="") || (Elem==null)) return "";
       else{
             if ((separator=="") || (separator==null)) return Elem;
             else{
                  // Remove everything after the first separator (ex : "-")
                	var tempIndex1 = Elem.indexOf(separator);
                	if (tempIndex1 != -1) {
						Elem = Elem.substring(tempIndex1+1);
                	}
                  return CoreCM_TrimAll(Elem);
             }
       }
     }   
        
    // Get the innerHTML content of DIV ID='nomVariable' inside the DOM
    // We need to call this function inside addLoadEvent() function otherwise we can't get the value (null)
    //Permet de recuperer une valeur de parametre Div Id='nomVariable' dans le DOM   
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromDiv(nomVariable)
    {
      var Elem = document.getElementById(nomVariable);
      if(Elem != null){
         Elem = Elem.innerHTML;
         if (Elem==null) Elem = "";
      }
      else Elem = "";
      
      return Elem;
     }   
        
    // Get the value content of INPUT ID='nomVariable' inside the DOM    
    // We need to call this function inside addLoadEvent() function otherwise we can't get the value (null)    
    //Permet de recuperer une valeur de parametre Input Id='nomVariable' dans le DOM   
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromInput(nomVariable)
    {
      var Elem = document.getElementById(nomVariable);
      if(Elem != null){
         Elem = Elem.value;
         if (Elem==null) Elem = "";
      }
      else Elem = "";
      
      return Elem;
     }      
    
    // Get the value of tje nomVariable GET parameter     
    //Permet de recuperer une valeur de parametre 'nomVariable' dans le GET   
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromGet(nomVariable)
    {
        var infos = location.href.substring(location.href.indexOf("?")+1, location.href.length)+"&";
        if (infos.indexOf("#")!=-1) infos = infos.substring(0,infos.indexOf("#"))+"&";
        var variable="";
        {
	        nomVariable = nomVariable + "=";
	        var taille = nomVariable.length;
	        if (infos.indexOf(nomVariable)!=-1)
		        variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"));
        }
        return CoreCM_Decode(variable);
    }
	
	// Get the value of tje nomVariable GET parameter     
    //Permet de recuperer une valeur de parametre 'nomVariable' dans le GET   
    //Si variable non trouve retourne ""     		
    function CoreCM_GetVarFromGet2(nomVariable)
    {
        var infos = location.href.substring(location.href.indexOf("#")+1, location.href.length)+"&";
        //if (infos.indexOf("#")!=-1) infos = infos.substring(0,infos.indexOf("#"))+"&";
        var variable="";
        {
	        nomVariable = nomVariable + "=";
	        var taille = nomVariable.length;
	        if (infos.indexOf(nomVariable)!=-1)
		        variable = infos.substring(infos.indexOf(nomVariable)+taille,infos.length).substring(0,infos.substring(infos.indexOf(nomVariable)+taille,infos.length).indexOf("&"));
        }
        return CoreCM_Decode(variable);
    }


    // Decoder la requete HTTP
    // manuellement pour le signe (+)
    function CoreCM_Decode(tChaine) {
      while (true) {
        var i = tChaine.indexOf('+');
        if (i < 0) break;
        tChaine = tChaine.substring(0,i) + '%20' + tChaine.substring(i + 1, tChaine.length);
      }
      
      return decodeURIComponent(tChaine);
    }


    //Return True if the String is not null and not Empty
    function CoreCM_ValidField(strVal){
        if ((strVal=="") || (strVal==null)){
             return false;
             }
        else {
             if( CoreCM_TrimAll(strVal).length != 0){ return true;}
             else {return false;}
        }
    }
    
    //Trim the String
    function CoreCM_TrimAll(sString) 
    {
        if ((sString=="") || (sString==null)) return sString;
        else{
            while (sString.substring(0,1) == ' ')
            {
                sString = sString.substring(1, sString.length);
            }
            
            while (sString.substring(sString.length-1, sString.length) == ' ')
            {
                sString = sString.substring(0,sString.length-1);
            }
            return sString;
        }
    }

   
   
   //Set the CoreMetrics Production Mode depending on the DomainName defined in CoreCM_Hosts
    function CoreCM_SetProduction(){
    
        if(window.location.host.indexOf(CoreCM_Hosts) !=-1){         
        	     cmSetProduction(); // Optionnal Call : we do not need to call the CM function cmSetProduction()
         }
    }
    
    
    // addLoadEvent()
    // Adds event to window.onload without overwriting currently assigned onload functions.
    // Function found at Simon Willison's weblog - http://simon.incutio.com/
    // http://www.huddletogether.com/projects/lightbox/lightbox.js
    // As JavaScript isn't a precompiled language (rather a scripting one), functions, objects and variables are processed 
    // one after another, following the source order. When you declare your variables, the browser is not yet aware of the 
    // existence of the two requested elements.
    function addLoadEvent(func)
    {	
    	var oldonload = window.onload;
    	if (typeof window.onload != 'function'){
        	window.onload = func;
    	} else {
    		window.onload = function(){
    		oldonload();
    		func();
    		}
    	}
    }

//-->

