﻿var ie = false;

function PageHeight( )
{
    if(typeof ie == "boolean");
    {
        if(ie)
        {
            ResizeBar();
        }
    }
    //alert(navigator.userAgent);
    FlashHeader( );
    
    var iHeight = document.height;
    var iWindow = window.innerHeight;
    if(iHeight > iWindow)
    {
        document.body.style.height = "auto";
    }
    else
    {
        document.body.style.height = "100%";
    }
}
function GetPageWidth( )
{
    return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth: null;
}
function FlashHeader( )
{
    var oPanel = document.getElementById("ctl00_pnlPdf");
    if(oPanel != null)
    {
        var oHeaders = document.getElementsByTagName("h1");
        var oHeader = oHeaders[0];
        oHeader.style.width = "380px";
        if(typeof IEHeaderFix == "function")
        {
            IEHeaderFix( );
        }
    }   
}
 function Popup( )
{
    var form = document.getElementById("emailform");
    if(form == null)
    {
        form = document.getElementById("ctl00_emailform");
    }
    if(form == null)
    {
        return;
    }
    form.style.display = "block";
}
function ClosePopup( )
{
    var form = document.getElementById("emailform");
    if(form == null)
    {
        form = document.getElementById("ctl00_emailform");
    }
    if(form == null)
    {
        return;
    }
    form.style.display = "none";
}
function CloseSubmit( )
{
    var form = document.getElementById("submitform");
    if(form == null)
    {
        form = document.getElementById("ctl00_submitform");
    }
    if(form == null)
    {
        return;
    }
    form.style.display = "none";
}
function SubmitPopup( )
{
    //ClosePopup( );
    var form = document.getElementById("emailform");
    if(form == null)
    {
        ClosePopup( );
        return;
    }
    //form.style.display = "block";
    //form.innerHTML = "<p>Thank you for subscribing to Brandtrends&trade;</p>";
    var newform = document.createElement("div");
    newform.className = "emailform";
    newform.setAttribute("id","submitform");
    newform.innerHTML = "<p>Thank you for subscribing to Brandtrends&trade;</p>";
    newform.style.display = "block";
    form.parentNode.appendChild(newform);
    setTimeout('CloseSubmit( )',1500);  
}
function PDFHover(link)
{
    document.body.style.cursor = 'pointer';
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/pdf_icon_hover.jpg");
    
    var span = link.parentNode.getElementsByTagName("span")[0];
    //span.style.display = "inline";
    span.innerHTML = "download single PDF";
}
function PDFMouseOut(link)
{
    document.body.style.cursor = 'default';
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/pdf_icon.jpg");
    
    var span = link.parentNode.getElementsByTagName("span")[0];
    //span.style.display = "none";
    span.innerHTML = "";
}
function BrochureHover(link)
{
    document.body.style.cursor = 'pointer';
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/brochure_icon_hover.jpg");
    var span = link.parentNode.getElementsByTagName("span")[0];
    span.innerHTML = "add to brochure";
}
function BrochureClick(link,num)
{
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/brochure_icon_click.jpg");
    var span = link.parentNode.getElementsByTagName("span")[0];
    
    var brochure = getCookie("brochure");
    if(brochure != null)
    {
        if(brochure.indexOf(";" + num + ";") > 0 || brochure.substring(((num + "").length + 1),0) == num + ";")
        {
            span.innerHTML = "already in brochure";
        }
        else
        {
            span.innerHTML = "page added";
        }
    }
    else
    {
        span.innerHTML = "page added";
    }
}
function BrochureRelease(link)
{
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/brochure_icon_hover.jpg");
}
function BrochureMouseOut(link)
{
    document.body.style.cursor = 'default';
    var img = link.firstChild;
    img.setAttribute("src","/images/buttons/brochure_icon.jpg");
    var span = link.parentNode.getElementsByTagName("span")[0];
    span.innerHTML = "";
}
function BrochureHighlight( )
{
    //alert(getCookie("brochure"));
    var iTime = 0
    SetToGray(SetToRed(SetToGray(SetToRed(SetToGray(SetToRed(iTime))))));
}
function BrochureView( )
{
    alert(getCookie("brochure"));
    var iTime = 0
    SetToGray(SetToRed(SetToGray(SetToRed(SetToGray(SetToRed(iTime))))));
}
function SetToRed(iTime)
{
    //alert("to red");
    var iInterval = 150;
    setTimeout('SetColor("926780")',iTime + 0);
    setTimeout('SetColor("A64D7E")',iTime + (iInterval * 1));
    setTimeout('SetColor("BA347B")',iTime + (iInterval * 2));
    setTimeout('SetColor("CE1A79")',iTime + (iInterval * 3));
    setTimeout('SetColor("E20177")',iTime + (iInterval * 4));
    
    return iTime + (iInterval * 5);
}
function SetToGray(iTime)
{
    //alert("to gray");
    var iInterval = 150;
    setTimeout('SetColor("CE1A79")',iTime + 0);
    setTimeout('SetColor("BA347B")',iTime + (iInterval * 1));
    setTimeout('SetColor("A64D7E")',iTime + (iInterval * 2));
    setTimeout('SetColor("926780")',iTime + (iInterval * 3));
    setTimeout('SetColor("7E8082")',iTime + (iInterval * 4));
    
    return iTime + (iInterval * 5);
}
function SetColor(color)
{
    var link = document.getElementById("brochure");
    link.style.color = "#" + color;
}
function Brochure()
{
    var brochure = getCookie("brochure");
    if(brochure != null)
    {
        window.location = "http://www.thinkkaleidoscope.com/brochure.aspx?brochure=" + brochure;
    }
    else
    {
        window.location = "http://www.thinkkaleidoscope.com/brochure.aspx";
    }
}
function RemoveBrochure(link,num)
{
    //alert("HELLOOOOOO");
    var now = new Date( );
    fixDate(now);
    
    //now.setTime(now.getTime( ) + 1000 * 60 * 30); //set the timeout for one half hour
    now.setTime(now.getTime( ) + 1000 * 60 * 60 * 24); //set the timeout for 24 hours
    
    var brochure = getCookie("brochure");
    
    if(brochure == null)
    {
        return;
    }
    else
    {
        brochure = brochure.replace(";" + num + ";",";");
        if(brochure.substring((num.length + 1),0) == num + ";")
        {
            brochure = brochure.substring(brochure.length,num.length + 1);
        }
    }
    setCookie("brochure",brochure,now,"/");
    
    Brochure( );
    //var row = link.parentNode.parentNode;
    //var table = row.parentNode;
    //table.removeChild(row);
}
function AddBrochure(link,num)
{
    var now = new Date( );
    fixDate(now);
    
    now.setTime(now.getTime( ) + 1000 * 60 * 60 * 24); //set the timeout for one half hour
    //now.setTime(now.getTime( ) + 1000 * 60 * 10); //set the timeout for ten minutes
    
    var brochure = getCookie("brochure");
    
    if(brochure == null)
    {
        brochure = num + ";";
    }
    else
    {
        if(brochure.indexOf(";" + num + ";") > 0 || brochure.substring(((num + "").length + 1),0) == num + ";")
        {
            //its already there;
            //alert("You already have this one");
            //var span = link.parentNode.getElementsByTagName("span")[0];
            //span.innerHTML = "already in brochure";
            return;
        }
        brochure = brochure + num + ";";
    }
    setCookie("brochure",brochure,now,"/");
    
    BrochureHighlight( );
}
function GoToPDF(link)
{
    window.location = "http://www.thinkkaleidoscope.com" + link;
}


/***A more elegant implementation of google analytics - by Al Stevens 20 July 2008***/


/* Simplifies onload, you will no longer have to add an onload event call just call addLoadEvent */
function addLoadEvent(func,arg){

if (!arg){
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
}
}
  else{/*if the onload event has an argument/parameter cater for that*/
  if (arg){
  oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func(arg); 
	}
     window.onload = function() {
      oldonload();
      func(arg); 
    }
  }
}
}
function loadGAScript(){
	/*Check browser for Dom compatibility*/
if (!document.getElementsByTagName) return false;
/*Determines whether the page is using a secure or unsecure protocol*/
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
/*Writes in the script to the document head*/
var gaScript = document.createElement("script");
gaScript.setAttribute("src",gaJsHost +"google-analytics.com/ga.js");
gaScript.setAttribute("type","text/javascript");
var domHead = document.getElementsByTagName("head")[0]
domHead.appendChild(gaScript);
	}
	loadGAScript();

/*Calls the analytics function*/
function callGA(){	
var pageTracker = _gat._getTracker("UA-7904963-3");
pageTracker._initData();
pageTracker._trackPageview();
}

addLoadEvent(callGA);