function doMenuOverOut(objCell, isOver, strLeftRight){
    
    var strImage = "images/menu";
    
    if (strLeftRight == ""){
        if (isOver){
            strImage = strImage + "_bg_over.jpg";
        } else {
            strImage = strImage + "_bg.jpg";
        }
    } else {
        if (isOver){
            strImage = strImage + "_" + strLeftRight + "_over.jpg";
        } else {
            strImage = strImage + "_" + strLeftRight + ".jpg";
        }
    }
    
    objCell.style.backgroundImage = "url(" + strImage + ")";
}

function doBookmark(){
    var title = "Tradelink Footy Fever"; 
    var url = window.location.href;

    if (window.sidebar) { // Mozilla Firefox Bookmark		
        window.sidebar.addPanel(title, url,"");	
    } else if (window.external) { // IE Favorite		
        window.external.AddFavorite(url, title); 
    } else if(window.opera && window.print) { // Opera Hotlist		
        return true; 
    }
}

function createLinkForBookmark() { 
    var linkStyle = 'style = "text-decoration: none; font-weight: bold; color: #005AAB;"';

    if (window.external) {  
        document.write('<a ' + linkStyle + ' href="javascript:doBookmark()");">Click here to bookmark this page!</a>');   
    } else if (window.sidebar) {  
        document.write('<a ' + linkStyle + ' href="javascript:doBookmark()");">Click here to bookmark this page!</a>');  
    } else if (window.opera && window.print) {	   
        document.write('<a ' + linkStyle + ' href="javascript:doBookmark()");">Click here to bookmark this page!</a>'); 
    }
}

function switchCompetitions(toCompetition_id){
    document.getElementById('change_competition_id').value = toCompetition_id;
    document.getElementById('frmMain').submit();
}

function redirect(url){
    window.location = url;
}

function submitTips(tip_draw_allowed){
    
    // Check that user has completed all tips and margins, if applicable
    var tips = document.forms[0].game;
    
    // go through all games and ensure that user has tipped them
    var i = 0;
    while (i<tips.length){
        
        if (tip_draw_allowed){
            if (!tips[i].checked && !tips[i+1].checked && !tips[i+2].checked){
                alert("Please ensure you provide tips for all games then try again.\n\nNOTE: Your tips have NOT been saved.");
                return false;
            }
            i=i+3;
        } else {
            if (!tips[i].checked && !tips[i+1].checked){
                alert("Please ensure you provide tips for all games then try again.\n\nNOTE: Your tips have NOT been saved.");
                return false;
            }
            i=i+2;
        }
    }
    
    // check if margin has been tipped
    var margin_tips = document.getElementsByName("margin_tip[]");
    
    for (i=0; i<margin_tips.length; i++){
        if (margin_tips[i].value == ""){
            alert("You have not selected a margin for one or more games.");
            return false;
        }
    }
    
    // all correct - submit form
    document.getElementById("submit_tips").value = "true";
    document.forms[0].submit();
}

function randomTips(tip_draw_allowed){
    
    // confirm user wants to submit tips
    if (!confirm("This will submit random tips for this round.\n\nPlease press the OK button to continue...")){
        return false;
    }
    
    // Check that user has completed all tips and margins, if applicable
    var tips = document.forms[0].game;
    
    // Go through all games and ensure that user has tipped them
    var i = 0;
    while (i<tips.length){
        
        // pick number between 1 and 100
        var rand = Math.floor(Math.random()*101);
        
        // if draw tipping allowed then make tipping draw roughly a 5% chance
        if (tip_draw_allowed){
            
            if (rand <= 47){
                tips[i].checked = true;
            } else if (rand >= 48 && rand <= 95){
                tips[i+2].checked = true;
            } else if (rand > 95){
                tips[i+1].checked = true
            }
            
            i=i+3;
        } else {
            
            if (rand <= 50){
                tips[i].checked = true;
            } else if (rand > 50){
                tips[i+1].checked = true;
            }
            
            i=i+2;
        }
    }
    
    // check if margin has been tipped
    var margin_tips = document.getElementsByName("margin_tip[]");
    
    for (i=0; i<margin_tips.length; i++){
        
        // do random number-
        var rand = Math.floor(Math.random()*21);
        rand = rand - 1;
        
        if (rand < 0){
            rand = 0;
        }
        
        margin_tips[i].value = rand;
    }
    
    // all correct - submit form
    document.getElementById("submit_tips").value = "true";
    document.forms[0].submit();
}

function updateTipsNotSaved(){
    document.getElementById("not_saved").style.display = "";
}

function doLeaderboard(rank_type, list_all){
    document.getElementById("leaderboard").value = rank_type;
    document.getElementById("listall").value = list_all;
    document.getElementById("frmMain").submit();
}

function changePassword(){
    var current_password = document.getElementById("current_password").value;
    var new_password = document.getElementById("new_password").value;
    var new2_password = document.getElementById("new2_password").value;
    
    // check if filled in current password
    if (current_password == ""){
        alert("You have not entered your current password.\n\nThis is required in order to change to a new password");
        return;
    }
    
    // check if enterd a new password
    if (new_password == ""){
        alert("You must enter in a new password.");
        return;
    }
    
    // check if new and confirm match
    if (new_password != new2_password){
        alert("The new password has not been confirmed.\n\nPlease note that passwords are case sensitive");
        return;
    }
    
    // submit form
    document.getElementById("frmMain").submit();
}

function printTips(league_id, competition_id, round_id, user_id){
    var frm = document.getElementById("frmMain");
    
    document.getElementById("print_league_id").value = league_id;
    document.getElementById("print_competition_id").value = competition_id;
    document.getElementById("print_round_id").value = round_id;
    document.getElementById("print_user_id").value = user_id;
    
    win=window.open('','myWin','toolbars=0,width=450,height=580,left=100,top=100'); 
    frm.target='myWin';
    frm.action='print_tips.php';
    
    frm.submit();
    
    // reset action and target
    frm.action = "";
    frm.target = "";
}