// JavaScript Document

window.onload = function()
{
	//alert(navigator.appVersion.indexOf("MSIE"));
  if (window.ActiveXObject)//navigator.appVersion.indexOf("MSIE")!=-1
  {//
    var field = document.getElementsByTagName("input"); 
    for(var i = 0; i < field.length; i++)
	{
      if (field[i].type == "text" || field[i].type == "password")
	  { 
	  	field[i].className += " inputblur";
        field[i].onfocus = function()
		{ 
			this.className = this.className.replace(/\binputblur\b/, "");
          	this.className += " inputfocus"; 
        };
		field[i].onblur = function()
		{ 
          this.className = this.className.replace(/\binputfocus\b/, "");
		  this.className += " inputblur";
        };   
      }; 
    }; 
	field = null; 

	var field = document.getElementsByTagName("textarea"); 
    for(var i = 0; i < field.length; i++)
	{
		field[i].className += " inputblur";
		field[i].onfocus = function()
		{ 
			this.className = this.className.replace(/\binputblur\b/, "");
	        this.className += " inputfocus"; 
        };
		field[i].onblur = function()
		{ 
          this.className = this.className.replace(/\binputfocus\b/, "");
		  this.className += " inputblur";
        };      
    }; 
	field = null;
	
	var field = document.getElementsByTagName("select"); 
    for(var i = 0; i < field.length; i++)
	{
		field[i].className += " inputblur";
		/*
		field[i].onfocus = function()
		{ 
			this.className = this.className.replace(/\binputblur\b/, "");
	        this.className += " inputfocus"; 
        };
		field[i].onblur = function()
		{ 
          this.className = this.className.replace(/\binputfocus\b/, "");
		  this.className += " inputblur";
        };
		*/
    }; 
	field = null;	
	
  }; 
};


Array.prototype.inArray = function (value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
    var i;
    for (i=0; i < this.length; i++) {
        // Matches identical (===), not just similar (==).
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

function exp_electronic()
{
	var disable;
	var cb=document.getElementById("expediat_electronic_delegat");
	if (cb.checked)
	{
		disable=true;
	}
	else
	{
		disable=false;
	}
	document.getElementById("nume_delegat").disabled=disable;
	document.getElementById("tip_act_delegat").disabled=disable;
	document.getElementById("act_seria_delegat").disabled=disable;
	document.getElementById("act_numar_delegat").disabled=disable;
	document.getElementById("eliberat_de_delegat").disabled=disable;
	document.getElementById("data_expediere_delegat_trigger").disabled=disable;
	document.getElementById("salveaza_delegat_nou").disabled=disable;
}

function delete_cont(id)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest cont?'))
	{
		window.location.href='index.php?module=admin&page=conturi&action=delete&id='+id;	
	}	
}

function delete_furnizor(id)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest furnizor?'))
	{
		window.location.href='index.php?module=admin&page=setare_date_furnizor&action=delete&id='+id;	
	}	
}

function modifica_user(id)
{
	document.getElementById("username").value=document.getElementById("h_username_"+id).value;
	document.getElementById("email").value=document.getElementById("h_email_"+id).value;
	document.getElementById("name").value=document.getElementById("h_name_"+id).value;
	document.getElementById("cnp").value=document.getElementById("h_cnp_"+id).value;
	document.getElementById("act_id").value=document.getElementById("h_act_id_"+id).value;
	document.getElementById("user_id").value=document.getElementById("h_user_id_"+id).value;
	document.getElementById("p_user_id").value=document.getElementById("h_user_id_"+id).value;
	/*
	var str=String();
	str=document.getElementById("h_access_"+id).value
	if (str.indexOf('admin')!=-1)
	{
		document.getElementById("access_admin").checked=true;
	}
	else
	{
		document.getElementById("access_admin").checked=false;
	}
	if (str.indexOf('aimfact')!=-1)
	{
		document.getElementById("access_aimfact").checked=true;
	}
	else
	{
		document.getElementById("access_aimfact").checked=false;
	}
	*/
}

function modifica_furnizor(id)
{
	document.getElementById("denumire_furnizor").value=document.getElementById("h_denumire_furnizor_"+id).value;
	document.getElementById("nr_orc_furnizor").value=document.getElementById("h_nr_orc_furnizor_"+id).value;
	document.getElementById("cif_furnizor").value=document.getElementById("h_cif_furnizor_"+id).value;
	document.getElementById("capital_social_furnizor").value=document.getElementById("h_capital_social_furnizor_"+id).value;
	document.getElementById("sediu_furnizor").value=document.getElementById("h_sediu_furnizor_"+id).value;
	document.getElementById("telefon_furnizor").value=document.getElementById("h_telefon_furnizor_"+id).value;
	document.getElementById("fax_furnizor").value=document.getElementById("h_fax_furnizor_"+id).value;
	document.getElementById("email_furnizor").value=document.getElementById("h_email_furnizor_"+id).value;
	document.getElementById("web_furnizor").value=document.getElementById("h_web_furnizor_"+id).value;
	document.getElementById("punct_de_lucru_furnizor").value=document.getElementById("h_punct_de_lucru_furnizor_"+id).value;
	document.getElementById("observatii_furnizor").value=document.getElementById("h_observatii_furnizor_"+id).value;
	document.getElementById("furnizor_id").value=id;
	for(i=0;i<document.getElementById("judet_furnizor").options.length;i++)
	{		
		if (document.getElementById("h_judet_furnizor_"+id).value==document.getElementById("judet_furnizor").options[i].value)
		{
			document.getElementById("judet_furnizor").options[i].selected=true;
		}				
	}
}

function modifica_facturier(id)
{
	renunta_facturier();
	document.getElementById("serie_facturier").value=document.getElementById("h_serie_facturier_"+id).value;
	document.getElementById("start_numar_facturier").value=document.getElementById("h_start_numar_facturier_"+id).value;
	document.getElementById("end_numar_facturier").value=document.getElementById("h_end_numar_facturier_"+id).value;
	document.getElementById("note_facturier").value=document.getElementById("h_note_facturier_"+id).value;
	document.getElementById("logo_facturier_img").src=document.getElementById("h_logo_facturier_"+id).value;
	document.getElementById("facturier_id").value=id;
	document.getElementById("fact_nou").disabled=true;
	var str_user_ids = document.getElementById("h_user_ids_"+id).value;
	var user_ids = str_user_ids.split(',');
	for(i=0;i<document.getElementById("user_ids_select_facturier").options.length;i++)
	{
		document.getElementById("user_ids_select_facturier").options[i].selected=false;
		if (user_ids.inArray(document.getElementById("user_ids_select_facturier").options[i].value))
		{
			document.getElementById("user_ids_select_facturier").options[i].selected=true;
		}				
	}
	for(i=0;i<document.getElementById("furnizor_id").options.length;i++)
	{		
		if (document.getElementById("h_furnizor_id_"+id).value==document.getElementById("furnizor_id").options[i].value)
		{
			document.getElementById("furnizor_id").options[i].selected=true;
		}				
	}
}

function renunta_facturier()
{
	document.getElementById("serie_facturier").value='';
	document.getElementById("start_numar_facturier").value='';
	document.getElementById("end_numar_facturier").value='';
	document.getElementById("note_facturier").value='';
	document.getElementById("facturier_id").value='';
	document.getElementById("logo_facturier_img").src='';
	document.getElementById("fact_nou").disabled=false;
	document.getElementById("furnizor_id").options[0].selected=true;
	for(i=0;i<document.getElementById("user_ids_select_facturier").options.length;i++)
	{
		document.getElementById("user_ids_select_facturier").options[i].selected=false;						
	}
	document.getElementById('error1').innerHTML='';
	document.getElementById('success1').innerHTML='';
}

function modifica_chitantier(id)
{
	renunta_chitantier();
	document.getElementById("serie_chitantier").value=document.getElementById("h_serie_chitantier_"+id).value;
	document.getElementById("start_numar_chitantier").value=document.getElementById("h_start_numar_chitantier_"+id).value;
	document.getElementById("end_numar_chitantier").value=document.getElementById("h_end_numar_chitantier_"+id).value;
	document.getElementById("note_chitantier").value=document.getElementById("h_note_chitantier_"+id).value;
	document.getElementById("logo_chitantier_img").src=document.getElementById("h_logo_chitantier_"+id).value;
	document.getElementById("chitantier_id").value=id;
	document.getElementById("chit_nou").disabled=true;
	var str_user_ids = document.getElementById("h_user_ids_c_"+id).value;
	var user_ids = str_user_ids.split(',');
	for(i=0;i<document.getElementById("user_ids_select_chitantier").options.length;i++)
	{
		document.getElementById("user_ids_select_chitantier").options[i].selected=false;
		if (user_ids.inArray(document.getElementById("user_ids_select_chitantier").options[i].value))
		{
			document.getElementById("user_ids_select_chitantier").options[i].selected=true;
		}				
	}
	for(i=0;i<document.getElementById("furnizor_id_c").options.length;i++)
	{		
		if (document.getElementById("h_furnizor_id_c_"+id).value==document.getElementById("furnizor_id_c").options[i].value)
		{
			document.getElementById("furnizor_id_c").options[i].selected=true;
		}				
	}
}

function renunta_chitantier()
{
	document.getElementById("serie_chitantier").value='';
	document.getElementById("start_numar_chitantier").value='';
	document.getElementById("end_numar_chitantier").value='';
	document.getElementById("note_chitantier").value='';
	document.getElementById("chitantier_id").value='';
	document.getElementById("logo_chitantier_img").src='';
	document.getElementById("chit_nou").disabled=false;
	document.getElementById("furnizor_id_c").options[0].selected=true;
	for(i=0;i<document.getElementById("user_ids_select_chitantier").options.length;i++)
	{
		document.getElementById("user_ids_select_chitantier").options[i].selected=false;						
	}	
	document.getElementById('error2').innerHTML='';	
	document.getElementById('success2').innerHTML='';
}

function delete_facturier(id)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest facturier?'))
	{
		document.form_setare_facturier.action='index.php?module=admin&page=setare_aplicatie&action=delete_facturier&id='+id;
		document.form_setare_facturier.submit();
	}
}

function delete_chitantier(id)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest chitantier?'))
	{
		document.form_setare_chitantier.action='index.php?module=admin&page=setare_aplicatie&action=delete_chitantier&id='+id;
		document.form_setare_chitantier.submit();
	}
}

function delete_user(id)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest utilizator?'))
	{
		window.location.href='index.php?module=admin&page=lista_utilizatorilor&action=delete&id='+id;	
	}
}


function schimba_moneda()
{
	if (document.getElementById("moneda").options[document.getElementById("moneda").selectedIndex].value=="RON")
	{
		document.getElementById("echivalent").value="1.00";
		document.getElementById("echivalent").readOnly=true;
	}
	else
	{		
		document.getElementById("echivalent").value="";
		document.getElementById("echivalent").readOnly=false;
	}
}

function delete_produs(index)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest produs/serviciu?'))
	{
		document.form_inregistrare_factura.action='index.php?module=aimfact&page=inregistrare_factura&action=delete&deleteindex='+index;
		document.form_inregistrare_factura.submit();
	}
}

function delete_produs_modificare(index)
{
	if (confirm('Sunteti sigur ca vreti sa stergeti acest produs/serviciu?'))
	{
		document.form_modificare_factura.action='index.php?module=aimfact&page=modificare_factura&action=delete&deleteindex='+index;
		document.form_modificare_factura.submit();
	}
}

function save_factura()
{
	document.form_inregistrare_factura.action='index.php?module=aimfact&page=inregistrare_factura&action=save';
	document.form_inregistrare_factura.submit();
}

function save_factura_modificata()
{
	document.form_modificare_factura.action='index.php?module=aimfact&page=modificare_factura&action=save';
	document.form_modificare_factura.submit();
}

function show_hide_chitantier()
{
	if (document.getElementById('genereaza_chitanta').checked)
	{
		document.getElementById('chitantier_tr').style.display='';
	}
	else
	{
		document.getElementById('chitantier_tr').style.display='none';
	}
}

function anuleaza_factura()
{
	if (confirm('Sunteti sigur ca vreti sa anulati aceasta factura?'))
	{
		document.form_modificare_factura.action='index.php?module=aimfact&page=modificare_factura&action=anuleaza';
		document.form_modificare_factura.submit();
	}
}

function sterge_factura()
{
	if (confirm('Sunteti sigur ca vreti sa stergeti aceasta factura?'))
	{
		document.form_modificare_factura.action='index.php?module=aimfact&page=modificare_factura&action=sterge';
		document.form_modificare_factura.submit();
	}
}

function anuleaza_chitanta()
{
	if (confirm('Sunteti sigur ca vreti sa anulati aceasta chitanta?'))
	{
		document.form_modificare_chitanta.action='index.php?module=aimfact&page=modificare_chitanta&action=anuleaza';
		document.form_modificare_chitanta.submit();
	}
}

function sterge_chitanta()
{
	if (confirm('Sunteti sigur ca vreti sa stergeti aceasta chitanta?'))
	{
		document.form_modificare_chitanta.action='index.php?module=aimfact&page=modificare_chitanta&action=sterge';
		document.form_modificare_chitanta.submit();
	}
}
