/**
 * This array is used to remember mark status of rows in browse mode
 */
 
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

var marked_row = new Array;

function expandDiv(divid){

      document.getElementById(divid).style.display = 'block';
  }
  
function collapseDiv(divid){

      document.getElementById(divid).style.display = 'none';
  }

 function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
    }else{
      document.getElementById(divid).style.display = 'none';
    }
  }
  
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function



function parseDate(input, format) {
	date = input.value;
	format = format.replace(/%/g, '');
	sep = format.charAt(1);
	yAt = format.indexOf('Y')
	// 1-1-06 or 1-12-06 or 1-1-2006 or 1-12-2006
	if(date.match(/^\d{1,2}[\/-]\d{1,2}[\/-]\d{2,4}$/) && yAt == 4) {
		if(date.match(/^\d{1}[\/-].*$/)) date = '0' + date;
		if(date.match(/^\d{2}[\/-]\d{1}[\/-].*$/)) date = date.substring(0,3) + '0' + date.substring(3,date.length);
		if(date.match(/^\d{2}[\/-]\d{2}[\/-]\d{2}$/)) date = date.substring(0,6) + '20' + date.substring(6,date.length);
	}
	// 06-11-1 or 06-1-1
	else if(date.match(/^\d{2,4}[\/-]\d{1,2}[\/-]\d{1,2}$/)) {
		if(date.match(/^\d{2}[\/-].*$/)) date = '20' + date;
		if(date.match(/^\d{4}[\/-]\d{1}[\/-].*$/)) date = date.substring(0,5) + '0' + date.substring(5,date.length);		
		if(date.match(/^\d{4}[\/-]\d{2}[\/-]\d{1}$/)) date = date.substring(0,8) + '0' + date.substring(8,date.length);		
	}
	else if(date.match(/^\d{4,8}$/)) { // digits only
		digits = 0;
		if(date.match(/^\d{8}$/)) digits = 8;// match for 8 digits
		else if(date.match(/\d{6}/)) digits = 6;// match for 5 digits
		else if(date.match(/\d{4}/)) digits = 4;// match for 5 digits
		else if(date.match(/\d{5}/)) digits = 5;// match for 5 digits
		
		switch(yAt) {
			case 0:
				switch(digits) {
					case 4: date = '20' + date.substring(0,2) + sep + '0' + date.substring(2, 3) + sep + '0' + date.substring(3,4); break;
					case 5: date = '20' + date.substring(0,2) + sep + date.substring(2, 4) + sep + '0' + date.substring(4,5); break;
					case 6: date = '20' + date.substring(0,2) + sep + date.substring(2, 4) + sep + date.substring(4,6); break;				
					case 8: date = date.substring(0,4) + sep + date.substring(4, 6) + sep + date.substring(6,8); break;
				}
				break;
			case 2:
				switch(digits) {
					case 4: date = '0' + date.substring(0,1) + sep + '20' + date.substring(1, 3) + sep + '0' + date.substring(3,4); break;
					case 5: date = date.substring(0,2) + sep + '20' + date.substring(2, 4) + sep + '0' + date.substring(4,5); break;
					case 6: date = date.substring(0,2) + sep + '20' + date.substring(2, 4) + sep + date.substring(4,6); break;				
					case 8: date = date.substring(0,2) + sep + date.substring(2, 6) + sep + date.substring(6,8); break;
				}
			case 4:
				switch(digits) {
					case 4: date = '0' + date.substring(0,1) + sep + '0' + date.substring(1, 2) + sep + '20' + date.substring(2,4); break;
					case 5: date = '0' + date.substring(0,1) + sep + date.substring(1, 3) + sep + '20' + date.substring(3,5); break;
					case 6: date = date.substring(0,2) + sep + date.substring(2, 4) + sep + '20' + date.substring(4,6); break;				
					case 8: date = date.substring(0,2) + sep + date.substring(2, 4) + sep + date.substring(4,8); break;
				}
				break;
		}
	}
	date = date.replace(/[\/-]/g, sep);
	input.value = date;
}







function clearForm(frm){
	frm.reset();
}

function resetForm(frm) {
	for (i=0;i<frm.elements.length;i++){
		var element=frm.elements[i];
		if (element.type=='text')
		{
			element.value="";
		}
		if (element.type=='select-one')
		{
			element.selectedIndex = 0;
		}
	}
}

function sendForm(frm){
	var i;
	var trimite=1;
	var p1,p2; //vor tine parola si confirmarea parolei
	//alert(frm.elements.length);
	for (i=0;i<frm.elements.length;i++){
		var element=frm.elements[i];
		//alert(element.type);
		if (element.type=='text' && element.title=='Obligatoriu'
			&& (!element.value
			|| element.value.length == 0))
		{
			trimite=0;
			alert('Va rugam sa completati campul ' + element.name);
			
		}
		//if (element.type=='select-one') alert(element.options[element.selectedIndex].value);
		if (element.type=='select-one' && element.title=='Obligatoriu'
			&& (!element.options[element.selectedIndex].value
			|| element.options[element.selectedIndex].value.trim().length == 0))
		{
			trimite=0;
			alert('Va rugam sa completati campul ' + element.name);
			
		}
		if (element.title=='Parola')
			p1=element.value;
		if (element.title=='Parola_confirm')
			p2=element.value;
		
	}

	if (p1 && p2 && p1!=p2){
		trimite=0;
		alert('Va rugam, confirmati corect parola');
	}
	
	if (trimite==1)
		frm.submit();
}

function setOrder(frm,orderby){
	frm.elements['orderby'].value=orderby;
	//alert (frm.elements['orderval'].value);
	if (frm.elements['orderval'].value=='ASC')
		frm.elements['orderval'].value='DESC';
	else
		frm.elements['orderval'].value='ASC';
	//alert (frm.elements['orderval'].value);
	sendForm(frm);
}


function anotherPage(frm,offset){
	//trebuie sa scot celalalt offset daca exista din action
	frm.action+='&offset='+offset;
	sendForm(frm);
}

function firstPage(frm){
	frm.action+='&offset=0';
	sendForm(frm);
}


function del(rec_id){
	var conf=confirm("Sunteti sigur ca doriti stergerea acestui element ?");
	if (conf){
		row_id=rec_id; //row_id = id-ul definit global in ajax_server.js. Ca sa stie ce rand sa stearga din DOM
		var sUrl = "ajax_del.php?id="+rec_id;
		
		//divId='continut';
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, delRand);
	}
}

function dup(rec_id){
	var conf=confirm("Sunteti sigur ca doriti duplicarea acestui element ?");
	if (conf){
		row_id=rec_id; //row_id = id-ul definit global in ajax_server.js. Ca sa stie ce rand sa adauge din DOM
		var sUrl = "ajax_dup.php?id="+rec_id;

		//divId='continut';
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, dupRand);
	}
}

function actualizare_curs_valutar(){
	var conf=confirm("Sunteti sigur ca doriti actualizarea cursului valutar pentur ziua in curs ?");
	if (conf){
		var sUrl = "auto_update.php?";
		divId="rasp_update_curs_valutar"; //div-ul in care se va scrie raspunsul
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, upd_curs_valutar);
	}
	
}


function populeazaNod(id){  //afla fiii unui nod din tabelul locatii
		
		var sUrl = "../util/ajax_getCopii.php?id="+id;
		syncRequest(sUrl);
		return getRaspunsSync();
		
}



function populeazaSelectDinTree(id,idModif,numeModif){ //primeste id-ul parintelui si afiseaza copiii
	//idModif ->va primi id-ul
	//numeModif ->va primi valoarea coresp id-ului
	var sUrl = "../util/ajax_PopuleazaSelectDinTree.php?id="+id+"&idModif="+idModif+"&numeModif="+numeModif;
	divId=numeModif;
	//divId="div_loc_prt_id"; //div-ul in care se va scrie raspunsul
	var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, p_SelectDinTree);
}

var nr_el=1000000000;
function addSupplement(form){
	
	input1=	document.createElement('input');
	input1.setAttribute('name','nume_supliment_' + nr_el);
	input1.setAttribute('id','nume_supliment_' + nr_el);
	input1.setAttribute('type','text');
	input1.setAttribute('value',form.nume_supliment.value);
	
	
	input2=	document.createElement('input');
	input2.setAttribute('name','valoare_supliment_' + nr_el);
	input2.setAttribute('id','valoare_supliment_' + nr_el);
	input2.setAttribute('type','text');
	input2.setAttribute('value',form.valoare_supliment.value);

	input3=	document.createElement('input');
	input3.setAttribute('name','sterge_supliment_' + nr_el);
	input3.setAttribute('id','sterge' + nr_el);
	input3.setAttribute('type','button');
	input3.setAttribute('value','Sterge');
	input3.setAttribute('onClick','remSupplement('+nr_el+', \'tabel1\');');

	form.nume_supliment.value='';
	form.valoare_supliment.value='';
	
	
	td1=document.createElement('td');
	td1.setAttribute('class','tabDetailViewDL');
	td1.setAttribute('colspan','2');

	td2=document.createElement('td');
	td2.setAttribute('class','tabDetailViewDL');
	td2.setAttribute('colspan','2');

	td1.appendChild(input1);
	td2.appendChild(input2);
	td2.appendChild(input3);
	
	var randReper=document.getElementById('rand_buton_suplimente');
	var indexInsert=randReper.rowIndex;
		
	tr=document.getElementById('tabel1').insertRow(indexInsert);
	tr.setAttribute('id','rand_tabel'+nr_el);
	tr.appendChild(td1);
	tr.appendChild(td2);
	
	nr_el++;
}

//var nr_elr=1000000000;
var nr_elr=0;
function addRed(form){

	input1=	document.createElement('input');
	input1.setAttribute('name','nume_reducere_' + nr_elr);
	input1.setAttribute('id','nume_reducere_' + nr_elr);
	input1.setAttribute('type','text');
	input1.setAttribute('value',form.nume_reducere.value);

	input2=	document.createElement('input');
	input2.setAttribute('name','valoare_reducere_' + nr_elr);
	input2.setAttribute('id','valoare_reducere_' + nr_elr);
	input2.setAttribute('type','text');
	input2.setAttribute('value',form.valoare_reducere.value);

	input3=	document.createElement('input');
	input3.setAttribute('name','sterge_reducere_' + nr_elr);
	input3.setAttribute('id','sterge' + nr_elr);
	input3.setAttribute('type','button');
	input3.setAttribute('value','Sterge');
	input3.setAttribute('onClick','remRed('+nr_elr+', \'tabel1\');');

	form.nume_reducere.value='';
	form.valoare_reducere.value='';


	td1=document.createElement('td');
	td1.setAttribute('class','tabDetailViewDL');
	td1.setAttribute('colspan','2');

	td2=document.createElement('td');
	td2.setAttribute('class','tabDetailViewDL');
	td2.setAttribute('colspan','2');

	td1.appendChild(input1);
	td2.appendChild(input2);
	td2.appendChild(input3);

	var randReper=document.getElementById('rand_buton_reduceri');
	var indexInsert=randReper.rowIndex;

	tr=document.getElementById('tabel1').insertRow(indexInsert);
	tr.setAttribute('id','rand_tabelr'+nr_elr);
	tr.appendChild(td1);
	tr.appendChild(td2);

	nr_elr++;
}

var randuriDefaultSejururi=9;
var randuriDefaultCircuite=7;
function addSubSupplement(form,tabelNr,sc){
	// TabelNr e de forma xxx unde xxx e instanta sejurului/circuitului
	//sc = 's' daca e apelat pt generarea de sejururi 
	//sc = 'c' daca e apelat la generarea de circuite
	nrTotalRanduri=document.getElementById('subtabel_'+tabelNr).rows.length;
	if (sc=='s')
		nr_el=nrTotalRanduri-randuriDefaultSejururi //nr de suplimente deja existente in tabelul asta
	else
		nr_el=nrTotalRanduri-randuriDefaultCircuite //nr de suplimente deja existente in tabelul asta
	
	//verific sa nu mai existe un supliment cu id-ul cu care vreau eu sa il creez
	while (document.getElementById('nume_supliment_' +tabelNr + '_' + nr_el) != null)
		nr_el++;
	
	if (document.getElementById('supmax_'+tabelNr)) //supmax_xxx tine minte ultimul supliment ca sa stiu unde ma opresc la inset
		document.getElementById('supmax_'+tabelNr).value=nr_el;
		
	
	
	input1=	document.createElement('input');
	input1.setAttribute('name','nume_supliment_' +tabelNr + '_' + nr_el);
	input1.setAttribute('id','nume_supliment_' +tabelNr + '_' + nr_el);
	input1.setAttribute('type','text');
	var n_tx='nume_supliment_'+tabelNr+'_0';
	var v_tx='valoare_supliment_'+tabelNr+'_0';
	var n_ob=document.getElementById(n_tx);
	var v_ob=document.getElementById(v_tx);
	input1.setAttribute('value',n_ob.value);
	
	input2=	document.createElement('input');
	input2.setAttribute('name','valoare_supliment_' +tabelNr + '_' + nr_el);
	input2.setAttribute('id','valoare_supliment_' +tabelNr + '_' + nr_el);
	input2.setAttribute('type','text');
	input2.setAttribute('value',v_ob.value);
    n_ob.value='';
	v_ob.value='';
	input3=	document.createElement('input');
	input3.setAttribute('name','sterge_supliment_' +tabelNr + '_' + nr_el);
	input3.setAttribute('type','button');
	input3.setAttribute('value','Sterge');
	input3.setAttribute('onClick','remSupplement(\''+tabelNr + '_' + nr_el+ '\',\'' + 'subtabel_'+tabelNr+'\');');

	td1= document.createElement('td');
	td1.setAttribute('class','tabDetailViewDL');
	td1.setAttribute('colspan','2');

	
	td2=document.createElement('td');
	td2.setAttribute('class','tabDetailViewDL');
	td2.setAttribute('colspan','2');

	td1.appendChild(input1);
	td2.appendChild(input2);
	td2.appendChild(input3);
	
	var randReper=document.getElementById('rand_buton_suplimente'+tabelNr);
	var indexInsert=randReper.rowIndex-1;
		
	tr=document.getElementById('subtabel_'+tabelNr).insertRow(indexInsert);
	tr.setAttribute('id','rand_tabel'+tabelNr + '_' + nr_el);
	tr.appendChild(td1);
	tr.appendChild(td2);
	
}

function addSubRed(form,tabelNr,sc){
	// TabelNr e de forma xxx unde xxx e instanta sejurului/circuitului
	//sc = 's' daca e apelat pt generarea de sejururi
	//sc = 'c' daca e apelat la generarea de circuite
	nrTotalRanduri=document.getElementById('subtabel_'+tabelNr).rows.length;
	if (sc=='s')
		nr_el=nrTotalRanduri-randuriDefaultSejururi //nr de suplimente deja existente in tabelul asta
	else
		nr_el=nrTotalRanduri-randuriDefaultCircuite //nr de suplimente deja existente in tabelul asta

	//verific sa nu mai existe un supliment cu id-ul cu care vreau eu sa il creez
	while (document.getElementById('nume_reducere_' +tabelNr + '_' + nr_el) != null)
		nr_el++;

	if (document.getElementById('redmax_'+tabelNr)) //supmax_xxx tine minte ultimul supliment ca sa stiu unde ma opresc la insert
		document.getElementById('redmax_'+tabelNr).value=nr_el;



	input1=	document.createElement('input');
	input1.setAttribute('name','nume_reducere_' +tabelNr + '_' + nr_el);
	input1.setAttribute('id','nume_reducere_' +tabelNr + '_' + nr_el);
	input1.setAttribute('type','text');
	var n_tx='nume_reducere_'+tabelNr+'_0';
	var v_tx='valoare_reducere_'+tabelNr+'_0';
	var n_ob=document.getElementById(n_tx);
	var v_ob=document.getElementById(v_tx);
	input1.setAttribute('value',n_ob.value);

	input2=	document.createElement('input');
	input2.setAttribute('name','valoare_reducere_' +tabelNr + '_' + nr_el);
	input2.setAttribute('id','valoare_reducere_' +tabelNr + '_' + nr_el);
	input2.setAttribute('type','text');
	input2.setAttribute('value',v_ob.value);
    n_ob.value='';
	v_ob.value='';
	input3=	document.createElement('input');
	input3.setAttribute('name','sterge_reducere_' +tabelNr + '_' + nr_el);
	input3.setAttribute('type','button');
	input3.setAttribute('value','Sterge');
	input3.setAttribute('onClick','remRed(\''+tabelNr + '_' + nr_el+ '\',\'' + 'subtabel_'+tabelNr+'\');');

	td1= document.createElement('td');
	td1.setAttribute('class','tabDetailViewDL');
	td1.setAttribute('colspan','2');


	td2=document.createElement('td');
	td2.setAttribute('class','tabDetailViewDL');
	td2.setAttribute('colspan','2');

	td1.appendChild(input1);
	td2.appendChild(input2);
	td2.appendChild(input3);

	var randReper=document.getElementById('rand_buton_reduceri'+tabelNr);
	var indexInsert=randReper.rowIndex-1;

	tr=document.getElementById('subtabel_'+tabelNr).insertRow(indexInsert);
	tr.setAttribute('id','rand_tabelr'+tabelNr + '_' + nr_el);
	tr.appendChild(td1);
	tr.appendChild(td2);

}

function remSupplement(id,tabel){
	var tinta=document.getElementById(tabel);
	for(i=0; i<tinta.rows.length; i++)
	{
      if(tinta.rows[i].id==('rand_tabel'+id))
        var rand=tinta.rows[i];
    }
	tinta.deleteRow(rand.rowIndex);
}

function remRed(id,tabel){
	var tinta=document.getElementById(tabel);
	for(i=0; i<tinta.rows.length; i++)
	{
      if(tinta.rows[i].id==('rand_tabelr'+id))
        var rand=tinta.rows[i];
    }
	tinta.deleteRow(rand.rowIndex);
}

var nr_elc=1000000000;




var nr_stop=1000000000;
function addStop(form){

	var i=0;
	
	var numeLocatieEscala=document.getElementById('nume_locatie_escala').innerHTML;


    /*spanAfisare= document.createElement('span');
   	spanAfisare.setAttribute('class','buttona');
	spanAfisare.setAttribute('onClick','YAHOO.example.myPanel.show();');
	spanAfisare.inneHTML='Afiseaza lista';

    spanAscundere= document.createElement('span');
   	spanAscundere.setAttribute('class','buttona');
	spanAscundere.setAttribute('onClick','YAHOO.example.myPanel.hide();');
	spanAscundere.inneHTML='Ascunde lista';*/

	input1=	document.createElement('input');
	input1.setAttribute('name','locatie_escala_' + nr_stop);
	input1.setAttribute('type','hidden');
	input1.setAttribute('value',form.locatie_escala.value);

	div1= document.createElement('div');
	div1.setAttribute('class','selected');
	div1.setAttribute('id','nume_locatie_escala_'+nr_stop);
	div1.innerHTML=numeLocatieEscala;

	input2=	document.createElement('input');
	input2.setAttribute('name','zi_escala_' + nr_stop);
	input2.setAttribute('type','text');
	input2.setAttribute('value',form.zi_escala.value);

	input3=	document.createElement('input');
	input3.setAttribute('name','ora_escala_' + nr_stop);
	input3.setAttribute('type','text');
	input3.setAttribute('value',form.ora_escala.value);

	input4=	document.createElement('select');
	input4.setAttribute('name','esc_status_' + nr_stop);

	var optiune=document.createElement('option');
    optiune.text='Activ';
	optiune.value='1';
	input4.add(optiune, null);

	var optiune=document.createElement('option');
    optiune.text='Inactiv';
	optiune.value='0';
	input4.add(optiune, null);

	if(form.esc_status.value==0)
      input4.selectedIndex=1;

	if(form.esc_status.value==1)
      input4.selectedIndex=0;


	input5=	document.createElement('input');
	input5.setAttribute('name','sterge_escala_' + nr_stop);
	input5.setAttribute('type','button');
	input5.setAttribute('value','Sterge');
	input5.setAttribute('onClick','remStop('+nr_stop+');');

	td1= document.createElement('td');
	td1.setAttribute('class','tabDetailViewDL');
	td1.appendChild(document.createTextNode('Locatie escala'));

	td2=document.createElement('td');
	td2.setAttribute('class','tabDetailViewDF');

	td3=document.createElement('td');
	td3.setAttribute('class','tabDetailViewDL');
	td3.appendChild(document.createTextNode('Zi escala'));

	td4=document.createElement('td');
	td4.setAttribute('class','tabDetailViewDF');

	td5= document.createElement('td');
	td5.setAttribute('class','tabDetailViewDL');
	td5.appendChild(document.createTextNode('Ora escala'));

	td6=document.createElement('td');
	td6.setAttribute('class','tabDetailViewDF');

	td7=document.createElement('td');
	td7.setAttribute('class','tabDetailViewDL');
	td7.appendChild(document.createTextNode('Status'));

	td8=document.createElement('td');
	td8.setAttribute('class','tabDetailViewDF');

    td2.appendChild(input1);
    //td2.appendChild(spanAfisare);
    //td2.appendChild(spanAscundere);
    td2.appendChild(div1);
	td4.appendChild(input2);
	td6.appendChild(input3);
	td8.appendChild(input4);

    td8.appendChild(input5);

	var randReper=document.getElementById('rand_buton_escale');
	var indexInsert=randReper.rowIndex-1;


	tr=document.getElementById('tabel1').insertRow(indexInsert);
	tr.setAttribute('id','rand_escala1_'+nr_stop);
	tr.appendChild(td1);
	tr.appendChild(td2);
	tr.appendChild(td3);
	tr.appendChild(td4);

	tr=document.getElementById('tabel1').insertRow(indexInsert);
	tr.setAttribute('id','rand_escala2_'+nr_stop);
	tr.appendChild(td5);
	tr.appendChild(td6);
	tr.appendChild(td7);
	tr.appendChild(td8);

	nr_stop++;
}

function remStop(id){
	var tinta=document.getElementById('tabel1');
    var rand=document.getElementById('rand_escala1_'+id);
	tinta.deleteRow(rand.rowIndex);
    var rand=document.getElementById('rand_escala2_'+id);
	tinta.deleteRow(rand.rowIndex);
}


var old_unicaz_loc_id=-1; //nu poate lua niciodata valoarea -1
function populeazaUnitatiCazare(unicaz_loc_id,sursa){
	if (arguments.length>=3)
		var Delimitator=arguments[2];
	else
		var Delimitator='';
											//delimitatorul face ca value=idDelimitatornume adica 1_hotelBulevard
												//sursa=selectul pe care sa il populeze
	if (old_unicaz_loc_id!=unicaz_loc_id){  //ca sa nu se incarce decat daca s-a schimbat locatia.
		old_unicaz_loc_id=unicaz_loc_id;   // altfel tot aceleasi hoteluri sunt si nu tb repopulata lista
		
		//executam functia care cauta in db hotelurile din loc_unicaz_id-ul selectat
		var sUrl = "../util/ajax_getUnitatiCazare.php?loc_id="+unicaz_loc_id+"&delim="+Delimitator;
		divId=sursa; //selectul care va fi populat cu option-uri
        if (arguments.length==4)
          var modLucru=arguments[3];
        else
          var modLucru='asincron';
        if(modLucru=='sincron')
        {
          syncRequest(sUrl);
          var request = getRaspunsSync();
          if (request!='Fara unitati de cazare')
          {
            eval(request);
            //stergem ce are selectul
            var sel= document.getElementById(divId);
            sel.options.length=0;
            sel.options[0] = new Option('Toate',''); //implicit
            var i; //populam cu ce s-a intors din php
            var j=0;
            for (i in arrUnicaz)
            {
              var curent=arrUnicaz[i];
              sel.options[j+1]= new Option(curent[1],curent[0]);
              j++;
            }
          }
          if (request=='Fara unitati de cazare')
          {
            var sel= document.getElementById(divId);
            sel.options.length=0;
            sel.options[0] = new Option('Fara unitati de cazare',''); //implicit
          }
        }
        else
        {
		  var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, p_UnitatiCazare);
        }
	}
}




function copiazaHidden(sursa, destinatie){
	document.getElementById(destinatie).value=document.getElementById(sursa).value;	
}

function generareCharterRetur(obj){
	if (obj.checked==true){
		obj.form.chadef_ret_start.disabled=false;
		obj.form.chadef_ret_stop.disabled=false;
		//document.getElementById('jscal_trigger4').setAttribute('onClick','');
	}
	else
	{
		obj.form.chadef_ret_start.disabled=true;
		obj.form.chadef_ret_stop.disabled=true;
	}
			
	
}


function construiesteChartere(id, dstart, dstop, cadenta, nr_locuri, nr_inmatriculare,durata,schema){  //afla fiii unui nod din tabelul locatii

		divId="tabel_instantiere_chartere"; //div-ul in care se va scrie raspunsul
		
		var sUrl = "generare_chartere.php?id=";
		if(id!=0){
		  sUrl=sUrl+id;
		}
		
		sUrl+='&dstart='+dstart+'&dstop='+dstop+'&cadenta='+cadenta+'&nr_locuri_alocate='+nr_locuri+'&nr_inmatriculare='+nr_inmatriculare+'&durata='+durata+'&schema='+schema;
		
		syncRequest(sUrl);
		var text=getRaspunsSync();
		
		tinta=document.getElementById(divId);
		tinta.innerHTML=text;
		
}

/*

function construiesteSejururi(id, dstart, dstop, cadenta, durata){  //afla fiii unui nod din tabelul locatii

		divId="tabel_instantiere_sejururi"; //div-ul in care se va scrie raspunsul
		
		var sUrl = "generare_sejururi.php?id=";
		if(id!=0){
		  sUrl=sUrl+id;
		}
		
		sUrl+='&dstart='+dstart+'&dstop='+dstop+'&cadenta='+cadenta+'&durata='+durata;
		
		syncRequest(sUrl);
		var text=getRaspunsSync();
		
		tinta=document.getElementById(divId);
		tinta.innerHTML=text;
		
}

*/




function copiazaHidden(sursa, destinatie){
	document.getElementById(destinatie).value=document.getElementById(sursa).value;	
}

function afisareCampuriCharterRetur(obj){
	if (obj.checked==true){
		obj.form.chadef_ret_start.disabled=false;
		obj.form.chadef_ret_stop.disabled=false;
		document.getElementById('chadef_ret_nume').className='dataField';
		document.getElementById('chadef_ret_start').className='dataField';
		document.getElementById('chadef_ret_stop').className='dataField';
		document.getElementById('chadef_ret_durata').className='dataField';
		
	
	}
	else
	{
		obj.form.chadef_ret_start.disabled=true;
		obj.form.chadef_ret_stop.disabled=true;
		document.getElementById('chadef_ret_nume').className='dataFieldDisabled';
		document.getElementById('chadef_ret_start').className='dataFieldDisabled';
		document.getElementById('chadef_ret_stop').className='dataFieldDisabled';
		document.getElementById('chadef_ret_durata').className='dataFieldDisabled';
		
	}
			
	
}






var nr_el=0;
function addUserFields(agentie){
	input1=	document.createElement('input');
	input1.setAttribute('name','usr_name_' + nr_el);
	input1.setAttribute('type','text');
	
	
	input2=	document.createElement('input');
	input2.setAttribute('name','usr_pass_' + nr_el);
	input2.setAttribute('type','password');
	input2.setAttribute('title','Parola');
	
	input3=	document.createElement('input');
	input3.setAttribute('name','usr_pass_conf_' + nr_el);
	input3.setAttribute('type','password');
	input3.setAttribute('title','Parola_confirm');
	


	input4=	document.createElement('input');
	input4.setAttribute('name','agetur_nume_' + nr_el);
	input4.setAttribute('type','text');
	input4.setAttribute('title','Obligatoriu');
	
	input5=	document.createElement('input');
	input5.setAttribute('name','agetur_cf_' + nr_el);
	input5.setAttribute('type','text');
	input5.setAttribute('title','Obligatoriu');
	
	input6=	document.createElement('input');
	input6.setAttribute('name','agetur_rc_' + nr_el);
	input6.setAttribute('type','text');
	input6.setAttribute('title','Obligatoriu');
	
	input7=	document.createElement('input');
	input7.setAttribute('name','agetur_adresa_' + nr_el);
	input7.setAttribute('type','text');
	input7.setAttribute('title','Obligatoriu');
	
	input8=	document.createElement('input');
	input8.setAttribute('name','agetur_telefon_' + nr_el);
	input8.setAttribute('type','text');
	input8.setAttribute('title','Obligatoriu');
	
	input9=	document.createElement('input');
	input9.setAttribute('name','agetur_fax_' + nr_el);
	input9.setAttribute('type','text');
	input9.setAttribute('title','Obligatoriu');
	
	input10=document.createElement('input');
	input10.setAttribute('name','agetur_email_' + nr_el);
	input10.setAttribute('type','text');
	input10.setAttribute('title','Obligatoriu');
	
		
	
	
	td11= document.createElement('td');
	td11.setAttribute('class','tabDetailViewDL');
	td11.appendChild(document.createTextNode('Username'));
	
	td12=document.createElement('td');
	td12.setAttribute('class','tabDetailViewDF');
	
	td13=document.createElement('td');
	td13.setAttribute('class','tabDetailViewDL');
	td13.appendChild(document.createTextNode('Agentie de turism'));
	
	td14=document.createElement('td');
	td14.setAttribute('class','tabDetailViewDF');
	td14.appendChild(document.createTextNode(agentie));
	

	
	td12.appendChild(input1);
	
	
	td21= document.createElement('td');
	td21.setAttribute('class','tabDetailViewDL');
	td21.appendChild(document.createTextNode('Parola'));
	
	td22=document.createElement('td');
	td22.setAttribute('class','tabDetailViewDF');
	
	td23=document.createElement('td');
	td23.setAttribute('class','tabDetailViewDL');
	td23.appendChild(document.createTextNode('Confirmare parola'));
	
	td24=document.createElement('td');
	td24.setAttribute('class','tabDetailViewDF');
	

	
	td22.appendChild(input2); //parola
	td24.appendChild(input3); //confirmarea
	
	
	td31= document.createElement('td');
	td31.setAttribute('class','tabDetailViewDL');
	td31.appendChild(document.createTextNode('Nume sucursala'));
	
	td32=document.createElement('td');
	td32.setAttribute('class','tabDetailViewDF');
	
	td33=document.createElement('td');
	td33.setAttribute('class','tabDetailViewDL');
	td33.appendChild(document.createTextNode('CF'));
	
	td34=document.createElement('td');
	td34.setAttribute('class','tabDetailViewDF');
	
	td32.appendChild(input4); //nume
	td34.appendChild(input5); //cf
	
	
	td41= document.createElement('td');
	td41.setAttribute('class','tabDetailViewDL');
	td41.appendChild(document.createTextNode('RC'));
	
	td42=document.createElement('td');
	td42.setAttribute('class','tabDetailViewDF');
	
	td43=document.createElement('td');
	td43.setAttribute('class','tabDetailViewDL');
	td43.appendChild(document.createTextNode('Adresa'));
	
	td44=document.createElement('td');
	td44.setAttribute('class','tabDetailViewDF');
	
	td42.appendChild(input6); //RC
	td44.appendChild(input7); //adresa
	
	
	td51= document.createElement('td');
	td51.setAttribute('class','tabDetailViewDL');
	td51.appendChild(document.createTextNode('Telefon'));
	
	td52=document.createElement('td');
	td52.setAttribute('class','tabDetailViewDF');
	
	td53=document.createElement('td');
	td53.setAttribute('class','tabDetailViewDL');
	td53.appendChild(document.createTextNode('Fax'));
	
	td54=document.createElement('td');
	td54.setAttribute('class','tabDetailViewDF');
	
	td52.appendChild(input8); //telefon
	td54.appendChild(input9); //fax
	
	
	td61= document.createElement('td');
	td61.setAttribute('class','tabDetailViewDL');
	td61.appendChild(document.createTextNode('Email'));
	
	td62=document.createElement('td');
	td62.setAttribute('class','tabDetailViewDF');
	
	td63=document.createElement('td');
	td63.setAttribute('class','tabDetailViewDL');
	td63.appendChild(document.createTextNode(' '));
	
	td64=document.createElement('td');
	td64.setAttribute('class','tabDetailViewDF');
	
	td62.appendChild(input10); //nume
	
	
	
	
	tr1=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr1.appendChild(td11);
	tr1.appendChild(td12);
	tr1.appendChild(td13);
	tr1.appendChild(td14);
	
	tr2=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr2.appendChild(td21);
	tr2.appendChild(td22);
	tr2.appendChild(td23);
	tr2.appendChild(td24);
	
	tr3=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr3.appendChild(td31);
	tr3.appendChild(td32);
	tr3.appendChild(td33);
	tr3.appendChild(td34);
	
	tr4=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr4.appendChild(td41);
	tr4.appendChild(td42);
	tr4.appendChild(td43);
	tr4.appendChild(td44);
	
	tr5=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr5.appendChild(td51);
	tr5.appendChild(td52);
	tr5.appendChild(td53);
	tr5.appendChild(td54);
	
	tr6=document.getElementById('tabel1').insertRow(document.getElementById('tabel1').rows.length-1);
	tr6.appendChild(td61);
	tr6.appendChild(td62);
	tr6.appendChild(td63);
	tr6.appendChild(td64);
	
	
	nr_el++;
	
}

/* pentru home */
function delUser(rec_id){
	var conf=confirm("Sunteti sigur ca doriti stergerea acestui user ?");
	if (conf){
		row_id=rec_id; //row_id = id-ul definit global in ajax_server.js. Ca sa stie ce rand sa stearga din DOM
		var sUrl = "ajax_delUser.php?id="+rec_id;
		
		//divId='continut';
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, delRand);
	}
}


function delCamere(camcum_id, camcum_start, camcum_stop, unicaz_id){
	var conf=confirm("Sunteti sigur ca doriti anularea acestor camere  ?");
	if (conf){
		row_id=camcum_id; //row_id = id-ul definit global in ajax_server.js. Ca sa stie ce rand sa stearga din DOM
		var sUrl = "ajax_delCamere.php?start="+camcum_start +'&stop='+camcum_stop+'&unicaz_id='+unicaz_id;
		
		//divId='continut';
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, delRand);
	}
}

function confirmUser(rec_id){
	var conf=confirm("Sunteti sigur ca doriti activarea acestui acestui user ?");
	if (conf){
		row_id=rec_id; //row_id = id-ul definit global in ajax_server.js. Ca sa stie ce rand sa stearga din DOM
		var sUrl = "ajax_confirmUser.php?id="+rec_id;
		
		//divId='continut';
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, delRand); //sterg randul penutr ca userul a fost activat iar lista este cu userii neactivati
	}
}



function actdeact(act, deact){
	a=document.getElementById(act);
	b=document.getElementById(deact);
		a.disabled=false;
		b.disabled=true;
	
		
}






function blocare(img,id,sessid,prefix_local,status_dorit,ific){
//daca src=galben atunci va incerca sa faca update where sessid=sesiunea curenta (ca sa poata rezerva doar locul lui) si se va face albastru
//daca src=verde atunci se va face insert si se va face din verde in galben
divId=img; //imaginea careia i se va schimba src-ul
prefix=prefix_local;
var sUrl;
var request;
switch (parseInt(status_dorit)){
	case 0:
		sUrl = prefix+"Scheme/Rezervari/ajax_loc_indisponibil.php?id="+id;
		request = YAHOO.util.Connect.asyncRequest('GET', sUrl, loc_indisponibil);
	break;
	case 1:
		 sUrl = prefix+"Scheme/Rezervari/ajax_loc_eliberat.php?id="+id;
		 request = YAHOO.util.Connect.asyncRequest('GET', sUrl, loc_liber);
	break;
	case 2: 
		 sUrl = prefix+"Scheme/Rezervari/ajax_loc_blocat.php?id="+id+"&sessid="+sessid+"&ific="+ific;
		 request = YAHOO.util.Connect.asyncRequest('GET', sUrl, loc_blocat);
	break;
	case 99: 
		 sUrl = prefix+"Scheme/Rezervari/ajax_loc_blocat.php?id="+id+"&sessid=fictiv"; // inseamna blocat fictiv
		 request = YAHOO.util.Connect.asyncRequest('GET', sUrl, loc_blocat);
	break;
	
		
}




}





function autocompletare(sursa,nr_instante,nr_zile){ //sursa e de forma subtabel_xyz
											//nr_instante = numarul de instante incepanad de la sursa pana la care se va 										                                            //face autocompletarea
	var index = sursa.indexOf('_');
	var index_tpl=sursa.substring(index+1);
	var baza=sursa.substring(0,index);
	//alert(baza + ' ' + index);
	
	var arrElemSingle= Array('cir_pret');

	var arrElemMulti =Array( 'cir_ghid_id', 'cir_status');
	var i;
	var j;
	for(i=2;i<=nr_instante;i++){
		for (j=0;j<arrElemSingle.length;j++){
			var elem= document.forms[0].elements[arrElemSingle[j]+'_'+i];
			elem.value= document.forms[0].elements[arrElemSingle[j]+'_'+index_tpl].value;
		}
	
		for (j=0;j<arrElemMulti.length;j++){
			var elem= document.forms[0].elements[arrElemMulti[j]+'_'+i];
			elem.selectedIndex=document.forms[0].elements[arrElemMulti[j]+'_'+index_tpl].selectedIndex;
		}
	//copiere informatii zile
		
		var arrZileSingle= Array('locatie_plecare','locatie_sosire','unicaz_loc_id','unicaz_id','observatii_zi');
		var arrZileMulti= Array('curse_linie','servicii_cazare');
		for (j=1;j<=nr_zile;j++){
			for (k=0;k<arrZileSingle.length;k++){
				var elemSingle= document.forms[0].elements[arrZileSingle[k]+'_'+i+'_'+j];
				elemSingle.value= document.forms[0].elements[arrZileSingle[k]+'_'+index_tpl+'_'+j].value;
			}	
			for (k=0;k<arrZileMulti.length;k++){
				if (arrZileMulti[k]=='servicii_cazare'){
					var referinta= document.forms[0].elements[arrZileMulti[k]+'_'+index_tpl+'_'+j+'[]'];
					var elemMulti= document.forms[0].elements[arrZileMulti[k]+'_'+i+'_'+j+'[]'];
					elemMulti.selectedIndex=-1; //curata tot
					for (l=0;l<referinta.length;l++) //se verifica care e selectat din sursa si se selecteaza in dest
						if(referinta.options[l].selected)
							elemMulti.options[l].selected= true;
				
				}
				else{
					var elemMulti= document.forms[0].elements[arrZileMulti[k]+'_'+i+'_'+j];
					elemMulti.selectedIndex= document.forms[0].elements[arrZileMulti[k]+'_'+index_tpl+'_'+j].selectedIndex;
				}
				
			}	
		
		/* verific daca transportul e charter atunci fac charter enabled peste tot si curse_linie disabled peste tot in ziua asta, si invers*/
			
			/*if (document.forms[0].elements['curse_linie_'+index_tpl+'_'+j].disabled){
				document.forms[0].elements['charter_'+i+'_'+j].disabled=false;
				document.forms[0].elements['curse_linie_'+i+'_'+j].disabled=true;
			
				
			}
			else{
				document.forms[0].elements['charter_'+i+'_'+j].disabled=true;
				document.forms[0].elements['curse_linie_'+i+'_'+j].disabled=false;
				
			}*/
			
		}
	}
}


function deselect(select_id){
	document.getElementById(select_id).selectedIndex=-1;
}


function clearVal(ob){
	ob.value='';
	if (arguments.length==2)
		changeClass(ob.id,arguments[1]);
}

function changeClass(ob_id,newClass){
	document.getElementById(ob_id).className=newClass;
}
