<!--Friday 6th of November 2009 10:38:59 AM-->
var baseappurl = "http://uma.chanel.com/";

var isfullscreen = false;
var isWin = (navigator.userAgent.indexOf('Win') != -1);
var isWinXP = (navigator.userAgent.indexOf('Windows NT 5.1') != -1);
var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
var isNS = (navigator.userAgent.indexOf('Mozilla') != -1) && (navigator.userAgent.indexOf('Firefox') == -1);
var isFirefox = (navigator.userAgent.indexOf('Firefox') != -1);
var isMAC = (navigator.platform.indexOf('Mac') != -1);
var version = parseInt(navigator.appVersion);
var previousXPosition = 0;
var previousYPosition = 0;
var previousWidth = 0;
var previousHeight = 0;


function openwin(name,myname,mywidth,myheight,mytool,mydir,mystatus,myscroll,myresize,mymenu)
{
	mytop=Math.floor((screen.height/2) - (myheight/2));
	myleft=Math.floor((screen.width/2) - (mywidth/2));
	debute =window.open(name,myname,"toolbar="+mytool+",width="+mywidth+",height="+myheight+",directories="+mydir+",status="+mystatus+",scrollbars="+myscroll+",top="+mytop+",left="+myleft+",resizable="+myresize+",menubar="+mymenu)
}

function openFullscreen(url,newwindow,reload, titlebar) 
{
	reload = (typeof reload=="undefined") ? true : reload;
	titlebar = (typeof titlebar=="undefined") ? true : titlebar;
	if (isIE) 
	{
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	} 
	else if (self.outerWidth) 
	{
		previousXPosition = self.screenX;
		previousYPosition = self.screenY;
		previousWidth = self.outerWidth;
		previousHeight = self.outerHeight;
	} 
	else 
	{
		previousXPosition = top.window.screenLeft;
		previousYPosition = top.window.screenTop;
		previousWidth = document.body.clientWidth;
		previousHeight = document.body.clientHeight;
	}
	
	if (isWin && isIE) 
	{
		top.window.resizeTo(screen.width/2,screen.height/2);
		top.window.moveTo(0,0);
		var wleftdiff = top.window.screenLeft;
		var wrightdiff = (screen.width/2) - top.window.document.body.clientWidth - wleftdiff;
		var htopdiff = top.window.screenTop;
		var hbottomdiff = (screen.height/2) - top.window.document.body.clientHeight - htopdiff;
		var newXPosition = -wleftdiff;
		var newYPosition = -htopdiff;
		var newWidth = screen.width+wleftdiff+wrightdiff;
		var newHeight = screen.height+htopdiff+hbottomdiff;
		if ((newWidth>screen.width) && (newHeight>screen.height)) 
		{
			previousXPosition -= wleftdiff;
			previousYPosition -= htopdiff;
			previousWidth += wleftdiff+wrightdiff;
			previousHeight += htopdiff+hbottomdiff;
		}
		top.window.resizeTo(previousWidth,previousHeight);
		top.window.moveTo(previousXPosition,previousYPosition);
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		if (isWinXP || newwindow) 
		{
			url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;

            if (!titlebar)
            {
                arg = 'fullscreen=yes';
            }
            else
            {
                deltaWidth = -8;
                deltaHeight = -30;
                
                newWidth = screen.width + deltaWidth;
                newHeight = screen.height + deltaHeight;

                arg = 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0'                
            }

			window.open(url,'chanelfullscreen', arg);
            if (!newwindow)
            {
                top.window.opener = top;
                top.window.close();
            }
		} 
		else 
		{
			top.window.moveTo(newXPosition-2,newYPosition-2);
			top.window.resizeTo(newWidth,newHeight);
			if (reload) 
			{
				top.location.href = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
			}
		}
	} 
	else 
	{
		deltaWidth = (isNS) ? ((isMAC) ? -10 : -5) : ((isMAC) ? -5 : 0);
		deltaHeight = (isNS) ? ((isMAC) ? -50 : -50) : ((isMAC) ? -2 : -30);
		deltaLeft = (isNS) ? ((isMAC) ? -6 : -6) : ((isMAC) ? -5 : -5);
		deltaTop = (isNS) ? ((isMAC) ? -30 : -30) : ((isMAC) ? -10 : -30);
		newWidth = screen.width + deltaWidth;
		newHeight = screen.height + deltaHeight;
		parameters = "x="+previousXPosition+"&y="+previousYPosition+"&width="+previousWidth+"&height="+previousHeight;
		url = (url.indexOf('?') != -1) ? url+"&"+parameters : url+"?"+parameters;
		newwin = window.open(url,'chanelfullscreen', 'width='+newWidth+',height='+newHeight+',left=0,top=0,status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0');
		newwin.resizeTo(newWidth,newHeight);
		newwin.moveTo(0,0);
        if (!newwindow)
        {
            top.window.opener = top;
            top.window.close();
        }
	}
}
var ns = (document.layers) ? 1:0;
var ns6 = (document.sidebar) ? 1:0;
var agt=navigator.userAgent.toLowerCase();
var is_ie=(agt.indexOf("msie")!=-1);
var is_net=(agt.indexOf("mozilla/5")!=-1);
var is_mac = agt.indexOf("Mac")>-1;

if (is_ie || is_net) 
{
	var ie = true;
}   

if (ns) 
{
	widthCheck = window.innerWidth;
	heightCheck = window.innerHeight;
	window.onResize = resizeFix;
}

function opnPop(mypage)
{
    if (is_ie && ! is_mac)
        {
            if (typeof win == "undefined")
			{
                 window.open(mypage,'','fullscreen=1');
			}
        }
        else
		{
        	var win=window.open(mypage,'ahs','width='+screen.width+',height='+screen.height+',top=0,left=0');
		}
}

function resizeFix() 
{
	if (widthCheck != window.innerWidth || heightCheck != window.innerHeight)
	{
		document.location.href = document.location.href;
	}
}



function RolloverEngine(pat)
{
	if (pat && pat != null)
	{
		this.pattern = (typeof pat == "string") ? new RegExp(pat) : pat;
	}
	else 
	{
		this.pattern = null;
	}

	RolloverEngine.images = new ImageCollection();
	this.ready = false;
	this.findImages();
	this.ready = true;
	return this;
}



RolloverEngine.prototype.findImages = function(doc)
{	
	if (!doc) doc = window.document;
	{
		if (doc.images.length > 0)
		{	
			var img, a, b;
			for (a = 0; a < doc.images.length; a++)
			{	
				img = doc.images[a];
				if (img.name)
				{	
					if (this.pattern == null || this.pattern.test(img.name))
					{
						this.loadImage(img);
					}
				}
			}
		}
		if (doc.layers && doc.layers != null)
		{	
			if (doc.layers.length > 0)
			{	
				for (b = 0; b < doc.layers.length; b++)
				{	
					this.findImages(doc.layers[b].document);
				}
			}
		}
	}
};

RolloverEngine.prototype.loadImage = function(img)
{
	if (img && img != null && img.src)
	{
		img.over = new Image();
		img.over.src = img.src.replace('_off', '_over');
		//alert(img.name);
		//RolloverEngine.images.addImage(img);
		if (img.name.lastIndexOf("Swatch") == -1) 
		{
			RolloverEngine.images.addImage(img);
		}
	}
};

RolloverEngine.prototype.containsImage = function(strName)
{	
	return (strName && strName != null) ? (RolloverEngine.images[strName] && RolloverEngine.images[strName] != null) : false;

};

RolloverEngine.prototype.getImage = function(strName)
{
	return (this.containsImage(strName)) ? RolloverEngine.images[strName] : null;
};

RolloverEngine.prototype.setOff = function(strName)
{
	if (img && img != null && this.ready && !img.locked) 
	{
		img.src = img.over.src.replace('_over', '_off');
	}
};

RolloverEngine.prototype.setOver = function(strName)
{
	img = this.getImage(strName);
	if (img && img != null && this.ready && !img.locked) 
	{
		img.src = img.over.src;
	}
};


RolloverEngine.prototype.isOver = function(strName)
{	
	img = RolloverEngine.images[strName];
	return (img && img != null && img.src == img.over.src);
};


function ImageCollection()
{	
	this.images = new Array();
}

ImageCollection.prototype.addImage = function(img)
{	
	if (img && img != null && img.name)
	{	
		this.images[this.images.length++] = img;
		eval("this." + img.name + " = img;");
	}
};

function setgnavstate() 
{
	if (chsetdefgnav) 
	{  
		eval("re.setOver('"+chsetdefgnav+"');");
	}
	if (chsetdefgnavdiv) 
	{
		eval("re.setOver('chgi"+chsetdefgnavdiv+"');");
	}
}

function gnavinit() 
{
	// re = new RolloverEngine();
	// setgnavstate();
}

if (!document.re) 
{ 
	re = new RolloverEngine();
}

function hFlashTrack()
{
	for (var I=0;I<arguments.length;I++)
	{
		if (arguments[I].indexOf('WT.')==0)
		{
			WT[arguments[I].substring(3)]=arguments[I+1];
			I++;
		}
		if (arguments[I].indexOf('DCS.')==0)
		{
			DCS[arguments[I].substring(4)]=arguments[I+1];
			I++;
		}
		if (arguments[I].indexOf('DCSext.')==0)
		{
			DCSext[arguments[I].substring(7)]=arguments[I+1];
			I++;
		}
		if (arguments[I].indexOf('dcsID')==0)
		{
			dcsID=arguments[I+1];
			I++;
		}
	}
	dcsTag(gTagPath);
}

function chopenwin(page, name, w, h, c) 
{
    xposition=0; 
	yposition=0;
    if ((parseInt(navigator.appVersion) >= 4 ) && (c))
	{
        xposition = (screen.width - w) / 2;
        yposition = (screen.height - h) / 2;
    }

    args = "width=" + w + "," 
		+ "height=" + h + "," 
		+ "location=0," 
		+ "menubar=0,"
		+ "resizable=0,"
		+ "scrollbars=1,"
		+ "status=0," 
		+ "titlebar=0,"
		+ "toolbar=0,"
		+ "hotkeys=0,"
		+ "screenx=" + xposition + "," 
		+ "screeny=" + yposition + ","  
		+ "left=" + xposition + ","     
		+ "top=" + yposition;
    window.open(page,name,args);
}

function chopenwinbig(page, name, w, h, c, resize) 
{
	if (name=='glosshome')
	{
		hFlashTrack('DCS.dcsuri','/fb/chanelcom/en-us/Gloss Link/Home Page URL','DCSext.ch_div','fb','DCSext.ch_loc','usa','DCSext.ch_lang','en-us','DCSext.ch_re','chanelcom','DCSext.ch_cat','Gloss Link','DCSext.ch_scat1','Home Page URL');
	}
	if (name=='glossnews')
	{
		hFlashTrack('DCS.dcsuri','/fb/chanelcom/en-us/Gloss Link/News Page URL','DCSext.ch_div','fb','DCSext.ch_loc','usa','DCSext.ch_lang','en-us','DCSext.ch_re','chanelcom','DCSext.ch_cat','Gloss Link','DCSext.ch_scat1','News Page URL');
	}
	xposition=0; 
	yposition=0;
	
	if ((parseInt(navigator.appVersion) >= 4 ) && (c))
	{
		xposition = (screen.width - w) / 2;
		yposition = (screen.height - h) / 2;
	}

	if (ns6) { h = h - 10; }

    args = "width=" + w + "," 
    + "height=" + h + "," 
    + "resizable=" + (resize ? "1" : "0") + ","
    + "scrollbars=1,"
    + "screenx=" + xposition + "," 
    + "screeny=" + yposition + ","  
    + "screeny=" + yposition + ","  
    + "left=" + xposition + ","   

	if (name=='glossnews'||name=='glosshome')
	{
		args=args+ "menubar=1,location=1,status=1,titlebar=1,toolbar=1,hotkeys=1,top=" + yposition;
	}
	else
	{
		args=args+ "menubar=0,location=0,status=0,titlebar=0,toolbar=0,hotkeys=0,top=" + yposition;
	}
	
	if (ns) {  args = args + ", alwaysRaised, dependent";  }

	window.open(wsmlMakeResourceUrl(page),name,args);
}

var precisionWin=0;

function openPrecisionWindow(URLStr, left, top, width, height)
{
  if (precisionWin)
  {
    if (!precisionWin.closed) { precisionWin.close(); }
  }
  precisionWin = open(URLStr, 'precisionWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  precisionWin.focus();
}


// Cookie Helper Functions
function getCookie(c_name)
{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
}

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function writeBagCount()
{
	var _nav_bag_count; 
	var _nav_count_image;
	_nav_bag_count = getCookie("CartCookie");
	_nav_count_image = "0.gif";
	if (Number(_nav_bag_count) > 0) { _nav_count_image = String(_nav_bag_count)+".gif"; }
	document.write('<img src="http://uma.live.chanel.com/images/common/bag/items/'+_nav_count_image+'" border="0">');
}


// Helper Functions
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_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_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];}
}
