var b = 1;// bascula
// verifica argumentele sa fie NonEmpty;
function valid_ne(){
    var r = 1;
    for (var i = 0; i < arguments.length; i++) {
        if (arguments[i].value === "") {
            r *= 0;
        }
        else {
            r *= 1;
        }
    }
    // if (r==0) alert("Va rugam sa completati campurile formularului.");
    return r;
}
///arata/ascunde elem
function ShowElem(id)
{
	a = document.getElementById(id);
	a.style.visibility = 'visible';
}
//revers
function HideElem(id)
{
	a = document.getElementById(id);
	a.style.visibility = 'hidden';
}
//
//


function valid_ne_s(){
    var r = 1;
    var s;
    for (var i = 0; i < arguments.length; i++) {
        s = arguments[i].value;
        if (s.replace(/\ /g, "") == "") 
            r *= 0;
        else 
            r *= 1;
    }
    return r;
}

// verifica argumentele de la 1 in sus sa fie de cel putin marime argument 0 --
// BiggerThan
function valid_bt(){
    var r = 1;
    for (var i = 1; i < arguments.length; i++) {
        if (arguments[i].value.length < arguments[0]) {
            r *= 0;
        }
        else {
            r *= 1;
        }
    }
    return r;
}

// verifica daca x este egal cu y; in caz de inegalitate alert mesajul z
function egale(x, y, z){
    var r = 1;
    if (x.value != y.value) {
        r = 0;
        x.focus();
        alert(z);
    }
    return r;
}

// pop-up fereastra de editare mesaj in limba lang
function AddEditLang(id, lang)// adauga sau editeaza mesajul id in limba lang
{
    var params = "id=" + id;
    
    if (lang.length > 0) {
        params = params + "&lang=" + lang;
    }
    window.open("./amsg_add_edit.php?" + params, "intretinere_tabela_mesaje", "alwaysRaised=yes, dependent=yes, directories=no, height=250, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																													// 1.0,
																																																													// 1.1
    return true;
}

// fereastra de editare categorie
function AddEditCateg(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adirfirmeed.php?" + params, "dirfirme_", "alwaysRaised=yes, dependent=yes, directories=no, height=400, width=650, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    w.focus();
    return true;
}

function AddEditCategProd(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adirproded.php?" + params, "dirprod_", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
    w.focus();
    return true;
}

function AddEditCategOport(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adiroported.php?" + params, "diroport_", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    w.focus();
    return true;
}

function AddEditCategCurs(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adircursed.php?" + params, "dircurs_", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
    w.focus();
    return true;
}

// fereastra de editare pagina
function AddEditPagstat(id){
    var params = '';
    
    if (arguments.length == 1) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id;
    }
    
    // window.open('./apagstat_add_edit.php?'+params, 'wsx',
	// 'height=600px,width=700px');//js 1.0, 1.1
    var w = window.open("./apagstat_add_edit.php?" + params, "intretinere_tabele_ispagstat", "alwaysRaised=yes, dependent=yes, directories=no, height=600, width=700, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																																	// 1.0,
																																																																	// 1.1
    w.focus();
    return true;
}
//
function awremwin(sir){
    var params = '';
    
    if (arguments.length == 1) 
    {
        params = 'addr=' + sir;
    }
    
    var w = window.open("./awremail.php?" + params, "adm_wremail", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=500, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js

    w.focus();
    return true;
}

// fereastra de editare tip de inscriere (gold, silver, etc;
function AddEditTip(id,pret,moneda,rang,tabel)
{
	var params='';
	
	if (arguments.length >= 4) //id est probabil ..
	{ 	params = 'id='+id+'&pret='+pret+'&moneda='+moneda+'&rang='+rang+'&wh='+tabel;}
//alert(params);
	window.open("./atip_add_edit.php?"+params, "intretinere_tabele_istip", "alwaysRaised=yes, dependent=yes, directories=no, height=330, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");//js 1.0, 1.1
	return true;
}

// fereastra de editare stare (activ, in asteptare, sters, etc);
function AddEditStare(id){
    var params = '';
    
    if (arguments.length == 1) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id;
    }
    
    window.open("./astare_add_edit.php?" + params, "intretinere_tabele_isstare", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																														// 1.0,
																																																														// 1.1
    return true;
}

// fereastra de scriere mesaj catre administratorul sitului
function ContactAdmin(linkid){
    var params = '';
    
    if (arguments.length == 1) {
        params = 'e=' + linkid;
    }
    
    window.open("./contact_admin.php?" + params, "contact_admin", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
    return true;
}

// fereastra de vizualizare history - bun pentru user si pentru admin daca
// apelat cu user
function ViewHistory(user, entry){
    var params = '';
    
    if (arguments.length == 2) {
        params = 'u=' + user + '&e=' + entry;
    }
    else {
        return false;
    }
    
    window.open("./view_history.php?" + params, "history_viewer", "alwaysRaised=yes, dependent=yes, directories=no, height=500, width=700, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
    return true;
}

// vizualizare instructiuni de plata
function ViewPayment(suma, moneda){
    var params = '';
    
    if (arguments.length == 2) {
        params = 'suma=' + suma + '&moneda=' + moneda;
    }
    else {
        return false;
    }
    
    window.open("./view_payment.php?" + params, "payment_viewer", "alwaysRaised=yes, dependent=yes, directories=no, height=500, width=700, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
    return true;
}

// vizualizare, gestionare evenimente
function ViewEditEvent(event){
    var params = '';
    
    if (arguments.length == 1) {
        params = 'e=' + event;
    }
    else {
        return false;
    }
    
    window.open("./viewedit_event.php?" + params, "event_editview", "alwaysRaised=yes, dependent=yes, directories=no, height=500, width=700, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    return true;
}

// vizualizare, gestionare inregistrari - administrator
function ViewEditAdmEntry(entry, id_categ, n_categ, evid){
    var params = '';
    
    if (arguments.length == 4) {
        params = 'id=' + entry + '&id_categ=' + id_categ + '&n_categ=' + n_categ + '&evid=' + evid;
    }
    else {
        return false;
    }
    
    window.open("./aviewedit_entry.php?" + params, "entry_editview", "alwaysRaised=yes, dependent=yes, directories=no, height=550, width=690, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    return true;
}

// vizualizare gestionare platile unei intrari
function ViewEditPlati(entry){
    var params = '';
    
    if (arguments.length == 1) {
        params = 'en=' + entry;
    }
    else {
        return false;
    }
    
    window.open("./viewedit_plati.php?" + params, "plati_editview", "alwaysRaised=yes, dependent=yes, directories=no, height=500, width=700, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    return true;
}

// pop-up selectare categorie; parametru numeric, care dintre variante sa o
// aduca
function SelectCateg(varianta){
    if (arguments.length == 0) {
        window.open("./select_categ.php", "select_categ", "alwaysRaised=yes, dependent=yes, directories=no, height=700, width=500, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																								// 1.0,
																																																								// 1.1
    }
    else// cel putin un parametru, presupus corect, numeric
    {
        window.open("./select_categ" + varianta + ".php", "select_categ", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=400, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																												// 1.0,
																																																												// 1.1
    }
    return true;
}

function FlashMe(id_x){
    var df;
    var elem = document.getElementById(id_x);
    
    elem.style.backgroundColor = "#cc0000";
    // df = new Date(new Date().getTime() + 1000);
    // while (new Date() < df) {}
    
    // for(i=0; i<10000; i++)
    // setTimeout('', 10000);
    
    return true;
}

// collapse/expand
function CollapseAllTD(){
    var rows = document.getElementById('tabel_categ').getElementsByTagName('td');
    
    for (i = 0; i < rows.length; i++) {
        if (rows[i].id.substr(0, 3) == 'fix') {
            rows[i].style.visibility = 'visible';
        }
        else {
            rows[i].style.visibility = 'collapse';
        }
    }
    return true;
}

function CollapseAllTR(){
    var rows = document.getElementById('tabel_categ').getElementsByTagName('tr');
    
    for (i = 0; i < rows.length; i++) {
        if (rows[i].id.substr(0, 3) == 'fix') {
            rows[i].style.visibility = 'visible';
        }
        else {
            rows[i].style.visibility = 'collapse';
        }
    }
    return true;
}

function ExpandTD(x){
    var cols = document.getElementById('tabel_categ').getElementsByTagName('td');
    CollapseAllTD();
    for (i = 0; i < cols.length; i++) {
        if (cols[i].id == x) {
            // if (cols[i].style.visibility == 'collapse')
            cols[i].style.visibility = 'visible';
        }
        // else
        // cols[i].style.visibility = 'collapse';
    
    }
    return true;
}

function ExpandTR(x){
    var rows = document.getElementById('tabel_categ').getElementsByTagName('tr');
    CollapseAllTR();
    for (i = 0; i < rows.length; i++) {
        if (rows[i].id == x) {
            // if (rows[i].style.visibility == 'collapse')
            rows[i].style.visibility = 'visible';
        }
        // else
        // rows[i].style.visibility = 'collapse';
    
    }
    // ExpandTD(x);
    return true;
}

// expand/collapse general
function ExpandCollapseCategList(){
    var rows = document.getElementById('tabel_categ').getElementsByTagName('tr');
    var cols = document.getElementById('tabel_categ').getElementsByTagName('td');
    var stare = '';
    
    if (b === 0) {
        for (i = 0; i < rows.length; i++) {
            rows[i].style.visibility = 'visible';
        }
        for (i = 0; i < cols.length; i++) {
            cols[i].style.visibility = 'visible';
        }
    }
    else {
        CollapseAllTD();
        CollapseAllTR();
    }
    b = (b + 1) % 2;
    return true;
}

// transfera selectia in parinte
function Transfer(nc, id, x){
    // validare: nu las categorie radacina si in plus nici id zero, oriunde ar
	// fi el.
    if (nc == 0 || id == 0) {
        return false;
    }
    else {
        window.opener.document.forms[0].n_categ.value = nc;
        window.opener.document.forms[0].id_categ.value = id;
        window.opener.document.forms[0].nume_categ.value = x;
        
        return true;
    }
}

// aduce in fata traducerea x (sincron, declansat de onclick pe lang)
function FetchLang(x){// comutare intre mai multe limbi; necesar cel putin
						// vector vlang, asociat campurilor lang
    var l = 0;
    var defined_nume = false;
    defined_continut = false;
    defined_titlu = false;
    defined_descriere = false;
    defined_keywords = false;
    defined_meta = false;
    defined_chk_arhiva = false;
    
    l = vlang.length;
    j = document.forms[0].elements.length;
    // cu ce campuri in afara de lang mergem mei departe...
    while (j-- > 0) {
        if (document.forms[0].elements[j].name == 'nume') {
            defined_nume = true;
        }
        if (document.forms[0].elements[j].name == 'continut') {
            defined_continut = true;
        }
        if (document.forms[0].elements[j].name == 'titlu') {
            defined_titlu = true;
        }
        if (document.forms[0].elements[j].name == 'descriere') {
            defined_descriere = true;
        }
        if (document.forms[0].elements[j].name == 'keywords') {
            defined_keywords = true;
        }
        if (document.forms[0].elements[j].name == 'meta') {
            defined_meta = true;
        }
        if (document.forms[0].elements[j].name == 'chk_arhiva') {
            defined_chk_arhiva = true;
        }
    }
    
    for (i = 0; i < l; i++) {
        if (vlang[i] == document.forms[0].lang.value) {
            if (defined_nume) {
                vnume[i] = document.forms[0].nume.value;
            }
            if (defined_continut) {
                vcontinut[i] = document.forms[0].continut.value;
            }
            if (defined_titlu) {
                vtitlu[i] = document.forms[0].titlu.value;
            }
            if (defined_descriere) {
                vdescriere[i] = document.forms[0].descriere.value;
            }
            if (defined_keywords) {
                vkeywords[i] = document.forms[0].keywords.value;
            }
            if (defined_meta) {
                vmeta[i] = document.forms[0].meta.value;
            }
        }
    }
    document.forms[0].lang.value = vlang[x];
    if (defined_nume) {
        document.forms[0].nume.value = vnume[x];
    }
    if (defined_continut) {
        document.forms[0].continut.value = vcontinut[x];
    }
    if (defined_titlu) {
        document.forms[0].titlu.value = vtitlu[x];
    }
    if (defined_descriere) {
        document.forms[0].descriere.value = vdescriere[x];
    }
    if (defined_keywords) {
        document.forms[0].keywords.value = vkeywords[x];
    }
    if (defined_meta) {
        document.forms[0].meta.value = vmeta[x];
    }
    // tinyMCE.updateContent('keywords');
    tinyMCE.updateContent('continut');
    // document.forms[0].keywords.focus(); tinyMCE.setContent(vkeywords[x]);
    
    
    if (l > (x + 1)) {
        document.forms[0].lang.readOnly = true;
        // if(defined_chk_arhiva) document.forms[0].chk_arhiva.checked = true;
    }
    else {
        document.forms[0].lang.readOnly = false;
        if (defined_chk_arhiva) {
            document.forms[0].chk_arhiva.checked = false;
        }
    }
    return true;
}

function TDKLang(){
    var l = 0;
    i = 0;
    done = false;
    
    l = vl.length;
    for (i = 0; i < l; i++) {
        if (vl[i] == document.forms[0].select_lang.options[document.forms[0].select_lang.selectedIndex].value) {
            document.forms[0].titlu.value = vt[i];
            document.forms[0].descriere.value = vd[i];
            document.forms[0].keywords.value = vk[i];
            done = true;
        }
    }
    if (!done) {
        document.forms[0].titlu.value = '';
        document.forms[0].descriere.value = '';
        document.forms[0].keywords.value = '';
        done = true;
    }
    // alert(document.forms[0].select_lang.options[document.forms[0].select_lang.selectedIndex].value);
    return true;
}

function isclick(enid, enurl){
    // modificata sa returneze intotdeauna true. motiv: deschis fereastra if
	// returnat false -
    var params = '';
    
    if (arguments.length == 2) {
        params = 'id=' + enid + '&url=' + enurl;
        window.open("./isclick_load.php?" + params, "isclick", "alwaysRaised=yes, dependent=yes, directories=no, height=570, width=780, location=yes, menubar=yes, resizable=yes, screenX=10, screenY=10, toolbar=yes, scrollbars=yes");// js
																																																										// 1.0,
																																																										// 1.1
        // window.open("./isclick_load.php?"+params, "isclick",
		// "alwaysRaised=yes, dependent=yes, height=550, width=750");//js 1.0,
		// 1.1
    }
    // else
    // {
    // return false;
    // }
    
    return true;
}

function isbroken(enid, enurl){
    var params = '';
    
    if (arguments.length == 2) {
        params = 'id=' + enid + '&url=' + enurl;
    }
    else {
        return false;
    }
    
    window.open("./broken_link.php?" + params, "isbroken", "alwaysRaised=yes, dependent=yes, directories=no, height=140, width=780, location=no, menubar=no, resizable=yes, screenX=10, screenY=10, toolbar=no, scrollbars=yes");// js
																																																									// 1.0,
																																																									// 1.1
    return true;
}

function isbookmark(url, title){
    // alert(navigator.appName);
    // alert(url);
    if (window.external) {
        window.external.AddFavorite(url, title);
    }
    else {
        alert("Sorry: could not automatically bookmark,\r\nPlease press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
    }
}

// //xmlhttprequest- ajax:,
// ///////////////////////////////////////////////////////////////////////////////////////
var dest;
var request;

function processStateChange(){
    if (request.readyState == 4) {
        // continut = getElementById(dest);
        if (request.status == 200) {
            response = request.responseText;
            voptiuni = response.split('!#!');
            dest.options[0] = new Option('select...', '0', false, false);
            for (i = 0; i < voptiuni.length; i++) {
                optiune = voptiuni[i].split('!^!');
                if (optiune[0].length > 0) {
                    dest.options[i + 1] = new Option(optiune[0], optiune[1], optiune[2], optiune[3]);
                }
            }
            dest.options[0].selected = true;
        }
        else {
            response = '';// error/ eventual seteaza combo pe altceva - 1
        }
    }
    // else alert('sdfsdfsd');/// eventual seteaza combo pe altceva - 2
}

// url: cine se ocupa se aducerea datelor, parinte: cine contine element (de ex.
// document.form) elem - baza (id)numelui elementului,
function isGetSubCateg(url, element, niv, nc){
    var l, k;
    var i, id;
    // alert(elem+':'+niv+':'+nc);
    if (niv >= (nc - 1)) {
        return;
    }// end aici, ultimul nu mai are la ce sa raspunda.
    dest = document.getElementById(element + (niv + 1));// dest = dest_;
    source = document.getElementById(element + niv);
    // alert(dest+','+source);
    k = source.length;
    if (source.selectedIndex == -1) {
        return false;
    }// de vazut cum incheiem diverse situatii
    for (i = 0; i < k; i++) {
        if (i == source.selectedIndex) {
            id = source.options[i].value;
            url = url + id;
        }
    }
    // alert(url);
    // acum url are si id-ul categ selectate
    
    // erste: wir anulam das existente list
    for (k = (niv + 1); k < nc; k++) {
        x = document.getElementById(element + k);
        l = x.length;
        for (i = 0; i < l; i++) {
            x.options[i].text = null;// optional, value conteaza
            x.options[i].value = null;
        }
        x.options.length = 0;// *
    }
    // anulat listele urmatoare listei in care se lucreaza
    // ajax
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = processStateChange;
        request.open("GET", url, true);
        request.send(null);
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = processStateChange;
                request.open("GET", url, true);
                request.send();
            }
        }
    // then wir adaugam elementen an list
    // dest.length sa fie asadar 0;

    // l = 0;
    // dest_.options[l] = new Option(url);
}

// /////////////////////////////////////////////////////////////////////
function isHide(x){
    var a, b;
    a = document.getElementById(x);
    a.style.visibility = 'hidden';
    // a.style.borderStyle = 'dotted';
    // a.style.borderColor = 'black';
    
    b = document.getElementById('l' + x);
    b.style.backgroundColor = 'transparent';
    b.style.borderStyle = 'solid';
    b.style.borderColor = '#eeeeee';
    b.style.borderWidth = '2px';
    b.style.padding = '3px';
}

function isShow(x){
    var a, b;
    a = document.getElementById(x);
    a.style.visibility = 'visible';
    a.style.borderStyle = 'solid';
    a.style.borderColor = '#dedede';
    a.style.borderWidth = '10px';
    a.style.padding = '7px';
    
    b = document.getElementById('l' + x);
    b.style.backgroundColor = '#dedede';
    b.style.borderStyle = 'solid';
    b.style.borderColor = '#dedede';
    b.style.borderWidth = '2px';
    b.style.padding = '3px';
}

// plus
function isshowtt(id_unde, msg){
    var elem = document.getElementById(id_unde);
    var i, l, x, y;
    
    y = document.getElementById('tt');
    if (y) {
    
    }
    else {
        y = document.createElement('div');
        elem.appendChild(y);
        
        y.id = 'tt';
        
        y.style.backgroundColor = '#dedede';
        y.style.borderStyle = 'dotted';
        y.style.borderColor = 'black';
        y.style.borderWidth = '1px';
        y.style.padding = '7px';
        y.style.position = 'absolute';
        
        y.style.left = y.offsetLeft + 100 + "px";
        y.style.top = y.offsetTop - 20 + "px";
        
    }
    
    y.style.visibility = 'visible';
    y.innerHTML = '<p>' + msg;// de ajustat acest innerhtml
    // for(i=0; i<100; i++)
    // {
    setTimeout(isrmtt, 3000);
    clearTimeout();
    // }
    // // elem.removeChild(y);
    return true;// problema e ca trebuie intarziat acest return.
}

function isrmtt(){
    var y = document.getElementById('tt');
    /*
	 * var now = new Date(); var exitTime = now.getTime() + 1000;//numberMillis
	 * while (now.getTime() < exitTime) { now = new Date(); }
	 */
    // for(i=0; i<10900; i++)
    // {
    // setTimeout(null, 10900);
    // }
    if (y) {
        y.style.visibility = 'hidden';
        y.parentNode.removeChild(y);
    }
    return true;
}

// ////////////////////////////////////////////////////////////////////////////
var dest;
var request;
// functia ajax in care se intoarce raspunsul response
function sqlExecResponse(){
    if (request.readyState == 4) {
        if (request.status == 200) {
            response = request.responseText;
            // alert(response);//it works - pe opera mai ales ajunge si aici
        }
        else {
            response = '';// error/ eventual seteaza ceva pe altceva - 1
        }
    }
    // else alert(request.readyState);/// eventual seteaza ceva/careva element
	// pe altceva - 2
}

// functia ajax de invocare a unei executii sql la distanta
function sqlExec(qry, val){
    var url = 'isremotesql.php';
    var post_data = '';
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
    // datele care vor fi transmise. in acest caz post; daca se schimba modul,
	// get;
    post_data = 'qry=' + encodeURIComponent(qry);// primul parametru
    for (var i = 1, ln_arg = arguments.length; i < ln_arg; i++) 
        post_data += '&val' + i + '=' + encodeURIComponent(arguments[i]);// restul
																			// parametrilor,
																			// un
																			// fel
																			// de
																			// indexare
    // ajax cu post de data asta
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = sqlExecResponse;
        request.open("POST", url, false);// parametrul 3 asyncron sau
											// sincron: adica sa stea dupa el
											// rezultatul sau ba
        request.setRequestHeader("Content-Type", contentType);
        request.send(post_data);
        // alert(request.responseText);
        return request.responseText;
        // return true;
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = sqlExecResponse;
                request.open("POST", url, false);
                request.setRequestHeader("Content-Type", contentType);
                request.send(post_data);
                return request.responseText;
            // return true;
            }
        }
    return false;
}
// /trimite mesaj la cerere - varianta 1;
function isSendMail(e_mail, msg){
    var url = 'issendmail.php';
    var post_data = '';
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
    // datele care vor fi transmise. in acest caz post; daca se schimba modul,
	// get;
    post_data = 'e_mail=' + encodeURIComponent(e_mail);// primul parametru
    post_data += '&msg=' + encodeURIComponent(msg);// al doilea
    // ajax cu get de data asta
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = sqlExecResponse;
        request.open("POST", url, false);// parametrul 3 asyncron sau
											// sincron: adica sa stea dupa el
											// rezultatul sau ba
        request.setRequestHeader("Content-Type", contentType);
        request.send(post_data);
        // alert(request.responseText);
        return request.responseText;
        // return true;
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = sqlExecResponse;
                request.open("POST", url, false);
                request.setRequestHeader("Content-Type", contentType);
                request.send(post_data);
                return request.responseText;
            // return true;
            }
        }
    return false;
}
// /////////////////////////////////////////////////////////////////
// seria de functii quod validatem diferentiae per valor
// functia de stergere a alertelor din familia al
var tagalert = "SPAN";
function isRmAlert(al){
    var l = 0, i = 0, k = 0, e, ee, re;
    e = new Array();
    // IE BUG: nu stie getElementsByName pentru dom introdusele.; ie8 va rezolva
	// problema????
    re = /[\.]*MSIE[\.]*/;
    if (re.test(window.navigator.userAgent)) // window.navigator.userAgent
												// contine MSIE
    {
        // ee = new Array();
        ee = document.getElementsByTagName(tagalert);
        k = ee.length;
        for (i = 0; i < k; i++) {
            if (ee[i].getAttribute("name") == al) {
                e[l] = ee[i];
                l++;
            }
        }
        // aici am e si l; perhaps corecte;
    }
    else // end IE BUG; normal:
    {
        e = document.getElementsByName(al);
        l = e.length;
    }
    
    if (l > 0) {
        for (i = 0; i < l; i++) {
            // adica intotdeauna sa fie elementul urmat de elementul alerta if
			// the case pt ca sa pot remove fundalul de eroare
            if (e[0].previousSibling) 
                e[0].previousSibling.removeAttribute("style");
            e[0].parentNode.removeChild(e[0]);
        }
    }
    return l;// cate erat si eliminat
}

// validare data
function isvalidd_core(z, l, a){
    var vz = new Array();
    vz[1] = 31;
    if ((a % 4) == 0) 
        vz[2] = 29;
    else 
        vz[2] = 28;
    vz[3] = 31;
    vz[4] = 30;
    vz[5] = 31;
    vz[6] = 30;
    vz[7] = 31;
    vz[8] = 31;
    vz[9] = 30;
    vz[10] = 31;
    vz[11] = 30;
    vz[12] = 31;
    
    if (a < 1000 || a > 9999) 
        return false;
    if (l < 1 || l > 12) 
        return false;
    if (z < 1 || z > vz[l]) 
        return false;
    return true;
}

// afiseaza mesaj daca bool e true, la toate controalele date ; bool e calculat
// in ext, la apel
function isValidBOOL(msg, bool){
    var r = 1;
    var l, i, e, c;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpBOOLvalidare");
    // 2. validarea dupa controalele date - dar against aceeasi valoare de
	// nevalid;
    l = arguments.length;
    // argumentul 0 e mesaj, 1 e valoarea de nevalid pt care testez
    for (i = 2; i < l; i++) {
        // alert(arguments[i].id);
        // e = document.getElementById(arguments[i].id);
        e = arguments[i];// transmis chiar elementul - de vazut if merge pe
							// ie
        if (bool) {
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpBOOLvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// especial pentru select: mesaj, retur 0 in cazul in care optiunea selectata e
// chiar cea nevalid
function isValidSel(msg, nevalid){
    var r = 1;
    var l, i, e, c;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpSelvalidare");
    // 2. validarea dupa controalele date - dar against aceeasi valoare de
	// nevalid;
    l = arguments.length;
    // argumentul 0 e mesaj, 1 e valoarea de nevalid pt care testez
    for (i = 2; i < l; i++) {
        // alert(arguments[i].id);
        // e = document.getElementById(arguments[i].id);
        e = arguments[i];// transmis chiar elementul - de vazut if merge pe
							// ie
        if (e.options[e.selectedIndex].value == nevalid) {
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpSelvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}
//v2 - cu less than pe conditie - sunt cazuri cand am nevoie de domenii de valori, etc
function isValidSelLt(msg, nevalid){
    var r = 1;
    var l, i, e, c;

    isRmAlert("isgrpSelLtvalidare");

    l = arguments.length;

    for (i = 2; i < l; i++) {

        e = arguments[i];// transmis chiar elementul - de vazut if merge pe
							// ie
        if (e.options[e.selectedIndex].value < nevalid) {

            e.style.background = "#ffd0d0";
            c = document.createElement(tagalert);

            c.className = "alerta";
            c.setAttribute("name", "isgrpSelLtvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul

            e.parentNode.appendChild(c);

            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// daca e bifat checkboxul e ok, altfel nu
function isValidChk(msg){
    var r = 1;
    var l, i, e, c;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpChkvalidare");
    // 2. validarea dupa controalele date - dar against aceeasi valoare de
	// nevalid;
    l = arguments.length;
    // argumentul 0 e mesaj, 1 e valoarea de nevalid pt care testez
    for (i = 1; i < l; i++) {
        // alert(arguments[i].id);
        // e = document.getElementById(arguments[i].id);
        e = arguments[i];// transmis chiar elementul - de vazut if merge pe
							// ie
        if (!e.checked) {
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpChkvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare X, non empty: 1 sau 0+msg
function isValidX(msg){
    var r = 1;
    // var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpXvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        // e = document.getElementById(arguments[i].name);
        // s = arguments[i].value;//select nu are value
        s = e.value;
        // if not ok - orice, mai putin spatieri
        if (s.replace(/\ /g, "") == "") {
            // caz de eroare, afisez alerta
            // e = document.getElementById(arguments[i].name);
            // if (e.nodeName == "INPUT") {
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpXvalidare");// asta merge si pe
														// msie! nodeName e
														// readonly - de aia
														// oare?
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare Telefon, fax, non empty
function isValidT(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpTvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        // e = document.getElementById(arguments[i].id);
        s = arguments[i].value;// select nu are value
        if ((s == "") || (s.replace(/[\+]{0,1}[0-9]{2}[0-9\-\.\ ]*/, "") != "")) {
            // caz de eroare, afisez alerta
            // e = document.getElementById(arguments[i].name);
            // if (e.nodeName == "INPUT") {
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpTvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare N, non empty; numar natural de vazut analog si pt float, etc
function isValidN(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpNvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        // e = document.getElementById(arguments[i].id);
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[0-9]+/, "") != "")) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpNvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// ???validare pe numeric non zero (select)- util de ex la combo/selecturi,
// checkbox, radio, etc;
function isValidNZS(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpNZSvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[0-9]+/, "") != "") || parseInt(s, 10) <= 0) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpNZSvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// valid float
function isValidF(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpFvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[0-9]+[\.]{0,1}[0-9]+/, "") != "") || parseFloat(s) <= 0) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpFvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare A, non empty; alfabetic
function isValidA(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpAvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[a-zA-Z_]{1}[a-zA-Z\-\(\)\!\?\/\ \{\}\:\;\,\%\&\*_\=]*/, "") != "")) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpAvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare AN, non empty; alfanumeric
function isValidAN(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpANvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[a-zA-Z_]{1}[a-zA-Z0-9\-_]*/, "") != "")) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpANvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare Email, non empty
function isValidE(msg){
    var r = 1;
    var s, e, c, l, i;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpEvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e mesajul
    for (i = 1; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;// select nu are value
        // if not ok
        if ((s == "") || (s.replace(/[a-zA-Z0-9_][a-zA-Z0-9._-]*@[a-zA-Z0-9-_.]+\.[a-zA-Z]{2,4}/, "") != "")) {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpEvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
        else 
            r *= 1;
    }
    return r;
}

// validare data, not empty; parametri: lang si string formatul
function isValidD(msg, fmt){
    var r = 1;
    var s, e, c, l, i, re;
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpDvalidare");
    // 2. validarea dupa toate argumentele
    l = arguments.length;
    // argumentul 0 e lang
    // argumentul 1 e formatul
    for (i = 2; i < l; i++) {
        e = arguments[i];
        s = arguments[i].value;
        err_param = false;
        if (fmt == "d/m/Y") // i.e. dd/mm/YYYY
        {
            re = /([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})/;
            if (k = s.match(re)) {
                ziua = parseInt(k[1], 10);
                luna = parseInt(k[2], 10);
                anul = parseInt(k[3], 10);// k[0] e expresia insasi
            }
            else {
                err_param = true;
            }
        }
        else {
            // inainte de err true: verificari pt celelalte sabloane posibile,
			// etc;
            err_param = true;
        }
        // aici avem zi luna an de verificat
        if (!err_param && (s != "") && isvalidd_core(ziua, luna, anul)) 
            r *= 1;// oarecumva inversat; explicatie: la sau face evaluare
					// totala, la si progresiva;
        else {
            // caz de eroare, afisez alerta
            // e.setAttribute("style", "background-color:
			// #ffd0d0;");//nesuportat de insuportabilul msie; asadar:
            e.style.background = "#ffd0d0";
            // }
            // pregatesc elementul/textul relatie tata fiu: span cu clasa si
			// text. elegant.
            c = document.createElement(tagalert);
            // c.setAttribute("class", "alerta");//nesuportat de insuportabilul
			// msie; asadar:
            c.className = "alerta";
            c.setAttribute("name", "isgrpDvalidare");
            c.appendChild(document.createTextNode(msg));// mesajul
            // sibling deci la elementul eronat plasez alerta
            e.parentNode.appendChild(c);
            // return 0;//prima eroare -iese afara; altfel cata aller erorile,
			// le marcheaza and gata
            r *= 0;
        }
    }
    return r;
}

// a doua functie de validare data: aici validez o singura data, data ca si zi,
// luna, an si atasez alerta la elem precizat
// atentie: aici colorarea e la parinte nu la elem!!! iar elem e de fapt
// parentnode al unuia dintre controalele care compun data
// index e un numarator de controale, daca sunt mai multe la fel, sa se stie
// care e acela/textul apartinator lui
function isValidD2(msg, ziua, luna, anul, elem, index){
    var r = 1;
    
    // 1. elimin nodurile din grupa....
    isRmAlert("isgrpD2validare" + index);
    // aici avem zi luna an de verificat
    if (isvalidd_core(ziua, luna, anul)) 
        r *= 1;
    else {
        // caz de eroare, afisez alerta
        // elem.style.background = "#ffd0d0";
        // pregatesc elementul/textul relatie tata fiu: span cu clasa si text.
		// elegant.
        c = document.createElement(tagalert);
        c.className = "alerta";
        c.setAttribute("name", "isgrpD2validare" + index);
        c.appendChild(document.createTextNode(msg));// mesajul
        // sibling undeva deci la elementul eronat plasez alerta
        elem.parentNode.appendChild(c);
        // return 0;//prima eroare -iese afara; altfel cata aller erorile, le
		// marcheaza and gata
        r *= 0;
    }
    return r;
}

// traducere de caractere, in special cele cu probleme
function htmlentities(s){
    // var s =new String;
    s = s.replace(/(')/g, "&#39;");
    s = s.replace(/(")/g, "&quot;");
    s = s.replace(/(<)/g, "&lt;");
    s = s.replace(/(>)/g, "&gt;");
    return s;
}

// functia inversa lui htmlentities
function html_entity_decode(s){
    // var s =new String;
    s = s.replace(/(&#39;)/g, "\'");
    s = s.replace(/(&quot;)/g, '\"');
    s = s.replace(/(&lt;)/g, "<");
    s = s.replace(/(&gt;)/g, ">");
    return s;
}
function no_quot(s)
{
    s = s.replace(/(')/g, "&#39;");
    s = s.replace(/(")/g, "&quot;");
    return s;

}

// ////////////////////////////////////////////////////
// probe///////////////////////////////////////////////
var alt = new Array();
var flip = 1;// bascula;
var request;

// actualizare continut, no submit, sta pe loc.
/*
 * function nosubmit(){ //era cu but save document.xx.save.click();
 * document.xx.inp.focus(); return false; }
 */
// intra in mod editare -
function enterEdit(){
    var id = this.getAttribute('id');
    // id transmis e o serie de parametridelimitati de ceva;pe de alta parte id
	// unic per doc.
    // aici prin id transmis lang si id_msg
    var pos = id.indexOf('o');
    var key1 = id.substr(pos + 1);// id_msg
    var key2 = id.substr(0, pos);// lang
    var params = this.getAttribute('name');
    // var who = document.getElementById(id);//adica:
    var who = this;
    
    if (null == id) 
        return true;// nu fac nimic - nu a dat id, nu ma ating de celula
    // un fel de trim: eliminare spatii
    // if (params)
    // params = params.replace(/\ /g, "");
    // else
    // params = "";
    
    // if (params !== "")
    // params = "?" + params;
    // si astfel sirul de parametri e sau nu e deloc
    
    // if (!this.firstChild.name)//nu am form inca in document
    if (!document.getElementById('i' + id) || flip == 0)// nu am form inca in
														// document sau caz de
														// bascula: pe un camp
														// fac pe flip=1, pe
														// altul 0 dupa cum
														// vreua sa basculeze
														// sau nu.
        if (!who) 
            return false;
        else {
            gasit = false;
            in_editare = false;
            index = 0;
            l = alt.length;
            i = 0;
            while (i < l) {
                if (alt[i][1] == id) {
                    gasit = true;
                    index = i;
                    if (alt[i][2] == 0) 
                        in_editare = false;
                    else 
                        in_editare = true;
                }
                else // inchid restul
                     if (alt[i][2] == 1) {
                        // alert('closing edit session2');
                        // daca nu copiez valoarea din form inseamna ca la
						// inchidere se pastreaza valoarea care a fost
                        // alt[i][0] = document.xx.inp.value;
                        /*
						 * w = document.getElementById(alt[i][1]); w.innerHTML =
						 * html_entity_decode(alt[i][0]); alt[i][2] = 0;
						 */
                        // schimbat in
                        // problema nerezolvata: vine de la elem x, cu params x
						// dar in enter edit deja incearca sa execute params y
						// cu valorile de la parmas x;
                        // problema rezolvata; parametrizat tot ce se transmite,
						// a.i. fiecare pleaca cu setul lui de valori;
                        if (alt[i][0] !== htmlentities(document.xx.inp.value)) // aici
																				// la
																				// copierea
																				// val
																				// din
																				// input
																				// de
																				// facut
																				// ceva
																				// de
																				// genul
																				// htmlentities;
// erat; schimbat forma interogarii, ordinea campurilor if (0 == sqlExec(params,
// alt[i][3], alt[i][4], no_quot(document.xx.inp.value))) { // sqlExec('update
// isgrup set descriere=\'' + document.xx.inp.value + '\' where ' + params);
                            if (0 == sqlExec(alt[i][5], no_quot(document.xx.inp.value), alt[i][3], alt[i][4] )) { // sqlExec('update
																													// isgrup
																													// set
																													// descriere=\''
																													// +
																													// document.xx.inp.value
																													// +
																													// '\'
																													// where
																													// ' +
																													// params);
                                alt[i][0] = htmlentities(document.xx.inp.value);// punem
																				// si
																				// aici
																				// htmlentities??da.
                            }
                        w = document.getElementById(alt[i][1]);
                        w.innerHTML = html_entity_decode(alt[i][0]);
                        alt[i][2] = 0;
                        
                    }
                i++;
            }
            if (gasit) {
            
                if (in_editare) {
                    // alert('closing edit session1');
                    // copiez noua valoare din form in document, daca am reusit
					// salvarea cu succes
                    if (alt[index][0] !== htmlentities(document.xx.inp.value)) // aici
																				// la
																				// copierea
																				// val
																				// din
																				// input
																				// de
																				// facut
																				// ceva
																				// de
																				// genul
																				// htmlentities;
// erat; schimbat forma interogarii, ordinea campurilor if (0 == sqlExec(params,
// alt[index][3], alt[index][4], no_quot(document.xx.inp.value))) { //important:
// erat: htmlentities(document.xx.inp.value); scos htmlentities din cauza ca la
// utf8 nu merge bine, face harceaparcea sirul salvat;// sqlExec('update isgrup
// set descriere=\'' + document.xx.inp.value + '\' where ' + params);
                        if (0 == sqlExec(alt[index][5], no_quot(document.xx.inp.value), alt[index][3], alt[index][4])) { // sqlExec('update
																															// isgrup
																															// set
																															// descriere=\''
																															// +
																															// document.xx.inp.value
																															// +
																															// '\'
																															// where
																															// ' +
																															// params);
                            alt[index][0] = htmlentities(document.xx.inp.value);// punem
																				// si
																				// aici
																				// htmlentities??da.
                        // alert(alt[index][0]);
                        }
                    who.innerHTML = html_entity_decode(alt[index][0]);
                    alt[index][2] = 0;
                }
                else {
                    alt[index][0] = htmlentities(who.innerHTML);
                    if ((lung = 0.89 * alt[index][0].length) > 50) 
                        lung = 50;
                    // era cu but save who.innerHTML = '<form name="xx"
					// method="POST" action="" onSubmit="return
					// nosubmit();"><input type="text" name="inp"
					// maxlength="400" size="' + lung + '" value="' +
					// alt[index][0] + '" id="i' + id + '" onClick="javascript:
					// flip=1;">&nbsp;<input type="button" name="save"
					// value="save" onClick="javascript: flip=0;"></form>';
                    who.innerHTML = '<form name="xx"><input type="text" name="inp" maxlength="400" size="' + lung + '" value="' + alt[index][0] + '" id="i' + id + '" onClick="javascript: flip=1;" onChange="javascript: flip=0;">&nbsp;&nbsp;[set]</form>';
                    alt[index][2] = 1;
                }
            }
            else// negasit - adaug elementul
            {
                alt[l] = new Array(htmlentities(who.innerHTML), id, 1, key1, key2, params);// campul3=1
																							// i.e.
																							// e in
																							// editare
																							// (0
																							// sau
																							// nedefinit
																							// inseamna
																							// ca
																							// nu e
																							// in
																							// editare
																							// sau
																							// a
																							// iesit
																							// din
																							// editare;
																							// adaugat
																							// param
																							// al
																							// 5-lea
																							// params
                if ((lung = 0.89 * alt[l][0].length) > 50) 
                    lung = 50;
                // era cu but save: who.innerHTML = '<form name="xx"
				// method="POST" action="" onSubmit="return nosubmit();"><input
				// type="text" name="inp" maxlength="400" size="' + lung + '"
				// value="' + alt[l][0] + '" id="i' + id + '"
				// onClick="javascript: flip=1;">&nbsp;<input type="button"
				// name="save" value="save" onClick="javascript:
				// flip=0;"></form>';
                who.innerHTML = '<form name="xx"><input type="text" name="inp" maxlength="400" size="' + lung + '" value="' + alt[l][0] + '" id="i' + id + '" onClick="javascript: flip=1;" onChange="javascript: flip=0;">&nbsp;&nbsp;[set]</form>';
            }
            return true;
        }
    
}

// adauga macheta de editare in situ pentru entitatea careia ii este asociat
// enterEdit
function addEditForm(){
    var altlist = document.getElementById("taltlist");// sectiunea delimitata
														// de id taltlist
    var altlistElements = altlist.getElementsByTagName("td");// elementele
																// din acea
																// sectiune,
																// elementele td
    // var altlistForms = altlist.getElementsByTagName("input");//butoanele de
	// submit save din form-urile respective fiecare din td de fapt
    
    for (var i = 0, l = altlistElements.length; i < l; i++) {
        altlistElements[i].onclick = enterEdit;
    }
}

// adaugare editare meniu
function NWEditMeniu(nivel, id){

    var w = window.open("./ameniu_edit.php?nivel=" + nivel + "&id=" + id, "intretinere_tabele_meniu", "alwaysRaised=yes, dependent=yes, directories=no, height=250, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																																			// 1.0,
																																																																			// 1.1
    w.focus();
}

function NWAddMeniu(nivel, id_parinte, usr_group){

    var w = window.open("./ameniu_edit.php?nivel=" + nivel + "&id_sup=" + id_parinte + "&usr_group=" + usr_group, "intretinere_tabele_meniu", "alwaysRaised=yes, dependent=yes, directories=no, height=250, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																																													// 1.0,
																																																																													// 1.1
    w.focus();
}

// un fel de zorder
function isResetChildrenBorderMSIE(elem, tag){
    // var nc = new Object();// sau fara lasand instantierea ad libitum
    if (nc = elem.firstChild) {
        if (nc.nodeName == tag) 
            nc.style.cssText = 'border: none;';
        
        while (nc = nc.nextSibling) {
            if (nc.nodeName == tag) 
                nc.style.cssText = 'border: none;';
        }
        return true;
    }
    return false;
}

// pune atributul dat cu valoarea data la totii copiii nodului
// adica numai width si heigth pentru ca functia de mai sus nu merge pe MSIE.
// sucks.
function isResetChildrenWidthHeightMSIE(elem, w, h, ro){
    var nc;
    
   if (nc = elem.firstChild) {
        nc.style.width = w + 'px';
        nc.style.height = h + 'px';
        if (ro) 
            nc.setAttribute("readOnly", ro);
        
        while (nc = nc.nextSibling) {
            nc.style.width = w + 'px';
            nc.style.height = h + 'px';
            if (ro) 
                nc.setAttribute("readOnly", ro);
        }
        return true;
    }
    return false;
}

function isPoliglotTextarea(id_textarea, id_link){
    var e = document.getElementById(id_textarea);
    var le = document.getElementById(id_link);

    isResetChildrenWidthHeightMSIE(e.parentNode, 0, 0, 'true');// aduc la 0, 0
																// tot
    e.style.width = 'auto';
    e.style.height = e.rows * 16 + 'px';// restaurez doar pe cel curent;
    e.removeAttribute("readOnly");// pt mai multe controale, actionate" in
									// grup", ca sa nu scrie "in spate", intr-un
									// control la care s-a ajuns cu tab dar nu e
									// vizibil.;
    e.focus();
    
    isResetChildrenBorderMSIE(le.parentNode, 'A');
    le.style.cssText = 'border: solid; border-width: 1px; border-color: #0000ff;';
}
// end zorder
// seteaza pe elementele nume_elem valoarea valoare; adica adauga pe child dupa
// ce l'a kilarit pe firstchild (if the case)
function SetTextNume(nume_elem, text){
    var i, l, ve;
    
    ve = document.getElementsByName(nume_elem);
    l = ve.length;
    for (i = 0; i < l; i++) {
        if (ve[i].firstChild) 
            ve[i].removeChild(ve[i].firstChild);
        ve[i].appendChild(document.createTextNode(text));
    }
    return true;
    // diferenta principala dintre functia asta si SetText e ca asta merge pe
	// nume nu pe id si asta e w3c compliant adica face cinstit append child,
	// etc;
}

// functia seteaza un text pentru un element dom precizat
function SetText(id, text){
    var dest = document.getElementById(id);
    dest.innerHTML = text;
}

// returneaza combo cascadat cu listele categoriilor pe nivele
function PopulareXCateg(tabel, nivele, id_dest, val){
    var url = 'ispopularexcateg.php';
    var post_data = '';
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
    // datele care vor fi transmise. in acest caz post; daca se schimba modul,
	// get;
    post_data = 'tabel=' + encodeURIComponent(htmlentities(String(tabel)));// al
																			// doilea
																			// parametru,
																			// id
																			// sau
																			// sir
																			// dupa
																			// caz
																			// se
																			// va
																			// vedea
																			// in
																			// procedura
    post_data += '&nivele=' + encodeURIComponent(htmlentities(String(nivele)));
    post_data += '&id_dest=' + encodeURIComponent(htmlentities(String(id_dest)));
    post_data += '&val=' + encodeURIComponent(htmlentities(String(val)));
    if(arguments.length > 4)
    {
        post_data += '&cu_alegeti=' + encodeURIComponent(htmlentities(String(arguments[4])));
    }
  
    // ajax cu post de data asta
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = sqlExecResponse;
        request.open("POST", url, false);// parametrul 3 asyncron sau
											// sincron: adica sa stea dupa el
											// rezultatul sau ba
        request.setRequestHeader("Content-Type", contentType);
        request.send(post_data);
        // alert(request.responseText);
        return request.responseText;
        // return true;
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = sqlExecResponse;
                request.open("POST", url, false);
                request.setRequestHeader("Content-Type", contentType);
                request.send(post_data);
                return request.responseText;
            // return true;
            }
        }
    return false;
}

// returneaza combo cu lista localitatilor din judetul judIndex
function PopulareLocalitati(pindex, tindex){
    var url = 'ispopulareloc.php';
    var post_data = '';
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
    // datele care vor fi transmise. in acest caz post; daca se schimba modul,
	// get;
    post_data = 'pindex=' + encodeURIComponent(htmlentities(String(pindex)));// al
																				// doilea
																				// parametru,
																				// id
																				// sau
																				// sir
																				// dupa
																				// caz
																				// se
																				// va
																				// vedea
																				// in
																				// procedura
    if (tindex) 
        post_data += '&tindex=' + encodeURIComponent(htmlentities(String(tindex)));
    
    // ajax cu post de data asta
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = sqlExecResponse;
        request.open("POST", url, false);// parametrul 3 asyncron sau
											// sincron: adica sa stea dupa el
											// rezultatul sau ba
        request.setRequestHeader("Content-Type", contentType);
        request.send(post_data);
        // alert(request.responseText);
        return request.responseText;
        // return true;
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = sqlExecResponse;
                request.open("POST", url, false);
                request.setRequestHeader("Content-Type", contentType);
                request.send(post_data);
                return request.responseText;
            // return true;
            }
        }
    return false;
}

// returneaza combo cu lista localitatilor din judetul judIndex
function PopulareJudete(pindex, tindex, ctrlgrup){
    var url = 'ispopularejud.php';
    var post_data = '';
    var contentType = "application/x-www-form-urlencoded; charset=UTF-8";
    
    // datele care vor fi transmise. in acest caz post; daca se schimba modul,
	// get;
    post_data = 'pindex=' + encodeURIComponent(htmlentities(String(pindex)));// al
																				// doilea
																				// parametru,
																				// id
																				// sau
																				// sir
																				// dupa
																				// caz
																				// se
																				// va
																				// vedea
																				// in
																				// procedura
    if (tindex) 
        post_data += '&tindex=' + encodeURIComponent(htmlentities(String(tindex)));
    if (ctrlgrup) 
        post_data += '&ctrlgrup=' + encodeURIComponent(htmlentities(String(ctrlgrup)));
    
    // ajax cu post de data asta
    if (window.XMLHttpRequest) {
        request = new XMLHttpRequest();
        request.onreadystatechange = sqlExecResponse;
        request.open("POST", url, false);// parametrul 3 asyncron sau
											// sincron: adica sa stea dupa el
											// rezultatul sau ba
        request.setRequestHeader("Content-Type", contentType);
        request.send(post_data);
        // alert(request.responseText);
        return request.responseText;
        // return true;
    }
    else 
        if (window.ActiveXObject) {
            request = new ActiveXObject("Microsoft.XMLHTTP");
            if (request) {
                request.onreadystatechange = sqlExecResponse;
                request.open("POST", url, false);
                request.setRequestHeader("Content-Type", contentType);
                request.send(post_data);
                return request.responseText;
            // return true;
            }
        }
    return false;
}
// functie care seteaza imaginea destinatie cu imaginea sursa
function isSetImg(id_sursa, id_dest)
{
	var dest = document.getElementById(id_dest);
	var sursa = document.getElementById(id_sursa);
	
	if (sursa) {
		dest.src = sursa.src;
	}
	return true;
	
}

// activeaza/dezactiveaza controalele cu id-ul dat
function isEnableCtrls()
{
	// primul argument boolean; true=enable, false=disable
	var enable = arguments[0];
	var l = arguments.length;
	
	
	if (l > 2)
	{
		for (var i = 1; i < l; i++)
		{
			if(e =  document.getElementById(arguments[i]))
			{
				if (enable)
				{
					e.removeAttribute('disabled');
				}
				else
				{
					e.setAttribute('disabled', 'true');
				}
			}
		}
	}
}

function AddEditDomOport(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adomoported.php?" + params, "domoport_", "alwaysRaised=yes, dependent=yes, directories=no, height=300, width=550, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    w.focus();
    return true;
}
//transfera inreg de la categ data la o categ selectata
function TransRecCateg(id, nivel, edit){
    var params = '';
    
    if (arguments.length == 3) // id est probabil add sau edit, altfel add
								// categ de rang 0
    {
        params = 'id=' + id + '&nivel=' + nivel + '&edit=' + edit;
    }
    
    var w = window.open("./adirfirmetrans.php?" + params, "dirfirmetrans_", "alwaysRaised=yes, dependent=yes, directories=no, height=500, width=650, location=no, menubar=no, resizable=yes, screenX=20, screenY=20, toolbar=no, scrollbars=yes");// js
																																																											// 1.0,
																																																											// 1.1
    w.focus();
    return true;
}

function SetZiua(dest, val){
    var t = document.getElementById(dest);//
    var vt = t.value;
    var re = /([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/;
    var ival = parseInt(val, 10);
    
    if (ival > 0 && ival < 32) {
        vt = vt.replace(re, val + "/$2/$3");
    }
    //	alert(vt+'--'+val);
    t.value = vt;
    
}

//seteaza anul cu validare intre limita inferioara si limita superioara relativ la anul curent
function SetAnul(dest, val, li, ls){
    var t = document.getElementById(dest);//
    var vt = t.value;
    var re = /([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/;
    var ival = parseInt(val, 10);
    var azi = new Date();
    var ancurent = azi.getFullYear();
    if (ival >= (ancurent - li) && ival <= (ancurent - ls))//i.e. individul are intre 12 si 70 de ani
    {
        vt = vt.replace(re, "$1/$2/" + val);
    }
    //	alert(vt+'--'+val);
    t.value = vt;
}

function SetLuna(dest, val){
    var t = document.getElementById(dest);//
    var vt = t.value;
    var re = /([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/;
    var ival = parseInt(val, 10);
    if (ival >= 0 && ival < 12)//i.e. de fapt always fiind selectie, dar nu se stie; poate se schimba
    {
        vt = vt.replace(re, "$1/" + (ival + 1) + "/$3");
    }
    //	alert(vt+'--'+val);
    t.value = vt;
}


//chk = true sau false - bun pt check uncheck dupa starea unui alt check
function CheckUncheckAll(nume, check)
{
	var elem = document.getElementsByName(nume);
	var i = 0, l = elem.length;
	//alert (l+'-'+check);
	if (arguments.length < 2) check = true;
	
	for (i = 0; i < l; i++)
	{
		elem[i].checked = check;
	}
	
}
