﻿var DOCUMENT_ROOT = ''; //u stránek, které jsou za rohem, přiřadí se sem například '../', nebo '../../' podle potřeby, aby fungovaly i funkce otevírající nějakou stránku

function ServiceAdd() {
    window.open(DOCUMENT_ROOT + 'ServiceEditor.aspx?' + GET_COMPANYID + '=' + companyId, 'ServiceAdd', 'scrollbars=no,status=no,menubar=no,resizable=no,width=550,height=365,left=' + (window.screen.width - 550) / 2 + ',top=' + (window.screen.height - 365) / 2);
}

function ServiceSettings(serviceId) {
    window.open(DOCUMENT_ROOT + 'ServiceEditor.aspx?' + GET_COMPANYID + '=' + companyId + '&' + GET_SERVICEID + '=' + serviceId, 'ServiceEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=550,height=365,left=' + (window.screen.width - 550) / 2 + ',top=' + (window.screen.height - 365) / 2);
    return false;
}

function CompanySettings(companyId) {
    window.open(DOCUMENT_ROOT + 'CompanyEdit.aspx?' + GET_COMPANYID + '=' + companyId, 'CompanySettings', 'scrollbars=no,status=no,menubar=no,resizable=no,width=530,height=255,left=' + (window.screen.width - 530) / 2 + ',top=' + (window.screen.height - 230) / 2);
}

function CompanyAdd() {
    window.open(DOCUMENT_ROOT + 'CompanyAdd.aspx', 'CompanyAdd', 'scrollbars=no,status=no,menubar=no,resizable=no,width=530,height=255,left=' + (window.screen.width - 530) / 2 + ',top=' + (window.screen.height - 230) / 2);
}

function CompanyRemove(id) {
    window.open(DOCUMENT_ROOT + 'CompanyRemove.aspx?' + GET_COMPANYID + '=' + id, 'CompanyRemove', 'scrollbars=no,status=no,menubar=no,resizable=no,width=480,height=110,left=' + (window.screen.width - 480) / 2 + ',top=' + (window.screen.height - 110) / 2);
}

function ChangePassword() {
    window.open(DOCUMENT_ROOT + 'Password.aspx?' + GET_COMPANYID + '=' + companyId, 'ChangePassword', 'scrollbars=no,status=no,menubar=no,resizable=no,width=380,height=220,left=' + (window.screen.width - 380) / 2 + ',top=' + (window.screen.height - 220) / 2);
    return false;
}

function openLinkEditor() {
    window.open(DOCUMENT_ROOT + 'LinkManagement/LinkEdit.aspx', 'linkEdit', 'scrollbars=yes,status=no,menubar=no,resizable=yes,width=800,height=600,left=' + (window.screen.width - 800) / 2 + ',top=' + (window.screen.height - 600) / 2);
}

function openAdrsapoCheck()
{
    windowOpen('adrsapoCheck', DOCUMENT_ROOT + 'AdrsapoCheck.aspx', 600, 450, false);
}

function linkGroupEdit(groupId, companyId) {
    window.open(DOCUMENT_ROOT + 'LinkManagement/LinkGroup.aspx?' + GET_LINKGROUPID + '=' + groupId + "&" + GET_COMPANYID + "=" + companyId, 'linkGroupEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=310,height=215,left=' + (window.screen.width - 310) / 2 + ',top=' + (window.screen.height - 215) / 2);
}

function linkGroupRemove(groupId) {
    window.open(DOCUMENT_ROOT + 'LinkManagement/LinkGroupRemove.aspx?' + GET_LINKGROUPID + '=' + groupId, 'linkGroupEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=350,height=155,left=' + (window.screen.width - 310) / 2 + ',top=' + (window.screen.height - 215) / 2);
}

function linkGroupAdd(cid, pid, sid) {
    var url = DOCUMENT_ROOT + 'LinkManagement/LinkGroup.aspx?' + GET_COMPANYID + '=' + cid + "&" + GET_ETSPRODID + "=" + pid + "&" + GET_SERVICEID + "=" + sid;
    window.open(url, 'linkGroupEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=310,height=215,left=' + (window.screen.width - 310) / 2 + ',top=' + (window.screen.height - 215) / 2);
}

function openEditor(url) {
    window.open(url, 'linkEditor', 'scrollbars=no,status=no,menubar=no,resizable=no,width=520,height=350,left=' + (window.screen.width - 520) / 2 + ',top=' + (window.screen.height - 330) / 2);
}

function linkAddToGroup(groupId) {
    openEditor(DOCUMENT_ROOT + 'LinkManagement/LinkEditor.aspx?' + GET_LINKGROUPID + '=' + groupId);
}

function linkAddToURI(cid, pid, sid) {
    openEditor(DOCUMENT_ROOT + 'LinkManagement/LinkEditor.aspx?' + GET_COMPANYID + '=' + cid + "&" + GET_ETSPRODID + "=" + pid + "&" + GET_SERVICEID + "=" + sid);
}

function linkEdit(linkId) {
    openEditor(DOCUMENT_ROOT + 'LinkManagement/LinkEditor.aspx?' + GET_LINKID + '=' + linkId);
}

function linkDel(linkId, groupId, cid, pid, sid) {
    url = DOCUMENT_ROOT + 'LinkManagement/LinkRemove.aspx?' + GET_LINKID + '=' + linkId + '&' + GET_LINKGROUPID + '=' + groupId + "&" + GET_ETSPRODID + "=" + pid + "&" + GET_SERVICEID + "=" + sid;
    if (cid > 0) url += '&' + GET_COMPANYID + '=' + cid;
    window.open(url, 'linkRemove', 'scrollbars=no,status=no,menubar=no,resizable=no,width=360,height=130,left=' + (window.screen.width - 360) / 2 + ',top=' + (window.screen.height - 130) / 2);
}

function linkImportToGroup(groupId) {
    window.open(DOCUMENT_ROOT + 'LinkManagement/LinksImport.aspx?' + GET_LINKGROUPID + '=' + groupId, 'linkImport', 'scrollbars=no,status=no,menubar=no,resizable=no,width=600,height=450,left=' + (window.screen.width - 600) / 2 + ',top=' + (window.screen.height - 450) / 2);
}

function linkImportToURI(cid, pid, sid) {
    var url = DOCUMENT_ROOT + 'LinkManagement/LinksImport.aspx?' + GET_COMPANYID + '=' + cid + "&" + GET_ETSPRODID + "=" + pid + "&" + GET_SERVICEID + "=" + sid;
    window.open(url, 'linkImport', 'scrollbars=no,status=no,menubar=no,resizable=no,width=600,height=450,left=' + (window.screen.width - 600) / 2 + ',top=' + (window.screen.height - 450) / 2);
}

function serviceImport() {
    windowOpen('serviceImport', DOCUMENT_ROOT + 'ServiceEtsImport.aspx?' + GET_COMPANYID + '=' + companyId, 600, 450);    
}

function serviceDelete(serviceId) {
    window.open(DOCUMENT_ROOT + 'ServiceDelete.aspx?' + GET_COMPANYID + '=' + companyId + '&' + GET_SERVICEID + '=' + serviceId, 'serviceDelete', 'scrollbars=no,status=no,menubar=no,resizable=no,width=380,height=190,left=' + (window.screen.width - 380) / 2 + ',top=' + (window.screen.height - 190) / 2);
    return false;
}

function serviceRemove(serviceId) {
    window.open(DOCUMENT_ROOT + 'ServiceRemove.aspx?' + GET_COMPANYID + '=' + companyId + '&' + GET_SERVICEID + '=' + serviceId, 'serviceDelete', 'scrollbars=no,status=no,menubar=no,resizable=no,width=380,height=190,left=' + (window.screen.width - 380) / 2 + ',top=' + (window.screen.height - 190) / 2);
    return false;
}

function authorizedUsers(companyId) {
    windowOpen('companyAuth', DOCUMENT_ROOT + 'CompanyAuth.aspx?' + GET_COMPANYID + '=' + companyId, 890, 400);
}

function userAdd(companyId) {
    window.open(DOCUMENT_ROOT + 'UserAdd.aspx?' + GET_COMPANYID + '=' + companyId, 'UserAdd', 'scrollbars=no,status=no,menubar=no,resizable=no,width=530,height=416,left=' + (window.screen.width - 530) / 2 + ',top=' + (window.screen.height - 416) / 2);
    return false;
}

function userEdit(userId, usersCompanyId) {
    var companyId = document.getElementById("lstCompanies").value;
    window.open(DOCUMENT_ROOT + 'UserEdit.aspx?' + GET_COMPANYID + '=' + usersCompanyId + '&' + GET_USERID + '=' + userId, 'UserEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=525,height=430,left=' + (window.screen.width - 525) / 2 + ',top=' + (window.screen.height - 430) / 2);
    return false;
}

function userMapping(userId, usersCompanyId)
{
    windowOpen('UserMapping', DOCUMENT_ROOT + 'UserMapping.aspx?' + GET_COMPANYID + '=' + usersCompanyId + '&' + GET_USERID + '=' + userId, 925, 560, 1);
}

function userAdministration(companyId) {
    windowOpen('userAuth', DOCUMENT_ROOT + 'UserAdministration.aspx?' + GET_COMPANYID + '=' + companyId, 950, 560, 1);    
}

function deleteUser(userId, usersCompanyId) {
    var companyId = document.getElementById("lstCompanies").value;
    window.open(DOCUMENT_ROOT + 'UserDel.aspx?' + GET_COMPANYID + '=' + usersCompanyId + '&' + GET_USERID + '=' + userId, 'UserDel', 'scrollbars=no,status=no,menubar=no,resizable=no,width=460,height=210,left=' + (window.screen.width - 530) / 2 + ',top=' + (window.screen.height - 210) / 2);
    return false;
}

function relEdit(userId, usersCompanyId) {
    var companyId = document.getElementById("lstCompanies").value;
    windowOpen('RelEdit', DOCUMENT_ROOT + 'Relace.aspx?' + GET_COMPANYID + '=' + usersCompanyId + '&' + GET_USERID + '=' + userId, 840, 430);
    return false;
}

function ChangeContactData() {
    window.open(DOCUMENT_ROOT + 'ContactDataChange.aspx?' + GET_COMPANYID + '=' + companyId, 'ChangeConData', 'scrollbars=no,status=no,menubar=no,resizable=no,width=380,height=194,left=' + (window.screen.width - 380) / 2 + ',top=' + (window.screen.height - 194) / 2);
    return false;
}

function eventDetail(eventId) {
    window.open(DOCUMENT_ROOT + 'EventDetail.aspx?' + GET_EVENTID + '=' + eventId, 'detailUdalosti', 'scrollbars=yes,status=no,menubar=no,resizable=yes,width=800,height=500,left=' + (window.screen.width - 800) / 2 + ',top=' + (window.screen.height - 500) / 2);
    return false;
}

function reportnik(idOdkazuReportu, idOkna, winWidth, winHeight) {
    var url = DOCUMENT_ROOT + 'LinkManagement/reportnik.aspx?' + GET_COMPANYID + '=' + companyId + '&' + GET_LINKID + '=' + idOdkazuReportu + '&' + GET_TARGET + '=' + GET_TARGET_NW;
    scrollableWindowOpen(idOkna, url, winWidth, winHeight);
    return false;
}

function addServiceToRequest()
{
    windowOpen('serviceToRequest', DOCUMENT_ROOT + 'RequestServices.aspx?' + GET_COMPANYID + '=' + companyId, 600, 450, false);
    return false;
}

function addDeviceToRequest()
{
    windowOpen('deviceToRequest', DOCUMENT_ROOT + 'RequestDevices.aspx?' + GET_COMPANYID + '=' + companyId, 870, 600, true);
    return false;
}

function SendUserData(userId, usersCompanyId)
{
    windowOpenNoResize('sendUserData', DOCUMENT_ROOT + 'SendUserData.aspx?' + GET_COMPANYID + '=' + usersCompanyId + '&' + GET_USERID + '=' + userId, 520, 430);
    return false;
}

function addTSRMMapping(categoryId)
{
    windowOpen('mappingTSRM' + categoryId, DOCUMENT_ROOT + 'TSRMMapping.aspx?' + GET_CATEGORYID + '=' + categoryId, 600, 135, false);
    return false;
}

function changeDefaultTSRMMapping()
{
    windowOpen('mappingTSRMDefault', DOCUMENT_ROOT + 'TSRMMapping.aspx?' + GET_SRDEFAULTS + '=1', 600, 135, false);
    return false;
}

function addResolver()
{
    windowOpen('addResolver', DOCUMENT_ROOT + 'AddExpertTeam.aspx', 500, 200, false);
    return false;
}

function changeDefaultResolver()
{
    windowOpen('changeDefaultResolver', DOCUMENT_ROOT + 'AddExpertTeam.aspx?' + GET_SRDEFAULTS + '=1', 400, 200, false);
    return false;
}

function changeRequestDefaults()
{
    windowOpen('changeRequestDefaults', DOCUMENT_ROOT + 'RequestDefaults.aspx', 600, 210, false);
    return false;
}

function clickButton(e, buttonid) {
    var bt = document.getElementById(buttonid);
    if (typeof bt == 'object') {
        if (navigator.appName.indexOf("Microsoft Internet Explorer") > (-1)) {
            if (event.keyCode == 13) {
                bt.click();
                return false;
            }
        }
        else if (e.keyCode == 13) {
            bt.click();
            return false;
        }
    }
}

function openRequestCategoryEditor() {
    scrollableWindowOpen("recaed", DOCUMENT_ROOT + "RequestCategoryEditor.aspx", 1004, 740);
}

function openRequestUrgencyMapping()
{
    windowOpen("urgencyMapping", DOCUMENT_ROOT + "UrgencyMapping.aspx", 400, 200);
}

function openRequestSourceMapping()
{
    windowOpen("sourceMapping", DOCUMENT_ROOT + "SourceMapping.aspx", 420, 100);
}

function Detail(x) {
    var a = 550;
    var b = 600;

    var sirka = (window.screen.width - a) / 2;
    var vyska = (window.screen.height - b) / 2;
    var okno = open("Obj.aspx?number=" + x, "", "width=" + a + ",height= " + b + ",left=" + sirka + ",top=" + vyska);
    okno.focus();
}

function Attach(x) {
    var a = 350;
    var b = 400;

    var sirka = (window.screen.width - a) / 2;
    var vyska = (window.screen.height - b) / 2;
    var okno = open("OfficeAttach.aspx?Obj=" + x, "", "width=" + a + ",height= " + b + ",left=" + sirka + ",top=" + vyska);
    okno.focus();
}

function Log(x) {
    var a = 360;
    var b = 500;

    var sirka = (window.screen.width - a) / 2;
    var vyska = (window.screen.height - b) / 2;
    var okno = open("ObjLog.aspx?number=" + x, "", "width=" + a + ",height= " + b + ",left=" + sirka + ",top=" + vyska);
    okno.focus();
}

function TitleEdit() {
    window.open(DOCUMENT_ROOT + 'TitleEdit.aspx?' + GET_COMPANYID + '=' + companyId, 'TitleEdit', 'scrollbars=no,status=no,menubar=no,resizable=no,width=440,height=240,left=' + (window.screen.width - 440) / 2 + ',top=' + (window.screen.height - 200) / 2);
}

function odhlasit() {
    window.location.href = DOCUMENT_ROOT + "Login.aspx";
}

function expandAdministration() {
    window.location.href = URL_SELF + ((URL_SELF.indexOf('?') < 0) ? '?' : '&') + GET_ADMINISTRATIONEXPANDED + '=1';
    return false;
}

function expandLogFiles()
{
    window.location.href = URL_SELF + ((URL_SELF.indexOf('?') < 0) ? '?' : '&') + GET_LOGFILESEXPANDED + '=1';
    return false;
}

function UserPermissions(linkId, linkGroupId) {
    var url = DOCUMENT_ROOT + "UserPermissions.aspx";  
    
    if (linkId < -1) // konstanta značící předání URL místo ID skupiny odkazů
        url += "?" + GET_PAGEURL + "=" + linkGroupId + "&" + GET_LINKID + "=" + linkId;   // linkGroupId je zde řetězec URL

    if (linkGroupId > 0 || linkId > 0)
        url += "?";
    
    if (linkGroupId > 0)
        url += GET_LINKGROUPID + "=" + linkGroupId;

    if (linkGroupId > 0 && linkId > 0)
        url += "&";        
        
    if (linkId > 0)
        url += GET_LINKID + "=" + linkId;        
        
    windowOpen("userPermissions", url, 890, 400);    
    return;
}

function windowOpen(id, url, width, height) {
    if (!url || url.length < 1)
        return false;
    window.open(url, id, 'scrollbars=no,status=no,menubar=no,resizable=yes,width=' + width + ',height=' + height + ',left=' + (window.screen.width - width) / 2 + ',top=' + (window.screen.height - height) / 2);
    return false;
}

function windowOpenNoResize(id, url, width, height)
{
    if (!url || url.length < 1)
        return false;
    window.open(url, id, 'scrollbars=no,status=no,menubar=no,resizable=no,width=' + width + ',height=' + height + ',left=' + (window.screen.width - width) / 2 + ',top=' + (window.screen.height - height) / 2);
    return false;    
}

function windowOpen(id, url, width, height, scrollbars) {
    if (!url || url.length < 1)
        return false;    
    scrollbars = (scrollbars == true) ? 'yes' : 'no';
    window.open(url, id, 'scrollbars=' + scrollbars + ',status=no,menubar=no,resizable=yes,width=' + width + ',height=' + height + ',left=' + (window.screen.width - width) / 2 + ',top=' + (window.screen.height - height) / 2);
    return false;
}

function scrollableWindowOpen(id, url, width, height) {
    if (!url || url.length < 1)
        return false;
    window.open(url, id, 'scrollbars=yes,status=no,menubar=no,resizable=yes,width=' + width + ',height=' + height + ',left=' + (window.screen.width - width) / 2 + ',top=' + (window.screen.height - height) / 2);
    return;
}

function linkTest(id, url, width, height, type) {
    if (!url || url.length < 1)
        return false;
    if (type == 1)
        window.location.href = url;
    else
        windowOpen(id, url, width, height);
    return false;
}