﻿var ExampleWindow = null;

function RunExample(exampleId) {
    if (ExampleWindow == null || ExampleWindow.closed)
        ExampleWindow = window.open(RunnerUrl + exampleId + "/");
}
function DownloadExample(projectId) {
	if((projectId == null) || (projectId == "")) return;
	document.location = "GetExample.ashx?projectId=" + projectId;
}

function GetProjectParameters(cmbSolution, cmbLanguage) {
	var selectedSolution = cmbSolution.GetSelectedItem();
	var selectedLanguage = cmbLanguage.GetSelectedItem();
	return "Solution=" + selectedSolution.value + ";" + "Language=" + selectedLanguage.value;
}

function SetExampleRunnerWarningShownCookie() {
	var date = new Date();
	date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
	ASPxClientUtils.SetCookie("ExampleRunnerWarningShown", "true", date);
}
function IsExampleRunnerWarningShown() {
    return ASPxClientUtils.GetCookie("ExampleRunnerWarningShown") == "true"
}
function DownloadOrNotify(buttonId, projectId) {
    if(!IsExampleRunnerWarningShown()) {
        popupDownload.ShowAtElementByID(buttonId);
        SetExampleRunnerWarningShownCookie();
    } else {
		DownloadExample(projectId);
    }
}

function DownloadExampleRunner(url) {
    var d = document.createElement('div');
    document.body.appendChild(d);
    d.style.display = 'none';

    d.innerHTML = '<iframe id="hiddenframe" name="hiddenframe" style="display: none; visibility: hidden;"></iframe>';
        
    var f = document.createElement('form');
    document.body.appendChild(f);
    f.style.display = 'none';
    f.method = 'get';
    f.action = url;
    f.enctype = 'multipart/form-data';
    f.target = 'hiddenframe';
    
    //workaround for Google Chrome
    f.onSubmit = '';
    
    f.submit();
}
function ShowExampleRunnerDescription(helpButton) {
	popupDownload.ShowAtElement(helpButton);
}

