// JavaScript Document

function del_confirm(lnk)
{
	if (confirm("Esti sigur ca vrei sa stergi?"))
		document.location=lnk;
}

function js_confirm(lnk, text)
{
	if (confirm(""+text))
		document.location=lnk;
}

function getkey(e)
{
	if (window.event)
	   return window.event.keyCode;
	else if (e)
	   return e.which;
	else
	   return null;
}


function goodchars(e, goods)
{
	var key, keychar;
	key = getkey(e);
	if (key == null)
		return true;
	
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	goods = goods.toLowerCase();
	
	if (goods.indexOf(keychar) != -1)
		return true;
	
	if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
	   return true;
	
	return false;
}

function repair_flash()
{
	theObjects=document.getElementsByTagName("object");
	for (var i=0; i<theObjects.length; i++)
	{
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

function toggle(control)
{
	obj=document.getElementById(control);
	if (obj.style.display=="none")
		obj.style.display="block";
	else
		obj.style.display="none";
}

function genereaza_campuri()
{
	theNr=document.getElementById('nr_optiuni');
	theDiv=document.getElementById('fieldset');
	
	numar=parseInt(theNr.value);
	codHTML="";
	for (var i=1; i<=numar; i++)
	{
		codHTML+="<b>Raspuns "+i+"</b> <input type='text' name='raspuns[]' />";
		if (i!=numar) codHTML+="<br />";
	}
	theDiv.innerHTML=codHTML;
}

marimeFontDefault = 12;
marimeFontMinim = 9;
marimeFontMaxim = 15;

function maresteFont()
{
	theDiv=document.getElementById('enunt_articol');
	marimeFontDefault = marimeFontDefault+1;
	if (marimeFontDefault > marimeFontMaxim) {marimeFontDefault = marimeFontMaxim;}
	theDiv.style.fontSize=marimeFontDefault+"px";
}

function micsoreazaFont()
{
	theDiv=document.getElementById('enunt_articol');
	marimeFontDefault = marimeFontDefault-1;
	if (marimeFontDefault < marimeFontMinim) {marimeFontDefault = marimeFontMinim;}
	theDiv.style.fontSize=marimeFontDefault+"px";
}

function popup(adresa, latime, inaltime, is_scroll)
{
	if (is_scroll=="scroll")
		completare=", SCROLLBARS=YES"
	else
		completare="";
	var newWin=window.open(adresa+"", "_blank", "WIDTH="+latime+", HEIGHT="+inaltime+completare);
	
	var X=(screen.width-latime)/2;
	var Y=(screen.height-inaltime)/2;
	newWin.moveTo(X,Y)
}

function arata_an_calendar(div)
{
	var divuri=document.getElementsByTagName('div');
	var str="";
	for(i=0; i<divuri.length; i++)
	{
		if(divuri[i].id.substr(0, 4)=="anul")
			divuri[i].style.display='none';
	}
	document.getElementById(div).style.display='block';
}

function isMouseOver(theDivX)
{
	var theDiv=document.getElementById(theDivX);
	var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
	var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1);
	
	if (!e) var e = window.event;
	
	var mouseXPos = 0;
	var mouseYPos = 0;
	
	if (e.pageX || e.pageY)
	{
		mouseXPos = e.pageX;
		mouseYPos = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		mouseXPos = e.clientX;
		mouseYPos = e.clientY;
		if (isIE)
		{
			mouseXPos += document.documentElement.scrollLeft;
			mouseYPos += document.documentElement.scrollTop;
		}
	}
	
	var theDivLeftPos=parseFloat(theDiv.offsetLeft);
	var theDivRightPos=theDivLeftPos+parseFloat(theDiv.style.width);
	var theDivTopPos=parseFloat(theDiv.offsetTop);
	var theDivBottomPos=theDivTopPos+parseFloat(theDiv.style.height);
	alert(mouseXPos+"/"+mouseYPos+" intre ("+theDivLeftPos+":"+theDivRightPos+") si ("+theDivTopPos+":"+theDivBottomPos+")?");
	if (theDivLeftPos<mouseXPos && mouseXPos<theDivRightPos && theDivTopPos<mouseYPos && mouseYPos<theDivBottomPos)
	{
		//alert("da");
		return true;
	}
	else
	{
		//alert("nu");
		return false;
	}
}

function hideRMenu()
{
	theDivID='nimic';
	theDiv1=document.getElementById(theDivID);
	if(theDiv1)
	{
		if(theDiv1.style.display=="block")
		{
			if(!isMouseOver(theDivID))
			{
				//alert("Mouse over");
				//alert("Mouse: "+event.clientX+"/"+event.clientY+"\n"+"coords: "+theDiv1.offsetLeft+"-"+(theDiv1.offsetLeft+parseFloat(theDiv1.style.width))+"-"+theDiv1.offsetTop+"-"+(theDiv1.offsetTop+parseFloat(theDiv1.style.height)));
				theDiv1.style.display="none";
			}
			else
			{
				//alert("Mouse off");
				//alert("Mouse: "+event.clientX+"/"+event.clientY+"\n"+"coords: "+theDiv1.offsetLeft+"-"+(theDiv1.offsetLeft+parseFloat(theDiv1.style.width))+"-"+theDiv1.offsetTop+"-"+(theDiv1.offsetTop+parseFloat(theDiv1.style.height)));
			}
		}
		return true;
	}
	return false;
}

var gAutoPrint = true;
function printFriendly() 
{ 
	if (document.getElementById!= null) 
	{ 
		var html = '<html>\n<head>\n'; 
		if (document.getElementsByTagName!= null) 
		{ 
			var headTags = document.getElementsByTagName("head"); 
			if (headTags.length > 0) 
				html += headTags[0].innerHTML; 
		} 
		html += '\n</he' + 'ad>\n<body style="margin:5px; font-size:12px;">\n'; 
		var printPageElem = document.getElementById("continutPrintabil"); 
		
		if (printPageElem!= null) 
		{ 
			html += printPageElem.innerHTML; 
		} 
		else 
		{ 
			alert("Nu am gasit sectiunea printabila."); 
			return; 
		} 

		html += '\n</bo' + 'dy>\n</ht' + 'ml>'; 
		
		var printWin = window.open("","continutPrintabil"); 
		printWin.document.open(); 
		printWin.document.write(html); 
		printWin.document.close(); 
		if (gAutoPrint) 
			printWin.print(); 
	} 
	else 
	{ 
		alert("Aceasta functie poate fi utilizata numai\nde browserele cu JavaScript activat."); 
	}
}

function trimiteRecomandare()
{
	toggle('divRecomanda');
	if(document.getElementById('divRecomanda').style.display=="block")
	{
		document.getElementById('email_recomandare').focus();
	}
}

function trimiteConvert()
{
	var c_suma=document.getElementById('suma').value;
	var c_din=document.getElementById('din').value;
	var c_in=document.getElementById('in').value;
	getConverter(c_suma, c_din, c_in);
}

function openComanda(path)
{
	var newW=280;
	var newH=(document.all)?570:550;
	
	var mainWindow=window.open(path, 'newWin', 'width='+newW+',height='+newH);
	
	var X=screen.width-newW;
	var Y=(screen.height-newH)/2;
	mainWindow.moveTo(X, Y);
}

function show_detalii(val)
{
	document.getElementById("div_spec1").style.display=(val==false)?"block":"none";
}	

function show_detalii2(val)
{
	//document.getElementById("div_spec1").style.display=(val==false)?"block":"none";
	document.getElementById("div_informatii_cv").style.display=(val==false)?"block":"none";
}

function show_detalii3(div_name,val)
{
	document.getElementById(div_name).style.display=(val==false)?"none":"block";
}
	
function show_oras(val)
{
	document.getElementById("div_oras").style.display=(val==true?"block":"none");
}

function displ_sector(ob)
{
	document.getElementById("div_sectoare").style.display=((ob.options[ob.selectedIndex].text=='Bucuresti' )?"block":"none");
}

function afis_alta_locatie(ob)
{
	document.getElementById("alta_locatie1").style.display=((ob.checked)?"block":"none");
	document.getElementById("alta_locatie2").style.display=((ob.checked)?"block":"none");
}

function stergeInputText(control, defaultText)
{
	if(control.value==defaultText)
		control.value='';
}

function scrieInputText(control, text)
{
	if(control.value=="")
		control.value=text;
}

function puneBifa(control, controlBifa, defaultText)
{
	if(control.value!="" && control.value!=defaultText)
		document.getElementById(controlBifa).checked=true;
	else
		document.getElementById(controlBifa).checked=false;
}

function puneBifa2(control, controlBifa)
{
	if(control.value!="")
		document.getElementById(controlBifa).checked=true;
	else
		document.getElementById(controlBifa).checked=false;
}

function showDiv(control)
{
	document.getElementById('cautareAdvDentisti').style.display='none';
	document.getElementById('cautareAdvCariere').style.display='none';
	document.getElementById('cautareAdvArticole').style.display='none';
	document.getElementById(control).style.display='block';
}

function submitNewsletter(sens)
{
	theForm=document.getElementById('formNewsletter');
	theField=document.getElementById('sens_newsletter');
	theField.value=sens;
	theForm.submit();
}

function getFileExtension(inputId)
{
	var fileinput=document.getElementById(inputId);
	if(!fileinput) return "";
	var filename=fileinput.value;
	if(filename.length==0) return "";
	var dot=filename.lastIndexOf(".");
	if(dot==-1) return "";
	var extension=filename.substr(dot+1,filename.length);
	return extension;
}

function toggleDeschis(id)
{
	document.getElementById('inchis_'+id).checked=false;
	document.getElementById('deschis_'+id).checked=true;
}

function arata_ascunde_harta(div_buton,div_harta,camp_ascuns) 
{
 	document.getElementById(camp_ascuns).value=-document.getElementById(camp_ascuns).value;
	
	if(document.getElementById(camp_ascuns).value==-1)
	{
		
		document.cookie = 'harta_vizibila=0';
		document.getElementById(div_buton).value="Arata harta";
		document.getElementById(div_harta).style.display="none";
		document.getElementById(div_buton).className  = "vizibilitate_harta";
	}
	else
	{
		
		document.cookie = 'harta_vizibila=1';
		document.getElementById(div_buton).value="Ascunde harta";
		document.getElementById(div_harta).style.display="block";
		document.getElementById(div_buton).className  = "vizibilitate_harta_viz";
	}
}

function arata_ascunde_div(div_element,camp_ascuns) 
{
	if(document.getElementById(camp_ascuns).value==1)
	{
		document.getElementById(div_element).style.display="block";
	}
	else
	{
		document.getElementById(div_element).style.display="none";
	}
	document.getElementById(camp_ascuns).value=-document.getElementById(camp_ascuns).value;
}

function toggle_subscribe(obj) {
	var el = document.getElementById(obj);
	if ( el.value != '1' ) {
		el.value = '1';
	}
	else {
		el.value = '0';
	}
}

function del_confirm(lnk,msg)
{
	if (confirm(msg))
		document.location=lnk;
}

function toggle(obj) {
	var el = document.getElementById(obj);
		el.style.display = (el.style.display != 'none') ? 'none' : '';
}

function submitenter(myfield,e,form_name)
{
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
	
	    if (keycode == 13)
	    {
		  document.form_name.submit();
		   return false;
	    }
	    else
	   	   return true;
}
function replaceAll (streng, soeg, erstat)
{ var st = streng;
  if (soeg.length == 0)
     return st;
  var idx = st.indexOf(soeg);
  while (idx >= 0)        
  {  st = st.substring(0,idx) + erstat + st.substr(idx+soeg.length);
     idx = st.indexOf(soeg);
  }
  return st;
}

function setCookie(c_name,value,expiredays)
	{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}
	
	function getCookie(c_name)
	{
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
		{ 
		c_start=c_start + c_name.length+1; 
		c_end=document.cookie.indexOf(";",c_start);
		if (c_end==-1) c_end=document.cookie.length;
		return unescape(document.cookie.substring(c_start,c_end));
		} 
	  }
	return "";
	}
	
/* ------ SETARE POZITIE SCROLL -------*/	
	function getScrollXY() {
		var scrOfX = 0, scrOfY = 0;
		if( typeof( window.pageYOffset ) == 'number' ) {
			scrOfY = window.pageYOffset; scrOfX = window.pageXOffset;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft;
		}
		//	window.alert( 'Horizontal scrolling = ' + scrOfX + '\nVertical scrolling = ' + scrOfY );
		setCookie('scrollingX', scrOfX, 99999);
		setCookie('scrollingY', scrOfY, 99999);
		setCookie('scrollingURL', window.location, 99999);
	}
		
	function SaveScrollXY() 
	{
		getScrollXY();
		
	}
	function ResetScrollPosition() 
	{
		if(getCookie('scrollingURL') == window.location){
		var hidx, hidy;
		hidx = getCookie('scrollingX');
		hidy = getCookie('scrollingY');
		window.scrollTo(hidx, hidy);
		}
	}
/* ------ SETARE POZITIE SCROLL -------*/	

function verify_hour(form,field,value)
{
	var myArr = new Array(); 
	var str=value; 
	myArr=str.split(':'); 
	if(myArr[0]<24) 
	{
		if(myArr[1]>59)
		{
			alert('Ora introdusa nu este acceptata');
			document.form.field.focus();
		}
	}
	if(myArr[0]==24) 
	{
		if(myArr[1]>0)
		{
			alert('Ora introdusa nu este acceptata');
			document.form.field.focus();
		}
	}
	if(myArr[0]>24)
	{
		alert('Ora introdusa nu este acceptata');
		document.form.field.focus();
	}
}

function arata_ascunde_impresii() 
{
 	document.getElementById('hidden_id_vizibilitate_impresii').value=-document.getElementById('hidden_id_vizibilitate_impresii').value;
	if(document.getElementById('hidden_id_vizibilitate_impresii').value==-1)
	{
		document.getElementById('arata_impresii').style.display="none";
	}
	else
	{
		document.getElementById('arata_impresii').style.display="block";
		
		/* dc impresiile sunt vizibile, ascundem formularul pt adaugare de review */
		if(document.getElementById('arata_formular_review').style.display=="block")
		{
			document.getElementById('arata_formular_review').style.display="none";
			document.getElementById('hidden_id_vizibilitate_formular_review').value=-1;
		}
		
	}
}
function arata_ascunde_formular_review() 
{
 	document.getElementById('hidden_id_vizibilitate_formular_review').value=-document.getElementById('hidden_id_vizibilitate_formular_review').value;
	if(document.getElementById('hidden_id_vizibilitate_formular_review').value==-1)
	{
		document.getElementById('arata_formular_review').style.display="none";
	}
	else
	{
		document.getElementById('arata_formular_review').style.display="block";
		
		// dc formularul pt adaugare de review e vizibil, ascundem impresiile
		if(document.getElementById('arata_impresii').style.display=="block")
		{
			document.getElementById('arata_impresii').style.display="none";
			document.getElementById('hidden_id_vizibilitate_impresii').value=-1;
		}
	}
}

// tooooltip
var tooltip=function(){
	var id = 'tt';
	var top = 4;
	var left = 4;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,t,c,b,h;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
			}
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tt.style.top = (u - h) + 'px';
			tt.style.left = (l + left) + 'px';
		},
		fade:function(d){
			var a = alpha;
			if((a != endalpha && d == 1) || (a != 0 && d == -1)){
				var i = speed;
				if(endalpha - a < speed && d == 1){
					i = endalpha - a;
				}else if(alpha < speed && d == -1){
					i = a;
				}
				alpha = a + (i * d);
				tt.style.opacity = alpha * .01;
				tt.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tt.timer);
				if(d == -1){tt.style.display = 'none'}
			}
		},
		hide:function(){
			clearInterval(tt.timer);
			tt.timer = setInterval(function(){tooltip.fade(-1)},timer);
		}
	};
}();

function del_cookie(name) {
	document.cookie = name +
	'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

function sp(e,d){if(e=='l'){e1='#left_pages'+(d?'_2':'');e2='#right_pages'+(d?'_2':'');}
else{e1='#right_pages'+(d?'_2':'');e2='#left_pages'+(d?'_2':'');}
if(jQuery(e1).is(":hidden")){if(jQuery(e2).is(":visible")){jQuery(e2).hide('normal');}
parentpos=jQuery(e1+"_p a").offset();jQuery(e1).css('top',parseInt(parentpos.top));if(e1.indexOf('right')==-1){jQuery(e1).css('left',parseInt(parentpos.left)-2);}
else{jQuery(e1).css('right',parseInt(jQuery(document).width())-parseInt(parentpos.left)-parseInt(jQuery(e1+"_p").outerWidth())-2);}
jQuery(e1).show('fast');}
else{jQuery(e1).hide('normal');}}

function go_to_anchor(name)
{
	window.location.hash = '#'+name;
}

function verificareValoareInInterval(field,int1,int2) 
{
	var re = /^[0-9]*$/;
	if (!re.test(field.value)) 
	{
		alert('Sunt acceptate doar caractere numerice.');
		//field.value = field.value.replace(/[^0-9]/g,"");
		field.value = "";
		return false;
	}
	else
	{		
		if((field.value<int1) || (field.value>int2))
		{
			alert('Se accepta doar numere cuprinse in intervalul '+int1+'-'+int2);
			//field.value = field.value.replace(/[^0-9]/g,"");
			field.value = "";
			return false;
		}
		else
		{
			return true;
		}
	}
}

/*function afiseaza_nr_echipe_calificate(ob,div_name,nr_echipe_inscrise) 
{
	if( (nr_echipe_inscrise==6) || (nr_echipe_inscrise==7) || (nr_echipe_inscrise==8) || (nr_echipe_inscrise==15) || (nr_echipe_inscrise==16) )
	{
		//document.getElementById(div_name).style.display=(val==false)?"none":"block";
		if(ob.options[ob.selectedIndex].text=='Grupe+Cupa')
		{
			document.getElementById(div_name).style.display="block";
		}
		else
		{
			document.getElementById(div_name).style.display="none";
		}
	}
	else
	{
		document.getElementById(div_name).style.display="none";
	}
	alert(ob.options[ob.selectedIndex].text);
	alert(nr_echipe_inscrise);
}
*/
function confirmare_submit($mesaj)
{
	var r=confirm($mesaj);
	if (r==true)
	{
	 	 //alert("TRUE");
		 return true;
	}
	else
	{
		//alert("FALSE");
		return false;
	}
}

function setCookie(key, value, maxlife) 
{  
		 var expires = new Date();  
		 expires.setTime(expires.getTime() + maxlife); // 31536000000 - 1 year  
		 document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();  
}  
     
function getCookie(key) 
{  
		 var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');  
		 return keyValue ? keyValue[2] : null;  
}  
 


