this.focus();

function printerFriendly(urlToOpen) {
	var x = (screen.width-600)/2, y = (screen.height-500)/2;
	OpenWin = this.open(urlToOpen, "CtrlWindow", "width=600,height=500,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')){
	
		var expireDate = $('mpPromo').getAttribute('expire');
		if(expireDate != 0) {
			Cookie.init({name: 'timex', expires: expireDate});
		} else {
			Cookie.init({name: 'timex'});
		}
		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() { initializeGMap(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);			
	}
	
}

// ### Countdown ###
// Description: displays the amount of time until the "dateFuture" entered below.
// NOTE: the month entered must be one less than current month. ie; 0=January, 11=December
// NOTE: the hour is in 24 hour format. 0=12am, 15=3pm etc
// format: dateFuture = new Date(year,month-1,day,hour,min,sec)
// example: dateFuture = new Date(2003,03,26,14,15,00) = April 26, 2003 - 2:15:00 pm

var timeDictionary = new Array('RO','EN');
timeDictionary['RO'] = new Array('zile', 'ore', 'minute', 'secunde');
timeDictionary['EN'] = new Array('days', 'hours', 'minutes', 'seconds');

function countdownTimer(){
	
	var timerBox = 'countdownTimer';
	var currLang = $(timerBox).readAttribute('currLang');
	var dateFuture = $(timerBox).readAttribute('dateFuture');
	
	if(dateFuture) {
	
		dateFuture = getDateFromFormat(dateFuture, "dd-MM-yyyy HH:mm:ss");
		dateNow = new Date();									//grab current date
		amount = dateFuture.getTime() - dateNow.getTime();		//calc milliseconds between dates
		delete dateNow;

		// time is already past
		if(amount < 0){
			$(timerBox).innerHTML = "Now!";
		}
		// date is still good
		else{
			days=0;hours=0;mins=0;secs=0;out="";

			amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

			days=Math.floor(amount/86400);//days
			amount=amount%86400;

			hours=Math.floor(amount/3600);//hours
			amount=amount%3600;

			mins=Math.floor(amount/60);//minutes
			amount=amount%60;

			secs=Math.floor(amount);//seconds

			// if(days != 0){out += days +" day"+((days!=1)?"s":"")+", ";}
			// if(days != 0 || hours != 0){out += hours +" hour"+((hours!=1)?"s":"")+", ";}
			// if(days != 0 || hours != 0 || mins != 0){out += mins +" minute"+((mins!=1)?"s":"")+", ";}
			// out += secs +" seconds";
			if(days != 0){out += days +" "+ timeDictionary[currLang][0] +", ";}
			if(days != 0 || hours != 0){out += hours +" "+ timeDictionary[currLang][1] +", ";}
			if(days != 0 || hours != 0 || mins != 0){out += mins +" "+ timeDictionary[currLang][2] +", ";}
			out += secs +" "+ timeDictionary[currLang][3];
			$(timerBox).innerHTML = out;

			setTimeout("countdownTimer()", 1000);
		}
		
	}
	
}

// ------------------------------------------------------------------
// getDateFromFormat( date_string , format_string )
//
// This function takes a date string and a format string. It matches
// If the date string matches the format string, it returns the 
// getTime() of the date. If it does not match, it returns 0.
// ------------------------------------------------------------------
function getDateFromFormat(val,format) {
	val=val+"";
	format=format+"";
	var i_val=0;
	var i_format=0;
	var c="";
	var token="";
	var token2="";
	var x,y;
	var now=new Date();
	var year=now.getYear();
	var month=now.getMonth()+1;
	var date=1;
	var hh=now.getHours();
	var mm=now.getMinutes();
	var ss=now.getSeconds();
	var ampm="";
	
	while (i_format < format.length) {
		// Get next token from format string
		c=format.charAt(i_format);
		token="";
		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
			token += format.charAt(i_format++);
			}
		// Extract contents of value based on format token
		if (token=="yyyy" || token=="yy" || token=="y") {
			if (token=="yyyy") { x=4;y=4; }
			if (token=="yy")   { x=2;y=2; }
			if (token=="y")    { x=2;y=4; }
			year=_getInt(val,i_val,x,y);
			if (year==null) { return 0; }
			i_val += year.length;
			if (year.length==2) {
				if (year > 70) { year=1900+(year-0); }
				else { year=2000+(year-0); }
				}
			}
		else if (token=="MMM"||token=="NNN"){
			month=0;
			for (var i=0; i<MONTH_NAMES.length; i++) {
				var month_name=MONTH_NAMES[i];
				if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
					if (token=="MMM"||(token=="NNN"&&i>11)) {
						month=i+1;
						if (month>12) { month -= 12; }
						i_val += month_name.length;
						break;
						}
					}
				}
			if ((month < 1)||(month>12)){return 0;}
			}
		else if (token=="EE"||token=="E"){
			for (var i=0; i<DAY_NAMES.length; i++) {
				var day_name=DAY_NAMES[i];
				if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
					i_val += day_name.length;
					break;
					}
				}
			}
		else if (token=="MM"||token=="M") {
			month=_getInt(val,i_val,token.length,2);
			if(month==null||(month<1)||(month>12)){return 0;}
			i_val+=month.length;}
		else if (token=="dd"||token=="d") {
			date=_getInt(val,i_val,token.length,2);
			if(date==null||(date<1)||(date>31)){return 0;}
			i_val+=date.length;}
		else if (token=="hh"||token=="h") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>12)){return 0;}
			i_val+=hh.length;}
		else if (token=="HH"||token=="H") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>23)){return 0;}
			i_val+=hh.length;}
		else if (token=="KK"||token=="K") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<0)||(hh>11)){return 0;}
			i_val+=hh.length;}
		else if (token=="kk"||token=="k") {
			hh=_getInt(val,i_val,token.length,2);
			if(hh==null||(hh<1)||(hh>24)){return 0;}
			i_val+=hh.length;hh--;}
		else if (token=="mm"||token=="m") {
			mm=_getInt(val,i_val,token.length,2);
			if(mm==null||(mm<0)||(mm>59)){return 0;}
			i_val+=mm.length;}
		else if (token=="ss"||token=="s") {
			ss=_getInt(val,i_val,token.length,2);
			if(ss==null||(ss<0)||(ss>59)){return 0;}
			i_val+=ss.length;}
		else if (token=="a") {
			if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
			else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
			else {return 0;}
			i_val+=2;}
		else {
			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
			else {i_val+=token.length;}
			}
		}
	// If there are any trailing characters left in the value, it doesn't match
	if (i_val != val.length) { return 0; }
	// Is date valid for month?
	if (month==2) {
		// Check for leap year
		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
			if (date > 29){ return 0; }
			}
		else { if (date > 28) { return 0; } }
		}
	if ((month==4)||(month==6)||(month==9)||(month==11)) {
		if (date > 30) { return 0; }
		}
	// Correct hours value
	if (hh<12 && ampm=="PM") { hh=hh-0+12; }
	else if (hh>11 && ampm=="AM") { hh-=12; }
	var newdate=new Date(year,month-1,date,hh,mm,ss);
	//return newdate.getTime();
	return newdate;
}

// ------------------------------------------------------------------
// Utility functions for parsing in getDateFromFormat()
// ------------------------------------------------------------------
function _isInteger(val) {
	var digits="1234567890";
	for (var i=0; i < val.length; i++) {
		if (digits.indexOf(val.charAt(i))==-1) { return false; }
		}
	return true;
}
function _getInt(str,i,minlength,maxlength) {
	for (var x=maxlength; x>=minlength; x--) {
		var token=str.substring(i,i+x);
		if (token.length < minlength) { return null; }
		if (_isInteger(token)) { return token; }
		}
	return null;
}

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(){  }
	});
}

function flashMe(){
	// animate flashMe class
	$$('.flashMe').each(function(el) {
		// new Effect.Pulsate(el, { pulses: 100, duration: 90 });
		new Effect.Pulsate(el, { pulses: 100, duration: 90, from: 0.7, queue: { scope: 'menuxscope' } });
	});
	// $$('.flashMe').each(function(el) {
		// new Effect.Highlight(
			// el, 
			// { startcolor: '#D90001', endcolor: '#EDEDED' }
		// );
	// });
}

//
//	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");
	
	// left side drop down menu
	anylinkcssmenu.trueinit("anchorclass");
	
	// countdown
	countdownTimer();
	
	// promo page
	promoPage();
	
	// flash the items
	flashMe();
	
}

Event.observe(window, 'load', pageInit, false);
