var env = "prod"; // dev = developement, stage = staging, agenda_stage = staging 2, prod = production 

//This prototype is provided by the Mozilla foundation and is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.indexOf)
{
  Array.prototype.indexOf = function(elt /*, from*/)
  {
	var len = this.length;
	var from = Number(arguments[1]) || 0;
	from = (from < 0)? Math.ceil(from): Math.floor(from);
	if (from < 0)from += len;
	for (; from < len; from++){ if (from in this && this[from] === elt) return from; }
	return -1;
  };
}

var env_prod = 0, env_stage = 1, env_dev = 2;
env = env_prod;

function getEnv() {
  var url = document.location.href.toLowerCase();
  var result = env_prod;
  for (var i = 0; i < 3; i++) {	if (url.indexOf("//" + dynamicDomains[i])>= 0){return i; }}
  for (var i = 0; i < 3; i++) {
		  for (var j=0; j < staticDomains[i].length; j++){
			  if (url.indexOf("//" + staticDomains[i][j])>= 0){  return i;  }
		  }
  }
 return result;
}

dynamicDomains = [];
dynamicDomains[env_prod] = "hk.asia.acuvue.com/";
dynamicDomains[env_stage]= "hk-staging.asia.acuvue.com/";
//dynamicDomains[env_dev]  = "hk-staging2.asia.av.dev.hk.agenda-asia.com/";
dynamicDomains[env_dev]  = "hk.asia.av.dev.hk.agenda-asia.com/";

staticDomains = [];
staticDomains[env_prod] = [];
staticDomains[env_prod][0] = "www.acuvue.com.hk";
staticDomains[env_prod][1] = "acuvue.com.hk";
staticDomains[env_stage] = [];
staticDomains[env_stage][0] = "stage.acuvue.com.hk";
staticDomains[env_dev] = [];
staticDomains[env_dev][0] = "hk.revamp.av.dev.hk.agenda-asia.com";

env = getEnv();
var env_protocol = "http://";
//if (env == env_prod) {        env_protocol = "https://";   }

us_wwwroot = "http://" + staticDomains[env][0] + "/";
wwwroot = "http://" + dynamicDomains[env] + "av/";
sslwwwroot  = env_protocol + dynamicDomains[env] + "av/";
nonSSLwwwroot  = env_protocol + dynamicDomains[env] + "av/";
myacuvueroot = env_protocol + dynamicDomains[env] + "";

wwwroot_dynamic ="http://" + dynamicDomains[env];


// for us server
var usDomainList = new Array();
usDomainList[0] = "www.acuvue.com.hk";
usDomainList[1] = "acuvue.com.hk";


// for sg server
var sgDomainList = new Array();
sgDomainList[0] = "hk.asia.acuvue.com";


var domainProtocal = "http://";
if (document.location.href.toLowerCase().indexOf('https://') ==0)
	domainProtocal = "https://";
var domainPath = document.location.href.toLowerCase().replace('http://',"").replace("https://","");
domainPath = domainPath.substr(0, domainPath.indexOf("/"));

var nonSSLPageListRE = new RegExp('');
var sSLPageListRE = new RegExp('');

nonSSLPageListRE.ignoreCase = true;
sSLPageListRE.ignoreCase = true;
var aspxRE = /.+\.aspx$/i;
var isHttps;
if (window.location.href.match(/^https:.+/i)) isHttps=true;
else isHttps=false;

/*
// prod
var wwwroot = "http://hk.asia.acuvue.com/av/";
var us_wwwroot = "http://www.acuvue.com.hk/";
var sslwwwroot = 'https://hk.asia.acuvue.com/av/';
var nonSSLwwwroot = 'http://hk.asia.acuvue.com/av/';
var siteroot = "";


if (usDomainList.indexOf(domainPath) >= 0)
{
	env = "prod";
	us_wwwroot = "http://" + domainPath + "/";
	siteroot = us_wwwroot;
}
else if (sgDomainList.indexOf(domainPath) >= 0)
{
	env = "prod";
	us_wwwroot = "http://" + usDomainList[0] + "/";	
	siteroot = domainProtocal + domainPath + "/av/";
}
if (env.toLowerCase() == "dev")
{
	wwwroot = "http://hk.asia.av.dev.hk.agenda-asia.com/av/";
	us_wwwroot = "http://www.av.dev.hk.agenda-asia.com/";
	sslwwwroot = 'http://hk.asia.av.dev.hk.agenda-asia.com/av/';
	nonSSLwwwroot = 'http://hk.asia.av.dev.hk.agenda-asia.com/av/';
} 
else if (env.toLowerCase() == "dev1")
{
	wwwroot = "http://hk-staging.asia.av.dev.hk.agenda-asia.com/av/";
	us_wwwroot = "http://hk-staging.www.av.dev.hk.agenda-asia.com/";
	sslwwwroot = 'http://hk-staging.asia.av.dev.hk.agenda-asia.com/av/';
	nonSSLwwwroot = 'http://hk-staging.asia.av.dev.hk.agenda-asia.com/av/';
} 
else if (env.toLowerCase() == "dev2")
{
	wwwroot = "http://hk-staging2.asia.av.dev.hk.agenda-asia.com/av/";
	us_wwwroot = "http://hk-staging2.www.av.dev.hk.agenda-asia.com/";
	sslwwwroot = 'http://hk-staging2.asia.av.dev.hk.agenda-asia.com/av/';
	nonSSLwwwroot = 'http://hk-staging2.asia.av.dev.hk.agenda-asia.com/av/';
} 
else if (env.toLowerCase() == "stage")
{
	wwwroot = "http://hk-staging.asia.acuvue.com/av/";
	us_wwwroot = "http://stage.acuvue.com.hk/";
	sslwwwroot = 'https://hk-staging.asia.acuvue.com/av/';
	nonSSLwwwroot = 'http://hk-staging.asia.acuvue.com/av/';
}
else if (env.toLowerCase() == "agenda_stage")
{
	wwwroot = "http://hk-staging.asia.acuvue.com/av/";
	us_wwwroot = "http://hk-staging.www.av.dev.hk.agenda-asia.com/";
	sslwwwroot = 'http://hk-staging.asia.acuvue.com/av/';
	nonSSLwwwroot = 'http://hk-staging.asia.acuvue.com/av/';
}  
*/


if (env != 0)
{
	if (document.URL.toLowerCase().indexOf(wwwroot) >= 0)
	  siteroot = wwwroot;
	else if (document.URL.toLowerCase().indexOf(us_wwwroot) >= 0)
	  siteroot = us_wwwroot;
}


var nonSSLPageListRE = new RegExp('');
var sSLPageListRE = new RegExp('');


function removeFirstSlash(URL){
	if(URL!=null&&URL.length>0&&URL.charAt(0)=="/")URL=URL.substring(1,URL.length);return URL;
}

function GetQueryStringVal(param)
{
	var q = document.location.search || document.location.hash;
	if(q)
	{
		var startIndex = q.indexOf(param +"=");
		var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
		if (q.length > 1 && startIndex > -1) 
		{
			return q.substring(q.indexOf("=", startIndex)+1, endIndex);
		}
	}
	return "";
}

function getRedirectLink(url)
{
	if (url.match(aspxRE)) {
		if (isHttps)
			return sslwwwroot+url;
		else
			return nonSSLwwwroot+url;
	}
	
	var isSSLPage;	
	if (nonSSLPageListRE!=null && nonSSLPageListRE.toString()!='//' && url.match(nonSSLPageListRE))
		isSSLPage = false;
	else if (sSLPageListRE!=null && sSLPageListRE.toString()!='//' && url.match(sSLPageListRE)) 
		isSSLPage = true;
	else isSSLPage = false;
	
	if (isSSLPage) {
		return sslwwwroot+url
	} else if (!isSSLPage) {
		return nonSSLwwwroot+url
	}
}

function getFullURL(URL){
	if (this.getRedirectLink?true:false){
		return getRedirectLink(URL);
	} else {
		return wwwroot + URL;
	}
}

function getWwwRoot(){
	return ((this.nonSSLwwwroot)?nonSSLwwwroot:wwwroot);
}

/*open popup*/
function openLegalWindow(url) {
	var legalWindow;
	if (legalWindow == null){
		legalWindow = window.open(url,legalWindow,'width=490,height=320,left=0,top=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	}
	else if (legalWindow.closed){
		legalWindow = window.open(url,legalWindow,'width=490,height=320,left=0,top=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	}
	legalWindow.focus();
}

function openPrivacyWindow(url) {
	var privacyWindow;
	if (privacyWindow == null){
		privacyWindow = window.open(url,privacyWindow,'width=490,height=320,left=0,top=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	}
	else if (privacyWindow.closed){
		privacyWindow = window.open(url,privacyWindow,'width=490,height=320,left=0,top=0,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no');
	}
	privacyWindow.focus();
}

function doThisPreload(){
	if (document.images){
		var these_images = new Array('/images/why_roll_left_2020_off.gif','/images/why_roll_left_2020_on.gif','/images/why_roll_left_health_off.gif','/images/why_roll_left_health_on.gif','/images/why_roll_left_trust_off.gif','/images/why_roll_left_trust_on.gif','/images/why_roll_left_cost_off.gif','/images/why_roll_left_cost_on.gif','/images/why_roll_left_pioneer_off.gif','/images/why_roll_left_pioneer_on.gif','/images/why_roll_left_uv_off.gif','/images/why_roll_left_uv_on.gif','/images/why_roll_copy_2020.gif','/images/why_roll_copy_2020.gif','/images/why_roll_copy_2020.gif','/images/why_roll_copy_2020.gif','/images/why_roll_copy_cost.gif','/images/why_roll_copy_health.gif','/images/why_roll_copy_pioneer.gif','/images/why_roll_copy_trust.gif','/images/why_roll_copy_uv.gif','/images/why_roll_top_2020.gif','/images/why_roll_top_health.gif','/images/why_roll_top_trust.gif','/images/why_roll_top_cost.gif','/images/why_roll_top_pioneer.gif','/images/why_roll_top_uv.gif');
		preloadImages(these_images);
	}
}

function preloadDaImages(these_images_array) {
	for(loop = 0; loop < these_images_array.length; loop++){
		var alf_image = new Image();
		alf_image.src = these_images_array[loop];
	}
}

function rollIt(img,newImg) {
	if (document.images) {
		document.images[img].src = newImg;
	}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}

openWin = function(url,name,width,height,xpos,ypos,chrome,scroll,resizable){
  var currentURL = document.URL.toLowerCase();
  
  if (!url.match("referrer"))
  {
    if (currentURL.match("eye_tips.html") ||
        currentURL.match("facts_about_the_sun_and_your_eyes.html") ||
        currentURL.match("ear_your_way_to_healthy_eyes.html") ||
        currentURL.match("cl_definition.html") ||
        currentURL.match("cl_type.html") ||
        currentURL.match("cl_wear_schedule.html") ||
        currentURL.match("cl_debunk_myths.html") ||
        currentURL.match("get_the_right_fit.html") ||
        currentURL.match("cl_tips.html") ||
        currentURL.match("banish_contamination.html") ||
        currentURL.match("why_acuvue.html") ||
        currentURL.match("faq.html") ||
        currentURL.match("pain_in_the_eyes.html") ||
        currentURL.match("the_pink_eye_effect.html") ||
        currentURL.match("the_dry_eye_syndrome.html") ||
        currentURL.match("eye_woes.html") ||
        currentURL.match("acuvue_life/index.html") ||
        //currentURL.match("sitemap.html") ||
        currentURL.match("two_eyes_better_than_four.html") ||
        currentURL.match("computer_vision_syndrome.html") ||
        currentURL.match("ditch_those_glasses.html") ||
        currentURL.match("seeing_in_the_water.html") ||
        currentURL.match("mr_n_mrs_photogenic.html") ||
        currentURL.match("its_in_the_eyes.html") ||
		currentURL.match("aw_eye_makeup.html")		
		)
    {
    /*
      if (url.match("acuvue_selection.html"))
      {
        acuvueSelectionOpenWin();
        return;
      }
      */  
      avlOpenWin(url,name,width,height,xpos,ypos,chrome,scroll,resizable);
      return;
    }
  }
  var x, y, w, h, moveX=0, moveY=0, features="";
  chrome = chrome ? "yes" : "no";
  scroll = scroll ? "yes" : "no";
  resizable = resizable ? "yes" : "no";
  features += "toolbar="+chrome+",location="+chrome+",status="+chrome+",menubar="+chrome;
  features += ",scrollbars="+scroll+",resizable="+resizable;
  if(width) features += ",width="+width;
  if(height) features += ",height="+height;
  if(xpos && window.screen){
    w = window.screen.availWidth;
    width = parseInt(width);
    switch(xpos){
      case "left": x = 0; break;
      case "center": x = (w-width)/2; break;
      case "right": x = w-width; break;
      default: x = xpos;
    }
    features += ",screenX="+x+",left="+x;
    var moveX = x;
  }
  if(ypos && window.screen){
    h = window.screen.availHeight;
    height = parseInt(height);
    switch(ypos){
      case "top": y = 0; break;
      case "middle": y = (h-height)/2; break;
      case "bottom": y = h-height; break;
      default: y = ypos;
    }
    features += ",screenY="+y+",top="+y;
    var moveY = y;
  }
  features +=",left="+moveX+",top="+moveY;
//  openWinReference = window.open('',name,features);
eval("openWinReference = window.open(url, name, features);");  
//  if(moveX || moveY){
 //   // position the window for browsers that don't recognize screenX, screenY
  //  openWinReference.moveTo(moveX,moveY);
//  }
 //   openWinReference = window.open(url,name);
	openWinReference.focus();
}

/*openScroll = function(url,name,width,height){
  openWin(url,name,width,height,false,false,false,"scroll");
}
openCenter = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle");
}
openCenterScroll = function(url,name,width,height){
  openWin(url,name,width,height,"center","middle",false,"scroll");
}
openFull = function(url,name){
  openWin(url,name,false,false,false,false,"chrome","scroll");
}*/


function openNewWindow(URL){ 
  openWin(URL,"nWin",794,600,"center","middle",false,"scroll");
//  newWindow=window.open(URL, 'nWin', 'scrollbars=yes, width=794,height=600'); 
}

function openNewWindow2(URL){ 
window.opener.openWin(URL,"nWin",794,600,"center","middle",false,"scroll");
window.focus();
//  newWindow=window.open(URL, 'nWin', 'scrollbars=yes, width=794,height=600'); 
}

function openENews(URL){ 
	openWin(URL,"eNews",595,400,"center","middle");
}

function trackingPage(_pagename){
	switch (_pagename.toLowerCase()){
	case "whichacuvue":
		openWhichCon('acuvue_care/acuvue_selection.html?fte_stitle='+pageTitleWhichAcuvue);
	break;
	case "quiz1":
		openWin('../acuvue_care/eye_quiz1.html?fte_stitle='+pageTitleStartQuiz1+'&fte_etitle='+pageTitleEndQuiz1,'test',595,400,'center','middle',false,'');
	break;
	case "quiz2":
		openWin('../acuvue_care/eye_quiz2.html?fte_stitle='+pageTitleStartQuiz2+'&fte_etitle='+pageTitleEndQuiz2,'test',595,400,'center','middle',false,'');
	break;
	case "quiz3":
		openWin('../acuvue_care/eye_quiz3.html?fte_stitle='+pageTitleStartQuiz3+'&fte_etitle='+pageTitleEndQuiz3,'test',595,400,'center','middle',false,'');
	break;
	case "news_promotion_teens":
		//teens banner in news & promomotion page;
		window.open('http://realclub.acuvue.com.hk');ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', pageTitlePromotionBanner, vparent_url+'Side_RealClub', 1, '', '', '', '', '');
		//window.open('http://realclub.acuvue.com.hk?fte_stitle='+pageTitlePromotionBanner;,'teens');
	break;
	default:
	break;	
	}
}

function openWhichCon(URL){ 
  var currentURL = document.URL.toLowerCase();
    if (currentURL.match("eye_tips.html") ||
        currentURL.match("facts_about_the_sun_and_your_eyes.html") ||
        currentURL.match("ear_your_way_to_healthy_eyes.html") ||
        currentURL.match("cl_definition.html") ||
        currentURL.match("cl_type.html") ||
        currentURL.match("cl_wear_schedule.html") ||
        currentURL.match("cl_debunk_myths.html") ||
        currentURL.match("get_the_right_fit.html") ||
        currentURL.match("cl_tips.html") ||
        currentURL.match("banish_contamination.html") ||
        currentURL.match("why_acuvue.html") ||
        currentURL.match("faq.html") ||
        currentURL.match("pain_in_the_eyes.html") ||
        currentURL.match("the_pink_eye_effect.html") ||
        currentURL.match("the_dry_eye_syndrome.html") ||
        currentURL.match("eye_woes.html") ||
        currentURL.match("acuvue_life/index.html") ||
        currentURL.match("sitemap.html") ||
        currentURL.match("two_eyes_better_than_four.html") ||
        currentURL.match("computer_vision_syndrome.html") ||
        currentURL.match("ditch_those_glasses.html") ||
        currentURL.match("seeing_in_the_water.html") ||
        currentURL.match("mr_n_mrs_photogenic.html") ||
        currentURL.match("aw_eye_makeup.html") ||
        currentURL.match("its_in_the_eyes.html"))
    {
      if (URL.match("acuvue_selection.html"))
      {
        acuvueSelectionOpenWin();
        return;
      }
      else if (URL.match("interactive/main3.html"))
      {
        interactiveGameOpenWin();
        return;
      }
      else if (URL.match("http://game.2008vision.com/zh/game_index.html"))
      {
        olympicGameOpenWin();
        return;
      }      
    }



if (URL.indexOf("fte_sopener")==-1){
	var sOpener = escape(window.location.href);
	if (sOpener.indexOf(".aspx")!=-1){
		sOpener=sOpener+"/"
	}
	if (URL.indexOf("?")!=-1){
		URL=URL+"&fte_sopener="+sOpener;
	}else{
		URL=URL+"?fte_sopener="+sOpener;
	}
}
URL=us_wwwroot+URL;
//  openWin(URL,"nWin1",420,570,"center","middle");
openWin(URL,"nWin1",640,590,"center","middle");
//   newWindow=window.open(URL, 'nWin1', 'scrollbars=no,width=420,height=570'); 
}

function openWhichCon2(URL){ 
//window.close();
if (URL.indexOf("fte_sopener")==-1){
	var sOpener = escape(window.location.href);
	if (sOpener.indexOf(".aspx")!=-1){
		sOpener=sOpener+"/"
	}
	if (URL.indexOf("?")!=-1){
		URL=URL+"&fte_sopener="+sOpener;
	}else{
		URL=URL+"?fte_sopener="+sOpener;
	}
}
URL=us_wwwroot+URL;
//window.opener.openWin(URL,"nWin1",420,570,"center","middle");
window.opener.openWin(URL,"nWin1",640,590,"center","middle");
window.focus();
}

function openLensAdvisor(URL){
  openWin(URL,'lensAdvisor',640,610,'center','middle',false,'');	
}

function openStoreLocator(URL) {
	URL=wwwroot_dynamic+'av/'+URL;
	window.location = URL;
}

function openTVC(URL){ 
  openWin(URL,"nTVC",400,370,"center","middle");
//   newWindow=window.open(URL, 'nTVC', 'scrollbars=no,width=380,height=360'); 
}

function openForm(URL){ 
URL=getWwwRoot()+URL;
  openWin(URL,"eFPP",613,640,"center","middle",false,"scroll");
//   newWindow=window.open(URL, 'eFPP', 'scrollbars=yes,width=613,height=640'); 
}

function openTrial(URL){ 
  openWin(URL,"nTrial",800,595,"center","middle",false,"scroll");
//  newWindow=window.open(URL, 'nTrial', 'scrollbars=yes,width=613 ,height=450'); 
}

function openCleanStep(URL){ 
  openWin(URL,"nClean",720,480,"center","middle");
//   newWindow=window.open(URL, 'nTrial', 'scrollbars=yes,width=613 ,height=450'); 
}

function openPromotion(URL){ 
  openWin(URL,"nECP",550,555,"center","middle",false,"");
//   newWindow=window.open(URL, 'nTrial', 'scrollbars=no,width=615 ,height=740'); 
}

function openECP(URL){ 
  openWin(URL,"nECP",615,740,"center","middle",false,"scroll");
//   newWindow=window.open(URL, 'nTrial', 'scrollbars=yes,width=615 ,height=740'); 
}

function openSegmnt(URL){ 
  openWin(URL,"nSegment",420,650,"right","top",false,"");
//   newWindow=window.open(URL, 'nTrial', 'scrollbars=yes,width=615 ,height=740'); 
}

function openGuide(page){ 
  openWin(us_wwwroot+"contact-lenses-products/guide/acuvue-user-guides.html","nGuide",624,640,"center","middle",false,"scroll");
//   newWindow=window.open(URL, 'eFPP', 'scrollbars=yes,width=613,height=640'); 
}

function openMoistTestimonial(section){ 
  openWin(us_wwwroot+"contact-lenses-products/acuvue-moist-testimonial.html?testimonial="+section,"nTestimonial",636,520,"center","middle",false,false);
//   newWindow=window.open(URL, 'eFPP', 'scrollbars=yes,width=613,height=640'); 
}

function openMoistEmotionIcon(){ 
  openWin(us_wwwroot+"contact-lenses-products/1dmoist_emotion.html","nEmotion",636,420,"center","middle",false,false);
//   newWindow=window.open(URL, 'eFPP', 'scrollbars=yes,width=613,height=640'); 
}

function openMoistResearch(){ 
  openWin(us_wwwroot+"contact-lenses-products/1dmoist_norub_research.html","nResearch",618,600,"center","middle",false,"scroll");
//   newWindow=window.open(URL, 'eFPP', 'scrollbars=yes,width=613,height=640'); 
}

function downloadEmotionIcon(icon){
		window.location = wwwroot+"contact-lenses-products/moist/icon_download"+icon+".aspx";
}

function openNotice(){
		var URL=wwwroot+"promotions/frequent_purchase.html";
		openWin(URL,"eNotice",613,640,"center","middle",false,"scroll");
}

function SegmntopenerURL(URL){
	if (window.opener!= null) {	
		window.opener.location=URL;
		window.focus();
		return; 
	}else{
		window.location=URL;
		window.focus();
		return; 		
	}
}


function openerURL(URL){
	if (window.opener!= null) {	
		window.opener.location=URL;
		window.opener.focus();
//		window.close();
		return; 
	}else{
		window.location=URL;
		window.focus();
		return; 		
	}
}

function openerURL2(URL){
	URL=getWwwRoot()+URL;	
	if (window.opener!= null) {	
		window.opener.location=URL;
		window.opener.focus();
//		window.close();
		return; 
	}else{
		window.location=URL;
		window.focus();
		return; 		
	}
}

function openURL(URL){
	URL=getWwwRoot()+URL;
	window.location=URL;
}

function writeObject(str){
	document.write(str);
}


function forwardFriendsButton(){
	document.write('<input type="image" src="'+getWwwRoot()+'images/forwardFriends/forwardFriend_btn.jpg" onclick="openForwardFriendsWindow()">');
}

function openForwardFriendsWindow(){
	var path = escape(document.location.pathname);
	var title = escape(document.title);
//	window.open(getWwwRoot()+"common/forwardFriends.aspx?url="+path+"&title="+title, "ForwardFriends", "width=613,height=650,scrollbars=yes");
	openWin(getWwwRoot()+"forms/products/forwardFriends.aspx?url="+path+"&title="+title+"&ec=big5&ub=5","ForwardFriends",613,650,"center","middle",false,"scroll");
	
}

function AjaxHttpPost(urlString, queryString, responseHandler) {
	this.ready = false;
	this.responseText = null;

  var xmlHttpReq = false;
  var self = this;

	self.xmlHttpReq = createAjaxObject();  
  self.xmlHttpReq.open('POST', urlString, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.onreadystatechange = function(){
		if (self.xmlHttpReq.readyState == 4) {
				responseHandler(self.xmlHttpReq.responseText);
		}
  }
  self.xmlHttpReq.send(queryString);
}

function createAjaxObject(){
	var ajaxObj;

	try{
			ajaxObj = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(ex){
		try{
			ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(ex){
			ajaxObj = new XMLHttpRequest();
		}
	}
	
	return ajaxObj;
}

/****************************************************************************************************/
var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the FSCommand messages in a Flash movie.
function index_DoFSCommand(command, args) {
	var indexObj = isInternetExplorer ? document.all.index : document.index;
	eval(command+"('"+args+"');");
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub index_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call index_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}
// Handle all the FSCommand messages in a Flash movie.
function topmenu_DoFSCommand(command, args) {
	var indexObj = isInternetExplorer ? document.all.index : document.index;
	eval(command+"('"+args+"');");
}
// Hook for Internet Explorer.
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
	document.write('<script language=\"VBScript\"\>\n');
	document.write('On Error Resume Next\n');
	document.write('Sub topmenu_FSCommand(ByVal command, ByVal args)\n');
	document.write('	Call topmenu_DoFSCommand(command, args)\n');
	document.write('End Sub\n');
	document.write('</script\>\n');
}

//function goto(URL){
//	alert(URL);
//}
	
function goto(URL){
//alert(URL);
	var _url = URL;
	if (URL.indexOf("?") > -1){
		_url = URL.substring(0,URL.indexOf("?"));
	}
	switch (_url.toLowerCase())
	{
		case "index.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/index.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av1_trueye.html":
			window.location=us_wwwroot+URL;
			break;
		case "forms/promotions/trueye_etrial.aspx":
		  window.location=wwwroot+URL
		  break;
		case "products/av1_moist.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av1_1day.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av2_acuvue2.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av2u_oasys.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av2u_advance.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av1_define.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/products_compare.html":
			openNewWindow(us_wwwroot+URL)
			break;
		case "products/av2usp_advance_astig.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av2u_oasys_astig.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av1_astig.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/av2sp_bifocal.html":
			window.location=us_wwwroot+URL;
			break;
		case "products/guide/acuvue-user-guides.html":
			openGuide();
			break;		
		case "acuvue_care/index.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_care/eyes.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_care/contact_lens.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_care/acuvue.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_care/faq.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/index.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/index.html?sectionid=1":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/index.html?sectionid=2":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/index.html?sectionid=3":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/index.html?sectionid=4":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/eye_tips.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/computer_vision_syndrome.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/mr_n_mrs_photogenic.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/interactive.html":
			window.location=us_wwwroot+URL;
			break;
		case "acuvue_life/interactive/main3.html":
			openWin(us_wwwroot+URL, 'test', 748, 605, 'center', 'middle', false, '');
			break;
		case "about_acuvue/index.html":
			window.location=us_wwwroot+URL;
			break;
		case "about_acuvue/our_credo.html":
			window.location=us_wwwroot+URL;
			break;
		case "about_acuvue/sight_kids.html":
			window.location=us_wwwroot+URL;
			break;
		case "about_acuvue/firstdcl_story.html":
			window.location=us_wwwroot+URL;
			break;
		case "about_acuvue/acuvue_school.html":
			window.location=us_wwwroot+URL;
			break;
		case "common/sitemap.html":
			window.location=us_wwwroot+URL;
			break;
		case "common/legal_notice.html":
			window.location=us_wwwroot+URL;
			break;
		case "common/privacy_policy.html":
			window.location=us_wwwroot+URL;
			break;
		case "forms/promotions/etrial.aspx":
			window.location=getFullURL(URL);
			break;
		case "forms/products/enewsletter_registration.aspx":
			//alert(getFullURL(URL));
			openENews(getFullURL(URL));
			break;
		case "http://www.1daymoist.com.hk/acuvue/1dmoist/research.html":
			window.open(URL)
			break;
		case "http://www.1dayacuvuemoist.com.hk/acuvue/1dmoist/promotion.html":
			window.open(URL)
			break;	
		case "http://www.1dayacuvuemoist.com.hk":
			window.open(URL)
			break;	
		case "http://www.1daymoist.com.hk/acuvue/1dmoist/promotion.html":
			window.open(URL)
			var vparent_url = window.location.href;
			if (vparent_url.indexOf(".html")!=-1)
				vparent_url = vparent_url + "/";
			ni_LoadUrl(vparent_url+'Slot1-Rotation3', 'PromoBanners-Homepage-Slot1-Rotation3');		
			break;
		case "http://realclub.acuvue.com.hk":
			window.open(URL)
			var vparent_url = window.location.href;
			if (vparent_url.indexOf(".html")!=-1)
				vparent_url = vparent_url + "/";
			ni_LoadUrl(vparent_url+'Slot1-Rotation1', 'PromoBanners-Homepage-Slot1-Rotation1');
			break;
		case "http://www.astig.com.hk":
			window.open(URL)
			var vparent_url = window.location.href;
			if (vparent_url.indexOf(".html")!=-1)
				vparent_url = vparent_url + "/";
			ni_LoadUrl(vparent_url+'Slot1-Rotation2', 'PromoBanners-Homepage-Slot1-Rotation2');
			break;
		/*case "http://www.beat-the-blur.com.hk":
			if (URL == "http://www.beat-the-blur.com.hk"){
				window.open(_url, target='_astig');
			}
			if (URL = "http://www.beat-the-blur.com.hk?source=center"){
				window.open(_url, target='_astig');
			};*/
		case "http://www.beat-the-blur.com.hk/new_wearer_video.html":
			if (URL == "http://www.beat-the-blur.com.hk/new_wearer_video.html"){
				window.open(_url, target='_astig'); 
			}
			if (URL == "http://www.beat-the-blur.com.hk/new_wearer_video.html?ac=vid110"){
				window.open(URL, target='_astig');
			};
			break;
		case "myacuvue/login.aspx":
			window.location = wwwroot+URL;		
			break;
		case "interactive_zone/hk_moist_tvc.html":
			openTVC(us_wwwroot+URL);
			break;
		case "interactive_zone/hk_define_tvc.html":
			openTVC(us_wwwroot+URL);
			break;
		case "interactive_zone/hk_toric_tvc.html":
			openTVC(us_wwwroot+URL);
			break;
		case "http://www.define.com.hk":
			window.open(URL)
			break;
		case "http://www.1daymoist.com.hk":
			if (URL == "http://www.1daymoist.com.hk?source=slot2banner2"){
			var vparent_url = window.location.href;
			if (vparent_url.indexOf(".html")!=-1)
				vparent_url = vparent_url + "/";
				ni_LoadUrl(vparent_url+'Slot2-Rotation2', 'PromoBanners-Homepage-Slot2-Rotation2');
			}
			window.open(_url)
		break;
		case "http://oasys.av.dev.hk.agenda-asia.com":
			window.open(URL)
			break;
		case "http://oasys.av.dev.hk.agenda-asia.com/#navigationpath=trial":
			window.open(URL)
			break;		
		case "http://www.oasys.com.hk":
			window.open(URL)
			break;
		case "http://www.oasys.com.hk/#navigationpath=trial":
			window.open(URL)
			break;
		case "http://www.oasys.com.hk/#navigationpath=feature":
			window.open(URL)
			break;
		case "http://www.acuvue.com.hk/blockuv":
			window.open(URL)
			break;
		case "http://hk.asia.acuvue.com/blockuv":
			if (URL == "http://hk.asia.acuvue.com/blockUV"){
				window.open(URL, target='_uv');
			}
			if (URL = "http://hk.asia.acuvue.com/blockUV?source=center"){
				window.open(URL, target='_uv');
			};
			break;
		case "http://hk.asia.acuvue.com/blockuv/#navigationpath=promo":
			window.open(URL, target='_uv');
			break;
		case "http://hk.asia.av.dev.hk.agenda-asia.com/blockuv":
			window.open(URL)
			break;
		case "http://www.1daymoist.com.hk/acuvue/1dmoist/calipromo.htm":
			window.open(URL)
			break;	
		case "http://www.define.com.hk/promotion.html":
			window.open(URL)
			break;
		case "acuvue_care/acuvue_selection.html":
			openWhichCon(URL);
			break;
		case "segmentation/glasses.html":
			openSegmnt(us_wwwroot+URL);
			break;
		case "segmentation/non_acuvue.html":
			openSegmnt(us_wwwroot+URL);
			break;
		case "segmentation/acuvue.html":
			openSegmnt(us_wwwroot+URL);
			break;
		case "myacuvue/demo.html":
			window.location=us_wwwroot+URL;
			break;
		case "promotions/index.html":
			window.location=getFullURL(URL);
			break;
		case "#":
			break;
		case "":
			break;
		default:
			window.location=getFullURL(URL);
			break;
	}
}

function getQueryVariable(variable)
{ 
  var query = window.location.search.substring(1); 
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
  return '';
} 

var pageTitleWhichAcuvue = "";

function ni_eventTrackHit(pageName)
{	
	//handle cross browser js error
	try{
		var title;
		if(getQueryVariable("fte_stitle") == "")
		{	//handle eSurvey
			if(window.opener == null)title = document.title;
			else title = window.opener.document.title;
		}
		else
		{
			title = getQueryVariable("fte_stitle");	
		}
	}catch(ex){
		return;	
	}	
		var temp;		
		if(GetQueryStringVal("fte_sopener") == "")
		{			
			 if(window.opener == null)temp = document.URL;
			 else temp = window.opener.location.href;
		}
		else
		{
			 temp = GetQueryStringVal("fte_sopener");
		}

	if (document.URL.indexOf('?') != -1){
			tempURL = document.URL.substr(0, document.URL.indexOf('?'));
	}
	else{	
			tempURL = document.URL;
	}

	var tempURL = temp.split("//")[1];
	if (tempURL.lastIndexOf("/") != tempURL.length - 1){
		tempURL += "/";
	}
	var trackingURL = "http://" + tempURL + pageName;

	return ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, trackingURL, 1, '', '', '', '', '');
}

function ni_avlTrackHit(pageName)
{
	var trackingURL;
  if (getQueryVariable("referrer") != null && getQueryVariable("referrer") != '')
			trackingURL = getQueryVariable("referrer") + "/";
	else
	{
    if (document.URL.indexOf('?') != -1)
			trackingURL = document.URL.substr(0, document.URL.indexOf('?')) + "/";
		else	
			trackingURL = document.URL + "/";
  }
  //var title = getTrackHitTitle(pageName,trackingURL);
  var title = getTrackHitTitle(pageName,trackingURL);
  //alert("title="+title+ " // URL="+trackingURL + pageName);
  return ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, trackingURL+pageName, 1, '', '', '', '', '');
}

function avlOpenWin(url,name,width,height,xpos,ypos,chrome,scroll,resizable){
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?'));
	else	
		currentURL = document.URL;
	//currentURL = currentURL.replace("#", "");
	url += "?referrer=" + currentURL;
	openWin(url,name,width,height,xpos,ypos,chrome,scroll,resizable);
}

function siteMapOpenWin(URL)
{
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?'));
	else	
		currentURL = document.URL;
	//currentURL = currentURL.replace("#", "");
	url += "?referrer=" + currentURL;
	alert('trap');
	openWin(URL,"nWin",794,600,"center","middle",false,"scroll");
}

function acuvueSelectionOpenWin(){
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?')) + "/";
	else	
		currentURL = document.URL + "/";
		currentURL = currentURL.replace("#", "");
	
	var pageName = "which_acuvue_is_best_for_me";
	var title = getTrackHitTitle(pageName,currentURL);
	//alert("title="+title+ " // URL="+currentURL + pageName);
	if (currentURL.match("sitemap.html"))
	    openWin("../acuvue_life/acuvue_selection.html","nWin1",640,590,"center","middle");
    else
	    openWin("acuvue_selection.html","nWin1",640,590,"center","middle");
	return ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, currentURL+pageName, 1, '', '', '','','');
}

function interactiveGameOpenWin(){
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?')) + "/";
	else	
		currentURL = document.URL + "/";
		currentURL = currentURL.replace("#", "");
	
	var pageName = "the_eye_personality_test";
	var title = "AV Life - Interactive|talking eyes|the_eye_personality_test";
	//alert("title="+title+ " // URL="+currentURL + pageName);
	openWin('../acuvue_life/interactive/main3.html', 'test', 748, 605, 'center', 'middle', false, '');
	return ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, currentURL+pageName, 1, '', '', '','','');
}

function olympicGameOpenWin(){
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?')) + "/";
	else	
		currentURL = document.URL + "/";
		currentURL = currentURL.replace("#", "");
	
	var pageName = "vision_challenge_game";
	var title = "AV Life - Interactive|Vision Challenge Game";
	//alert("title="+title+ " // URL="+currentURL + pageName);
	openWin('http://game.2008vision.com/zh/game_index.html', '', 1015	, 750, 'center', 'middle', false, '');
	return ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, currentURL+pageName, 1, '', '', '','','');
}

function productsCompareOpenWin(){
/*
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?')) + "/";
	else	
		currentURL = document.URL + "/";
	currentURL = currentURL.replace("#", "");	
	var pageName = "product_comparison";
	var title = getTrackHitTitle(pageName,currentURL);
	alert("title="+"productsCompareOpenWin" + " // URL="+currentURL + pageName);	
	ni_TrackHit(global_te_server, global_te_sitecode, '', '', '', '', '', '', title, currentURL+pageName, 1, '', '', '','','');
*/	
	var currentURL;
	if (document.URL.indexOf('?') != -1)
		currentURL = document.URL.substr(0, document.URL.indexOf('?'));
	else	
		currentURL = document.URL;
	//currentURL = currentURL.replace("#", "");
	var targetUrl;
	targetUrl = "../products/products_compare.html" + "?referrer=" + currentURL;
	window.location = targetUrl;
}

function getTrackHitTitle(pageName,trackingURL)
{
  var title = "";
  var currentURL = trackingURL.toLowerCase();
	
		
	if (currentURL.match("facts_about_the_sun_and_your_eyes.html") ||
			currentURL.match("eye_tips.html") ||
			currentURL.match("ear_your_way_to_healthy_eyes.html"))
	{
		title = "AV_Life-Health|Basic_Eye_Anatomy|" + pageName;
	}
	else if (currentURL.match("cl_definition.html") ||
			currentURL.match("cl_type.html") ||
			currentURL.match("cl_wear_schedule.html") ||
			currentURL.match("cl_debunk_myths.html") ||
			currentURL.match("get_the_right_fit.html") ||
			currentURL.match("cl_tips.html") ||
			currentURL.match("banish_contamination.html"))
	{
		title = "AV_Life-Health|About_Contact_Lenses|" + pageName;
	}		

	else if (currentURL.match("why_acuvue.html"))
	{
		title = "AV Life - Health|The Smart Choice|" + pageName;
	}	

	else if (currentURL.match("faq.html"))
	{
		title = "AV Life - Health|The Smart Choice|" + pageName;
	}

	else if (currentURL.match("pain_in_the_eyes.html") ||
			currentURL.match("the_pink_eye_effect.html") ||
			currentURL.match("the_dry_eye_syndrome.html") ||
			currentURL.match("eye_woes.html"))
	{
		title = "AV_Life-Health|Eye_Care|" + pageName;
	}	

	else if (currentURL.match("sitemap.html"))
	{
		title = "Compliance|Footer|" + pageName;
	}

	else if (currentURL.match("two_eyes_better_than_four.html"))
	{
		title = "AV_Life-Lifestyle|lifestyle|" + pageName;
	}	
	else if (currentURL.match("computer_vision_syndrome.html"))
	{
		title = "AV_Life-Lifestyle|Work|" + pageName;
	}	
	else if (currentURL.match("ditch_those_glasses.html"))
	{
		title = "AV_Life-Lifestyle|Play|" + pageName;
	}	
	else if (currentURL.match("seeing_in_the_water.html"))
	{
		title = "AV_Life-Lifestyle|Play|" + pageName;
	}	
	else if (currentURL.match("mr_n_mrs_photogenic.html"))
	{
		title = "AV_Life-Beauty|Photogenic|" + pageName;
	}	
	else if (currentURL.match("its_in_the_eyes.html"))
	{
		title = "AV_Life-Beauty|Makeup|" + pageName;
	}					
	else if (currentURL.match("aw_eye_makeup.html"))
	{
		title = "AV_Life-Beauty|Makeup|" + pageName;
	}
			
	else if (currentURL.match("index.html"))
	{
		if (pageName == "which_acuvue_is_best_for_me" || pageName == "product_comparison")
			title = "AV_Life-Health|Main_Page|" + pageName;
			
		else if (pageName == "eye_quiz_2_start" || pageName == "eye_quiz_2_complete")
			title = "AV_Life-Health|About_Contact_Lenses|" + pageName;			
		
		else if (pageName == "which_acuvue_is_best_for_me" || pageName == "product_comparison" || pageName == "eye_quiz_3_start" || pageName == "eye_quiz_3_complete")
		    title = "AV_Life-Health|The Smart Choice|" + pageName;		
			
		else if (pageName == "eye_diseases" || 
			pageName == "glaucoma" ||
			pageName == "cataract" ||
			pageName == "macular_degeneration" ||
			pageName == "diabetic_retinopathy" ||
			pageName == "hypertensive_retinopathy" ||
			pageName == "multiple_sclerosis")
			title = "AV_Life-Health|Eye_Care|" + pageName;						
			
		else if (pageName == "packing_for_travel")
			title = "AV Life - Lifestyle|Play|" + pageName;						
			
		else
			title = "AV_Life-Health|Basic_Eye_Anatomy|" + pageName;
	}		
		
  return title;
}
