<!-- Common Site JS -->

var g_form_modified = false;

function redraw (elm)
{
    elm.style.display="none";
    var redrawFix = elm.offsetHeight;
    elm.style.display="block";
}

function redrawById (elId)
{
    var elm = document.getElementById(elId);
    elm.style.display="none";
    var redrawFix = elm.offsetHeight;
    elm.style.display="block";
}

function simulateClick(elId) 
{
    var evt;
    var el = document.getElementById(elId);
    if (document.createEvent){
    evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
    }
    (evt)? el.dispatchEvent(evt):(el.click && el.click());
}

function SimulateMouseOver(elId)
{
    var elem = document.getElementById(elId);
    var evt = elem.ownerDocument.createEvent('MouseEvents');
    evt.initMouseEvent('mouseover',true,true,
        elem.ownerDocument.defaultView,0,0,0,0,0,
        false,false,false,false,0,null);
    var canceled = !elem.dispatchEvent(evt);
    if(canceled)
        alert('Event Cancelled');
}
    
function ShowPopup(hoveritem, popupname)
{
hp = document.getElementById(popupname);

// Set position of hover-over popup
hp.style.top = hoveritem.offsetTop + 18;
//hp.style.left = hoveritem.offsetLeft + 20;

// Set popup to visible
hp.style.visibility = "Visible";
}

function HidePopup(popupname)
{
hp = document.getElementById(popupname);
hp.style.visibility = "Hidden";
}

function PopupWindow( url )
{
	winParams='toolbar=no,status=no,resizable=yes,scrollbars=yes';	
	window.open( url, 2, winParams );
}

function DropDownChange(url)
{
	if (url != '')
	{
		window.location = url;
	}
}

function ConfirmSwitchProfileVisibility(userid, onoroff, urlExtend)
{
    var message = "You are about to switch " + onoroff + " the profile visibility.  Type the word SWITCH to confirm.";
    var def = "";
    var rv = prompt(message,def);

    if ( rv.toLowerCase() == 'switch' )
    {
       window.location = '/findplayer/playerprofile.php?switchvis=1&uid=' + userid + urlExtend;
    }
}

function ConfirmDeleteClub(clubid, name, urlExtend)
{
    var message = "You are about to delete " + name + ".  Type the word DELETE to confirm.";
    var def = "";
    var rv = prompt(message,def);

    if ( rv.toLowerCase() == 'delete' )
    {
       window.location = '/findcourt/deleteclub.php?clubid=' + clubid + urlExtend;
       //window.location = '/sup/admin/courts/courtstobeupdated.php?type=2';
    }
}

function ConfirmDeleteResult(resultid)
{
    var message = "Please confirm that you wish to remove this result by typing the word DELETE in the box below.";
    var def = "";
    var rv = prompt(message,def);

    if ( rv.toLowerCase() == 'delete' )
    {
       window.location = '/results/results.php?deleteresultid=' + resultid;
    }    
}

function ConfirmLeaveCompetition(competitionid)
{
    var message = "Please confirm that you wish to leave this competition.";

    if (confirm(message) == true)
    {
       window.location = '/leagues/leagues.php?action=remove&competitionid=' + competitionid;
    }
}

function ConfirmRemoveFromCompetition(userid, competitionid, areaid, sex, seasonid)
{
    var message = "Please confirm that you wish to remove this player from this competition.";

    if (confirm(message) == true)
    {
       window.location = '/sup/admin/leagues/adminleagues.php?removefromcompetitionid=' + competitionid + '&removeuserid=' + userid + '&seasonid=' + seasonid + '&areaid=' + areaid + '&sex=' + sex;
    }
}

function ToggleBlock(elementId)
{
	var element = document.getElementById( elementId )
	if( element.style.display == "block" )
	{
		element.style.display = "none";
		element.style.position = "relative";
	}
	else
	{
		element.style.display = "block";
		element.style.position = "relative";
	}
}

function EnableBlock(elementId)
{
	var element = document.getElementById( elementId )
	element.style.display = "block";
	element.style.position = "relative";
}

function DisableBlock(elementId)
{
	var element = document.getElementById( elementId )
	element.style.display = "none";
	element.style.position = "relative";
}

function HideBlock(elementId)
{
	var element = document.getElementById( elementId )
	element.style.visibility = "hidden";
	element.style.position = "relative";
}

function ShowBlock(elementId)
{
	var element = document.getElementById( elementId )
	element.style.visibility = "visible";
	element.style.position = "relative";
}

function FormModified()
{
	g_form_modified = true;
}

function UpdateCourtsBoxByType(type, linkId)
{
    document.getElementById( linkId ).style.color = "#FFFFFF";
    document.getElementById( 'Courts_All' ).style.color = "#000000";
    document.getElementById( 'Courts_Free' ).style.color = "#000000";
    document.getElementById( 'Courts_Pay' ).style.color = "#000000";
    document.getElementById( 'Courts_Clubs' ).style.color = "#000000";
    //document.getElementById( 'Courts_Popular' ).style.color = "#000000";
    document.getElementById( linkId ).style.color = "#FFFFFF";

    //titleOrig = document.getElementById( 'courtsconsole_TitleBar' ).innerHTML;
    //document.getElementById( 'courtsconsole_TitleBar' ).innerHTML = '<img src="/img/ajax/ajax-bar.gif">';
    
    for (i=1; i<=600; i++)
    {
        e = document.getElementById('green_' + i);
        f = document.getElementById('green_' + i + '_Popup');
        if (e) 
        {
            if (type == 'A' || type == 'F') e.style.visibility = "visible"; else e.style.visibility = "hidden";
            if (type == 'A' || type == 'F') f.style.visibility = "inherit"; else f.style.visibility = "hidden";
        }
        e = document.getElementById('yellow_' + i);
        f = document.getElementById('yellow_' + i + '_Popup');
        if (e) 
        {
            if (type == 'A' || type == 'P') e.style.visibility = "visible"; else e.style.visibility = "hidden";
            if (type == 'A' || type == 'P') f.style.visibility = "inherit"; else f.style.visibility = "hidden";
        }
        e = document.getElementById('grey_' + i);
        f = document.getElementById('grey_' + i + '_Popup');
        if (e) 
        {
            if (type == 'A' || type == 'C') e.style.visibility = "visible"; else e.style.visibility = "hidden";
            if (type == 'A' || type == 'C') f.style.visibility = "inherit"; else f.style.visibility = "hidden";
        }
    }

//    document.getElementById( 'courtsconsole_TitleBar' ).innerHTML = titleOrig;
}

function getInternetExplorerVersion() {
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}


function PopPlayerInfo( ev, playerId, offSetXParam, offSetYParam )
{
    var offSetX = offSetXParam;
    var offSetY = offSetYParam;
    var popWinId = 'xgamesummary' +  Math.floor(Math.random()*99999)
    var popWin = new CPopWin( ev, popWinId, 490, true, offSetX, offSetY );    
    url =  '/xml/xmenu/playerinfo.php?id=' + playerId;    
    popWin.Launch( 'Player Details', url );
}

function PopUserProfile( ev, userId, offSetXParam, offSetYParam, isNewWindow )
{
    $("#dialog_ltplayerprofile").dialog( {autoOpen: false, width: 510, height: 575} ); 
    $("#dialog_ltplayerprofile").html
    (
        "<img src='/img/ajax/ajax-bar.gif' alt='loading...' />"  
    ).load
    (
        "/findplayer/dialog/dialog_playerprofile.php", {userid: userId}, OpenPlayerProfileDialog()
    ); 
}

function OpenPlayerProfileDialog()
{
    $('#dialog_ltplayerprofile').dialog('option', 'show', 'blind');
    $('#dialog_ltplayerprofile').dialog('option', 'hide', 'blind');
    $('#dialog_ltplayerprofile').dialog('option', 'title', 'Player Profile');
    $("#dialog_ltplayerprofile").dialog("open");
}

function PopUserProfile_Old( ev, userId, offSetXParam, offSetYParam, isNewWindow )
{
    var popX = document.getElementById('popx').value;
    var popY = document.getElementById('popy').value;
    var newPopX = offSetXParam + parseInt(popX);
    var newPopY = offSetYParam + parseInt(popY);
    var offSetX = newPopX;
    var offSetY = newPopY;
    var popWinId = 'xgamesummary' +  Math.floor(Math.random()*99999)
    var popWin = new CPopWin( ev, popWinId, 490, true, offSetX, offSetY );
    url =  '/xml/xmenu/userprofile.php?userid=' + userId + '&nw=' + isNewWindow;    
    popWin.Launch( 'Player Profile', url );
    if (newPopX > 50)
    {
        document.getElementById('popx').value = 0;
        document.getElementById('popy').value = 0;
    }
    else
    {
        document.getElementById('popx').value = newPopX + 15;
        document.getElementById('popy').value = newPopY + 15;
    }
}

function PopLeagueMatch( ev, player1Id, player2Id, leagueId, division, sexForLeague, offSetXParam, offSetYParam, isNewWindow )
{
    var popX = document.getElementById('popx').value;
    var popY = document.getElementById('popy').value;
    var newPopX = offSetXParam + parseInt(popX);
    var newPopY = offSetYParam + parseInt(popY);
    var offSetX = newPopX;
    var offSetY = newPopY;
    var popWinId = 'xgamesummary' +  Math.floor(Math.random()*99999)
    var popWin = new CPopWin( null, popWinId, 490, true, offSetX, offSetY );    
    url =  '/xml/xmenu/leaguematch.php?player1id=' + player1Id + '&player2id=' + player2Id + '&leagueid=' + leagueId + '&division=' + division + '&sexforleague=' + sexForLeague + '&nw=' + isNewWindow;
    popWin.Launch( 'League Match Details', url );
    if (newPopX > 50)
    {
        document.getElementById('popx').value = 0;
        document.getElementById('popy').value = 0;
    }
    else
    {
        document.getElementById('popx').value = newPopX + 15;
        document.getElementById('popy').value = newPopY + 15;
    }
}

function PopConjugation( ev, verbId, infinitive )
{
    var offSetX = 0;        
    var offSetY = 0;            
    var popWinId = 'xgamesummary' +  Math.floor(Math.random()*99999)
    var popWin = new CPopWin( ev, popWinId, 550, true, offSetX, offSetY );    
    url =  '/xml/xmenu/verbconjugation.php?verbid=' + verbId;    
    popWin.Launch( 'Verb Conjugation for ' + infinitive, url );
}

function PopProTourMatch( ev, playerId, opponentId, startDate, endDate, surfaceId, categoryId, tour, offSetXParam, offSetYParam, isNewWindow )
{
    var offSetX = offSetXParam || -348;        
    var offSetY = offSetYParam || -15;            
    offSetX = 0;
    offSetY = 0;    
    var popWinId = 'xgamesummary' +  Math.floor(Math.random()*99999)
    var popWin = new CPopWin( null, popWinId, 550, true, offSetX, offSetY );    
    //url =  '/xml/xmenu/playerinfo.php?id=' + userId;    
    url =  '/xml/xmenu/matches.php?pid=' + playerId + '&oid=' + opponentId + '&sd=' + startDate + '&ed=' + endDate + '&sid=' + surfaceId + '&cid=' + categoryId + '&t=' + tour;
    //alert(offSetX);
    popWin.Launch( 'Match List', url );
}

