if(typeof(jQuery)!=="undefined") jQuery.noConflict();

// D E T E C T : browser
var browser=navigator.appName;
if(browser.indexOf('Microsoft')!==-1) browser='ie';
else browser='other';
//

function urlencode(str) {
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function rolloverImg(id,src) {
	doc=document;
  el=doc.getElementById(id);
  if(!el.oldSrc) el.oldSrc=el.src;
  el.src=src;
	el.onmouseout=restoreImg;
  doc.currentHover=id;
}
function restoreImg() {
	doc=document;
  id=doc.currentHover;
  el=doc.getElementById(id);
  el.src=el.oldSrc;
}
function check_email(str) {
at=str.indexOf('@');
dot=str.indexOf('.',at);
last_at=str.lastIndexOf('@');
last_dot=str.lastIndexOf('.');
if(at>0 && dot>0 && (dot-at)>1 && str.length-dot>1 && last_dot==dot && last_at==at && str.length>5) { valid='1' }
else { valid='0'; }
return valid
}
function show_and_hide(id1,id2) {
	document.getElementById(id1).style.display='block';
	document.getElementById(id2).style.display='none';
}
function pop_up(url,name,width,height,scroll) {
  if(!scroll || scroll=="" || typeof(scroll)=="undefined") scroll=0;  
	w = (document.body.clientWidth - width)/2;
  h = (document.body.clientHeight)/2;
	window.open(url,name,'width=' + width + ',height=' + height + ',menubar=no,left='+w+',top='+h+',screenX='+w+',screenY='+h+',scrollbars='+scroll);
}
function write_editor(text_to_write) {
	parent.frame_editor.document.write(text_to_write);
}
function show_hide(id) {
	if(document.getElementById(id).style.display == 'none') { document.getElementById(id).style.display = 'block'; }
	else { document.getElementById(id).style.display = 'none'; }
}
function show_hide_check(id) {
	
	alert('You must login to add a review.');
	}
function increase_height(id) {
	var h = parseInt(document.getElementById(id).style.height);
	var h = h + 50;
	document.getElementById(id).style.height = h + 'px';
}
function decrease_height(id) {
	var h = parseInt(document.getElementById(id).style.height);
	if(h > 50) {
	var h = h - 50;
	document.getElementById(id).style.height = h + 'px';
	}
	else {
		alert('Minimum height reached');
	}
}
function add_emot(id_t,emot) {
	document.getElementById(id_t).value = document.getElementById(id_t).value + emot;
	document.getElementById(id_t).focus();
}
function over(id,color) {
	document.getElementById(id).style.backgroundColor = "#" + color;
}
function out(id) {
	document.getElementById(id).style.backgroundColor = '';
}
function over_u(id) {
	document.getElementById('usermenu' + id).style.backgroundColor = "#83c274";
	document.getElementById('usermenu' + id).style.padding = "2";
	document.getElementById('userlink' + id).style.color="#ffffff";
	document.getElementById('userlink' + id).style.fontWeight="bold";
}
function out_u(id) {
	document.getElementById('usermenu' + id).style.backgroundColor = "";
	document.getElementById('usermenu' + id).style.padding = "2";
	document.getElementById('userlink' + id).style.color="#000000";
	document.getElementById('userlink' + id).style.fontWeight="normal";
}
function show(id) {
	document.getElementById(id).style.display='block';
}
function hide(id) {
	document.getElementById(id).style.display='none';
}
function browser_detection() {
	browser_version = parseInt(navigator.appVersion);
	browser_type = navigator.appName;
	if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
   var type='ie';
	} 
	else {
   var type='other';
	}
	return type;
}
function hover_star(nr,star) {
	for(i=1;i<=nr;i++) {
  	document.getElementById("star"+i).src='/images/over_'+star+'.gif';
  }
}
function out_star(nr,star) {
	for(i=1;i<=nr;i++) {
  	tp=document.getElementById('star'+i).name;
  	document.getElementById("star"+i).src='/images/'+tp+'_'+star+'.gif';
  }
}
function checkSearch() {
	s=$("search_keyword");
  if(trim(s.value).length<3) {
  	alert("Trebuie sa adaugati minim un cuvant cheie de 3 caractere");
    s.focus();
    return false;
  }
}
function preload_images(folder,pics) {
	pics=pics.split(";");
  for(i=0;i<pics.length;i++) {
  	img=new Image();
    img.src=folder+pics[i];
  }
}
function changeValue(id) {
	d=document; el=d.getElementById(id);
	if(!el.oldValue) {
  	el.oldValue=el.value;
  }
  val=el.oldValue;
  if(el.value==el.oldValue) {
    el.focus();
  	el.value='';
    el.onblur=function() { returnValue(id) };
  }
}
function returnValue(id) {
	d=document; el=d.getElementById(id);
  if(el.value=='') el.value=el.oldValue;
}

// ---------- transparent png's for ie correction ----------

if(navigator.appVersion.indexOf("MSIE")!==-1) {
  function correctPNG()
  {
     var arVersion = navigator.appVersion.split("MSIE")
     var version = parseFloat(arVersion[1])
     if ((version >= 5.5) && (document.body.filters)) 
     {
        for(var i=0; i<document.images.length; i++)
        {
           var img = document.images[i]
           var imgName = img.src.toUpperCase()
           if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
           {
              var imgID = (img.id) ? "id='" + img.id + "' " : ""
              var imgClass = (img.className) ? "class='" + img.className + "' " : ""
              var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
              var imgStyle = "display:inline-block;" + img.style.cssText 
              if (img.align == "left") imgStyle = "float:left;" + imgStyle
              if (img.align == "right") imgStyle = "float:right;" + imgStyle
              if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
              var strNewHTML = "<span " + imgID + imgClass + imgTitle
              + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
              + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
              + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
              img.outerHTML = strNewHTML
              i = i-1
           }
        }
     }    
  }
  //window.attachEvent("onload", correctPNG);
}
// ---------- end transparent png's for ie correction ----------

function runFile(file) {
	d=document;
  ifr=d.getElementById('hiddenIfr');
  ifr.src=file;
}
function getElementPosition(elemID){
  var offsetTrail = document.getElementById(elemID);
  var offsetLeft = 0;
  var offsetTop = 0;
  while (offsetTrail){
   offsetLeft += offsetTrail.offsetLeft;
   offsetTop += offsetTrail.offsetTop;
   offsetTrail = offsetTrail.offsetParent;
  }
  if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
   offsetLeft += document.body.leftMargin;
   offsetTop += document.body.topMargin;
  }
  return {left:offsetLeft,top:offsetTop};
}
function getEl(el) {
	return document.getElementById(el);
}

function forms() {
  this.toCheck=new Array();
	this.checkPass=new Array();
	this.checkEmails=new Array();
	this.message="";
  this.alertMsg="";
  this.createMessage=true;
  this.badBg="url('/images/inp_check.gif') no-repeat top left";
  this.goodBg="url('/images/inp.gif') no-repeat top left";
	this.check=function () {
		var clean=true;
		var d=document;
		var first;
		// check if filled
  	for(i=0;i<this.toCheck.length;i++) {
			el=d.getElementById(this.toCheck[i]);
			if(el.value=="" || el.value==" ") {
				if(clean) first=el;
	  		clean=false;
				el.style.background=this.badBg;
			}
			else {
				el.style.background=this.goodBg;
			}
  	}
		// check emails
		ems=true;
		for(i=0;i<this.checkEmails.length;i++) {
			el=d.getElementById(this.checkEmails[i]);
			if(check_email(el.value)==0 && clean==true && ems==true) {
				el.style.background=this.badBg;
				el.focus();
				alert("Adresa de email este incorecta");
				ems=false;
				return false;
			}
			else
				if(clean==true) el.style.background=this.goodBg;
		}
  	if(clean==false) {
			first.focus();
      if(this.alertMsg=="") this.alergMsg="Te rog completeaza toate campurile marcate cu '*'";
			alert(this.alertMsg);
		  return false;
	  }
	  else return true;
	}
	
	this.send=function (formId,urlSend,fRes) {
		d=document;
		f=d.getElementById(formId);
		if(!fRes) fRes="formResult";
		resDiv=d.getElementById(fRes);
		f.target="hiddenIfr";
		f.action=urlSend;
		resDiv.style.display='block';
    if(this.createMessage) resDiv.innerHTML="<div class='success'>"+this.message+"<br><center><img src='/inc/files/loader.gif'></center></div>";
		f.style.display='none';
		
		f.submit();
	}
}

function checkNewsletterForm() {
	if(trim($("nume_newsletter").value)=="Nume" || trim($("nume_newsletter").value)=="") {
		alert("Scrieti-ti numele");
		$("nume_newsletter").focus();
		return false;
	}
	if(check_email($("email_newsletter").value)=="0") {
		alert("Scrie un email valid te rog");
		$("email_newsletter").focus();
		return false;
	}
}

window.addEvent('domready', function() {
     $$('a.tipz').each(function(element,index) {  
         var content = element.get('title').split('::');  
         element.store('tip:title', content[0]);  
         element.store('tip:text', content[1]);  
     });
     $$('a.tipzFixed').each(function(element,index) {  
         var content = element.get('title').split('::');  
         element.store('tip:title', content[0]);  
         element.store('tip:text', content[1]);  
     });  
     
			var tipz = new Tips('.tipz', { 
				className: 'tip'
			});
			var tipzImg = new Tips('.imgTipz', { 
				className: 'imgTip'
			});
			
			var tipz2 = new Tips('.tipzFixed', {
				fixed: true,
				className: 'tip'
			});
});

function addComent(pentru, id, ver_code) {
	var cForm=new forms();
	cForm.message="Incarca...";
	cForm.toCheck=new Array("nume_coment", "email_coment", "coment", "ver_code_coment");
	cForm.checkEmails=new Array("email_coment");
  cForm.badBg="#fffcd7";
  cForm.goodBg="#e8e5da";
  cForm.createMessage=false;
	clear=cForm.check();
	if(clear==false) return false;
  else {
  	if(md5($("ver_code_coment").value)!==ver_code) {
    	alert("Codul de verificare este incorect");
      $("ver_code_coment").focus();
      return false;
    }
    else {
    	cForm.send('add_coment','/inc/ajax/add_coment.php?pentru='+pentru+'&id='+id, "add_coment_loader");
    	return false;
    }
  }
}

function setOpacity(el,chTo) {
	var elem;
	elem=getEl(el);
	if(browser=='ie')
		elem.filter='alpha(opacity='+chTo+')';
	else
		elem.style.opacity=chTo/100;
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function getTopScroll() {
	if (navigator.appName == "Microsoft Internet Explorer")
		r=document.body.scrollTop;
	else
		r=window.pageYOffset;
	return r;
}

var topLoginCheckNr=0;
function checkTopLogin() {
  topLoginCheckNr++;
	if($("top-login-email").value=="" || $("top-login-email").value=="email") {
   if(topLoginCheckNr<=2) {
  	alert(top_login_errors["no-email"]);
    $("top-login-email").focus();
    return false;
   }
   else {
    window.location='/recover-pass';
    return false;
   }
  }
  else {
  	$("topLoginForm").action="/inc/ajax/top-login.php?nr="+topLoginCheckNr;
    $("topLoginForm").target="hiddenIfr";
    $("topLoginForm").submit();
    $("topLoginForm").style.display="none";
    $("top-login-loader").style.display="block";
  }
}

// for rate
function hover_star(idType,nr,star) {
	if(!star) star='/images/icons/star_hover.gif';
	for(i=1;i<=nr;i++) {
  	el=document.getElementById(idType+i);
		el.oSrc=el.src;
  	el.src=star;
  }
}
function out_star(idType,nr) {
	for(i=1;i<=nr;i++) {
		el=document.getElementById(idType+i);
  	el.src=el.oSrc;
  }
}
function rateIt(id,file) {
	d=document;
	dv=d.getElementById('rating'+id);
	dv.innerHTML='<img src="/images/loaders/2.gif" alt="">';
	runFile(file);
}
//

// + thumbs
preload_images("/images/icons/", "thumb_up-disabled.gif;thumb_down-disabled.gif");
function func_thumbIt(dir, tId, table, crThumbs, dis1, dis2) {
	if(dir=="up") crThumbs++; else crThumbs--;
  
  if(crThumbs>0) $("thumbsNr_"+table+tId).style.color='green';
  else if(crThumbs==0) $("thumbsNr_"+table+tId).style.color='#555';
  else $("thumbsNr_"+table+tId).style.color='red';
  if(crThumbs>0) $("thumbsNr_"+table+tId).innerHTML="+"+crThumbs; else $("thumbsNr_"+table+tId).innerHTML=crThumbs;
  
  $("thumbDown_"+table+tId).src=dis1;
  $("thumbDown_"+table+tId).onclick=function() { };
  $("thumbDown_"+table+tId).style.cursor='auto';
  $("thumbUp_"+table+tId).src=dis2; 
  $("thumbUp_"+table+tId).onclick=function() { };
  $("thumbUp_"+table+tId).style.cursor='auto';
  
  runFile("/inc/ajax/thumb.php?id="+tId+"&table="+table+"&dir="+dir);
}
// - thumbs


var reporting=false;
// + report
function reportIt(r_id, r_table, r_link) {
	//$("report"+r_table+r_id).innerHTML=vars["reported"];
  //theLink="/inc/ajax/report.php?id="+r_id+"&table="+r_table+"&link="+r_link;
  //runFile(theLink);
  if(reporting!==r_id) {
  closeReport();
  reporting=r_id;
  
  elId="report"+r_table+r_id;
  offset=jQuery("#"+elId).offset();
  width=jQuery("#"+elId).width();
  
  bd=document.getElementsByTagName("body")[0];
	dv=document.createElement("div");
	dv.setAttribute("id","reportItDiv");
	dv.style.position='absolute';
	dv.style.zIndex=1000;
	dv.style.top=(offset["top"]-3)+"px";
  left=offset["left"]+width+2;
  dv.style.left=left+"px";
	dv.style.width="220px";
  dv.style.background="#fff";
  dv.style.border="1px solid #ccc";
  dv.style.padding="4px";
	
	bd.appendChild(dv);
  
  dv.innerHTML="<div id='reportReasonLoader' style='display:none'><br><br><center><img src='/images/loaders/1.gif'><br><br><br></div><form id='reportReasonForm' method='post' target='hiddenIfr' action='/inc/ajax/report.php' style='margin:0px' onsubmit='return reportCheck()'><font class='t11 grey3'>"+vars["report-reason"]+"</font><br><textarea class='inp' style='width:100%; height:50px; font-size:11px;' id='report-reason' name='report-reason' onkeydown='limitText(this.id, \"reportReasonCounter\", 250)' onkeyup='limitText(this.id, \"reportReasonCounter\", 250)'></textarea><span class='t11 grey3'><span id='reportReasonCounter'>250</span> "+vars["char-left"]+"</span><br><input type='submit' value='"+vars["report-submit"]+"' class='submit'><input type='button' onclick='closeReport()' value='"+vars["cancel"]+"' class='submit'><input type='hidden' name='report-id' value='"+r_id+"'><input type='hidden' name='report-table' value='"+r_table+"'><input type='hidden' name='report-link' value='"+r_link+"'></form>";
	}
  else closeReport();
}
function closeReport() {
	d=document;
	bd=d.getElementsByTagName("body")[0];
	if(reporting!==false) bd.removeChild($("reportItDiv"));
  reporting=false;
}
function reportCheck() {
	if(trim($("report-reason").value)=="") {
  	alert(vars["errors"]["no-report-reason"]);
    $("report-reason").focus();
  }
  else {
		$("reportReasonForm").submit();
    $("reportReasonForm").style.display="none";
    $("reportReasonLoader").style.display="block";  	
  }
  return false;
} 
 
// - report

function topChangeLang() {
	jQuery("#top-languages").toggle("fast");
}


function limitText(fieldId, counterId, maxNr) {
	if($(fieldId).value.length>maxNr) $(fieldId).value=$(fieldId).value.substring(0, maxNr);
  else $(counterId).innerHTML=maxNr-$(fieldId).value.length;
}
// onkeydown="limitText(this.id, counterId, 250)" onkeyup="limitText(this.id, counterId, 250)


if(typeof(jQuery)!=="undefined") {
// + term search
var termSearch_closing=false;
function termSearch() {
	term=trim($("dict-search").value);
  if(term=="") {
  	$("dict-search-res").style.display="none";
    $("dict-search-res").innerHTML="";
  }
  else {
  	pos=jQuery("#dict-search").offset();
    h=jQuery("#dict-search").height(); 
    //w=jQuery("#dict-search").width();
    if(browser=='ie') w=380;
    else w=378;
    $("dict-search-res").style.width=w+"px";
    $("dict-search-res").style.top=(pos["top"]+h)+"px";
    $("dict-search-res").style.left=pos["left"]+"px";
    $("dict-search-res").style.display="block";
    if($("dict-search-res").innerHTML.indexOf("loaders/2.gif")==-1)
    	$("dict-search-res").innerHTML="&nbsp;&nbsp;<img src='/images/loaders/2.gif'>";
    //runFile("/dictionary/ajax/searchTerm.php?term="+urlencode(term));
    jQuery("#dict-search-res").load("/dictionary/ajax/searchTerm.php?term="+urlencode(term));
    $("dict-search").addEvent("blur", function() { termSearch_closing=setTimeout('termSearch_close()', 200); });
  }
  
}
function termSearch_close() {
	$("dict-search-res").style.display="none";
  $("dict-search-res").innerHTML="";
  //$("dict-search").focus();
}
// - term search


// search
jQuery(document).ready(function(){
  jQuery("#search-keyword").focus(function() {
    if(this.value==vars["search"] || typeof(this.origValue)=="undefined" || this.value==this.origValue) {
      this.origValue=this.value;
    	this.value="";
      this.style.color='#555';
    }
  });
  jQuery("#search-keyword").blur(function() {
  	if(this.value=="") { this.value=this.origValue; this.style.color='#aaa'; }    
  });
  jQuery("#search-form").submit(function() {
  	if($("search-keyword").value==vars["search"] || trim($("search-keyword").value).length<3) {
    	alert(vars["search-error"]);
      $("search-keyword").focus();
      return false;
    }
  });
  jQuery("#search-submit").click(function() {
  	jQuery("#search-form").submit();
  });
});

//
}

preload_images("/images/but/", "php.gif;js.gif;php-hover.gif;js-hover.gif");
preload_images("/images/loaders/", "1.gif;2.gif;2-white.gif");
preload_images("/images/icons/", "star_hover.gif");
preload_images("/images/", "sidebar-but.gif;sidebar-but-hover.gif");
