function addgamepop(id,list) {
    popupWin = window.open('/pages/profile/add_game.php?pid=' + id + '&list=' + list, 'trackpop', 'width=260,height=440,resizable=1,scrollbars=0');
}

function track_contact(contact_username, mode, force_reload ) {
    if('undefined' == typeof force_reload) {force_reload = true;}
    addcontactpop( contact_username, mode );

    if ( force_reload ) {
        // reload the current page with the updated data.
        window.location.reload( force_reload );
    }
}

function track_union(union_id, mode, force_reload  ) {
    popupWin = window.open('/pages/profile/track_union.php?mode=' + mode + '&union_id=' + union_id, 'uniontrackpop', 'width=260,height=260,resizable=1,scrollbars=0');

    if('undefined' == typeof force_reload) {force_reload = true;}
    if ( force_reload ) {
        // reload the current page with the updated data.
        window.location.reload( force_reload );
    }
}

function addcontactpop(contact_username,mode) {
  popupWin = window.open('/pages/profile/track_contact.php?mode=' + mode + '&username=' + contact_username, 'contactpop', 'width=260,height=260,resizable=1,scrollbars=0');
}

function videoplayerpop(sid,pid,rgroup) {
  rgroup = rgroup ? '&rgroup=' + rgroup : '';
  popupWin = window.open('/pages/video_player/popup.php?sid=' + sid + '&pid=' + pid + rgroup, 'videoplayerpop', 'width=810,height=700,resizable=1,scrollbars=0');
  popupWin.focus();
}

function boxshotpop(pid) {
  popupWin = window.open('/pages/image_viewer/boxshot.php?pid=' + pid, 'boxshotpop', 'width=640,height=910,resizable=1,scrollbars=1');
  popupWin.focus();
}

function pollPop() {
  pollwin = window.open('/pages/modules/poll.php','pollwin','height=500,width=400');
  pollwin.focus();
}

function chatpop(chatroom) {
  popupWin = window.open('/chat/chat.php?room='+chatroom,'chatpop','width=620,height=420,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=1');
}

function tourntvpop(tourn,rgroup) {
  window.location = 'http://www.gamespot.com/tournaments/'+tourn+'/tv.php';
  popupWin = window.open('/pages/gamecenter/tournaments/video_player/popup.php?id=' + tourn + '&rgroup=' + rgroup, 'tourntvplayerpop', 'width=810,height=700,resizable=1,scrollbars=0');
  popupWin.focus();
}

function onthespotpop(rgroup) {
  popupWin = window.open('/pages/features/onthespot/video_player/popup.php?rgroup=' + rgroup, 'onthespotplayerpop', 'width=867,height=800,resizable=0,scrollbars=1');
  popupWin.focus();
}

function eventPopup(event) {
  popupWin = window.open('/pages/event_popup/index.php?event=' + event, 'eventPopup_'+event, 'width=800,height=800,resizable=1,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,');
  popupWin.focus();
}


function livereviewpop(rgroup) {
  popupWin = window.open('/pages/video_player/popup_special.php?rgroup=' + rgroup, 'livereviewpop', 'width=867,height=840,resizable=0,scrollbars=1');
  popupWin.focus();
}

function prefspop(tab) {
  popupWin = window.open('/pages/preferences/' + tab + '.php','prefspop','width=778,height=480,scrollbars=1,menubar=0,toolbar=0,location=0,status=0,resizable=1');
}

function pmpop(tab,user) {
  popupWin = window.open('/pages/pm/' + tab + '.php?to=' + user,'pmpop','width=778,height=480,scrollbars=1,menubar=0,toolbar=0,location=0,status=0,resizable=1');
}

function emblempop(id) {
  popupWin = window.open('/pages/profile/show_emblem.php?id=' + id,'emblempop','width=330,height=360,scrollbars=auto,menubar=0,toolbar=0,location=0,status=0,resizable=1');
  popupWin.focus();
}

function open_image_viewer(pid,img,sid,path,caption,numimg) {
    var page = '/pages/image_viewer/frame_lead.php?pid=' + pid + '&img=' + img + '&sid=' + sid;
    if(path) {
        page += '&path=' + path;
    }
    if(caption) {
        page += '&caption=' + caption;
    }
    if(numimg) {
        page += '&numimg=' + numimg;
    }

    x = window.open(page, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=800,height=600,left=0,top=0');

}

function open_image_viewer_for_feature(pid,img,sid,path,caption,single) {
    var page = '/pages/image_viewer/frame.php?pid=' + pid + '&img=' + img + '&sid=' + sid;
    if(path) {
        page += '&path=' + path;
    }
    if(caption) {
        page += '&caption=' + caption;
    }
    if(single) {
    	page += '&single=1';
    }

    x = window.open(page, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=800,height=600,left=0,top=0');

}

function open_image_viewer_for_path_gallery(img,numimg,path,caption) {
    var page = '/pages/image_viewer/frame.php?img=' + img + '&numimg=' + numimg + '&path=' + path;
    if(caption) {
        page += '&caption=' + caption;
    }

    x = window.open(page, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=800,height=600,left=0,top=0');

}

function genpop(url,name,width,height,resize,scroll) {
    popupWin = window.open(url, name,'width='+width+',height='+height+',resizable='+resize+',scrollbars='+scroll+',location=0,menubar=0,statusbar=0,toolbar=0');
}



// use this instead of body.onload (see below for usage)

function addEvent(obj, evType, fn, useCapture){
    if (obj.addEventListener){
        obj.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    }
    else {
        alert("Handler could not be attached");
    }
}

// resize forum images

function resize_forum_images() {
    divs = document.getElementsByTagName("div");
    for (i=0; i < divs.length; i++) {
        if (divs[i].className == 'message') {
//            alert('message ' + i);
//            pop.document.write('starting new message<br>');
            child = divs[i].childNodes;
            for (j=0; j < child.length; j++) {
//                pop.document.write(child[j].nodeName + '<br>');
                if (child[j].nodeName.toLowerCase() == 'img' && child[j].width > 600) {
                    child[j].width = 600;
                }
            }
        }
    }
}

//Begin Iframe Auto Resize

var iframeids=["most_popular"]
var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=getFFVersion>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function dyniframesize() {
    var dyniframe=new Array()
    for (i=0; i<iframeids.length; i++) {
        if (document.getElementById) { //begin resizing iframe procedure
            dyniframe[dyniframe.length] = document.getElementById(iframeids[i]);
            if (dyniframe[i] && !window.opera) {
                dyniframe[i].style.display="block"
                if (dyniframe[i].contentDocument && dyniframe[i].contentDocument.body.offsetHeight) //ns6 syntax
                    dyniframe[i].height = dyniframe[i].contentDocument.body.offsetHeight+FFextraHeight;
                else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //ie5+ syntax
                dyniframe[i].height = dyniframe[i].Document.body.scrollHeight;
            }
        }
    }
}

addEvent(window, "load", dyniframesize);

// community piechart flipper

function show_piechart(x) {
    var a = new Array('score', 'curve', 'diff', 'time');
    for (i=0; i < a.length; i++) {
        if (a[i] == x) {
            document.getElementById('piechart_' + a[i]).style.display='';
            document.getElementById('piechart_span_' + a[i]).style.color='white';
        }
        else {
            document.getElementById('piechart_' + a[i]).style.display='none';
            document.getElementById('piechart_span_' + a[i]).style.color='';
        }
    }
}


// use: <img onerror="hide_broken_img(this)" src="http://broken.com/image.gif" />
function hide_broken_img(img) {
    img.src='http://img.gamespot.com/gamespot/shared/forum/user_icons/GameSpot/gamespot.gif';
}

function hide_broken_union_img(img) {
    img.src='http://img.gamespot.com/gamespot/shared/unions/union_icon.gif';
}

function embed(tag){
    // msoft activex controls no longer start up 'activated' after april 11/06 (require focus to activate)
    // workaround requires object/embed tags to be included in external js
    // hence this func... sb
    // note: if 'allow script debugging' is *not* checked in ie settings, you will still get the activiation prompt!
    document.write(tag);
}