//to disable community, uncomment the following line, and flush the cache on this file

//SetCookieUtil("cCommunityAccess", "true");

//to re-enable community, uncomment the following line and flush the cache on this file
/* */

/*
* EB - Set, Get, and Delete Cookie utils - copied from 
* \\isteamsite.mtvi.com\iwserver\ismusic\main\mtv.com\STAGING\sitewide\fbml\scripts\utils.jhtml
*
*/
function GetCookieUtil (name) {
var result = null;
var myCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = myCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length;
endOfCookie = myCookie.indexOf(";", startOfCookie);
result = unescape(myCookie.substring(startOfCookie, endOfCookie));
}
if (result == "") result = null;
return result;
}

function SetCookieUtil (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "; path=/") +
((domain) ? "; domain=" + domain : "; domain="+document.location.hostname) +
((secure) ? "; secure" : "");
}

function DeleteCookieUtil (name,path,domain) {
if (GetCookieUtil(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}

var today = new Date();
var oneDay = new Date(today.getTime() + 24 * 60 *60 * 1000);
var oneWeek = new Date(today.getTime() + 24 * 60 *60 * 1000 * 7);
var oneYear = new Date(today.getTime() + 24 * 60 *60 * 1000 * 365);

/**** TACONITE SCRIPTS ****/
/**
@fileoverview
This JavaScript file represents the core browser-side functionality
supplied by Taconite. In general, the tools in this file wrap an instance
of XMLHttpRequest object and provide utility methods for gather data from
form elements to be sent to the server as par of an Ajax request.
*/

/**
Constructor for the AjaxRequest class. 

<br><br>
Example:

<br><br>
var ajaxRequest = new AjaxRequest("YOUR_URL");

@class The AjaxRequest object wraps an instance of XMLHttpRequest and provides 
facilities for setting functions that are called before a request is made
and after a request returns. By default, AjaxRequest handles the server
response by simply calling eval(), passing to it the responseText from 
the XMLHttpRequestObject, of course assuming that the response was 
generated by Taconite on the server side and that running eval() will 
update the web page.<br><br>Example Usage:<br><br>var ajaxRequest = new AjaxRequest("YOUR_URL");
<br>ajaxRequest.addFormElements("form_element_id_attribute_value");
<br>ajaxRequest.sendRequest();

@constructor
@param {String} a String repesenting the URL to which the Ajax request
will be sent.
*/
var taconite_client_version=1.6;
function AjaxRequest(url) {
/** @private */
var self = this;

/** @private */
var xmlHttp = createXMLHttpRequest();

/** @private */
var queryString = "";

/** @private */
var requestURL = url;

/** @private */
var method = "GET";

/** @private */
var preRequest = null;

/** @private */
var postRequest = null;

/** @private */
var debugResponse = false;

/** @private */
var async = true;

/** @private errorHandler*/ 
var errorHandler = null;

/** @private */ 
var useCacheBust = false;

/**
Return the instance of the XMLHttpRequest object wrapped by this object.
@return XMLHttpRequest
*/
this.getXMLHttpRequestObject = function() {
return xmlHttp;
}

/**
Set the pre-request function. This function will be called prior to 
sending the Ajax request. The pre-request function is passed a reference
to this object.
@param {Function} The function to be called prior to sending the Ajax
request. The function is passed a refernce of this object.
*/
this.setPreRequest = function(func) {
preRequest = func;
}

/**
Set the post-request function. This function will be called after the
response has been received and after eval() has been called using the 
XMLHttpRequest object's responseText. The post-request function is passed 
a reference to this object.
@param {Function} The function to be called after receiving the Ajax
response. The function is passed a refernce of this object.
*/
this.setPostRequest = function(func) {
postRequest = func;
}

/**
Return the post request function.
*/
this.getPostRequest = function() {
return postRequest;
}

/**
Send the Ajax request using the POST method. Use with caution -- some
browsers do not support the POST method with the XMLHttpRequest object.
*/
this.setUsePOST = function() {
method = "POST";
}

/**
Send the Ajax request using the GET method, where parameters are sent
as a query string appended to the URL. This is the default behavior.
*/
this.setUseGET = function() {
method = "GET";
}

/**
Enable client-side debugging. The server's response will be written
to a text area appended to the bottom of the page. If parsing is
performed on the client side, then the results of the parsing operations
are shown in their own text areas.
*/
this.setEchoDebugInfo = function() {
debugResponse = true;
}

/**
Indicate if debugging is enabled.
@return boolean
*/
this.isEchoDebugInfo = function() {
return debugResponse;
}

/**
Set the query string that will be sent to the server. For GET
requests, the query string is appended to the URL. For POST
requests, the query string is sent in the request body. This 
method is useful, for example, if you want to send an XML string
or JSON string to the server.
@param {String} qa, the new query string value.
*/
this.setQueryString = function(qs) {
queryString = qs;
}

/**
Return the query string.
@return The query string.
*/
this.getQueryString = function() {
return queryString;
}

/** 
@param {Boolean} asyncBoolean, set to true if asynchronous request, false synchronous request. 
*/
this.setAsync = function(asyncBoolean){
async = asyncBoolean;
}

/** 
@param {Function} Set the error handler function that is called if the 
server's HTTP response code is something other than 200.
*/	
this.setErrorHandler = function(func){
errorHandler = func;
}

/**
Set cache busting on the request. (reifmanm)
*/
this.setUseCacheBust = function() {
useCacheBust = true;
}

/**
Add all of the form elements under the specified form to the query
string to be sent to the server as part of the Ajax request. The values
are automatically encoded.
@param {String} formID, the value of the id attribute of the form from
which you wish to accumulate the form values.
*/
this.addFormElements = function(formID) {
var formElements = document.getElementById(formID).elements;
var values = toQueryString(formElements);
accumulateQueryString(values);
}

/** @private */
function accumulateQueryString(newValues) {
if(queryString == "") {
queryString = newValues; 
}
else {
queryString = queryString + "&" + newValues;
}
}

/**
Add the name/value pair to the query string.
@param {String} name
@param {String} value
*/
this.addNameValuePair = function(name, value) {
var nameValuePair = name + "=" + encodeURIComponent(value);
accumulateQueryString(nameValuePair);
}

/**
Same as addNamedFormElements, except it will filter form elements by form's id.
For example, these are all valid uses:<br>
<br>ajaxRequest.addNamedFormElements("form-id""element-name-1");
<br>ajaxRequest.addNamedFormElements("form-id","element-name-1",
"element-name-2", "element-name-3");
*/
this.addNamedFormElementsByFormID = function() {
var elementName = "";
var namedElements = null;

for(var i = 1; i < arguments.length; i++) {
elementName = arguments[i];
namedElements = document.getElementsByName(elementName);
var arNamedElements = new Array();
for(j = 0; j < namedElements.length; j++) {
if(namedElements[j].form && namedElements[j].form.getAttribute("id") == arguments[0]){
arNamedElements.push(namedElements[j]);	
}
}
if(arNamedElements.length > 0){
elementValues = toQueryString(arNamedElements);
accumulateQueryString(elementValues);
}
}
}

/**
Add the values of the named form elements to the query string to be
sent to the server as part of the Ajax request. This method takes any 
number of Strings representing the form elements for wish you wish to 
accumulate the values. The Strings must be the value of the element's 
name attribute.<br><br>For example, these are all valid uses:<br>
<br>ajaxRequest.addNamedFormElements("element-name-1");
<br>ajaxRequest.addNamedFormElements("element-name-1", "element-name-2", "element-name-3");
*/
this.addNamedFormElements = function() {
var elementName = "";
var namedElements = null;

for(var i = 0; i < arguments.length; i++) {
elementName = arguments[i];
namedElements = document.getElementsByName(elementName);

elementValues = toQueryString(namedElements);

accumulateQueryString(elementValues);
}

}

/**
Add the values of the id'd form elements to the query string to be
sent to the server as part of the Ajax request. This method takes any 
number of Strings representing the ids of the form elements for wish you wish to 
accumulate the values. The Strings must be the value of the element's 
name attribute.<br><br>For example, these are all valid uses:<br>
<br>ajaxRequest.addFormElementsById("element-id-1");
<br>ajaxRequest.addFormElementsById("element-id-1", "element-id-2", "element-id-3");
*/
this.addFormElementsById = function() {
var id = "";
var element = null;
var elements = new Array();

for(var h = 0; h < arguments.length; h++) {
element = document.getElementById(arguments[h]);
if(element != null) {
elements[h] = element;
}
}

elementValues = toQueryString(elements);
accumulateQueryString(elementValues);
}

/**
Send the Ajax request.
*/
this.sendRequest = function() {
if(preRequest) {
preRequest(self);
}

var obj = this;
if(async)
xmlHttp.onreadystatechange = function () { handleStateChange(self) };

if(useCacheBust){
if(requestURL.indexOf("?") > 0) {
requestURL = requestURL + "&ts=" + new Date().getTime();
}
else {
requestURL = requestURL + "?ts=" + new Date().getTime();
}
}

try {
if(method == "GET") {
if(queryString.length > 0) {
var connector = (requestURL.indexOf("?") > 0) ? "&" : "?";
requestURL = requestURL + connector + queryString;
}
xmlHttp.open(method, requestURL, async);
xmlHttp.send(null);
}
else {
xmlHttp.open(method, requestURL, async);
//Fix a bug in Firefox when posting
try {
if (xmlHttp.overrideMimeType) {
xmlHttp.setRequestHeader("Connection", "close");//set header after open
}	
}
catch(e) {
// Do nothing
}
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
xmlHttp.send(queryString);
}
}
catch(exception) {
if(errorHandler) {
errorHandler(self, exception);
}
else {
throw exception;
}
}

if(!async) { //synchronous request, handle the state change
handleStateChange(self);
}

if(self.isEchoDebugInfo()) {
echoRequestParams();
}
}

handleStateChange = function(ajaxRequest) {
if(ajaxRequest.getXMLHttpRequestObject().readyState != 4) {
return;
}
try {
var debug = ajaxRequest.isEchoDebugInfo();
if(debug) {
echoResponse(ajaxRequest);
}

//handle null responseXML
var nodes = null;
if (ajaxRequest.getXMLHttpRequestObject().responseXML != null) {
nodes = ajaxRequest.getXMLHttpRequestObject().responseXML.documentElement.childNodes;
}
else {
nodes = new Array();
}

var parser = new XhtmlToDOMParser();
var parseInBrowser = "";
for(var i = 0; i < nodes.length; i++) {
if(nodes[i].nodeType != 1 || !isTaconiteTag(nodes[i])) {
continue;
}

parseInBrowser = nodes[i].getAttribute("parseInBrowser");
if(parseInBrowser == "true") {
parser.parseXhtml(nodes[i]);
var js = parser.getJavaScript();
if(debug) {
echoParsedJavaScript(js);
}
}
else {
eval(nodes[i].firstChild.nodeValue);
}
}

if(ajaxRequest.getPostRequest()) {
var f = ajaxRequest.getPostRequest();
f(ajaxRequest);
}
}
catch(exception) {
if(errorHandler) {
errorHandler(self, exception);
}
else {
throw exception;
}
}
}

/** @private */
function isTaconiteTag(node) {
return node.tagName.substring(0, 9) == "taconite-";
}

/** @private */
function toQueryString(elements) {
var node = null;
var qs = "";
var name = "";

var tempString = "";
for(var i = 0; i < elements.length; i++) {
tempString = "";
node = elements[i];
name = node.getAttribute("name");

//use id if name is null
if (!name) {
name = node.getAttribute("id");
}

if(node.tagName.toLowerCase() == "input") {
if(node.type.toLowerCase() == "radio" || node.type.toLowerCase() == "checkbox") {
if(node.checked) {
tempString = name + "=" + node.value;
}
}

if(node.type.toLowerCase() == "text" || node.type.toLowerCase() == "hidden" || node.type.toLowerCase() == "password") {
tempString = name + "=" + encodeURIComponent(node.value);
}
}
else if(node.tagName.toLowerCase() == "select") {
tempString = getSelectedOptions(node);
}

else if(node.tagName.toLowerCase() == "textarea") {
tempString = name + "=" + encodeURIComponent(node.value);
}

if(tempString != "") {
if(qs == "") {
qs = tempString;
}
else {
qs = qs + "&" + tempString;
}
}

}

return qs;

}

/** @private */
function getSelectedOptions(select) {
var options = select.options;
var option = null;
var qs = "";
var tempString = "";

for(var x = 0; x < options.length; x++) {
tempString = "";
option = options[x];

if(option.selected) {
tempString = select.name + "=" + option.value;
}

if(tempString != "") {
if(qs == "") {
qs = tempString;
}
else {
qs = qs + "&" + tempString;
}
}
}

return qs;
}

/** @private */
function echoResponse(ajaxRequest) {
var echoTextArea = document.getElementById("debugResponse");
if(echoTextArea == null) {
echoTextArea = createDebugTextArea("Server Response:", "debugResponse");
}
var debugText = ajaxRequest.getXMLHttpRequestObject().status 
+ " " + ajaxRequest.getXMLHttpRequestObject().statusText + "\n\n\n";
echoTextArea.value = debugText + ajaxRequest.getXMLHttpRequestObject().responseText;
}

/** @private */
function echoParsedJavaScript(js) {
var echoTextArea = document.getElementById("debugParsedJavaScript");
if(echoTextArea == null) {
var echoTextArea = createDebugTextArea("Parsed JavaScript (by JavaScript Parser):", "debugParsedJavaScript");
}
echoTextArea.value = js;
}

/** @private */
function createDebugTextArea(label, id) {
echoTextArea = document.createElement("textarea");
echoTextArea.setAttribute("id", id);
echoTextArea.setAttribute("rows", "15");
echoTextArea.setAttribute("style", "width:100%");
echoTextArea.style.cssText = "width:100%";

document.getElementsByTagName("body")[0].appendChild(document.createTextNode(label));
document.getElementsByTagName("body")[0].appendChild(echoTextArea);
return echoTextArea;
}

/** @private */
function echoRequestParams() {
var qsTextBox = document.getElementById("qsTextBox");
if(qsTextBox == null) {
qsTextBox = createDebugTextBox("Query String:", "qsTextBox");
}
qsTextBox.value = queryString;

var urlTextBox = document.getElementById("urlTextBox");
if(urlTextBox == null) {
urlTextBox = createDebugTextBox("URL (Includes query string if GET request):", "urlTextBox");
}
urlTextBox.value = requestURL;
}

/** @private */
function createDebugTextBox(label, id) {
textBox = document.createElement("input");
textBox.setAttribute("type", "text");
textBox.setAttribute("id", id);
textBox.setAttribute("style", "width:100%");
textBox.style.cssText = "width:100%";

document.getElementsByTagName("body")[0].appendChild(document.createTextNode(label));
document.getElementsByTagName("body")[0].appendChild(textBox);
return textBox;
}

}

/**
Create an instance of the XMLHttpRequest object, using the appropriate
method for the type of browser in which this script is running. For Internet
Explorer, it's an ActiveX object, for all others it's a native JavaScript
object.
@return an instance of the XMLHttpRequest object.
*/
function createXMLHttpRequest() {
var req = false;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
req = false;
}
}
}
return req;
}

//JavaScript Document
var taconite_parser_version=1.502;
var isIE=document.uniqueID;
String.prototype.trim = function() {
//skip leading and trailing whitespace
//and return everything in between
var x=this;
x=x.replace(/^\s*(.*)/, "$1");
x=x.replace(/(.*?)\s*$/, "$1");
return x;
};

function requiresContextNode(xmlTagName) {
return !(xmlTagName == "taconite-execute-javascript" || xmlTagName == "taconite-redirect");
}

function XhtmlToDOMParser(){
this.parseXhtml = function(xml){
var xmlTagName=xml.tagName.toLowerCase();
var contextNode=document.getElementById(xml.getAttribute("contextNodeID"));
if(contextNode == null && requiresContextNode(xmlTagName)){
return false;
}
switch (xmlTagName) {
case "taconite-append-as-children":
getReplaceChildren(contextNode,xml,false);
break;
case "taconite-delete":
getDelete(contextNode,xml);
break;
case "taconite-append-as-first-child":
getAppendAsFirstChild(contextNode,xml);
break; 
case "taconite-insert-after":
getInsertAfter(contextNode,xml);
break;
case "taconite-insert-before":
getInsertBefore(contextNode,xml);
break; 
case "taconite-replace-children":
getReplaceChildren(contextNode,xml,true);
break;
case "taconite-replace":
getReplace(contextNode,xml);
break; 
case "taconite-set-attributes":
xml.removeAttribute("contextNodeID");
xml.removeAttribute("parseInBrowser");
handleAttributes(contextNode,xml);
break;
case "taconite-redirect":
handleRedirect(xml);
break;
case "taconite-execute-javascript":
executeJavascript(xml);
break;
} 
return true;
};

function isInlineMode(node) {
var attrType;
if(!node.tagName.toLowerCase() == "input") {
return false;
}
attrType=node.getAttribute("type");

if(attrType=="radio" || attrType=="checkbox") {
return true;
}
return false;
} 
this.getJavaScript= function() {
return "var dummy_taconite_variable=0";
}; 
function handleNode(xmlNode){
var nodeType = xmlNode.nodeType; 
switch(nodeType) {
case 1: //ELEMENT_NODE
return handleElement(xmlNode);
case 3: //TEXT_NODE
case 4: //CDATA_SECTION_NODE
var textNode = document.createTextNode(xmlNode.nodeValue);
if(isIE) {
textNode.nodeValue = textNode.nodeValue.replace(/\n/g, '\r'); 
}
return textNode;
} 
return null;
}
function handleElement(xmlNode){
var domElemNode=null;
var xmlNodeTagName=xmlNode.tagName.toLowerCase();
if(isIE){
if(isInlineMode(xmlNode)) {
return document.createElement("<INPUT " + handleAttributes(domElemNode,xmlNode,true) + ">");
}
if(xmlNodeTagName == "style"){
//In internet explorer, we have to use styleSheets array.	
var text,rulesArray,styleSheetPtr;
var regExp = /\s+/g;
text=xmlNode.text.replace(regExp, " ");
rulesArray=text.split("}");

domElemNode=document.createElement("style");
styleSheetPtr=document.styleSheets[document.styleSheets.length-1];
for(var i=0;i<rulesArray.length;i++){
rulesArray[i]=rulesArray[i].trim();
var rulePart=rulesArray[i].split("{");
if(rulePart.length==2) {//Add only if the rule is valid
styleSheetPtr.addRule(rulePart[0],rulePart[1],-1);//Append at the end of stylesheet.
}
}	
return domElemNode;	
}

}
if(domElemNode == null){
if(useIEFormElementCreationStrategy(xmlNodeTagName)) {
domElemNode = createFormElementsForIEStrategy(xmlNode);
}
else {
domElemNode = document.createElement(xmlNodeTagName);
}

handleAttributes(domElemNode,xmlNode);
//Fix for IE Script tag: Unexpected call to method or property access error
//IE don't allow script tag to have child
if(isIE && !domElemNode.canHaveChildren){
if(xmlNode.childNodes.length > 0){
domElemNode.text=xmlNode.text;
}

} 
else{
for(var z = 0; z < xmlNode.childNodes.length; z++) {
var domChildNode=handleNode(xmlNode.childNodes[z]);
if(domChildNode!=null) {
domElemNode.appendChild(domChildNode);
}
}
}
} 

return domElemNode;
}

function useIEFormElementCreationStrategy(xmlNodeTagName) {
var useIEStrategy = false;

if (isIE && ( xmlNodeTagName.toLowerCase() == "form" ||
xmlNodeTagName.toLowerCase() == "input" ||
xmlNodeTagName.toLowerCase() == "textarea" ||
xmlNodeTagName.toLowerCase() == "select" ||
xmlNodeTagName.toLowerCase() == "a" ||
xmlNodeTagName.toLowerCase() == "applet" ||
xmlNodeTagName.toLowerCase() == "button" ||
xmlNodeTagName.toLowerCase() == "img" ||
xmlNodeTagName.toLowerCase() == "link" ||
xmlNodeTagName.toLowerCase() == "map" ||
xmlNodeTagName.toLowerCase() == "object")) {

useIEStrategy = true;
}

return useIEStrategy;
}

function createFormElementsForIEStrategy(xmlNode) {
var attr = null;
var name = "";
var value = "";
for (var x = 0; x < xmlNode.attributes.length; x++) {
attr = xmlNode.attributes[x];
name = attr.name.trim();
if (name == "name") {
value = attr.value.trim();
}
}

domElemNode = document.createElement("<" + xmlNode.tagName + " name='" + value + "' />"); // e.g. document.createElement("<input name='slot2'>");

return domElemNode;
}

function handleAttributes(domNode, xmlNode) {
var attr = null;
var attrString = "";
var name = "";
var value = "";
var returnAsText = false;
if(arguments.length == 3) {
returnAsText = true;
}

for(var x = 0; x < xmlNode.attributes.length; x++) {
attr = xmlNode.attributes[x];
name = cleanAttributeName(attr.name.trim());
value = attr.value.trim().replace("&#38;", "&"); // added replace() to fix the safari bug that turns & in to numeric entity - gg
if(!returnAsText){
if(name == "style") {
/* IE workaround */
domNode.style.cssText = value;
/* Standards compliant */
domNode.setAttribute(name, value);
}
else if(name.trim().toLowerCase().substring(0, 2) == "on") {
/* IE workaround for event handlers */
//domNode.setAttribute(name,value);
eval("domNode." + name.trim().toLowerCase() + "=function(){" + value + "}");
}
else if(name == "value") {
/* IE workaround for the value attribute -- makes form elements selectable/editable */
domNode.value = value;
}
else if(useIEFormElementCreationStrategy(xmlNode.tagName) && name == "name") {
//Do nothing, as the "name" attribute was handled in the createFormElementsForIEStrategy function
continue;
}
else {
/* Standards compliant */
domNode.setAttribute(name,value);
}
/* class attribute workaround for IE */
if(name == "class") {
domNode.setAttribute("className",value);
}
}else{
attrString = attrString + name + "=\"" + value + "\" " ;
}
}
return attrString;
}
function getAppendAsFirstChild(domNode,xml){
var firstNode=null;
if(domNode.childNodes.length > 0) {
firstNode=domNode.childNodes[0];
}

for(var i=0;i<xml.childNodes.length;i++){
domChildNode=handleNode(xml.childNodes[i]);
if(domChildNode!=null){
if(firstNode==null){
domNode.appendChild(domChildNode);
firstNode=domChildNode;
}
else {
domNode.insertBefore(domChildNode,firstNode);
}

}
} 
}

function getInsertAfter(domNode,xml){
var domChildNode=null;
var nextSibling=domNode.nextSibling;
for(var i=0;i<xml.childNodes.length;i++){
domChildNode=handleNode(xml.childNodes[i]);
if(domChildNode!=null){
if(nextSibling!=null) {
domNode.parentNode.insertBefore(domChildNode,nextSibling);
}
else {
domNode.parentNode.appendChild(domChildNode);
}
}
} 
}
function getInsertBefore(domNode,xml){
var domChildNode=null;
for(var i=0;i<xml.childNodes.length;i++){
domChildNode=handleNode(xml.childNodes[i]);
if(domChildNode!=null) {
domNode.parentNode.insertBefore(domChildNode,domNode);
}
} 
} 
function getReplace(domNode,xml){
getInsertAfter(domNode,xml);
domNode.parentNode.removeChild(domNode);
}
function getDelete(domNode) {
domNode.parentNode.removeChild(domNode);
}
function getReplaceChildren(domNode,xml,doRemoveChildren) {
var domChildNode=null;
if(doRemoveChildren){
while(domNode.childNodes.length >0){
domNode.removeChild(domNode.childNodes[0]);
} 
}
for(var i=0;i<xml.childNodes.length;i++){
domChildNode=handleNode(xml.childNodes[i]);
if(domChildNode!=null) {
domNode.appendChild(domChildNode);
}
} 
}

function handleRedirect(xmlNode) {
var targetUrl = xmlNode.getAttribute("targetUrl");
window.location.replace(targetUrl);
}

function executeJavascript(xmlNode) {
var scripts = xmlNode.getElementsByTagName("script");
for (var i = 0; i < scripts.length; i++) {
var script = scripts[i];
if (script.getAttribute("type") == "text/javascript") {
var js = script.firstChild.nodeValue;
eval(js);
}
}
}

function cleanAttributeName(name) {
if(isIE == false) {
return name; // added "return name;" - previously only worked when isIE was undefined. MR
}

// IE workaround to change cellspacing to cellSpacing, etc
var cleanName = name.toLowerCase();
if(cleanName == "cellspacing") {
cleanName = "cellSpacing";
}
else if(cleanName == "cellpadding") {
cleanName = "cellPadding";
}
else if(cleanName == "colspan") {
cleanName = "colSpan";
}
else if(cleanName == "tabindex") {
cleanName = "tabIndex";
}
else if(cleanName == "readonly") {
cleanName = "readOnly";
}
return cleanName;
}

}

/* EB END Copied from utils */

if (GetCookieUtil("cCommunityAccess")=="false"){ SetCookieUtil("cCommunityAccess", ""); }

function injectFluxWidget(widgetName, options){
var showWidget = "false";

if (widgetName=="Comments2" && GetCookieUtil("cCommunityComments")=="true"){ 
showWidget = "true"; 
if (GetCookieUtil("cCommunityPhase")=="2") options.displayUserName = true;
}
if (widgetName=="Rating" && GetCookieUtil("cCommunityRating")=="true"){ showWidget = "true"; }
if (widgetName=="Usage" && GetCookieUtil("cCommunityUsage")=="true"){ showWidget = "true"; }
if (widgetName=="QuickMenu" && GetCookieUtil("cCommunityPhase")=="2"){ showWidget = "true"; }
if (widgetName=="ContentAction" && GetCookieUtil("cCommunityPhase")=="2"){ showWidget = "true"; }

if (showWidget=="true" && GetCookieUtil("cCommunityAccess")=="true"){
if (Flux && Flux.Utils.WidgetsLoader) {
Flux.Utils.WidgetsLoader.createWidget(widgetName, options);
}
}
}

function fluxWidgetError(errorCode){
//alert('fluxWidgetError');
community.open(errorCode);
}

function Community() {
var fluxAuthTokenCookieName = 'RtxAuth2407';
var communityHostname = 'http://community.mtv.com';	
var onFinish = "";

/* dialogue open and close */
this.open = function(page){
if((page=="login" || page=="register") && GetCookieUtil("cCommunityAccess")!="true"){
switch(page){
case 'login': window.open('/sitewide/community/login/', 'loginPopUp', 'width=448,height=309,'); break;
case 'register': window.open('/community/account/join.jhtml?serv=&amp;mtvparams=&amp;target=&amp;mesg=', 'loginPopUp', 'width=448,height=309,'); break;
document.getElementById("big_blue").style.display = "block"; 
default: break;
}
}
else{
if (GetCookieUtil("cCommunityPhase")>=2 && (page=="register" || page=="login" || page=="join")){ 
this.hostedPageLink(page);
document.getElementById("big_blue").style.display = "block"; 
}
else{
overlayOpen();
window.scrollTo(0,0);
this.link(page);
document.getElementById("big_blue").style.display = "block"; 
}
}
}

this.close = function(){
overlayClose();
this.link('clear');
document.getElementById("big_blue").style.display = "none"; 
}

this.finish = function(){
this.close();	
if (this.onFinish != undefined){
switch(this.onFinish){
case 'reload': window.location.reload(); break;
default: window.location.href = this.onFinish; break;
}
}
}

/* links */
this.hostedPageLink = function(page, id){
var hostedPage = "/";
switch(page){
case 'discussion': hostedPage = '/-/Content/Discussions/DiscussionBoard.aspx?catId=' + id; break;
case 'join': hostedPage = '/-/JoinInterim.aspx?returnPath=' + window.location.href; break;
case 'login': hostedPage = '/-/SignUp.aspx?returnPath=' + window.location.href; break;
case 'register': hostedPage = '/-/SignUp.aspx?returnPath=' + window.location.href; break;
default: break;
}	

window.location.href=communityHostname + hostedPage;
}

this.link = function(page){
if (GetCookieUtil("cCommunityPhase")>=2 && (page=="register" || page=="login" || page=="join")){ 
this.hostedPageLink(page);
}
else{
/* temporary iframe fix */
this.hide(document.getElementById('communityUpload'));

switch(page){
case 'clear': submit('/sitewide/community/forms/clear.jhtml'); break;
case 'join': submit('/sitewide/community/forms/join.jhtml'); break;
case 'login': submit('/sitewide/community/forms/login.jhtml'); break;
case 'loginFromReg': submit('/sitewide/community/forms/login.jhtml?event=loginFromRegLink'); break;
case 'notJoined': submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
case 'notLoggedIn': submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
case 'notVerified':	submit('/sitewide/community/forms/error.jhtml?errorCode=' + page + '&phase=' + GetCookieUtil("cCommunityPhase")); break;
case 'passwordReminder': submit('/sitewide/community/forms/passwordReminder.jhtml'); break;
case 'problems': submit('/sitewide/community/forms/problems.jhtml'); break;
case 'register': submit('/sitewide/community/forms/register.jhtml'); break;
case 'sendValidation': submit('/sitewide/community/forms/sendValidation.jhtml'); break;
case 'updateAccount': submit('/sitewide/community/forms/updateAccount.jhtml'); break;
case 'updatePassword': submit('/sitewide/community/forms/updatePassword.jhtml'); break;
case 'uploadPhoto': submit('/sitewide/community/forms/uploadPhoto.jhtml'); break;
case 'uploadSuccess': submit('/sitewide/community/forms/updateAccount.jhtml?action=uploadSuccess'); break;
case 'uploadSkip': submit('/sitewide/community/forms/welcome.jhtml?action=register&event=uploadSkip'); break;
case 'quit': submit('/sitewide/community/forms/quit.jhtml'); break;
case 'welcomeRegister': submit('/sitewide/community/forms/welcome.jhtml?action=register'); break;
default: submit(page); break;
}
}
}

/* form handlers */
this.handle = function(form, elements){
switch(form){
case 'deactivate': submit('/sitewide/community/forms/do_deactivate.jhtml'); break;
case 'join': submit('/sitewide/community/forms/do_join.jhtml', ['firstName', 'lastName', 'username', 'agreeToTerms']); break;
case 'login': submit('/sitewide/community/forms/do_login.jhtml', ['loginName', 'password']); break;
case 'logout': submit('/sitewide/community/forms/logout.jhtml'); break;
case 'passwordReminder': submit('/sitewide/community/forms/do_passwordReminder.jhtml', ['email']); break;
case 'register': submit('/sitewide/community/forms/do_register.jhtml', ['email', 'emailConfirm', 'password', 'passwordConfirm', 'loginName', 'firstName', 'lastName', 'birthDateMonth', 'birthDateDay', 'birthDateYear', 'postalCode', 'agreeToTerms', 'gender']); break;
case 'updateAccount': submit('/sitewide/community/forms/do_updateAccount.jhtml', elements); break;	
case 'updatePassword': submit('/sitewide/community/forms/do_updatePassword.jhtml', ['currentPassword', 'newPassword', 'newPasswordConfirm']); break;
case 'unjoin': submit('/sitewide/community/forms/do_unjoin.jhtml'); break;
case 'sendValidation': submit('/sitewide/community/forms/do_sendValidation.jhtml', ['email']); break;
default: break;
}
}

this.updateWidgets = function(){
submit('/sitewide/community/forms/updateWidgets.jhtml');
}

this.pop = function(url, type){
var features;
if (type=='legal') features = "width=620,height=600,scrollbars";
if (url=='faq'){
url = "/sitewide/mtvinfo/social_project_faq.jhtml";
features = "width=620,height=600,scrollbars";
}
if (url=='betaInvite'){
url = "/community/invite/index.jhtml";
features = "width=344,height=320,menubar=no,status=yes,scrollbars=no";
}
window.open(url, '', features);
}

/* utils */
this.getQuickmenu = function(){
if(GetCookieUtil("cCommunityPhase")=="2"){
this.show(document.getElementById("quickmenu"));
}
else{ 
if(GetCookieUtil("cCommunityAccess")=="true") this.loadMamabar();
this.show(document.getElementById("mamabar"));
}
}

this.loadMamabar = function(){
submit('/sitewide/community/includes/mamabar.jhtml', [], false);
}

this.checkUsername = function(username){
submit('/sitewide/community/forms/checkUsername.jhtml?loginName=' + username);
}

this.setBetaCookies = function(){
SetCookieUtil('cCommunityAccess', 'true', oneYear);
SetCookieUtil('cCommunityComments', 'true', oneYear);
SetCookieUtil('cCommunityRating', 'true', oneYear);
SetCookieUtil('cCommunityUsage', 'true', oneYear);
}

this.clearAuthCookie = function(){
if (GetCookieUtil(fluxAuthTokenCookieName)!=null){
var hostname = document.location.hostname;
hostname = hostname.substring(hostname.indexOf('www.')+4, hostname.length);
SetCookieUtil(fluxAuthTokenCookieName, '', '', '/', hostname);
}
}

this.toggleFormFields = function(inputId, action){
var input = document.getElementById(inputId);
var open = document.getElementById(inputId + "Open");
var closed = document.getElementById(inputId + "Closed");
var parentForm = input.form;

if (action == 'show'){
/* toggle */
show(open);
hide(closed);

/* show related fields */
var x = parentForm.getElementsByTagName('tr');
for (var i=0;i<x.length;i++){
var tr = x[i];
if (x[i].getAttribute('rel') == inputId){
x[i].className = x[i].className.substring(0, x[i].className.indexOf('hide'));
}
}
}
if (action == 'hide'){
/* toggle */
show(closed);
hide(open);

/* hide related fields */
var x = parentForm.getElementsByTagName('tr');
for (var i=0;i<x.length;i++){
if (x[i].getAttribute('rel') == inputId){
x[i].className = x[i].className + " hide";
}
}
}
}

this.show = function(element){
show(element);
}

this.hide = function(element){
hide(element);
}

function show(element){
//alert('show');
if (element!=null && element.className.indexOf('hide') >= 0){
element.className = element.className.substring(0, element.className.indexOf('hide'));
}
}

function hide(element){
//alert('hide');
if (element!=null){
element.className = element.className + " hide";
}
}

function loadingOn(){
//alert('loadingOn');
var element = document.getElementById('communityLoading');
if (element!=null && element.className.indexOf('hide') >= 0){
element.className = element.className.substring(0, element.className.indexOf('hide'));
}
}

function loadingOff(){
//alert('loadingOff');
var element = document.getElementById('communityLoading');
if (element!=null){
element.className = element.className + " hide";
}
}

function submit(url, formElements, async){
//alert('submit');
var ar = new AjaxRequest(url);
if (formElements != undefined){
for (var i=0; i < formElements.length; i++){
ar.addNamedFormElements(formElements[i]); 
}
}

if (async!=null){ ar.setAsync(async); }

ar.setPreRequest(loadingOn);
ar.sendRequest();
ar.setPostRequest(loadingOff);
}

function overlayOpen(){
//alert('overlayIsOpen');
if (document.getElementById("embeddedPlayer")) document.getElementById("embeddedPlayer").pausePlayer();;
//if (document.getElementById("game")) hide(document.getElementById("game"));
if (document.getElementById("overlay") && document.getElementById("dialogue")){
document.getElementById("overlay").className = "open";
document.getElementById("overlay").style.display = "block";
document.getElementById("overlay").style.height = document.body.offsetHeight + "px";
document.getElementById("dialogue").className= "open";
}	
}

function overlayClose(){
//alert('overlayClose');
//if (document.getElementById("embeddedPlayer")) document.getElementById("embeddedPlayer").externalUnPauseRequest();
document.getElementById("overlay").className = "";
document.getElementById("overlay").style.height = "0px";
document.getElementById("overlay").style.display = "none";
document.getElementById("dialogue").className= "";
//if (document.getElementById("game")) show(document.getElementById("game"));
}

this.setReportingVars = function(){
var vars = "";
var numkeys = 2;
var keyvals = new Array(2);
var keynames = new Array(2);

keynames[0] = "siteFormat";	//prop31 - logged in
keynames[1] = "betaUsage";	// prop34 - beta user	

keyvals[0] = (GetCookieUtil(fluxAuthTokenCookieName) != null) ? 'community' : 'non-community';
keyvals[1] = (GetCookieUtil('cCommunityAccess')=='true') ? 'community' : '';

for (var i=0; i<numkeys; i++){
if (keyvals[i].length != 0){
vars = vars + keynames[i] + "=" + keyvals[i] + ";";
}
}
return vars;
}

this.report = function(page, event){
var regEvent;
var pageName = 'community/dialogue/' + page + '.jhtml'; 

//dispatcher.setAttribute('pageName', pageName);
//dispatcher.setAttribute('hier2', pageName);
//dispatcher.setAttribute('channel', 'community');
//dispatcher.setAttribute('prop31', 'community');
//dispatcher.setAttribute('prop34', 'community');

switch(page){
case 'register': 
regEvent='event2';	// register open
this.setCampaignAttribute();
break;
case 'uploadPhoto': regEvent='event3'; break;	// register success
case 'welcomeRegister': 
if(event=='uploadSkip'){ regEvent='event5'; }	// upload skip
else{ regEvent='event4'; }	// upload success
break;
case 'login':
if(event=='loginFromRegLink'){ regEvent='event6'; }	// login open from registration link
if(event=='loginFromRegSubmit'){ regEvent='event7'; }	// login open from registration submit
break;	
case 'join': regEvent='event8'; break;	// login success
case 'welcomeJoin': regEvent='event9'; break;	// join success
default: break;
}

if (regEvent!=null){
//dispatcher.setAttribute('eVar1', 'registration');
//dispatcher.setAttribute('events', regEvent); 
}

//dispatcher.sendCall();

// clear attributes
//dispatcher.setAttribute('pageName', '');
//dispatcher.setAttribute('hier2', '');
//dispatcher.setAttribute('channel', '');
//dispatcher.setAttribute('prop31', '');
//dispatcher.setAttribute('prop34', '');
//dispatcher.setAttribute('eVar1', '');
//dispatcher.setAttribute('events', '');
}

this.setBetaLandingAttributes = function(){
//dispatcher.setAttribute('events','event1');
}

this.setCampaignAttribute = function(){
var cmp = com.mtvi.util.queryStringToHash(top.location.search);
if (cmp.source != undefined){
//dispatcher.setAttribute('campaign',cmp.source);
}
}

}

var community = new Community();

/* set beta cookies for all users */
community.setBetaCookies();

/*
function toggleGuestbook(){
alert('toggleGuestbook');
community.setBetaCookies();
community.loadMamabar();
community.hide(document.getElementById('guestbookLegacy'));
community.show(document.getElementById('guestbook'));
}

function openHillsBoards(){
alert('openHillsBoards');
if (GetCookieUtil("cCommunityAccess")!="false"){
window.location.href = "/ontv/dyn/the_hills/message_boards.jhtml";
}
else{
boardPop('5553');
}
}

*/