var DEPOZIT_ID_COL=0;
var DEPOZIT_DENUMIRE_COL=1;
var DEPOZIT_CARACT_COL=3;
var DEPOZIT_OBS_COL=4;
var DEPOZIT_USD_COL=5;
var DEPOZIT_RON_COL=4;
var DEPOZIT_STOC_COL=7;
var DEPOZIT_CANT_COL=9;
var DEPOZIT_PRECOMENZI_COL = 8;
var COS_ID_COL=0;
var COS_DENUMIRE_COL=1;
var COS_PROMOTIE_COL=2;
var COS_RON_DEPOZIT=3;
var COS_RON_FARA_TVA_COL=5;
var COS_RON_COL=4;
var COS_CANT_COL=6;
var COS_TOTAL_COL=7;
var FACTURI_COL_PUNCTE = 10;
var layer = 1;
var BROWSER = navigator.appName;

function ReplaceAll(s1, s2, s3){
  //return s3;
  while (s3.indexOf(s1)>=0) {s3=s3.replace(s1, s2);}
  return s3;
}

function IE_browser(){
  return BROWSER == "Microsoft Internet Explorer";
}

function FF_browser(){
  return BROWSER == "Netscape";
}

function OP_browser(){
  return BROWSER == "Opera";
}

function Start(page) {
  OpenWin = window.open(page, "CtrlWindow", "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes");
}

function SelectByValue(combo,v){
  if (v.charAt(0)*1.0==0) v=v.substring(1);
  for (var i=0;i<combo.options.length;i++) if (combo.options[i].text==v) return i;
  return null;
}

function RowStart(){
  app=navigator.appName;
  if (app=="Netscape") return 0;
  else return 1;
}

function Selected(row){
  if (Element.hasClassName(row.cells[0],"selected")) return true;
  else return false;
}

function filter(combo,optiuni,valori,tipuri,max_rows,full_compare){
  combo.options.length=0;
  if (valori!="" || optiuni.length<=max_rows){
    var regexp=new Array();
    var val=new Array();
    valoare=valori.split("#");
    tip=tipuri.split("#");
    for(i=0;i<valoare.length;i++){
      if (tip[i]==-1){
        if (valoare[i].length==1) valoare[i]="^"+valoare[i];
      }
      else valoare[i]="^"+valoare[i]+"$";
      valoare[i]=valoare[i].replace("(","\\(");
      valoare[i]=valoare[i].replace(")","\\)");
      valoare[i]=ReplaceAll("|", "", valoare[i]);
      valoare[i]=ReplaceAll("+", "", valoare[i]);
      valoare[i]=ReplaceAll("[", "", valoare[i]);
      valoare[i]=ReplaceAll("]", "", valoare[i]);
      regexp[i] = new RegExp(valoare[i], "i");
    };
    index=0;
    optiuni.each(function (optiune){
        opt=optiune.split('###');
        cond=true;
        for (i=0;i<valoare.length;i++){
          if (tip[i]!=null){
            if (tip[i]==-1) val=opt[0];
            else{
              a=opt[1].split("#");
              val=a[tip[i]];
            };
            val=ReplaceAll("|", "", val);            
            val=ReplaceAll("+", "", val);
            val=ReplaceAll("[", "", val);
            val=ReplaceAll("]", "", val);
            if (tip[i]!=-1){
              if (valoare[i]!="^-1$")
                cond = cond && regexp[i].test(val);
            }
            else {
              if (valoare[i]=="" && optiuni.length>max_rows) cond=false;
              else cond = cond && regexp[i].test(val);
            };
          }
        };
        if (cond) combo.options[index++]=new Option(opt[0],opt[1],false);
      }
    );
  };
  combo.selectedIndex=0;
  if (full_compare != null) {
    for (var i = 0; i < combo.options.length; i++) if (combo.options[i].text.toUpperCase() == full_compare.toUpperCase()) combo.selectedIndex = i;
  }
};

function checkKey(thisOne,text,loc,param) {
  var keycode = window.event ? window.event.keyCode : thisOne.which;
  if (keycode == "13") window.location=loc + "&" + param + "=" + text;
}

function checkKey2(thisOne,text,loc,param) {
  var keycode = window.event ? window.event.keyCode : thisOne.which;
  if (keycode == "13") {
    document.shortcut.action+="&option=Cautare&action=search&serie="+text;
    document.shortcut.submit();
  }
}

function SubmitIfEnter(thisOne,form) {
  var keycode = window.event ? window.event.keyCode : thisOne.which;
  if (keycode == "13") form.submit();
}

function SubmitIfEnterSpec(thisOne,form) {

  var keycode = window.event ? window.event.keyCode : thisOne.which;
  if (keycode == "13") {
    form.action += "&new_client=change";
    form.submit();
  }
}

function ComboSelect(combo,text) {
  var s1=text.value;
  var s2;
  if (combo.length>0){
    for (i=0;i<combo.length;i++) {
      s2=combo.options[i].text;
      if (s2.substring(0,s1.length).toUpperCase()==s1.toUpperCase()){
        combo.options[i].selected=1;
        break;
      };
    };
  };
}

function redirect(url){
  window.location=url;
}

function AddRow(values){
  var tbl=document.getElementById("PREVIEW");
  while (tbl.rows.length>0) tbl.deleteRow(0);
  randuri=values.split("###");
  var tt = new Array();
  for (i=0;i<randuri.length;i++){
  	tt[i]=0;
    lastrow=tbl.rows.length;
    var row=tbl.insertRow(lastrow);
    row.height=14;
    //row.id='idRow';
    coloane=randuri[i].split('$$$');
    var cell;
    var textNode;
    for (j=0;j<coloane.length;j++){
    	if (coloane[j].indexOf('Observatii')==-1 && coloane[j].indexOf('Produs')==-1 && coloane[j].indexOf('Cantitate')==-1 && coloane[j].indexOf('Seriale')==-1 && tt[i]==0) {row.id=coloane[0];} else {row.removeAttribute('id');tt[i]=1;};
      cell=row.insertCell(j);
      cell.innerHTML=coloane[j];
    };
  };
};

function AlternateLinks(question,link1,link2){
  if (confirm(question)) {
    if (confirm("Trimiteti mail?")) link1 += "&trimite_mail=ok";
    else link1 += "&trimite_mail=no";
    window.location=link1;
  }
  else {
    if (confirm("Trimiteti mail?")) link2 += "&trimite_mail=ok";
    else link2 += "&trimite_mail=no";
    window.location=link2;
  }
};

function ParseSelected(care,TableID){
  var valoare=document.DataGridSelections.SelectedRows.value;
  if (valoare=='') return -1;
  valoare=valoare.substr(0,valoare.length-1);
  var rez='';
  a=valoare.split(',');
  if (care=='last') a.each(function(i){b=i.split('#');if (b[0]==TableID) rez=b[1]+",";});
  else if (care=='first') a.each(function(i){b=i.split('#');if (b[0]==TableID) return b[1];});
  else if (care=='all') a.each(function(i){b=i.split('#');if (b[0]==TableID) rez += b[1]+",";});
  if (rez=="") return -1;
  return rez.substr(0,rez.length-1);
}

function DisplayTable(id, redir){
  var tbl=document.getElementById(id);
  var parts1 = window.location.toString().split("option=");
  if (parts1.length > 1){
    var parts2 = parts1[1].split("&");
    var option = parts2[0];
  }
  else {
    var option = "Adaosuri";
  }
  var parts1 = window.location.toString().split("suboption=");
  if (parts1.length > 1){
    var parts2 = parts1[1].split("&");
    var suboption = parts2[0];
  }
  else {
    var suboption = "";
  }
  if (tbl.style.display == "none"){
    tbl.style.display = "";
    if (option == "Comanda") {
      if (tbl.rows.length == 3){
        var div = tbl.rows[1].getElementsByTagName("div")[0];
        ActionDepozit(0, div.id);
      }
    }
    if ((option == "Depozit" || option == "Adaosuri") && suboption != "DepozitRMA"){
      if (tbl.rows.length == 3 && redir == null){
        var ah = tbl.rows[1].cells[1].getElementsByTagName("a")[0];
        var parts = ah.toString().split("javascript: ");
        eval(parts[1]);
      }
    }
  }
  else {
    tbl.style.display = "none";
  }
  //tbl.style.display=(tbl.style.display=='none'?'':'none');
}

function ReplaceTags(xStr){
  var regExp = /<\/?[^>]+>/gi;
  xStr = xStr.replace(regExp,"");
  return xStr;
}

function myround(n,d){
  var x=n;
  x=x*Math.pow(10,d);
  x=Math.round(x);
  x=x/Math.pow(10,d);
  return x;
}

function IsNumeric(sText)
{
   if (sText.length==0) return false;
   var ValidChars = "-+,0123456789.";
   var IsNumber=true;
   var Char;
   var j;


   for (j = 0; j < sText.length && IsNumber == true; j++)
      {
      Char = sText.charAt(j);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }

function SubmitComanda(mode,more_link){
  app=navigator.appName;
  if (app=="Netscape") st=0;
  else st=1;
  if (more_link.length>0) {
    if (more_link.substr(1,18)=="suboption=Gestiune") document.Depozit.Observatii.value=prompt("Observatii: ","");
    if (more_link.substr(1,20)=="suboption=Precomanda") document.Depozit.Observatii.value=prompt("Observatii: ","")
  }
  document.Depozit.comanda.value="";
  var d=document.getElementById("KPRODUSE");
  var t=$A(d.getElementsByTagName('table'));
  var table=t[2];
  table=document.getElementById("PRODUSE_DEPOZIT");
  for (i=st;i<table.rows.length;i++) {
    s=table.rows[i].cells[DEPOZIT_ID_COL].innerHTML;
    if (!IsNumeric(s)) s=s.substring(1);
    s="cant_"+s;
    cantitate=document.getElementsByName(s)[0].value;
    if (cantitate>0) {
      s1=ReplaceTags(table.rows[i].cells[DEPOZIT_ID_COL].innerHTML);
      s2=ReplaceTags(table.rows[i].cells[DEPOZIT_RON_COL].innerHTML);
      if (app=="Netscape"){
        if(!IsNumeric(s1)) s1=s1.substr(1);
        if(!IsNumeric(s2)) s2=s2.substr(1);
      };
      document.Depozit.comanda.value += s1+"#"+ToNumber(s2)+"#"+cantitate+",";
    }
  }
  document.Depozit.comanda.value = document.Depozit.comanda.value.substring(0,document.Depozit.comanda.value.length-1);
  if (document.Depozit != null) if (document.Depozit.completare_comanda != null) document.Depozit.comanda.value += document.Depozit.completare_comanda.value
  document.Depozit.action += "&action=InsertProducts&mode="+mode+more_link;
  document.Depozit.submit();
}

function ChangeDiscount(_idx, max_proc){
	var idx;
	if (_idx == null) 
		idx = 1000;
	else 
		idx = _idx
	document.Depozit.val_discount.value='';
	if (document.Depozit.discount.selectedIndex > idx) 
		document.Depozit.discount.selectedIndex = idx
	i=document.Depozit.discount.selectedIndex;
	if (document.Depozit.discount.selectedIndex==0) {
		document.Depozit.val_discount.style.visibility="hidden";
		document.Depozit.semn.style.visibility="hidden";
	} else {
		document.Depozit.val_discount.style.visibility="visible";
		document.Depozit.semn.style.visibility="visible";
	}
	if (document.Depozit.discount.selectedIndex==1) document.Depozit.semn.value="%";
	if (document.Depozit.discount.selectedIndex==2) document.Depozit.semn.value="RON";
	SetDiscount();
}
function ChangeDiscount2(_idx, max_proc){
	var idx;
	if (_idx == null) 
		idx = 1000;
	else 
		idx = _idx
	if (document.Depozit.discount.selectedIndex > idx) 
		document.Depozit.discount.selectedIndex = idx
	i=document.Depozit.discount.selectedIndex;
	if (document.Depozit.discount.selectedIndex==0) {
		document.Depozit.val_discount.style.visibility="hidden";
		document.Depozit.semn.style.visibility="hidden";
	} else {
		document.Depozit.val_discount.style.visibility="visible";
		document.Depozit.semn.style.visibility="visible";
	}
	if (document.Depozit.discount.selectedIndex==1) document.Depozit.semn.value="%";
	if (document.Depozit.discount.selectedIndex==2) document.Depozit.semn.value="RON";
	SetDiscount();
}

function fUpdatePret(thisOne,textfield,lostfocus,brand,categ){
  var keycode = window.event ? window.event.keyCode : thisOne.which;
  if (keycode == "13" || lostfocus) {
    textfield.onblur="";
    textfield.onkeyup="";
    if (confirm("Sigur?")){
      document.Depozit.UpdatePret.value=textfield.value;
      document.Depozit.action += "&id=" + ParseSelected('last','COS_PRODUSE') + "&branduri="+brand+"&categ="+categ+"&action=UpdatePret";
      document.Depozit.submit();
    }
    else document.Depozit.submit();
  }
}

function ToNumber(s){
  var rez=s.replace(",","");
  return rez*1.0;
}

function ToNumber2(s){
  var rez=s.replace(",",".");
  return rez*1.0;
}

function SetDiscount(dm){
  app=navigator.appName;
  if (document.Depozit.discount.value != "Procentual") dm = 50000;
  if (app=="Netscape") st=0;
  else st=1;
  tva=document.Depozit.cota_tva.value/100 + 1;
  //if (!IsNumeric(tva)) tva=19;
  var total=0;
  var d=document.Depozit.discount.selectedIndex;
  var vd=ToNumber2(document.Depozit.val_discount.value);
  if (dm > 0) if (vd > dm) {
    vd = dm;
    document.Depozit.val_discount.value = vd;
  }
  var tab=document.getElementById("COS_PRODUSE");
  var c;
  if (d==0 || d==2){
    for (i=st;i<tab.rows.length;i++){
      s=ReplaceTags(tab.rows[i].cells[COS_ID_COL].innerHTML);
      if (!IsNumeric(s)) s=s.substring(1);
      pi=document.getElementsByName("preti_"+s)[0].value;
      document.getElementsByName("pret_"+s)[0].value=myround(document.getElementsByName("preti_"+s)[0].value,2);
      document.getElementsByName("pret_"+s)[0].value=new NumberFormat(document.getElementsByName("pret_"+s)[0].value).toFormatted();
      tab.rows[i].cells[COS_RON_FARA_TVA_COL].innerHTML=new NumberFormat(myround(pi/tva,2)).toFormatted();
      ron_tva=ReplaceTags(tab.rows[i].cells[COS_RON_COL].innerHTML);
      if (!IsNumeric(ron_tva)) ron_tva=ron_tva.substring(1);
      c=document.getElementsByName("cant_"+s)[0].value;
      tab.rows[i].cells[COS_TOTAL_COL].innerHTML=new NumberFormat(myround(myround(pi/tva,2)*c+myround(myround(pi/tva,2)*c*(tva - 1),2),2)).toFormatted();
      total += ToNumber(ReplaceTags(tab.rows[i].cells[COS_TOTAL_COL].innerHTML));
    }
  }
  else if (d==1){
    for (i=st;i<tab.rows.length;i++){
      if (ReplaceTags(tab.rows[i].cells[COS_PROMOTIE_COL].innerHTML).charAt(0)*1.0==0) FF_SUCKS=ReplaceTags(tab.rows[i].cells[COS_PROMOTIE_COL].innerHTML).substring(1);
      else FF_SUCKS=ReplaceTags(tab.rows[i].cells[COS_PROMOTIE_COL].innerHTML);
      if (FF_SUCKS=="-"){
        s=ReplaceTags(tab.rows[i].cells[COS_ID_COL].innerHTML);
        if (!IsNumeric(s)) s=s.substring(1);
        pi=document.getElementsByName("preti_"+s)[0].value;
        document.getElementsByName("pret_"+s)[0].value = myround(pi-(pi*(vd/100)),2);
        document.getElementsByName("pret_"+s)[0].value=new NumberFormat(document.getElementsByName("pret_"+s)[0].value).toFormatted();
        pf=myround(pi-(pi*(vd/100)),2);
        c=document.getElementsByName("cant_"+s)[0].value;
        tab.rows[i].cells[COS_RON_FARA_TVA_COL].innerHTML=new NumberFormat(myround(pf/tva,2)).toFormatted();
        tab.rows[i].cells[COS_TOTAL_COL].innerHTML=new NumberFormat(myround(myround(pf/tva,2)*c+myround(myround(pf/tva,2)*c*(tva-1),2),2)).toFormatted();
      }
      total += ToNumber(ReplaceTags(tab.rows[i].cells[COS_TOTAL_COL].innerHTML));
    }
  }
  total -= document.Depozit.ValoareDiscount.value;
  if (d!=2) document.getElementById("total_factura").innerHTML=new NumberFormat(total).toFormatted();
  else document.getElementById("total_factura").innerHTML=new NumberFormat(total-vd).toFormatted();

}

function afterSubmitProforma(xml){
  if (getXMLData(xml, "promotii") != "ok") alert("ATENTIE: Aveti promotii pe proforma al caror pret nu este cel din depozit");
}

function changeExportFormat(){
	var f1 = document.getElementById("_format_pdf").checked;
	var f2 = document.getElementById("_format_excel").checked;
	ajaxRead2("setExportFormat.php?format=" + (f2?"excel":"pdf"), "GET", true);
}

function SubmitProforma(option,url){
  if (option != "Comanda") ajaxRead2("comanda.php?checkPromotii=", "GET", false, "", afterSubmitProforma);
  if (option=="Comanda" || option == "UpSell" || option == "Promotii3") url += "&action=justRedirect";
  else url += "&action=commitChanges&plata=" + document.Depozit.plata_n.value;;
  document.Depozit.action = url;
  document.Depozit.submit();
}

function CalcProduseRamase(textfield){
  app=navigator.appName;
  if (app=="Netscape") st=0;
  else st=1;
  vo=document.getElementById("tot_cantitate").innerHTML;
  var tab=document.getElementById("PRODUSE_DEPOZIT");
  var total=0;
  var c,n;
  for (i=st;i<tab.rows.length;i++) {
    n=ReplaceTags(tab.rows[i].cells[DEPOZIT_ID_COL].innerHTML);
    if (!IsNumeric(n)) n=n.substring(1);
    c=document.getElementsByName("cant_"+n)[0].value;
    total += c*1.0;
  }
  if (total>document.Depozit.cate_produse.value){
    alert("Nu puteti selecta decat maxim " + (document.Depozit.cate_produse.value) + " produse.");
    document.getElementById("tot_cantitate").innerHTML=vo;
    textfield.value="0";
  }
  else document.getElementById("tot_cantitate").innerHTML="Selectati produsele carora promotia sa le fie aplicata. Mai aveti de selectat <span class='text_arial'><b>" + (document.Depozit.cate_produse.value-total) + "</b></span> produse";
}

function ValidarePromotie(){
  app=navigator.appName;
  if (app=="Netscape") st=0;
  else st=1;
  var tab=document.getElementById("PRODUSE_DEPOZIT");
  var total=0;
  var c,n;
  for (i=st;i<tab.rows.length;i++) {
    n=ReplaceTags(tab.rows[i].cells[DEPOZIT_ID_COL].innerHTML);
    if (!IsNumeric(n)) n=n.substring(1);
    c=document.getElementsByName("cant_"+n)[0].value;
    total += c*1.0;
  }

  if (total!=document.Depozit.cate_produse.value) alert("Nu ati selectat exact " + document.Depozit.cate_produse.value + " produse. ");
  else {
    if (confirm("Doriti ca pretul produsului discount sa fie distribuit in pretul celorlalte produse? (daca nu, va fi evidentiat separat pe factura)")) SubmitComanda("1","");
    else SubmitComanda("0","");
  }
}

function SetNewPromotionLinks(){
  var xmlTEMP = ajaxRead("comanda.php?getTexte=", "GET", true);
  if (document.Depozit.PromotieNoua.value.length<=0) return ;
  var promotii=document.Depozit.PromotieNoua.value.split(",");
  var promotii_name=document.Depozit.PromotiiNume.value.split("#");
  app=navigator.appName;
  if (app=="Netscape") st=0;
  else st=1;
  var k;
  var tab=document.getElementById("COS_PRODUSE");
  var val_min=1000000;
  for (i=0;i<promotii.length;i++){
    val_min = 1000000;
    ids=promotii[i].split("#");
    for (j=2;j<ids.length;j++){
      k=st;
      ok=0;
      while (k<tab.rows.length && !ok) {
        FF_SUCKS=ReplaceTags(tab.rows[k].cells[COS_ID_COL].innerHTML);
        if (!IsNumeric(FF_SUCKS)) FF_SUCKS=FF_SUCKS.substring(1);
        if(FF_SUCKS==ids[j]) ok=1;
        if (!ok) k++;
      }
      if (ok==1) {
        if (val_min==1000000) val_min=k;
        else if (ToNumber(ReplaceTags(tab.rows[val_min].cells[COS_RON_FARA_TVA_COL].innerHTML))>ToNumber(ReplaceTags(tab.rows[k].cells[COS_RON_FARA_TVA_COL].innerHTML))) val_min=k;
      }
    }
    tab.rows[val_min].cells[COS_PROMOTIE_COL].innerHTML=
        "<a href=\"javascript: ConfirmPromotion(" + i + ", " + (ids[1]==3 || ids[1]==4 || ids[1]==5?"'no'":"''") + ")\"><b><font color='#ff0000'>Aplica promotie</font></b></a> ("+ promotii_name[i] +")";
  }
}

function AnularePrecomanda(subsuboption, branduri, categ){
  if (subsuboption=="Modify"){
    var cantitate=prompt("Noua cantitate:", "");
    if (IsNumeric(cantitate)) {
      document.Depozit.iduri.value=ParseSelected('last','PRODUSE_DEPOZIT');
      document.Depozit.action += "&suboption=Precomanda&subsuboption=" + subsuboption + "&action=cancelReservation&branduri=" + branduri + "&categ=" + categ + "&cantitate=" + cantitate;
      document.Depozit.submit();
    }
  }
  else{
    document.Depozit.pid.value=ParseSelected('all','REZERVARI');
    var parts = document.Depozit.pid.value.split("DELDEL");
    if (!IsNumeric(parts[0])) document.Depozit.pid.value = document.Depozit.pid.value.substring(1);
    document.Depozit.action += "&suboption=Precomanda&subsuboption=" + subsuboption + "&action=cancelReservation";
    document.Depozit.submit();
  }
}

function ResetareFiltruRMAProforme(){
  document.Depozit.de_la.value="";
  document.Depozit.la.value="";
  document.Depozit.submit();
}

function SubmitPlata(act){
  var ok=true;
  var mess="";
  if (act!='update'){
    if (!IsNumeric(document.Fisa_Cont.suma.value)) mess+="Nu ati introdus o suma valida. ";
    if (document.Fisa_Cont.nr.value.length==0) mess+="Nu ati introdus un numar de document valid.";
    if (mess!="") alert(mess);
    else{
      document.Fisa_Cont.iduri.value=ParseSelected('all','FISACONT');
      document.Fisa_Cont.action += "&action=NewPay";
      document.Fisa_Cont.submit();
    }
  }
  else{
    if (!IsNumeric(document.Fisa_Cont.msuma.value)) mess+="Nu ati introdus o suma valida. ";
    if (document.Fisa_Cont.mnr.value.length==0) mess+="Nu ati introdus un numar de document valid.";
    if (mess!="") alert(mess);
    else{
      document.Fisa_Cont.iduri.value=ParseSelected('all','FISACONT');
      document.Fisa_Cont.action += "&action=UpdatePay";
      document.Fisa_Cont.submit();
    }
  }
}

function ToDate(s){
  if (IsNumeric(s.substr(0,2))) return s.substr(6,4)+"-"+s.substr(3,2)+"-"+s.substr(0,2)+" "+s.substring(11);
  else return s.substr(7,4)+"-"+s.substr(4,2)+"-"+s.substr(1,2)+" "+s.substring(12);
}

function ModifPlata(){
  var modpl=document.getElementById("MODIFICARE_PLATA");
  if (modpl.style.display!="none") DisplayTable("MODIFICARE_PLATA");
  document.Fisa_Cont.id_update.value="-1";
  document.Fisa_Cont.iduri.value=ParseSelected('last','FISACONT');
  var tab=document.getElementById("FISACONT");
  var i=tab.rows.length;
  if (document.Fisa_Cont.iduri.value=="-1") alert("Nu ati selectat nici o plata.");
  else{
    app=navigator.appName;
    if (app=="Netscape") st=0;
    else st=1;
    for (i=st;i<tab.rows.length;i++) {
      id=ReplaceTags(tab.rows[i].cells[0].innerHTML);
      if (id==document.Fisa_Cont.iduri.value) break;
    }
  }
  if (i<tab.rows.length){
    zile=ReplaceTags(tab.rows[i].cells[7].innerHTML);
    if (!IsNumeric(zile)) zile=zile.substring(1);
    if (zile!="-") alert("Nu ati selectat nici o plata.");
    else {
      document.Fisa_Cont.id_update.value=tab.rows[i].cells[0].innerHTML;
      document.Fisa_Cont.msuma.value=ToNumber(tab.rows[i].cells[5].innerHTML);
      de_la=5;
      tip_op=tab.rows[i].cells[2].innerHTML.substr(0,4);
      if (tip_op.substr(0,1)!="O" && tip_op.substr(0,1)!="C") {tip_op=tip_op.substring(1)+tab.rows[i].cells[2].innerHTML.substr(4,1);de_la=6;}
      if (tip_op=="O.P.") document.Fisa_Cont.mtip_plata.selectedIndex=0;
      if (tip_op=="Cash") document.Fisa_Cont.mtip_plata.selectedIndex=1;
      if (tip_op=="O.C.") document.Fisa_Cont.mtip_plata.selectedIndex=2;
      numar=tab.rows[i].cells[2].innerHTML.substring(de_la);
      document.Fisa_Cont.mnr.value=numar;
      document.Fisa_Cont.mdata.value=ToDate(tab.rows[i].cells[1].innerHTML);
      banca=tab.rows[i].cells[9].innerHTML.substr(0,3);
      if (banca.substr(0,1)!="V" && banca.substr(0,1)!="B") banca=banca.substring(1)+tab.rows[i].cells[9].innerHTML.substr(3,1);
      if (banca=='VKB') document.Fisa_Cont.mbanca.selectedIndex=0;
      if (banca=='BCR') document.Fisa_Cont.mbanca.selectedIndex=1;
      if (document.Fisa_Cont.mcurs_valutar!=null) document.Fisa_Cont.mcurs_valutar.value=tab.rows[i].cells[11].innerHTML;
      DisplayTable("MODIFICARE_PLATA");
    }
  }
}

function ResetareSumaAchitata(){
  var desch="";
  document.Fisa_Cont.iduri.value=ParseSelected('all','FISACONT');
  var tab=document.getElementById("FISACONT");
  if (document.Fisa_Cont.iduri.value=="-1") alert("Nu ati selectat nici o factura.");
  else{
    if (confirm("Sigur?")){
      app=navigator.appName;
      if (app=="Netscape") st=0;
      else st=1;
      for (i=st;i<tab.rows.length;i++) if (Selected(tab.rows[i]))
        if (tab.rows[i].cells[10].innerHTML==1) if (confirm("Resetati si data de inchidere pentru factura "+tab.rows[i].cells[2].innerHTML+" ?")) desch += tab.rows[i].cells[0].innerHTML+",";
      if (desch.length>0) desch=desch.substr(0,desch.length-1);
      document.Fisa_Cont.action += "&ResetDate="+desch+"&action=ResetSum";
      document.Fisa_Cont.submit();
    }
  }
}

function BDFirma(act){
  if (confirm("Sigur?")){
    document.Fisa_Cont.action+="&action="+act;
    document.Fisa_Cont.submit();
  }
}

function RedistribSuma(){
  var tab=document.getElementById("FISACONT");
  var facturi="";
  for (i=RowStart();i<tab.rows.length;i++) if (Selected(tab.rows[i])) if (tab.rows[i].cells[10].innerHTML==1 || tab.rows[tab.rows.length-2].cells[2].innerHTML.indexOf("Sold initial")) facturi += tab.rows[i].cells[0].innerHTML+",";
  if (facturi=="") alert("Nu ati selectat nici o factura.");
  else{
    document.Fisa_Cont.iduri.value=facturi.substr(0,facturi.length-1);
    document.Fisa_Cont.action += "&action=RedistPay";
    document.Fisa_Cont.submit();
  }
}

function ResetDate(){
  if (confirm("Sigur?")){
    var tab=document.getElementById("FISACONT");
    var facturi="";
    for (i=RowStart();i<tab.rows.length;i++) if (Selected(tab.rows[i])) if (tab.rows[i].cells[10].innerHTML==1) facturi += tab.rows[i].cells[0].innerHTML+",";
    if (facturi=="") alert("Nu ati selectat nici o factura.");
    else{
      document.Fisa_Cont.iduri.value=facturi.substr(0,facturi.length-1);
      document.Fisa_Cont.action += "&action=ResetDate";
      document.Fisa_Cont.submit();
    }
  }
}

function AdDef(){
  document.intrare_RMA.defect.value += document.intrare_RMA.defect_predef.options[document.intrare_RMA.defect_predef.selectedIndex].text;
}

function ajax_do (url) {
  var _url = document.location.href;
  var xend = _url.lastIndexOf("/") + 1;
  var base_url = _url.substring(0, xend);
  // Does URL begin with http?
  if (url.substring(0, 4) != 'http') {
          url = base_url + url;
  }

  // Create new JS element
  var jsel = document.createElement('SCRIPT');
  jsel.type = 'text/javascript';
  jsel.src = url;

  // Append JS element (therefore executing the 'AJAX' call)
  document.body.appendChild (jsel);
}

function ajax(strURL,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) {
	var xmlHttpReq = false;var self = this;if (window.XMLHttpRequest) {self.xmlHttpReq = new XMLHttpRequest();} else if (window.ActiveXObject) {self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");};self.xmlHttpReq.open('POST', strURL, true);self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');self.xmlHttpReq.onreadystatechange = function() {if (self.xmlHttpReq.readyState == 4) {eval(self.xmlHttpReq.responseText);}};self.xmlHttpReq.send(getquerystring(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10));
}

function getquerystring(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10) {
	qstr = 'x1='+x1+'&x2='+x2+'&x3='+x3+'&x4='+x4+'&x5='+x5+'&x6='+x6+'&x7='+x7+'&x8='+x8+'&x9='+x9+'&x10='+x10;return qstr;
}



function ajaxRead(file, method, asinc, send_text){
  var xmlObj = null;
  if(window.XMLHttpRequest){
    xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
    xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    return;
  }
  xmlObj.onreadystatechange = function(){
    /* alert(xmlObj.responseText + " | " + xmlObj.status + "|" + xmlObj.statusText + "|" + xmlObj.responseXML.getElementsByTagName('response_type').length);
    alert(xmlObj.responseXML.getElementsByTagName('response_type')[0].firstChild.data); */
    if (xmlObj.responseXML.getElementsByTagName('response_type').length>0) var response_type = xmlObj.responseXML.getElementsByTagName('response_type')[0].firstChild.data;
    else {
      //alert(xmlObj.responseText);
      if (xmlObj.readyState == 4) 
		if (xmlObj.status == 200) 
			if (xmlObj.responseText.indexOf("timer_MailSent") != -1) 
				var response_type = "timer_MailSent";
    }
    //alert(response_type);
    if (response_type == "steps" || response_type == "timer_steps") {
     pb.step = 100 / xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data;
     var f = document.MailClienti;
     if (f.personalizat.checked) {
       if (xmlObj.responseXML.getElementsByTagName('ids1')[0].firstChild.data != 0) ids1 = xmlObj.responseXML.getElementsByTagName('ids1')[0].firstChild.data.split(",");
       if (xmlObj.responseXML.getElementsByTagName('ids2')[0].firstChild.data != 0) ids2 = xmlObj.responseXML.getElementsByTagName('ids2')[0].firstChild.data.split(",");
       if (ids1.length > 0) index1 = 0;
       else if (ids2.length > 0) index2 = 0;
     }
    }
    else if (response_type == "MailSent") {
      //alert(xmlObj.responseText);
      if (xmlObj.responseXML.getElementsByTagName('id')[0].firstChild.data!=-2){
        var tab = document.getElementById("JUDETE_SELECTATE");
        for (var i=RowStart();i<tab.rows.length;i++){
          id = tab.rows[i].cells[0].innerHTML;
          if (!IsNumeric(id)) id = id.substring(1);
          if (id == xmlObj.responseXML.getElementsByTagName('id')[0].firstChild.data) tab.deleteRow(i);
        }
        pb.step_it();
        pb.show_Text(xmlObj.responseXML.getElementsByTagName('view_text')[0].firstChild.data);
      }
     if (xmlObj.responseXML.getElementsByTagName('id')[0].firstChild.data == -2) {
        var status = document.getElementById("status");
        var tab = document.getElementById("JUDETE_SELECTATE");
        for (var i=RowStart();i<tab.rows.length;i++){
          id = tab.rows[i].cells[0].innerHTML;
          if (!IsNumeric(id)) id = id.substring(1);
          if (id == xmlObj.responseXML.getElementsByTagName('init_id')[0].firstChild.data) tab.deleteRow(i);
        }
        if (xmlObj.responseXML.getElementsByTagName('id')[0].firstChild.data!=-8){
          pb.step_it();
          pb.show_Text(xmlObj.responseXML.getElementsByTagName('view_text')[0].firstChild.data);
        }
        status.parentNode.bgColor = document.MailClienti.PORTOCALIU.value;
        status.innerHTML = 'Mesaj trimis';
     }
    }
    else if (response_type == "last_mail"){
     var status = document.getElementById("status");
     status.innerHTML += "Ultimul judet: " + xmlObj.responseXML.getElementsByTagName('data')[0].firstChild.data;
     if (confirm("Reincarcati pagina (pt a elimina judetele la care s-a trimis mail?")) history.go(0);
    }
    else if (response_type == "TEST"){
      var status = document.getElementById("status");
      alert(xmlObj.responseXML.getElementsByTagName('id')[0].firstChild.data);
    }
    else if (response_type == "timer_MailSent"){
      var tab = document.getElementById("JUDETE_SELECTATE");
      var f = document.MailClienti;
      if (f.personalizat.checked){
        pb.step_it();
        sending = false;
      }
      else{
        if (tab.rows.length>RowStart() && document.MailClienti.la_clienti.checked) tab.deleteRow(RowStart());
        pb.step_it();
        sending = false;
      }
    }
    else if (response_type == "categs_retrive"){
      var xml = xmlObj.responseXML;
      var f=document.Modificari;
      f.categ.options.length = 0;
      var categs = xml.childNodes[1].childNodes;
      var id, c;
      //alert(categs[1].childNodes.length);
      for (var i=1; i<categs.length; i++){
        id = categs[i].childNodes[0].text;
        c = categs[i].childNodes[1].text;
        f.categ.options[i] = new Option(c, id, false);
      }
      //alert(xml.childNodes[1].childNodes.length);
    }
    else if (response_type == "mail_config"){
      var f=document.Facturi;
      /* f.useri_ids.value = xmlObj.responseXML.getElementsByTagName('useri_ids')[0].firstChild.data;
      f.clienti_ids.value = xmlObj.responseXML.getElementsByTagName('clienti_ids')[0].firstChild.data; */
      useri_ids = xmlObj.responseXML.getElementsByTagName('useri_ids')[0].firstChild.data.split(",");
      if (xmlObj.responseXML.getElementsByTagName('clienti_ids')[0].firstChild != null) clienti_ids = xmlObj.responseXML.getElementsByTagName('clienti_ids')[0].firstChild.data.split(",");
      pb.step = 100 / xmlObj.responseXML.getElementsByTagName('mails')[0].firstChild.data;
    }
    else if (response_type == "mail_factura_sent"){
      if (sending_user){
        sending_user = false;
        current_user ++;
      }
      if (sending_client){
        sending_client = false;
        current_client ++;
      }
      pb.step_it();
      sending = false;
    }
    else if (response_type == "articol_retrieved"){
      var articol = document.getElementById("articol");
      var html = "";
      for (var i = 0; i < xmlObj.responseXML.getElementsByTagName('innerHTML').length; i++){
        html += xmlObj.responseXML.getElementsByTagName('innerHTML')[i].firstChild.data;
      }
      html = ReplaceAll("&lt;", "<", html);
      html = ReplaceAll("&gt;", ">", html);
      html = ReplaceAll("&amp;", "&", html);
      articol.innerHTML = html;
      var loading = document.getElementById("loading");
      loading.style.display="none";
    }
    else if (response_type == "comandaRefresh"){
		if (xmlObj.readyState == 4) 
			if (xmlObj.status == 200) {
			  var xml = xmlObj.responseXML;
			  var id = xml.getElementsByTagName("id")[0].firstChild.data;
			  var rol = xml.getElementsByTagName("id_user_rol")[0].firstChild.data;
			  InsertTable(xml, id, rol)
			}
    }
    else if (response_type == "donePrecomanda"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild == null) {
        alert("Precomanda adaugata");
        ResetTexts("getPrecomenzi");
      }
      else alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);
    }
    else if (response_type == "doneGestiune"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild == null) {
        alert("Produse adaugate in gestiune");
        ResetTexts("getStoc");
      }
      else alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);
    }
    else if (response_type == "getPrecomanda"){
      var xml = xmlObj.responseXML;
      var row = document.getElementById("PRODUSE_DEPOZIT" + xml.getElementsByTagName("id_car_prod")[0].firstChild.data);
      row.cells[DEPOZIT_PRECOMENZI_COL].innerHTML = xml.getElementsByTagName("precomenzi")[0].firstChild.data;
    }
    else if (response_type == "donegetStoc"){
      var xml = xmlObj.responseXML;
      var row = document.getElementById("PRODUSE_DEPOZIT" + xml.getElementsByTagName("id_car_prod")[0].firstChild.data);
      row.cells[DEPOZIT_STOC_COL].innerHTML = "<b>" + xml.getElementsByTagName("stoc")[0].firstChild.data + "</b>";
    }
    else if (response_type == "doneInsertStoc"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild == null) {
        //alert("Produse adaugate in cos");
        ResetTexts("getStoc");
      }
      else alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);

      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "TRUE"){
        SendRequestUpdateCos();
        xmlTEMP = ajaxRead("comanda.php?getTexte=", "GET", true);
      }
      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "NIR"){
        SendRequestUpdateCos2();
      }
      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "OFERTA"){
        SendRequestUpdateCos3();
      }
    }
    else if (response_type == "doneUpdateCos") {
      var total = (xmlObj.responseXML.getElementsByTagName("total")[0].firstChild == null?0:xmlObj.responseXML.getElementsByTagName("total")[0].firstChild.data)
      UpdateCosProduse(xmlObj.responseXML, total);
    }
    else if (response_type == "doneUpdateCosNIR") {
      //alert("ACI");
      UpdateCosProduse2(xmlObj.responseXML);
    }
    else if (response_type == "doneUpdateCosOferta") {
      //alert("ACI");
      UpdateCosProduse2(xmlObj.responseXML);
    }
    else if (response_type == "donenewPromotions"){
      document.Depozit.PromotieNoua.value = "";
      document.Depozit.PromotiiNume.value = "";
      if (xmlObj.responseXML.getElementsByTagName("PromotieNoua")[0].firstChild != null) document.Depozit.PromotieNoua.value = xmlObj.responseXML.getElementsByTagName("PromotieNoua")[0].firstChild.data;
      if (xmlObj.responseXML.getElementsByTagName("PromotiiNume")[0].firstChild != null) document.Depozit.PromotiiNume.value = xmlObj.responseXML.getElementsByTagName("PromotiiNume")[0].firstChild.data;
      //COMENTARII PROMOTII
      /* SetNewPromotionLinks(); */
      //COMENTARII PROMOTII
    }
    else if (response_type == "doneUpdateCantitate"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild != null) alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);
      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "TRUE"){
        SendRequestUpdateCos();
        var xmlTEMP = ajaxRead("comanda.php?getTexte=", "GET", true);
      }
    }
    else if (response_type == "doneUpdateCantitateNIR"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild != null) alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);
      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "TRUE")
        SendRequestUpdateCos2();
    }
    else if (response_type == "doneUpdatePretNIR"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild != null) {
        alert("Eroare: " + xml.getElementsByTagName("errors")[0].firstChild.data);
        SendRequestUpdateCos2();
      }
    }
    else if (response_type == "doneApplyPromotion"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("updateCos")[0].firstChild.data == "TRUE")
        SendRequestUpdateCos();
    }
    else if (response_type == "doneDeleteValue"){
      SendRequestUpdateCos();
    }
    else if (response_type == "doneDeleteValueNIR"){
      SendRequestUpdateCos2();
    }
    else if (response_type == "doneDeleteValueOferta"){
      SendRequestUpdateCos3();
    }
    else if (response_type == "donePreturiDepozit"){
      SendRequestUpdateCos();
    }
    else if (response_type == "doneGetTexte"){
      var xml = xmlObj.responseXML;
      var texte = "";
      if (xml.getElementsByTagName("texte")[0].firstChild != null) texte = xml.getElementsByTagName("texte")[0].firstChild.data;
      texte = ReplaceAll("&lt;", "<", texte);
      texte = ReplaceAll("&gt;", ">", texte);
      texte = ReplaceAll("&amp;", "&", texte);
      var div_texte = document.getElementById("texte_promotii");
      div_texte.innerHTML = texte;
    }
    else if (response_type == "doneNewUser"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("errors")[0].firstChild != null) alert(xml.getElementsByTagName("errors")[0].firstChild.data);
      else {
        alert("Intrucat este prima data cand accesati contul, acesta trebuie activat. A fost trimit un mesaj pe adresa " + xml.getElementsByTagName("adr")[0].firstChild.data + " cu instructiuni pentru activarea contului. Va multumim. ");
        window.location = "index.php?PentruDealeri=true&adr=" + escape(xml.getElementsByTagName("adr")[0].firstChild.data);
      }
    }
    else if (response_type == "redirectLogin"){
      document.login.submit();
    }
    else if (response_type == "doneNewUserLogin"){
      document.login.submit();
    }
    else if (response_type == "donegetCaracts"){
      var xml = xmlObj.responseXML;
      showTipBox('','',false, xml.getElementsByTagName("caracts")[0].firstChild.data);
    }
    else if (response_type == "donegetSuggestions"){
      var xml = xmlObj.responseXML;
      var link, denumire;
      var suggestions = xml.getElementsByTagName("suggestion");
      if (suggestions != null){
        AutoS.eligible = new Array();
        for (var i = 0; i<suggestions.length; i++) if (suggestions[i].childNodes.length == 2){
          link = ReplaceAll("&amp;", "&", suggestions[i].childNodes[0].firstChild.data);
          denumire = suggestions[i].childNodes[1].firstChild.data;
          AutoS.eligible.push(link + "#" + denumire);
        }
        AutoS.getEligibleContinue();
      }
    }
    else if (response_type == "donegetAllDataRMA"){
      var xml = xmlObj.responseXML;
      var id = xml.getElementsByTagName("id")[0].firstChild.data;
      InsertTable(xml, id)
    }
    else if (response_type == "donegetBuget"){
      var f = document.Bugete;
      var valuta = "RON";
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("valuta")[0].firstChild.data == 1) valuta = "USD";
      if (xml.getElementsByTagName("valuta")[0].firstChild.data == 2) valuta = "EUR";

      var cm = myround(xml.getElementsByTagName("CM")[0].firstChild.data / xml.getElementsByTagName("curs")[0].firstChild.data, 0);

      cm = new NumberFormat(cm).toFormatted();

      var td = document.getElementById("SELECTIE");
      td.innerHTML = "<h3>" + xml.getElementsByTagName("selectie")[0].firstChild.data +
        (xml.getElementsByTagName("CM")[0].firstChild.data != -1?" (cost mediu marfa: " + cm + valuta + ")":"");
        "</h3>";
      f.buget.value = xml.getElementsByTagName("buget")[0].firstChild.data;
      f.valuta.selectedIndex = xml.getElementsByTagName("valuta")[0].firstChild.data;
      f.factor_vanzare.value = xml.getElementsByTagName("factor_vanzare")[0].firstChild.data;
      f.zile_tranzit.value = "";
      if (xml.getElementsByTagName("zile_tranzit")[0].childNodes.length>0) f.zile_tranzit.value = xml.getElementsByTagName("zile_tranzit")[0].firstChild.data;
      f.zile_comanda.value = "";
      if (xml.getElementsByTagName("zile_comanda")[0].childNodes.length>0) f.zile_comanda.value = xml.getElementsByTagName("zile_comanda")[0].firstChild.data;
    }
    else if (response_type == "doneSaveBuget") {
      var mess = xmlObj.responseXML.getElementsByTagName("mess")[0];
      if (mess.childNodes.length == 0) alert("Buget salvat");
      else alert(mess.firstChild.data);
    }
    else if (response_type == "doneCalcAutoBuget") {
      var f = document.Bugete;
      var VRA = xmlObj.responseXML.getElementsByTagName("VRA")[0].firstChild.data;
      var valuta = xmlObj.responseXML.getElementsByTagName("valuta")[0].firstChild.data;
      var curs = xmlObj.responseXML.getElementsByTagName("curs")[0].firstChild.data;
      if (confirm("Pentru a realiza acest cost al marfi va trebuie un buget de " + myround((cost_marfa_dorit / VRA), 0) + valuta + ". Salvati noul buget?")){
        f.buget.value = myround((cost_marfa_dorit / curs) / VRA, 0);
        Save();
      }
    }
    else if (response_type == "doneLoadMail") {
      var f = document.MailClienti;
      var subject = xmlObj.responseXML.getElementsByTagName("subject")[0];
      var body = xmlObj.responseXML.getElementsByTagName("body")[0];
      if (subject.childNodes.length>0) f.subiect.value = subject.firstChild.data;
      if (body.childNodes.length>0) {
        var b = body.firstChild.data;
        b = ReplaceAll("&lt;", "<", b);
        b = ReplaceAll("&gt;", ">", b);
        b = ReplaceAll("&amp;", "&", b);
        f.mymail.value = b;
        tinyMCE.updateContent("mymail");
      }
      f.la_clienti.checked = (xmlObj.responseXML.getElementsByTagName("la_clienti")[0].firstChild.data == 1?true:false);
      f.la_useri.checked = (xmlObj.responseXML.getElementsByTagName("la_useri")[0].firstChild.data == 1?true:false);
      f.personalizat.checked = (xmlObj.responseXML.getElementsByTagName("personalizat")[0].firstChild.data == 1?true:false);
    }
    else if (response_type == "doneSaveMail") {
      /* var mess = xmlObj.responseXML.getElementsByTagName("mess")[0];
      alert(mess.firstChild.data); */
      alert("Mail salvat");
    }
    else if (response_type == "doneOpenComanda"){
      var xml = xmlObj.responseXML;
      if (xml.getElementsByTagName("mes")[0].firstChild != null) alert(xml.getElementsByTagName("mes")[0].firstChild.data);
      else {
        var loc = window.location.toString();
        var p1 = Array();
        p1 = loc.split("suboption=");
        var new_loc = p1[0] + "suboption=Noi";
        new_loc = new_loc + "&brand=" + xml.getElementsByTagName("brand")[0].firstChild.data;
        window.location = new_loc;
      }
    }
    else if (response_type == "doneGetUseri"){
      var xml = xmlObj.responseXML;
      UpdateUseriCOMBO(xml);
    }
    else if (response_type == "doneChangeRole"){
      /* var xml = xmlObj.responseXML;
      var f = document.change_rol;
      f.action += "&auto=&user=" + xml.getElementsByTagName("id_user")[0].firstChild.data +"&pass=" + xml.getElementsByTagName("password")[0].firstChild.data; */
      document.change_rol.submit();
    }
    else if (response_type == "doneAplicaTaxaCatalog"){
      SendRequestUpdateCos3();
    }
    else if (response_type == "doneGetAdrese"){
      var xml = xmlObj.responseXML;
      var adrese = xml.getElementsByTagName("adrese");
      var f = document.Etichete;
      for (var i = 0; i<adrese.length; i++)
        f.adresa.options[i] = new Option(adrese[i].getElementsByTagName("adresa")[0].firstChild.data, adrese[i].getElementsByTagName("id_adresa_postala")[0].firstChild.data);
    }
    else if (response_type == "doneGetPuncte"){
      var xml = xmlObj.responseXML;
      var html = xml.getElementsByTagName("html")[0].firstChild.data;
      html = ReplaceAll("&lt;", "<", html);
      html = ReplaceAll("&gt;", ">", html);
      html = ReplaceAll("&amp;", "&", html);
      var column = document.getElementById("BUT_PUNCTE");
      column.innerHTML = html;
    }
    else if (response_type == "doneGetPromotieTemp"){
      var xml = xmlObj.responseXML;
      var html = xml.getElementsByTagName("html")[0].firstChild.data;
      html = ReplaceAll("&lt;", "<", html);
      html = ReplaceAll("&gt;", ">", html);
      html = ReplaceAll("&amp;", "&", html);
      var column = document.getElementById("BUT_TEMP");
      column.innerHTML = html;
    }
    else if (response_type == "doneSetPuncte"){
      var xml = xmlObj.responseXML;
      var puncte = xml.getElementsByTagName("puncte")[0].firstChild.data;
      var total = xml.getElementsByTagName("total")[0].firstChild.data;
      var id_factura = xml.getElementsByTagName("id_factura")[0].firstChild.data;
      var column = document.getElementById("BUT_PUNCTE");
      column.innerHTML = "";
      var id;

      var div = document.getElementById("KFACTURI");
      var tabs = div.getElementsByTagName("TABLE");
      var tab = tabs[2];
      for (var i = RowStart(); i<tab.rows.length; i++) {
        if (tab.rows[i].cells[1].className.indexOf("selected") != -1){
          id=tab.rows[i].cells[0].innerHTML;
          if (!IsNumeric(id)) id=id.substr(1);
          if (id == id_factura) {
            tab.rows[i].cells[4].innerHTML = total;
            tab.rows[i].cells[FACTURI_COL_PUNCTE].innerHTML = puncte;
          }
        }
      }
    }
  }
  xmlObj.open (method, file, asinc);
  if (method=='POST') xmlObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlObj.send (send_text);
  return xmlObj;
}

function ActionDepozit(tipAction, params){
  switch (tipAction){
    case 0: case 1: GetDate(params);break;
    case 2:
    	var f = document.ProduseComplementare;
    	f.action += "&" + params;
    	f.submit();
    break;
  }
}

function _SelTemp(idx){
  var sel = document.getElementById("sel" + idx);
  sel.src="images/skin/buton-" + idx.substring(1) + "b.gif";
}

function _DeSelTemp(idx){
  var sel = document.getElementById("sel" + idx);

  if(idx.substring(1) != current_page) sel.src="images/skin/buton-" + idx.substring(1) + "a.gif";
}

function getXMLData(xml, tag_name, default_value){
	var data = xml.getElementsByTagName(tag_name);
	if (data.length == 0) 
		return 'TAG NAME NOT FOUND';
	if (data[0].childNodes.length > 0) 
		return (data[0].firstChild.data).replace(/^\s*|\s*$/g,'');
	if (default_value == null) 
		return '';
	return default_value;
}

function ajaxRead2(file, method, asinc, send_text, func, params){
  var xmlObj = null;
  if(window.XMLHttpRequest){
    xmlObj = new XMLHttpRequest();
  } else if(window.ActiveXObject){
    xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
  } else {
    return;
  }
  xmlObj.onreadystatechange = function(){
    xml = xmlObj.responseXML;
    if (xmlObj.readyState == 4) if (xmlObj.status == 200) {
      if (xml.getElementsByTagName("eroare_modul").length > 0) {
      }
      else{
        if (typeof(func) == "function") {
          if (params == "undefined") func(xml);
          else func(xml, params);
        }
      }
    }
  }
  xmlObj.open (method, file, asinc);
  if (method=='POST') {
    send_text = send_text.replace(/\+/g, escape("&#43;"));
    xmlObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  }
  xmlObj.send(send_text);
}

function disableSite(){
  w = document.body.offsetWidth;
  if (!OP_browser()) h = document.body.offsetHeight;
  else h = document.body.parentElement.offsetHeight;

  if (h < screen.height) h = screen.height;
  
  h = document.body.scrollHeight;

  if (IE_browser()) document.body.scroll = "no";
  else {
    document.body.style.overflow = "hidden";
  }

  layer++;

  var img = document.createElement('img');
  img.setAttribute("src", "/images/skin/transp.png");
  img.setAttribute("width", screen.width - 20);
  img.setAttribute("height", h);
  img.setAttribute("id", "img_disable_site" + layer);

  var div = document.createElement('div');
  div.style.position = "absolute";
  div.style.left = 0;
  div.style.top = 0;
  div.setAttribute("id", "disable_site" + layer);
  div.setAttribute("width", screen.width - 20);
  div.setAttribute("height", h);
  div.appendChild(img);
  div.style.zIndex = layer - 1;
  document.body.appendChild(div);

}

function enableSite(){
  var div = document.getElementById("disable_site" + layer);
  document.body.removeChild(div);
  layer--;
  if (layer == 1){
    if (IE_browser()) document.body.scroll = "yes";
    else document.body.style.overflow = "auto";
  }
}

function siteDisabled(){
  return (layer > 1);
}