function isInteger (s)
{
	var i;

	if (isEmpty(s))
		if (isInteger.arguments.length == 1) return 0;
		else return (isInteger.arguments[1] == true);
	for (i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if (!isDigit(c)) return false;
	}
	return true;
}
function isEmpty(s)
{
	return ((s == null) || (s.length == 0))
}
function isDigit (c)
{
	return ((c >= "0") && (c <= "9"))
}
function formValidator(type){
	if(type=="upload"){
		titlu = document.getElementById('uploadtitlu');
		nume = document.getElementById('uploadname');
		city = document.getElementById('uploadcity');
		email = document.getElementById('uploademail');
		phone = document.getElementById('uploadphone');
		text = document.getElementById('uploadtext');
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

		if (isEmpty(titlu.value)){
			alert("Va rugam sa introduceti Titlul materialului.");
			titlu.focus();
			return (false);
		}
		if (isEmpty(nume.value)){
			alert("Va rugam sa introduceti Numele.");
			nume.focus();
			return (false);
		}
		if (isEmpty(city.value)){
			alert("Va rugam sa introduceti Orasul.");
			city.focus();
			return (false);
		}
		if (isEmpty(email.value)){
			alert("Va rugam sa introduceti Email-ul.");
			email.focus();
			return (false);
		} else if(reg.test(email.value) == false) {
			alert("Va rugam sa introduceti un Email valid.");
			return false;
		}
		if (isEmpty(phone.value)){
			alert("Va rugam sa introduceti Nr. de telefon.");
			phone.focus();
			return (false);
		}
		if (isEmpty(text.value)){
			alert("Va rugam sa introduceti Comentariul.");
			text.focus();
			return (false);
		}
	} else {
		nume = document.getElementById('commentname');
		comentariu = document.getElementById('commenttext');
		if (nume.value == ""){
			alert("Va rugam sa va introduceti numele.");
			nume.focus();
			return (false);
		}
		if (comentariu.value == ""){
			if(type==1){
				alert("Introduceti comentariul.");
			}else{
				alert("Introduceti intrebarea.");
			}
			comentariu.focus();
			return (false);
		}
	}
	return (true);
}
function cnv (cr){
	bs = parseFloat(document.forms['fr_cnv'][cr].value);

	if (cr=='MDL') mdl = bs;
	else mdl = Math.round(100 * bs * parseFloat(document.forms['fr_cnv']['hd_'+cr].value)) / 100;
	
	rol = Math.round(100 * mdl / parseFloat(document.forms['fr_cnv']['hd_ROL'].value)) / 100;
	eur = Math.round(100 * mdl / parseFloat(document.forms['fr_cnv']['hd_EUR'].value)) / 100;
	usd = Math.round(100 * mdl / parseFloat(document.forms['fr_cnv']['hd_USD'].value)) / 100;
	uah = Math.round(100 * mdl / parseFloat(document.forms['fr_cnv']['hd_UAH'].value)) / 100;
	rub = Math.round(100 * mdl / parseFloat(document.forms['fr_cnv']['hd_RUB'].value)) / 100;

	if (!isNaN(rol) && cr !='ROL') document.forms['fr_cnv']['ROL'].value = rol;
	if (!isNaN(eur) && cr !='EUR') document.forms['fr_cnv']['EUR'].value = eur;
	if (!isNaN(usd) && cr !='USD') document.forms['fr_cnv']['USD'].value = usd;
	if (!isNaN(uah) && cr !='UAH') document.forms['fr_cnv']['UAH'].value = uah;
	if (!isNaN(rub) && cr !='RUB') document.forms['fr_cnv']['RUB'].value = rub;
	if (!isNaN(mdl) && cr !='MDL') document.forms['fr_cnv']['MDL'].value = mdl;
}
function valbaza(id, text){
	if (id.value == ""){
		id.value = text;
	}
}
function valnula(id, text){
	if (id.value == text){
		id.value = "";
	}
}
function togLayer(id){
	if(currLayerId) setDisplay(currLayerId, "none");
	if(id)setDisplay(id, "block");
	currLayerId = id;
}
function setDisplay(id,value){
	var elm = document.getElementById(id);
	elm.style.display = value;
}
function togNews(id, img){
	if(currNews != id){
		if(currNews) {
			setDisplay(currNews, "none");
			setImage(currImg, "sys/img/common/rg.gif");
		}
		if(id){
			setDisplay(id, "block");
			setImage(img, "sys/img/common/dw.gif");
		}
		currNews = id;
		currImg = img;
	} else if(currNews) {
		setDisplay(currNews, "none");
		setImage(currImg, "sys/img/common/rg.gif");

		currNews = null;
		currImg = null;
	}
}
function setImage(img,value){
	var elm = document.getElementById(img);
	elm.src = value;
}
var browser=navigator.userAgent.toLowerCase();
var isFF=((browser.indexOf('mozilla')!=-1) && (browser.indexOf('spoofer')==-1) && (browser.indexOf('compatible')==-1) && (browser.indexOf('opera')==-1) && (browser.indexOf('webtv')==-1) && (browser.indexOf('hotjava')==-1));
var isIE=((browser.indexOf("msie")!=-1) && (browser.indexOf("opera")==-1));
var isOP=(browser.indexOf("opera")!=-1);

function insert(insert, type, elem){
	if(type==1){
		if(isIE){
			el = document.getElementById(elem);
			el.focus();
			document.selection.createRange().text='['+insert+']'+document.selection.createRange().text+'[/'+insert+']';
		}else{
			el = document.getElementById(elem);
			var text=el;
			el.focus();
			text=text.value.substring(0, text.selectionStart)+'['+insert+']'+text.value.substring(text.selectionStart, text.selectionEnd)+'[/'+insert+']'+text.value.substring(text.selectionEnd, text.value.length);
			el.value=text;
		}
	}else{
		if(isIE){
			el = document.getElementById(elem);
			el.focus();
			document.selection.createRange().text='['+insert+']http://'+document.selection.createRange().text+'[/'+insert+']';
		}else{
			el = document.getElementById(elem);
			var text=el;
			el.focus();
			text=text.value.substring(0, text.selectionStart)+'['+insert+']http://'+text.value.substring(text.selectionStart, text.selectionEnd)+'[/'+insert+']'+text.value.substring(text.selectionEnd, text.value.length);
			el.value=text;
		}
	}
}