function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

// General globals
var channel = 'intl';

// zoom-related global variables
var bigWidth; //width of the zoom image 
var smallWidth; // width of zoomed image
var bigHeight; // height of the zoom image
var bigX = 0; // zoom image x position
var bigY = 0; // zoom image y position

//ratio between the small and big images of the product
//hard-coded, we could work this out dynamically
var zoomRatio = 0.25;

//Used to define a custom area where the zooming functionality can occur.
var productImageMarginTop = 32;
var productImageMarginSides = 50;
var productImageMarginBottom = 20;

var zoomWindowBoxWidth = 0;
var zoomWindowBoxHeight = 0;
var smallHeight;
var bigBoxWidth;
var bigBoxHeight;
var factorY;
var factorX;
var easing = 0.22;
var zoomInterval = 0; 
var mouseX = 0;
var mosueY = 0;
var sHeight;
var elements;
var scrollBorder;
var thumbsPos = new Array();
var thumbsPosDown = new Array();
var imgAmount;
var i = 0;
var g = 92*5;
var idc = 0;
var delay = 0;
var rollOverInetrval;
var hideInterval;
var str =  new String(window.location);
var zoomImageShown = false;
var nr;
var issueNumber;
var pageNumber;
var images;
var scrollHeight; 
var isZoomOn = false;
var isVideoOn = false;
var videoHasBeenLoaded = false;

function initProductPage()
{
	sHeight = 92;
	document.body.onmousemove=setMouseCoords;
	elements = countElements("thumbnails-mask","img");
	scrollHeight = sHeight * elements ; 
	//document.getElementById("thumbnails-loop").style.top = scrollHeight+'px';

	smallWidth = 336;  //335
	smallHeight = 500;

	bigBoxWidth = document.getElementById('zoom-box').offsetWidth;
	bigBoxHeight = document.getElementById('zoom-box').offsetHeight;

	//document.getElementById('zoom-image').style.left = -450 + 'px';
	//document.getElementById('zoom-image').style.top = -800 + 'px';
	

	YAHOO.util.Event.addListener("up-arrow", "click", moveDown);
	YAHOO.util.Event.addListener("down-arrow", "click", moveUp);

	//zoom onload vars 
	var oUpArrow = document.getElementById("up-arrow");
	var oDownArrow = document.getElementById("down-arrow");

	countsImages ('thumbnails-mask');
	document.getElementById('medium-image').onclick=showBig;
	//document.getElementById('large-image').onmouseover=clearIntrv;

	//document.getElementById('large-image').onmouseout=hideBig;
    
	//document.getElementById('large-image').onclick=showBig;
	bigWidth = document.getElementById('zoom-image').offsetWidth ;
	bigHeight = document.getElementById('zoom-image').offsetHeight ;
	
	//Set the height and width of the box which shows where you are
	//zooming on the original normal sized product image. This box 
	//should be same size in relation to the normal product image
	//as the zoom-box is to the extra large sized product image. 
	zoomWindowBoxWidth = (zoomRatio * bigBoxWidth);
	zoomWindowBoxHeight = (zoomRatio * bigBoxHeight);
	document.getElementById('zoomWindowBox').style.width = zoomWindowBoxWidth + 'px';
	document.getElementById('zoomWindowBox').style.height = zoomWindowBoxHeight + 'px';
}


function prevPage()
{
	navigtionsetup();
	if (pageNumber>1) {
		pageNumber--;
		window.location="/Content/"+issueNumber+"/Issue&pageNo="+pageNumber+"";
	}
}

function navigateToPage(nr)
{
	navigtionsetup();
	window.location = "/Content/"+issueNumber+"/Issue&pageNo="+nr+"";
}

function nextPage()
{
	navigtionsetup();
	pageNumber++;
	window.location= "/Content/"+issueNumber+"/Issue&pageNo="+pageNumber+"";
}

function navigtionsetup()
{
	str =  new String(window.location);
	str = str.split("/");
	issueNumber = str[4];

	if(str[5]!="Issue") {
		pageNumber = str[5].split("=");
		pageNumber = pageNumber[1];
		pageNumber = pageNumber.split("");

		if(pageNumber[1]=="?"||pageNumber[1]==undefined) {
			pageNumber = pageNumber[0];
		} else {
			pageNumber = pageNumber[0]+""+pageNumber[1];
		}
	}
}

function countsImages (element_id)
{
	images = document.getElementById(element_id).getElementsByTagName('img');

	imgAmount = (images.length -1);
	idcc = (images.length -1);
	//var images2 = document.getElementById('thumbnails-loop').getElementsByTagName('img');
	scrollBorder = (sHeight * 3 ) - (sHeight*images.length);

	for(var d=0;d<images.length;d++)
	{
		thumbsPos.push(sHeight*(d-1));
		
		thumbsPosDown.unshift(sHeight*(d-1));
		
		document.getElementById(images[d].id).style.left = thumbsPos[d]+'px';
		document.getElementById(images[d].id).style.top = '0px';
		YAHOO.util.Event.addListener(images[d].id, "click", moveUp);
		//YAHOO.util.Event.addListener(images2[d].id, "click", moveUp);
	}
}


function setMouseCoords(e)
{
	var ie = document.all?true:false;
	if (!e) {
		   e = window.event;
	}
	
	if (e.pageX || e.pageY) {
		   mouseX = e.pageX;
		   mouseY = e.pageY;

	} else if (e.clientX || e.clientY) {
		
	   mouseX = YAHOO.util.Event.getPageX(e); 
	   mouseY = YAHOO.util.Event.getPageY(e); 	
	}
}

//////////////COVER ROLLOVER FUNCTIONALITY //////////////////////////////Pawel

function imageOn(imageName){

	var imgSrcOff = new String(imageName.src);
	var imgSrcOn = imgSrcOff.replace(/inactive/gi, "active");
	var promoTxtOff = document.getElementById("promo-text").src;
	var promoTxtOn = promoTxtOff.replace(/off/gi, "on");
	var promoId = imageName.id;	
	var issueNbr = document.getElementById("promo-text").src;
		 issueNbr = issueNbr.split("/");
	promoId = promoId.slice(5);	
	imageName.src = imgSrcOn;
	document.getElementById("promo-text").src = "/images/issues/2008/"+issueNbr[6]+"/cover/promotext"+promoId+"_active.jpg";

}


function imageOff(imageName){

	var imgSrcOff = new String(imageName.src);
	var imgSrcOn = imgSrcOff.replace(/active/gi, "inactive");;
	var promoTxtOff = document.getElementById("promo-text").src;
	var promoTxtOn = promoTxtOff.replace(/active/gi, "inactive");
	var promoId = imageName.id;
	var issueNbr = document.getElementById("promo-text").src;
	// var issueNbr = issueNbr.slice(49,53);
	var issueNbr = issueNbr.split("/");
	
	promoId = promoId.slice(5);
	imageName.src = imgSrcOn;
	document.getElementById("promo-text").src = "/images/issues/2008/"+issueNbr[6]+"/cover/promotext_inactive.jpg";
}

////////////////////////////////////////////////////////////////////////


//show zoom image 
function showBig()
{	
	largeImageShown = true;

    // Hide the video if it's on
    if (isVideoOn) {
        hideVideo();
    }

    clearIntrv();
    setVisibilityById('demo', false);
    setVisibilityById('sizing', false);
    setVisibilityById('designer', false);
    setVisibilityById('zoom-image', true);
    setVisibilityById('zoom-box', true);
    setVisibilityById('zoomWindowBox', true);

	zoomInterval = setInterval("animateBigImage()", 10);
	
    isZoomOn = true;
}

/*
 * Removes the zoom & hides the image zoom's containing elements
 */
function removeZoom()
{
    clearInterval(zoomInterval);
    setVisibilityById('zoom-image', false);
    setVisibilityById('zoom-box', false);
    isZoomOn = false;
}

/*
 * Displays the normally hidden video box element & loads the Flash *.flv video file into it, playing
 * the video
 * @param prodId The product ID used in the path to the product's *.flv file
 */
function showVideo(prodId)
{
    if (isZoomOn) {
		removeZoom();
    }

    if (!isVideoOn) {

        // See if the video has not been loaded yet (i.e. this is the first view video request since the page loaded)
        // GH 19/12/08: Including this logic to save reloading the product video into the swf object makes the video
        // not play more than once for any page load for some reason 
        // if (!videoHasBeenLoaded) {

            // Set any additional Flash swing object variables - in this case the product ID, required for the path to the *.flv file
            var flashvars = [];
            flashvars.prodID = prodId;

            // Load the video into the swing object & set that is has been
            swfobject.embedSWF("/images/flash/productVideo.swf", "prod-page-video", "390", "412", "9.0.0", null, flashvars);
            videoHasBeenLoaded = true;
        // }

        // Set the relevant visibilities of elements
        setVisibilityById('video-box', true);
        setVisibilityById('demo', false);
        setVisibilityById('sizing', false);
        setVisibilityById('designer', false);

        //  Set that the video is on
        isVideoOn = true;
    } 
}


function hideVideo()
{
    setVisibilityById('video-box', false);
    setVisibilityById('prod-page-video', false);
    setVisibilityById('demo', true);
    setVisibilityById('sizing', true);
    setVisibilityById('designer', true);
	isVideoOn = false;
}

//////SIZING CHART TAB//////////////////////////////////////////////////////
function showtab(tabname)
{
    var measuring_guide_tab = document.getElementById('measuring-guide');
    var size_conversion_tab = document.getElementById('size-conversion');
    var product_measurement_tab = document.getElementById('product-measurement');

    //Hide all tabs by default
    measuring_guide_tab.style.display = 'none';
    size_conversion_tab.style.display = 'none';
    product_measurement_tab.style.display = 'none';

    //Then show the selected one
    document.getElementById(tabname).style.display = 'block';
}
 
function prepViewLargeImageLink(product_id, image_type, cache_url)
{
    var fullsize_link = document.getElementById('full-size-image-link');
    if (fullsize_link != null) {
        fullsize_link.onclick = function()
        {
            launchNamePopUp('imgL', '/' + channel + '/ViewFullSizeImage.ice?productID=' + product_id + '&imageType=' + image_type, 580,760);
        }
    }
}

function loadBig(img, prodId, cache_url)
{
    prepViewLargeImageLink(prodId, img, cache_url);
    document.getElementById("medium-image").src =  cache_url + '/images/products/' + prodId + '/' + img + '_l.jpg';
    loadZoomImage(img,prodId, cache_url);
}

function loadZoomImage(img,prodId, cache_url)
{		 
	document.getElementById("zoom-image").src = cache_url + '/images/products/' + prodId + '/' + img + '_xl.jpg';
}

function clearIntrv()
{
	clearTimeout(hideInterval);		
}

function hideBig()
{	
	hideInterval = setTimeout("hideDelay()", 250);	
}

function hideDelay()
{	
	if (isZoomOn) {

        if (!isVideoOn) {
            setVisibilityById('demo', true);
            setVisibilityById('sizing', true);
            setVisibilityById('designer', true);
            setVisibilityById('zoom-image', false);
            setVisibilityById('zoom-box', false);
            setVisibilityById('zoomWindowBox', false);
            clearInterval (zoomInterval);
        }
        
        isZoomOn = false;
	}
}

function hideBigBox()
{	
	setVisibilityById('zoom-image', false);
}

//zoom function 
function animateBigImage()
{

 

	var xPos =  mouseX;
	var yPos =  mouseY;	
	var bigXPos = YAHOO.util.Dom.getX('zoom-image');
	var bigYPos = YAHOO.util.Dom.getY('zoom-image');

	//X and Y coordinates of the normal sized product image
	//from the page corner
	var largeXOffset = YAHOO.util.Dom.getX('medium-image');
	var largeYOffset = YAHOO.util.Dom.getY('medium-image');

    var mediumImageWidth = document.getElementById('medium-image').offsetWidth;
    var mediumImageHeight = document.getElementById('medium-image').offsetHeight;

    /*
     * Work out if the cursor is within some custom bounds of the product image. If it is, then
     * stop animating.
     */


    if(xPos < (largeXOffset - 0) ||
       xPos > (largeXOffset + mediumImageWidth + 0) ||
       yPos < (largeYOffset - 0) ||
       yPos > (largeYOffset + mediumImageHeight + 0))
    {
        hideBig();
        return;
    }

	//var bigXPos = document.getElementById('zoom-image').offsetLeft;
	//var bigYPos = document.getElementById('zoom-image').offsetTop;	

	factorX = (bigWidth- bigBoxWidth)/smallWidth;
	factorY = (bigHeight-bigBoxHeight)/smallHeight ;	

	var targetX = 0 - (factorX * (xPos-largeXOffset));
	var targetY = 0 - (factorY * (yPos-largeYOffset));		

	targetX = Math.round(targetX);
	targetY = Math.round(targetY);

	bigX +=  ((targetX-bigX)*easing); 
	bigY +=  ((targetY-bigY)*easing);	

	bigY = Math.round(bigY);
	bigX = Math.round(bigX);
	
	document.getElementById("zoom-image").style.left  = bigX + 'px';
	document.getElementById("zoom-image").style.top = bigY + 'px';
 	//var move = new YAHOO.util.Anim('bImg', {top: { to: bigY }, left:{to:bigX}}, 1 ,YAHOO.util.Easing.easeOut);
	
	//X and Y coordinates of the zoom box from the page corner
	var bigBoxXOffset = YAHOO.util.Dom.getX('zoom-box');
	var bigBoxYOffset = YAHOO.util.Dom.getY('zoom-box');
	
	//X and Y coordinates of the extra large product image from the page corner
	var zoomImageXOffset = YAHOO.util.Dom.getX('zoom-image');
	var zoomImageYOffset = YAHOO.util.Dom.getY('zoom-image');

	//Work out where zoom-box is in relation to the extra large zoom image.
	//Apply the zoom ratio to work out where our small box which shows where
	//you are zooming should be located in relation to the normal sized product image
	var windowBoxXOffset = (bigBoxXOffset - zoomImageXOffset) * zoomRatio;
	var windowBoxYOffset = (bigBoxYOffset - zoomImageYOffset) * zoomRatio;

	var window_width = document.documentElement.clientWidth;
	var window_height = document.documentElement.clientHeight;
	
	//Add the X and Y coordinates  of the normal sized image to get the X and Y
	//coordinates for the small box in relation to the page corner.
	windowBoxXOffset = windowBoxXOffset; //420
	windowBoxYOffset = windowBoxYOffset; //210
	
	//Make sure our X and Y coordinates are integers.
	windowBoxXOffset = Math.round(windowBoxXOffset);
	windowBoxYOffset = Math.round(windowBoxYOffset);

	//Set the coordinates for the small box which shows where
	//you are zooming
	document.getElementById('zoomWindowBox').style.left  = windowBoxXOffset + 'px';
	document.getElementById('zoomWindowBox').style.top  = windowBoxYOffset  + 'px';
}

//scroll fucntionality 

function countElements(container_id, tag)
{
	var container = document.getElementById(container_id);
	var elem_count = container.getElementsByTagName(tag).length;
	return elem_count;
}
 
function moveDown(e)
{		
	if (idc>0) {
		idc--;
	} else {
		idc=images.length-1;
	}
	var tempPoss = thumbsPos.shift();
	thumbsPos.push(tempPoss);
	document.getElementById(images[idc].id).style.left = -92+'px';	
	
	for(var d=0;d<images.length;d++)
	{
		var moves = new YAHOO.util.Anim(images[d].id, {left: {to: thumbsPos[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		moves.animate();		
	}
}
 
//move thumbnails up 
function moveUp(e) 
{ 				
	if(document.getElementById(images[idc].id).offsetTop<92) 
	{		
		document.getElementById(images[idc].id).style.left = 368+'px';
	}
	if(idc<imgAmount)
	{						
		idc++;
	}
	else 
	{
		idc=0;
	}
		
	var tempPos = thumbsPos.pop();
	thumbsPos.unshift(tempPos);
	
	for(var d=0;d<images.length;d++)
	{	
		var move = new YAHOO.util.Anim(images[d].id, {left: {to: thumbsPos[d]}} ,  0.6 ,YAHOO.util.Easing.easeOutStrong); 		
		move.animate();	
	}
	
}

// ADDED BY ANDY FROM INLINE ON 8th FEB

function openSignUp()
{
	if (validateEmail())
	{
		var url = '/' + channel + '/Content.ice?page=Sign-Up-For-Fashion-News&pgForward=popup' + '&email=' + document.getElementById('email').value;
        open(url,'SignupForFashionNews','width=700,height=500');
        var tmp = open(url,'SignupForFashionNews','width=700,height=500');
		tmp.focus();
	}
	return false;
}

function clearDefault(el) 
{
	if (el.defaultValue==el.value) el.value = ""
}

function jsubmit()
{
	if (validate()) 
	{
		document.emailreg.submit();
	}
}

function validate()
{
	if(!isGoodEmail(document.emailreg.email.value))
	{
		alert("Please make sure that you\ninput a valid e-mail address");
		document.emailreg.email.focus()
		return false
	}
	return true;
}

function validateEmail() 
{
	if(!isGoodEmail(document.emailreg.email.value, false))
	{
		alert("Please make sure that you\ninput a valid e-mail address");
		document.emailreg.email.focus()
		return false
	}
	return true;
}

function isGoodEmail(emailStr, thankyouflag) 
{
	if (thankyouflag == null) 
	{
		thankyouflag=true;
	}
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\!\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var firstChars=validChars;
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom="(" + firstChars + validChars + "*" + ")";
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)
	{
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// See if "user" is valid
	if (user.match(userPat)==null) 
	{
		return false;
	}
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if(IPArray[i]>255) 
			{
				return false;
			}
		}
		return true;
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		return false;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
	{
	   // the address must end in a two letter or three letter word.
	   return false
	}
	if (domArr[domArr.length-1].length==3 && len<2) 
	{
	   return false
	}

	// default behavior - keep existing uses continue to work
	if(thankyouflag) 
	{
	// Everything's valid:
	   window.open('Thank You', 'newFormWindow', 'width=340,height=260');
	}
	return true;
}
	
var rollover_state_re = /\/images\/issues.*(_on|_off)\.(gif|jpg)$/;

function rolloverimage_handler() 
{
	var ON = '_on';  var OFF = '_off'; var SUFFIX = '.';
	if (rollover_state_re.test(this.src)) 
	{
		this.src = this.src.replace(RegExp.$1 + SUFFIX, (RegExp.$1==ON?OFF:ON)  + SUFFIX);
	}
	/* else, by convention, do nothing */
}

function rolloverimage_setup()
{
	for(var i=0; i<document.images.length; i++) 
	{
		var img = document.images[i];
		if (rollover_state_re.test(img.src)) 
		{
			img.onmouseover = rolloverimage_handler;
			img.onmouseout = rolloverimage_handler;
		}
	}
}

function s(o,f) 
{	 
	eval ("document."+o+".src= "+f+".src;");
}


function csoon()
{
	launchNamePopUp('csoon', 'http://www.net-a-porter.com/popups/comingsoon.html', 340, 110);
}


function msg(a)
{
	if(a==1) 
	{
		csoon();
	} 
	else 
	{
		launchNamePopUp('soldout', 'http://www.net-a-porter.com/popups/soldout.html', 340, 260);
	}
}

function stay()
{
}

///////////////////////////////////////////////////////////
//above are old functions kept for backwards compatibility.
//please add new global functions below. ta.
///////////////////////////////////////////////////////////
var dom,ns,ie;

if (document.getElementById) 
{
	dom = 1;
} 
else if (document.layers) 
{
	nn = 1;
} 
else if (document.all) 
{
	ie = 1;
}

/*
 * Overwritten: use setVisibilityById method instead
 */
function set_visible(div, value)
{
	var ref;
	if(dom == 1)
	{
		ref = document.getElementById(div).style;
	}
    // GH 19/12/08: Supports IE 4 which we shouldn't need to anymore
	else if(ie == 1)
	{
		ref = eval('document.all.div.style');
	}
    // GH 19/12/08: Supports Netscape 4 which we shouldn't need to anymore
	else if(nn == 1)
	{
		ref = eval('document.layers[div]');
	}
	ref.visibility = value;
}

function image_swap(layer, id, newpic) 
{
	if (dom || ie)
	{
		eval ("document."+id+".src = "+newpic+".src;");
	}
	else if (nn) 
	{
		eval("document.layers['" + layer + "'].document.images['" + id  +"'].src = " + newpic + ".src");  
	}
}

function switchClass(which,what)
{
	if (!document.layers) 
	{
		if (document.all) 
		{ 
			switchObj = eval('document.all.' + which + ''); 
		}
		else
		{
			switchObj = document.getElementById(''+which+''); 
		} 
		switchObj.className = what;
	}
}

// custom object
function product_info(designer, status)
{
	this.designer = designer;
	this.status = status;
}

var product = new Array();

function clickOn(sku) 
{
	var _sku = '_'+sku;
	var status = product[_sku].status;
	
    // Register interest
    if (!status || status == "none" ) {
		ri(product[_sku].designer, sku);

    // Sold out
    } else if (status == 3) {
		launchNamePopUp('soldout', '/' + channel + '/Content.ice?page=Sold-Out&pgForward=popup',280,210);

    // In stock or prepay
    } else {
        // Go to the product page
		window.location.href = "/product/" + sku;
	} 
}

var ri_subdir = "";
var Collection_ID = "";
function ri(designer,sku) 
{
	designer = designer.toLowerCase();
	var url = '/' + channel + '/Content.ice?page=RegisterInterest&pgForward=popup&designer=' + designer + '&sku=' + sku;
	if (sku == null) 
	{ 
		url = '/' + channel + '/Content.ice?page=RegisterInterest&pgForward=popup&designer=' + designer + '&sku=' + Collection_ID + '&collection=1';
	}
	if (ri_subdir != null && ri_subdir != "")
	{
		url += '&subdir='+ri_subdir;
	}
	launchNamePopUp('ri', url, 320, 320);
}

function designerri(designer,sku) 
{
	designer = designer.toLowerCase();
	var url = '/' + channel + '/Content.ice?page=DesignerRegisterInterest&pgForward=popup&designer=' + designer;
	if (sku == null) 
	{ 
		url = '/' + channel + '/Content.ice?page=DesignerRegisterInterest&pgForward=popup&designer=' + designer;
	}
	if (ri_subdir != null && ri_subdir != "")
	{
		url += "&subdir=" + ri_subdir;
	}
	launchNamePopUp('des_ri', url, 320, 300);
}

// generate instock|soldout|prepay|(none) tags 
function show_instock_tags()
{
	var string="";
	for (var _id in product)
	{
		var sku = _id.replace(/_(\d+).*/,"$1");
		var id = _id.replace(/^_/,"");
		var instock_tag = product[_id].status;
		if(product[_id].status == 0 || product[_id].status == "" || product[_id].status == "none") 
		{
			continue;
		}

		switch (product[_id].status) 
		{
			case 1: instock_tag = "instock"; break;
			case 3: instock_tag = "soldout"; break;
			case 2: instock_tag = "prepay";  break;
		}
		string += "<div id=\"instock" +id+ "\">\n" +
                "<a href=\"javascript:clickOn("+sku+")\" onmouseover=\"switchClass('link"+id+"','black')\" onmouseout=\"switchClass('link"+id+"','a')\"><img src=\"/i/nav_elements/" +instock_tag+ ".gif\" border=0 alt=\"\"></a>\n" +
                "</div>\n";      
   }
   document.write(string);
}

if (top.tempo == null) top.tempo = new Object();

function save(id, val) 
{
	if (val!=null) top.tempo[id] = val;
}

function restore(id) 
{
	return (top.tempo[id]!=null)?top.tempo[id]:null;
}

function clear(id) 
{
	if (top.tempo[id]!=null) top.tempo[id] = null;
}

//The base class for launching a pop-up, which should
//be called by all other pop-up launching functions
//NB: incScroll should be 1/yes or 0/no.
function launchGenericPopUp(winName, url, w, h, incScroll)
{	
	var newWindow = window.open(url, winName, 'width='+w+',height='+h+',menubar=no,location=no,resizable=1,status=no,scrollbars='+incScroll);
	if (window.focus) {
		newWindow.focus();
	}	
}

//The following are wrappers to the above launchGenericPopUp.
//launchGenericPopup isn't called directly and is instead
//called via one of the following 4 methods.
function launchNamePopUp(name, url, w, h)
{
	launchGenericPopUp(name, url, w, h, 1);
}

function launchNamePopUpNoScroll(name, url, w, h)
{
	launchGenericPopUp(name, url, w, h, 0);
}

// launchPopUp: Has to be kept as it is used directly
// in the JSPs. Use launchNamePopUp from now on.
function launchPopUp(url, w, h)
{
	launchNamePopUp('NAP_pop', url, w, h);
}

// launchPopUpNoScrolls: As with launchPopUp above
function launchPopUpNoScrolls(url, w, h) 
{
	launchNamePopUpNoScroll('NAP_pop_noscr', url, w, h);
}

function help(url)
{
	launchNamePopUp('NAPHelp', url, 670, 540);
}	

// function to handle mouse actions, added by AJ 30-10-2006   
function mouseAction(state, image)
{					
	rollOverDiv			= "div" + image.name;
	rollOverImageName	= image.name ;
	rollOverImage		= "";	
	if (state == "on")
	{	
		rollOverImage = image.name + "1";
	}
	else if(state == "off")
	{
		rollOverImage = image.name + "0";
	}	
	image_swap(rollOverDiv,rollOverImageName,rollOverImage);
}

var rollover_state_re = /\/images\/issues.*(_on|_off)\.(gif|jpg)$/;

function rolloverimage_handler() 
{
	var ON = '_on';  var OFF = '_off'; var SUFFIX = '.';
	
	
	if(rollover_state_re.test(this.src)) 
	{
		this.src = this.src.replace(RegExp.$1 + SUFFIX, (RegExp.$1==ON?OFF:ON)  + SUFFIX);
	
	}
	/* else, by convention, do nothing */
}

function rolloverimage_setup() 
{
	
	for(var i=0; i<document.images.length; i++) 
	{
		var img = document.images[i];
		if (rollover_state_re.test(img.src)) 
		{
			img.onmouseover = rolloverimage_handler;
			img.onmouseout = rolloverimage_handler;
		}
	}
}

// Flash Player Version Detection - Rev 1.5
// Detect Client Browser type
// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved.
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function ControlVersion()
{
	var version;
	var axo;
	var e;
	// NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry
	try 
	{
		// version will be set for 7.X or greater players
		axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		version = axo.GetVariable("$version");
	} 
	catch (e) 
	{
	}
	if (!version)
	{
		try 
		{
			// version will be set for 6.X players only
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
			
			// installed player is some revision of 6.0
			// GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
			// so we have to be careful. 
			
			// default to the first public version
			version = "WIN 6,0,21,0";

			// throws if AllowScripAccess does not exist (introduced in 6.0r47)		
			axo.AllowScriptAccess = "always";

			// safe to call for 6.0r47 or greater
			version = axo.GetVariable("$version");

		} 
		catch(e) 
		{
		}
	}

	if (!version)
	{
		try 
		{
			// version will be set for 4.X or 5.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = axo.GetVariable("$version");
		} 
		catch (e) 
		{
		}
	}

	if(!version)
	{
		try 
		{
			// version will be set for 3.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
			version = "WIN 3,0,18,0";
		} 
		catch (e) 
		{
		}
	}

	if (!version)
	{
		try 
		{
			// version will be set for 2.X player
			axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			version = "WIN 2,0,0,11";
		} 
		catch (e) 
		{
			version = -1;
		}
	}
	
	return version;
}

// JavaScript helper required to detect Flash Player PlugIn version information
function GetSwfVer()
{
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	var flashVer = -1;
	
	if (navigator.plugins != null && navigator.plugins.length > 0) 
	{
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) 
		{
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;			
			var descArray = flashDescription.split(" ");
			var tempArrayMajor = descArray[2].split(".");
			var versionMajor = tempArrayMajor[0];
			var versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) 
			{
				tempArrayMinor = descArray[3].split("r");
			} 
			else 
			{
				tempArrayMinor = descArray[4].split("r");
			}
			var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			var flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	else if ( isIE && isWin && !isOpera ) 
	{
		flashVer = ControlVersion();
	}	
	return flashVer;
}

// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	versionStr = GetSwfVer();
	if (versionStr == -1 ) 
	{
		return false;
	} 
	else if (versionStr != 0) 
	{
		if(isIE && isWin && !isOpera) 
		{
			// Given "WIN 2,0,0,11"
			tempArray         = versionStr.split(" "); 	// ["WIN", "2,0,0,11"]
			tempString        = tempArray[1];			// "2,0,0,11"
			versionArray      = tempString.split(",");	// ['2', '0', '0', '11']
		} 
		else 
		{
			versionArray      = versionStr.split(".");
		}
		var versionMajor      = versionArray[0];
		var versionMinor      = versionArray[1];
		var versionRevision   = versionArray[2];

        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
		if (versionMajor > parseFloat(reqMajorVer)) 
		{
			return true;
		} 
		else if (versionMajor == parseFloat(reqMajorVer)) 
		{
			if (versionMinor > parseFloat(reqMinorVer))
			{
				return true;
			}
			else if(versionMinor == parseFloat(reqMinorVer))
			{				
				if (versionRevision >= parseFloat(reqRevision))
				{
					return true;
				}
			}
		}
		return false;
	}
}

function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
    var str = '';
    if (isIE && isWin && !isOpera)
    {
  		str += '<object ';
  		for (var i in objAttrs)
  			str += i + '="' + objAttrs[i] + '" ';
  		for (var i in params)
  			str += '><param name="' + i + '" value="' + params[i] + '" /> ';
  		str += '></object>';
    } else {
  		str += '<embed ';
  		for (var i in embedAttrs)
  			str += i + '="' + embedAttrs[i] + '" ';
  		str += '> </embed>';
    }

    document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
      case "id":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

function uncheckAll()
{
	email_prefs.weekly_newsletter.checked = false ;
	email_prefs.sale_special.checked = false ;
}

function toggleOpenClosedById(id)
{
    var elem = document.getElementById(id);
    if (elem) {
        // See if the element has a class of 'closed'
        if ((' ' + elem.className + ' ').indexOf(' closed ') != -1) {
            // Replace the 'closed' part of the class with 'open'
            elem.className = elem.className.replace('closed', 'open');
        } else {
            // Replace the 'open' part of the class with 'closed'
            elem.className = elem.className.replace('open', 'closed');
        }
    }
}

function toggleDisplay(id)
{
    var elem = document.getElementById(id);
    var disp = elem.style.display;
    if('none' != disp)
    {
        elem.style.display = 'none';
    }
    else
    {
        elem.style.display = 'block'
    }
}

function toggleArrowClass(src)
{
    var elem = document.getElementById(src);
    var elemclass = elem.getAttributeNode('class').value;
    //alert(elemclass);
    if('productnav-toggle-rightarrow' == elemclass)
    {
        elem.setAttribute('class','productnav-toggle-downarrow');
        elem.className = 'productnav-toggle-downarrow';
    }
    else if('productnav-toggle-downarrow' == elemclass)
    {
        elem.setAttribute('class','productnav-toggle-rightarrow');
        elem.className = 'productnav-toggle-rightarrow';
    }
}

/*feeder*/
/*
var length = new Number();
var t;
onload = function () {
	
	var imgWidth = [];	 
	var img_container = document.getElementById("feeder-container");
	
	if (img_container) {

		var imgs = img_container.getElementsByTagName("img");
		var zIndex = imgs.length;
	
		var pos = 0 ;
		var feederInterval;
		for (var index = 0; index < zIndex; index++) {
			imgWidth.push(imgs[index].width);
			length = length + imgWidth[index];
		}
		
		length = length/2;

		document.getElementById('feeder2').style.left = length + 'px';
		document.getElementById('feeder').style.width = length + 'px';
		document.getElementById('feeder2').style.width = length + 'px';  

		startFeeder();
	}
}

stopFeeder = function () {
	clearInterval(feederInterval);
}


startFeeder =function () {
	feederInterval = setInterval(moveFeeder,20);
}

var c=0;
var t;
function timedCount() {
document.getElementById('txt').value=c;
c=c+1;
t=setTimeout("timedCount()",1000);
}

moveFeeder = function () {

	if(document.getElementById('feeder').offsetLeft < -length){
	document.getElementById('feeder').style.left = length + 'px';
	}

	if(document.getElementById('feeder2').offsetLeft < -length){
	document.getElementById('feeder2').style.left = length + 'px';
	}

document.getElementById('feeder').style.left = document.getElementById('feeder').offsetLeft - 1+'px';
document.getElementById('feeder2').style.left = document.getElementById('feeder2').offsetLeft - 1+'px';

}*/

goToLocation = function (url) {
	window.location = url;
}

/*
 * General method for setting an element's visibility, targetted
 * by the element ID, taking care to only attempt it on elements
 * that exist on the page
 * @param id The element id string
 * @param visibility The visibility flag i.e. 0/false=hidden, 1/true=visible
 */
function setVisibilityById(id, visibility) {
    if (document.getElementById(id) != null) {
        if (visibility) {
            document.getElementById(id).style.visibility = 'visible';
        } else {
            document.getElementById(id).style.visibility = 'hidden';
        }
    }
}
