// Flash debugging code 
var printable;
var popup;
var newwindow = 0;
var lastpageid = "Home";


if(getCookie("referrer") == "" && document.referrer != ""){
	document.cookie="referrer="+escape(document.referrer);	
}



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 "";
} 


///////////////////////////////////////////////////////////////////////
//////   perform redirects for old-style urls

/*
why?
The new version of swfaddress has changed the URL format to:
http://whatever/#/?whatever
There may and probably will still be users with old bookmarks and
links floating around that look like:
http://whatever/#whatever
or
http://whatever/#?whatever

we need to look for this on the client side because the browser
doesn't send the part after the # to the server.
if we find an incorrect URL, we change it and redirect.

*/

 function doRedirectForImproperURLs()
 {
	 var urlstr = '' + document.location;

	 var index = urlstr.indexOf('/#/?');
	 if (index > -1) return; // correct syntax, no redirect

	 // the order is important
	 if (checkForRedirect(urlstr, '/#?', '/#/?')) return;
	 if (checkForRedirect(urlstr, '/?#', '/#/?')) return;
	 if (checkForRedirect(urlstr, '#?', '#/?')) return;
	 if (checkForRedirect(urlstr, '?#', '#/?')) return;
	 if (checkForRedirect(urlstr, '/#', '/#/?')) return;
	 if (checkForRedirect(urlstr, '/?', '/#/?')) return;
	 if (checkForRedirect(urlstr, '#', '#/?')) return;
	 if (checkForRedirect(urlstr, '?', '#/?')) return;
 }
 
// why? DRY principle.
// for a given substring, if it is found, replace and redirect.
// returns true if we redirected, otherwise false.
// this function is only used by doRedirect, above.
//
 function checkForRedirect(urlstr, sub, repl)
 {
	 var index = urlstr.indexOf(sub);
	 if (index > -1) {
		 var s1 = urlstr.substring(0, index);
		 var s2 = urlstr.substring(index + sub.length);
		 redir =  s1 + repl + s2; // return correct url
		 //alert('changing document.location to' + redir)
		 document.location = redir;
		 return true;
	 }
	 return false;
 }


///////////////////////////////////////////////////////////////////////
//////   sharing

var pagespec='top{media:register}';

function setPagespec(str){
	pagespec=str;		
}			

function shareOnDelicious(url, title)
{
	window.open('http://delicious.com/save?v=5&amp;noui&amp;jump=close&amp;url='+encodeURIComponent(url)+'&amp;title='+encodeURIComponent(title), 'delicious','toolbar=no,width=550,height=550');
	return false;
}


function checkUnload(){				
	var flashMovie = document.getElementById('website');
	flashMovie.navigateFromJS(pagespec);
	
	var msg = '...';
	return msg;
}

function showMsgBeforeLeaving(on){
	window.onbeforeunload = (on) ? checkUnload : null;
}

showMsgBeforeLeaving(false);


///////////////////////////////////////////////////////////////////////
//// crm tracking

function SetSiebelReaction()
{
    var qs = new Querystring();
    var siebelReaction = qs.get("crm_email");
    var passedID = "";

    if(siebelReaction != null && siebelReaction != "")
        passedID = siebelReaction;

    if(passedID != "")
        Set_Cookie("crm_email", passedID, 0 ,"/","","");
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );

    /*
    if the expires variable is set, make the correct 
    expires time, the current script below will set 
    it for x number of days, to make it for hours, 
    delete * 24, for minutes, delete * 60 * 24
    */
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
    ( ( path ) ? ";path=" + path : "" ) + 
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}

///////////////////////////////////////////////////////////////////////
/// omniture tracking

var omnitureaccname;

function setOmnitureAccountName(accname)
{
	if ((accname + '') == 'undefined' || accname == null || accname == '') {
		omnitureaccname = 'lorealuscomdev';
	} else {
		omnitureaccname = accname;
	}
}

function getOmnitureAccountName()
{
	return omnitureaccname;
}


///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
/// atlas tracking

var TrackTag = 'http://switch.atdmt.com/jaction/';

function GetActionTag(URL){ 
  document.action_tag.src = TrackTag + URL;
}

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//// I don't know

function findElementWithName(d, name)
{
	if (d.nodeName == name) {
		return d;
	} else {
		for (var c = d.firstChild ; c ; c = c.nextSibling) {
			var t = findElementWithName(c, name);
			if (t != null) return t;
		}
		return null;
	}
}

function showAdditionalFooter(val)
{
	if ('' + val == 'true') {
		var c = document.getElementById('fm2');
		c.style.display = 'block';
	} else {
		var c = document.getElementById('fm2');
		c.style.display = 'none';
	}
}

function resizeFlash(newheight)
{
	var c = document.getElementById('flashcontent');
	c.style.height = '' + newheight  + 'px';
	// for safari we have to resize the embed tag also
	// since we are doing embed we might as well do the object tag as well
	var obj = findElementWithName(c, 'OBJECT');
	if (obj != null) {
		obj.height = newheight;
	}
	var embed = findElementWithName(c, 'EMBED');
	if (embed != null) {
		embed.height = newheight;
	}
}

///////////////////////////////////////////////////////////////////////
//// inserting the swfobject

// why:
// this function takes care of the annoying
// tricky business of adding a potentially
// null string onto the end of a potentially
// null string and making sure you don't get
// stray &'s
function addQSVar(qs, toadd)
{
	if (qs == '' && toadd == '') {
		return '';
	} else if (qs == '') {
		return toadd;
	} else if (toadd == '') {
		return qs;
	} else {
		return qs + '&' + toadd;
	}
}

var ___cid;

function setCID(newcid)
{
	___cid = newcid;
}

// why: pass query string values into flash.
// flashvar syntax is same as the query string format
// so we don't really need to parse the qs.
// The CID is not in the query string but
// everything else is.
function getTheFlashVars()
{
	var qs = '' + window.location;
	var left = qs.indexOf('?') + 1;
	var fv = qs.substring(left);
	var cid = ___cid;
	if (cid != '') {
		cid = 'cid=' + cid;
	}
	fv = addQSVar(fv, cid);
	return fv;
}


function insertSWFObject() {
	//alert('got here.');
	var so = new SWFObject('swf/lorealparis.swf', 'website', '950', '620', '9', '#000000');

	so.addParam('menu', 'false');
	so.addParam('scale', 'noscale');
	so.addParam('quality', 'high');
	so.addParam('flashvars',getTheFlashVars());
	so.addParam('allowScriptAccess','always');

	so.addParam('wmode','opaque');


	//alert('flashcontent=' + document.getElementById('flashcontent'));
	so.write('flashcontent');
}


///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////


function openWindowWithProps (url, target, props){
    window.open("redirect.aspx?url="+url, target, props);   
}

function openWindow (url, target){
    window.open("redirect.aspx?url="+url, target); 
}


function getURL(newWindow){
	window.open(newWindow);
}


function trace(str)
{
	if (newwindow == 0) {
		newwindow = window.open("about:blank", "", "width=400,height=500,scrollbars=yes");
		newwindow.document.write("<html><head></head><body><div id=\"debugspace\"></div></body></html>");
	}
	newwindow.document.all("debugspace").innerHTML += str;
}

function getFlashVars(wcflashvars)
{
	var fv;
	var qs = '' + window.location;
	var left = qs.indexOf("?") + 1;
	qs = qs.substring(left, qs.length);
	fv = qs + ((wcflashvars == '' && qs == '')?'':'&') + wcflashvars;
}
function printview (url, width, height, resizable){
//trace("url: "+url+" width: "+width+" height: "+height)
    if(printable == undefined || (printable && printable.closed)){
        printable = window.open("","printable", "width="+width+",height="+height+",resizable="+resizable+",scrollbars=yes,toolbar=yes,menubar=yes,status=yes")
    }   
    printable.location.replace(url);
}
function getLocation(){
    return location.toString();
}
function getReferrer()
{
    var cookieReferrer=getCookie("referrer");
    document.cookie =  "referrer=;expires=Thu, 01-Jan-1970 00:00:01 GMT";
    
    if(document.referrer != ""){
	    //alert("document: "+document.referrer);
	    return document.referrer;
    }else{
	//alert("cookie: "+cookieReferrer);
	    return cookieReferrer;
    }
}
function getElement(nm)
{
	return document.getElementById(nm);
}

function shouldDebugTracking()
{
	var qs = '' + window.location;
	return (qs.search(/showtracking=true/) != -1);
}


/* ADDED TO TEST BACKGROUND CENTERING */

function getWinSize()
{
	var myWidth = 0, myHeight = 0;
      if( typeof( window.innerWidth ) == 'number' )
      {
         //Non-IE
         myWidth = window.innerWidth;
         myHeight = window.innerHeight;
      }
      else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
      {
          //IE 6+ in 'standards compliant mode'
          myWidth = document.documentElement.clientWidth;
          myHeight = document.documentElement.clientHeight;
      }
      else if(document.body && (document.body.clientWidth || document.body.clientHeight))
      {
          //IE 4 compatible
          myWidth = document.body.clientWidth;
          myHeight = document.body.clientHeight;
      }
      return {w:myWidth,h:myHeight}
      
}   
   
function adjustObjectSize(id,w,h)
{
//alert("test");
      var winSizes = getWinSize();
            
      var tmpObject = document.getElementById(id);

      if(winSizes.w < w)
      {
         tmpObject.style.width = w + "px";
      }
      else
      {
         tmpObject.style.width = "100%";
      }
      if(winSizes.h < h)
      {
         tmpObject.style.height = h + "px";
      }
      else
      {
         tmpObject.style.height = (winSizes.h)-2 + "px";
      }
}
