    // Returns the file name with extension.
       function getFileName(filepath){
          if(filepath!=null && filepath!=''){
              filepath = String(filepath);
              var filename = filepath.substr( filepath.lastIndexOf("/")+1,filepath.length);
	      var temp = filename.split("?");
		if(temp!= null && temp.length > 0){
		   if(temp[0].indexOf("#") != -1){
	   	      var result = temp[0].split("#");
	   	       if(result!= null && result.length > 0){
	   	          return result[0];
  	   	        }
		    }else{
	   	     return temp[0];
		    }
                 }//if-l2
           }// if-l1
      }
      
     // Returns the parameters (if any) present in url 
        function getParameters(filepath){
            if(filepath!=null && filepath!=''){
               var filename = filepath.split('?'); 
               if(filename != null){
         	    return filename[1]; 
         	 }else{
         	    return null;
         	 }
            }
          }
         
    // Checks whether the function's first argument has the second argument string. 
      function hasParam(strFilepath,paramname ){
      	var pattern = "[\\?&]"+paramname+"=([^&#]*)";
      	var regex = new RegExp( pattern );
      	var results = regex.exec(strFilepath.toLowerCase());
      	 if( results == null ){
      	   return false;
          }else{
      	    return true;
      	  }
   }
   
   // Checks whether the key-value pair exits in the given string 
    function checkKeyValue(key,value,paramstring) {
        if(paramstring!= null) {
   	 var params = paramstring.split('&');
   	 var actualValue;
   	 for (var i=0; i<params.length; i++){
   	    actualValue = getValue(key,params[i]);
    	    if(actualValue != null && actualValue == value){
   	        return true;
               }
           }
       }
       return false;
    }
   	  
   
    // If the string has RC name-value pair then return the value;
       function getValue(key,paramstring){
           var arr = paramstring.split('=');
           if(arr.length>1) {
     	      for(var i=0; i<arr.length; i++){
   	         var arg = arr[i].toLowerCase();
   	         if(arg ==key){
   	            return arr[i+1];
   		 }
   	      }
          }
       }
       
   
   //This method checks whether the page URL has flowId,RC and SkinId parameters.
   //If present then it opens FTPC pop-up on page load.
   //NOTE:THIS METHOD SHOUD BE USED ONLY FOR PRODUCTS PAGE.
   
  function launch_ftpc(filepath){
  
      if(filepath == null){
         filepath = window.location.href;
       }
      var filename = getFileName(filepath)
      if(filename == null || filename ==''){
     	return;
      }
      
        //If the page URL has '#nopopup' then don't display any pop-up window
     if (filepath.indexOf("#nopopup") != -1 ) {
      	   return;
      }
     
      var paramstring = getParameters(filepath);
     
     if(filename == 'products-acuvue-oasys-for-presbyopia.htm'){
       	  //CR:4920.Show FTPC with Skin 'S118' if RC is 'Z77'
     	 if(checkKeyValue("rc","Z77",paramstring)){
     	     captureWebtrends();
     	     buildAppWindow("flowId=1&rc=Z77&skinId=S118&promoId=web");
     	     return;
     	 }
     }else if(filename == 'products-acuvue-1day-moist.htm'){
       		//CR#5066
		if (window.location.hash == "#costco") {
		    if (is1DayMoist(paramstring)){
 			buildAppWindow();
    		 	return;		    
		     } else{
		         captureWebtrends();
			 buildAppWindow('flowId=1&rc=Z68&skinId=S116&promoId=TV')
			}
		 } else {
		    if (is1DayMoist(paramstring)){
		     	  buildAppWindow();
    		 	  return;		    
		    }else{
		        var rc= captureWebtrends();
                        if(rc!= null){
                             buildAppWindow('flowId=1&rc='+rc+'&skinId=S117&promoId=web');
                          }
                        else{
		     	    buildAppWindow('flowId=1&rc=Z90&skinId=S117&promoId=TV')
			 }
	           }		    
	       } 
	   return;
     }
     
      if( isValidFTPCUrl(filepath,paramstring)){
            captureWebtrends();
            buildAppWindow(paramstring);
      }
    
 } //end of launch_ftpc


	// NOTE: THIS FUNCTION IS INVOKED FROM 'acuvue-global-header.html' 
    function show_ftpc(filepath){

	    if(filepath == null){
	        filepath = window.location.href;
	     }
	     
             var filename = getFileName(filepath)
	     if(filename == null || filename ==''){
		return;
	     }

	      // If the page URL has '#nopopup' then don't display any pop-up window
	    if (filepath.indexOf("#nopopup") != -1 ) {
		   return;
	     }
	     
	    var launchFTPC = false; 
	    var paramstring = getParameters(filepath);
	    
	    /*if(filename == 'thinking-adult.htm'){
		 var rc= captureWebtrends();
		 if(rc!= null){
		     buildAppWindow('flowId=1&rc='+rc+'&skinId=S112&promoId=TV');
		  } else{
		     buildAppWindow('flowId=1&rc=AA110&skinId=S112&promoId=TV');
		  }
		  return;
	    } else if(filename == 'free-trial-visionDirect.htm'){*/

		if(filename == 'free-trial-visionDirect.htm'){
		       buildAppWindow('flowId=1&rc=Z73&skinId=S119&promoId=TV');
		       return;
	    } else if(filename == 'savemoney.htm'){
		      if(paramstring == null){
			 captureWebtrends();
			 buildAppWindow('flowId=1&rc=TW00&skinId=S107&promoId=TV');
			 return;
		      }
	    } else if(filename == 'twins.htm'){
	    		 captureWebtrends();
		         buildAppWindow('flowId=1&rc=FUN110&skinId=S111&promoId=TV')
		         return;
	    } else if (filename == 'products-ask-acuvue.htm'){
	    		 //CR:5339.Show FTPC with Skin 'S101' if RC is 'Z77'
	    		  if(checkKeyValue("rc","S25",paramstring)){
	    		     captureWebtrends();
	    		     buildAppWindow("flowId=1&rc=S25&skinId=S101&promoId=102");
	    		     return;
	    		  }
	    } else if( filename == 'wearing-eye-health-comfort.htm'||
	    	       filename == 'wearing-eye-health-redness.htm'||
	               filename == 'wearing-apply-remove.htm'      ||
	    	       filename == 'wearing-optimize-vision.htm'   ||	
	    	       filename == 'wearing-tips-travel.htm'       ||
	    	       filename == 'wearing-tips-makeup.htm'       ||
	    	       filename == 'wearing-tips-guides.htm'       ||
	    	       filename == 'wearing-tips-lens-care.htm'    ||
	    	       filename == 'buying-rebates.htm'            ||
	    	       filename == 'buying-getting-started.htm'    ||	
	    	       filename == 'buying-get-contacts.htm'       ||
	    	       filename == 'buying-talk-to-eye-doctor.htm' ||
	    	       filename == 'buying-home.htm'		       ||
	    	       filename == 'buying-cost-insurance.htm'     ||
	    	       filename == 'buying-rebates-launch386-160.htm'||
	               filename == 'vision-myopia.htm'             ||
	               filename == 'vision-hyperopia.htm'          ||
	    	       filename == 'vision-astigmatism.htm'        ||
	    	       filename == 'vision-presbyopia.htm'         ||
	    	       filename == 'vision-performance.htm'        ||
	    	       filename == 'vision-common-problems.htm'	   ||
	    	       filename == 'vision-allergies.htm'          ||
	    	       filename == 'vision-eyes-health.htm'        ||
	    	       filename == 'thinking-whocanwear-ask.htm'   ||
	    	       filename == 'thinking-whocanwear-child.htm' ||
	    	       filename == 'thinking-whocanwear-prevent.htm'||
	    	       filename == 'thinking-whocanwear-snellen.htm'||
	    	       filename == 'thinking-whocanwear-test.htm'  ||
	    	       filename == 'thinking-testimonials.htm'     ||
	    	       filename == 'thinking-why-try.htm'          ||
	    	       filename == 'thinking-myths-main.htm'       ||
	    	       filename == 'thinking-myths-facts.htm'      ||
	    	       filename == 'thinking-myths-faq.htm'        ||
	    	       filename == 'thinking-whocanwear.htm'       ||
	    	       filename == 'thinking-teens.htm'            ||
	    	       filename == 'thinking-child.htm'            ||
	    	       filename == 'thinking-why-ask.htm'          ||
	    	       filename == 'thinking-why-ask-comfort-convenience.htm'||
	    	       filename == 'home-acuminder.htm'		       ||
	    	       filename == 'contact_us.htm'	     	       ||
	    	       filename == 'events-promo.htm'              ||
	    	       filename == 'fair_balance.htm'              ||
	    	       filename == 'our_credo.htm'                 ||
	    	       filename == 'about_us.htm'                  ||
	    	       filename == 'press.htm'                     ||
	    	       filename == 'careers.htm'                   ||
	    	       filename == 'site_map.htm'                  ||
	    	       filename == 'legal_notice.htm'              ||
	    	       filename == 'safe_harbor.htm'               ||
	    	       filename == 'country_list.htm'              ||
	    	       filename == 'privacy_policy.htm'            ||
	    	       filename == 'products-home.htm'             ||
	    	       filename == 'whipit.htm'		               ||
				   filename == 'thinking-adult.htm'               ||
	    	       filename == 'technologies-home.htm')       
	          {
	          
	              captureWebtrends(); //RC tracking by webtrends.
		      launchFTPC = true;
	          } 

            if( launchFTPC && isValidFTPCUrl(filepath,paramstring) ){
                 buildAppWindow(paramstring); //Irrespective of function call's param,this method tries to extract param string from page url and uses it
	         return;
	     }
  }


function isValidFTPCUrl(filepath, paramstring){
  if(paramstring == null || paramstring=='' ){
      return false;
  }
  var result1 = hasParam(filepath, "flowid");
  var result2 = hasParam(filepath, "rc");
  var result3 = hasParam(filepath, "skinid");
  var result4 = checkKeyValue("flowid","1", paramstring);
        
  if(result1 && result2 && result3 && result4){
       return true;
    }else {
     	return false;
    }
}

//CR#5066
//Costco "products-acuvue-1day-moist.htm"
function is1DayMoist(paramstring) {
	if(paramstring != null && paramstring != '') {
		var params = paramstring.split('&');
		var thisIs1DayMoist = false;
		//var flow = false;	
		for(var i=0; i<params.length; i++){
			if(params[i] =='flowId=1'){
				//capture webtrends    
				captureWebtrends();
				//show ftpc flyout
				thisIs1DayMoist = true;		
				break;		    	        
			}//end if
		}//end for
		if(thisIs1DayMoist){
			return true;
		}else{
			   return false;
		}//edn elseif
   }//end if
   
}//end function

   
//If the string has RC name-value pair then return the value;
function getRCValue(key,param){
	var arr = param.split('=');
    if(arr.length>1) {
    	for(var i=0; i<arr.length; i++){
   	    	var arg = arr[i].toLowerCase();
	    	if(arg==key){
		  		return stripHash(arr[i+1]);
	    	}else{
		    	return null;
			}//end if
   		}//end for
	}//end if
}//end function    


function stripHash(arg){

  if(arg != null && arg != '') {
      if (arg.indexOf("#") == -1 ) {
       	  return arg;
       } else {
      	   var arr = arg.split('#');
     	   if(arr.length>1) {
    	      return arr[0];
    	    }
       }
   }
}


//CR#5111
//this function will work for page onclick event only.
//it will capture the rc value, form the url example -
//1 : "http://vusjadwdevel.na.jnj.com/buying-get-contacts.htm?rc=AA76" [ only with rc value ]
//2 : "http://vusjadwdevel.na.jnj.com/buying-get-contacts.htm?flowId=1&rc=AA76&skinId=S101&promoId=102" [ with all the params ]
//3 : "http://vusjadwdevel.na.jnj.com/buying-get-contacts.htm" [ without any params ]
//CR#5165
//  : Any product page should launch the ftpc flyout, this function is used on the FTPC tout in LeftNav, if the url has rc with product id also
//4 :  "http://vusjadwdevel.na.jnj.com/products-acuvue-oasys-for-astigmatism.htm?ProdId=4"  
//5 :  "http://vusjadwdevel.na.jnj.com/products-acuvue-oasys-for-astigmatism.htm?ProdId=4&tabId=2"  
//6 :  "http://vusjadwdevel.na.jnj.com/products-acuvue-oasys-for-astigmatism.htm?ProdId=4&rc=AA188"  
//7 :  "http://vusjadwdevel.na.jnj.com/products-acuvue-oasys-for-astigmatism.htm?ProdId=4&tabId=2&rc=AA188"  
//8 :  "http://vusjadwdevel.na.jnj.com/products-acuvue-oasys-for-astigmatism.htm?ProdId=4&tabId=2&rc=AA188&flowId=.... rest of the param's"  
function onclick_ftpc(){
    //this grabs params from redirect link
    var curURL = window.location.href;
    var vars = curURL.split('?');
    var showFTPCWindow=false;
    if(vars.length>1) {
		var params = vars[1].split('&');
		// this tells the page to only open app 
		if (params != null){
			for(var i=0; i<params.length; i++){
				var strVal = params[i];
				var urlFirstVal = strVal.substr(0,2);
				if (urlFirstVal == 'rc'){
			    	var rcVal = getRCValue('rc',strVal);	    				
					if ( rcVal != null ){
					  	//capture webtrends value
						_tag.WT.mc_id=rcVal;
						_tag.dcsMultiTrack("_tag.WT.mc_id",rcVal);
						var targetURL = "flowId=1&rc="+rcVal+"&skinId=S101&promoId=102";
						buildAppWindow(targetURL);			
					}					
				} else { // checks if the url has all parameters.
                	if(hasParamVal(curURL)){
						showFTPCWindow=true;
						//capture webtrends value for RC
						captureWebtrends();
						break;
				  	}else{ //added for CR#5165
				  	    // For the product pages which has ProdId as the url param
				  	    if ( hasProdIDParam(curURL) ){
							//capture webtrends value for RC
							var rcVal = captureWebtrends();	    				
							if ( rcVal != null ){
								var targetURL = "flowId=1&rc="+rcVal+"&skinId=S101&promoId=102";
								buildAppWindow(targetURL);											
								break;
							} else{
							    //FTPC flyout will launch withdefault params.
	   							buildAppWindow();
							}	
						}
						//check if the url has web trends param
						if(hasWebtrendsParam(curURL)){
							//capture webtrends value for RC
							var rcVal = captureWebtrends();	    				
							if ( rcVal != null ){
								var targetURL = "flowId=1&rc="+rcVal+"&skinId=S101&promoId=102";
								buildAppWindow(targetURL);											
								break;
							} else{
							    //FTPC flyout will launch withdefault params.
	   							buildAppWindow();
							}							
						}
						break;				  								
				  	}//end ifelse				
				}//end ifelse
			}//end for
		}//end if (param)
		//this will execute when the url has the flowId and all other parameters
		if(showFTPCWindow){
			buildAppWindow(params);					
		}
    }else{
    	//this will execute when page url does not have any url parameters
		//It will show the flyout with default skin and other default values
		//please see app-function.js 
	   	buildAppWindow();
	}//end elseif (vars)
}//end function


//CR#5111
//Checks whether the ftpc url has the parameter and value for flowId and SkinId as these are mandatory for FTPC popup to launch. 
function hasParamVal(strFilepath){
    var pattern="(flowId=1).*(skinId=)";
    var regex = new RegExp( pattern );
    var results = regex.exec(strFilepath);
    if( results == null ){
    	return false;
    }else{
        var isSkinVal = false;
        var vars = strFilepath.split('?');
        var params = vars[1].split('&');
        if (params != null){
			for(var i=0; i<params.length; i++){
				var strVal = params[i];
				var skinVal = getRCValue('skinid',strVal);	    				
				if ( (skinVal != null) && (skinVal.length > 0)){
				    isSkinVal = true;
    				break;
				}//end if
            }//end for
        }//end if    
        if(isSkinVal){
    		return true;				        
        }else{
    		return false;				        
        }//end else
	}//end else
}//end hasParamVal


//CR#5111
//buying-rebate.htm
//to capture the RC value for webtrends and app,
//when the transition of rebates are active
function rebateUrl(url){
    var curURL = window.location.href;
    var vars = curURL.split('?');    
    captureWebtrends();
    if (vars[1] != null) {
	    window.location.href=url+"?"+vars[1];
    } else{
    	window.location.href=url;    
    }
}//end function



//CR#5111
//Capture the webtrends value (RC Value) and return the RC value,
//if present in the query string or it will return null.
function captureWebtrends(){
    var curURL = window.location.href;
    var vars = curURL.split('?');    
    var rcVal = null;
    if(vars.length>1) {
		var params = vars[1].split('&');
		// this tells the page to only open app 
		if (params != null){
			for(var i=0; i<params.length; i++){
				var strVal = params[i];
		    	rcVal = getRCValue('rc',strVal);	    				
				if ( rcVal != null ){
					//capture webtrends value
					_tag.WT.mc_id=rcVal;
					_tag.dcsMultiTrack("_tag.WT.mc_id",rcVal);				
					break;
				}//end if	
			}//end for
		}//end if	
    }//end if
	return rcVal;    
}//end function



//for products pages & iwantcontacts detail page
//CR#5165 - Checks whether the ftpc url has the parameter and value for ProdId, tabId or rc or anyother combination of these id's to launch FTPC flyout.
//CR#5719 - Checks whether the ftpc url has the parameter and value for for cardId or cardId & rc (specifically) to launch FTPC flyout.
function hasProdIDParam(strFilepath){
    var pattern="(ProdId=)|(ProdId=).*(tabId=)|(ProdId=).*(rc=)|(ProdId=).*(rc=).*(tabId=)|(ProdId=).*(tabId=).*(rc=)|(tabId=)|(cardId=)|(cardId=).*(rc=)";
    var regex = new RegExp( pattern );
    var results = regex.exec(strFilepath);
    if( results == null ){
    	return false;
    }else{
    	return true;				        
	}//end else
}//end hasProdIDParam


//CR#5165
//Check url has web trends param
function hasWebtrendsParam(strFilepath){
    var pattern="(WT.)|(WT.).*(rc=)";
    var regex = new RegExp( pattern );
    var results = regex.exec(strFilepath);
    if( results == null ){
    	return false;
    }else{
    	return true;				        
	}//end else
}//end hasProdIDParam





