// JavaScript Document
var hostName = "http://www.wweaffiliates.com";
var count = 0;
var timeDelay = 4000;
var newsItems = null;
var newsCount = null;

function setupTicker() {
        newsItems = document.getElementById("news-items").getElementsByTagName("div");
        newsCount = newsItems.length;
        interval = window.setInterval("updateTicker()", timeDelay)
        updateTicker();
}

function updateTicker() {
        var newsItem = newsItems[count].getElementsByTagName("span");
        document.getElementById("news-title").innerHTML = "<span>" + newsItem[0].innerHTML + "</span>";
        document.getElementById("news-description").innerHTML = "<span>" + newsItem[1].innerHTML + "</span>";
        count++;
        if(count >= newsCount) { count = 0; }
}

function toggleMenu(node) {

        var lNodes = node.parentNode.parentNode.childNodes;

        for (var i = 0; i < lNodes.length; i++) {
                if(lNodes[i].className == 'expand') { lNodes[i].className = 'collapse'; }
        }

        switch (node.parentNode.className) {
                case 'expand':          node.parentNode.className = 'collapse'; break
                case 'collapse':        node.parentNode.className = 'expand'; break
        }
}

function wwefiximages (e) {
        if (document.getElementById) {
                var element = document.getElementById(e)

                var imgs = element.getElementsByTagName('img');
                for (i=0; i<imgs.length; i++) {
                        imgs[i].className  = imgs[i].getAttribute('align');
                }
        }
}

function popup(url, width, height, resizable, location, statusbar, menubar, toolbar, scrollbars) {
        if (!width || !height) {
                // open a full browser window
                window.open(url);
        } else {
                // open a popup with options
                var day = new Date();
                var id = day.getTime();

                var params = '';

                if (!width) width = 0;
                if (!height) height = 0;
                if (!resizable) resizable = 0;
                if (!location) location = 0;
                if (!statusbar) statusbar = 0;
                if (!menubar) menubar = 0;
                if (!toolbar) toolbar = 0;
                if (!scrollbars) scrollbars = 0;

                if (height >= (window.screen.availHeight - 40)) {
                        height = window.screen.availHeight - 40;
                        width = width + 20;
                        scrollbars = 1;
                }

                if (width >= (window.screen.availWidth - 20)) {
                        width = window.screen.availWidth - 20;
                        scrollbars = 1;
                }

                params += 'width=' + width + ',';
                params += 'height=' + height + ',';
                params += 'resizable=' + resizable + ',';
                params += 'location=' + location + ',';
                params += 'statusbar=' + statusbar + ',';
                params += 'menubar=' + menubar + ',';
                params += 'toolbar=' + toolbar + ',';
                params += 'scrollbars=' + scrollbars + ',';

                window.open(url, id, params);
        }
}

function wwevideoplayer(path, type, parent) {
        var show = 'wwe';
        if (typeof(type) == 'undefined') type = 'general';
        if (typeof(parent) == 'undefined') parent = '';

        if (window.location.pathname.indexOf('shows/raw') >= 0) {
                show = 'raw';
        } else if (window.location.pathname.indexOf('shows/smackdown') >= 0) {
                show = 'smackdown';
        } else if (window.location.pathname.indexOf('shows/247') >= 0) {
                show = '247';
        } else if (window.location.pathname.indexOf('community/bytethis') >= 0) {
                show = 'bytethis';
        }

        switch(type) {
                case 'general':
                        popup(path + '?show=' + show, 700, 515);
                        break
                case 'jukebox':
                        popup(path + "?view=jukebox&parent=" + parent, 650, 530);
                        break
                default:
                        break
        }
}

function wwecookie (document, name, hours, path, domain, secure) {
        this.$document = document;
        this.$name = name;
        if (hours) {
                this.$expiration = new Date((new Date()).getTime( ) + hours*3600000);
        } else {
                this.$expiration = null;
        }
        if (path) this.$path = path; else this.$path = null;
        if (domain) this.$domain = domain; else this.$domain = null;
        if (secure) this.$secure = true; else this.$secure = false;
}

wwecookie.prototype.store = function () {
        var cookieval = "";
        for(var prop in this) {
                if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || (prop == '')) continue;
                if (cookieval != "") cookieval += '&';
                cookieval += prop + ':' + escape(this[prop]);
        }

        var cookie = this.$name + '=' + cookieval;
        if (this.$expiration) cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}

wwecookie.prototype.load = function() {
        var allcookies = this.$document.cookie;
        if (allcookies == "") return false;

        var start = allcookies.indexOf(this.$name + '=');
        if (start == -1) return false;
        start += this.$name.length + 1;
        var end = allcookies.indexOf(';', start);
        if (end == -1) end = allcookies.length;
        var cookieval = allcookies.substring(start, end);

        var a = cookieval.split('&');
        for(var i=0; i < a.length; i++) {
                a[i] = a[i].split(':');
        }

        for(var i = 0; i < a.length; i++) {
                this[a[i][0]] = unescape(a[i][1]);
        }

        return true;
}

wwecookie.prototype.remove = function() {
        var cookie;
        cookie = this.$name + '=';
        if (this.$path) cookie += '; path=' + this.$path;
        if (this.$domain) cookie += '; domain=' + this.$domain;
        cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

        this.$document.cookie = cookie;
}

// Setup Global Cookie
var host;
if (window.location.host.toString() != 'localhost') host = '.wwe.com';
var visitordata = new wwecookie(document, ".visitor", 24*356, '/', host);
if (!visitordata.load()) visitordata.store();

function countrySelect(country) {
                //set country cookie
                if (countrydata == null) {
                        var countrydata = new wwecookie(document, ".country", 24*356, '/', host);
                }
                countrydata.country = country;
                countrydata.store();
                document.location.href='?country='+country;
}

var on_cable      = ['hc1',      'hc3',                  'hc7'];
var on_satellite  = [                  'hc4'                  ];
var on_telco      = [                                    'hc7','hca'];
var on_tv         = [                        'hc5'            ];
var on_agency     = [                              'hc6'      ];
var on_marketing  = [                              'hc6'      ];
var on_radio      = [                              'hc6'      ];
var on_other      = [      'hc2',                  'hc6'      ];
var on_wwe        = [                                                'hc12'];

var off_cable     = [      'hc2',      'hc4','hc5','hc6',     ,'hca','hc12'];
var off_satellite = ['hc1','hc2','hc3',      'hc5','hc6'      ,'hca','hc12'];
var off_telco     = ['hc1','hc2','hc3','hc4','hc5','hc6'            ,'hc12'];
var off_tv        = ['hc1','hc2','hc3','hc4',      'hc6','hc7','hca','hc12'];
var off_agency    = ['hc1','hc2','hc3','hc4','hc5',      'hc7','hca','hc12'];
var off_marketing = ['hc1','hc2','hc3','hc4','hc5',      'hc7','hca','hc12'];
var off_radio     = ['hc1','hc2','hc3','hc4','hc5',      'hc7','hca','hc12'];
var off_other     = ['hc1',      'hc3','hc4','hc5',      'hc7','hca','hc12'];
var off_wwe       = ['hc1','hc2','hc3','hc4','hc5','hc6','hc7','hca'       ];

if (typeof(AFF) == 'undefined') {
        AFF = function () {}
}

if (typeof(AFF.Toggle) == 'undefined') {
        AFF.Toggle = function () {
                return {
                        toggleTable: function (id, obj) {
                        var display = 'table-row';
                          if (navigator.appName == "Microsoft Internet Explorer") { display = 'block'; }
                        document.getElementById(id).style.display=(obj.checked==true) ? display : 'none';
                        },

                        toggleTables: function (arr, obj) {
                                for (id in arr) {
                                        this.toggleTable(arr[id], obj);
                                }
                        },

                        closeTable: function(id, obj) {
                          var display = 'table-row';
                          if (navigator.appName == "Microsoft Internet Explorer") { display = 'block'; }
                          document.getElementById(id).style.display='none';
                        },

                        closeTables: function(arr, obj) {
                                for (id in arr) {
                                        this.closeTable(arr[id], obj);
                                }
                        }
                };
  }();
}


if (typeof(AFF.Ajax) == 'undefined') {
        AFF.Ajax = function () {
                return {
                        ajaxRequest: null,
                        selectCtl: null,
                        xmlHttp: null,
                        obj: null,

                        createXMLHttpRequest : function() {
                                if (window.ActiveXObject) {
                                        try {
                                                this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                                        } catch (e) {
                                                this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                                        }
                                } else if (window.XMLHttpRequest) {
                                                        this.xmlHttp = new XMLHttpRequest();
                                }
                        },

                        ajaxCall : function() {
                                this.createXMLHttpRequest();
                                this.xmlHttp.onreadystatechange = this.handleResponse;
                                this.xmlHttp.open("GET", this.ajaxRequest, true);
                                this.xmlHttp.send(null);
                        },

                        refreshT_system : function(index, id) {
                                this.ajaxRequest = hostName+"/ajaxdata.do?option_id="+index;
                                this.selectCtl = id;

                                this.ajaxCall();
                        },

                        handleResponse : function() {
                                if(this.xmlHttp.readyState == 4) {
                                        if(this.xmlHttp.status == 200) {
                                                this.updateSelectList();
                                        }
                                }
                        },

                        updateSelectList : function() {
                                this.clearSelectList();

                                var oSelectCtl = document.getElementById(selectCtl);
                                var results = this.xmlHttp.responseXML.getElementsByTagName("option");
                                for(var i = 0; i < results.length; i++) {
                                        if (null != results[i].firstChild) {

                                                var sValue = results[i].firstChild.firstChild.nodeValue;
                                                var sText = results[i].lastChild.firstChild.nodeValue;

                                                var oOptionText = document.createTextNode(sText);
                                                var oOption = document.createElement("option");

                                                oOption.setAttribute("value", sValue);
                                                oOption.appendChild(oOptionText);
                                                oSelectCtl.appendChild(oOption);
                                        }
                                }
                        },

                        clearSelectList : function() {
                                var models = document.getElementById(selectCtl);
                                while(models.childNodes.length > 0) {
                                        models.removeChild(models.childNodes[0]);
                                }
                        }
                };
  }();
}

var ajaxRequest, selectCtl, xmlHttp, obj;

function createXMLHttpRequest() {
        if (window.ActiveXObject) {
                try {
                        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                } catch (e) {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                /*    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); */
        } else if (window.XMLHttpRequest) {
                xmlHttp = new XMLHttpRequest();
        }
}


function ajaxCall() {
  createXMLHttpRequest();
  xmlHttp.onreadystatechange = handleResponse;
  xmlHttp.open("GET", ajaxRequest, true);
  xmlHttp.send(null);
}

function refreshT_system(index,id,selected_id) {
        if (selected_id == null) {
                selected_id = 1;
        }

        ajaxRequest = hostName+"/ajaxdata.do?option_id="+index+"&selected_id="+selected_id;
        selectCtl = id;

        obj1 = new Object();
        obj1.tagname = id;

        ajaxCall();
}

function handleResponse() {
        if(xmlHttp.readyState == 4) {
                if(xmlHttp.status == 200) {
                        updateSelectList();
                }
        }
}

function updateSelectList() {
        clearSelectList();

        var selectedValue;
        var oSelectCtl = document.getElementById(selectCtl);
        var selected;

        if (navigator.appName == "Microsoft Internet Explorer") {
                selected = xmlHttp.responseXML.getElementsByTagName("selected");
                selectedValue = selected.context.firstChild.firstChild.text;
        } else {
                selectedValue = xmlHttp.responseXML.firstChild.firstChild.textContent;
        }

        var results = xmlHttp.responseXML.getElementsByTagName("option");
        for(var i = 0; i < results.length; i++) {
        if (null != results[i].firstChild && null != results[i].lastChild.firstChild) {
      var sValue = results[i].firstChild.firstChild.nodeValue;
      var sText = results[i].lastChild.firstChild.nodeValue;

                        var oOptionText = document.createTextNode(sText);
                        var oOption = document.createElement("option");

                        oOption.setAttribute("value", sValue);
                        oOption.appendChild(oOptionText);
                        if (sValue == selectedValue) {
                                oOption.setAttribute('selected', 'true');
                        }
                        oSelectCtl.appendChild(oOption);
    }
        }

}

function clearSelectList() {
        var models = document.getElementById(selectCtl);
        while(models.childNodes.length > 0) {
                models.removeChild(models.childNodes[0]);
        }
}

function onMSOTextBox(obj, id) {

        if (obj.options[obj.selectedIndex].text == 'Other') {
                document.getElementById(id).style.display = 'block';
        } else {
                document.getElementById(id).style.display = 'none';
        }
}


function onSysTextBox(obj, id) {

        if (obj.options[obj.selectedIndex].text == 'Other') {
                document.getElementById(id).style.display = 'block';
        } else {
                document.getElementById(id).style.display = 'none';
        }
}

function offMSOTextBox(obj, id) {
                document.getElementById(id).style.display = 'none';
}

function CiFormSend() {
        document.WWE.submit();
        return false;
}

