// JavaScript Document - functii ce sunt necesare in tot site-ul


function empty_field(textfield){
	textfield.value="";
}

function LimitWordsSearch(word,lng,lngmax)
		{
			var lng_curr=lng+word.length;
			if (lng_curr<=lngmax) {return lng_curr;}
			else {return -1;}
		}
		

function LimitWords(cuvinte,lngmax)
		{
			var word=cuvinte.split(' ');
			var rez='';
			i=0;
			while (i < word.length)
			{
				if (word[i].length<(lngmax-rez.length) && (rez.length<lngmax))
					rez=rez+' '+word[i];
				i+=1;
			}
			rez=rez+" ... ";
			return rez;
		}		

function MakeWordsLength(word,lng)
		{
			var lng_curr=word.length;
			var new_word=word;
			while (lng_curr<lng)
				{
					new_word=new_word+"&nbsp;";
					lng_curr=lng_curr+1;
				}
			return new_word;
		}		
	
function redirectToMessages(id_comp,sHow)
{
	document.location = "http://www.profitromania.ro/index.php?unde=mesagerie&id_comp=" + id_comp + '&how=' + sHow;
}

///necesara pentru determinarea pozitiei elementele cu pozitie relativa in pagina
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 show_hide_cautare_stiri(){
	pos_x=findPosX(document.getElementById('hang_in_cautare_stiri'));
	pos_y=findPosY(document.getElementById('hang_in_cautare_stiri'));
	div_cautare=document.getElementById('cautare_stiri');
	div_recomanda=document.getElementById('recomanda_div');
	if(div_cautare){
		div_cautare.style.top=pos_y+20+"px";
		div_cautare.style.left=pos_x-70+"px";
		if(div_cautare.style.display=='none'){
			if(div_recomanda){
			div_recomanda.style.display="none";
			}
			div_cautare.style.display="";
			document.cauta_stiri['search_stiri'].focus();
		}
		else{
			div_cautare.style.display="none";
		}
	}
	return false;
}

function show_hide_advanced_search_stiri(){
	div_cautare_avansata=document.getElementById("cautare_avansata_stiri");
	if(div_cautare_avansata.style.display=='none'){
		div_cautare_avansata.style.display="";
	}
	else{
		div_cautare_avansata.style.display="none";
	}
	return false;
}

function show_hide_recomanda_stiri(){
	pos_x=findPosX(document.getElementById('comenzi_stiri'));
	pos_y=findPosY(document.getElementById('comenzi_stiri'));
	div_recomanda=document.getElementById('recomanda_div');
	//div_cautare=document.getElementById('cautare_stiri');
	if(div_recomanda){
		div_recomanda.style.top=pos_y+20+"px";
		div_recomanda.style.left=(pos_x-90)+"px";
		if(div_recomanda.style.display=='none'){
			//div_cautare.style.display="none";
			deja=true;
			div_recomanda.style.display="";
			document.recomanda_stirea['email_address'].focus();
		}
		else{
			div_recomanda.style.display="none";
		}
	}
	return false;
}
///////// Afaceri ////////////////////////////////
function show_hide_cautare_afaceri(){
	pos_x=findPosX(document.getElementById('hang_in_cautare_afaceri'));
	pos_y=findPosY(document.getElementById('hang_in_cautare_afaceri'));
	div_cautare=document.getElementById('cautare_afaceri');
	div_recomanda=document.getElementById('recomanda_div');
	if(div_cautare){
		div_cautare.style.top=pos_y+20+"px";
		div_cautare.style.left=pos_x-70+"px";
		if(div_cautare.style.display=='none'){
			if(div_recomanda){
			div_recomanda.style.display="none";
			}
			div_cautare.style.display="";
			document.cauta_afaceri['search_afaceri'].focus();
		}
		else{
			div_cautare.style.display="none";
		}
	}
	return false;
}

function show_select(){
	
	if (document.getElementById("tip_companie_select")){
		document.getElementById("tip_companie_select").style.visibility="visible";
	}
	if(document.getElementById("judet_select")){
		document.getElementById("judet_select").style.visibility="visible";
	}
	if(document.getElementById('perioada')){
		document.getElementById('perioada').style.visibility="visible";
	}
	if(document.getElementById('incorporation_form')){
		document.getElementById('incorporation_form').style.visibility="visible";
	}
	if(document.getElementById('nr_angajati')){
		document.getElementById('nr_angajati').style.visibility="visible";
	}
	if(document.getElementById('activitate_primara')){
		document.getElementById('activitate_primara').style.visibility="visible";
	}
}

function hide_div(obj){
	if(document.getElementById(obj)){
		divulet=document.getElementById(obj);
		//divulet.style.display="none";	
		divulet.style.visibility="hidden";	
		//hideSelects('visible');
		if (obj=='localitate_companii')
		{
			show_select();			
		}
	}
	return false;
}

function show_hide_advanced_search_afaceri(){
	div_cautare_avansata=document.getElementById("cautare_avansata_afaceri");
	if(div_cautare_avansata.style.display=='none'){
		div_cautare_avansata.style.display="";
	}
	else{
		div_cautare_avansata.style.display="none";
		hide_div("domenii_companii");
		hide_div("codcaen_companii");
		hide_div("localitate_companii");
	}
	return false;
}

function show_hide_recomanda_afaceri(){
	pos_x=findPosX(document.getElementById('comenzi_afaceri'));
	pos_y=findPosY(document.getElementById('comenzi_afaceri'));
	div_recomanda=document.getElementById('recomanda_div');
	//div_cautare=document.getElementById('cautare_afaceri');
	if(div_recomanda){
		div_recomanda.style.top=pos_y+20+"px";
		div_recomanda.style.left=(pos_x-90)+"px";
		if(div_recomanda.style.display=='none'){
			deja=true;
			//div_cautare.style.display="none";
			div_recomanda.style.display="";
			document.recomanda_afacerea['email_address'].focus();
		}
		else{
			div_recomanda.style.display="none";
		}
	}
	return false;
}
///////// Gata Afaceri ////////////////////////////////


///////// cereri ////////////////////////////////
function show_hide_cautare_cereri(){
	pos_x=findPosX(document.getElementById('hang_in_cautare_cereri'));
	pos_y=findPosY(document.getElementById('hang_in_cautare_cereri'));
	div_cautare=document.getElementById('cautare_cereri');
	div_recomanda=document.getElementById('recomanda_div');
	if(div_cautare){
		div_cautare.style.top=pos_y+20+"px";
		div_cautare.style.left=pos_x-70+"px";
		if(div_cautare.style.display=='none'){
			if(div_recomanda){
			div_recomanda.style.display="none";
			}
			div_cautare.style.display="";
			document.cauta_cereri['search_cereri'].focus();
		}
		else{
			div_cautare.style.display="none";
		}
	}
	return false;
}

function show_hide_advanced_search_cereri(){
	div_cautare_avansata=document.getElementById("cautare_avansata_cereri");
	if(div_cautare_avansata.style.display=='none'){
		div_cautare_avansata.style.display="";
	}
	else{
		div_cautare_avansata.style.display="none";
		hide_div("domenii_companii");
		hide_div("codcaen_companii");
		hide_div("localitate_companii");
	}
	return false;
}

function show_hide_recomanda_cereri(){
	pos_x=findPosX(document.getElementById('comenzi_cereri'));
	pos_y=findPosY(document.getElementById('comenzi_cereri'));
	div_recomanda=document.getElementById('recomanda_div');
	//div_cautare=document.getElementById('cautare_cereri');
	if(div_recomanda){
		div_recomanda.style.top=pos_y+20+"px";
		div_recomanda.style.left=(pos_x-90)+"px";
		if(div_recomanda.style.display=='none'){
			//div_cautare.style.display="none";
			deja=true;
			div_recomanda.style.display="";
			document.recomanda_cererea['email_address'].focus();
		}
		else{
			div_recomanda.style.display="none";
		}
	}
	return false;
}
///////// Gata cereri ////////////////////////////////


function show_hide_recomanda_compani(){
	pos_x=findPosX(document.getElementById('comenzi_companii'));
	pos_y=findPosY(document.getElementById('comenzi_companii'));
	if(document.getElementById('recomanda_div')){
		div_recomanda=document.getElementById('recomanda_div');
	}
	//if(document.getElementById('cautare_companii')){
	//	div_cautare=document.getElementById('cautare_companii');
	//}
	if(div_recomanda){
		div_recomanda.style.top=pos_y+20+"px";
		div_recomanda.style.left=(pos_x-90)+"px";
		if(div_recomanda.style.display=='none'){
			deja=true;
			div_recomanda.style.display="";
			document.recomanda_stirea['email_address'].focus();
		}
		else{
			div_recomanda.style.display="none";
		}
	}
	return false;
}


function show_hide_cautare_companii(){
	pos_x=findPosX(document.getElementById('hang_in_cautare_companii'));
	pos_y=findPosY(document.getElementById('hang_in_cautare_companii'));
	div_cautare=document.getElementById('cautare_companii');
	if(document.getElementById('recomanda_div')){
		div_recomanda=document.getElementById('recomanda_div');
	}
	if(div_cautare){
		div_cautare.style.top=pos_y+20+"px";
		div_cautare.style.left=pos_x-70+"px";
		if(div_cautare.style.display=='none'){
			div_cautare.style.display="";
			if(document.getElementById('recomanda_div')){
				div_recomanda.style.display="none";
			}
			if(document.advanced_search['nume_produs']){
				document.advanced_search['nume_produs'].focus();
			}
			if(document.advanced_search['nume_firma']){
				document.advanced_search['nume_firma'].focus();
			}
		}
		else{
			div_cautare.style.display="none";
			hide_div("domenii_companii");
			hide_div("codcaen_companii");
			hide_div("localitate_companii");
			show_select();
		}
	}
	return false;
}

function show_hide_cautare_companiicaen(){
	pos_x=findPosX(document.getElementById('hang_in_cautare_companii'));
	pos_y=findPosY(document.getElementById('hang_in_cautare_companii'));
	div_cautare=document.getElementById('cautare_companii');
	if(div_cautare){
		div_cautare.style.top=pos_y+20+"px";
		div_cautare.style.left=pos_x-70+"px";
		if(div_cautare.style.display=='none'){
			div_cautare.style.display="";
			if(document.advanced_search['nume_produs']){
				document.advanced_search['nume_produs'].focus();
			}
			if(document.advanced_search['nume_firma']){
				document.advanced_search['nume_firma'].focus();
			}
		}
		else{
			div_cautare.style.display="none";
			hide_div("domenii_companii");
			hide_div("codcaen_companii");
			hide_div("localitate_companii");
			show_select();
		}
	}
	return false;
}

function show_hide_advanced_search_produsesiservicii(){
	div_cautare_avansata=document.getElementById("cautare_avansata_produsesiservicii");
	if(div_cautare_avansata.style.display=='none'){
		div_cautare_avansata.style.display="";
	}
	else{
		div_cautare_avansata.style.display="none";
		
		hide_div("domenii_companii");
		hide_div("localitate_companii");
	}
	return false;
}


function show_hide_advanced_search_companii(){
	div_cautare_avansata=document.getElementById("cautare_avansata_companii");
	if(div_cautare_avansata.style.display=='none'){
		div_cautare_avansata.style.display="";
	}
	else{
		div_cautare_avansata.style.display="none";

		hide_div("domenii_companii");
		hide_div("codcaen_companii");
		hide_div("localitate_companii");

		show_select();
	}
	return false;
}

function show_domenii(obj,str){

	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("domenii_companii");
	divulet.style.visibility="visible";
	//divulet.style.top=pos_y+20;
	//divulet.style.left=pos_x;
	
	hide_div("codcaen_companii");
	hide_div("localitate_companii");

	document.getElementById("get_domenii_companii").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_domenii");
	iframe_proc.setAttribute("src","/?unde=procdomenii&didi="+str,0);
	show_select();
}

function hide_select(){
	if(document.getElementById("tip_companie_select")){
		document.getElementById("tip_companie_select").style.visibility="hidden";
	}
	if(document.getElementById("judet_select")){
		document.getElementById("judet_select").style.visibility="hidden";
	}
}

function show_domenii_oferte(obj,str){

	hide_select();
	//document.getElementById('perioada').style.visibility="hidden";
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("domenii_companiiOf");
	divulet.style.visibility="visible";

	document.getElementById("get_domenii_companiiOf").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_domeniiOf");
	iframe_proc.setAttribute("src","/?unde=procdomeniiof&didi="+str,0);
}
function show_domenii_produse(obj,str){

	hide_select();
	//document.getElementById('perioada').style.visibility="hidden";
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("domenii_companiiProduse");
	divulet.style.visibility="visible";
	
	document.getElementById("get_domenii_companiiProduse").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_domeniiProduse");
	iframe_proc.setAttribute("src","/?unde=procdomeniiproduse&didi="+str,0);
}

function show_nume_companii(obj,str){

	hide_select();
	var pos_x=findPosX(obj);
	var pos_y=findPosY(obj);
	var divulet=document.getElementById("nume_companii");
		divulet.style.visibility="visible";
		//divulet.style.top=pos_y+20;
		//divulet.style.left=pos_x;	

	document.getElementById("get_nume_companii").innerHTML="Loading...";

	var iframe_proc=document.getElementById("proceseaza_nume_companii");
		iframe_proc.setAttribute("src","/?unde=procnumecompanii&didi="+str,0);
}

function show_localitate(obj,str,tabela){
	
	hide_select();
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("localitate_companii");
	divulet.style.visibility="visible";
	//divulet.style.top=pos_y+20;
	//divulet.style.left=pos_x;

	hide_div("domenii_companii");
	hide_div("codcaen_companii");

	document.getElementById("get_localitate_companii").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_localitate");
	iframe_proc.setAttribute("src","/?unde=proclocalitate&tabela="+tabela+"&didi="+str,0);
}
function show_localitate_oferte(obj,str,tabela){
	
	hide_select();
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("localitate_companiiOf");
	divulet.style.visibility="visible";
	//divulet.style.top=pos_y-340;
	//divulet.style.left=pos_x;

	hide_div("domenii_companiiOf");

	document.getElementById("get_localitate_companiiOf").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_localitateOf");
	iframe_proc.setAttribute("src","/?unde=proclocalitateof&tabela="+tabela+"&didi="+str,0);
}

function show_localitate_produse(obj,str,tabela){
	
	hide_select();
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("localitate_companiiProduse");
	divulet.style.visibility="visible";

	hide_div("domenii_companiiProduse");

	document.getElementById("get_localitate_companiiProduse").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_localitateProduse");
	iframe_proc.setAttribute("src","/?unde=proclocalitateproduse&tabela="+tabela+"&didi="+str,0);
}

function show_codcaen(obj,str){
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("codcaen_companii");
	divulet.style.visibility="visible";
	//divulet.style.top=pos_y+20;
	//divulet.style.left=pos_x;
	
	hide_div("domenii_companii");
	hide_div("localitate_companii");

	document.getElementById("get_codcaen_companii").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_codcaen");
	iframe_proc.setAttribute("src","/?unde=codcaen&didi="+str,0);
	show_select();
}


function show_codcaen_ddany(obj,str){
	pos_x=findPosX(obj);
	pos_y=findPosY(obj);
	divulet=document.getElementById("codcaen_companii");
	divulet.style.visibility="visible";
	divulet.style.top=pos_y+20;
	divulet.style.left=pos_x;
	
	hide_div("activitate_primara");
	hide_div("nr_angajati");
	hide_div("incorporation_form");

	document.getElementById("get_codcaen_companii").innerHTML="Loading...";

	iframe_proc=document.getElementById("proceseaza_codcaen");
	iframe_proc.setAttribute("src","/?unde=codcaen&didi="+str,0);
	//alert("/?unde=codcaen&didi="+str);
	//show_select();
}


function change_color(id)
{
		tr=document.getElementById(id);
		
		if(tr.getAttribute("bgcolor")=="#eeeeee"){
			tr.setAttribute("bgcolor","#ffffff",0);
			tr.style.bgcolor="#ffffff";
		}
		else{
			tr.setAttribute("bgcolor","#eeeeee",0);
			tr.style.bgcolor="#eeeeee";
		}
		tr.style.cursor="hand";
		tr.style.cursor="pointer";
}

function change_input(obj,input_name,nume,id){
	formulet=document['advanced_search'];
	divulet=document.getElementById(obj);
	//divulet.style.display="none";
	divulet.style.visibility="hidden";
	eval("formulet."+input_name+".value=unescape(nume);");
	if ((input_name=='localitate' && obj=='localitate_companii') || input_name=='domenii' || input_name=='cod_caen')
	{
		show_select();
	}
	if (input_name=='domenii')
	{
		formulet.domeniu_id.value=id;
	}
}

function change_inputOf(obj,input_name,nume,id){
	formulet=document['advanced_search'];
	divulet=document.getElementById(obj);
	//divulet.style.display="none";
	divulet.style.visibility="hidden";
	eval("formulet."+input_name+".value=unescape(nume);");
	if ((input_name=='localitateOf' && obj=='localitate_companiiOf') || input_name=='domeniiOf' || input_name=='cod_caenOf')
	{
		show_select();
	}
	if (input_name=='domeniiOf')
	{
		formulet.domeniuOf_id.value=id;
	}
}


function hide_div_ddany(obj){
	if(document.getElementById(obj)){
		divulet=document.getElementById(obj);
		divulet.style.visibility="hidden";	
		//hideSelects('visible');
		if (obj=='codcaen_companii')
		{
			show_select();			
		}
	}
	return false;
}


////pentru partea de thumbnails_produse
function thumb_divOver(obj){
	var divuri_from_obj=obj.getElementsByTagName("div");
	for(var i=0;i<divuri_from_obj.length;i++){
		if(divuri_from_obj[i].getAttribute("attr")=='divover'){
			var divulet_over=divuri_from_obj[i];
			break;
		}
	}
	
	caseta=divulet_over.parentNode;
	var divWidth1 = caseta.offsetWidth? caseta.offsetWidth : caseta.style.width? parseInt( caseta.style.width,10 ) : 0; 
	var divHeight1 = caseta.offsetHeight? caseta.offsetHeight : caseta.style.height? parseInt( caseta.style.height,10 ) : 0; 

	divulet_over.style.width=parseInt(divWidth1,10)-8+"px";
	divulet_over.style.height=parseInt(divHeight1,10)-15+"px";

	var divWidth =  parseInt(divulet_over.style.width,10);
	var divHeight = parseInt(divulet_over.style.height,10); 

	//alert(divHeight1+":"+divHeight);

	divulet_over.style.display='block';
	if(document.all){
		divulet_over.style.top=parseInt((divWidth1-divWidth)/2,10)+4+"px";
		divulet_over.style.left=parseInt((divHeight1-divHeight)/2,10)-7+"px";
	}
	else{
		divulet_over.style.top=parseInt((divWidth1-divWidth)/2,10)+"px";
		divulet_over.style.left=parseInt((divHeight1-divHeight)/2,10)-7+"px";
	}
}

function thumb_divOut(obj){
	
	var divuri_from_obj=obj.getElementsByTagName("div");
	for(var i=0;i<divuri_from_obj.length;i++){
		if(divuri_from_obj[i].getAttribute("attr")=='divover'){
			var divulet_over=divuri_from_obj[i];
			break;
		}
	}
	divulet_over.style.display='none';
}

function arata_div(nume){
	if(document.getElementById(nume).style.display=='none'){
		document.getElementById(nume).style.display='';
	}
	if(document.getElementById(nume).style.visibility=='hidden'){
		document.getElementById(nume).style.visibility='visible';
	}
}

function ascunde_div(nume){
	if(document.getElementById(nume).style.display==''){
		document.getElementById(nume).style.display='none';
	}
	if(document.getElementById(nume).style.visibility=='visible'){
		document.getElementById(nume).style.visibility='hidden';
	}
}

function numai_numere(nume,strict){
	 var checkOK = "0123456789-,/\ .";
	 if (strict){
		 checkOK = "0123456789";
	 }
	  var checkStr = nume.value;	 
	  var allValid = true;
	  var decPoints = 0;
	  var allNum = "";
	  for (i = 0;  i < checkStr.length;  i++)
	  {
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
		{
			if (ch == checkOK.charAt(j))
				{break;}
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
		}
		if (ch == ",")
		{
		  allNum += ".";
		  decPoints++;
		}
		else
		  {allNum += ch;}
	  }
	  return allValid;
}

function hideSelects(action) {
	
	//documentation for this script at http://www.shawnolson.net/a/1198/
	//possible values for action are 'hidden' and 'visible'
	if (action!='visible'){
			action='hidden';
	}
	if (navigator.appName.indexOf("MSIE")) {
		selects=document.getElementsByTagName("select");
		for(var i=0;i<selects.length;i++){
			selects[i].style.visibility = action;
		}
	}
	
}

function trim(content) {
  return content.replace(/^\s+|\s+$/g, '');
}


function show_hide_mesaje(){
	pos_x=findPosX(document.getElementById('mesajele'));
	pos_y=findPosY(document.getElementById('mesajele'));
	if(document.getElementById('mesaje_div')){
		div_recomanda=document.getElementById('mesaje_div');
	}
	if(document.getElementById('cautare_companii')){
		div_cautare=document.getElementById('cautare_companii');
	}
	if(div_recomanda){
		div_recomanda.style.top=pos_y-208+"px";
		div_recomanda.style.left=(pos_x)+"px";
		if(div_recomanda.style.display=='none'){
			if(document.getElementById('cautare_companii')){
				div_cautare.style.display="none";
			}
			div_recomanda.style.display="";
			if (document.getElementById('subiect')){
				document.form_mesaj['subiect'].focus();
			}
		}
		else{
			div_recomanda.style.display="none";
		}
	}
	return false;
}
