function menuSelect(action)
{
document.menu.menuItem.value = action;
document.menu.submit();
}

function MainWindow(button)
{
main=window.open('./index.php', 'main'); 
main.focus();
}

function RedirectTo(location)
{
	if(location == undefined) { location="./index.php" }
    window.location=location;
}

function submitLogin(e)
{
	if (!e) e = window.event;
	if(e.keyCode == 13)
		{
		menuSelect("noauth_Login");
		}
}

function switch_thumb(id) {
    thumbholder = document.getElementById('vote_img_'+id);
    selected = document.getElementById('vote_box_'+id);
    thumbholder.src = "./images/thumbs/game"+selected.options[selected.selectedIndex].value+".jpg";
}

function expand_thumb(id) {
    selected = document.getElementById('vote_box_'+id);
    sel_id = selected.options[selected.selectedIndex].value;
    sel_text = selected.options[selected.selectedIndex].text;
    win_Create('', '', 'winDetailVote'+sel_id, sel_text+' Details', 100, 30, '', '', true, 'winDetailVote'+sel_id+'_Content');
}

var ie = document.all;
var nn6 = document.getElementById &&! document.all;

var isdrag = false;
var x, y;
var parent, current;
var topZ = 1;

function win_Create(e,bindTo,id,title, newWinx, newWiny, height, width, floating, contents) {
    if( document.getElementById(id) ) { return false; }
    ( bindTo != '') ? windowParent = document.getElementById(bindTo) : windowParent = document.body;
    parent = windowParent;
    newWindow = document.createElement('div');
    newWindow.style.zIndex = topZ;
    newWindow.id = id;
    (newWinx == '') ? newWindow.style.left = ((parent.offsetWidth - width)/2)+"px" : newWindow.style.left = newWinx+"px";
    (newWiny == '') ? newWindow.style.top = ((parent.offsetHeight - height)/2)+"px" : newWindow.style.top = newWiny+"px";
    if(width != '') { newWindow.style.width = width+"px"; }
    if(height != '') { newWindow.style.height = height+"px"; } 
    newWindow.style.border = "1px solid black";
    newWindow.style.background = "gray";
    newWindow.style.position = "absolute";
    newWindow.onmousedown = win_Select;
    windowParent.appendChild(newWindow);
    
    newTitleBar = document.createElement('div');
    newTitleBar.id = id+"_title_bar";
    newTitleBar.style.zIndex = 1;
    newTitleBar.style.position = "static";
    newTitleBar.style.top = "0px";
    newTitleBar.style.width = width+"px";
    newTitleBar.style.height = "18px";
    newTitleBar.style.font = "12px Arial";
    newTitleBar.style.borderBottom = "1px solid black";
    newTitleBar.style.background = "white";
    newWindow.appendChild(newTitleBar);
    
    newTitleText = document.createElement('div');
    newTitleText.id = id+"_title_text";
    newTitleText.style.position = "absolute";
    newTitleText.style.top = "2px";
    newTitleText.style.left = "5px";
    newTitleText.style.cursor = "default";
    newTitleBar.appendChild(newTitleText);
    newTitleTextContents = document.createTextNode(title);
    newTitleText.appendChild(newTitleTextContents);
    
    newWinClose = document.createElement('div');
    newWinClose.id = id+"_close";
    newWinClose.style.zIndex = 2;
    newWinClose.style.position = "absolute";
    newWinClose.style.right = "1px";
    newWinClose.style.top = "1px";
    newWinClose.style.height = "18px";
    newWinClose.style.width = "18px";
    newWinClose.style.cursor = "pointer";
    newWindow.appendChild(newWinClose);
    
    newWinCloseImg = document.createElement('img');
    newWinCloseImg.id = id+"_close_img";
    newWinCloseImg.src = "./images/red_left.gif";
    newWinClose.appendChild(newWinCloseImg);
    
    newWinContentFrame = document.createElement('div');
    newWinContentFrame.id = id+"_content_frame";
    newWinContentFrame.style.position = "static";
    newWinContentFrame.style.height = "100%";
    newWinContentFrame.style.width = "100%";
    newWindow.appendChild(newWinContentFrame);
    
    newContentOriginal = document.getElementById(contents);
    newContent = newContentOriginal.cloneNode(true);
    newContent.style.display = "block";
    newWinContentFrame.appendChild(newContent);
    
    delete newWindow;
    delete newTitleBar;
    delete newTitleText;
    delete newWinClose;
    delete newWinCloseImg;
}

function win_Update(e) {
    if( isdrag ) {
        nn6 ? cursorXCurrent = "e.clientX" : cursorXCurrent = "event.clientX";
        nn6 ? cursorYCurrent = "e.clientY" : cursorYCurrent = "event.clientY";
        curLeft = parseInt(current.offsetLeft);
        curWidth = parseInt(current.offsetWidth);
        curTop = parseInt(current.offsetTop);
        curHeight = parseInt(current.offsetHeight);
        parLeft = parseInt(parent.offsetLeft);
        parWidth = parseInt(parent.offsetWidth);
        parTop = parseInt(parent.offsetTop);
        parHeight = parseInt(parent.offsetHeight);
        cursorXOffset = x - tx;
        cursorYOffset = y - ty;
        
        if( eval(cursorXCurrent) - cursorXOffset > 0) { 
            if( (eval(cursorXCurrent) - cursorXOffset) + curWidth < parWidth) {
                tempX = eval(cursorXCurrent) - cursorXOffset;   
            }
            else {
                tempX = parWidth - curWidth;
            }
        }
        else {
            tempX = 0;
        }
        
        if( eval(cursorYCurrent) - cursorYOffset > 0) { 
            if( (eval(cursorYCurrent) - cursorYOffset) + curHeight < parHeight) {
                tempY = eval(cursorYCurrent) - cursorYOffset;   
            }
            else {
                tempY = parHeight - curHeight;
            }
        }
        else {
            tempY = 0;
        }
        
        current.style.left = String(tempX)+"px";
        current.style.top  = String(tempY)+"px";
       // if (eval(cursorXCurrent) < 1 || eval(cursorXCurrent) < 1 ) { isdrag = false; }
        return false;
    }
}

function win_Select(e) {
    var topelement = nn6 ? "HTML" : "BODY" ;
    current = nn6 ? e.target : event.srcElement;
    if(current.tagName != topelement) {
        //if( current.floating != 'true' ) { return false; }
        var objcmd = current.id.split('_');
        if( objcmd[1] == "close" ) {
            current = document.getElementById(objcmd[0]); 
            current.parentNode.removeChild(current);
            return false;
        }
        if ( objcmd[1] == "title" ) {
            current = document.getElementById(objcmd[0]);
            isdrag = true;
            tx = parseInt(current.style.left);
            ty = parseInt(current.style.top);
            y = nn6 ? e.clientY : event.clientY;
            x = nn6 ? e.clientX : event.clientX;
            document.onmousemove=win_Update;
            
            current.style.zIndex = topZ;
            topZ++;
            
            if (e.preventDefault) {
                e.preventDefault();
            }
            else {
                document.onselectstart = function () { return false; };
                e.cancelBubble = true;
            }
            return false;
        }
        if (objcmd.length > 0 && objcmd[1] != '' ) {
            current = document.getElementById(objcmd[0]);
            current.style.zIndex = topZ;
            topZ++;
            return false;
        }
    }
}
document.onmouseup=new Function( "isdrag = false" ); 