
function SSTC_OpenWindow(windowUri, windowName, windowWidth, windowHeight) {
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;

    windowSettings = "width=" + windowWidth + ",height=" + windowHeight + ",left=" + centerWidth + ",top=" + centerHeight + ",status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1";

    newWindow = window.open(windowUri, windowName, windowSettings);
    newWindow.focus();

    //return newWindow.name;

}

function SSTC_WindowClose() {
    window.close();
    return false;
}

function SSTC_RefreshParent(ParentClientID) {

    if (opener == null || opener == 'undefined')
        return;

    _hidCommand = opener.document.getElementById(ParentClientID + "_hidCommand");
    _hidValue = opener.document.getElementById(ParentClientID + "_hidValue");
    _hidValueParams = opener.document.getElementById(ParentClientID + "_hidValueParams");
    _imgSubmit = opener.document.getElementById(ParentClientID + "_imgSubmit");

    if (_hidCommand != null && _hidCommand != 'undefined') {
        _hidCommand.value = "Refresh";
        _imgSubmit.click();
    }

    return false;
}

function SSTC_ReloadParent(ParentClientID) {

    if (opener == null || opener == 'undefined')
        return;

    opener.location.reload();
}

function SSTC_Redirect(Url) {
    document.location.href = Url;
    return false;
}

function SSTC_ClearHtmlTags() {

    for (var i = 0; i < document.forms[0].elements.length; i++) {
        if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea") {
            if (document.forms[0].elements[i].value.indexOf("<") >= 0) {
                do {
                    document.forms[0][i].value = document.forms[0].elements[i].value.replace("<", "&lt;")
                }
                while (document.forms[0].elements[i].value.indexOf("<") >= 0);
            }

            if (document.forms[0].elements[i].value.indexOf(">") >= 0) {
                do {
                    document.forms[0][i].value = document.forms[0].elements[i].value.replace(">", "&gt;")
                }
                while (document.forms[0].elements[i].value.indexOf(">") >= 0);
            }
        }
    }
}

// Delete Confirmations

function SSTC_GridItemAction_ConfirmCourseDeletion() {

    return confirm("Aven alla kurstillfallen och kursanmalningar for denna kurs kommer att tas bort!\r\n\r\nAr du saker pa att du vill ta bort denna kursen?\r\n\r\nOBS! Ingen 'undo'!");
}

function SSTC_GridItemAction_ConfirmCourseCategoryDeletion() {

    return confirm("Aven alla kurser, kurstillfallen och kursanmalningar for denna kurskategori kommer att tas bort!\r\n\r\nAr du saker pa att du vill ta bort denna kurskategorin?\r\n\r\nOBS! Ingen 'undo'!");
}

function SSTC_GridItemAction_ConfirmCourseInstanceDeletion() {

    return confirm("Aven alla kursanmalningar for detta kurstillfalle kommer att tas bort!\r\n\r\nAr du saker pa att du vill ta bort detta kurstillfalle?\r\n\r\nOBS! Ingen 'undo'!");
}

function SSTC_GridItemAction_ConfirmCourseRegistrationPersonDeletion() {

	return confirm("Ar du saker pa att du vill ta bort denna personens kursanmalan?\r\n\r\nOBS! Ingen 'undo'!");
}

function SSTC_GridItemAction_ConfirmPersonDeletion() {

    return confirm("Ar du saker pa att du vill ta bort denna personen?\r\n\r\nOBS! Ingen 'undo'!");
}

// EditControls

function SSTC_CourseEdit(CourseID, ParentClientID) {

    SSTC_OpenWindow("/admin/dialogs/kursedit.aspx?courseid=" + CourseID + "&parentclientid=" + ParentClientID, 'CourseEdit', 1024, 768);
    return false;
}
function SSTC_CourseCategoryEdit(CourseCategoryID, ParentClientID) {

    SSTC_OpenWindow("/admin/kurshantering/dialogues/kurskategoriedit.aspx?coursecategoryid=" + CourseCategoryID + "&parentclientid=" + ParentClientID, 'CourseCategoryEdit', 1024, 768);
    return false;
}
function SSTC_CourseInstanceEdit(CourseID, CourseInstanceID, ParentClientID) {

    SSTC_OpenWindow("/admin/dialogs/kurstillfalleedit.aspx?courseid=" + CourseID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID, 'CourseInstanceEdit', 1024, 768);
    return false;
}
function SSTC_PersonEdit(CourseInstanceID, PersonID, ParentClientID) {

    SSTC_OpenWindow("/admin/kurshantering/dialogues/personedit.aspx?personid=" + PersonID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID, 'PersonEdit', 1024, 768);
    return false;
}
function SSTC_CourseRegistrationEdit(CourseRegistrationID, CourseInstanceID, ParentClientID, ImportMode) {

    if (ImportMode == null || ImportMode == 'undefined' || ImportMode==false)
        SSTC_OpenWindow("/admin/dialogs/kursregistreringedit.aspx?courseregistrationid=" + CourseRegistrationID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID, 'CourseRegistrationEdit', 1024, 768);
    else
        SSTC_OpenWindow("/admin/dialogs/kursregistreringedit.aspx?courseregistrationid=" + CourseRegistrationID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID + "&import=true", 'CourseRegistrationEdit', 1024, 768);
    return false;
}


// ViewControls

function SSTC_CourseInstanceView(CourseInstanceID) {

    SSTC_OpenWindow("/admin/kurshantering/dialogues/kurstillfalle.aspx?courseinstanceid=" + CourseInstanceID, 'CourseInstanceView', 1024, 768);
    return false;
}
function SSTC_PersonView(PersonID) {

    SSTC_OpenWindow("/admin/kurshantering/dialogues/person.aspx?personid=" + PersonID, 'PersonView', 1024, 768);
    return false;
}
function SSTC_ShowEMailAddresses(CourseInstanceID) {

    SSTC_OpenWindow("/admin/kurshantering/dialogues/emailadresser.aspx?courseinstanceid=" + CourseInstanceID, 'EMailAddresses', 1024, 768);
    return false;
}

// Export

function SSTC_CourseInstanceExport(CourseID, CourseInstanceID, ParentClientID) {

    SSTC_OpenWindow("/admin/dialogs/kurstillfalleexport.aspx?courseid=" + CourseID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID, 'CourseInstanceEdit', 1024, 768);
    return false;
}

function SSTC_CourseInstanceEMail(CourseID, CourseInstanceID, ParentClientID) {

	SSTC_OpenWindow("/admin/dialogs/showemailaddressesforcourseinstance.aspx?courseid=" + CourseID + "&courseinstanceid=" + CourseInstanceID + "&parentclientid=" + ParentClientID, 'CourseInstanceEdit', 640, 480);
	return false;
}

function SSTC_ExpandControl_OnClick(expCtrlSpanId, expCtrlTargetId, expCtrlTextBoxId) {

    //alert(expCtrlSpanId + " - " + expCtrlTargetId + " - " + expCtrlTextBoxId);
    
    if (expCtrlTargetId != "") {
        expCtrlTarget = document.getElementById(expCtrlTargetId);

        if (expCtrlTarget.style.display == "")
            expCtrlTarget.style.display = "none";
        else if (expCtrlTarget.style.display == "block")
            expCtrlTarget.style.display = "none";
        else if (expCtrlTarget.style.display == "none")
            expCtrlTarget.style.display = "block";

        expCtrlSpan = document.getElementById(expCtrlSpanId);
        expCtrlSpanImg = expCtrlSpan.childNodes[0];
        expCtrlTextBox = document.getElementById(expCtrlTextBoxId);

        if (expCtrlTarget.style.display == "block")
            expCtrlSpanImg.src = "/images/Contract.gif";
        else if (expCtrlTarget.style.display == "none")
            expCtrlSpanImg.src = "/images/Expand.gif";

        if (expCtrlTextBox.value == "1")
            expCtrlTextBox.value = "0";
        else if (expCtrlTextBox.value == "0")
            expCtrlTextBox.value = "1";
    }
}
