// 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;">\n'; 
		var printPageElem = document.getElementById("printReady"); 
		
		/* ma asigur ca div-ul de recomandare anunt este inchis */
		document.getElementById('divOptiuni').style.display="none";
		document.getElementById('divSubPoza').style.display="none";
		
		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("","printFriendly"); 
		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."); 
	}
	document.getElementById('divOptiuni').style.display="block";
	document.getElementById('divSubPoza').style.display="block";
}

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 doFilter(completareLink)
{
	theSelect=document.getElementById('tara');
	if(theSelect.value!="")
	{
		document.location=absPath+theSelect.value+"/"+completareLink;
	}
}

function genereazaLista()
{
	theDiv=document.getElementById('divLista');
	theIFrame=frames['iFrameLista'];
	theDiv.style.display='block';
	theIFrame.location.href='newsletter_lista.php';
}

function submitNewsletter(sens)
{
	theForm=document.getElementById('formNewsletter');
	theField=document.getElementById('sens_newsletter');
	theField.value=sens;
	theForm.submit();
}
