
function setStar(objId,nr)
{
	$(objId).src="images/stars"+nr+".gif";
}
function memoStar(objId,nr)
{
	$(objId).value=nr;
}
function resetStar(objId1,objId2)
{
	$(objId1).src="images/stars"+$(objId2).value+".gif";
}

function rateArticle(articleId, rating){
	var ajax = new sack();
	ajax.requestFile = "ajax.php";
	ajax.setVar("act", "rateArticle");
	ajax.setVar("articleId", articleId);
	ajax.setVar("rating", rating); 
	ajax.method = "POST";
	ajax.onCompletion = evalResponse;
	ajax.runAJAX();
}

function updateArticleRating(articleId,rateSum,votes)
{
	r = parseInt(rateSum);
	v = parseInt(votes);
	if(v>0)	rate = r/v;
	else rate = 0;
	if($("articleRatingText"+articleId))
		$("articleRatingText"+articleId).innerHTML = 'Nota curenta <strong>'+(Math.round(rate*10)/10)+'</strong> din '+v+' voturi <img id="stars'+articleId+'" src="images/stars'+Math.round(rate)+'.gif" border="0" style="vertical-align:middle"/>';
	if($("articleRatingTextList"+articleId))
		$("articleRatingTextList"+articleId).innerHTML = '<strong>'+(Math.round(rate*10)/10)+'</strong>/'+v+' voturi<img src="images/stars'+Math.round(rate)+'.gif" border="0" style="vertical-align:middle"/>';
}

function evalResponse()
{		
	try{
		//alert(this.response);
		eval(this.response);
	}
	catch(err){
		alert("Error: "+ err.description + "\n\n" + this.response);
	}
}

function popupWindow(url, width, height){
	var winl = (screen.width - width) / 2;
	var wint = (screen.height - height) / 2;
	var winprops = 'resizable=yes,fullscreen=no,height='+height+',width='+width+',top='+wint+',left='+winl+'resizable=0'
	window.open(url, '', winprops)
}

function openImgPopup(file,title,baseDir)
{
	if(file=='') return;
	if(baseDir == undefined) baseDir = '';
	window.open(baseDir+'popupimg.php?f=' + file + (title!=undefined?'&t='+escape(title):''), '', 'width=200,height=200,left=150,top=100,status=no,toolbar=no,menubar=no,resizable=no');
}

function focusNewsletter(focus) {
	var el = $("mainNewsletter");
	if(focus && el.value=="e-mail address") el.value = "";
	if(!focus && el.value == "" ) el.value = "e-mail address";
}

function focusTellAFriend(focus) {
	var el = $("mainTellAFriend");
	if(focus && el.value=="e-mail address") el.value = "";
	if(!focus && el.value == "" ) el.value = "e-mail address";
}


function mainNewsletterSubmit() {
	var el = $("mainNewsletter");
	if(el.value=="e-mail address" || el.value=="") {
		el.value = " ";
		alert("E-mail address is required");
		el.value = "";
		el.focus();
		return false;
	}
	if(!isEmail(el.value)) {
		alert("E-mail address is invalid");
		el.focus();
		return false;
	}
	return true;
}


function mainSearchSubmit() {
	var el = $("mainSearch");
	var v = el.value.replace(/^\s+|\s+$/g,"");
	if(v == "" || v == 'search our website' ) {
		el.value = " ";
		alert('Please enter some search terms');
		el.focus();
		return false;
	}
	return true;
}

function focusSearch(focus) {
	var el = $("mainSearch");
	if(focus && el.value=="search our website") el.value = "";
	if(!focus && el.value == "" ) el.value = "search our website";
}


	function mainSondajSubmit() {
		if($("sondajSelected").value=="") {
			alert("Selectati o optiune!");
			return false;
		}
		$("mainSondajForm").submit();
	}
