
function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function getWindowHeight() {
var windowHeight=0;
if (typeof(window.innerHeight)=='number') {
windowHeight=window.innerHeight;
}
else {
if (document.documentElement&&
document.documentElement.clientHeight) {
windowHeight=document.documentElement.clientHeight;
}
else {
if (document.body&&document.body.clientHeight) {
windowHeight=document.body.clientHeight;
}
}
}
return windowHeight;
}

function getWindowWidth() {
var windowHeight=0;
if (typeof(window.innerWidth)=='number') {
windowHeight=window.innerWidth;
}
else {
if (document.documentElement&&
document.documentElement.clientWidth) {
windowHeight=document.documentElement.clientWidth;
}
else {
if (document.body&&document.body.clientWidth) {
windowHeight=document.body.clientWidth;
}
}
}
return windowHeight;
}


function blocheaza(){
		st=document.createElement("div");
		st.id="block_surface";
		document.body.appendChild(st);
//		st.style="filter:alpha(opacity=50); -moz-opacity:0.5";
		st.style.display='block';
		st.style.position='absolute';
		st.style.top="0px";
		st.style.left="0px";
		st.style.backgroundColor="#333333";
		st.style.width="100%";
		inaltime=getWindowHeight();
		st.style.height=inaltime+"px";
		st.style.zIndex="15000";
		opacity=50;
			 if (navigator.appName.indexOf("Netscape")!=-1
			  &&parseInt(navigator.appVersion)>=5)
				st.style.MozOpacity=opacity/100;
			 else if (navigator.appName.indexOf("Microsoft")!= -1 
			  &&parseInt(navigator.appVersion)>=4)
				st.filter="opacity:50";
			
//		alert (document.body.clientHeight);
//		alert (clientHeight);
//		st.style.height=document.body.clientHeight+"px";
		st.innerHTML="XXX";
	}

function afiseaza_calendar(obj){
	st=document.getElementById('calendar_container');
	if(!st){
		st=document.createElement("div");
		st.id="calendar_container";
		document.body.appendChild(st);
	}
		st.style.display='block';
		st.style.position='absolute';
		st.style.top=findPosY(obj)+"px";
		st.style.left=findPosX(obj)+"px";
		st.style.backgroundColor="#333333";

valoare_actuala=obj.value;
valori_separate=valoare_actuala.split("-");

for(x=0;x<=valori_separate.length;x++){
		if((valori_separate[x]*1)<10){
			valori_separate[x]="0"+valori_separate[x];
		}
}

string_actual=valori_separate[1]+"/"+valori_separate[0];
data_selectata=valori_separate[1]+"/"+valori_separate[2]+"/"+valori_separate[0];

	cal1 = new YAHOO.widget.Calendar("cal1","calendar_container",string_actual,data_selectata);
			cal1.maxDate = YAHOO.widget.DateMath.add(new Date(), YAHOO.widget.DateMath.DAY, 0);
			cal1.onSelect=function(){
				data_aleasa=new Date();
				data_aleasa=cal1.getSelectedDates();
				data_finala_de_prelucrat=new String();
				data_finala_de_prelucrat=cal1._toFieldArray(data_aleasa);
//				datafinala=data_finala_de_prelucrat.split(",");
				obj.value=data_finala_de_prelucrat;//datafinala[0]+"-"+datafinala[1]+"-"+datafinala[2];
				//alert(data_aleasa);.toDateString("yyyy-mm-dd"));*/
				ascunde_calendar(obj);
			}
			cal1.render();
}

function ascunde_calendar(obj){
	valoare=obj.value;
	valori=valoare.split(",");
	obj.value=valori[0]+"-"+valori[1]+"-"+valori[2];
	calendar_holder=document.getElementById('calendar_container');
	if(calendar_holder){
			while (calendar_holder.firstChild) {
				calendar_holder.removeChild(calendar_holder.firstChild);
			}
	}
}


//////////////////////////////////////////////////////////////////////////////////
///Cautare clienti
//////////////////////////////////////////////////////////////////////////////////

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

var lista_localitati;
var index_localitate=-1;
var total_localitati=0;

//cauta clienti
function populeaza_localitati(obiect){
	
/*			selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='hidden';
			}*/

if(obiect==1){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_expeditor;
obx=1;
}
if(obiect==2){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_destinatar;
obx=2;
}
if(obiect==3){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_taxe;
obx=5;
}
if(obiect==4){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_ramburs;
obx=6;
}

if(obiect==31){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_ramb;
obx=31;
}

if(obiect==100){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client;
obx=100;
}


container_box=document.getElementById('container_ajax');
container_box.innerHTML='Asteptati...';
container_box.style.top=(findPosY(box_in_cauza))+"px";
container_box.style.left=(findPosX(box_in_cauza)+50)+"px";
container_box.style.width="100px";
container_box.style.display='block';

urlstring="d1_x_list_clienti.php?masca="+box_in_cauza.value;
if(obiect==1) urlstring="d1_x_list_clienti.php?masca="+box_in_cauza.value+"&restrict=birou";

	 xmlhttp.open("GET", urlstring ,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
			container_box.style.display='none';
	   lista_localitati=xmlhttp.responseText.split("!@#");
	      
	   total_localitati=lista_localitati.length;
	   if(total_localitati>=1) index_localitate=0;
	    
	   //verifica daca exista UL-ul ce contine localitati. daca nu exista il creaza
	   ulLocalitati=document.getElementById('ul_localitati');
	   if(ulLocalitati){ 
			while (ulLocalitati.firstChild) {
				ulLocalitati.removeChild(ulLocalitati.firstChild);
			}
	   }

	   if(!ulLocalitati){
	   		ulLocalitati=document.createElement("ul");
			ulLocalitati.id='ul_localitati';
			document.body.appendChild(ulLocalitati);
	   }
	   
	   ulLocalitati.style.backgroundColor='#CCCCCC';
	   ulLocalitati.style.width="200px";
	   ulLocalitati.style.position="absolute";
	   ulLocalitati.style.display="block";
		ulLocalitati.style.zIndex=10000;
	   ulLocalitati.className="localitati";
   	   ulLocalitati.style.top=(findPosY(box_in_cauza))+"px";
		if(obiect==3 || obiect==4){
		ulLocalitati.style.left=(findPosX(box_in_cauza)-200)+"px";
		}else{
		ulLocalitati.style.left=(findPosX(box_in_cauza)+150)+"px";
		}

var IfrRef = document.getElementById('DivShim');
IfrRef.style.width = ulLocalitati.offsetWidth;
IfrRef.style.height = "200px";
if(obiect==2) IfrRef.style.height = "500px";
IfrRef.style.top = ulLocalitati.style.top;
IfrRef.style.left = ulLocalitati.style.left;
IfrRef.style.zIndex = ulLocalitati.style.zIndex - 1;
IfrRef.style.display = "block";
IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';

	//creaza primul li
	   		liActiv=document.createElement("li");
			ulLocalitati.appendChild(liActiv);
	   		aActiv=document.createElement("a");
			liActiv.appendChild(aActiv);
			aActiv.href="javascript:;";
			aActiv.className="marcat";
			de_afisat=lista_localitati[0].split("^&*");
			aActiv.innerHTML=de_afisat[0]+" , "+de_afisat[3];
			aActiv.id=0;
			aActiv.onclick=function(){fill_up(obx,this.id);}
	
		//creaza alte 5 li_uri
			
			for(x=1;x<=5;x++){
				if(lista_localitati[x]){
					liNormal=document.createElement("li");
					ulLocalitati.appendChild(liNormal);
					aNormal=document.createElement("a");
					liNormal.appendChild(aNormal);
					aNormal.href="javascript:;";
					de_afisat=lista_localitati[x].split("^&*");
					aNormal.innerHTML=de_afisat[0]+" , "+de_afisat[3];
					aNormal.id=x;
					aNormal.onclick=function(){fill_up(obx,this.id);}
				}			
			}
			
		//adauga scroll_down_daca e necesar
			if(lista_localitati.length>6){
				liScrollDown=document.createElement("li");
				ulLocalitati.appendChild(liNormal);
				aNormal=document.createElement("a");
				liNormal.appendChild(aNormal);
				aNormal.href="javascript:;";
				aNormal.className="scroll";
				aNormal.innerHTML='<img src="images/sort_desc.gif" border=0 />';
				aNormal.onclick=function(){index_localitate++; reordoneaza_lista_localitati(obx);}
			}
	  }
	 }
	 xmlhttp.send(null)

}

//cauta localitati
function populeaza_localitati2(obiect){
	
		/*	selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='hidden';
			}*/
	
	
if(obiect==1){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_expeditor;
obx=3;
}
if(obiect==2){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_destinatar;
obx=4;
}
if(obiect==3){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_taxe;
obx=7;
}
if(obiect==4){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_ramburs;
obx=8;
}

if(obiect==30){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_ramb;
obx=30;
}

container_box=document.getElementById('container_ajax');
container_box.innerHTML='Asteptati...';
container_box.style.top=(findPosY(box_in_cauza))+"px";
container_box.style.left=(findPosX(box_in_cauza)+50)+"px";
container_box.style.width="100px";
container_box.style.display='block';

urlstring="d0_x_list_localitati.php?masca="+box_in_cauza.value;
if(obiect==1) urlstring="d0_x_list_localitati.php?masca="+box_in_cauza.value+"&restrict=birou";


	 xmlhttp.open("GET", urlstring,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
			container_box.style.display='none';
	   lista_localitati=xmlhttp.responseText.split("!@#");
	      
	   total_localitati=lista_localitati.length;
	   if(total_localitati>=1) index_localitate=0;
	    
	   //verifica daca exista UL-ul ce contine localitati. daca nu exista il creaza
	   ulLocalitati=document.getElementById('ul_localitati');
	   if(ulLocalitati){ 
			while (ulLocalitati.firstChild) {
				ulLocalitati.removeChild(ulLocalitati.firstChild);
			}
	   }

	   if(!ulLocalitati){
	   		ulLocalitati=document.createElement("ul");
			ulLocalitati.id='ul_localitati';
			document.body.appendChild(ulLocalitati);
	   }
	   
	   ulLocalitati.style.backgroundColor='#CCCCCC';
	   ulLocalitati.style.width="200px";
	   ulLocalitati.style.position="absolute";
	   ulLocalitati.style.display="block";
	   ulLocalitati.className="localitati";
   	   ulLocalitati.style.top=(findPosY(box_in_cauza))+"px";
		if(obiect==3 || obiect==4){
		ulLocalitati.style.left=(findPosX(box_in_cauza)-200)+"px";
		}else{
		ulLocalitati.style.left=(findPosX(box_in_cauza)+150)+"px";
		}

var IfrRef = document.getElementById('DivShim');
IfrRef.style.width = ulLocalitati.offsetWidth;
IfrRef.style.height = "200px";
IfrRef.style.top = ulLocalitati.style.top;
IfrRef.style.left = ulLocalitati.style.left;
IfrRef.style.zIndex = ulLocalitati.style.zIndex - 1;
IfrRef.style.display = "block";
IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';


	   //creaza primul li
	   		liActiv=document.createElement("li");
			ulLocalitati.appendChild(liActiv);
	   		aActiv=document.createElement("a");
			liActiv.appendChild(aActiv);
			aActiv.href="javascript:;";
			aActiv.className="marcat";
			de_afisat=lista_localitati[0].split("^&*");
			aActiv.innerHTML=de_afisat[0]+" , "+de_afisat[3];
			aActiv.id=0;
			aActiv.onclick=function(){fill_up(obx,this.id);}
	
		//creaza alte 5 li_uri
			
			for(x=1;x<=5;x++){
				if(lista_localitati[x]){
					liNormal=document.createElement("li");
					ulLocalitati.appendChild(liNormal);
					aNormal=document.createElement("a");
					liNormal.appendChild(aNormal);
					aNormal.href="javascript:;";
					de_afisat=lista_localitati[x].split("^&*");
					aNormal.innerHTML=de_afisat[0]+" , "+de_afisat[3];
					aNormal.id=x;
					aNormal.onclick=function(){fill_up(obx,this.id);}
				}			
			}
			
		//adauga scroll_down_daca e necesar
			if(lista_localitati.length>6){
				liScrollDown=document.createElement("li");
				ulLocalitati.appendChild(liNormal);
				aNormal=document.createElement("a");
				liNormal.appendChild(aNormal);
				aNormal.href="javascript:;";
				aNormal.className="scroll";
				aNormal.innerHTML='<img src="images/sort_desc.gif" border=0 />';
				aNormal.onclick=function(){index_localitate++; reordoneaza_lista_localitati(obx);}
			}
	  }
	 }
	 xmlhttp.send(null)

}

//functia completeaza campurile necesare daca se da click pe un element din lista
function fill_up(obiect,x){
//alert(x+lista_localitati[x]);
//return;
	if(obiect==1){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client_expeditor;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('adresa_expeditor').value=de_afisat[1];
		document.getElementById('judet_expeditor').value=de_afisat[2];
		document.getElementById('localitate_expeditor').value=de_afisat[3];
		document.getElementById('persoana_expeditor').value=de_afisat[4];
		document.getElementById('telefon_expeditor').value=de_afisat[5];
		document.getElementById('km_expeditor').value=de_afisat[6];
		document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
		document.getElementById('birou_expeditor').value=de_afisat[7];		
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_destinatar').focus();
	}
	if(obiect==2){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client_destinatar;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('adresa_destinatar').value=de_afisat[1];
		document.getElementById('judet_destinatar').value=de_afisat[2];
		document.getElementById('localitate_destinatar').value=de_afisat[3];
		document.getElementById('persoana_destinatar').value=de_afisat[4];
		document.getElementById('telefon_destinatar').value=de_afisat[5];
		document.getElementById('km_destinatar').value=de_afisat[6];
		document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
		document.getElementById('birou_destinatar').value=de_afisat[7];		
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('masa1').focus();
	}
	if(obiect==3){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.localitate_expeditor;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('km_expeditor').value=de_afisat[2];
		document.getElementById('birou_expeditor').value=de_afisat[1];
		document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
		document.getElementById('judet_expeditor').value=de_afisat[3];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_destinatar').focus();
	}
	if(obiect==4){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.localitate_destinatar;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		
		document.getElementById('km_destinatar').value=de_afisat[2];
		document.getElementById('birou_destinatar').value=de_afisat[1];
		document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
		document.getElementById('judet_destinatar').value=de_afisat[3];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('masa1').focus();
	}
	if(obiect==5){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client_taxe;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('adresa_taxe').value=de_afisat[1];
		document.getElementById('judet_taxe').value=de_afisat[2];
		document.getElementById('localitate_taxe').value=de_afisat[3];
		document.getElementById('persoana_taxe').value=de_afisat[4];
		document.getElementById('telefon_taxe').value=de_afisat[5];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_taxe').focus();
	}
	if(obiect==6){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client_ramburs;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('adresa_ramburs').value=de_afisat[1];
		document.getElementById('judet_ramburs').value=de_afisat[2];
		document.getElementById('localitate_ramburs').value=de_afisat[3];
		document.getElementById('persoana_ramburs').value=de_afisat[4];
		document.getElementById('telefon_ramburs').value=de_afisat[5];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_ramburs').focus();
	}
	if(obiect==7){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.localitate_taxe;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('judet_taxe').value=de_afisat[3];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_taxe').focus();
	}
	if(obiect==8){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.localitate_ramburs;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('judet_ramburs').value=de_afisat[3];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_destinatar').focus();
	}
	
	if(obiect==30){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.localitate_ramb;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('judet_ramb').value=de_afisat[3];
		document.getElementById('birou_ramb').value=de_afisat[1];
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_destinatar').focus();
	}	
	if(obiect==31){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client_ramb;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('adresa_ramb').value=de_afisat[1];
		document.getElementById('judet_ramb').value=de_afisat[2];
		document.getElementById('localitate_ramb').value=de_afisat[3];
		document.getElementById('persoana_ramb').value=de_afisat[4];
		document.getElementById('telefon_ramb').value=de_afisat[5];
		document.getElementById('km_ramb').value=de_afisat[6];
//		document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
		document.getElementById('birou_ramb').value=de_afisat[7];		
		document.getElementById('ul_localitati').style.display='none';
		document.getElementById('persoana_destinatar').focus();
	}
	
	if(obiect==100){
	form_in_cauza=document.getElementById('form1');
	box_in_cauza=form_in_cauza.client;
		de_afisat=lista_localitati[x].split("^&*");
		box_in_cauza.value=de_afisat[0];
		document.getElementById('ul_localitati').style.display='none';		
		document.getElementById('clientID').value=de_afisat[8]; //de afisat ID
	}
	
	
}


//functia are grija sa fie vizibila localitatea selectata
function reordoneaza_lista_localitati(obiect){

			/*selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='hidden';
			}*/


if(obiect==1){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_expeditor;
}
if(obiect==2){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_destinatar;
}
if(obiect==3){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_expeditor;
}
if(obiect==4){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_destinatar;
}
if(obiect==5){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_taxe;
}
if(obiect==6){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_ramburs;
}
if(obiect==7){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_taxe;
}
if(obiect==8){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_ramburs;
}

if(obiect==30){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_ramb;
}

if(obiect==31){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_ramb;
}

if(obiect==100){
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client;
}


ulLocalitati=document.getElementById('ul_localitati');
if(ulLocalitati){ 
	while (ulLocalitati.firstChild) {
		ulLocalitati.removeChild(ulLocalitati.firstChild);
	}
}

if(!ulLocalitati){
	ulLocalitati=document.createElement("ul");
	ulLocalitati.id='ul_localitati';
	document.body.appendChild(ulLocalitati);
}

ulLocalitati.style.backgroundColor='#CCCCCC';
ulLocalitati.style.width="200px";
ulLocalitati.style.position="absolute";
ulLocalitati.style.display="block";
ulLocalitati.className="localitati";
increase=0;


//adauga scroll up daca e nevoie
if(index_localitate>5){
	liScrollUp=document.createElement("li");
	ulLocalitati.appendChild(liScrollUp);
	aNormal2=document.createElement("a");
	liScrollUp.appendChild(aNormal2);
	aNormal2.href="javascript:;";
	aNormal2.className="scroll";
	aNormal2.innerHTML='<img src="images/sort_asc.gif" border=0 />';
	aNormal2.onclick=function(){index_localitate--; reordoneaza_lista_localitati(obiect);}
	increase=17;
}

//creaza primele 5
localitati_deasupra=0;
for(x=index_localitate-5;x<index_localitate;x++){
	if(lista_localitati[x]){
		liNormal=document.createElement("li");
		ulLocalitati.appendChild(liNormal);
		aNormal=document.createElement("a");
		liNormal.appendChild(aNormal);
		aNormal.href="javascript:;";
		de_afisat=lista_localitati[x].split("^&*");
		aNormal.innerHTML=de_afisat[0]+" , "+de_afisat[3];
		aNormal.id=x;
		aNormal.onclick=function(){fill_up(obiect,this.id);}
		localitati_deasupra=localitati_deasupra+1;
	}			
}

//pozitia_ul_ului
ulLocalitati.style.top=(findPosY(box_in_cauza)-(localitati_deasupra*19)-increase)+"px";
		if((obiect==6)||(obiect==8)||(obiect==5)||(obiect==7)){
		ulLocalitati.style.left=(findPosX(box_in_cauza)-200)+"px";
		}else{
		ulLocalitati.style.left=(findPosX(box_in_cauza)+150)+"px";
		}


var IfrRef = document.getElementById('DivShim');
IfrRef.style.width = ulLocalitati.offsetWidth;
IfrRef.style.height = "200px";
if(obiect==2) IfrRef.style.height = "300px";
IfrRef.style.top = ulLocalitati.style.top;
IfrRef.style.left = ulLocalitati.style.left;
IfrRef.style.zIndex = ulLocalitati.style.zIndex - 1;
IfrRef.style.display = "block";
IfrRef.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';


//creaza li Activ
liActiv=document.createElement("li");
ulLocalitati.appendChild(liActiv);
aActiv=document.createElement("a");
liActiv.appendChild(aActiv);
aActiv.href="javascript:;";
aActiv.className="marcat";
			de_afisat=lista_localitati[index_localitate].split("^&*");
aActiv.innerHTML=de_afisat[0]+" , "+de_afisat[3];
aActiv.id=index_localitate;
aActiv.onclick=function(){fill_up(obiect,this.id);}
//creaza alte 5 li_uri

for(x=index_localitate+1;x<=index_localitate+5;x++){
	if(lista_localitati[x]){
		liNormal=document.createElement("li");
		ulLocalitati.appendChild(liNormal);
		aNormal=document.createElement("a");
		liNormal.appendChild(aNormal);
		aNormal.href="javascript:;";
		de_afisat=lista_localitati[x].split("^&*");
		aNormal.innerHTML=de_afisat[0]+" , "+de_afisat[3];
		aNormal.id=x;
		aNormal.onclick=function(){fill_up(obiect,this.id);}
	}			
}

	//adauga scroll_down_daca e necesar
	if(lista_localitati.length-index_localitate>7){
		liScrollDown=document.createElement("li");
		ulLocalitati.appendChild(liScrollDown);
		aNormal=document.createElement("a");
		liScrollDown.appendChild(aNormal);
		aNormal.href="javascript:;";
		aNormal.className="scroll";
		aNormal.innerHTML='<img src="images/sort_desc.gif" border=0 />';
		aNormal.onclick=function(){index_localitate++; reordoneaza_lista_localitati(obiect);}
	}
}



function attach_clienti_events(){
	
	minim_caractere=2;
	if (document.all&&document.getElementById) {
		minim_caractere=2;
	}
	
//expeditor
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_expeditor;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(1);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(1);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(1);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('adresa_expeditor').value=de_afisat[1];
					document.getElementById('judet_expeditor').value=de_afisat[2];
					document.getElementById('localitate_expeditor').value=de_afisat[3];
					document.getElementById('persoana_expeditor').value=de_afisat[4];
					document.getElementById('telefon_expeditor').value=de_afisat[5];
					document.getElementById('km_expeditor').value=de_afisat[6];
					document.getElementById('birou_expeditor').value=de_afisat[7];

document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);					

						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_destinatar.focus();
					}
			}
		}//end if codul
	}



//beneficiar ramburs
form_in_cauza=document.getElementById('form1');
if(form_in_cauza.client_ramb){
	box_in_cauza=form_in_cauza.client_ramb;
	/*	
	box_in_cauza.onblur=function(e){
			document.getElementById('ul_localitati').style.display='none';
			document.form1.Cod_Postal.focus();
		}
		*/
		box_in_cauza.onkeydown=function(e){
			if(document.all){
				codul_tastat=event.keyCode;
			}else{
				codul_tastat=e.keyCode;
			}
			if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
				if((this.value.length)>=minim_caractere){
					populeaza_localitati(31);
				}else{
					if(container_box=document.getElementById('ul_localitati')){
						container_box.style.display='none';
					}
					if(container_box=document.getElementById('container_ajax')){
						container_box.style.display='none';
					}
				}//end if length
			}else{
				if(codul_tastat==40 || codul_tastat==39){
					if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
	//				alert(codul_tastat);
					reordoneaza_lista_localitati(31);
				}
				if(codul_tastat==38 || codul_tastat==37){
					//alert(codul_tastat);
					if(index_localitate>0) index_localitate=index_localitate-1;
					reordoneaza_lista_localitati(31);
				}
				if(codul_tastat==13){
					if(lista_localitati.length>=1){
						de_afisat=lista_localitati[index_localitate].split("^&*");
						this.value=de_afisat[0];
						document.getElementById('adresa_ramb').value=de_afisat[1];
						document.getElementById('judet_ramb').value=de_afisat[2];
						document.getElementById('localitate_ramb').value=de_afisat[3];
						document.getElementById('persoana_ramb').value=de_afisat[4];
						document.getElementById('telefon_ramb').value=de_afisat[5];
						document.getElementById('km_ramb').value=de_afisat[6];
						document.getElementById('birou_ramb').value=de_afisat[7];
	
	document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);					
	
							document.getElementById('ul_localitati').style.display='none';
							document.form1.persoana_destinatar.focus();
						}
				}
			}//end if codul
		}
}



//destinatar
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_destinatar;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(2);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(2);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(2);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('adresa_destinatar').value=de_afisat[1];
					document.getElementById('judet_destinatar').value=de_afisat[2];
					document.getElementById('localitate_destinatar').value=de_afisat[3];
					document.getElementById('persoana_destinatar').value=de_afisat[4];
					document.getElementById('telefon_destinatar').value=de_afisat[5];
					document.getElementById('km_destinatar').value=de_afisat[6];
					document.getElementById('birou_destinatar').value=de_afisat[7];

document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);

						document.getElementById('ul_localitati').style.display='none';
						document.form1.masa1.focus();
					}
			}
		}//end if codul
	}

//localitate expeditor
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_expeditor;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati2(1);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(3);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(3);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('judet_expeditor').value=de_afisat[3];
						document.getElementById('ul_localitati').style.display='none';
					document.getElementById('km_expeditor').value=de_afisat[2];
					document.getElementById('birou_expeditor').value=de_afisat[1];
document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);					
						document.form1.persoana_destinatar.focus();

					}
			}
		}//end if codul
	}
	
//localitate destinatar
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_destinatar;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati2(2);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(4);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(4);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('judet_destinatar').value=de_afisat[3];
						document.getElementById('ul_localitati').style.display='none';
					document.getElementById('km_destinatar').value=de_afisat[2];
					document.getElementById('birou_destinatar').value=de_afisat[1];
document.getElementById('km_exteriori').value=(document.getElementById('km_destinatar').value*1)+(document.getElementById('km_expeditor').value*1);
						document.form1.masa1.focus();
					}
			}
		}//end if codul
	}

//ultimele 2 coloane


//platitor taxe
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_taxe;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(3);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(5);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(5);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('adresa_taxe').value=de_afisat[1];
					document.getElementById('judet_taxe').value=de_afisat[2];
					document.getElementById('localitate_taxe').value=de_afisat[3];
					document.getElementById('persoana_taxe').value=de_afisat[4];
					document.getElementById('telefon_taxe').value=de_afisat[5];
					
						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_taxe.focus();
					}
			}
		}//end if codul
	}

//platitor ramburs
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client_ramburs;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(4);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(6);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(6);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('adresa_ramburs').value=de_afisat[1];
					document.getElementById('judet_ramburs').value=de_afisat[2];
					document.getElementById('localitate_ramburs').value=de_afisat[3];
					document.getElementById('persoana_ramburs').value=de_afisat[4];
					document.getElementById('telefon_ramburs').value=de_afisat[5];
					
						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_ramburs.focus();
					}
			}
		}//end if codul
	}

//localitate taxe
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_taxe;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati2(3);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(7);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(7);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('judet_taxe').value=de_afisat[3];
						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_taxe.focus();
					}
			}
		}//end if codul
	}
	
//localitate destinatar
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.localitate_ramburs;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati2(4);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(8);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(8);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('judet_ramburs').value=de_afisat[3];
						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_ramburs.focus();
					}
			}
		}//end if codul
	}

//localitate beneficiar ramburs
form_in_cauza=document.getElementById('form1');
box_in_cauza=document.getElementById('localitate_ramb');
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
if(box_in_cauza){	
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati2(30);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(30);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(30);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('judet_ramb').value=de_afisat[3];
					document.getElementById('birou_ramb').value=de_afisat[1];
						document.getElementById('ul_localitati').style.display='none';
						document.form1.persoana_destinatar.focus();
					}
			}
		}//end if codul
	}
}//end if box_in_cauza



campuri_text=document.getElementsByTagName('input');

	for(x=0;x<campuri_text.length;x++){
		campuri_text[x].onblur=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
/*			selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='visible';
			}*/
		}
		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			if(IfrRef) IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}

	campuri_text=document.getElementsByTagName('textarea');
	for(x=0;x<campuri_text.length;x++){
		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}


}

function rgb (r, g, b) {
	var n = (r<<16) + (g<<8) + b;
	return '#' + (r<16? '0':'') + n.toString(16);
}

function insertAfter(parent, node, referenceNode) {
  parent.insertBefore(node, referenceNode.nextSibling);
}

function randuri_hover(tabel){
	tabelul=document.getElementById(tabel);
	randuri=tabelul.getElementsByTagName('tr');

var asocieri = Array();

	for(x=0;x<randuri.length-1;x++){
		if(id1=randuri[x].id.split("_")){
			for(y=0;y<randuri.length-1;y++){
				if(id2=randuri[y].id.split("_")){
//						alert(id1[0]+":"+id1[1]+" - "+id2[0]+":"+id2[1]);
					if(id1[0]==id2[1]) {
						insertAfter(document.getElementById(id1[0]+"_"+id1[1]).parentNode,document.getElementById(id2[0]+"_"+id2[1]),document.getElementById(id1[0]+"_"+id1[1]));
					}
				}
			}
					if (id1[1]=="0"){
						celule=randuri[x].getElementsByTagName('td');
						for(l=0;l<celule.length;l++){
							el=celule[l];
							el.style.borderTop="2px solid #999999";
						}						
					}

		}
	}
	
	c=1;
	for(x=2;x<randuri.length-1;x++){
			coloane=randuri[x].getElementsByTagName('td');
			aul=coloane[0].getElementsByTagName('a');
			if(aul[0]){
				aul[0].innerHTML=c;
			}else{
				coloane[0].innerHTML=c;
			}
			c++;
	}

	contor=0;
	for(x=0;x<randuri.length-1;x++){
		if(contor>1){
			element=randuri[x];

			celule=element.getElementsByTagName('td');
			for(l=0;l<celule.length-1;l++){
				el=celule[l];
				el.style.paddingRight="1px";
			}

			element.onmouseover=function(){
				culoare=this.style.backgroundColor;
				if (culoare.substring(0,3)=="rgb") culoare = eval(culoare);
				if(culoare=='#efefef'){
					this.style.backgroundColor="#e0e0e0";
				}else if(culoare=='#ffeeee'){
					this.style.backgroundColor="#ffdddd";
				}else{
					this.style.backgroundColor="#eeffee";					
				}
				this.style.cursor='default';
					celule=this.getElementsByTagName('td');
					for(l=0;l<celule.length-1;l++){
						el=celule[l];
						el.style.paddingRight="0px";
						el.style.borderRight="1px solid #BCBCBC";
						el.style.color="#000000";
					}
			}
			element.onmouseout=function(){
				culoare=this.style.backgroundColor;
				if (culoare.substring(0,3)=="rgb") culoare = eval(culoare);

				if(culoare=='#e0e0e0'){
					this.style.backgroundColor="#efefef";
				}else if(culoare=='#ffdddd'){
					this.style.backgroundColor="#ffeeee";
				}else{
					this.style.backgroundColor="transparent";
				}
				this.style.cursor='normal';				
					celule=this.getElementsByTagName('td');
					for(l=0;l<celule.length-1;l++){
						el=celule[l];
						el.style.paddingRight="1px";						
						el.style.borderRight='0px none #000000';
						el.style.color="#333333";						
					}

			}
		}
		contor++;
	}
}

function fill_curieri(id_birou){
	curierif=document.getElementById('curier');
	while (curierif.length> 0) {
		curierif.remove(0);
	}
	curierif.options[0]=new Option("Selecteaza un birou","0",true,true);	
	if(id_birou==0){
		xmlhttp.open("GET", "d1_x_list_ccurieri.php?birou="+id_birou,true);
		xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				container_box.style.display='none';
				lista_localitati=xmlhttp.responseText.split("!@#");
			}
		}
	}
}

function schimba_predat(objx,birou){
		obiect=document.getElementById('confirm_img'+objx);
		obiect.className="waiting";
			xmlhttp.open("GET", "d1_set_predat.php?stid="+objx+"&birou="+birou,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
/*					if(xmlhttp.responseText=="1"){
							obiect.className="enabled";
					}
					if(xmlhttp.responseText=="0"){
							obiect.className="disabled";
					}*/
//					alert(xmlhttp.responseText);
					statusl=xmlhttp.responseText.split("~~~");
					stat=statusl[0];
					if(statusl[1]){
						iduri=statusl[1].split(",./");
						for(x=0;x<iduri.length;x++){
							if(camp=document.getElementById('confirm_img'+iduri[x])){
								if(stat==0) camp.className="enabled";
								if(stat==1) camp.className="disabled";
							}
						}
					}
					if(xmlhttp.responseText=="-1"){
							obiect.className="eroare";
					}
	
				}else{
						obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)
}

function schimba_primit(objx,birou){
		obiect=document.getElementById('confirm_img'+objx);
		obiect.className="waiting";
			xmlhttp.open("GET", "d1_set_primit.php?stid="+objx+"&birou="+birou,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
/*					if(xmlhttp.responseText=="1"){
							obiect.className="enabled";
					}
					if(xmlhttp.responseText=="0"){
							obiect.className="disabled";
					}*/
//					alert(xmlhttp.responseText);
					statusl=xmlhttp.responseText.split("~~~");
					stat=statusl[0];
					if(statusl[1]){
						iduri=statusl[1].split(",./");
						for(x=0;x<iduri.length;x++){
							if(camp=document.getElementById('confirm_img'+iduri[x])){
								if(stat==0) camp.className="enabled";
								if(stat==1) camp.className="disabled";
							}
						}
					}
					if(xmlhttp.responseText=="-1"){
							obiect.className="eroare";
					}
	
				}else{
						obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)
}


function filluplocalitati(camp,birou){
		obiect=document.getElementById(camp);

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d1_x_list_localitati_birou.php?birouid="+birou,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
					
				obiect.options[0]=new Option("Alegeti o localitate","-1",true,true);							
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
					}
	
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)
}

function lista_st_uri_negrupata(){
	xmlhttp.open("GET", "d1_x_list_stp_negrupate.php?st_tip="+document.getElementById('tip_stp').value+"&stnr="+document.getElementById('stp').value+"&data="+document.getElementById('data1').value+"&birou1="+document.getElementById('birou1').value+"&birou2="+document.getElementById('birou2').value+"&grupajID="+document.getElementById('grupajID').value,true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				document.getElementById('container_stp_uri').innerHTML=xmlhttp.responseText;
			}else{

			}

	}
	 xmlhttp.send(null)
}

function move_stp_to_stg(stp,stg){
	xmlhttp.open("GET", "d1_x_asociaza_stp_stg.php?stpID="+stp+"&stgID="+stg,true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if(xmlhttp.responseText!="EROARE"){
					document.getElementById('stp_box_'+stp).style.display='none';
					document.getElementById('container_stp_stg').innerHTML=xmlhttp.responseText;
				}else{
					alert("A intervenit o eroare. Incercati dinnou.");
				}
			}else{

			}

	}
	 xmlhttp.send(null)
}

function remove_stg(stp,stg){
	xmlhttp.open("GET", "d1_x_asociaza_stp_stg.php?stpID="+stp+"&stgID="+stg+"&act=remove",true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				if(xmlhttp.responseText!="EROARE"){
					document.getElementById('container_stp_stg').innerHTML=xmlhttp.responseText;
					lista_st_uri_negrupata();
				}else{
					alert("A intervenit o eroare. Incercati dinnou.");
				}
			}else{

			}

	}
	 xmlhttp.send(null)
}

function randuri_hover2(tabel){
	tabelul=document.getElementById(tabel);
	randuri=tabelul.getElementsByTagName('tr');
	contor=0;
	for(x=0;x<randuri.length-1;x++){
		if(contor>=1){
			element=randuri[x];

			celule=element.getElementsByTagName('td');
			for(l=0;l<celule.length-1;l++){
				el=celule[l];
				el.style.paddingRight="1px";
			}

			element.onmouseover=function(){
				this.style.backgroundColor="#EEFFEE";
				this.style.cursor='default';
					celule=this.getElementsByTagName('td');
					for(l=0;l<celule.length-1;l++){
						el=celule[l];
						el.style.paddingRight="0px";
						el.style.borderRight="1px solid #BCBCBC";
						el.style.color="#000000";
					}
			}
			element.onmouseout=function(){
				this.style.backgroundColor="";
				this.style.cursor='normal';				
					celule=this.getElementsByTagName('td');
					for(l=0;l<celule.length-1;l++){
						el=celule[l];
						el.style.paddingRight="1px";						
						el.style.borderRight='0px none #000000';
						el.style.color="#333333";						
					}

			}
		}
		contor++;
	}
}

function sterge_expeditor(){
	tabel=document.getElementById('expeditor_table');
	texturi=tabel.getElementsByTagName('input');
	for(x=0; x<texturi.length;x++){
		texturi[x].value='';
	}
	texturix=document.getElementById('adresa_expeditor');
	texturix.value='';
		document.getElementById('add_expeditor').value='checkbox';
}

function sterge_ramb(){
	tabel=document.getElementById('ramb_table');
	texturi=tabel.getElementsByTagName('input');
	for(x=0; x<texturi.length;x++){
		texturi[x].value='';
	}
	texturix=document.getElementById('adresa_ramb');
	texturix.value='';
}

function sterge_destinatar(){
	tabel=document.getElementById('destinatar_table');
	texturi=tabel.getElementsByTagName('input');
	for(x=0; x<texturi.length;x++){
		texturi[x].value='';
	}
	texturix=document.getElementById('adresa_destinatar');
	texturix.value='';
	document.getElementById('add_destiantar').value='checkbox';
}


function extractNumber(obj, decimalPlaces, allowNegative)
{
	var temp = obj.value;
	
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
		
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	
	return isFirstN || isFirstD || reg.test(keychar);
}








function attach_clienti_events2(){

checkboxuri=document.getElementsByTagName('input');
for(x=0;x<checkboxuri.length;x++){
	if(checkboxuri[x].type=="checkbox"){
		checkboxuri[x].onclick=function(){
			denumire=this.id;
			if(denumire.substring(9,17)=="incasare"){
				id=denumire.substring(18,50);
				setstatus("incasare",id,this.checked);
			}
			if(denumire.substring(9,17)=="depunere"){
				id=denumire.substring(18,50);
				setstatus("depunere",id,this.checked);
			}
			if(denumire.substring(9,15)=="virare"){
				id=denumire.substring(16,50);
				setstatus("virare",id,this.checked);
			}
			if(denumire.substring(9,16)=="predare"){
				id=denumire.substring(17,50);
				setstatus("predare",id,this.checked);
			}
			
		}
	}
}

//	randuri_hover2('rambursuri');
	
	minim_caractere=2;
	if (document.all&&document.getElementById) {
		minim_caractere=2;
	}
	
//expeditor
form_in_cauza=document.getElementById('form1');
box_in_cauza=form_in_cauza.client;
/*	
box_in_cauza.onblur=function(e){
		document.getElementById('ul_localitati').style.display='none';
		document.form1.Cod_Postal.focus();
	}
	*/
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(100);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(100);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(100);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('clientID').value=de_afisat[8];
						document.getElementById('ul_localitati').style.display='none';
					}
			}
		}//end if codul
	}


campuri_text=document.getElementsByTagName('input');

	for(x=0;x<campuri_text.length;x++){
		campuri_text[x].onblur=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
/*			selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='visible';
			}*/
		}
		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}

	campuri_text=document.getElementsByTagName('textarea');
	for(x=0;x<campuri_text.length;x++){
		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}


}




function fill_terta_client_op(tip){
	
d=tip.length;

if (parseInt(d)>3){
	document.getElementById('client_terta').style.display='';
	document.getElementById('client_terta_text').style.display='';	
	


		obiect=document.getElementById('client_terta');

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d0_x_list_terta_clienti.php?tip="+tip,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
					
				obiect.options[0]=new Option("SELECTATI CLIENTUL","0",true,true);
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
												
					}
					
				
					
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)	
}
}



function fill_subcontractori_op(tip){
		obiect=document.getElementById('subcontractori');

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d16_x_list_subcontractori.php?tip="+tip,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
					
				obiect.options[0]=new Option("SELECTATI SUBCONTRACTORUL","0",true,true);
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
					}
					
				
					
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)	
}



function fill_unitati_op(tip){
		obiect=document.getElementById('unitate_op');

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d5_x_list_unitati_op.php?tip="+tip,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
					
				obiect.options[0]=new Option("Toate","0",true,true);
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
					}
					
					fill_unitati_curieri(obiect.value);
					
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)	
}



function fill_unitati_op2(tip){
                obiect=document.getElementById('birou_predare');

                                        while (obiect.length> 0) {
                                                obiect.remove(0);
                                        }

                obiect.options[0]=new Option("Asteptati...","-1",true,true);                                                 

                        xmlhttp.open("GET", "d8_x_list_unitati_op.php?tip="+tip,true);
                        xmlhttp.onreadystatechange=function() {
                                if (xmlhttp.readyState==4) {

                                        while (obiect.length> 0) {
                                                obiect.remove(0);
                                        }


                                obiect.options[0]=new Option("Toate","0",true,true);
                                inregistrari=xmlhttp.responseText.split("!@#");
//                              alert(inregistrari.length);
                                        for(x=0;x<inregistrari.length-1;x++){
                                                valori=inregistrari[x].split("^&*");
                                                obiect.options[x+1]=new Option(valori[0],valori[1],false,false);             
                                        }

                                        fill_unitati_curieri(obiect.value);

                                }else{
                                                //obiect.className="waiting";
                                }

                        }
                 xmlhttp.send(null)
}


function fill_unitati_curieri(unitate){
		obiect=document.getElementById('curier');

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d5_x_list_unitati_curieri.php?unitate="+unitate+"&tip_unitate="+document.getElementById('tip_unitate').value,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
				lista="";
				obiect.options[0]=new Option("Toti","0",true,true);
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						lista+=valori[0]+", ";
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
					}
//					alert(lista);
	
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)	
}


function fill_unitati_curieri2(unitate){
		obiect=document.getElementById('curier');

					while (obiect.length> 0) {
						obiect.remove(0);
					}

		obiect.options[0]=new Option("Asteptati...","-1",true,true);							

			xmlhttp.open("GET", "d5_x_list_unitati_curieri.php?unitate="+unitate+"&tip_unitate="+document.getElementById('tip_unitate').value+"&restrict=retea",true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
					
					while (obiect.length> 0) {
						obiect.remove(0);
					}
					
				lista="";
				obiect.options[0]=new Option("Toti","0",true,true);
				inregistrari=xmlhttp.responseText.split("!@#");
//				alert(inregistrari.length);
					for(x=0;x<inregistrari.length-1;x++){
						valori=inregistrari[x].split("^&*");
						lista+=valori[0]+", ";
						obiect.options[x+1]=new Option(valori[0],valori[1],false,false);							
					}
//					alert(lista);
	
				}else{
						//obiect.className="waiting";					
				}
	
			}
		 xmlhttp.send(null)	
}



function show_thing(camp, mesaj) {
	parentFrame=window.parent;
	camp_afectat=camp;
//	alert(findPosX(camp_afectat)+" = "+findPosY(camp_afectat));
	if(document.getElementById(camp+"error")){
		oDiv = document.getElementById(camp+"error")
		oImg = document.getElementById(camp+"error_arrow")
	}else{
		oDiv = document.createElement("div");
		oImg = document.createElement("img");
		oDiv.id=camp+"error";
		oImg.id=camp+"error_arrow";
	}
	document.body.appendChild(oDiv);
	document.body.appendChild(oImg);
	oDiv.style.backgroundColor="#DEDEEF";
	oDiv.style.border="1px solid #0000EF";
	oDiv.style.borderRightWidth="3px";
	oDiv.style.borderBottomWidth="3px";
	oDiv.style.width="200px";
	oDiv.style.position="absolute";
	oDiv.style.top=findPosY(camp_afectat)+"px";
	oDiv.style.left=findPosX(camp_afectat)+13+"px";
	oDiv.style.display="block";
	oDiv.style.padding="2px";
	oDiv.style.cursor="pointer";
	oImg.src="images/small_left_arrow2.gif";
	oImg.style.position="absolute";
	oImg.style.top=findPosY(camp_afectat)+3+"px";
	oImg.style.left=findPosX(camp_afectat)+10+"px";
	oImg.style.display='block';
	oDiv.onclick=function(){
		this.style.display='none';
		oImg.style.display='none';
	}
	oDiv.innerHTML=mesaj;
	
}


function display_client_info(id,obj,pers){
//	alert("detalii_client.php?clientID="+id);
	inregistrari="";
					if(pers){
						inregistrari+="<strong>"+pers+"</strong><br />";
					}					

			xmlhttp.open("GET", "detalii_client.php?clientID="+id,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
				inregistrari+=xmlhttp.responseText;
				show_thing(obj,inregistrari);
				}else{
				inregistrare="ASTEPTATI... ";
				show_thing(obj,inregistrare);
				}
			}
		 xmlhttp.send(null)	
}


function setstatus(camp,id,valoare){
	if(valoare){
		desetat=1;
	}else{
		desetat=0;
	}
//alert(camp+" -> "+desetat);

			xmlhttp.open("GET", "d5_x_set_status.php?camp="+camp+"&id="+id+"&valoare="+desetat,true);
			xmlhttp.onreadystatechange=function() {
				if (xmlhttp.readyState==4) {
//						document.getElementById('span_'+camp+'_'+id).innerHTML=xmlhttp.responseText;
						rezultat=xmlhttp.responseText.split("!@#");
						document.getElementById('span_'+camp+'_'+id).innerHTML=rezultat[2];
						if(rezultat[1]==1){
							document.getElementById('checkbox_'+camp+'_'+rezultat[0]).checked=true;
						}else{
//							alert(xmlhttp.responseText);
							document.getElementById('checkbox_'+camp+'_'+rezultat[0]).checked=false;
						}
				}else{
						document.getElementById('span_'+camp+'_'+id).innerHTML='Asteptati ...';
				}
	
			}
		 xmlhttp.send(null)	
}





function attach_clienti_events_rapoarte(){

minim_caractere=2;
if (document.all&&document.getElementById) {
	minim_caractere=2;
}
form_in_cauza=document.getElementById('form1');

//client expeditor
box_in_cauza=getElementById('clientExpeditor');
	box_in_cauza.onkeydown=function(e){
		if(document.all){
			codul_tastat=event.keyCode;
		}else{
			codul_tastat=e.keyCode;
		}
		if(codul_tastat!=13 && codul_tastat!=38 && codul_tastat!=40 && codul_tastat!=35 && codul_tastat!=36 && codul_tastat!=37 && codul_tastat!=39){
			if((this.value.length)>=minim_caractere){
				populeaza_localitati(110);
			}else{
				if(container_box=document.getElementById('ul_localitati')){
					container_box.style.display='none';
				}
				if(container_box=document.getElementById('container_ajax')){
					container_box.style.display='none';
				}
			}//end if length
		}else{
			if(codul_tastat==40 || codul_tastat==39){
				if(index_localitate<lista_localitati.length-2) index_localitate=index_localitate+1;
//				alert(codul_tastat);
				reordoneaza_lista_localitati(110);
			}
			if(codul_tastat==38 || codul_tastat==37){
				//alert(codul_tastat);
				if(index_localitate>0) index_localitate=index_localitate-1;
				reordoneaza_lista_localitati(110);
			}
			if(codul_tastat==13){
				if(lista_localitati.length>=1){
					de_afisat=lista_localitati[index_localitate].split("^&*");
					this.value=de_afisat[0];
					document.getElementById('clientID').value=de_afisat[8];
						document.getElementById('ul_localitati').style.display='none';
					}
			}
		}//end if codul
	}


campuri_text=document.getElementsByTagName('input');

	for(x=0;x<campuri_text.length;x++){
/*		campuri_text[x].onblur=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			selecturi=document.getElementsByTagName('select');
			for(x=0;x<selecturi.length;x++){
				selecturi[x].style.visibility='visible';
			}		}*/

		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}

	campuri_text=document.getElementsByTagName('textarea');
	for(x=0;x<campuri_text.length;x++){
		campuri_text[x].onfocus=function(){
			var IfrRef = document.getElementById('DivShim');
			IfrRef.style.display="none";
			if(document.getElementById('ul_localitati'))document.getElementById('ul_localitati').style.display='none';
		}
		
	}


}


function attach_clienti_events3(){

}

function sync_cb(camp,valoare){
	document.getElementById(camp).value=valoare;
}

function select_all_checkboxes(){
count=0;
casute=document.getElementsByTagName('input');
for(x=0;x<casute.length;x++){
	if(casute[x].type=='checkbox'){
		if(casute[x].disabled==false){
			if(casute[x].checked==false){
				casute[x].checked=true;
				count++;
				if(casute[x].id.indexOf('check_')==0){
					detalii=casute[x].id.split("_");
					document.getElementById('statusst_'+detalii[1]).value=casute[x].checked*1;
				}
			}
		}
	}
}
alert(count+" inregistrari au fost marcate.");
}

function select_none_checkboxes(){
count=0;
casute=document.getElementsByTagName('input');
for(x=0;x<casute.length;x++){
	if(casute[x].type=='checkbox'){
		if(casute[x].disabled==false){
			if(casute[x].checked==true){
				casute[x].checked=false;
				count++;
				if(casute[x].id.indexOf('check_')==0){
					detalii=casute[x].id.split("_");
					document.getElementById('statusst_'+detalii[1]).value=casute[x].checked*1;
				}
			}
		}
	}
}
alert(count+" inregistrari au fost marcate.");
}

