﻿/*******************************************************************/
var req;
/*******************************************************************/
function getReqXMLHTTPObj() {
    var a = null;
    try { a = new ActiveXObject("Msxml2.XMLHTTP"); }
    catch (b) {
        try { a = new ActiveXObject("Microsoft.XMLHTTP") }
        catch (c) { a = null; }
    }
    if (!a && typeof XMLHttpRequest != "undefined") {
        a = new XMLHttpRequest();
    }
    return a;
}
/*******************************************************************/
function AjaxCall(url, onCallback) {
    req = getReqXMLHTTPObj();
    req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random() * 100000);
    url = url + "&rnd=" + rnd;
    req.open("GET", url, true);
    req.send(null);
}
/*******************************************************************/
function AjaxCallNoCallBack(url) {
    req = getReqXMLHTTPObj();
    req.open("GET", url, false);
    req.send(null);
}
/*******************************************************************/
function AjaxPostCall(url, qs, onCallback) {
    req = getReqXMLHTTPObj();
    req.onreadystatechange = onCallback;
    var rnd = Math.floor(Math.random() * 100000)
    qs = qs + "&rnd=" + rnd + "&method=post";
    req.open("POST", url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.setRequestHeader("Accept", "text/xml");
    req.send(qs);
}
/*********************************************************************/
function checkDisplayName(val) {
    var url = "checkDisplayName.ashx?d=" + val;
    AjaxCall(url, onDisplayNameCheck);
}
/*********************************************************************/
function onDisplayNameCheck() {
    var d = document.getElementById("divDisplayName");
    d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                if (rtext == '1')
                    d.innerHTML = "<font size='1' color='red'>DisplayName is taken already, please select a different DisplayName</font>";
                else
                    d.innerHTML = "<font size='1' color='red'>DisplayName is Available</font>";
            }
        }
    }
}
/*********************************************************************/
function addSubscriber(userId, subscriberId) {
    var url = 'addSubscription.ashx?u=' + userId + '&s=' + subscriberId;
    AjaxCall(url, onAddSubscriber);
}
/*********************************************************************/
function onAddSubscriber() {
    var d = document.getElementById("divSubscriberMsg");
    d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                if (rtext == '1')
                    d.innerHTML = "<font size='1' color='red'>Thank you for subscribing to My Feeds</font>";
                else
                    d.innerHTML = "<font size='1' color='red'>An error has occured, please try again later</font>";
            }
        }
    }
}
/*********************************************************************/

function deleteEvent(Id) {
    var msg = "Are you sure you would like to delete this Event?";
    if (confirm(msg)) {
        var url = "deleteEvent.ashx?eid=" + Id;
        AjaxCall(url, updateEventGrid);
    }
}
/*********************************************************************/
function updateEventGrid() {
    var d = document.getElementById("dEvent");
    d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
                window.location.href = window.location.href;
            }
        }
    }
}
/*********************************************************************/
function editEvent(Id) {
    window.location.href = "events.aspx?m=e&i=" + Id;
    //document.getElementById("<%=hMode.ClientID %>").value = Id;
    //alert(document.getElementById("<%=hMode.ClientID %>").value);
    //document.forms[0].submit();
}

/*********************************************************************/
function getUserEvents(cid, pid) {
    var url = "getUserEvents.ashx?i=" + cid + "&p=" + pid;
    AjaxCall(url, onUserEvents);
}
/*********************************************************************/
function onUserEvents() {
    var d = document.getElementById("dEventGrid");
    if (d != null) {
        d.style.display = "block";
    }
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                if (d != null)
                    d.innerHTML = rtext;
            }
        }
    }
}
/*********************************************************************/
function getGallery(Id) {
    var url = "getGallery.ashx?gid=" + Id;
    AjaxCall(url, onLoadGallery);
}
/*********************************************************************/
function onLoadGalleries() {
    var d = document.getElementById("divGalleries");
    if (d != null)
        d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
            }
        }
    }
}

function onLoadGallery() {
    var d = document.getElementById("divGalleryPreview");
    if (d != null)
        d.style.display = "block";

    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
            }
        }
    }
}


/*********************************************************************/
function galleries(pageId, type) {

    var url = "getGalleries.ashx?pageId=" + pageId + "&type=" + type;
    AjaxCall(url, onLoadGalleries);
}


function TrackHits(module, item, languageId) {
   
    var url = "/logHits.ashx?m=" + module + "&i=" + item + "&li="+languageId;
    AjaxCallNoCallBack(url);
}

/*********************************************************************/
function deleteGallery(Id) {
    var msg = "Are you sure you would like to delete this Gallery?";
    if (confirm(msg)) {
        var url = "deleteGallery.ashx?gid=" + Id;
        AjaxCall(url, updateGalleryGrid);
    }
}
/*********************************************************************/
function updateGalleryGrid() {
    var d = document.getElementById("dGallery");
    d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
                window.location.href = window.location.href;
            }
        }
    }
}
/*********************************************************************/
function getVideoDetails(id) {
    var url = "getVideo.ashx?vid=" + id;
    AjaxCall(url, updateVideoPreview);

}
/*********************************************************************/
function updateVideoPreview() {
    var d = document.getElementById("divVideoPreview");
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
            }
        }
    }
}
/*********************************************************************/
function validateVideo() {

    if (document.getElementById("<%=txtVideoTitle.ClientID %>").value == "") {
        alert("Please enter video title");
        return false;
    }
    if (document.getElementById("<%=txtVideoDescription.ClientID %>").value == "") {
        alert("Please enter video description");
        return false;
    }
    if (document.getElementById("<%=txtVideoEmbedCode.ClientID %>").value == "") {
        alert("Please enter EmbedCode for this video");
        return false;
    }
    return true;
}
/*********************************************************************/
function deleteVideo(Id) {
    var msg = "Are you sure you would like to delete this Video?";
    var ans = confirm(msg);
    if (ans) {
        var url = "/community/deleteVideo.ashx?vid=" + Id;
        AjaxCallNoCallBack(url);
    }
    else
        return 'c';
}
function deleteGroupVideo(Id) {
    var msg = "Are you sure you would like to delete this Video?";
    var ans = confirm(msg);
    if (ans) {
        var url = "/community/group/deleteGroupVideo.ashx?vid=" + Id;
        AjaxCallNoCallBack(url);
    }
    else
        return 'c';
}
function deletePost(Id, returnUrl) {
    var ans = confirm("Are you sure you want to delete this Post?");
    if (ans) {
        var url = "/community/blog/deletePost.ashx?pid=" + Id;
        AjaxCallNoCallBack(url);
        document.location.href = returnUrl;
    }
    else
        return;

}
/*********************************************************************/

//function clearVideoForm()
//{
//    alert('calling');
//    alert(document.getElementById('<%= txtVideoTitle.ClientID %>'));
//    alert(document.getElementById('<%= txtVideoDescription.ClientID %>'));
//    alert(document.getElementById('<%= txtVideoEmbedCode.ClientID %>'));
//    return true;
//}

/*********************************************************************/
function updateVideoGrid() {
    var d = document.getElementById("dVideo");
    if (d != null)
        d.style.display = "block";
    if (req.readyState == 4) {
        if (req.status == 200) {
            var rtext = req.responseText;
            if (rtext != "") {
                d.innerHTML = rtext;
                window.location.href = window.location.href;
            }
        }
    }
}
/*********************************************************************/
/*
<!-- Dynamic Version by: Nannette Thacker -->
<!-- http://www.shiningstar.net -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
*/
function textCounter(field, cntfield, maxlimit) {
    if (field.value.length > maxlimit) // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
    // otherwise, update "characters left" counter
    else
        cntfield.value = maxlimit - field.value.length;
}
//  End -->
/*******************************************************************************/

function cascadeVisibility(panelId, hpanelId, val) {
    var pnl = document.getElementById(panelId);
    var hpnl = document.getElementById(hpanelId);

    if (val) {
        pnl.style.display = 'block';
        hpnl.style.display = 'none';
    }
    else {
        pnl.style.display = 'none';
        hpnl.style.display = 'block';
    }
}

var toggle = false;
function hidediv() {
    if (toggle) {
        var t = document.getElementById("hideme");
        t.style.display = "none";
        toggle = false;
    }
    else {
        var t = document.getElementById("hideme");
        t.style.display = "block";
        toggle = true;

    }
}
// replica of hidediv function for teamelite extranet
var toggle = false;
function hideTEdiv() {
    if (toggle) {
        var t = document.getElementById("hideSubMenu");
        t.style.display = "none";
        toggle = false;
    }
    else {
        var t = document.getElementById("hideSubMenu");
        t.style.display = "block";
        toggle = true;

    }
}
function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

// Comma separated list of images to rotate 
var imgs = new Array('/images/homepage/image_billboard_ski.jpg', '/images/homepage/image_billboard_soccer.jpg', '/images/homepage/image_billboard_surf.jpg', '/images/homepage/image_billboard_tri.jpg');
// delay in milliseconds between image swaps 1000 = 1 second 
var delay = 5000;
var counter = 0;

function preloadImgs() {
    for (var i = 0; i < imgs.length; i++) {
        MM_preloadImages(imgs[i]);
    }
}

function randomImages() {
    if (counter == (imgs.length)) {
        counter = 0;
    }
    MM_swapImage('rotator', '', imgs[counter++]);
    setTimeout('randomImages()', delay);
}


function openGoogleMap(url) {
    window.open(url);
}


function categories(mode) {
    if (mode == 1) {
        for (var i = 15; i < 45; i++) {
            document.getElementById('cat_list').style.height = i + 'px';
        }
    }
    if (mode == 0) {
        for (var i = 45; i > 15; i--) {
            document.getElementById('cat_list').style.height = i + 'px';
        }
    }
    return false;
}
//function preloadImages() {
//    preload_image_object = new Image();
//    // set image url
//    image_url = new Array();
//    image_url[0] = "/images/grass/bg_tile2.jpg";
//    image_url[1] = "/images/asphalt/bg_tile1.jpg";
//    image_url[2] = "/images/ocean/bg_tile3.jpg";
//    image_url[3] = "/images/wood/bg_tile4.jpg";

//    var i = 0;
//    for (i = 0; i <= 3; i++)
//        preload_image_object.src = image_url[i];
//}
function changeBG(pattern, headerPattern) {
//pattern = 'http://www.powerbar.com' + pattern;
    var path = 'url(' + pattern + '.jpg)';
  
    document.getElementsByTagName('body')[0].style.backgroundImage =path;
   //alert(document.getElementsByTagName('body')[0].style.backgroundImage );
     //document.getElementsByTagName('body')[0].style.backgroundImage =path;
    var headerPath = '';
    //      if (headerPattern != null)
    //      {
    //        headerPath = changeHeader (headerPattern);
    //      }
    createCookie("UserBackgroundSelection", path + ':' + 'url(' + headerPattern + '.jpg)', 49);
    
    return false;
     // save selection

}

function changeBGOld(pattern, headerPattern) {
 //pattern = 'http://www.powerbar.com' + pattern;
    var path = 'url(' + pattern + '.jpg)';
    document.getElementsByTagName('body')[0].style.backgroundImage = path;
   
    //document.getElementsByTagName('body')[0].style.backgroundImage = path;
    //  document.getElementById ('top').style.backgroundImage = path;
    var headerPath = '';
    //      if (headerPattern != null)
    //      {
    //       // headerPath = changeHeader (headerPattern);
    //      }
    createCookie("UserBackgroundSelection", path + ':' + headerPath, 49); // save selection
  return false;
}


function changeHeader(pattern) {
    var path = 'url(' + pattern + '.jpg)';
    var behindTop = document.getElementById('behind-top');
    behindTop.style.backgroundImage = path;
    return path;
}


function createCookie(name, value, days) {
    if (days) {

        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else
        expires = "";

    document.cookie = name + "=" + value + expires + "; path=/";
    //document.cookie = value+expires+"; path=/";
}


function readCookie(name) {
    if (document.cookie.length > 0) {
        var ca = document.cookie.split(';');
        var nameEQ = name + "=";
        var bg = '';
        for (var i = 0; i < ca.length; i++) {
            var s = ca[i];
            while (s.charAt(0) == ' ') s = s.substring(1, s.length);
            if (s.indexOf(nameEQ) == 0)
                bg = s.substring(nameEQ.length, s.length);
        }

        if (bg != '') {
            document.getElementsByTagName('body')[0].style.backgroundImage = bg;
            //            var topdiv = document.getElementById ('top');
            //            topdiv.style.backgroundImage = bg;    
        }
    }
    return;
}

function setClass(itemName) {
    var i;
    for (i = 1; i < 6; i++) {
        document.getElementById("li" + i).className = "off";
    }
    document.getElementById(itemName).className = "on";
}

function showSport() {
    if (document.getElementById('ddlSports').selectedIndex > 0) {
        var ddl = document.getElementById('ddlSports');
        var url = '/sport/' + ddl.options[ddl.selectedIndex].value;
        url += '/' + ddl.options[ddl.selectedIndex].text;
        var u = url.replace(/\s/g, '_') + '.aspx';
        window.location.href = u;
    }

}
//-----------------------------------Gloabal c2Max Popup-------------------------//

function OpenC2MaxPopup() {
    window.open('/products/C2Max/C2MaxMovie.aspx', 'C2Max', 'menubar=0,resizable=0,width=750,height=470,left=300,top=300');
}
//-----------------------------------End c2Max Popup-------------------------//

//----------------------------------- open bumper -------------------------------------//
function openBumperShopNow(url) {
    var width = 600;
    var height = 475;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    //var f = 'height='+ height+',width='+width+',directories=no,toolbar=no,top='+top+',screenX='+ left+',screenY='+ top;
    var f = 'height=' + height + ',width=' + width + ',directories=no,resizable=yes,toolbar=no,top=' + top + ',left=' + left + ',top=' + top;
    window.open('/leave.aspx?url=' + url, 'bumper', f);
}
//-----------------------------------Canada Popup -------------------------------------//

function openBumperShopNowCanada(url) {
    var width = 600;
    var height = 475;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    //var f = 'height='+ height+',width='+width+',directories=no,toolbar=no,top='+top+',screenX='+ left+',screenY='+ top;
    var f = 'height=' + height + ',width=' + width + ',directories=no,resizable=yes,toolbar=no,top=' + top + ',left=' + left + ',top=' + top;
    window.open('/Canadaleave.aspx?url=' + url, 'bumper', f);
}


//---------------------------------------------------
//German Popup
function openModalPage() {
    var width = 500;
    var height = 280;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    //var f = 'height='+ height+',width='+width+',directories=no,toolbar=no,top='+top+',screenX='+ left+',screenY='+ top;    
    var f = 'height=' + height + ',width=' + width + ',directories=no,toolbar=no,top=' + top + ',left=' + left + ',top=' + top;
    window.open('/ModalPopup/popup.aspx', 'europebumper', f);
}
function PopupCenter(pageURL, title, w, h) {
    var left = (screen.width / 2) - (w / 2);
    var top = (screen.height / 2) - (h / 2);
    var targetWin = window.open(pageURL, 'TermsAndConditions', 'toolbar=no, location=no, directories=no, status=no,menubar=no, scrollbars=1, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
} 