/**
 * (c) Copyright 2007 Slacker, Inc.
 * 16935 West Bernardo Dr.
 * San Diego, CA 92127
 *
 */
var version = "0.0.1";


// Create a class that holds specific bits for the site pages.
function siteUtils(){
	this.session;
	this.random;
	this.date = new Date();
	this.domain = location.host;
};

siteUtils.prototype  = {
	/* Session Coockie */
	setBCookie : function(){
		this.session = GetCookie('B');
		this.random = Math.ceil(2000000000*Math.random());
		var ysL = new Date( this.date.getTime() );
		var expD = ysL.toGMTString();
		if(this.domain.indexOf('.slacker.com') >= 0){
			this.domain = "slacker.com";
		}
		else if(this.domain.indexOf('.stg.') >= 0 ){
			this.domain = "stg.sdslacker.com";
		}
		else if(this.domain.indexOf('.dev.') >= 0){
			this.domain = "dev.sdslacker.com";
		}
		else if(this.domain.indexOf('xeno.') >= 0){
			this.domain = "xeno.dev.sdslacker.com";
		}

		if (this.session == null){
			SetCookie( 'B', this.random, null, '/', this.domain, false, false );
		}
		else{ /*DeleteCookie ('b', rdVal, '/', dmL , false)*/ }
	},
	/* Instantiate a LightWindow when LW cannot load, for example using AJAX calls will defeat thbe LW API. */
	getLWLink : function (obj, r){
		var t = jQuery('#'+obj).title;
		var a = jQuery('#'+obj).author;
		var c = jQuery('#'+obj).caption;
		myLightWindow.activateWindow({
			href: r,
			title: t,
			author: a,
			caption: c
		});
	},
	/* Email Obfuscation */
	emThis : function(pref,text,subj){
	    var s = "@";
	    var d = "slacker";
	    var e = "com";
	    document.write("<a href=\"mailto:"+pref+s+d+"."+e+"?subject="+escape(subj)+"\">"+text+"</a>");
	}
};
	UTIL = new siteUtils();

	UTIL.setBCookie();

/* Common script used to find anything anywhere by its id and return that element
 * @PARAM n = the elemend id value to look for
 * @PARAM d = the document or frame to look in
 */
function findObj(n, d) {
  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);
  }
  for (i=0;!x&&i<d.forms.length;i++)
    x=d.forms[n];
  if(!x && d.getElementById)
    x=d.getElementById(n);
  return x;
}

/* Global function to show mesages in the browser's status bar */
function displaySBMsg(msgStr){window.status=msgStr;return true;}

function popUpWindow( filename , title , windowHeight , windowWidth , scroll, options)
{
    var ScrollBar = 0;
    var strOptions = "";
    if(typeof(scroll) != "undefined"){
        if (scroll == "yes" || scroll == "Yes")
            ScrollBar = 1;
    }

    var features = "top=20,left=20,alwaysRaised=1,resizable=yes,scrollbars=" + ScrollBar;
    if(typeof(windowWidth) != "undefined"){
        if( windowWidth && windowWidth > 0 )
            features += ",width=" + windowWidth;
        else
            features += ",width=550";
    }

    if(typeof(windowHeight) != "undefined"){
        if( windowHeight && windowHeight > 0 )
            features += ",height=" + windowHeight;
        else
            features += ",height=585";
    }

    if ( typeof(options) != "undefined" && options && options != " " )
    {
        var strChopList = options.split( ",");
            strOptions = "?";
        for (count = 0 ; count < strChopList.length; count++ )
          strOptions = strOptions + "&" + strChopList[ count ];
    }
    if( typeof(title) != "undefined" ||!title )
        title = "SlackerWindow";

    if( top.window.popupWindow && ! top.window.popupWindow.closed )
        top.window.popupWindow.close();


    if(arguments.length != popUpWindow.length) {
        top.window.popupWindow=window.open(filename, title, "");
    }
    else{
        top.window.popupWindow=window.open(filename + strOptions, title, features);
    }
    void(0);
}

function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  }
}

//document.onload = MM_CheckFlashVersion('8,0,0,0','Content on this page requires a newer version of Adobe Flash Player. Do you want to download it now?');
/**
 * Cookie handling
 * Get named cookie
 * @param {String} name
 * @return {String}
 */
function GetCookie (name) {
	var start = document.cookie.indexOf( name + "=" );
    var len = start + name.length + 1;
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
        return null;
    }
    if ( start == -1 ) return null;
    var end = document.cookie.indexOf( ";", len );
    if ( end == -1 ) end = document.cookie.length;
    var c    = document.cookie.substring(len,end);
    if (c.indexOf("<<::") > -1) {
        c = decode64(c.substring(c.indexOf("<<::")+4,c.length));
    }
    return c;
}
/**
 * Get a "compound" cookie.  A compound cookie is a cookie that has multiple name/value
 * pairs stored in it separated by a delimiter.
 * @param {String} name Cookie name
 * @param {String} delimiter Delimiter that separates the name/value pairs.  This is the same delimiter you used when calling SetCompoundCookie} SetCompoundCookie
 *
 * return {Object} \{name:value,name:value\}
 */
function GetCompoundCookie(name, delimiter) {
    var c    = GetCookie(name) || "";
    var data  = c.split(delimiter);
    var struct = {};
    if (data.length > 1) {
        while (data.length > 0) {
            struct[data.shift()]  = data.shift();
        }
    }
    return struct;
}
/**
 * Set a compound cookie (a cookie with multiple name/value pairs in it)
 * @param {String} name
 * @param {Object} struct Object of format \{name:value,name:value\}
 * @param {String} delimiter
 * @param {Integer} expires Time in minutes
 * @param {String} path
 * @param {String} domain
 * @param {Boolean} secure
 *
 * @return void
 */
function SetCompoundCookie(name, struct, delimiter, expires, path, domain, secure, encode) {
    var data    = [];
    for (i in struct) {
        data.push(i);
        data.push(struct[i]);
    }
    SetCookie(name, data.join(delimiter), expires, path, domain, secure, encode);
}
/**
 * Set a cookie
 * @param {String} name
 * @param {String} value
 * @param {Integer} expires Time in minutes
 * @param {String} path
 * @param {String} domain
 * @param {Boolean} secure
 *
 * @return void
 */
function SetCookie( name, value, expires, path, domain, secure, encode )  {
    // set time, it's in milliseconds
    var c;
    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 minutes
    */
    if ( expires ) {
        expires = expires * 1000 * 60;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    // Encode the value for a little bit of security
    if (encode) {
        value   = "<<::"+encode64(value);
    }
    //alert ("Set cookie value: "  + value)
    c = name + "=" + value +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );

    document.cookie = c;
}
/**
 * Delete a cookie
 * @param {String} name The cookie to be deleted
 */
function DeleteCookie (name, value, path, domain, secure) {
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);

	var c = name + "=" + value + ";expires=" + exp.toGMTString() +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );

	document.cookie = c;
}


var oCopy   = "This code 64 bit encoding code was written by Tyler Akins and has been placed in the"+
              "public domain.  It would be nice if you left this header intact."+
              "Base64 code from Tyler Akins -- http://rumkin.com"+
              "2007 - Slacker, Inc. DB - Changed '=' in keyStr to '|' to allow storage of results in cookies."+
              "Also modified to fit into 'Jax' framework.";

window.onerror  = parent.window.onerror;
/**
 * Handling for various data encoding schemes
 */
 com = parent.com;
this.version  = "$LastChangedRevision: 1400 $";

var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/|";

/**
 * Base64 encode a string.  Note the standard = has been replaced with | in the keyStr to avoid issues with encoded strings stored in cookies
 * @param {String} input
 */
function encode64(input) {
   var output = [];
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output[output.length] = keyStr.charAt(enc1);
      output[output.length] = keyStr.charAt(enc2);
      output[output.length] = keyStr.charAt(enc3);
      output[output.length] = keyStr.charAt(enc4);

   } while (i < input.length);

   return output.join("");
}
/**
 * Base64 decode a string.
 * @param {String} input
 * @return {String}
 */
function decode64(input) {
   var output = [];
   var chr1, chr2, chr3;
   var enc1, enc2, enc3, enc4;
   var i = 0;

   if (!input) {
       return "";
   }

   // remove all characters that are not A-Z, a-z, 0-9, +, /, or |
   input = input.replace(/[^A-Za-z0-9\+\/\|]/g, "");

   do {
      enc1 = keyStr.indexOf(input.charAt(i++));
      enc2 = keyStr.indexOf(input.charAt(i++));
      enc3 = keyStr.indexOf(input.charAt(i++));
      enc4 = keyStr.indexOf(input.charAt(i++));

      chr1 = (enc1 << 2) | (enc2 >> 4);
      chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
      chr3 = ((enc3 & 3) << 6) | enc4;

      output[output.length] = String.fromCharCode(chr1);

      if (enc3 != 64) {
         output[output.length] = String.fromCharCode(chr2);
      }
      if (enc4 != 64) {
         output[output.length] = String.fromCharCode(chr3);
      }
   } while (i < input.length);

   return output.join("");
}


function checkEmail(f){
	var str=jQuery('#'+f).value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)jQuery/i;
	if (filter.test(str)){
		return true;
	}
	else{
		alert("Please input a valid email address. This field is required.");
		return false;
	}
	return false;
}
function checkFullName(f){
	var str=jQuery('#'+f).value;
	if ( str.length >= 2 ){
		return true;
	}
	else{
		alert("Please enter your name. This field is required.");
		return false;
	}
	return false;
}
function checkComments(f){
	var str=jQuery('#'+f).value;
	if ( str.length >= 8 ){
		return true;
	}
	else{
		alert("Please enter a comment with 8 or more letters. This field is required.");
		return false;
	}
	return false;
}





// Scrumboogidy.
var io = new Image();
var pageAction, price, sku, order_code, currency_id, user_defined1, user_defined2, user_defined3, user_defined4, ic_cat, ic_bu, ic_bc, ic_ch, ic_nso, altid, ic_type, urlA, prefix;
function pixel(){var icstring =".ic-live.com/goat.php?cID=1498&cdid=4935&campID=8";var refVar = (document.referrer);var locURL = location.href;var locHttp = locURL.split(":")[0];if (!pageAction) { pageAction = 0; };if (!price) { price=""; }if (!sku) { sku=""; }if (!order_code) { order_code=""; }if (!user_defined1) { user_defined1=""; }if (!user_defined2) { user_defined2=""; }if (!user_defined3) { user_defined3=""; }if (!user_defined4) { user_defined4=""; }if (!currency_id) { currency_id=""; }if (!ic_bu) { ic_bu=""; }if (!ic_bc) { ic_bc=""; }if (!ic_ch) { ic_ch=""; }if (!ic_nso) { ic_nso=""; }if (!altid) { altid=""; }if (!ic_cat) { ic_cat=""; }if (!ic_type) { ic_type=""; }if (locHttp.toLowerCase( ) == "https")  { prefix="https://www"+icstring+"";}if (locHttp.toLowerCase( ) == "http")  { prefix="http://1498"+icstring+"";}if (pageAction > 0) { urlA = prefix+"&convID="+pageAction+"&convP="+price+"&curID="+currency_id+"&ordID="+escape(order_code)+"&ud1="+escape(user_defined1)+"&ud2="+escape(user_defined2)+"&ud3="+escape(user_defined3)+"&ud4="+escape(user_defined4)+"&ic_cat="+escape(ic_cat)+"&ic_type="+escape(ic_type)+"&ic_bu="+escape(ic_bu)+"&ic_bc="+escape(ic_bc)+"&ic_ch="+escape(ic_ch)+"&ic_nso="+escape(ic_nso)+"&altid="+escape(altid)+"&sku="+escape(sku)+"&refVar="+escape(refVar); } else { urlA = prefix+"&ic_cat="+escape(ic_cat)+"&ic_type="+escape(ic_type)+"&ic_bu="+escape(ic_bu)+"&ic_bc="+escape(ic_bc)+"&ic_ch="+escape(ic_ch)+"&ic_nso="+escape(ic_nso)+"&altid="+escape(altid)+"&refVar="+escape(refVar); }	 io.src = urlA; }


