﻿// xp_progressbar
// Copyright 2004 Brian Gosselin of ScriptAsylum.com
//
// v1.0 - Initial release
// v1.1 - Added ability to pause the scrolling action (requires you to assign
//        the bar to a unique arbitrary variable).
//      - Added ability to specify an action to perform after a x amount of
//      - bar scrolls. This requires two added arguments.
// v1.2 - Added ability to hide/show each bar (requires you to assign the bar
//        to a unique arbitrary variable).
// var xyz = createBar(
// total_width,
// total_height,
// background_color,
// border_width,
// border_color,
// block_color,
// scroll_speed,
// block_count,
// scroll_count,
// action_to_perform_after_scrolled_n_times
// )
var w3c=(document.getElementById)?true:false;
var ie=(document.all)?true:false;
var N=-1;
function createBar(w,h,bgc,brdW,brdC,blkC,speed,blocks,count,action){
if(ie||w3c){
var t='<div style="width: 100%; text-align: center; display: block; margin-top: 50px;" id="featbar_container"><div id="_xpbar'+(++N)+'" style="visibility:visible; position:relative; margin: auto; overflow:hidden; width:'+w+'px; height:'+h+'px; background-color:'+bgc+'; border-color:'+brdC+'; border-width:'+brdW+'px; border-style:solid; font-size:1px;">';
t+='<span id="blocks'+N+'" style="left:-'+(h*2+1)+'px; position:absolute; font-size:1px">';
for(i=0;i<blocks;i++){
t+='<span style="background-color:'+blkC+'; left:-'+((h*i)+i)+'px; font-size:1px; position:absolute; width:'+h+'px; height:'+h+'px; '
t+=(ie)?'filter:alpha(opacity='+(100-i*(100/blocks))+')':'-Moz-opacity:'+((100-i*(100/blocks))/100);
t+='"></span>';
}
t+='</span></div></div>';
document.write(t);
var bA=(ie)?document.all['blocks'+N]:document.getElementById('blocks'+N);
bA.bar=(ie)?document.all['_xpbar'+N]:document.getElementById('_xpbar'+N);
bA.blocks=blocks;
bA.N=N;
bA.w=w;
bA.h=h;
bA.speed=speed;
bA.ctr=0;
bA.count=count;
bA.action=action;
bA.togglePause=togglePause;
bA.showBar=function(){
this.bar.style.visibility="visible";
}
bA.hideBar=function(){
this.bar.style.visibility="hidden";
if(document.getElementById("featbar_container"))
{
featbar_container.style.display="none";
}
}
bA.tid=setInterval('startBar('+N+')',speed);
return bA;
}}
function startBar(bn){
var t=(ie)?document.all['blocks'+bn]:document.getElementById('blocks'+bn);
if(parseInt(t.style.left)+t.h+1-(t.blocks*t.h+t.blocks)>t.w){
t.style.left=-(t.h*2+1)+'px';
t.ctr++;
if(t.ctr>=t.count){
eval(t.action);
t.ctr=0;
}}else t.style.left=(parseInt(t.style.left)+t.h+1)+'px';
}
function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}
function togglePause(){
if(this.tid==0){
this.tid=setInterval('startBar('+this.N+')',this.speed);
}else{
clearInterval(this.tid);
this.tid=0;
}}


/* Client-side access to querystring name=value pairs
        Version 1.2.3
        22 Jun 2005
        Adam Vandenberg
*/
    function Querystring(qs) { // optionally pass a querystring to parse
        this.params = new Object()
        this.get=Querystring_get
        
        if (qs == null)
            qs=location.search.substring(1,location.search.length)
        if (qs.length == 0) return
    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
        qs = qs.replace(/\+/g, ' ')
        var args = qs.split('&') // parse out name/value pairs separated via &
        
    // split out each name=value pair
        for (var i=0;i<args.length;i++) {
            var value;
            var pair = args[i].split('=')
            var name = unescape(pair[0])
            if (pair.length == 2)
                value = unescape(pair[1])
            else
                value = name
            
            this.params[name] = value
        }
    }
    function Querystring_get(key, default_) {
        // This silly looking line changes UNDEFINED to NULL
        if (default_ == null) default_ = null;
        
        var value=this.params[key]
        if (value==null) value=default_;
        
        return value
    }


/*
Rudi Sugiato
This is used in pop up feature page to display the desired feature item
Initially, all item are hidden
*/
    function displayFeat()
    {
        var qs = new Querystring();
        var featid = qs.get("id","");

        if(document.getElementById("featbar_container"))
        {
            featbar.hideBar();
            //featbar_container.style.display="none";
        }
        if (featid != "")
        {
            document.getElementById('featid_' + featid).style.display="block";
        }
    }


/*
Rudi Sugiato
This is used in tab content container/foundation page so that if user tries
to open the page by itself, it will reload it using parent frame (contURL)
*/
    var checkedPage = 0;
    function reloadFrame(contURL,affURL)
    {
        var qs = new Querystring();
        var strAction = qs.get("Action","");
        affurl = new String(parent.location.href);
        
        if(affurl.indexOf("resources") >= 0)
         contURL = affURL;  

        if (checkedPage == 0 && contURL != "" && strAction == "")
        {
            parenturl = new String(parent.location.href);
            if (parenturl.indexOf(contURL) < 0)
            {     
                parent.location.href = "http://" + location.hostname + contURL + "?tabContent=" + parent.location.pathname;
                //alert(contURL);
                //alert(contURL);
                //alert(parent.location.href);
            }
            checkedPage = 1;
        }
    }



/*
Rudi Sugiato
This is to overcome RedDot limitations in adding qs to links (to file in asset manager)
Ex. Related links has link to Product intro html in asset manager
*/
function addQS(ancObj, theQS)
{
window.open(ancObj.href + theQS);
return false;
}

/*
Rudi Sugiato
Google Clicktracks Cookie
*/
function rand(number) {
    return Math.ceil(Math.random()*number);
}
function SetClickTracksCookie()
{
    var thisCookie = GetCookie("CLICKTRACKSCOOKIE");
    if( thisCookie == null)
    {
        //Setup the random cookie value
        var myValue = new Date();
        var randNum = rand(100);        
        myValue = myValue.toGMTString() + "_" + randNum;
        //Setup the expiry date to expire in 2010
        var expiryDate = new Date();
        var date2010 = "Fri, 31 Dec 2030 23:00:00 EST";
        var dt = Date.parse(date2010);
        expiryDate.setTime(dt);
        SetCookie("CLICKTRACKSCOOKIE", myValue, expiryDate, "/", ".macrovision.com");
        
    }
    //add cookie for user res and browser
    //just check one of them, screenres is more important
    //rudi sugiato
    var otherCookie = GetCookie("SCREENRES");
    if (otherCookie == null)
    {
        //Setup the expiry date to expire in 2010
        var expiryDate = new Date();
        var date2010 = "Fri, 31 Dec 2030 23:00:00 EST";
        var dt = Date.parse(date2010);
        expiryDate.setTime(dt);
        
        var screenres = screen.width + 'x' + screen.height;
        SetCookie("SCREENRES", screenres, expiryDate, "/", window.location.hostname);
        var browseragent = navigator.appName+' '+navigator.appVersion;
        SetCookie("BROWSERAGENT", browseragent, expiryDate, "/", window.location.hostname);
    }
}

// ---------------------------------------------------------------
    //  Cookie Functions - Second Helping  (21-Jan-96)
    //  Written by:  Bill Dortch, hIdaho Design <BDORTCH@NETW.COM>
    //  The following functions are released to the public domain.
    //
    //  The Second Helping version of the cookie functions dispenses with
    //  my encode and decode functions, in favor of JavaScript's new built-in
    //  escape and unescape functions, which do more complete encoding, and
    //  which are probably much faster.
    //
    //  The new version also extends the SetCookie function, though in
    //  a backward-compatible manner, so if you used the First Helping of
    //  cookie functions as they were written, you will not need to change any
    //  code, unless you want to take advantage of the new capabilities.
    //
    //  The following changes were made to SetCookie:
    //
    //  1.  The expires parameter is now optional - that is, you can omit
    //      it instead of passing it null to expire the cookie at the end
    //      of the current session.
    //
    //  2.  An optional path parameter has been added.
    //
    //  3.  An optional domain parameter has been added.
    //
    //  4.  An optional secure parameter has been added.
    //
    //  For information on the significance of these parameters, and
    //  and on cookies in general, please refer to the official cookie
    //  spec, at:
    //
    //      http://www.netscape.com/newsref/std/cookie_spec.html    
    //
    //
    // "Internal" function to return the decoded value of a cookie
    //
    function getCookieVal (offset) {
      var endstr = document.cookie.indexOf (";", offset);
      if (endstr == -1)
        endstr = document.cookie.length;
      return unescape(document.cookie.substring(offset, endstr));
    }
    //
    //  Function to return the value of the cookie specified by "name".
    //    name - String object containing the cookie name.
    //    returns - String object containing the cookie value, or null if
    //      the cookie does not exist.
    //
    function GetCookie (name) {
      var arg = name + "=";
      var alen = arg.length;
      var clen = document.cookie.length;
      var i = 0;
      while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
          return getCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break; 
      }
      return null;
    }
    //
    //  Function to create or update a cookie.
    //    name - String object object containing the cookie name.
    //    value - String object containing the cookie value.  May contain
    //      any valid string characters.
    //    [expires] - Date object containing the expiration data of the cookie.  If
    //      omitted or null, expires the cookie at the end of the current session.
    //    [path] - String object indicating the path for which the cookie is valid.
    //      If omitted or null, uses the path of the calling document.
    //    [domain] - String object indicating the domain for which the cookie is
    //      valid.  If omitted or null, uses the domain of the calling document.
    //    [secure] - Boolean (true/false) value indicating whether cookie transmission
    //      requires a secure channel (HTTPS).  
    //
    //  The first two parameters are required.  The others, if supplied, must
    //  be passed in the order listed above.  To omit an unused optional field,
    //  use null as a place holder.  For example, to call SetCookie using name,
    //  value and path, you would code:
    //
    //      SetCookie ("myCookieName", "myCookieValue", null, "/");
    //
    //  Note that trailing omitted parameters do not require a placeholder.
    //
    //  To set a secure cookie for path "/myPath", that expires after the
    //  current session, you might code:
    //
    //      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
    //
    function SetCookie (name, value) {
      var argv = SetCookie.arguments;
      var argc = SetCookie.arguments.length;
      var expires = (argc > 2) ? argv[2] : null;
      var path = (argc > 3) ? argv[3] : null;
      var domain = (argc > 4) ? argv[4] : null;
      var secure = (argc > 5) ? argv[5] : false;
      document.cookie = name + "=" + escape (value) +
        ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
        ((path == null) ? "" : ("; path=" + path)) +
        ((domain == null) ? "" : ("; domain=" + domain)) +
        ((secure == true) ? "; secure" : "");
    }
    //  Function to delete a cookie. (Sets expiration date to current date/time)
    //    name - String object containing the cookie name
    //
    function DeleteCookie (name) {
      var exp = new Date();
      exp.setTime (exp.getTime() - 1);  // This cookie is history
      var cval = GetCookie (name);
      document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
    }
//---------------------------------------------------------------------------------------------

//Call the SetClickTracksCookie() function
SetClickTracksCookie();