var x = 400, y = 0;               // Window position and size
var dx = 5, dy = 10;              // Window velocity   
var interval = 100;              // Milliseconds between updates
var intervalID  = 0;
var win;
var ver=parseInt(navigator.appVersion);
var ie4=(ver>3  && navigator.appName!="Netscape")?1:0;
var ns4=(ver>3  && navigator.appName=="Netscape")?1:0;
var ns3=(ver==3 && navigator.appName=="Netscape")?1:0;

document.onmousedown=disableRightClick;
document.onmouseup=disableRightClick;

if(document.layers)
    window.captureEvents(Event.MOUSEDOWN);
if(document.layers)
    window.captureEvents(Event.MOUSEUP);

window.onmousedown=disableRightClick;
window.onmouseup=disableRightClick;
                
function popUp(winURL, width, height, resizable, scrollbars)
{
    if(winURL != '')
    {
        w = screen.width - 150
        h = screen.height - 150
        wleft = (screen.width - w) / 2;
        wtop = ((screen.height - h) / 2) - 50 ;
     
        window.open(winURL, "popup", "width=" + width + ", height=" + height + ", left=" + wleft + 
            ", top=" + wtop + ", location=no, menubar=no, status=no, toolbar=no, scrollbars=" + scrollbars + ", resizable=" + resizable); 
    }
    else
        alert("Access Denied");
}

function disableRightClick(e)
{
    var _strErrorMessage = "Sorry, right click has been disabled.";
    
    if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3))
    {
        alert(_strErrorMessage);
        return false;
    }
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3))
    {
        alert(_strErrorMessage);
        return false;
    }
    
    return true;
}

function openUpcomingGames()
{
    var left = parseInt((screen.availWidth/2) - (800/2));
    win = window.open("UpcomingGames.aspx", "UpcomingGamesWindow","width=750,left=" + left + ",top=0,height=360,scrollbars=no,statusbar=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,copyhistory=no;", true);
    window.setInterval('windowFlyIn(' + left + ')', interval);
}

function windowFlyIn(left)
{
    // If the user closed the window, stop the animation.
    // Create the window that we're going to move around.
    // The javascript: URL is simply a way to display a short document.
    // The final argument specifies the window size.

    if (win.closed)
    {
        clearInterval(intervalID);
        return;
    }
          
    // Bounce if we have reached the bottom or top edge.
    if ((y+dy > (screen.availHeight - 200)) || (y+dy < 0)) dy = -dy;

    if(y > 300)
    {
        clearInterval(intervalID);
        return;
    }
    else
        // Finally, move the window to the new position.
        win.moveTo(left,y);

    // Update the current position of the window.
    y += dy;
}
      
function loadBackgroundMusic(ImageFilePath, ImageCtrl, AudioFile, Culture)
{            
    var cookie = Get_Cookie("BackgroundMusic");
    var img = document.getElementById(ImageCtrl);
                         
    if(cookie == "Turn Music On")
        img.src = ImageFilePath + "Play.jpg";
    else
    {
        img.src = ImageFilePath + "Stop.jpg";
        playSound(AudioFile);
        Set_Cookie("BackgroundMusic", "Turn Music Off", true, "/");
    }

    setAudioToolTip(ImageCtrl, cookie, Culture);
}     
   
function toggleBackgroundMusic(ImageFilePath, ImageCtrl, AudioFile, Culture)
{
    var cookie = Get_Cookie("BackgroundMusic");
    var img = document.getElementById(ImageCtrl);
    var cookieValue;

    if(cookie == "Turn Music On")
    {
        playSound(AudioFile);
        img.src = ImageFilePath + "Stop.jpg";
        cookieValue = "Turn Music Off";
    }
    else
    {
        stopSound();
        img.src = ImageFilePath + "Play.jpg";
        cookieValue = "Turn Music On";
    }
    
    setAudioToolTip(ImageCtrl, cookieValue, Culture);
    
    var dteExpiryDate = new Date();
    dteExpiryDate.setTime(dteExpiryDate.getTime() + (24 * 60 * 60 * 1000));  //24 hrs
     
    Set_Cookie("BackgroundMusic", cookieValue, true, "/");
}  
 
function playSound(AudioFile)
{
    //All other browsers (Firefox, Opera and Safari, visibility:hidden hides embed object
    //and you still hear the music play. In Internet Explorer, you will not hear music play.

    var _embed = "<embed src='" + AudioFile + "' autostart='true', loop='true' hidden='true' wmode='transparent' type='audio/wav'";
    
    if(navigator.appName != "Microsoft Internet Explorer")
        _embed += " style='visibility:hidden;width:1px;height:1px'>";
        
    _embed += "</embed>";
    
    _spanAudioPlayer = document.getElementById("spanAudioPlayer");
    _spanAudioPlayer.innerHTML = _embed;
}

function stopSound()
{
    _spanAudioPlayer = document.getElementById("spanAudioPlayer");
    _spanAudioPlayer.innerHTML = "";
}
      
function setAudioToolTip(ImageCtrl, CookieValue, Culture)
{
    var img = document.getElementById(ImageCtrl);
    
    if(CookieValue == "Turn Music On")
    {
        switch(Culture)
        {
            case "en-US":
                img.title = "Play";
                break;
            case "fr-ca":
                img.title = "Jouer";
                break;
            default:
                img.title = "Play";
                break;              
        }
    }
    else
    {
        switch(Culture)
        {
            case "en-US":
                img.title = "Stop";
                break;
            case "fr-ca":
                img.title = "Arret";
                break;
            default:
                img.title = "Stop";
                break;              
        }
    }
}
      
function Get_Cookie( check_name ) {
    // first we'll split this cookie up into name/value pairs
    // note: document.cookie only returns name=value, not the other components
    var a_all_cookies = document.cookie.split( ';' );
    var a_temp_cookie = '';
    var cookie_name = '';
    var cookie_value = '';
    var b_cookie_found = false; // set boolean t/f default f
	
    for ( i = 0; i < a_all_cookies.length; i++ )
    {
        // now we'll split apart each name=value pair
        a_temp_cookie = a_all_cookies[i].split( '=' );

        // and trim left/right whitespace while we're at it
        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
        // if the extracted name matches passed check_name
        if ( cookie_name == check_name )
        {
	        b_cookie_found = true;
	        // we need to handle case where cookie has no value but exists (no = sign, that is):
	        if ( a_temp_cookie.length > 1 )
	        {
		        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
	        }
	        // note that in cases where cookie is initialized but no value, null is returned
	        return cookie_value;
	        break;
        }
        a_temp_cookie = null;
        cookie_name = '';
    }
    if ( !b_cookie_found ) 
    {
        return null;
    }
}

function Set_Cookie( name, value, expires, path, domain, secure ) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    // if the expires variable is set, make the correct expires time, the
    // current script below will set it for x number of days, to make it
    // for hours, delete * 24, for minutes, delete * 60 * 24
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    //alert( 'today ' + today.toGMTString() );// this is for testing purpose only
    var expires_date = new Date( today.getTime() + (expires) );
    //alert('expires ' + expires_date.toGMTString());// this is for testing purposes only
    
    document.cookie = name + "=" +escape( value ) +
        ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
        ( ( path ) ? ";path=" + path : "" ) + 
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}
function ChangeMap(iframeID, LeageTeamLocationID)
{ 
    var objFrame = document.getElementById(iframeID); 
    var objSelect = document.getElementById(LeageTeamLocationID);
    objFrame.src = objSelect.options[objSelect.selectedIndex].value;
}

function viewPlayerStatistics(OID_Season, OID_Program, OID_SkillLevel, OID_Category, OID_Player) 
{ 
    var win = window.open("../Public/PlayerStatistics.aspx?OID_Season=" + OID_Season + "&OID_Program=" + OID_Program + 
        "&OID_SkillLevel=" + OID_SkillLevel + "&OID_Category=" + OID_Category + "&OID_Player=" + OID_Player, "PlayerStats", "left=200,top=10,width=850,height=700,scrollbars=yes,statusbar=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,copyhistory=no;", true);
    
    win = null;
}

function viewTeamGamePlayerStatistics(OID_TeamGameSchedule) 
{ 
    var win = window.open("TeamGamePlayerStatistics.aspx?OID_TeamGameSchedule=" + OID_TeamGameSchedule, "TeamGamePlayerStatistics", "left=10,top=10,width=825,height=700,scrollbars=no,statusbar=no,locationbar=no,location=no,toolbar=no,status=no,menubar=no,copyhistory=no;", true);
    win = null;
}

function ltrim(str) {
  return str.replace(/^\s+/g, '');
}
function rtrim(str) {
  return str.replace(/\s+$/g, '');
}
function trim(str) {
  return str.replace(/^\s+|\s+$/g, '');
}
