var randDARTNumber=0;
var pageURI='';
function genSetRandDARTNumber()
{
  randDARTNumber = Math.round(Math.random()*1000000000000);
}
function genPageURI()
{
  pageURI = escape(document.URL.substring(document.URL.indexOf('/',8)+1));
}
genSetRandDARTNumber();
genPageURI();

locationDetails = whereAmI();

domain = "http://" + locationDetails.currLoc + "/";
currPageType = location.href;
currPageType = currPageType.substring(domain.length, currPageType.length);
currPageType = currPageType.split("/");

if(currPageType[0] == "style" && currPageType.length == 1) {
  window.location.replace("http://" + locationDetails.currLoc + "/style/");
}

// code yanked from the Yahoo media player. Thanks, Yahoo.
if (! ("console" in window) || !("firebug" in console)) {
    var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
    window.console = {};
    for (var i = 0; i <names.length; ++i) window.console[names[i]] = function() {};
}

/*
	Date Format 1.1
	(c) 2007 Steven Levithan <stevenlevithan.com>
	MIT license
	With code by Scott Trenda (Z and o flags, and enhanced brevity)
*/

/*** dateFormat
	Accepts a date, a mask, or a date and a mask.
	Returns a formatted version of the given date.
	The date defaults to the current date/time.
	The mask defaults ``"ddd mmm d yyyy HH:MM:ss"``.
*/
var dateFormat = function () {
	var	token        = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloZ]|"[^"]*"|'[^']*'/g,
		timezone     = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (value, length) {
			value = String(value);
			length = parseInt(length) || 2;
			while (value.length < length)
				value = "0" + value;
			return value;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask) {
		// Treat the first argument as a mask if it doesn't contain any numbers
		if (
			arguments.length == 1 &&
			(typeof date == "string" || date instanceof String) &&
			!/\d/.test(date)
		) {
			mask = date;
			date = undefined;
		}

		date = date ? new Date(date) : new Date();
		if (isNaN(date))
			throw "invalid date";

		var dF = dateFormat;
		mask   = String(dF.masks[mask] || mask || dF.masks["default"]);

		var	d = date.getDate(),
			D = date.getDay(),
			m = date.getMonth(),
			y = date.getFullYear(),
			H = date.getHours(),
			M = date.getMinutes(),
			s = date.getSeconds(),
			L = date.getMilliseconds(),
			o = date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4)
			};

		return mask.replace(token, function ($0) {
			return ($0 in flags) ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":       "ddd mmm d yyyy HH:MM:ss",
	shortDate:       "m/d/yy",
	mediumDate:      "mmm d, yyyy",
	longDate:        "mmmm d, yyyy",
	fullDate:        "dddd, mmmm d, yyyy",
	shortTime:       "h:MM TT",
	mediumTime:      "h:MM:ss TT",
	longTime:        "h:MM:ss TT Z",
	isoDate:         "yyyy-mm-dd",
	isoTime:         "HH:MM:ss",
	isoDateTime:     "yyyy-mm-dd'T'HH:MM:ss",
	isoFullDateTime: "yyyy-mm-dd'T'HH:MM:ss.lo"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask) {
	return dateFormat(this, mask);
}

function redirectTopic(currPageType) {
  domain = "http://" + locationDetails.currLoc + "/";
  console.log(domain);
  currPageType = currPageType.substring(domain.length, currPageType.length);
  currPageType = currPageType.split("/");
  console.log(currPageType);
  if(currPageType[0] == "topic") {
      window.location.replace("http://" + locationDetails.currLoc + "/showcase/" + currPageType[1] + "/");
  }
}

function getUID() {
    var d = new Date();
    var uID = Math.floor(Math.random()*d.getMilliseconds()) + "-" + Math.floor(Math.random()*d.getMilliseconds());
    return uID;
}

function refreshAds() {
        genSetRandDARTNumber();
        refreshAd("#leaderboard");
        refreshAd("iframe#square", "square");
	refreshAd("#companionad");
    }
    
function refreshAd(id) {
    if($(id).size() != 0 && typeof $(id)[0].src != "undefined") {
      adServerURL = $(id)[0].src.substring(0,$(id)[0].src.lastIndexOf("?"));
      qString = $(id)[0].src.substring(($(id)[0].src.lastIndexOf("?")+1),$(id)[0].src.length);
      temp = qString.split("&");
      var qArray = {};
      for(i=0;i<temp.length;i++) {
	  z = temp[i].split("=");
	  qArray[z[0]] = z[1];
      }
      qArray["randDARTNumber"] = randDARTNumber;
      qArray["adType"] = id.substring(1,id.length);
      if(arguments.length > 1) {
        qArray["adType"] = arguments[1];
      }
      newServerURL = adServerURL;
      currOperator = "?";
      i = 0;
      for(var key in qArray) {
	  if(i != 0) {
	      currOperator = "&";
	  }
	  newServerURL = newServerURL + currOperator + key + "=" + qArray[key];
	  i++;
      }
      $(id)[0].src = newServerURL;
    }
}

function jumpToAnchor(anchor) {
    if($(anchor).size() != 0) {
        newPos = $(anchor).offset().top;
        document.documentElement.scrollTop = newPos;
        document.body.scrollTop = newPos;
    }
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}

function getPageScrollTop(){
	var yScrolltop;
	var xScrollleft;
	if (self.pageYOffset || self.pageXOffset) {
		yScrolltop = self.pageYOffset;
		xScrollleft = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop || document.documentElement.scrollLeft ){	 // Explorer 6 Strict
		yScrolltop = document.documentElement.scrollTop;
		xScrollleft = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScrolltop = document.body.scrollTop;
		xScrollleft = document.body.scrollLeft;
	}
	arrayPageScroll = new Array(xScrollleft,yScrolltop) 
	return arrayPageScroll;
}

function getPageSize(){
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight
	arrayPageSize = new Array(w,h) 
	return arrayPageSize;
}

function setPos(elm) {
    $elm = $(elm);
    var pagesize = [];
    pagesize.push($(window).width());
    pagesize.push($(window).height());
    var arrayPageScroll = getPageScrollTop();
    var newLeft = arrayPageScroll[0] + (pagesize[0] - $elm.width())/2;
    var newTop = arrayPageScroll[1] + (pagesize[1]-$elm.height())/2;
    if(newLeft < 0) {
        newLeft = 0;
    }
    if(newTop < 0) {
        newTop = 0;
    }
    var style = {position:"absolute", left: newLeft, top: newTop, display:"none"};
    $elm.css(style).fadeIn();
}

function generateID() {
    var curdate = new Date()
    var seconds = curdate.getSeconds();
    var milliseconds = curdate.getTime();
    id = "id" + Math.floor(Math.random()*Math.floor(milliseconds/seconds));
    return id;
}

function playSelectedVideo(url) {
    if($("div#videoplayer").size() != 0) {
        param = url.substring(url.lastIndexOf("?")+1, url.length);
        params = param.split("&");
        for(i=0;i<params.length;i++) {
          temp = params[i];
          temp = temp.split("=");
          if(temp[0] == "id") {
            param = temp[1];
          }
        }
        if(embeddedPlayerManager.getPlayer().isPlayingAd() == false) {
            embeddedPlayerManager.getPlayer().playVideo(param);
            embeddedPlayerManager.getPlayer().play();
        } else {
            alert("Please wait till the pre-roll ad is finished before selecting another video to play.");
        }
    } else {
        window.location = url;
    }
    return false;
}

function playVideoInEP(id) {
    $("div.videoinfo").remove();
    embeddedPlayerManager.getPlayer().playVideo(id);
    embeddedPlayerManager.getPlayer().play();
}

function popupWin(aUrl,aName,properties) {
    window.open(aUrl,aName,properties);
}

function hpPopupWin(aUrl,aName,width,height) {
    paramString = 'width=' + width + ',height=' + height + ',scrollbars=1,resizable=1';
    window.open(aUrl,aName,paramString);
	//hpPopupWin('http://www.accesshollywood.com/special/live-stream/','popup','660','450');
    //popupWin('http://www.accesshollywood.com/special/sag-dress-game/index.php','popup','width=956,height=670')
}

function setColumnHeights(location) {
    settings = {
        base: 1,
        columns: [
            "#panel_0_0,#panel_0_1",
            "#panel_0_0,#panel_0_2",
            "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2"
        ],
        columnEnds: []
    };
    switch(location) {
        default:
            obj = null;
        break;
        case 'home':
            obj = {
                columns: [
                    "#panel_0_0,#panel_0_1",
                    "#panel_0_0,#panel_0_2",
                    "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2"
                ]
            }
        break;
        case 'topic':
            obj = {
                columns: [
                    "#panel_0_0,#panel_0_1",
                    "#panel_0_0,#panel_0_2",
                    "#panel_1_0,#panel_1_1,#channel_1_1,#panel_1_2"
                ]
            }
        break;
        case 'celeb':
            obj = {
                base: 0,
                columns: [
                    "#panel_0_0,#channel_0_0,#panel_0_2,#channel_0_2,#panel_0_3,#channel_0_3,#panel_0_4,#channel_0_4,#panel_0_6",
                    "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2,#channel_1_2,#panel_1_3"
                ]
            }
        break;
        case 'celebs':
            obj = {
                base: 0,
                columns: [
                    "#col_0",
                    "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2,#channel_1_2,#panel_1_3,#channel_1_3,#panel_1_4,#channel_1_4,#panel_1_5"
                ]
            }
        break;
        case 'galleries':
            obj = {
                base: 0,
                columns: [
                    "#col_0",
                    "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2,#channel_1_2,#panel_1_3,#channel_1_3,#panel_1_4,#channel_1_4,#panel_1_5"
                ]
            }
        break;
        case 'topics':
            obj = {
                base: 0,
                columns: [
                    "#col_0",
                    "#panel_1_0,#channel_1_0,#panel_1_1,#channel_1_1,#panel_1_2,#channel_1_2,#panel_1_3,#channel_1_3,#panel_1_4,#channel_1_4,#panel_1_5"
                ]
            }
        break;
    }
    if(obj == null) {
        return;
    }
    settings = $.extend(settings, obj);
    heights = [];
    for(i=0;i<settings.columns.length;i++) {
        heights[i] = 0;
        panels = settings.columns[i].split(",");
        for(z=0;z<panels.length;z++) {
            $(panels[panels.length-1] + " div.end").css("margin-top", 0);
            heights[i] += $(panels[z]).outerHeight();
            if(z==panels.length - 1) {
                settings.columnEnds.push(panels[z] + " div.end");
            }
        }
    }
    for(i=0;i<settings.columns.length;i++) {
        if(i != settings.base) {
            diff = heights[settings.base] - heights[i];
            if(diff > 0) {
                $(settings.columnEnds[i]).css("margin-top", diff);
            }
        }
    }
}

function initBase() {
    $("div.btnlcround").each(function () {
        baseFrag = $(this).find("span");
        htmlFrag = baseFrag.clone().addClass("shadow").css("margin-right",(baseFrag.outerWidth({padding:true})* -1));
        $(this).find("a").prepend(htmlFrag);
    });
    
    $(".flashcontent").each(function () {
        var newID = generateID();
        $(this).attr("id",newID);
        classNames = $(this)[0].className.split(" ");
        fontSize = 22;
        for(i=0;i<classNames.length;i++) {
            check = classNames[i].split("-");
            if(check.length > 1) {
                fontSize = check[1];
            }
        }
        $(this).removeClass("flashcontent").height(fontSize*2);
        txtString = $("#" + newID).text();
        uid = getUID();
        var so = new SWFObject("http://" + locationDetails.staticLoc + "/ah/flash/reflectionHeadlines.swf", newID, "990", "88", "9", "#000000");
        so.addParam("wmode", "transparent");
        so.addVariable("text",txtString);
        so.addVariable("size",fontSize);
        //so.addVariable("uid",uid);
        so.write(newID);
    });
    
    $("a[@href=#]").bind("click", function () {
        return false;
    });
    
    $("div.logo").each(function () {
        var newID = generateID();
        $(this).attr("id",newID);
        var so = new SWFObject("http://" + locationDetails.staticLoc + "/ah/flash/access-logo.swf", newID, "250", "130", "9", "#000000");
        so.addParam("wmode", "transparent");
        so.write(newID);
    });
    
    $("div.news h2:eq(0)").each(function () {
        var newID = generateID();
        $(this).attr("id",newID);
        var so = new SWFObject("http://" + locationDetails.staticLoc + "/ah/flash/breaking4.swf", newID, "440", "65", "9", "#000000");
        so.addParam("wmode", "transparent");
        so.write(newID);
    });
    
    $("div.search_box label").each(function () {
        forName = $(this).attr("for");
        if(forName != undefined) {
	    if($("#" + forName).attr("type") == "text") {
		$("#" + forName).attr("value",$(this).text());
		$(this).remove();
	    }
        }
    });
    
    $("div.search_box input").bind("focus", function () {
        this.value = "";
        $(this).css("color","black");
    }).bind("blur",function () {
        $(this).css("color","#B5B5B5");
    });
    
    $("div.search_box input.button").each(function () {
        htmlFrag = $("<div class='button'><div class='ender'><a href='#'><span>" + $(this).attr("value") + "</span></a></div></div>");
	$(this).css({width:"1px", height:"1px", position:"absolute", top:"-1000px"}).after(htmlFrag);
    });
    
    if($("body").attr("id") == "article") {
      setTimeout(function () {
          checkVideo("playEPVideo()");
      }, "8000");
    }
    
    $("div.promote a[@class=]").each(function () {
        if(this.href.indexOf("javascript") == -1) {
          hrefMod = "__source=promote";
          queryStringMod = "?";
          if(this.href.indexOf("?") != -1) {
              queryStringMod = "&";
          }
          this.href = this.href + queryStringMod + hrefMod;
        }
    });
	
	/* 2008-03-25 AML - Added code for loading the flippy */
	/* 2008-03-26 AC - Refined code */
	if($("#flipAd").size() != 0) {
	  var xmlPath = "http://" + locationDetails.staticLoc + "/ah/xml/flippy/flippy.xml";
	  var loadFlippy = function(xmlPath){
		  var flipSO = new SWFObject("http://" + locationDetails.staticLoc + "/ah/flash/flippy.swf", "flipAd", "300", "80", "9", "#09212B");
		  flipSO.addParam("quality", "high");
		  flipSO.addParam("allowScriptAccess", "always");
		  flipSO.addParam("play", "true");
		  flipSO.addParam("autoPlay", "true");
		  flipSO.addParam("salign", "middle");
		  flipSO.addParam("wmode", "transparent");
		  flipSO.addVariable("path", xmlPath);
		  flipSO.write("flipAd");
	  }
	  loadFlippy(xmlPath);
	}
	
	/* 2008-04-23 AML - Added code for loading the second flippy */
	if($("#flipAd2").size() != 0) {
	  var xmlPath2 = "http://" + locationDetails.staticLoc + "/ah/xml/flippy/flippy2.xml";
	  var loadFlippy2 = function(xmlPath){
		  var flipSO = new SWFObject("http://" + locationDetails.staticLoc + "/ah/flash/flippy.swf", "flipAd2", "300", "80", "9", "#09212B");
		  flipSO.addParam("quality", "high");
		  flipSO.addParam("allowScriptAccess", "always");
		  flipSO.addParam("play", "true");
		  flipSO.addParam("autoPlay", "true");
		  flipSO.addParam("salign", "middle");
		  flipSO.addParam("wmode", "transparent");
		  flipSO.addVariable("path", xmlPath2);
		  flipSO.write("flipAd2");
	  }
	  loadFlippy2(xmlPath);
	}

        
    $("a[@href*=/gallery], a[@href*=/video], a[@href*=/article]").bind("click", function () {
      if(!checkForChild(this.href)) {
        $(this).attr("target", "contentWin");
      }
    });
    
    $("div#navigation li#home a, a[@href*=/topic], a[@href*=/galleries], a[@href*=/celeb], a[@href*=/special], a[@href*=/blogs], a[@href*=/showcase], a[@href*=/feature]").bind("click", function () {
      if(checkforParent(this.href)) {
        window.opener.location = this.href;
        window.close();
      }
    });
    
    $("div.promote img").bind("click", function () {
      window.location = $(this).parents("a").attr("href");
    });
    
    /*if(location.href == "http://www.accesshollywood.com" || location.href == "http://www.accesshollywood.com/") {
      htmlFrag = $("<div id='olympic-medals'></div>");
      $("#col_1 div.promotes h3").after(htmlFrag);
      setTimeout(function () {
          var so = new SWFObject("http://wgtclsp.nbcolympics.com/o/4815fb5c4809f394/489f1dc3f089e60d/4833049d801812e7/1785244c", "olympic-medals", "300", "400", "9", "#ffffff");
          so.addParam("transparent", "wmode");
          so.addParam("allowNetworking", "all");
          so.addParam("allowScriptAccess", "always");
          so.write("olympic-medals");
      }, "250");
    }*/
	
	$("a[@href*=11123]").bind("click",function () {
		hpPopupWin('http://www.accesshollywood.com/special/live-stream/','popup','675','460');
		return false;
	  });
	
  
    setTimeout(function () {setColumnHeights($("body").attr("id"))}, "3000");
    if($("div.drawers b:contains(There is no result to display.)").size() != 0) {
      setTimeout(function () {showEPVideoDetails()}, "4000");
    }
    setTimeout(function () { document.location.reload(); }, "12000000");
}

function checkForChild(href) {
  if(typeof window.children == "undefined") {
    return false;
  } else {
    return true;
  }
}

function checkforParent(href) {
  if(typeof window.opener == null || typeof window.opener == "undefined") {
    return false;
  } else {
    return true;
  }
}

var itemsPer = 4;

function fadePromotes(items, destination) {
    i = 0;
    itemHeight = 0;
    contFrag = $("<div class='promotes'></div>");
    $(items).each(function () {
        if(i == 0) {
            htmlFrag = $("<ul></ul>");
        }
        if(itemHeight < $(this).outerHeight()) {
            itemHeight += $(this).outerHeight();
        }
        liFrag = $("<li></li>");
        $(this).appendTo($(liFrag));
        liFrag.appendTo($(htmlFrag));
        i++;
        if(i == itemsPer) {
            i = 0;
        }
        htmlFrag.appendTo($(contFrag));
    });
    $(destination).after($(contFrag));
    $(destination).siblings("div.promotes").find("ul").each(function(i) {
        $(this).css("height",itemHeight).innerfade({
            animationtype: 'fade',
            speed: 1000,
            timeout: 4000 + (i * 1000),
            type: 'sequence',
            containerheight: itemHeight + 'px'
        });
    });
}

function playEPVideo() {
  if(typeof embeddedPlayerManager.getPlayer().play == "function") {
    embeddedPlayerManager.getPlayer().play();
  } else {
    setTimeout(function () {
        playEPVideo();
    }, "250");
  }
}

function showVideoDetails() {
    if(embeddedPlayerManager.getPlayer() != undefined && embeddedPlayerManager.getPlayer().currentClip.title != undefined) {
      $("div.videoinfo").remove();
      currClipInfo = embeddedPlayerManager.getPlayer().currentClip;
      htmlFrag = $("<div class='videoinfo'></div>");
      titleFrag = $("<p class='title'><strong>" + currClipInfo.title + "</strong></p>");
      descFrag = $("<p>" + currClipInfo.shortDescription + "</p>");
      htmlFrag.hide().append(titleFrag).append(descFrag);
      $("div.search_box form").before(htmlFrag);
      $("div.videoinfo").fadeIn();
      setColumnHeights($("body").attr("id"));
    } else {
      setTimeout(function () {
          showVideoDetails();
      }, "250");
    }
}

function showEPVideoDetails() {
    if(embeddedPlayerManager.getPlayer() != undefined && embeddedPlayerManager.getPlayer().currentClip.title != undefined) {
      $("div.videoinfo").remove();
      currClipInfo = embeddedPlayerManager.getPlayer().currentClip;
      htmlFrag = $("<div class='videoinfo'></div>");
      titleFrag = $("<p class='title'><strong>" + currClipInfo.title + "</strong></p>");
      descFrag = $("<p>" + currClipInfo.shortDescription + "</p>");
      htmlFrag.hide().append(titleFrag).append(descFrag);
      $("#videoplayer").after(htmlFrag);
      $("div.videoinfo").fadeIn();
      $("div.drawers").remove();
      setColumnHeights($("body").attr("id"));
    } else {
      setTimeout(function () {
          showEPVideoDetails();
      }, "250");
    }
}

function checkVideo() {
    func = showVideoDetails();
    if(arguments[0] != "") {
      func = arguments[0];
    }
    if(typeof embeddedPlayerManager.getPlayer == "function" && typeof embeddedPlayerManager.getPlayer() == "object") {
        eval(func);
    } else {
        setTimeout(function () {
            checkVideo();
        }, "250");
    }
    eval(func);
}

$(document).ready(function () {
    initBase();
	setupRockTheVotePopup();
});

// 2008-04-07 AML - Code added to allow first entrance popup of Garnier Contest
function createCookie(name,value,days) {
	if (!isNaN(parseFloat(days))) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		if (Date.parse(days)) {
			var date = new Date(days);
			var expires = "; expires=" + date.toGMTString();
		} else var expires = "";
	} 
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function setupGarnierPopup(){
	var garnier = readCookie('garnier');
	var now = new Date();
	var garnierEndDate = new Date('April 15, 2008');
	if ((now < garnierEndDate) && (garnier == null)) {
		createCookie('garnier', 'true', 'April 15, 2008');
		popupWin('http://www.accesshollywood.com/special/rock-your-style-contest/index.php', 'popup', 'width=400,height=300');
	}
}
function setupRockTheVotePopup(){
	var rockthevote = readCookie('rockthevote');
	var rockthevoteEndDate = new Date('November 7, 2008');
	if (rockthevote == null) {
		createCookie('rockthevote', 'true', 'November 7, 2008');
		popupWin('http://www.registrationbyworkingassets.com/register/?api_key=Mq8g7O0XQVAWVkSKKYkhpkX7Gjk', 'popup', 'width=600,height=300');
	}
}