if (window.location.search.indexOf("ignorecookies") == -1) {

	var version = parseInt(navigator.appVersion);

	if (version < 4)

		window.location.href="/browser.html";

}



function getDomain(){

	var p = (location.host.substring(0, location.host.lastIndexOf("."))).lastIndexOf(".");

	var p2 = location.host.lastIndexOf(":");

	p2 = (p2 == -1) ? location.host.length : p2;

	return location.host.substring(p, location.host.length-(location.host.length-p2));

}



function setCookie(name, value, expire) {

   document.cookie = name + "=" + escape(value)  + ';pth=/;domain=' + getDomain();

}



function getCookie(name){

  var result = null;

  var start = document.cookie.indexOf(name + "=");

  if (start != -1){

    start += (name.length + 1);

    end = document.cookie.indexOf(";", start);

    if (end == -1) end = document.cookie.length;

      result = unescape(document.cookie.substring(start, end));

  }

  return result;

}



function validateURL(urlString){return true;}



//added to replace function from navbarloader.js

function popUpWindow(url, width, height, resizable, scrollbars){

	if (arguments.length == 1){

		width = 335;

		height = 370;

		resizable = "yes";

		scrollbars = "yes";

	}else if (arguments.length == 3){

		resizable = "no";

		scrollbars = "no";

	}else if (arguments.length == 4){

		scrollbars = "no";

	}



	var win = window.open(url, "PopUp", "width=" + width + ",height=" + height + ",resizable=" + resizable + ",scrollbars=" + scrollbars + ",menubar=no,toolbar=no,left=20,top=20");

}



// 



function signupForEmail1() {

	var form = document.getElementById("signupForEmailForm");

	var email = form.passedEmail.value;

	//var action = "/commerce/application?namespace=emailexclusive&origin=myMain.jsp&event=link.emailexclusive&passedEmail=" + email;
	var action = "/emailSignup/email.html?passedEmail=" + email;

	form.action = action;

	form.submit();

}



	//FP logic

	if (location.host.indexOf("www2") == -1 && getCookie("home") != "yes")

		setCookie("home", "yes");

	if (location.search.indexOf("fp_redirect=") != -1)

	{	var strURL = unescape(location.search.substr(13,location.search.length));

		if (strURL.indexOf("?") > -1) strURL += "&";

		else strURL += "?";

		strURL += "fp_redirected=1"

		if (validateURL(strURL))

			location.replace(strURL);

	}



today=new Date();

millisecs_in_a_day=86400000;

time_to_expire=14 * millisecs_in_a_day;

expiration = new Date(today.getTime() + time_to_expire);

refer_url = getCookie("referrer");

if (refer_url == null ) {

   document.cookie = 'referrer=none;path=/;domain=www.victoriassecret.com';

   document.cookie = 'referrer=none;path=/;domain=.victoriassecret.com';

}

if (location.search.indexOf("goto=") != -1) {

  newurl_startpos=location.search.indexOf("goto=")+5;

  newurl_endpos=location.search.indexOf("&",newurl_startpos);

  if(newurl_endpos == -1) {

    newurl_endpos = location.search.length;

  }

  newurl=location.search.substring(newurl_startpos,newurl_endpos);

  if (validateURL(unescape(newurl)))

  {

	  refer_startpos=location.search.indexOf("refer=")+6;

	  refer_endpos=location.search.indexOf("&",refer_startpos);

	  if(refer_endpos == -1) {

	    refer_endpos = location.search.length;

	  }

	  if (refer_startpos == refer_endpos) {

	    refer="none";

	  }  else {

	    refer=location.search.substring(refer_startpos,refer_endpos);

	  }

	  setCookie("referrer", unescape(refer),expiration);

	  urlparam_startpos=location.search.indexOf("urlparam=")+9;

	  urlparam_endpos=location.search.indexOf("&",urlparam_startpos);

	  if(urlparam_endpos == -1) {

	    urlparam_endpos = location.search.length;

	  }

  urlparam=location.search.substring(urlparam_startpos,urlparam_endpos);

	  setCookie("urlparam", unescape(urlparam),expiration);	  

	  window.location.replace(unescape(newurl));

  }

}





function SpecialOffer() {

	window.open('/html/popup/SpecialOffer/010208/index.html','','height=380,width=380,scrollbars=no,scrolling=no,left=20,top=20');

	void(0);

}



function popupCenter(theURL,wName,theW,theH) {

  openedWindow = window.open(theURL,wName,'width='+theW+',height='+theH+',left='+((screen.availWidth-8)/2-theW/2)+',top='+(screen.availHeight/2-theH/2-14)+',toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');

}





//----- added from navnar_loader.js



function isNumeric(num){

	for (i=0; i<num.length; i++)

		if (num.charAt(i) < "0" || num.charAt(i) > "9")

			return false;

	return true;

}



function getVSCookie(name){

	var result = "";

	var start = document.cookie.indexOf(name + "=");

	var end;



	if (start != -1){

		start += (name.length + 1);

		end = document.cookie.indexOf(";", start);

		if (end == -1)

			end = document.cookie.length;

		result = unescape(document.cookie.substring(start, end));

	}

	return result;

}



function showWelcomeMessage(homepage_1021) {

	var NavbarCookie = getVSCookie("NAVBAR");

	var nickname = "";

	if (NavbarCookie != "") {

		if (NavbarCookie.lastIndexOf(",") != -1) {

			var item_count = NavbarCookie.substring(NavbarCookie.lastIndexOf(",") + 1, NavbarCookie.length);

		}

		

		if (isNumeric(item_count)) {

			nickname = NavbarCookie.substring(0, NavbarCookie.lastIndexOf(","));

		} else {

			nickname = NavbarCookie;

		}

	} else {

		nickname = NavbarCookie;

	}

	var showheader = false;

	

	if (nickname != "") {
		document.getElementById("signinpart").innerHTML = "<!-- mp_trans_disable_start -->" + nickname + "<!-- mp_trans_disable_end -->" + ", YOU ARE SIGNED IN";//nickname + ", YOU ARE SIGNED IN";
		
		if (homepage_1021 == true) {
		var sign_in_image  = document.getElementById("sign_in_image");
		sign_in_image.src = "/images/common/pagenav/10-21-09_Homepage_Nav/top_nav_sign_out.gif";		
		sign_in_image.height = "33";
		sign_in_image.alt = "sign out";	
		var sign_in_link = document.getElementById("sign_in_link");
		sign_in_link.href = "/commerce/logoff.vs?namespace=main&origin=myMain.jsp&event=link.logout";
		}
		else {
		var sign_in_image  = document.getElementById("sign_in_image");
		sign_in_image.src = "/images/common/pagenav/top_nav_sign_out.gif";		
		sign_in_image.height = "33";
		sign_in_image.alt = "sign out";	
		var sign_in_link = document.getElementById("sign_in_link");
		sign_in_link.href = "/commerce/logoff.vs?namespace=main&origin=myMain.jsp&event=link.logout";
		}
		showheader = true;
	}

	

	if (getVSCookie('SHOPCA') != '') {

		document.getElementById("ca_link").style.display = "block";

		showheader = true;

	}

	

	if (showheader) {

		document.getElementById("header_section").style.display = "block";

	}



}



// --- added from navbar_loader.js (AB Testing Stuff)



var AB_TESTING_ON = true; // whether to turn all of this ab functionality on

var AB_BUCKET; // will be populated by the tagBucket()

var AB_EXPIRATION_DATE = new Date(Date.parse("Mar 4, 2008")); // cookie expiration date

var AB_BUCKET_COUNT = 12;



if (AB_TESTING_ON) {

	tagBucket("abTestBucket",AB_BUCKET_COUNT);

}



function getBucket(bucketsCount) {

	if (!bucketsCount || !isNumeric(bucketsCount))

		bucketsCount = 2;

	return Math.floor(Math.random() * bucketsCount);

}



function tagBucket(cookiename,bucketCount) {

	var bucketCookieValue = getVSCookie(cookiename);

	if (bucketCookieValue == "")

	{		

		// set the cookie (A, B, C, etc) and set the flag indicating that we need to call coremetrics

		bucketCookieValue = String.fromCharCode(getBucket(bucketCount) + 65);

		

		// BASIK: setVSCookie undefined during development.

		

		try

		{

			setVSCookie(cookiename, bucketCookieValue, AB_EXPIRATION_DATE);

		}

		catch ( e )

		{

		}

		

		AB_CALL_COREMETRICS = true;

	}



	// set global variable

	AB_BUCKET = bucketCookieValue;

}



function determinefinaldisplay() {

	var url = document.location.href;

	var pagename = url.substr(url.lastIndexOf("/")+1,url.length);

	if (AB_BUCKET == 'L' && pagename == "index.html") {

//		window.location.replace("indexnew.html");

		alert('redirect to new home page');

	} else {

		if (pagename == "indexnew.html") {

			window.location.replace("indexnew.html");

			alert('redirect to normal home page');

		}

	}

}

