//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ReloadWindow() {
    window.location.href = window.location.href;    
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function CloseWindow() {
    window.close();    
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenWindow(url, name, width, height) {
    OpenWindow(url, name, height, width, false);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenWindow(url, name, width, height, enableScrollbars) {
    OpenWindow(url, name, height, width, enableScrollbars, false);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenWindow(url, name, width, height, enableScrollbars, resizable) {
	if(navigator.appName.indexOf("WebTV")!=-1)
		window.location.href=url;
	else
	{
		winhandle=window.open(url, name, "width=" + width + ",height=" + height + ",scrollbars=" + GetWindowBoolString(enableScrollbars) + ",resizable=" + GetWindowBoolString(enableScrollbars) + ",status=no,menubar=no");
		winhandle.focus();
	}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function GetWindowBoolString(value) {
    if(value) 
        return "yes";
    else
        return "no";   
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function SetSelectOptions(select, selectedIndex, arrayText, arrayValues) {
    var text, value, option;
    if(select) {
        for(var i = 0; i < arrayText.length; i++) {
            value = "";
            text = arrayText[i];
            if(arrayValues) {
                if(i < arrayValues.length) {
                    value = arrayValues[i];
                }
            }
            if(value == "") {
                value = text;
            }
            option = new Option(text, value);
            if(i == selectedIndex) {
                option.selected = true;
            }
            select.options[i] = option;
        }
            
    }                    
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function ClearSelect(select) {
    if(select) {select.options.length = 0;}
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenRecruitProfile(id) {
    OpenWindow("../Crew/RecruitProfile.aspx?id=" + id, "recruitprofile" + id, 773, 550);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenCrewProfile(id) {
    OpenWindow("../Crew/CrewProfile.aspx?id=" + id, "crewprofile" + id, 773, 550, true);
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenSponsorProfile(id) {
    OpenWindow("../SCenter/SponsorProfile.aspx?id=" + id, "sponsorprofile" + id, 773, 550);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenRaceResultsWindow(RaceID,isTestRun,isCompiled) {
	if(isTestRun)
	{
		OpenWindow("../Schedule/PracticeResults.aspx?RaceID="+RaceID,"practiceresults"+RaceID,773,550,true);
	}
    else 
    {
		if(isCompiled)
		{
			OpenWindow("../Schedule/RaceResults.aspx?RaceID="+RaceID,"raceresults"+RaceID,773,550,true);
		}
		else OpenWindow("../Schedule/QualifyResults.aspx?RaceID="+RaceID,"qualifyresults"+RaceID,773,550,true);
    } 
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenRacePBPWindow(RaceID,TeamID,Qualify) {
	if (Qualify == 0) {
		OpenWindow("../Schedule/RacePBP.aspx?RaceID="+RaceID+"&TeamID="+TeamID,"racepbp"+RaceID,773,550,true);
	} else {
		OpenWindow("../Schedule/RacePBP.aspx?section=results&RaceID="+RaceID+"&TeamID="+TeamID,"racepbp"+RaceID,773,550,true);
	}
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenRunSettingsWindow(RaceID) {
	OpenWindow("../Schedule/SavedSettings.aspx?RID="+RaceID,"racepbp"+RaceID,518,530,true);
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenTeamProfileWindow(TeamID) {
	OpenWindow("../Main/TeamProfile.aspx?TeamID="+TeamID,"TeamProfile"+TeamID,773,550,true);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenOwnerProfileWindow(UID) {
	OpenWindow("../Main/OwnerProfile.aspx?UID="+UID,"OwnerProfile"+UID,773,550,true);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenTeamEditorWindow(TeamID) {
	OpenWindow("../Main/ChangeTeamName.aspx","TeamEditor"+TeamID,773,550,false);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenRaceProfileWindow(RaceID) {
	OpenWindow("../Schedule/ScheduledTrackInfo.aspx?RID="+RaceID,"RaceProfile"+RaceID,773,550,false);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenFinancialLedgerWindow() {
	OpenWindow("../Office/FinancialLedger.aspx","FinancialLedger",773,550,true);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenCreditsWindow() {
	OpenWindow("../Main/Credits.aspx","CRDCredits",498,155,false);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function OpenPartHistoryWindow(PartType, PartID) {
	OpenWindow("../Office/Garage_PartHistory.aspx?pt="+PartType + "&pid="+PartID,"PartHistoryProfile"+PartID,773,550,true);
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
function FixIEObjects() {
	objects = document.getElementsByTagName("object");
	for (var i = 0; i < objects.length; i++)
	{
		objects[i].outerHTML = objects[i].outerHTML;
	}
}

function ReloadWorldOverviewPage(WorldDD, RegionDD, AllTimeType, AllTimeView)
{
	window.location = 'WorldOverview.aspx?wid='+ document.getElementById(WorldDD).value + '&r='+ document.getElementById(RegionDD).value + '&t=' + document.getElementById(AllTimeType).value + '&v=' + document.getElementById(AllTimeView).value;
}
