﻿
////////////////////////////////

/// Functie care seteaza data revizuirii entitatii curente la data publicarii + offset ani
function setDefaultRevDate(txtDate, txtRevDate, offset) {
    // Preluam intr-o variabila data din txtDate
    var date = new Date();
    date.setFullYear(parseInt(txtDate.value.substr(6, 4), 10) - 1, parseInt(txtDate.value.substr(3, 2), 10) - 1, parseInt(txtDate.value.substr(0, 2), 10));

    if ((date.getMonth() + 1) == 2 && date.getDate() == 29) {
        txtRevDate.value = "28-02-" + (date.getFullYear() + offset + 1);
    }
    else {
        txtRevDate.value = (date.getDate() >= 10 ? date.getDate() : "0" + date.getDate()) + "-" + (date.getMonth() + 1 >= 10 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1)) + "-" + (date.getFullYear() + offset + 1);
    }

    // setarea corecta a calendarextender-ului astfel incat acesta sa corespunda cu textboxul asociat
    var calext2 = $find("calext2");
    var value = Date.parseLocale(txtRevDate.value, "dd-MM-yyyy");
    if (isNaN(value))
        value = null;
    if (calext2 != null) {
        calext2._selectedDate = value;
    }
}

function clearTextBoxes() {
    document.getElementById('ctl00_ContentPlaceHolderMainContent_txtLoginUsername').value = '';
    document.getElementById('ctl00_ContentPlaceHolderMainContent_txtLoginPassword').value = '';
}
////////////////////////////////

/// Functie care afiseaza fereastra de search si select Calificare
function showSelectQWindow(targettxt1, targettxt2) {
    /*if(window.showModalDialog)
    {
    var ret = new Array(0,0);
    ret = window.showModalDialog("../Q/SearchQ.aspx?target1=" + targettxt1
    + "&target2=" + targettxt2
    , "Q_Search", "dialogWidth:900px;dialogHeight:500px");
    window.document.getElementById(targettxt1).value = ret[0];
    window.document.getElementById(targettxt2).value = ret[1];
    }
    else
    {*/
    var searchQ;
    searchQ = window.open("../Q/SearchQ.aspx?target1=" + targettxt1
        + "&target2=" + targettxt2
        , "Q_Search", "width=900,height=500");
    searchQ.focus();
    //}
    return false;
}


/// Functie care afiseaza fereastra de search & select persoana implicata in proiect
//function showSelectIPWindow(targettxt1, targettxt2, targettxt3, targettxt4) {
    /*if(window.showModalDialog)
    {
    var ret = new Array(0,0,0,0);
    ret = window.showModalDialog("../OS/SearchOS_IP.aspx?target1=" + targettxt1
    + "&target2=" + targettxt2
    + "&target3=" + targettxt3
    + "&target4=" + targettxt4
    , "IP_Search", "dialogWidth:900px;dialogHeight:500px")
    window.document.getElementById(targettxt1).value = ret[0];
    window.document.getElementById(targettxt2).value = ret[1];
    window.document.getElementById(targettxt3).value = ret[2];
    window.document.getElementById(targettxt4).value = ret[3];
    }
    else
    {*/
   /* var searchListWindows;
    searchListWindows = window.open("../OS/SearchOS_IP.aspx?target1=" + targettxt1
            + "&target2=" + targettxt2
            + "&target3=" + targettxt3
            + "&target4=" + targettxt4
            , "IP_Search", "width=900,height=500, modal=yes");

    searchListWindows.focus();
    //}      
    return false;
}*/

/// Functie care afiseaza fereastra de search & select analiza ocupationala
function showSelectOAWindow(targettxt1, targettxt2, targettxt3, targettxt4) {
    /*if(window.showModalDialog)
    {
    var ret = new Array(0,0,0,0);
    ret = window.showModalDialog("../OA/SearchOA.aspx?target1=" + targettxt1
    + "&target2=" + targettxt2
    + "&target3=" + targettxt3
    + "&target4=" + targettxt4
    , "OA_Search", "dialogWidth:900px;dialogHeight:500px");
    window.document.getElementById(targettxt1).value = ret[0];
    window.document.getElementById(targettxt2).value = ret[1];
    window.document.getElementById(targettxt3).value = ret[2];
    window.document.getElementById(targettxt4).value = ret[3];
    }
    else
    {*/
    searchListWindows = window.open("../OA/SearchOA.aspx?target1=" + targettxt1
            + "&target2=" + targettxt2
            + "&target3=" + targettxt3
            + "&target4=" + targettxt4
            , "OA_Search", "width=900,height=500, modal=yes");

    searchListWindows.focus();
    //}
    return false;
}

/// Functie care afiseaza fereastra de search & select standard ocupational
function showSelectOSWindow(targettxt1, targettxt2, targettxt3, targettxt4) {
    searchListWindows = window.open("../OS/SearchOS.aspx?target1=" + targettxt1
            + "&target2=" + targettxt2
            + "&target3=" + targettxt3
            + "&target4=" + targettxt4
            , "OS_Search", "width=900,height=500");

    searchListWindows.focus();
    return false;
}


/// Functie care afiseaza fereastra de search & select UC
function showSelectUCWindow_forCompetence(targettxt1, targettxt2, targettxt3) {
    /*if(window.showModalDialog)
    {
    ret = window.showModalDialog("../UC/SearchUC.aspx"
    , "UC_Search", "dialogWidth:900px;dialogHeight:500px");
    var function_name = ret[0];
    var pArg = ret[1];
    //alert(function_name);
    //alert(pArg);
    eval(function_name + '(' + pArg + ')');
    alert("dupa evaluare");
    } 
    else
    {*/
    searchListWindows = window.open("../UC/SearchUC.aspx?target1=" + targettxt1
            + "&target2=" + targettxt2
            + "&target3=" + targettxt3
            , "UC_Search", "width=900,height=500");
    searchListWindows.focus();
    //}    
    return false;
}

function showSelectUCWindow_forOS() {
    searchListWindows = window.open("../UC/SearchUC.aspx?SO=#"
            , "UC_Search", "width=900,height=500");
    searchListWindows.focus();
    return false;
}


/// Functie care scrie in controlul target informatia din content
function ReKey(target, content) {
    document.getElementById(target).value = content;
}

/// Ca mai sus, doar ca avem doua controale destinatie
function ReKeyQ(targettxt1, content1, targettxt2, content2) {
    if (window.opener.document.URL.indexOf('login.aspx', 0) < 0) {
        /*if(window.showModalDialog)
        {
        var ret = new Array(content1, content2);
        window.returnValue = ret;
        window.close();
        }
        else
        {*/
        window.opener.document.getElementById(targettxt1).value = content1;
        window.opener.document.getElementById(targettxt2).value = content2;
        window.close();
        //}
    }
    else {
        alert("Sesiunea a expirat. Vă rugăm sa vă reautentificaţi.");
        window.close();
    }
}

/// Ca mai sus, doar ca avem patru controale destinatie
function ReKeyOA(targettxt1, content1, targettxt2, content2, targettxt3, content3, targettxt4, content4) {
    if (window.opener.document.URL.indexOf('login.aspx', 0) < 0) {
        /*if(window.showModalDialog)
        {
        var ret = new Array(content1, content2, content3, content4);
        window.returnValue = ret;
        window.close();
        }    
        else
        {*/
        window.opener.document.getElementById(targettxt1).value = content1;
        window.opener.document.getElementById(targettxt2).value = content2;
        window.opener.document.getElementById(targettxt3).value = content3;
        window.opener.document.getElementById(targettxt4).value = content4;
        window.close();
        //}
    }
    else {
        alert("Sesiunea a expirat. Vă rugăm sa vă reautentificaţi.");
        window.close();
    }
}

function ReKeyOS(targettxt1, content1, targettxt2, content2, targettxt3, content3, targettxt4, content4) {
    if (window.opener.document.URL.indexOf('login.aspx', 0) < 0) {
        window.opener.document.getElementById(targettxt1).value = content1;
        window.opener.document.getElementById(targettxt2).value = content2;
        window.opener.document.getElementById(targettxt3).value = content3;
        window.opener.document.getElementById(targettxt4).value = content4;
    }
    else {
        alert("Sesiunea a expirat. Vă rugăm sa vă reautentificaţi.");
        window.close();
    }
}

function ReKeyUC(targettxt1, content1, targettxt2, content2, targettxt3, content3) {
    if (window.opener.document.URL.indexOf('login.aspx', 0) < 0) {
        window.opener.document.getElementById(targettxt1).value = content1;
        window.opener.document.getElementById(targettxt2).value = content2;
        var listSelected = window.opener.document.getElementById(targettxt3);
        for (var i = 0; i < listSelected.options.length; i++) {
            if (listSelected.options[i].text == content3) {
                listSelected.options[i].selected = true;
                break;
            }
        }

        window.close();
    }
    else {
        alert("Sesiunea a expirat. Vă rugăm sa vă reautentificaţi.");
        window.close();
    }
}

function ReKeyIP(targettxt1, content1, targettxt2, content2, targettxt3, content3, targettxt4, content4) {
    if (window.opener.document.URL.indexOf('login.aspx', 0) < 0) {
        if (content3 <= 0 || content4 <= 0) {
            alert("Trebuie selectate Tip Persoană Implicată şi Tip Output Persoană Implicată");
            return false;
        }
        /*if(window.showModalDialog)
        {
        var ret = new Array(content1, content2, content3, content4);
        window.returnValue = ret;
        window.close();
        }    
        else
        {*/

        window.opener.document.getElementById(targettxt1).value = content1;
        window.opener.document.getElementById(targettxt2).value = content2;
        window.opener.document.getElementById(targettxt3).value = content3;
        window.opener.document.getElementById(targettxt4).value = content4;
        window.close();
        //}
    }
    else {
        alert("Sesiunea a expirat. Vă rugăm sa vă reautentificaţi.");
        window.close();
    }
}


/// Functie care rescrie link-ul care a generat fereastra de popup curenta
function remLink() {
    if (window.searchListWindows && window.searchListWindows.open && !window.searchListWindows.closed)
        window.searchListWindows.opener = null;
}

////////////////////////////////

/* functie nefolosita
// Functie care afiseaza fereastra de search & select AO
function showSelectAOWindows(targettxt) {
searchAOListWindows = window.open("../OA/SearchOA.aspx?target=" + targettxt + "", "AO_Search", "width=900,height=500");
searchAOListWindows.focus();
return false;
}
*/

function __forcePostBackWrapperFunction(function_name, pArg) {
    var ret = new Array(function_name, pArg);
    window.returnValue = ret;
    window.close();
}

/// Functie folosita la randarea butoanelor
function hov(loc, cls) {
    if (loc.className)
        loc.className = cls;
}
