﻿/******************************************************************************
** AJAX
******************************************************************************/

function createXMLHttp() {
    var xmlhttp = false;
    /*@cc_on@*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end@*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
            xmlhttp = new XMLHttpRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp = false;
        }
    }
    return xmlhttp;
}

function genericAjax(url) {
    var ajaxObj = createXMLHttp();
    //Use this function when no response is needed
    ajaxObj.open("GET", url + '&rand=' + Math.random(), true);
    ajaxObj.open("GET", url, true);
    ajaxObj.send(null);
}

//Pass the web service a reference to the function to call when it returns
//Callback must be a function accepting a single argument, which will be the response text
function MakeAjaxCall(url, callback) {

    var ajaxObj = createXMLHttp();
    ajaxObj.open("GET", url + '&rand=' + Math.random(), true);
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send(null);
}

//Pass the web service a reference to the function to call when it returns
//Callback must be a function accepting a single argument, which will be the response text
function MakeAjaxPost(url, postData, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + '&rand=' + Math.random(), true);
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    ajaxObj.send(postData);
}

//Calls a web service that returns HTML, placing it into the specified element
function FillDivWithAjax(url, target) {
    MakeAjaxCall(url, function(returnHTML) {
        target.innerHTML = returnHTML;
    });
}

/* Sets a session variable - callback should expect a simple result code ("0" for success, else "ERROR:[errortext]") 
Make sure that the value you are setting stringifies nicely, or has been pre-stringified
*/
function SetSessionVariable(url, key, value, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + "?cmd=setcookie&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send("key=" + key + "&value=" + value);
}

/* sets a .NET application variable (global variable) */
function SetApplicationVariable(url, key, value, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + "?cmd=setappvar&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send("key=" + key + "&value=" + value);
}

/*... and gets it back :) */
function GetApplicationVariable(url, key, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + "?cmd=getappvar&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send("key=" + key);
}

/*... destroys (sets to null) an application variable */
function KillApplicationVariable(key) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", "/app_info/ajaxendpoint/default.aspx?cmd=killappvar&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.send("key=" + key);
}


/* Retrieves a previously set session variable. The callback should expect the string value of the
cookie if it exists, "null" if it does not, else the standard error format */
function GetSessionVariable(url, key, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + "?cmd=getcookie&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send("key=" + key);
}



/******************************************************************************
** Form validation
******************************************************************************/
/* Quickie Validation Methods - Requires that JQuery be loaded and available to call */
/* Error messages should be of class sn_visibleInlineError */

var isPageValid = true;

function HideAllErrors() {
    /*
    var $j= jQuery.noConflict();
    $$(".sn_visibleInlineError").each(Element.hide);
    */
}

function ShowAllErrors() {
    $$(".sn_visibleInlineError").each(Element.show);
}

//id = ID of error message container
function ShowError(id) {
    $(id).show();
}
function HideError(id) {

    $(id).hide();

}



/******************************************************************************
** UI
******************************************************************************/
/* UI Methods - Requires that JQuery be loaded and available to call */
function ClearTextFields() {
    //TODO: write in prototype or regular JS.
}

/* Methods involving "Hanging Gets" (server callbacks) */
function WaitForCondition(url, key, value, callback) {
    var ajaxObj = createXMLHttp();
    ajaxObj.open("POST", url + "?cmd=RegisterEvent&rand=" + Math.random(), true);
    ajaxObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            callback(ajaxObj.responseText);
        }
    }
    ajaxObj.send("key=" + key + "&value=" + value);
}



/******************************************************************************
** Event page functionality
******************************************************************************/
/******* Scheduling Methods *********/
/* Shows the appropriate location options */
function toggleLocation(toggleValue) {
    eval("$('.onlineVenueDetails')." + ((toggleValue != "realVenue") ? "show();" : "hide();"));
    eval("$('.realVenueDetails')." + ((toggleValue == "realVenue") ? "show();" : "hide();"));
    eval("$('.mapTbl')." + ((toggleValue == "realVenue") ? "show();" : "hide();"));

    //add or remove the style with the vertical line on the td
    if ($("#venueContainer").attr("style") != "")
        $("#venueContainer").attr("style", "");
    else
        $("#venueContainer").attr("style", "border-right:solid 1px #cccccc;");
}

/******* Event display *********/
function GetEventSummary(id, target) {
    MakeAjaxCall("/app_info/eventstats.aspx?id=" + id, function(data) {
        var info = eval(data);
        document.getElementById('numAttending').innerHTML = info[1];
        document.getElementById('numDeclined').innerHTML = info[2];
        document.getElementById('daysLeft').innerHTML = info[3];
    });
}

function UpdateSummary(id) {
    var info = eval(document.getElementById('metadata' + id).innerHTML);
    document.getElementById('numAttending').innerHTML = info[1];
    document.getElementById('numDeclined').innerHTML = info[2];
    document.getElementById('daysLeft').innerHTML = info[3];
    //document.getElementById('eventStats').innerHTML = document.getElementById('metadata'+id).innerHTML;
}

function attend(instanceid, memberid) {
    MakeAjaxCall("/app_info/eventcommands.aspx?cmd=accept&memberID=" + memberid + "&instanceID=" + instanceid, function(data) {
        location.reload();
        //eventsPaginator.OnPage(eventsPaginator.curPage);
        //MakeAjaxCall('/app_info/dynamiceventlist.aspx?type='+listingType+'&direction='+direction+'&date=<%=DateTime.Now.ToString()%>', function(data2){document.getElementById('listContainer').innerHTML=data2;});
    });
}

function decline(instanceid, memberid) {
    MakeAjaxCall("/app_info/eventcommands.aspx?cmd=decline&memberID=" + memberid + "&instanceID=" + instanceid, function(data) {
        location.reload();
        //eventsPaginator.OnPage(eventsPaginator.curPage);
        //MakeAjaxCall('/app_info/dynamiceventlist.aspx?type='+listingType+'&direction='+direction+'&date=<%=DateTime.Now.ToString()%>', function(data2){document.getElementById('listContainer').innerHTML=data2;});
    });
}

function artistAttend(instanceid, memberid) {
    MakeAjaxCall("/app_info/eventcommands.aspx?cmd=artistaccept&memberID=" + memberid + "&instanceID=" + instanceid, function(data) {
        location.reload();
        //eventsPaginator.OnPage(eventsPaginator.curPage);
        //MakeAjaxCall('/app_info/dynamiceventlist.aspx?type='+listingType+'&direction='+direction+'&date=<%=DateTime.Now.ToString()%>', function(data2){document.getElementById('listContainer').innerHTML=data2;});
    });
}

function artistDecline(instanceid, memberid) {
    MakeAjaxCall("/app_info/eventcommands.aspx?cmd=artistdecline&memberID=" + memberid + "&instanceID=" + instanceid, function(data) {
        location.reload();
        //eventsPaginator.OnPage(eventsPaginator.curPage);
        //MakeAjaxCall('/app_info/dynamiceventlist.aspx?type='+listingType+'&direction='+direction+'&date=<%=DateTime.Now.ToString()%>', function(data2){document.getElementById('listContainer').innerHTML=data2;});
    });
}



/******************************************************************************
** String helpers
******************************************************************************/
String.prototype.addslashes = function() {
    return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function() {
    return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
}



/******************************************************************************
** Mess...
******************************************************************************/
/*Originally designed specifically for the TabbedView.ascx, but is now to be used to populate any div with AJAX content*/
function tabContent(divID, serviceURL, func) {

    document.getElementById(divID).innerHTML = SN.UI.loaderCode;
    this.acObj = null;
    var ajaxObj = createXMLHttp();
    ajaxObj.open("GET", "/app_info/TabContent.aspx?ctrl=" + serviceURL + '&rand=' + Math.random(), true);
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            document.getElementById(divID).innerHTML = ajaxObj.responseText;
            if (typeof (func) != "undefined") eval(func);
        }
    }
    ajaxObj.send(null);
}

function applySpinnyThing(divID) {
    document.getElementById(divID).innerHTML = SN.UI.loaderCode;
}

function ApplySpinnyThing(divID) {
    applySpinnyThing(divID);
}

//Specialized read message version - takes msg id as param
function msgContent(divID, serviceURL, id) {
    document.getElementById(divID).innerHTML = SN.UI.loaderCode;
    this.acObj = null;
    var ajaxObj = createXMLHttp();
    //Is this reply msg or read msg?
    if (serviceURL.toLowerCase().indexOf('compose') > 0)
        ajaxObj.open("GET", "/app_info/TabContent.aspx?replyid=" + id + "&ctrl=" + serviceURL + '&rand=' + Math.random(), true);
    else
        ajaxObj.open("GET", "/app_info/TabContent.aspx?id=" + id + "&ctrl=" + serviceURL + '&rand=' + Math.random(), true);
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) {
            document.getElementById(divID).innerHTML = ajaxObj.responseText;
            mceInit();
        }
    }
    ajaxObj.send(null);
}

function divContent(divID, serviceURL)  //divID is just a string, but serviceURL must always end in either ? or &
{
    document.getElementById(divID).innerHTML = "loading...";
    this.acObj = null;
    var ajaxObj = createXMLHttp();
    ajaxObj.open("GET", serviceURL + 'rand=' + Math.random(), true);
    ajaxObj.onreadystatechange = function() {
        if (ajaxObj.readyState == 4) { document.getElementById(divID).innerHTML = ajaxObj.responseText; }
    }
    ajaxObj.send(null);
}


function adjSpanOvr(obj, status) {
    obj.parentNode.getElementsByTagName("span")[0].innerHTML = status;
}


function toggle(obj) {
    var objArr = obj.parentNode.getElementsByTagName("a");
    for (var ii = 0; ii < objArr.length; ii++)
        if (objArr[ii].className == "toggleOn") objArr[ii].className = "toggleOff";
    obj.className = "toggleOn";
}
function getParentByClassName(classname, child) {
    var tmpObj = child;
    while (tmpObj != document.body) {
        try {
            if (typeof (tmpObj.className) != "undefined") {
                if (tmpObj.className != classname)
                    tmpObj = tmpObj.parentNode;
                else
                    break;
            } else { tmpObj = tmpObj.parentNode; }
        } catch (err) {
            break;
        }
    }
    return tmpObj;
}
function sn_getElementsByClassName(classname, node) {

    if (!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)
        if (re.test(els[i].className)) a.push(els[i]);
    return a;
}



/*  Variables in place for the mouse-over menus..  This menu is functions based on it's containing classes, and the overArray being built as*   a JSON array with two properties: 
*    pClass - the parent class which the menu and button/icon/object which activates the menu
*    cClass - the child class which will have it's visibility and opacity manipulated based on the mouse's movements.
*/
SN = new Object();
SN.UI = new Object();
SN.EVENT = new Object();
//Add this Image object to load the gif faster at Page_Load
SN.LOADPIC = new Image(32, 32);
SN.LOADPIC.src = "/images/master/ajax-loader1.gif";
SN.LOADPIC.className = "ajaxloader";

/*  THE LOADER CODE IS IN THIS VARIABLE FOR ALL TO USE */
SN.UI.loaderCode = "<div class='loading'><img src='/images/master/ajax-loader1.gif' class='ajaxloader' /></div>"
SN.UI.loaderImg = "<img src='/images/master/ajax-loader1.gif' class='ajaxloader' />"
/* ENJOY!! */

SN.UI.timerObj = null;
//takes .35 of a second to fade out
SN.UI.activeObj;
SN.UI.oldTarg;
SN.UI.overArray = []; //when over they stay open, but soon after they fade out

SN.UI.overIDs = []; //bass ID parent class which hold's something that, when no longer over, will fade out
SN.UI.clickArray = []; //when not clicked on, they close
SN.UI.addToOverIDArr = function(pID)//pass the parent class and the child class which is to be activated
{
    SN.UI.overIDs.push(pID);
}
SN.UI.addToOverArr = function(pCl, cCl)//pass the parent class and the child class which is to be activated
{
    SN.UI.overArray.push({ pClass: pCl, cClass: cCl });
}
SN.UI.addToClkArr = function(pCl, cCl)//pass the parent class and the child class which is to be deactivated
{
    SN.UI.clickArray.push({ pClass: pCl, cClass: cCl });
}
SN.UI.getTarg = function(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;
    return targ;
}
SN.UI.treeScan = function(t, arrObj) {
    var overFlag = false;
    for (var xx = 0; xx < arrObj.length; xx++) {
        if (getParentByClassName(arrObj[xx].pClass, t) != document.body)  //if the old target (from the last movement) is inside one of the overarray classes, fade out.
        {
            overFlag = true; break;
        }
    }
    return overFlag;
}

SN.UI.fadeOut = function()//fades out the active Object
{
    SN.UI.activeObj.style.opacity = SN.UI.activeObj.style.opacity - 0.1;
    if (SN.UI.activeObj.style.opacity > 0)
        SN.UI.timerObj = setTimeout(function() { SN.UI.fadeOut(); }, SN.UI.fadeOutTime / 10);
    else {
        SN.UI.activeObj.style.display = 'none';
        SN.UI.activeObj.style.visibility = 'hidden';
    }

}
SN.UI.checkFade = function() {
    if (!SN.UI.treeScan(SN.UI.oldTarg, SN.UI.overArray)) SN.UI.fadeOut();
}
/* overTree checks to see if the target (targ) is inside the parent object. */
SN.UI.overTree = function(obj, targ) {
    var theParent = getParentByClassName(obj.pClass, targ);

    if (theParent != document.body) {
        clearTimeout(SN.UI.timerObj); //clear previous call for fade out
        var node = sn_getElementsByClassName(obj.cClass, theParent); //find the first instance of the child class in the parent.
        if (SN.UI.activeObj != node[0] && SN.UI.activeObj != null) //if a menu has already been activated, turn it off.
            SN.UI.activeObj.style.visibility = 'hidden';
        SN.UI.activeObj = node[0]; //set the new active object, opacity and display
        SN.UI.activeObj.style.opacity = 1;
        SN.UI.activeObj.style.visibility = 'visible';
        SN.UI.activeObj.style.display = 'block';
        SN.UI.timerObj = setTimeout(function() { SN.UI.checkFade(); }, SN.UI.timerCountdown);
    }
}
SN.UI.overTree = function(obj, targ) {
    var theParent = getParentByClassName(obj.pClass, targ);

    if (theParent != document.body) {
        clearTimeout(SN.UI.timerObj); //clear previous call for fade out
        var node = sn_getElementsByClassName(obj.cClass, theParent); //find the first instance of the child class in the parent.
        if (SN.UI.activeObj != node[0] && SN.UI.activeObj != null) //if a menu has already been activated, turn it off.
            SN.UI.activeObj.style.visibility = 'hidden';
        SN.UI.activeObj = node[0]; //set the new active object, opacity and display
        SN.UI.activeObj.style.opacity = 1;
        SN.UI.activeObj.style.visibility = 'visible';
        SN.UI.activeObj.style.display = 'block';
        SN.UI.timerObj = setTimeout(function() { SN.UI.checkFade(); }, SN.UI.timerCountdown);
    }
}

SN.UI.addEvent = function(evObj, eventName, functionObject) {

    if (evObj != null) {
        if (document.addEventListener)
            evObj.addEventListener(eventName, functionObject, false);
        else if (document.attachEvent)
            evObj.attachEvent("on" + eventName, functionObject);
    }

}
SN.UI.removeEvent = function(evObj, eventName, functionObject) {

    if (evObj != null) {
        if (document.removeEventListener)
            evObj.removeEventListener(eventName, functionObject, false);
        else if (document.detachEvent)
            evObj.detachEvent("on" + eventName, functionObject);
    }

}

SN.UI.clickCheck = function(e) {
    var targ = SN.UI.getTarg(e);
    if (SN.UI.overArray != [] && typeof (SN.UI.activeObj) != "undefined") {
        if (!SN.UI.treeScan(targ, SN.UI.overArray)) {
            SN.UI.activeObj.style.visibility = 'hidden';
            SN.UI.activeObj.style.display = 'none';
        }
    }
}
SN.UI.isChildInParent = function(pObj, child) {
    var tmpObj = child;
    while (tmpObj != document.body) {
        try {
            if (typeof (tmpObj) != "undefined") {
                if (tmpObj != pObj)
                    tmpObj = tmpObj.parentNode;
                else
                    break;
            } else { tmpObj = tmpObj.parentNode; }
        } catch (err) { break; }
    }
    return (tmpObj == pObj);
}
SN.UI.overCheck = function(e) {
    var targ = SN.UI.getTarg(e);
    //if(typeof(SN.UI.overArray)!="undefined")
    if (SN.UI.overArray.length > 0) {
        if (targ != SN.UI.oldTarg) {
            for (var xx = 0; xx < SN.UI.overArray.length; xx++) {
                SN.UI.overTree(SN.UI.overArray[xx], targ);
            }
        }

    }
    SN.UI.oldTarg = targ;
}
document.onmousedown = SN.UI.clickCheck;
//document.onmousemove=SN.UI.overCheck;
SN.UI.addEvent(document, "mousemove", SN.UI.overCheck)




/*  END OVER MENU CODE */


/* DATE PICKER MODULE */
/*
  
*/
//SN.UI.activePop=null;
//SN.UI.activeButton=null;
SN.UI.timerCountdown = 50;  //takes .45 second to start the fade out (IE just disappears)
SN.UI.fadeOutTime = 50;
function clearAllPopups() {
    //self.container.setAttribute('genPop', 'x');
    var divArr = document.getElementsByTagName("div");
    for (var oo = 0; oo < divArr.length; oo++) {
        if (divArr[oo] != self.container) {
            if (divArr[oo].getAttribute("genPop") == "x") {
                divArr[oo].style.display = 'none';
                divArr[oo].style.visibility = 'hidden';
                SN.UI.clearSelForPopup(false);
            }
        } else {
            //  SN.UI.updDebug("this is:"+self.button.innerHTML);
        }
    }
    SN.UI.removeEvent(window, "scroll", clearAllPopups);

}
SN.UI.createPopup = function(contentJSON) {
    // The process of creating a table for the popup content is unfortunately required to be done in javascript because of IE6
    var self = this;
    this.timerObj = null; //temp timer for fadeout
    this.lifeTimer = null; //life line timer for the life of the object after the mouse is no longer over the container

    if (typeof (contentJSON.xoffset) != "undefined")
        this.xoffset = contentJSON.xoffset;
    else
        this.xoffset = 0;

    if (typeof (contentJSON.yoffset) != "undefined")
        this.yoffset = contentJSON.yoffset;
    else
        this.yoffset = 0;

    if (typeof (contentJSON.mouseoutfade) != "undefined") {
        this.mouseoutfade = contentJSON.mouseoutfade;
    }
    else
        this.mouseoutfade = false;

    this.pop = function(ev) {
        SN.UI.posElementWithButton(self.button, self.container, self.xoffset, self.yoffset);
        if (self.container.style.visibility == "visible") {
            self.fadeOut(ev);
        } else {
            if (self.container.style.display == "none") clearAllPopups();
            clearTimeout(self.timerObj);

            self.container.style.opacity = 1;
            self.container.style.visibility = "visible";
            self.container.style.display = "block";

            SN.UI.clearSelForPopup();
        }
    }
    this.hide = function() {
        self.container.style.display = 'none';
        self.container.style.visibility = 'hidden';
    }
    this.fadeOut = function(ev)//fades out the active Object
    {
        if (self.container.style.opacity > 0) self.container.style.opacity = self.container.style.opacity - 0.1;
        self.container.style.display = 'none';
        self.container.style.visibility = 'hidden';
        SN.UI.clearSelForPopup(false);
    }

    this.setEvent = function(ev) {
        var str = self.event.replace("on", "");
        self.event = ev;
        SN.UI.removeEvent(self.button, (str == "click") ? "mouseover" : "click", self.pop);
        SN.UI.addEvent(self.button, str, self.pop);
        SN.UI.addEvent(self.container, "mousemove", self.overCheck);
    }
    this.overCheck = function(ev) {
        var targ = SN.UI.getTarg(ev);
        //        SN.UI.updDebug("you are over "+targ);

        if (SN.UI.isChildInParent(self.container, targ)) {
            clearTimeout(self.timerObj);
            SN.UI.addEvent(targ, "mouseout", self.mouseoutFunc); //self.overCheck);
            SN.UI.addEvent(window, "scroll", clearAllPopups);


        } else {
            clearTimeout(self.timerObj);
            self.container.style.display = "none";
            SN.UI.removeEvent(window, "scroll", clearAllPopups);
            //self.timerObj=setTimeout(self.pop,SN.UI.timerCountdown);
        }
    }
    this.mouseoutFunc = function(ev) {
        var targ = SN.UI.getTarg(ev);
        if (SN.UI.isChildInParent(self.container, targ))
            clearTimeout(self.timerObj);

        SN.UI.removeEvent(this, "mouseout", self.mouseoutFunc)
        self.timerObj = setTimeout(self.pop, SN.UI.timerCountdown);
    }
    /*Constructor*/

    if (typeof (contentJSON.content) == "undefined") {
        alert('Invalid Content - must be in JSON Format:\n{id:"divID",cssClass:"className",content:"<table><td>Lorem Ipsum</td></table>"}');
        return false;
    } else {
        this.container = document.createElement("div");
        if (typeof (contentJSON.id) != "undefined") {
            this.container.id = contentJSON.id;
            if (typeof (contentJSON.button) != "undefined") {
                this.button = contentJSON.button;
                if (typeof (contentJSON.event) != "undefined")
                    self.event = contentJSON.event;
                else
                    self.event = "onclick";

                if (this.button) {
                    this.orig_onclick = (typeof (this.button.onclick) != "undefined") ? this.button.onclick : "";
                    this.orig_onmouseover = (typeof (this.button.onmouseover) != "undefined") ? this.button.onmouseover : "";
                }

                self.setEvent(self.event);

            }
        }
        if (typeof (contentJSON.cssClass) != "undefined") self.container.className = contentJSON.cssClass;

        if (typeof (contentJSON.content) == "string")
            self.container.innerHTML = contentJSON.content;
        else {
            if (contentJSON.content != null && typeof (contentJSON.content.innerHTML) == "string") {
                self.container.innerHTML = contentJSON.content.innerHTML;
                contentJSON.content.style.display = "none";
            }
        }
        self.container.setAttribute('genPop', 'x');
        if (this.button && typeof (this.button.attributes["snID"]) != "undefined") {
            var arr = this.container.getElementsByTagName("*");
            for (var ii = 0; ii < arr.length; ii++)
                if (typeof (arr[ii].attributes["snID"]) != "undefined")
                arr[ii].attributes["snID"].value = this.button.attributes["snID"].value;
        }

        document.getElementById("sn_header").appendChild(self.container);
        //if(self.mouseoutfade)SN.UI.addToOverArr(container.id,container.id);

        return this;
    }


}

SN.UI.datePicker = function(id, callBackFunc, specialDays) {
    var self = this;
    var objID = id;
    this.callBack = null;




    if (typeof (callBackFunc) == "undefined" || callBackFunc == null)
        this.callBack = function() { alert("no callback given:\n self.DateCal.currentDate.print('%m-%d-%Y')='" + self.DateCal.currentDate.print('%m-%d-%Y') + "'"); }
    else
        this.callBack = eval(callBackFunc);

    if (typeof (specialDays) == "undefined" || specialDays == null)
        this.SPECIAL_DAYS = [];
    else
        this.SPECIAL_DAYS = specialDays;


    function dateIsSpecial(year, month, day) {

        if (typeof (self.SPECIAL_DAYS) != "undefined") {
            for (ii = 0; ii < self.SPECIAL_DAYS.length; ii++) {
                if (((self.SPECIAL_DAYS[ii][0]) == month) &&
			            (((self.SPECIAL_DAYS[ii][1]) == day)) &&
			            (((self.SPECIAL_DAYS[ii][2]) == year))) {
                    return true;
                }
            }
        }
        return false;
    };


    this.DateCal = new Zapatec.Calendar.setup({
        firstDay: 1,
        weekNumbers: false,
        noHelp: true,
        range: [2000.01, 2012.12],
        flat: objID + "Div",
        flatCallback: this.callBack,
        dateStatusFunc: function(date, y, m, d) {
            if (dateIsSpecial(y, m, d)) return "SpecialDay";
            else return false;
        },
        titleHtml: function(strTitle, month, year) {
            return "<div class='monthName'" + ((SN.is_IE && SN.Version >= 7) ? " style='left:-63px;'" : "") + "><img src='http://media.supernova.com/images/DynamicImaging/interstate14.aspx?v=" + Zapatec.Calendar.i18n(month, "mn") + "%20" + Zapatec.Calendar.i18n(year, "mn") + "'></div>";
        }
    });
    return this;
}




/******** Zapatec code 'aquired' ******/
SN.is_gecko = /Gecko/i.test(navigator.userAgent);
SN.is_khtml = /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
SN.is_IE = (navigator.userAgent.match(/msie/i));
SN.Version = parseFloat(navigator.appVersion.split("MSIE")[1]);
SN.UI.getPageScrollX = function() {
    if (window.pageXOffset) {
        return window.pageXOffset;
    } else if (document.body && document.body.scrollLeft) {
        return document.body.scrollLeft;
    } else if (document.documentElement && document.documentElement.scrollLeft) {
        return document.documentElement.scrollLeft;
    }
    return 0;
};
SN.UI.getPageScrollY = function() {
    if (window.pageYOffset) {
        return window.pageYOffset;
    } else if (document.body && document.body.scrollTop) {
        return document.body.scrollTop;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        return document.documentElement.scrollTop;
    }
    return 0;
};
SN.UI.getStyleProperty = function(oEl, sPr) {
    var oDV = document.defaultView;
    if (oDV && oDV.getComputedStyle) {
        var oCS = oDV.getComputedStyle(oEl, '');
        if (oCS) {
            sPr = sPr.replace(/([A-Z])/g, '-$1').toLowerCase();
            return oCS.getPropertyValue(sPr);
        }
    }
    else if (oEl.currentStyle) {
        return oEl.currentStyle[sPr];
    }
    return oEl.style[sPr];
};
SN.UI.getElementOffset = function(oEl) {

    var iLeft = iTop = iWidth = iHeight = 0;
    var sTag;

    if (oEl.getBoundingClientRect) {
        var oRect = oEl.getBoundingClientRect();
        iLeft = oRect.left;
        iTop = oRect.top;
        iWidth = oRect.right - iLeft;
        iHeight = oRect.bottom - iTop;
        iLeft += SN.UI.getPageScrollX() - 2;
        iTop += SN.UI.getPageScrollY() - 2;
    } else {
        iWidth = oEl.offsetWidth;
        iHeight = oEl.offsetHeight;
        var sPos = SN.UI.getStyleProperty(oEl, 'position');
        if (sPos == 'fixed') {
            iLeft = oEl.offsetLeft + SN.UI.getPageScrollX();
            iTop = oEl.offsetTop + SN.UI.getPageScrollY();
        }
        else if (sPos == 'absolute') {
            while (oEl) {
                sTag = oEl.tagName;
                if (sTag) {
                    sTag = sTag.toLowerCase();
                    if (sTag != 'body' && sTag != 'html') {
                        iLeft += parseInt(oEl.offsetLeft, 10) || 0;
                        iTop += parseInt(oEl.offsetTop, 10) || 0;
                    }
                }
                oEl = oEl.offsetParent;
                sTag = oEl ? oEl.tagName : null;
                if (sTag) {
                    sTag = sTag.toLowerCase();
                    if (sTag != 'body' && sTag != 'html') {
                        iLeft -= oEl.scrollLeft;
                        iTop -= oEl.scrollTop;
                    }
                }
            }
        } else {
            var bMoz = (SN.is_gecko && !SN.is_khtml);
            var fStyle = SN.UI.getStyleProperty;
            var oP = oEl;
            while (oP) {
                if (bMoz) {
                    sTag = oP.tagName;
                    if (sTag) {
                        sTag = sTag.toLowerCase();
                        if (sTag == 'body' && !(fStyle(oP, '-moz-box-sizing') == 'border-box')) {
                            iLeft += parseInt(fStyle(oP, 'border-left-width'));
                            iTop += parseInt(fStyle(oP, 'border-top-width'));
                        }
                    }
                }
                iLeft += parseInt(oP.offsetLeft, 10) || 0; iTop += parseInt(oP.offsetTop, 10) || 0; oP = oP.offsetParent;
            }
            oP = oEl;
            while (oP.parentNode) {
                oP = oP.parentNode;
                sTag = oP.tagName;
                if (sTag) {
                    sTag = sTag.toLowerCase();
                    if (sTag != 'body' && sTag != 'html' && sTag != 'tr') {
                        iLeft -= oP.scrollLeft; iTop -= oP.scrollTop;
                    }
                }
            }
        }
    }

    return { left: iLeft, top: iTop, x: iLeft, y: iTop, width: iWidth, height: iHeight };
};

SN.UI.addOnload = function(Str) {
    if (document.body.onload != null) document.body.onload = "";
    if (typeof (document.body.onload) != "undefined")
        document.body.onload = document.body.onload + eval(Str);
    else
        document.body.onload = eval(Str);
}




SN.UI.posElementWithButton = function(button, element, xoffset, yoffset) {
    var p = SN.UI.getElementOffset(button);
    element.style.position = "absolute";
    element.style.left = (p.x + xoffset) + "px";
    element.style.top = (p.y + yoffset) + "px";
}


SN.UI.updDebug = function(str) {
    var debugDiv;
    if (document.getElementById("debug") == null) {
        debugDiv = document.createElement("div");
        debugDiv.id = "debug";
        debugDiv.onclick = function(e) { SN.UI.getTarg(e).style.display = 'none'; };
        document.body.appendChild(debugDiv);
    } else
        debugDiv = document.getElementById("debug");

    if (debugDiv.style.display != "block")
        debugDiv.style.display = "block";
    debugDiv.innerHTML = str + "<br>" + debugDiv.innerHTML;
}


SN.UI.toggleDisplay = function(obj) {

    obj.style.display = (obj.style.display == "block" ? "none" : (obj.style.display == "none" ? "block" : "none"));
}


/*  Inviter code */

//SN.UI.inviteJSON=[];
SN.UI.inviteSearch = function(setup) {

    this.setup = setup;
    var self = this;
    this.gigID = setup.gigID;
    this.num = 0;
    var resultDiv, resultInfo;
    if (setup.filter)
        this.filter = setup.filter;

    if (setup.rightSideOnly)
        this.rightSideOnly = true;
    else
        this.rightSideOnly = false;

    if (document.getElementById(setup.divID) == null) {
        resultDiv = document.createElement("DIV");
        resultDiv.id = setup.divID;
        document.getElementById(setup.destDivID).appendChild(resultDiv);
        resultInfo = document.createElement("DIV")
        resultInfo.id = setup.divID + "Info";
        document.getElementById("resultInfo").appendChild(resultInfo);
    } else {
        resultDiv = document.getElementById(setup.divID);
        resultInfo = document.getElementById(setup.divID + "Info");
    }
    resultDiv.className = "results";
    resultInfo.className = "info";
    var Service = setup.service;
    var ServiceArgs = Service.slice(Service.indexOf("?"));

    var ajaxObj = createXMLHttp();

    var selectedContainer = document.getElementById("inviteList"); //destDivID);
    this.dispArray = new Array();
    this.json = null;
    this.infoStatus = null;
    var tempStatus = null;
    var toBeSent = awaitingReply = attending = notAttending = 0;
    this.select = function(num) {
        //self.num=num;
        tempStatus = self.infoStatus.innerHTML;
        //self.infoStatus.innerHTML="Saving...&nbsp;&nbsp;"+self.infoStatus.innerHTML;

        var service = "/app_info/updates/event_invite_add.aspx?gigID=" + self.gigID + "&rID=" + self.json[num].ID + "&type=" + self.json[num].type
        if (self.json[num].type != "supernova") service += "&u=" + SN.inviteEmail + "&p=" + SN.invitePass;
        sn_getElementsByClassName("resultCover", self.dispArray[num].object)[0].style.visibility = "visible";
        MakeAjaxPost(service, "thumb=" + self.json[num].thumb + "&name=" + self.json[num].name, function(e) {
            if (e == "err1") alert("Already Added");
            RefreshInviteList();
            self.infoStatus.innerHTML = tempStatus;

        });
    }
    function RefreshInviteList() {
        //Add filter - if none added, it will pull down "to-be-sent"
        var filter = "";
        if (self.filter) {
            filter = "&status=" + self.filter;
        }
        if (self.json) {
            if (self.json.length == 0) {
                filter = "&status=invited";
                byid("inviteSelect").selectedIndex = 1;
            }
        }
        MakeAjaxCall("/app_info/inviteResults/event_invite_list.aspx?gigID=" + self.gigID + filter,
                function(e) {
                    var inviteJSON = eval(e);
                    selectedContainer.innerHTML = "";
                    var tempDiv, arrPos;
                    for (var ii = 0; ii < inviteJSON.length; ii++) {
                        //if(arrPos>-1)self.json[arrPos].status="selected";
                        //tempDiv = display(inviteJSON[ii], "self.deselect('" + inviteJSON[ii].type + "|" + inviteJSON[ii].ID + "');")
                        tempDiv = display(inviteJSON[ii], ii);
                        sn_getElementsByClassName("resultCheck", tempDiv)[0].checked = true;
                        /*if(inviteJSON[ii].inviteStatus==""&&inviteJSON[ii].deliveryStatus=="")
                        toBeSent++;
                        else if(inviteJSON[ii].inviteStatus=="invited")
                        {
                        if(inviteJSON[ii].deliveryStatus=="pending")
                        toBeSent++;
                        else if(inviteJSON[ii].deliverStatus=="sent")
                        awaitingReply++;
                        }else if(inviteJSON[ii].deliveryStatus=="declined")
                        */
                        selectedContainer.appendChild(tempDiv);
                    }

                    //Only "to be sent" items should allow use of the checkbox
                    //otherwise it is disabled
                    if (self.filter && self.filter != "pending") {
                        var cbArr = sn_getElementsByClassName("resultCheck", selectedContainer);
                        for (var i = 0; i < cbArr.length; i++) {
                            cbArr[i].disabled = true;
                        }
                    }
                });

    }
    this.findArrPos = function(id) {
        for (var pp = 0; pp < self.json.length; pp++)
            if (self.json[pp].ID == id)
            return pp;
        return -1;
    }
    this.deselect = function(str) {
        var type = str.split("|")[0];
        var ID = str.split("|")[1];
        var locJson = SN.findSearchJSON(str);
        if (locJson != null) {
            locJson.status = "open";
            sn_getElementsByClassName("resultCover", document.getElementById(locJson.type + "|" + locJson.ID))[0].style.visibility = "hidden"; var checkbox = sn_getElementsByClassName("resultCheck", document.getElementById(locJson.type + "|" + locJson.ID))[0];
            if (SN.is_IE) checkbox.attributes["checked"].value = "false";
            checkbox.checked = false;
        }
        MakeAjaxCall("/app_info/updates/event_invite_delete.aspx?gigID=" + self.gigID + "&rID=" + ID + "&type=" + type, function(e) {
            RefreshInviteList();
        });
    }
    this.populateJSON = function() {
        resultDiv.innerHTML = SN.UI.loaderCode;
        MakeAjaxCall(Service, function(e) {

            self.json = eval(e);

            popDispArray();
            self.displayResults();
            RefreshInviteList();
        })
    }
    function display(jsonObj, num) {
        //jsonObj, checkOnclick) {
        var oDiv, oCheck, oNameSpan, oTypeSpan, oImg, oCover, oLabel;
        //tempDiv = display(inviteJSON[ii], "self.deselect('" + inviteJSON[ii].type + "|" + inviteJSON[ii].ID + "');")
        //oDiv = display(self.json[ii], "self.select(" + ii + ");");
        oDiv = document.createElement("DIV");
        oDiv.className = "resultThumb " + jsonObj.type + "Thm";
        oDiv.id = jsonObj.type + "|" + jsonObj.ID;
        oLabel = document.createElement("LABEL")
        oDiv.appendChild(oLabel);

        oCheck = document.createElement("INPUT");
        oCheck.type = 'checkbox';
        oCheck.className = 'resultCheck';

        //if (jsonObj.status == "selected") {
        eval("oCheck.onclick=function(){var checked=((SN.is_IE&& SN.Version<7)? this.attributes['checked'].value== 'checked':this.checked);checked?self.select(" + num + "):self.deselect('" + jsonObj.type + "|" + jsonObj.ID + "');};");
        /*} else {
        eval("oCheck.onclick=function(){self.select(" + num + ");this.onclick=function(){self.deselect('" + jsonObj.type + "|" + jsonObj.ID + "');};};");
        }*/
        oLabel.appendChild(oCheck);

        oNameSpan = document.createElement("SPAN")
        oNameSpan.innerHTML = jsonObj.name;
        oNameSpan.className = "resultName";
        oLabel.appendChild(oNameSpan);

        oIDSpan = document.createElement("SPAN")
        oIDSpan.innerHTML = jsonObj.ID;
        oIDSpan.className = "resultID";

        oLabel.appendChild(oIDSpan);


        oTypeSpan = document.createElement("SPAN")
        oTypeSpan.innerHTML = "(" + jsonObj.type + ")";
        oTypeSpan.className = "resultType";

        oLabel.appendChild(oTypeSpan);

        oCover = document.createElement("IMG");
        oCover.src = "/images/blackpixel.gif";
        oCover.className = "resultCover";
        oCover.style.opacity = 0.1;
        //oCover.filters.alpha.opacity = 10;
        if (jsonObj.status == "selected") {
            if (SN.is_IE && SN.Version < 7)
                oCheck.attributes["checked"].value = "checked";
            else
                oCheck.checked = true;
            oCover.style.visibility = "visible";
        }

        oDiv.appendChild(oCover);

        oImg = document.createElement("IMG");
        oImg.src = jsonObj.thumb;
        oImg.className = "resultImg";

        oLabel.appendChild(oImg);

        return oDiv;
    }
    this.inviteStats = function(type, num) {
        var cssClass, Title, oDiv, oChk, oSpan;
        cssClass = type + "Info";
        /*
        if(type=="supernova")
        Title="All Friends";
        else if(type=="myspace")
        Title="MySpace Friends";
        else if(type=="email")
        Title=SN.inviteEmail.split("@")[1]+" e-mail address book";
        */
        oDiv = document.createElement("DIV");

        oDiv.className = cssClass;
        self.infoStatus = document.createElement("SPAN");
        self.infoStatus.className = "totalCount";
        self.infoStatus.innerHTML = "<b>" + num + " Total</b>";
        oDiv.appendChild(self.infoStatus);
        oChk = document.createElement("INPUT");
        oChk.type = "checkbox";
        oChk.className = 'selectAllCheck';
        oChk.onclick = self.selectAll;


        oSpan = document.createElement("label");
        oSpan.className = "chkspan";
        oSpan.innerHTML = "Select all";
        if (self.json[0].type != "supernova") oSpan.style.display = "none";

        oSpan.appendChild(oChk);
        oDiv.appendChild(oSpan);

        return oDiv;
    }
    function getCover(number) {
        //var elements=self.dispArray[num].object.getElementsByTagName("IMG");
        self.dispArray[num].object.getElementsByTagName("IMG")[1].style.display = false;
    }
    function popDispArray() {
        self.dispArray = new Array();
        var oDiv;
        for (var ii = 0; ii < self.json.length; ii++) {   //populates the array of display objects (divs)
            //           oDiv = display(self.json[ii], "self.select(" + ii + ");");
            oDiv = display(self.json[ii], ii);
            /*  THIS LINE IS PURELY TO TAKE OFF THE RIGHT BORDER ON THE 3RD COLUMN */
            if (((ii + 1) % (_invSize == "large" ? 3 : 2)) == 0) oDiv.style.borderRight = "0px";

            //resultDiv.appendChild(oDiv);
            self.dispArray.push({ object: oDiv, selected: false });
        }
    }
    this.displayResults = function() {
        var dispStr = "";
        resultDiv.innerHTML = "";
        resultInfo.innerHTML = "";
        try {
            resultInfo.appendChild(self.inviteStats(self.json[0].type, self.json.length));
        } catch (err) {
            //Not found shit goes here
        }
        for (var ii = 0; ii < self.dispArray.length; ii++) {
            resultDiv.appendChild(self.dispArray[ii].object);
        }


    }
    this.selectedAll = false;
    this.selectAll = function() {
        if (self.selectedAll) {
            var type = self.json[0].type;
            var ID = "";
            self.selectedAll = false;
            for (var ii = 0; ii < self.json.length; ii++) {
                if (ii > 0) ID += ",";
                ID += self.json[ii].ID;
                self.json[ii].status = "open";
                sn_getElementsByClassName("resultCover", self.dispArray[ii].object)[0].style.visibility = "hidden";
                $(".resultCheck").removeAttr("checked");
            }
            MakeAjaxCall("/app_info/updates/event_invite_delete.aspx?gigID=" + self.gigID + "&rID=" + ID + "&type=" + type, function(e) {
                RefreshInviteList();
            });
        } else {
            var type = self.json[0].type;
            var service = "/app_info/updates/event_invite_add.aspx" + ServiceArgs + "&type=" + type + "&rID=";
            for (var ii = 0; ii < self.json.length; ii++) {
                if (ii > 0) service += ",";
                service += self.json[ii].ID;
                self.json[ii].status = "selected";
                sn_getElementsByClassName("resultCover", self.dispArray[ii].object)[0].style.visibility = "visible";
                sn_getElementsByClassName("resultCheck", self.dispArray[ii].object)[0].checked = "true";
            }
            self.selectedAll = true;
            MakeAjaxPost(service, "", function(e) {
                RefreshInviteList();
            });
        }
    }

    //if setup as right side only, that means just refresh
    //invite list, not friends on left
    if (!this.rightSideOnly)
        self.populateJSON();
    else
        RefreshInviteList();

    return this;
}


function tabAct(obj) {
    var oArr = obj.parentNode.getElementsByTagName("A");
    for (var zz = 0; zz < oArr.length; zz++)
        if (oArr[zz].className = "active") oArr[zz].className = "";
    obj.className = "active";
    return false;
}

function eInvTab(obj) {
    var dArr = document.getElementById("invCriteria").getElementsByTagName("div");
    for (var zz = 0; zz < dArr.length; zz++)
        if (dArr[zz].className == "tabCon") dArr[zz].style.display = "none";
    dArr = sn_getElementsByClassName("results", document.getElementById("resultsWin"));
    for (var zz = 0; zz < dArr.length; zz++)
        dArr[zz].style.display = "none";

    dArr = sn_getElementsByClassName("info", document.getElementById("resultInfo"));
    for (var zz = 0; zz < dArr.length; zz++)
        dArr[zz].style.display = "none";


    if (document.getElementById(obj.id + "Result") != null) document.getElementById(obj.id + "Result").style.display = "block";
    if (document.getElementById(obj.id + "ResultInfo") != null) document.getElementById(obj.id + "ResultInfo").style.display = "block";
    document.getElementById(obj.id + "Search").style.display = "block";
    return tabAct(obj);
}
function getChkVal(objName) {
    objArr = document.getElementsByName(objName);
    for (var ii = 0; ii < objArr.length; ii++)
        if (objArr[ii].checked == true)
        return objArr[ii].value;

}

SN.findSearchJSON = function(str) {
    var type = str.split("|")[0];
    var ID = str.split("|")[1];
    var arrPos = 0;

    for (var ii = 0; ii < 2; ii++) {
        if (eval("search" + ii)) {
            if (eval("search" + ii + ".json[0].type==type")) {
                arrPos = eval("search" + ii + ".findArrPos(ID);");
                if (arrPos > -1) return eval("search" + ii + ".json[arrPos]");
            }
        }
    }
    return null;
}
var search0, search1, search2 = null;
SN.inviteEmail = null;
SN.invitePass = null;



/* Methods for sending off friend search requests for event invite */
function inviteImport(gID) {

    if (byid("importEmail").value.trim() == '') {
        alert("Type your e-mail address so we can import your contacts.");
        byid("importEmail").focus();
        return false;
    }

    if (byid("importPass").value.trim() == '') {
        alert("Type your password.");
        byid("importPass").focus();
        return false;
    }


    SN.inviteEmail = byid("importEmail").value.trim();
    SN.invitePass = byid("importPass").value;
    var serviceURL = '/app_info/inviteResults/email_invite_json.aspx?gigID=' + gID + "&u=" + SN.inviteEmail + "&p=" + SN.invitePass;
    if (SN.inviteEmail != "" && SN.invitePass != "" && serviceURL != "") search1 = SN.UI.inviteSearch({
        service: serviceURL,
        divID: 'importResult',
        destDivID: 'resultsWin',
        gigID: gID,
        login: SN.inviteEmail,
        password: SN.invitePass
    });
    /*document.getElementById("importInstructions").style.display="none";
    document.getElementById("rememberMeInst").style.display="none";*/
    return false;
}

function searchToggle(obj, txt) {

    document.getElementById("friendAdvanced").style.display = document.getElementById("friendAdvanced").style.display == "block" ? "none" : "block";

    obj.className = obj.className == "togglePlus" ? "toggleMinus" : "togglePlus";

    if (txt) {
        obj.onclick = function() { return searchToggle(this, obj.innerHTML); };

        obj.innerHTML = txt;
    } else {
        if (obj.className == "togglePlus")
            obj.innerHTML = "Advanced Search";
        else
            obj.innerHTML = "Basic Search";
    }

    return false;

}

function isAdvancedSearch() {
    //return true;
    try {
        return (document.getElementById("friendAdvanced").style.display == 'block') ? true : false;
    }
    catch (ex) { return true; }
}

function checkFirstClick(obj) {
    if (obj.value == 'Profile name, real name, artist name')
        obj.value = '';
}


function initPopEntries(setup) {

    var popEntryArr = sn_getElementsByClassName(setup.buttonClass, document.getElementById(setup.containerID));
    for (var ii = 0; ii < popEntryArr.length; ii++) {
        var sibArr = popEntryArr[ii].parentNode.getElementsByTagName("*");
        for (var zz = 0; zz < sibArr.length; zz++) {
            if (sibArr[zz] == popEntryArr[ii]) {
                for (var xx = zz; xx < (sibArr.length - zz); xx++)
                    if (sibArr[xx].className == setup.detailsClass)
                    popDetails = new SN.UI.createPopup({
                        content: sibArr[xx],
                        id: "details",
                        button: popEntryArr[ii],
                        event: "onmouseover",
                        yoffset: setup.yoff, xoffset: setup.xoff,
                        cssClass: "popUp"
                    });
            }
        }
    }
}
function isValidDate(dateStr, format) {
    if (format == null) { format = "MDY"; }
    format = format.toUpperCase();
    if (format.length != 3) { format = "MDY"; }
    if ((format.indexOf("M") == -1) || (format.indexOf("D") == -1) ||
      (format.indexOf("Y") == -1)) { format = "MDY"; }
    if (format.substring(0, 1) == "Y") { // If the year is first
        var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
        var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
    } else if (format.substring(1, 2) == "Y") { // If the year is second
        var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
        var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
    } else { // The year must be third
        var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
        var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
    }
    // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
    if ((reg1.test(dateStr) == false) && (reg2.test(dateStr) == false)) { return false; }
    var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
    // Check to see if the 3 parts end up making a valid date
    if (format.substring(0, 1) == "M") { var mm = parts[0]; } else
        if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
    if (format.substring(0, 1) == "D") { var dd = parts[0]; } else
        if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
    if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else
        if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
    if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
    if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
    var dt = new Date(parseFloat(yy), parseFloat(mm) - 1, parseFloat(dd), 0, 0, 0, 0);
    if (parseFloat(dd) != dt.getDate()) { return false; }
    if (parseFloat(mm) - 1 != dt.getMonth()) { return false; }
    return true;
}
//Replaces Date.parse because it sucks
function stringToDate(dateStr, format) {
    if (format == null) { format = "MDY"; }
    format = format.toUpperCase();
    if (format.length != 3) { format = "MDY"; }
    if ((format.indexOf("M") == -1) || (format.indexOf("D") == -1) ||
      (format.indexOf("Y") == -1)) { format = "MDY"; }
    if (format.substring(0, 1) == "Y") { // If the year is first
        var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
        var reg2 = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
    } else if (format.substring(1, 2) == "Y") { // If the year is second
        var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
        var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
    } else { // The year must be third
        var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
        var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
    }
    // If it doesn't conform to the right format (with either a 2 digit year or 4 digit year), fail
    if ((reg1.test(dateStr) == false) && (reg2.test(dateStr) == false)) { return false; }
    var parts = dateStr.split(RegExp.$1); // Split into 3 parts based on what the divider was
    // Check to see if the 3 parts end up making a valid date
    if (format.substring(0, 1) == "M") { var mm = parts[0]; } else
        if (format.substring(1, 2) == "M") { var mm = parts[1]; } else { var mm = parts[2]; }
    if (format.substring(0, 1) == "D") { var dd = parts[0]; } else
        if (format.substring(1, 2) == "D") { var dd = parts[1]; } else { var dd = parts[2]; }
    if (format.substring(0, 1) == "Y") { var yy = parts[0]; } else
        if (format.substring(1, 2) == "Y") { var yy = parts[1]; } else { var yy = parts[2]; }
    if (parseFloat(yy) <= 50) { yy = (parseFloat(yy) + 2000).toString(); }
    if (parseFloat(yy) <= 99) { yy = (parseFloat(yy) + 1900).toString(); }
    var dt = new Date(parseFloat(yy), parseFloat(mm) - 1, parseFloat(dd), 0, 0, 0, 0);
    return dt;
}

SN.UI.clearSelForPopup = function(bool) {
    if (SN.is_IE && location.href.indexOf('friends.aspx') < 0) {
        if (typeof (bool) == "undefined")
            bool = true;
        var arr = document.getElementsByTagName("select");
        for (var ii = 0; ii < arr.length; ii++)
            arr[ii].style.visibility = bool ? "hidden" : "visible";
    }

}


/*** Random Utility Crap ***/


//LOL
function byid(elementID) {
    return document.getElementById(elementID);
}




function checkEnter(e, element, onEnterFunction) {
    var characterCode;

    if (e && e.which) {
        e = e;
        characterCode = e.which;
    }
    else {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) {
        onEnterFunction(element.value);
        return false;
    }
    else {
        return true;
    }
}


var viewport = {
    o: function() {
        if (self.innerHeight) {
            this.pageYOffset = self.pageYOffset;
            this.pageXOffset = self.pageXOffset;
            this.innerHeight = self.innerHeight;
            this.innerWidth = self.innerWidth;
        } else if (document.documentElement && document.documentElement.clientHeight) {
            this.pageYOffset = document.documentElement.scrollTop;
            this.pageXOffset = document.documentElement.scrollLeft;
            this.innerHeight = document.documentElement.clientHeight;
            this.innerWidth = document.documentElement.clientWidth;
        } else if (document.body) {
            this.pageYOffset = document.body.scrollTop;
            this.pageXOffset = document.body.scrollLeft;
            this.innerHeight = document.body.clientHeight;
            this.innerWidth = document.body.clientWidth;
        }
        return this;
    },
    init: function(el) {
        //$(el).css("position", "absolute");
        $(el).css("left", Math.round(viewport.o().innerWidth / 2) + viewport.o().pageXOffset - Math.round($(el).width() / 2));
        $(el).css("top", Math.round(viewport.o().innerHeight / 2) + viewport.o().pageYOffset - Math.round($(el).height() / 2));
    }
};


SN.UI.GreyOut = function(vis, options) {

    if (!isPageValid)
        return false;
    // Pass true to gray out screen, false to ungray
    // options are optional.  This is a JSON object with the following (optional) properties
    // opacity:0-100         // Lower number = less grayout higher = more of a blackout 
    // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
    // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
    // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
    // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
    // in any order.  Pass only the properties you need to set.
    var options = options || {};
    var zindex = options.zindex || 4000000;
    var opacity = options.opacity || 70;
    var opaque = (opacity / 100);
    var bgcolor = options.bgcolor || '#000000';
    var dark = document.getElementById('darkenScreenObject');
    if (!dark) {
        // The dark layer doesn't exist, it's never been created.  So we'll
        // create it here and apply some basic styles.
        // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
        var tbody = document.getElementsByTagName("body")[0];
        var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position = 'absolute';                 // Position absolutely
        tnode.style.top = '0px';                           // In the top
        tnode.style.left = '0px';                          // Left corner of the page
        tnode.style.overflow = 'hidden';                   // Try to avoid making scroll bars            
        tnode.style.display = 'none';                      // Start out Hidden
        tnode.id = 'darkenScreenObject';                   // Name it so we can find it later
        tbody.appendChild(tnode);                            // Add it to the web page
        dark = document.getElementById('darkenScreenObject');  // Get the object.
    }
    if (vis) {
        // Calculate the page width and height 
        if (document.body && (document.body.scrollWidth || document.body.scrollHeight)) {
            var pageWidth = document.body.scrollWidth + 'px';
            var pageHeight = document.body.scrollHeight + 'px';
        }
        else if (document.body.offsetWidth) {
            var pageWidth = document.body.offsetWidth + 'px';
            var pageHeight = document.body.offsetHeight + 'px';
        }
        else {
            var pageWidth = '100%';
            var pageHeight = '100%';
        }
        //set the shader to cover the entire page and make it visible.
        dark.style.opacity = opaque;
        dark.style.MozOpacity = opaque;
        dark.style.filter = 'alpha(opacity=' + opacity + ')';
        dark.style.zIndex = zindex;
        dark.style.backgroundColor = bgcolor;
        dark.style.width = pageWidth;
        dark.style.height = pageHeight;
        dark.style.display = 'block';
    }
    else {
        dark.style.display = 'none';
    }
}


function welcomeClose() {
    document.getElementById("welcomeMod").style.display = 'none';
    MakeAjaxCall("/app_info/user/manage.aspx?cmd=hideWelcomeModule", function() { });
}

var tmpVal = "";
function textToggle(obj) {
    if (obj.style.color == "rgb(0,0,0)") {
        obj.style.color = "rgb(174,174,174)";
    } else {
        obj.value = "";
        obj.style.color = "rgb(0,0,0)";
    }
}

function descriptionExpander(obj) {
    targ = sn_getElementsByClassName("expandedInfo", obj.parentNode.parentNode)[0];
    SN.UI.toggleDisplay(targ);
    if (typeof (obj.src) == "undefined")
        obj = obj.parentNode.getElementsByTagName("img")[0];
    obj.src = (obj.src.indexOf("plusIco.jpg") == -1 ? "/images/icons/plusIco.jpg" : "/images/icons/minusIco.jpg");
    return false;
}
var musicPopup;
function popMusic(songs) {
    soundManager.stopAll();
    musicPopup = window.open('/music/popMusic.aspx?songs=' + songs, "popMusic", "location=no,status=no,scrollbars=no,resizable=no,titlebar=no,width=310,height=466");
    return false;
}

window.name = 'SNTopWindowDude';


function refreshCaptcha(el) {
    el.src = '/images/captcha/sncptcha.aspx?rand=' + Math.ceil(Math.random() * 10000000000);
}


function forceNumericInput(el, allowDot, allowMinus, event) {
    var allowed = false,
        key = String.fromCharCode(event.charCode || event.keyCode);

    switch (key) {
        case '-':
            if (allowMinus === true) {
                allowed = true;
                // wait until the element has been updated to see if the minus is in the right spot
                setTimeout(function(el) {
                    return function() {
                        removeNonstartingMinus(el);
                    };
                } (el), 250);
            }
            break;
        case '.':
            if (allowDot === true) {
                allowed = true;
                if (el.value.indexOf(".") > -1) {
                    // don't allow more than one dot
                    allowed = false;
                }
            }
            break;
        default:
            if ((key >= '0' && key <= '9') || event.keyCode == 8) {
                allowed = true;
            }
    }
    return allowed;
}
function removeNonstartingMinus(el) {
    var s = el.value,
        i = s.lastIndexOf("-");
    // if "-" exists then it better be the 1st character
    if (i > 0) {
        el.value = s.substring(0, i) + s.substring(i + 1);
    }
}

function writeMailDown() {
    var email = "";
    var huehuss = new Array();
    for (var i = 0; i < zqyhajz.length; i++) { huehuss[zqyhajz[i]] = kruhfns[i]; }
    for (var i = 0; i < huehuss.length; i++) { email += huehuss[i] + "<!-- >@. -->"; }

    document.write("<span style='text-transform:lowercase;'>" + email + "</span>");
    //document.write("<a href='mailto:" + email + "' style='text-transform:lowercase;font-size:smaller;'>" + email + "</a>");

}

function removeCharRegEx(string, searchFor) {
    // This searches for all occurrences of searchFor that occurs once or more
    // {1,} means 1 or more repeats
    // The second param, "gi", marks the search GLOBAL case-insensitive

    var RegEx = new RegExp("(" + searchFor + "){1,}", "gi");
    return string.replace(RegEx, searchFor);
}

function removeChar(string, searchFor) {

    var newString = "";

    for (i = 0; i < string.length; i++) {

        if (string.substr(i, 1) != searchFor)
            newString += string.substr(i, 1);
    }

    return newString;
}

function removeHTMLTags(strInputCode) {
    strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
        return (p1 == "lt") ? "<" : ">";
    });
    var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
    return strTagStrippedText;
}

function normalizeString(str) {
    str = removeHTMLTags(str);

    str = str.trim();
    str = str.replace(/\"/g, "");
    str = str.replace(/\n/g, "");
    str = str.replace(/\r/g, "");
    str = str.replace(/\f/g, "");
    str = removeChar(str, "/");
    str = str.trim();

    return str;

}

function WebSiteValidate(source, clientside_arguments) {
    var dv = new DataValidator();
    isPageValid = dv.IsValidURL(clientside_arguments.Value.trim());
    clientside_arguments.IsValid = isPageValid;
    if (!isPageValid)
        scroll(0, 260);
}

function setCookier(c_name, value, expiredays) {
    var exdate = new Date();

    exdate.setDate(exdate.getDate() + expiredays);

    document.cookie = c_name + "=" + value + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookier(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");

        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;

            c_end = document.cookie.indexOf(";", c_start);

            if (c_end == -1)
                c_end = document.cookie.length;

            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function checkCookier(byName) {
    var value = getCookier(byName);
    if (value != null && value != "") {
        return value;
    } else {
        if (byName = "signUpToPlay -- returnURL") {
            return "/battle-of-the-bands";
        }
    }
};
























var Loader = new Object();
Loader.timer = null;
Loader.stack = new Array();
Loader.file = "/images/master/ajax-loader1.gif";

/* Static function */
Loader.execute = function(index, bgPosition) {
    if (Loader.stack.length > 0) {
        if (Loader.stack[index].getAttribute("cleared") == "false") {
            Loader.stack[index].style.backgroundPosition = bgPosition;
            Loader.stack[index].style.backgroundImage = "url(" + Loader.file + ")";
            Loader.stack[index].style.backgroundRepeat = "no-repeat";
        }
        Loader.stack.splice(index, 1);
    }
};

/* Create an instance of this class below -> eg: var nipples = new Loader.loader(document.getElementById("nipple"), "center center");
* Then, once we load whatever, call the following method to clear the loading symbol -> nipples.clear();
* If nipples.clear() is called before 0.1 seconds after intialization, the loader symbol will not display :D
*/
Loader.loader = function(whereToShow, bgPosition) {
    /* Init Code */
    whereToShow.setAttribute("cleared", "false");
    Loader.stack.push(whereToShow);

    var indexToFind = Math.min(0, Loader.stack.length - 1);

    Loader.timer = setTimeout("Loader.execute(" + indexToFind + ", '" + bgPosition + "')", 300);

    this.clear = function() {
        whereToShow.setAttribute("cleared", "true");
        whereToShow.style.backgroundImage = "none";
        Loader.stack.splice(indexToFind, 1);
    };
};


function addLoadEvent(func) { /* TODO: Add to library */
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        };
    }
};