browser_IE  = (document.all && navigator.appName == 'Microsoft Internet Explorer') ? true : false;
browser_NS4 = (document.layers) ? true : false;
browser_W3C = (!document.all && document.getElementById) ? true : false;

var platForm=navigator.platform;
var isMac=platForm.indexOf("Mac");

var now = new Date();
var one_year= new Date(now.getTime() + 1000 * 60 * 60 * 24 * 365);
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
/*
var idolColor = getCookie("idolColor");
var idolUser = getCookie("idolUser");
if ((idolColor!=null)&&(idolColor!="")){
document.write('<link rel="stylesheet" type="text/css" href="http://www.ctv.ca/idol/css/idol'+idolColor+'.css" />');
}else{
document.write('<link rel="stylesheet" '+'type="text/css" href="http://www.ctv.ca/idol/css/idol1.css" />');
}
*/
function rnd() {
  rnd.seed = (rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0);
}

function rand(number) {
  return Math.ceil(rnd()*number);
}
function splitDate(inputdate,separator) {
  arrayOfStrings = inputdate.split(separator);
  outputdate= new Date(arrayOfStrings[0],arrayOfStrings[1],arrayOfStrings[2]);
  return outputdate;
}

function playVideo(video_link_high, video_link_low, clip_start, clip_end, clip_caption, archive, slug, sortdate, clip_id, hub){
        var hub="idol";
  var w = 755, h = 519; // adjust width and height here.
  var vUrl = "/servlet/HTMLTemplate/!ctvVideo/"
    +  "/"
    +  "/"
    + "/?"
; // the video url
  var qString = 'hub='+hub+'&video_link_high=' + video_link_high + '&'
    + 'video_link_low=' + video_link_low + '&'
    + 'clip_start=' + clip_start + '&'
    + 'clip_end=' + clip_end + '&'
    + 'clip_caption=' + escape(clip_caption) + '&'
    + 'clip_id=' + clip_id;

  window.open( vUrl + qString
    +'&subhub=video','ctvVideo','width=' + w + ',height=' + h
    +',status=no,scrollbars=no,resizable=no,toolbar=no,left=176,screenX=200,top=0,screenY=0');
}


// Trims a string
function trim(str) {
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

/**
  * Used to correct the MAC date bug
  */
function fixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0) {  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
  }
}

function setCookie (cookieName, cookieValue, expires, path) {
  fixCookieDate(expires);
  document.cookie =
    escape(cookieName) + '=' + escape(cookieValue)
    + (expires ? '; EXPIRES=' + expires.toGMTString() : '')
    + (path ? '; PATH=' + path : '');
}

/**
  * Gets the cookie
  */
function getCookie (cookieName) {
    var cookieValue = null;
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) {
            cookieValue = unescape(document.cookie.substring(posValue,endPos));
        } else {
            cookieValue = unescape(document.cookie.substring(posValue));
        }
    }
    return cookieValue;
}

function checkUser(){
var user = getCookie("idolUser");
if (user==null || user==""){
window.location.href="/idol/login.html";
}
}
function framesPopUp(filename,winTitle, winName, winX, winY) {
 winName = "__" + winName;
 var regex = /\W+/;
 if( regex.test(winName) ) {
        winName = winName.replace(/\W+/, '_');
 }
 params = "width="+ winX +",height="+winY;
 winExec = winName +"= window.open('','"+winName+"', params)"
 content = "<html><head><title>"+winTitle+"</title><script>window.onload=function(){}</script></head><frameset rows='0,*' frameborder='NO' border='0' framespacing='0'><frame name='topFrame' scrolling='NO' noresize src='about:blank'><frame name='mainFrame' src='"+ filename +"' scrolling=AUTO></frameset><noframes><body bgcolor='#FFFFFF' text='#000000'></body></noframes></html>"
 eval(winExec);
 eval(winName + ".document.open()")
 eval(winName + ".document.write(content)")
 eval(winName + ".document.close()")
}

function _open_popup_window(w, h, link_url, slug, title){
 var regex = /\W+/;
 if( regex.test(slug) ){
   slug = slug.replace(/\W+/, '_');
 }
 if( w != '' && h != '' ) {
   framesPopUp(link_url, title, slug, w, h);
   return false;
 }
 return true;
}

function iRestore() { //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_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_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 iSwap() { //v3.0
  var i,j=0,x,a=iSwap.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];}
}

document.write('<input type="hidden" id="testHBX" value="testHBXCode1234" />');
document.write('<input type="hidden" id="testHBXPath" value="testHBXCode1234" />');
 
function mymovie_DoFSCommand(command, args)
{
	//if (command == "writeHBX")
	{		
		var html_doc = document.getElementsByTagName('head').item(0);
		js2 = document.createElement('script');
		js2.setAttribute('type', 'text/javascript');
		js2.setAttribute('src', "http://www.ctv.ca/mar/hbx/customIdolhbx2.js");
		//alert("GOT HERE");
		document.getElementById('testHBX').value = args;
		document.getElementById('testHBXPath').value = command;
		html_doc.appendChild(js2);
	 
	}
}

function mymovie2_DoFSCommand(command, args)
{
	mymovie_DoFSCommand(command, args);
}

function mymovie3_DoFSCommand(command, args)
{
	mymovie_DoFSCommand(command, args);
}

function mymovie4_DoFSCommand(command, args)
{
	mymovie_DoFSCommand(command, args);
}

