this.focus();

function show_flash(id) {
	document.getElementById(id).outerHTML = document.getElementById(id).outerHTML;
}

function printerFriendly(urlToOpen) {
		var x = (screen.width-750)/2, y = (screen.height-600)/2;
	  OpenWin = this.open(urlToOpen, "CtrlWindow", "width=750,height=600,toolbar=no,menubar=yes,location=no,scrollbars=yes,resizable=no, screenX="+x+", screenY="+y+", left="+x+", top="+y);
}

function recommend(urlRecommandForThisArticle) {
		var x = (screen.width-400)/2, y = (screen.height-300)/2;
	  OpenWin = this.open(urlRecommandForThisArticle, "CtrlWindow", "width=400,height=400,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no, screenX="+x+", screenY="+y+", left="+x+", top="+y);
}

function gE(el) {
		return document.getElementById(el);
}

//end browser user
var globalTimeout = "";
function showToolTipFader(texty,obj,doNotCloseAfter) {	
	obj = $(obj);

	if($('tooltipX')) {
		document.body.removeChild($('tooltipX'));		
		window.clearTimeout(globalTimeout);	
	}
	
	var newdiv = document.createElement('div');
	newdiv.id="tooltipX";
	newdiv.style.display = "none";
	
	//generating table inside div
	if(document.all) {
		var tbl = document.createElement('<table cellpadding=0 cellspacing=0 border=0>');	
		var tbb = document.createElement("tbody");	
	} else {
		var tbl = document.createElement('table');		
		var tbb = document.createElement("tbody");	
		
		tbl.setAttribute('cellpadding','0');
		tbl.setAttribute('cellspacing','0');
		tbl.setAttribute('border','0');
	}	
	
	
	// create up arrow td
		var row = document.createElement('tr');
			
			if(document.all)
				var cell = document.createElement('<td colspan=3>');
			else 
				var cell = document.createElement('td');	
			cell.setAttribute('colspan','3');
				//create img
				 var nimg = document.createElement('img');
				 if(document.all)
				 	nimg.src="images/pop-up/sageata_sus.gif";
				 else	
				 	nimg.src="images/pop-up/sageata_sus.png";
				 nimg.className="tooltipUpArrow";	
				 nimg.id = "toolArrowU";
				 			 
			cell.appendChild(nimg);			
		row.appendChild(cell);		
	tbb.appendChild(row);
	//end create up arrow td
		
	//create top tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipCorner_ul";
		row.appendChild(cell);		
		
		
			var cell = document.createElement('td');
			cell.className="tooltipBar_u";
		row.appendChild(cell);
		
		
			var cell = document.createElement('td');
			cell.className="tooltipCorner_ur";
		row.appendChild(cell);
	tbb.appendChild(row);
	//end create top tooltip
	
	if(doNotCloseAfter) {
		var imgClose = "<img src='images/pop-up/icon-close.gif' style='cursor:pointer;float:right; top:-10px;' onClick=\"hidePopup();\"/><b>Detaliu utilizator</b>";
	//create close tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipBar_l";
		row.appendChild(cell);
		
			var cell = document.createElement('td');
			cell.className="tooltipText";
			cell.innerHTML=imgClose;
		row.appendChild(cell);
				
			var cell = document.createElement('td');
			cell.className="tooltipBar_r";
		row.appendChild(cell);
	tbb.appendChild(row);	
	//end close tooltip		
	}

	//create middle tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipBar_l";
		row.appendChild(cell);
		
			var cell = document.createElement('td');
			cell.className="tooltipText";			
			cell.innerHTML=texty;
		row.appendChild(cell);
				
			var cell = document.createElement('td');
			cell.className="tooltipBar_r";
		row.appendChild(cell);
	tbb.appendChild(row);	
	//end middle tooltip	
	
	//create bottom tooltip
		var row = document.createElement('tr');
			var cell = document.createElement('td');
			cell.className="tooltipCorner_bl";
		row.appendChild(cell);		
		
		
			var cell = document.createElement('td');
			cell.className="tooltipBar_b";
		row.appendChild(cell);
		
		
			var cell = document.createElement('td');
			cell.className="tooltipCorner_br";
		row.appendChild(cell);
	tbb.appendChild(row);
	//end create bottom tooltip
	
	// create down arrow td
		var row = document.createElement('tr');
			
			if(document.all)
				var cell = document.createElement('<td colspan=3>');
			else 
				var cell = document.createElement('td');	
			cell.setAttribute('colspan','3');
				//create img
				 var nimg = document.createElement('img');
				 if(document.all)
				 	nimg.src="images/pop-up/sageata_jos.gif";
				 else	
				 	nimg.src="images/pop-up/sageata_jos.png";
				 nimg.className="tooltipDownArrow";	
				 nimg.id = "toolArrowD";
				 			 
			cell.appendChild(nimg);			
		row.appendChild(cell);		
	tbb.appendChild(row);
	//end create down arrow td
	
	tbl.appendChild(tbb);
	newdiv.appendChild(tbl);
	
	newdiv.className ="tooltipDiv";
	
	//add tooltip to document
	document.body.appendChild(newdiv);
	
	//position tooltip
	setPopupPosition(obj,newdiv); 
	
	
	Effect.Appear(newdiv.id,{duration:.2});
	
	//set fade out
	if(!doNotCloseAfter)
		globalTimeout = window.setTimeout('Effect.Fade(\'tooltipX\', {duration:.3,from:1.0, to:0.0})',2500);
	
	//========================================	
}

function setPopupPosition(el, x)  {	
				var direction = "up";
        var position = Position.cumulativeOffset(el);
        var scrollY = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        var viewHeight = (navigator.userAgent.toLowerCase().indexOf("safari") != -1 && window.innerHeight) ? window.innerHeight : document.documentElement.clientHeight;
       	x.style.left = position[0]-40 + "px";	
        var popupTop = position[1] + Element.getHeight(el);
        if((popupTop + x.offsetHeight > scrollY + viewHeight) && (position[1] - x.offsetHeight > scrollY)) {
            popupTop = position[1] - x.offsetHeight ;
        }
        if(popupTop > (scrollY + Element.getHeight(x) + 40  + Element.getHeight(el))) {
        	direction="down";
        	$('toolArrowD').style.visibility = "visible";
        } else {
        	$('toolArrowU').style.visibility = "visible";        	
        }
        if(direction == "up")
        	x.style.top = (popupTop+30) + "px";
        else 
        	x.style.top = (popupTop - Element.getHeight(x) - (document.all ? 15 : 25) - Element.getHeight(el)) + "px";
}

function hidePopup() {
	if($('tooltipX')) {
		document.body.removeChild($('tooltipX'));		
		window.clearTimeout(globalTimeout);			
	}
	
}

String.prototype.trim = function() { var _ret = this.replace(/^\s+|\s+$/g, ''); return _ret.replace(/^(\&nbsp\;)+|(\&nbsp\;)+$/g, ''); }



function number_format(a, b, c, d) {
 a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
 e = a + '';
 f = e.split('.');
 if (!f[0]) {
  f[0] = '0';
 }
 if (!f[1]) {
  f[1] = '';
 }
 if (f[1].length < b) {
  g = f[1];
  for (i=f[1].length + 1; i <= b; i++) {
   g += '0';
  }
  f[1] = g;
 }
 if(d != '' && f[0].length > 3) {
  h = f[0];
  f[0] = '';
  for(j = 3; j < h.length; j+=3) {
   i = h.slice(h.length - j, h.length - j + 3);
   f[0] = d + i +  f[0] + '';
  }
  j = h.substr(0, (h.length % 3 == 0) ? 3 : (h.length % 3));
  f[0] = j + f[0];
 }
 c = (b <= 0) ? '' : c;
 return f[0] + c + f[1];
}


//COOKIES
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {		
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) 
			return c.substring(nameEQ.length,c.length);
	}
	return '';
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function checkFeedBack(){
		var fEmail = $('fEmail').value;
		var fMessage = $('fMessage').value;
//		alert(fMessage);
		var baseHref = document.getElementsByTagName('base')[0].href;
		var strError = ''; iType = '';
		if(fEmail.length < 6 || fEmail.indexOf('@') == -1 || fEmail.indexOf('.') == -1){
			strError = 'Emailul introdus este invalid';
			iType = 'fEmail';
		}
		
		if(!strError && fMessage < 3){
			strError = 'Mesajul introdus trebuie sa aiba minim 3 caractere';
			var iType = 'fMessage';
		}
		
		if(!strError)
			new Ajax.Request(baseHref+'index.html/articles|feedback',  {
		    method:'post',    
		    parameters: {'email' : fEmail,  'message' : fMessage},
		    onSuccess: function(transport){
		    		var response = transport.responseText;
		    		Effect.Fade($('feedbackBox'), { 'queue': 'start' });
		    		divTag = new Element('div', { 'id':'feedbackSysMsg', 'class':'errorDiv', 'style':'display:none;'}).update(response);
		    		$('dreapta').insert(divTag);
		    		Effect.Appear($('feedbackSysMsg'), { 'queue': 'end'});
		    },
		    onFailure: function(){  }
		  });	
		else
			showToolTipFader(strError, $(iType));
	}

// var avnetFontSize=12;
// function increaseFontSize(elema) {
	// if(!elema)
		// elema = $('stanga');
	// if(avnetFontSize <= 16) {
	// avnetFontSize++;
	// elema.style.fontSize = avnetFontSize+'px';
	// }
// }
// function decreaseFontSize(elema) {
	// if(!elema)
		// elema = $('stanga');
		
	// if(avnetFontSize >= 10) {
	// avnetFontSize--;
	// elema.style.fontSize = avnetFontSize+'px';
	// }	
// }

function toggleMenu(el, elID){
	createCookie('lastKnownOpenMenuID', elID, 92);
	
	$('left').select('div[id^=my_menu_]').each(function(dEl) {
		new Effect.toggle(dEl, 'blind');
	});
	$('left').select('.toggle').each(function(sEl){
		if(sEl.innerHTML == '-'){
			sEl.innerHTML = '+';
		} else {
			sEl.innerHTML = '-';
		}
	});
	return false;


	if($(el).innerHTML == '-'){
		new Effect.BlindUp($(elID));
		$(el).innerHTML = '+';
	}
	else{
		el.innerHTML = '-';
		new Effect.BlindDown($(elID));
	}		
}

// function toggleMenu(el, elID){
	// new Effect.toggle($(elID), 'blind');
	// if($(el).innerHTML == '-'){
		// $(el).innerHTML = '+';
		// eraseCookie('elID');
	// }
	// else{
		// $(el).innerHTML = '-';
		// createCookie(elID, 1, 92);
	// }
// }

function clearIfDefault(oElem, sDefault, bBluring){
		if (oElem.value.length == 0 && bBluring == 1)
			oElem.value = sDefault;
		else
			if (oElem.value == sDefault)
				oElem.value = '';
	}


//function TMDecider(){
//	lastKnownOpenMenuID = readCookie('lastKnownOpenMenuID');
////	alert('aaa');
//	if(lastKnownOpenMenuID)
//		toggleMenu(document.getElementById(lastKnownOpenMenuID+'_a'), lastKnownOpenMenuID);
//	
//}


//window.onload = setTimeout('TMDecider()', 500);



var map = null;
		
function GetMap(){
 var defaultLocation = new VELatLong(44.388962, 26.121846);
 var pinPoint = null;
 var pinPixel = null;

	map = new VEMap('myMap');
	map.LoadMap(defaultLocation, 17, VEMapStyle.BirdseyeHybrid, false, VEMapMode.Mode2D, true, 1);
	map.Resize();
	AddPin();
}

function AddPin(){
	// Add a new pushpin to the center of the map.
	pinPoint = map.GetCenter();
	map.AddPushpin(pinPoint);
}


function ToggleImage(el, state){
	el.src = (state == 1) ? el.src.replace('.gif', '_on.gif') : el.src.replace('_on.gif', '.gif') ;
}






var shCarousel = Class.create({
	options: {
		pauseOnOver: true
	},

	_index: 0,
	_items: [],
	_maxItemHeight: 100, // default height
	_isOver: false,

	initialize: function (container, items, slideDurationInSeconds) {
		// FIXME:
		// if (! is_array(items))
			// return false;
		// if (! is_defined(container))
			// return false;

		this._items = items;
		
		// items: events + counting
		this._items.each(function(item, key) {
			item.observe(
				'mouseover',
				function(a, b, c) {
					this._isOver = true;

					// console.log('over', a, b, c, this, this.options.pauseOnOver);
				}.bind(this)
			);

			item.observe(
				'mouseout',
				function(a, b, c) {
					this._isOver = false;

					// console.log('out', a, b, c, this);
				}.bind(this)
			);

			// max item height
			if (item.getHeight() > this._maxItemHeight)
				this._maxItemHeight = item.getHeight();

			// hide all but current
			if (key !== this._index) {
				item.hide();
				// console.log('next: hiding', item, key, this);
			}


		}.bind(this));
		
		if (this._items.length > 1) {
			this._index = this._index + 1;
		}

		// set height
		container.setStyle({ 'height' : this._maxItemHeight + 'px'});
		
		// periodicalExecuter
		this._periodicalExecuter = new PeriodicalExecuter(this._periodicalExecuterHdl.bind(this), slideDurationInSeconds);

		// this.next();

	},

	_periodicalExecuterHdl: function() {
		// console.log('_periodicalExecuterHdl', this);
		if (this.options.pauseOnOver && !this._isOver) {
			// console.log('carouselPeriodicalExecuter', this._index);
			this.next();
		}
		else {
			// console.log('carouselPeriodicalExecuter: as fi rulat dar esti over');
		}
	},

	next: function () {
		// hide all but current
		this._items.each(function(item, key) {
			if (key !== this._index) {
				item.fade({duration: 0.4});
				// item.hide();
				// console.log('next: hiding', item, key, this);
			}
			else {
				item.setStyle({ 'height' : this._maxItemHeight + 'px'});
				item.appear({duration: 0.3});
				// console.log('next: showing', item, key, this);
			}
		}.bind(this));

		// increment
		this._index = this._index + 1;

		// reset
		if (this._index === this._items.length) {
			this._index = 0;
		}
	}
});
