// constanta generala care tine calea absoluta spre imaginile referite aici
var imgRoot = "http://www.fny.ro/";

// verifica in select-ul sel cate valori sunt selectate si le returneaza in nrSelected
function updateTotalValue(sel, totalValue, fImgConv, fJokConv, fMixConv, fBonus)
{
  // 0 - exista doar o imagine/banc, nu se cumuleaza/
  // 1 - se cumuleaza cel putin doua imagini (se ia in considerare fImgConv)
  // 2 - se cumuleaza cel putin doua bancuri (se ia in considerare fJokConv)
  // 3 - se cumuleaza cel putin o imagine si un banc (se ia in considerare fMixConv)
  var iNrImg = 0;
  var iSumImg = 0;
  var iNrJok = 0;
  var iSumJok = 0;
//  var iCurrValue = 0;
  
//  alert(fImgConv+'-'+fJokConv+'-'+fMixConv+'-'+fBonus);

  for (var i = 0; i < sel.options.length; i++) 
  {
    if (sel.options[i].selected)
    {
	   // daca valoare este negativa, se aduna la suma de imagini
	   iCurrValue = String(sel.options[i].value).split("|");

	   if (Math.round(iCurrValue[0]) < 0)
	   {
	     iSumImg += Math.round(-iCurrValue[0]);
		 iNrImg++;
	   }
	   else
	   {
	     iSumJok += Math.round(iCurrValue[0]);
		 iNrJok++;
	   }
    }
  }
  
  // daca doar suma de imagini este pozitiva, doar imagini au fost selectate
  if ((iSumImg > 0) && (iSumJok == 0))
  {
	if (iNrImg == 1)	// daca este doar o imagine, nu se aplica nici un factor de conversie
	  totalValue.value = iSumImg;
	else				// daca sunt cel putin doua imagini, se aplica factorul de conversie pentru imagini cumulate
	  totalValue.value = Math.round(iSumImg*fImgConv);
  }
  else	// daca sunt selectate doar bancuri
  if ((iSumImg == 0) && (iSumJok > 0))
  {
	  if (iNrJok == 1)	// daca doar un banc a fost selectat, nu se aplica nici un factor de conversie
	    totalValue.value = iSumJok;
	  else
	    totalValue.value = Math.round(iSumJok*fJokConv);
  }
  else	// daca sunt selectate si imagini si bancuri atunci se aplica factorul de conversie mix
  {
	  totalValue.value = Math.round((iSumImg+iSumJok)*fMixConv);
  }
  
  totalValue.value -= fBonus;
}

function computeDate(sYear, sMon, sDay, sDif, tPeriod)
{
	tPeriod.value = sYear+'-'+sMon+'-'+(sDay - sDif)+' 00:00:00';
}

// cere confirmare pentru o operatie, iar daca se raspunde
// afirmativ, se redirecteaza spre redirTrue
function askConf(sMess, pRedirTrue)
{
	var answer = confirm(sMess);
	
	if (answer)
	{
		document.location = pRedirTrue;
	}
}

function insertStr(sToInsert, tTextArea)
{
  
  tTextArea.value = tTextArea.value + sToInsert;
  tTextArea.focus();
}

function showDiv(objectID) 
{
  var theElementStyle = document.getElementById(objectID);

  if(theElementStyle.style.display == "none")
  {
    theElementStyle.style.display = "block";
  }
  else
  {
    theElementStyle.style.display = "none";
  }
}

// functie care adauga la favorite site-ul
function addFav(sTitle, sLink) {
  var agt = navigator.userAgent.toLowerCase();
  var app = navigator.appName.toLowerCase();
  var ieAgent = agt.indexOf('msie');
  var nsAgent = app.indexOf('netscape');

  if (ieAgent!= -1) {
    window.external.AddFavorite(sLink, sTitle+' - fny.ro | Te face sa zambesti :) | Singurul site premium de fun din Romania');
  }
  else if (nsAgent!= -1) {
    window.sidebar.addPanel(sTitle+' - fny.ro | Te face sa zambesti :) | Singurul site premium de fun din Romania', sLink, "");
  }
  else {
    alert('Apasa Ctrl+D pentru a adauga pagina la favorite!');
  }
}

// verifica dimensiunea unui textarea sa nu depaseasca valoarea data ca si parametru
// si returneaza numarul de caractere permise
function checkTextAreaLength(sText, iCarDisp, iNrMaxCar)
{
  // sText - pointerul spre textarea (valoarea se va accesa cu sText.value)
  // iCarDisp - pointerul spre textbox cu numarul de caractere permise (valoarea se acceseaza cu iCarDisp.value)
  if (sText.value.length > iNrMaxCar)
  {	// se trunchiaza textul la 255 caractere
    sText.value = sText.value.substring(0, iNrMaxCar);
  }
  iLenText = iNrMaxCar - sText.value.length;
  iCarDisp.value = iLenText;
}

function changePic(picName, newPic)
{
	picName.src = imgRoot+"data/fresh/smileys/z_" + newPic + ".png";
//	alert(picName.src);
}

function changeSymb(el, pic1, pic2) 
{
  var pic=((el.src.match(pic1)!=null)? pic2 : pic1); 
  el.src=imgRoot+"data/fresh/"+pic;
}

//** Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)

//** Updated: July 14th 06' to v2.0
	//1) Ability to "left", "center", or "right" align the menu items easily, just by modifying the CSS property "text-align".
	//2) Added an optional "swipe down" transitional effect for revealing the drop down menus.
	//3) Support for multiple Chrome menus on the same page.

//** Updated: Nov 14th 06' to v2.01- added iframe shim technique

//** Updated: July 23rd, 08 to v2.4
	//1) Main menu items now remain "selected" (CSS class "selected" applied) when user moves mouse into corresponding drop down menu. 
	//2) Adds ability to specify arbitrary HTML that gets added to the end of each menu item that carries a drop down menu (ie: a down arrow image).
	//3) All event handlers added to the menu are now unobstrusive, allowing you to define your own "onmouseover" or "onclick" events on the menu items.
	//4) Fixed elusive JS error in FF that sometimes occurs when mouse quickly moves between main menu items and drop down menus

//** Updated: Oct 29th, 08 to v2.5 (only .js file modified from v2.4)
	//1) Added ability to customize reveal animation speed (# of steps)
	//2) Menu now works in IE8 beta2 (a valid doctype at the top of the page is required)

var cssdropdown={
disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseout
dropdownindicator: '<img src="http://www.fny.ro/data/1/symb_down.png" width="9" height="5" border="0" />', //specify full HTML to add to end of each menu item with a drop down menu
enablereveal: [true, 2], //enable swipe effect? [true/false, steps (Number of animation steps. Integer between 1-20. Smaller=faster)]
enableiframeshim: 1, //enable "iframe shim" in IE5.5 to IE7? (1=yes, 0=no)

//No need to edit beyond here////////////////////////

dropmenuobj: null, asscmenuitem: null, domsupport: document.all || document.getElementById, standardbody: null, iframeshimadded: false, revealtimers: {},

getposOffset:function(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	//alert(what.offsetLeft);

	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset + 1/*+parentEl.offsetLeft*/ : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
},

css:function(el, targetclass, action){
	var needle=new RegExp("(^|\\s+)"+targetclass+"($|\\s+)", "ig")
	if (action=="check")
		return needle.test(el.className)
	else if (action=="remove")
		el.className=el.className.replace(needle, "")
	else if (action=="add" && !needle.test(el.className))
		el.className+=" "+targetclass
},

showmenu:function(dropmenu, e){
	if (this.enablereveal[0]){
		if (!dropmenu._trueheight || dropmenu._trueheight<10)
			dropmenu._trueheight=dropmenu.offsetHeight
		clearTimeout(this.revealtimers[dropmenu.id])
		dropmenu.style.height=dropmenu._curheight=0
		dropmenu.style.overflow="hidden"
		dropmenu.style.visibility="visible"
		this.revealtimers[dropmenu.id]=setInterval(function(){cssdropdown.revealmenu(dropmenu)}, 10)
	}
	else{
		dropmenu.style.visibility="visible"
	}
	this.css(this.asscmenuitem, "selected", "add")
},

revealmenu:function(dropmenu, dir){
	var curH=dropmenu._curheight, maxH=dropmenu._trueheight, steps=this.enablereveal[1]
	if (curH<maxH){
		var newH=Math.min(curH, maxH)
		dropmenu.style.height=newH+"px"
		dropmenu._curheight= newH + Math.round((maxH-newH)/steps) + 1
	}
	else{ //if done revealing menu
		dropmenu.style.height="auto"
		dropmenu.style.overflow="hidden"
		clearInterval(this.revealtimers[dropmenu.id])
	}
},

clearbrowseredge:function(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=document.all && !window.opera? this.standardbody.scrollLeft+this.standardbody.clientWidth-15 : window.pageXOffset+window.innerWidth-15
		var dropmenuW=this.dropmenuobj.offsetWidth
		if (windowedge-this.dropmenuobj.x < dropmenuW)  //move menu to the left?
			edgeoffset=dropmenuW-obj.offsetWidth
	}
	else{
		var topedge=document.all && !window.opera? this.standardbody.scrollTop : window.pageYOffset
		var windowedge=document.all && !window.opera? this.standardbody.scrollTop+this.standardbody.clientHeight-15 : window.pageYOffset+window.innerHeight-18
		var dropmenuH=this.dropmenuobj._trueheight
		if (windowedge-this.dropmenuobj.y < dropmenuH){ //move up?
			edgeoffset=dropmenuH+obj.offsetHeight
			if ((this.dropmenuobj.y-topedge)<dropmenuH) //up no good either?
				edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
		}
	}
	return edgeoffset
},

dropit:function(obj, e, dropmenuID){
	if (this.dropmenuobj!=null) //hide previous menu
		this.hidemenu() //hide menu
	this.clearhidemenu()
	this.dropmenuobj=document.getElementById(dropmenuID) //reference drop down menu
	this.asscmenuitem=obj //reference associated menu item
	this.showmenu(this.dropmenuobj, e)
	this.dropmenuobj.x=this.getposOffset(obj, "left")
	this.dropmenuobj.y=this.getposOffset(obj, "top")
	this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
	this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
	this.positionshim() //call iframe shim function
},

positionshim:function(){ //display iframe shim function
	if (this.iframeshimadded){
		if (this.dropmenuobj.style.visibility=="visible"){
			this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
			this.shimobject.style.height=this.dropmenuobj._trueheight+"px"
			this.shimobject.style.left=parseInt(this.dropmenuobj.style.left)+"px"
			this.shimobject.style.top=parseInt(this.dropmenuobj.style.top)+"px"
			this.shimobject.style.display="block"
		}
	}
},

hideshim:function(){
	if (this.iframeshimadded)
		this.shimobject.style.display='none'
},

isContained:function(m, e){
	var e=window.event || e
	var c=e.relatedTarget || ((e.type=="mouseover")? e.fromElement : e.toElement)
	while (c && c!=m)try {c=c.parentNode} catch(e){c=m}
	if (c==m)
		return true
	else
		return false
},

dynamichide:function(m, e){
	if (!this.isContained(m, e)){
		this.delayhidemenu()
	}
},

delayhidemenu:function(){
	this.delayhide=setTimeout("cssdropdown.hidemenu()", this.disappeardelay) //hide menu
},

hidemenu:function(){
	this.css(this.asscmenuitem, "selected", "remove")
	this.dropmenuobj.style.visibility='hidden'
	this.dropmenuobj.style.left=this.dropmenuobj.style.top="-1000px"
	this.hideshim()
},

clearhidemenu:function(){
	if (this.delayhide!="undefined")
		clearTimeout(this.delayhide)
},

addEvent:function(target, functionref, tasktype){
	if (target.addEventListener)
		target.addEventListener(tasktype, functionref, false);
	else if (target.attachEvent)
		target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});
},

startchrome:function(){
	if (!this.domsupport)
		return
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body
	for (var ids=0; ids<arguments.length; ids++){
		var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
		for (var i=0; i<menuitems.length; i++){
			if (menuitems[i].getAttribute("rel")){
				var relvalue=menuitems[i].getAttribute("rel")
				var asscdropdownmenu=document.getElementById(relvalue)
				this.addEvent(asscdropdownmenu, function(){cssdropdown.clearhidemenu()}, "mouseover")
				this.addEvent(asscdropdownmenu, function(e){cssdropdown.dynamichide(this, e)}, "mouseout")
				this.addEvent(asscdropdownmenu, function(){cssdropdown.delayhidemenu()}, "click")
				try{
					menuitems[i].innerHTML=menuitems[i].innerHTML+" "+this.dropdownindicator
				}catch(e){}
				this.addEvent(menuitems[i], function(e){ //show drop down menu when main menu items are mouse over-ed
					if (!cssdropdown.isContained(this, e)){
						var evtobj=window.event || e
						cssdropdown.dropit(this, evtobj, this.getAttribute("rel"))
					}
				}, "mouseover")
				this.addEvent(menuitems[i], function(e){cssdropdown.dynamichide(this, e)}, "mouseout") //hide drop down menu when main menu items are mouse out
				this.addEvent(menuitems[i], function(){cssdropdown.delayhidemenu()}, "click") //hide drop down menu when main menu items are clicked on
			}
		} //end inner for
	} //end outer for
	/*if (this.enableiframeshim && document.all && !window.XDomainRequest && !this.iframeshimadded){ //enable iframe shim in IE5.5 thru IE7?
		document.write('<IFRAME id="iframeshim" src="about:blank" frameBorder="0" scrolling="no" style="left:0; top:0; position:absolute; display:none;z-index:90; background: transparent;"></IFRAME>')
		this.shimobject=document.getElementById("iframeshim") //reference iframe object
		this.shimobject.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)'
		this.iframeshimadded=true
	}*/
} //end startchrome

}
