/**START GLOBAL FUNCTIONS**/
rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
	rnd.seed = (rnd.seed*9301+49297) % 233280;
	return rnd.seed/(233280.0);
}
function rand(number) {
	return Math.ceil(rnd()*number);
}


function MM_findObj(n, d) {
  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_preloadImages() {
  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_openBrWindow(theURL,winName,features) {
  var winObj;
  winObj = window.open(theURL,winName,features);
}

function nvp_struct(){
		var args = nvp_struct.arguments;
		this.nvp_qvpair = args[0];
		this.nvp_var = args[1];
		this.nvp_value = args[2];
}

var nvp_array = new Array;
function nvp_parse(){
	var querystring = location.search; nvp = querystring.indexOf('&'); searchstring = "true"; prev_nvp = 1; x = 0;
	do {
	if (nvp == -1){nvp = querystring.length; searchstring = "false";}
	var nvp_qvpair = querystring.substring(prev_nvp, nvp); nvp_var = nvp_qvpair.substring(0, nvp_qvpair.indexOf('=')); nvp_value = nvp_qvpair.substring(nvp_qvpair.indexOf('=')+1);
	nvp_array[x] = new nvp_struct(nvp_qvpair,nvp_var,nvp_value); querystring = querystring.substring(nvp + 1,querystring.length);
	if(querystring == null){searchstring = "false"} else {var prev_nvp = 0;		nvp = querystring.indexOf('&');		x++;}
	} while (searchstring == "true")
}

function nvp_get(){
	var args = nvp_get.arguments; nvpsearch = args[0]; nvpvalue = "noval"; nvp_length = nvp_array.length;
	for (var x = 0; x != nvp_length; x++){
		if(nvp_array[x].nvp_var == nvpsearch){nvpvalue = nvp_array[x].nvp_value};
	}
return nvpvalue;
}

function MM_validateForm() {
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
	if (val) { nm=val.name; if ((val=val.value)!="") {
	  if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
		if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
	  } else if (test!='R') {
		if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
		if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
		  min=test.substring(8,p); max=test.substring(p+1);
		  if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
	} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

var numChars = 250;
function notTooBig() {
		if (document.pcard.message.value.length > numChars+1) {
		document.pcard.message.value = document.pcard.message.value.substring(0,numChars-1);
		alert("You cannot enter more than 250 characters in the message field."); }
}

var hostName = location.host;

var serverHostname = 'http://'+hostName;

function getTopNavLink(){
	var args = getTopNavLink.arguments;
	if(typeof(args[0]) == 'string') window.location = args[0];
	else if (typeof(args[0]) == 'function')args[0]()
}

var siteWidth = 859;		

function getTopNavLayers(pageType){
}

function productCartNumber(){
	var cartNum = readCookie('myCart');
	if(cartNum == null){
		if(readCookie('myStore') == '12406'){
			cartNum = '0,£0.00';
		} else {
			cartNum = '0,$0.00';
		}
	}
	setCartNum(cartNum);
}

function showNav(img, state){
	for (i=0;i<5;i++){
		rollover(i, 0);
	}
	
	rollover(img, 1);
}

function rollover(img, state){
	oImg = eval("document.img" + img);
	if (state == 1){
		oImg.src = imgOn[img].src;
	}
	else if (state == 0){
		if(oImg){
			oImg.src = imgOff[img].src;
		}
	}
}


function getStyleObject(objectId) {
	if(document.getElementById && document.getElementById(objectId)) {
	return document.getElementById(objectId).style;
	} else if (document.all && document.all(objectId)) {
	return document.all(objectId).style;
	} else if (document.layers && document.layers[objectId]) {
	return document.layers[objectId];
	} else {
	return false;
	}
}

function changeObjectVisibility(objectId, newVisibility) {
	var styleObject = getStyleObject(objectId);
	if(styleObject) {
	styleObject.visibility = newVisibility;
	return true;
	} else {
	return false;
	}
}

function changeObjectProperty(objectId, cssProperty, newValue) {
	var styleObject = getStyleObject(objectId);
	if(styleObject) {
	eval("styleObject."+cssProperty+" = newValue");
	return true;
	} else {
	return false;
	}
}

function getTopNav(){
	var html = '';
	html += '<script language="JavaScript">';
	html += '</script> ';
	document.write(html);
}

var division = null;
var category = null;
function highlightMenu(){
	if(document.getElementById('navHolder')){
		if(division == 12202 || division == 12204) var target= 'mens'; 
		else if(division == 12203 || division == 12205) var target = 'womens';
		else return;
		var targetObj = eval('document.getElementById(\'' + target + 'MenuImg\')');
		targetObj.parentNode.onmouseover = null;
		targetObj.parentNode.onmouseout = null;
		targetObj.src = '/anf/images/nav/' + target + '_on.gif';
		
		var link = (division == 12205 || division == 12204) ? document.getElementById('clearance') : category ? document.getElementById(category) : null;
		if(link){	
			link.className = 'menuHighlight'
			var arrow = document.createElement('img');
			arrow.className = 'menuArrow';
			arrow.src = '/anf/onlinestore/common/arrow.gif';
			link.insertBefore(arrow, link.firstChild);
		}
	}else return;
}



function showWrap(){
	changeObjectProperty('wrapper','visibility','visible');
	changeObjectProperty('contentcontainer','display','block');
	changeObjectProperty('gencntnr','visibility','visible');
}


function setContent(id,content){
	if (document.all){
		document.all[id].innerHTML = content;
	} else if (document.layers){
		document.layers[id].innerHTML = content;
	} else if (document.getElementById){
		document.getElementById(id).innerHTML = content;
	}
}

function ajaxCall(url, params, cb, m, rt, as) {
	this.url = url
	this.parameters = params
	this.callback = cb
	this.method = m ? m : 'get'
	this.responseType = rt ? rt : 'text/xml'
	this.async = as ? as : true
	this.response = null
}

ajaxCall.prototype.parseForm = function(form){
	var formObj = null;
	if(typeof(form) == 'string'){
		if(document.forms[form]) formObj = document.forms[form]
		else if(document.getElementById(form)) formObj = document.getElementById(form)
	}else if (typeof(form) == 'object') formObj = form

	if(!formObj) return
}

ajaxCall.prototype.makeRequest = function(){
	var urlString = this.url;
	if(this.parameters){
		urlString += '?'
		for(p in this.parameters) urlString += p + '=' + this.parameters[p] + '&';
	}
	if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) 
			http_request.overrideMimeType(this.responseType);
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) return false;
	var ajaxObj = this;
	http_request.onreadystatechange = function() {ajaxObj.getContents(http_request)};
	http_request.open(this.method, urlString, this.async);
	http_request.send('');
}

ajaxCall.prototype.getContents = function(http_request){
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
        	this.response = http_request.responseText;
        	this.callback(http_request)       	
        } else {
        }
    } else {
    }
}


function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

function getIEVersion()
{
  var rv = -1; // Return value assumes failure
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

var contactUsType = null
function contactUsLink(p){
	if(p) contactUsType = p
	var params = {
			"storeId" : globalStoreId,
			"catalogId" : globalCatalogId,
			"langId" : -1,
			"type" : p ? p : 'def'
	}
	var cu = new ajaxCall('/anf/lifestyles/html/contactus.html', params, contactUsCB, null, 'text/plain', null);
	cu.makeRequest();
}

function contactUsCB(http_request){
	getFadeUpDiv('cu', http_request.responseText);
	contactForm.init(contactUsType);
}

function contactUsSubmit(){
	if(IsEmailValid(document.forms.ContactUsForm.fromEmail.value)){
		document.getElementById('cuError').innerHTML = '&nbsp;'
		document.getElementById('cuError').visibility = 'hidden'
		params = {
			'storeId' : globalStoreId,
			'subjectEmail' : document.forms.ContactUsForm.subjectEmail.value.replace(/&/g, '%26'),
			'subSubjectEmail' : document.forms.ContactUsForm.subSubjectEmail.value.replace(/&/g, '%26'),
			'ordNum' : document.forms.ContactUsForm.ordNum.value,
			'GCNum' : document.forms.ContactUsForm.GCNum.value,
			'fromName' : document.forms.ContactUsForm.fromName.value,
			'fromEmail' : document.forms.ContactUsForm.fromEmail.value,
			'bodyEmail' : encodeURIComponent(document.forms.ContactUsForm.bodyEmail.value)
		}
		var cuSub = new ajaxCall('/webapp/wcs/stores/servlet/ContactUsForm', params, cuSubCB, 'post', null, null);
		cmCreatePageviewTag("CONTACT US FADE UP","13000");
		cuSub.makeRequest();
	}else{
		document.getElementById('cuError').style.color = '#681414';
		document.getElementById('cuError').innerHTML = 'Please enter a valid e-mail address';
	}
}

function cuSubCB(http_request){
	document.forms.ContactUsForm.style.visibility = 'hidden';
	document.getElementById('response').innerHTML = 'Thanks! We got it!';
}

var rmvdOs = new Array();
function getFadeUpDiv(l, content){
	if(!content) return;
	var fadeUpHolder = document.createElement('div')
	fadeUpHolder.id = 'fadeUpHolder'
	fadeUpHolder.style.display = 'none'
	fadeUpHolder.style.width = '279px';
	if(getIEVersion() > -1){
		fadeUpHolder.style.height = l == 'cu' ? '379px' : l == 'je' ? '174px' : l == 'eaf' ? '278px' : '209px' ;
	}
	fadeUpHolder.innerHTML = content
	document.getElementsByTagName('body')[0].appendChild(fadeUpHolder)
	var editMode = document.getElementById('editMode') ? document.getElementById('editMode') : null
	if(!editMode){
		var editMode = document.createElement('div')
		editMode.id = 'editMode'
		editMode.style.display = 'none'
		document.getElementsByTagName('body')[0].appendChild(editMode);
	}
	var isMac = navigator.userAgent.toLowerCase().indexOf('mac') > -1 ? true : false
	var objectEmbed = (document.getElementsByTagName('object').length > 0 || document.getElementsByTagName('embed').length > 0) ? true : false
	if(isMac && objectEmbed){
		var oes = document.getElementsByTagName('object');
		for(i = 0; i < oes.length; i++){
			rmvdOs[i] = {'parent' : oes[i].parentNode, 'child' : oes[i]} 
			oes[i].parentNode.removeChild(oes[i])
		}
	}
	fadeThisDiv('fadeUpHolder');
}

function closeFadeUp(){
	fadeThisDiv('fadeUpHolder')
	changeObjectVisibility('size','visible')
	changeObjectVisibility('sizelist','visible')
	setTimeout("document.getElementsByTagName('body')[0].removeChild(document.getElementById('fadeUpHolder'))", 500)
	if(rmvdOs.length > 0){
		for(i = 0; i < rmvdOs.length; i++)rmvdOs[i].parent.appendChild(rmvdOs[i].child);
	}
}

var myEffects = {
  fade: function(elid) {
	var opacs = ["0",".1",".2",".3",".4",".5",".6",".7",".8",".9","1"];
	var opacs2 = ["0",".1",".2",".3",".4",".5",".6"];
	if (document.getElementById(elid).style.display == 'none'){
		if(elid == 'editMode'){
			document.getElementById(elid).style.opacity = '0';
			document.getElementById(elid).style.filter = 'alpha(opacity=0)';
			document.getElementById(elid).style.display = 'block';
			for (var i = 0; i < 7; i++){
				setTimeout('document.getElementById(\''+elid+'\').style.opacity = "'+opacs2[i]+'";', i * 40);
				setTimeout('document.getElementById(\''+elid+'\').style.filter = "alpha(opacity='+(opacs2[i] * 100)+')";', i * 40);
			}
		} else {
			document.getElementById(elid).style.opacity = '0';
			document.getElementById(elid).style.filter = 'alpha(opacity=0)';
			document.getElementById(elid).style.display = 'block';
			for (var i = 0; i < 11; i++){
				setTimeout('document.getElementById(\''+elid+'\').style.opacity = "'+opacs[i]+'";', i * 40);
				setTimeout('document.getElementById(\''+elid+'\').style.filter = "alpha(opacity='+(opacs[i] * 100)+')";', i * 40);
			}
		}
	}else{
		if(elid == 'editMode'){
			opacs2.reverse();
			for (var i = 0; i < 7; i++) {
		    	setTimeout('document.getElementById(\''+elid+'\').style.opacity = "'+opacs2[i]+'";', i * 40);
		    	setTimeout('document.getElementById(\''+elid+'\').style.filter = "alpha(opacity='+(opacs2[i] * 100)+')";', i * 40);
			}
			setTimeout('document.getElementById(\''+elid+'\').style.display = "none";', i * 40);
		} else{
			opacs.reverse();
			for (var i = 0; i < 11; i++) {
		    	setTimeout('document.getElementById(\''+elid+'\').style.opacity = "'+opacs[i]+'";', i * 40);
		    	setTimeout('document.getElementById(\''+elid+'\').style.filter = "alpha(opacity='+(opacs[i] * 100)+')";', i * 40);
			}
			setTimeout('document.getElementById(\''+elid+'\').style.display = "none";', i * 40);
		}
	}
   }
}

function fadeThisDiv(divname){
	var floatThisDiv = false;
	if (document.getElementById(divname).style.display == 'none'){
		var ctnTop = 175;
		var nLeft = document.getElementById('wrapper').offsetLeft+"px";
		var nLeft2 = (document.getElementById('headerCtn').offsetLeft + 250)+"px";
		var nHeight = document.getElementById('wrapper').offsetHeight+"px";
		var nWidth = document.getElementById('wrapper').offsetWidth+"px";
		var nTop = ctnTop + "px";
		var divObj = document.getElementById(divname);
		var wrapObj = document.getElementById('wrapper');
		
		changeObjectProperty('editMode', 'left', nLeft);
		changeObjectProperty('editMode', 'height', nHeight);
		changeObjectProperty('editMode', 'width', nWidth);
		changeObjectProperty(divname, 'left', nLeft2);
		changeObjectProperty(divname, 'top', nTop);
		
		if (divObj.childNodes[0].id != 'cover') {
			var ieMat=document.createElement('iframe');
			ieMat.src="/anf/onlinestore/html/blank.html";
			ieMat.scrolling="no";
			ieMat.frameBorder="0";
			ieMat.id="cover";
			ieMat.style.background = 'none';
			ieMat.style.width=getStyleObject(divname).width;
			ieMat.style.height=getStyleObject(divname).height;
			ieMat.style.zIndex="-1";
			divObj.insertBefore(ieMat, divObj.childNodes[0]);
		}
		floatThisDiv = true;
		cmCreatePageviewTag("FADE UP: "+divname,"13000");
	}
	myEffects.fade('editMode');
	myEffects.fade(divname);
	if (floatThisDiv){
		JSFX_FloatTopDiv(divname);
	}
}

var verticalpos="fromtop"

function JSFX_FloatTopDiv(thediv)
{
	var startX = document.getElementById('wrapper').offsetLeft + 125;
	startY = 130;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){
			this.style.top=y + "px";;
		};
		el.x = document.getElementById('wrapper').offsetLeft + 125;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : document.documentElement.scrollTop + document.documentElement.clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : document.documentElement.scrollTop;
		ftlObj.y += (pY + startY - ftlObj.y)/8;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight : document.documentElement.scrollTop + document.documentElement.clientHeight;
		ftlObj.y += (pY - startY - ftlObj.y)/8;
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml(thediv);
	stayTopLeft();
}

