this.focus();

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 readFunc(ident){
	var el = $('toggle_' + ident);
	if(el.innerHTML == '<span>detalii...</span>'){
		$('less_' + ident).hide(); 
		Effect.SlideDown('more_' + ident);
		$(el).innerHTML = '<span>ascunde...</span>';
	}else{
		Effect.SlideUp('more_' + ident);
		Effect.SlideDown('less_' + ident);
		$(el).innerHTML = '<span>detalii...</span>';
	}
	return false;
}

function myToggle(myID){
	var el = $(myID);
	if(el.style.display == 'none'){
		el.show();
	} else {
		el.hide();
	}
}

var expandedID = 0;
function emulateAccordion(accordID){
	var myTriggers = $(accordID).select('.accordion_trigger');
	
	myTriggers.each(function(currTrigger){
		var currContent = 'accordion_content_' + currTrigger.getAttribute('triggerID');
		
		currTrigger.observe('click', function(){
			if(currTrigger.getAttribute('triggerID') == expandedID){
				Effect.SlideUp(currContent);
				expandedID = 0;
			} else {
				Effect.SlideDown(currContent);
				if(expandedID){
					var prevContent = 'accordion_content_' + expandedID;
					Effect.SlideUp(prevContent);
				}
				expandedID = currTrigger.getAttribute('triggerID');
			}
		});
		
		$(currContent).hide();
		
	});
}

function setPage(pageID, hInput, formID){
	//alert(pageID);
	$(hInput).value = pageID;
	$(formID).submit();
}

function completeMe(){
	// autocomplete toggle for all elements having completeMe class
	$$('.completeMe').each(function(el) {
		Event.observe(el, 'focus', function(event) {
			if(el.value == el.defaultValue){
				el.value = '';
				if(el.innerHTML)
					el.innerHTML = '';
			}
		});
		Event.observe(el, 'blur', function(event) {
			if(el.value == ''){
				el.value = el.defaultValue;
				if(el.innerHTML)
					el.innerHTML = el.defaultValue;
			}
		});
	});
}

function listen2filters(formID, ajaxThis){
	// listen to an entire form or just some of it's elements for changes that trigger ansubmit/AJAX
	if(ajaxThis){
		var observeThisID = ajaxThis;
	} else {
		var observeThisID = formID;
	}

	var checkboxes = $$('#' + observeThisID + ' input[type=checkbox]');
	checkboxes.each(function(box){
		box.observe('change', function(){
			if(ajaxThis){
				submitMyForm(formID, $(ajaxThis).getAttribute('ajaxResultTo'), $(ajaxThis).getAttribute('ajaxTo'));
			} else {
				$(formID).submit();
			}
		});
	});
	
	var radios = $$('#' + observeThisID + ' input[type=radio]');
	radios.each(function(radio){
		radio.observe('change', function(){
			if(ajaxThis){
				submitMyForm(formID, $(ajaxThis).getAttribute('ajaxResultTo'), $(ajaxThis).getAttribute('ajaxTo'));
			} else {
				$(formID).submit();
			}
		});
	});
	
	var selects = $$('#' + observeThisID + ' select');
	selects.each(function(sele){
		sele.observe('change', function(){
			if(ajaxThis){
				submitMyForm(formID, $(ajaxThis).getAttribute('ajaxResultTo'), $(ajaxThis).getAttribute('ajaxTo'));
			} else {
				$(formID).submit();
			}
		});
	});
	
}

function submitMyForm(formsID, messageDIV, urlOverride, doToolTip) {
	var aVariables = '';
	
	//get data from multiple forms (ids separated by | )
	var formIDs = formsID.split("|");
	formIDs.each(function(formID){
		var currFrmEntries = $(formID).serialize();
		if(aVariables.empty()){
			aVariables = currFrmEntries;
		} else {
			aVariables = aVariables + '&' + currFrmEntries;
		}
	});
	//alert(aVariables);
	
	//if no redirect URL specified, use the first form's action
	if(!urlOverride){
		var formURL = $(formIDs[0]).action;
	} else {
		var baseHref = document.getElementsByTagName('base')[0].href;
		var formURL = baseHref + 'index.html/' + urlOverride;
	}
	//alert(formURL);
	
	new Ajax.Request(formURL, {
		method:'post',
		parameters: {'allVars' : aVariables},
		onSuccess: function(transport){
			//alert(transport.responseText);
			var response = transport.responseXML;
			var iStatus = response.childNodes[0].childNodes[0].firstChild.nodeValue;
			var iMessage = response.childNodes[0].childNodes[1].firstChild.nodeValue;
			var iOption = response.childNodes[0].childNodes[2].firstChild.nodeValue;
			if(iStatus == 'true') {
				if(doToolTip){
					showToolTipFader(iMessage, $(messageDIV));
				} else {
					$(messageDIV).innerHTML = '';
					if($(messageDIV).hasClassName('error')){
						$(messageDIV).removeClassName('error');
						$(messageDIV).addClassName('message');
					}
					$(messageDIV).innerHTML = iMessage;
				}
				//lock the forms
				formIDs.each(function(formID){
					$(formID).disable();
				});
				if(iOption){
					setTimeout("window.location.reload();", iOption);
				}
			}	else {
				if(doToolTip){
					showToolTipFader(iMessage, $(messageDIV));
				} else {
					$(messageDIV).innerHTML = '';
					if($(messageDIV).hasClassName('message')){
						$(messageDIV).removeClassName('message');
						$(messageDIV).addClassName('error');
					}
					$(messageDIV).innerHTML = iMessage;
				}
			}
			if(!doToolTip)
				$(messageDIV).show();
		},
		onFailure: function(error){
			alert('FAIL! ' + error);
		}
	});
}

function resetPagination1(){
	if(proceed){
		var allPages = $('paginare').select('a');
		
		var notFound = true;
		allPages.each(function(mypag){
			//alert(mypag.innerHTML);
			if(mypag.hasClassName('activ') && notFound){
				var currNo = mypag.down();
				mypag.removeClassName('activ');
				if(currNo.innerHTML==3){
					currNo = 1;
				} else {
					currNo = currNo.innerHTML*1 + 1*1;
				}
				$('trigg-' + currNo).addClassName('activ');
				notFound = false;
			}
		});
	} else {
		proceed = true;
	}
	
}

var skipOneReset = false;
function resetPagination2(dir){
	
	if(!skipOneReset && !dir){
		if(dir){
			skipOneReset = true;
		} else {
			var dir = 'fw';
		}
		
		nowPag = $('currPag').innerHTML;
		totalPag = $('totalPag').innerHTML;
		if((dir=='rw') && (nowPag>1)){
			nextPag = nowPag*1-1*1;
		} else if((dir=='fw') && (nowPag<totalPag)) {
			nextPag = nowPag*1+1*1;
		} else if((dir=='rw') && (nowPag==1)){
			nextPag = totalPag;
		} else if((dir=='fw') && (nowPag==totalPag)){
			nextPag = 1;
		}
		
		setTimeout("$('currPag').innerHTML = nextPag;", 10);
	} else {
		skipOneReset = false;
	}
	
}

function resetPagination(triggersContainer, triggersID, totalPag, dir){
	var proceed = $(triggersContainer).readAttribute('onswitch');
	if(proceed == 1){
		// console.log(triggersContainer + ' -- ' + triggersID + ' -- ' + totalPag + ' -- ' + dir + ' -- ' + proceed);
		var allTriggers = $(triggersContainer).select('a.carousel-jumper');
			
		var notFound = true;
		allTriggers.each(function(myTrigger){
			// alert(myTrigger.innerHTML);
			if(myTrigger.hasClassName('activ') && notFound){
				var currPag = myTrigger.readAttribute('carouselcounter');
				var nextPag = 0;
				myTrigger.removeClassName('activ');
				
				if(dir){
					if((dir=='rw') && (currPag>1)){
						nextPag = currPag*1-1*1;
					} else if((dir=='fw') && (currPag<totalPag)) {
						nextPag = currPag*1+1*1;
					} else if((dir=='rw') && (currPag==1)){
						nextPag = totalPag;
					} else if((dir=='fw') && (currPag==totalPag)){
						nextPag = 1;
					}
				} else {
					if(currPag == totalPag){
						nextPag = 1;
					} else {
						nextPag = currPag*1 + 1*1;
					}
				}
				// console.log(currPag + ' --> ' + nextPag + ' | total: ' + totalPag);
				var tempDOMid = triggersID + '-' + nextPag;
				$(tempDOMid).addClassName('activ');
				notFound = false;
			}
		});
		
	} else {
		// proceed = true;
		$(triggersContainer).setAttribute('onswitch', '1');
	}
	
}

function promoPage() {
	if($('mpPromo')){
	
		Cookie.init({name: 'timex', expires: $('mpPromo').getAttribute('expire')});
		var promoID = $('mpPromo').getAttribute('pID');
		var status = $('mpPromo').getAttribute('status');
		var skipPromo = Cookie.getData('skipPromo' + promoID);
		if((skipPromo != 1) && (status == 'enabled')){
			
			var promoName = $('mpPromo').getAttribute('pName');
			Modalbox.show($('mpPromo').href, {title: promoName, width: 780, height: 575, afterLoad: function() { Modalbox.resizeToContent(); } });
			Cookie.setData('skipPromo' + promoID, 1);
			
		}
		
	}
	
}

function initializeGMap(countyAbr, gpsLat, gpsLng, locName) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2($("map_canvas"));
		map.setMapType(G_SATELLITE_MAP);
		map.setCenter(new GLatLng(gpsLat, gpsLng), 15);
		
		var point = new GLatLng(gpsLat, gpsLng);
		map.addOverlay(new GMarker(point));
		map.setUIToDefault();

		var marker = new GMarker(new GLatLng(gpsLat, gpsLng));
		var WINDOW_HTML = '<div style="text-align: center;"><img src="images/lubexpert_logo.gif" _wpro_src="images/logo-final.png" alt="ceva" style="width: 152px;"></div>';
		map.addOverlay(marker);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(WINDOW_HTML);
		});
		marker.openInfoWindowHtml(WINDOW_HTML);
	}
}

function showMap(countyAbr, gpsLat, gpsLng, locName) {
	
	var node = new Element(
							'div', {id: 'map_canvas', style: 'width: 759px; height: 534px; margin: 0px; padding: 0px;'}
						);
	Modalbox.show(node, {title: locName, width: 780, height: 575, afterLoad: function() { initilizeGMap(countyAbr, gpsLat, gpsLng, locName); }});

}

//Cookie front end handler ( extending JS with cookie object - Prototype style)
//based on Jason McCreary creation - http://jason.pureconcepts.net/articles/javascript_cookie_object

/* Example Usage
Cookie that expires 90 days from visit, and sets a value:
    Cookie.init({name: 'yourdata', expires: 90});
    Cookie.setData('favorites', false);

Cookie that only lasts the session, with default data:
    Cookie.init({name: 'mydata'}, {foo: 'bar', x: 0});
    alert(Cookie.getData('foo'));
*/

var Cookie = {
  data: {},
  options: {expires: 1, domain: "", path: "", secure: false},

	init: function(options, data) {
		Cookie.options = Object.extend(Cookie.options, options || {});

		var payload = Cookie.retrieve();
		if(payload) {
			Cookie.data = payload.evalJSON();
		} else {
			Cookie.data = data || {};
		}
		Cookie.store();
	},
	getData: function(key) {
		return Cookie.data[key];
	},
	setData: function(key, value) {
		Cookie.data[key] = value;
		Cookie.store();
	},
	removeData: function(key) {
		delete Cookie.data[key];
		Cookie.store();
	},
	retrieve: function() {
		var start = document.cookie.indexOf(Cookie.options.name + "=");

		if(start == -1) {
				return null;
		}
		if(Cookie.options.name != document.cookie.substr(start, Cookie.options.name.length)) {
				return null;
		}

		var len = start + Cookie.options.name.length + 1;   
		var end = document.cookie.indexOf(';', len);

		if(end == -1) {
				end = document.cookie.length;
		} 
		return unescape(document.cookie.substring(len, end));
	},
	store: function() {
		var expires = '';

		if (Cookie.options.expires) {
			var today = new Date();
			expires = Cookie.options.expires * 86400000;
			expires = ';expires=' + new Date(today.getTime() + expires);
		}

		document.cookie = Cookie.options.name + '=' + escape(Object.toJSON(Cookie.data)) + Cookie.getOptions() + expires;
	},
	erase: function() {
		document.cookie = Cookie.options.name + '=' + Cookie.getOptions() + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
	},
	getOptions: function() {
		return (Cookie.options.path ? ';path=' + Cookie.options.path : '') + (Cookie.options.domain ? ';domain=' + Cookie.options.domain : '') + (Cookie.options.secure ? ';secure' : '');      
	}
};

function updateStrength(pw) {
	var strength = getStrength(pw);
	var width = (100/32)*strength;
	new Effect.Morph('psStrength', {style:'width:'+width+'px', duration:'0.4'}); 
}

function getStrength(passwd) {
	intScore = 0;
	if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
		{
		intScore = (intScore+1)
		}
	if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
		{
		intScore = (intScore+5)
		} // NUMBERS
	if (passwd.match(/\d+/)) // [verified] at least one number
		{
		intScore = (intScore+5)
		}
	if (passwd.match(/(\d.*\d.*\d)/)) // [verified] at least three numbers
		{
		intScore = (intScore+5)
		} // SPECIAL CHAR
	if (passwd.match(/[!,@#$%^&*?_~]/)) // [verified] at least one special character
		{
		intScore = (intScore+5)
		}
	if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/)) // [verified] at least two special characters
		{
		intScore = (intScore+5)
		} // COMBOS
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/)) // [verified] both upper and lower case
		{
		intScore = (intScore+2)
		}
	if (passwd.match(/\d/) && passwd.match(/\D/)) // [verified] both letters and numbers
		{
		intScore = (intScore+2)
		} // [Verified] Upper Letters, Lower Letters, numbers and special characters
	if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(/\d/) && passwd.match(/[!,@#$%^&*?_~]/))
		{
		intScore = (intScore+2)
		}
	return intScore;
}

// tooltip
//end browser user
var globalTimeout = "";
function showToolTipFader(texty,obj,doNotCloseAfter) {	
	
	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);			
	}
	
}

function setupShareLinks(el) {
	var baseHref = document.getElementsByTagName('base')[0].href;
	var ajaxTo = baseHref + 'index.html' + '/mainpage|getShortUrl';
	
	var icon = el.down('img');
	icon.setAttribute('data-orig-src', icon.getAttribute('src'));
	icon.setAttribute('src', 'images/butoane/r0.gif');

	new Ajax.Request(ajaxTo,  {
		method:'post',
		parameters: {'url': escape(window.location.href) },
		onSuccess: function(transport){
			var shareLinks = el.up('div').select('a.shareLink');
			shareLinks.each(function(shareLink) {
				shareLink.setAttribute('href', shareLink.href + transport.responseText);
				shareLink.setAttribute('onclick', ';');
			});

			icon.setAttribute('src', icon.getAttribute('data-orig-src'));

		},
		onFailure: function(){  }
	});
}

//
//	fire all js here on page load
//
function pageInit() {
	
	// autocomplete all input fields that have class completeMe with their default value
	completeMe();
	
	// top drop down menu
	cssdropdown.startchrome("chromemenu");
	
	// promo page
	// promoPage();
	
}

Event.observe(window, 'load', pageInit, false);
