function validEmail(email) {
	var regEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if(email.match(regEmail)){
		return true;
	}else{
		return false;
	}
}
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function isInternetExplorer(){
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		return true;
 	else
		return false;
}

/*FONT SIZE*/
function changeFontSize(size, id) { 
	if ($('intro')) {
		$('intro').style.fontSize = size+"px";
	}
	if (id!='fontSmall') $('fontSmall').className='buttonSmall';
	if (id!='fontBig') $('fontBig').className='buttonSmall';
	if (id!='fontNormal') $('fontNormal').className='buttonSmall';
	$(id).className='';
}

/*PRINT PAGE*/
function printPage() {
	$('boxContainer').style.background = 'none';
	$('mainContainer').style.background = 'none';
	$('footerContainer').style.background = 'none'; 
}

/*RESIZE*/
function Resize() { 
	if(window.getWidth()<974){
		$('boxContainer').style.backgroundPosition = '-34px 353px';
		$('mainContainer').style.backgroundPosition = '-34px top';
		$('footerContainer').style.backgroundPosition = '-34px top'; 
		$('boxContainer').style.width="974px";
		$('mainContainer').style.width="974px";
		$('footerContainer').style.width="974px";
		if (Browser.Engine.trident && getInternetExplorerVersion() < 8) {
			document.body.style.overflow="";
		}
	}else{
		$('boxContainer').style.backgroundPosition = 'center 353px';
		$('mainContainer').style.backgroundPosition = 'center top';
		$('footerContainer').style.backgroundPosition = 'center top'; 
		if (Browser.Engine.trident && getInternetExplorerVersion() < 8) {
			document.body.width="100%";
			document.body.className='takeAll';
			document.body.style.overflow="hidden";
		}
		$('boxContainer').style.width="100%";
		$('mainContainer').style.width="100%";
		$('footerContainer').style.width="100%";	
	}
}

/*TAB*/
function changeTabOpacity(element,duration){
	$(element).set('opacity','0');
	var myEffects = new Fx.Morph(element, {
		duration: duration
	});
	myEffects.start({
		'opacity': [0, 1],
		'margin-left': [-$(element).scrollWidth, 0]     
		//'margin-top': [-$(element).scrollHeight, 0]
	});
}

function activeTab(id, tabsTitleId) {
	$$('#tabs_title'+tabsTitleId+' td').each(function(element,index) { 
		element.className = "inactive";
	})
	$$('#tabs_panel_container div').each(function(element,index) { 
		if (element.className.search("tabs_panel")>=0) 
			element.className = "tabs_panel takeAll";
	})
	$(id).className = "tabs_panel_active takeAll";
	changeTabOpacity(id, delayDaNonPerdere);
}

/*CUSTOM SELECT*/
function hideSelect(id,img) {
	//$(img).src = $(img).src.replace("_a.png",".png");
	$(img).className = $(img).className.replace("selectionHover","selection");
	$(id).setStyle('display', 'none');
}

function showSelect(id,img) {
	//$(img).src = $(img).src.replace(".png","_a.png");
	$(img).className = $(img).className.replace("selection","selectionHover");
	$(id).setStyle('display', 'block');
}

function displaySelect(id,img) {
	if ($(id).style.display=='block'){
		//hideSelect(id,img);
		setTimeout("hideSelect('"+id+"','"+img+"');",100);
	}else{
		//showSelect(id,img);
		setTimeout("showSelect('"+id+"','"+img+"');",100);
	}
}

function createSelect(parent,id,img,html,imgBottom,addToTop){
	profile = new Element('div').addClass('abs').injectInside($('extrasArea')); 
	profile.set('id', id);
	profile.set('class', 'customSelect');
	profile.setStyle('top', $(parent).offsetTop+74+addToTop+'px');
	if ($('extrasArea').scrollWidth > 300)
		profile.setStyle('left', '693px');
	else	
		profile.setStyle('left', '728px');
	//space = $('extrasArea').offsetLeft+$(img).offsetLeft; //8x2 margin
	//profile.setStyle('left', space+'px');
	profile.setStyle('display', 'block');
	inner = new Element('div').addClass('select takeAll').injectInside(profile);	
	
	image = new Element('div').injectInside(profile);
	if (imgBottom.search(".gif")>0 || imgBottom.search(".jpg")>0 || imgBottom.search(".png")>0) {
		image.className = "takeAll max";
		innerImage = new Element('img').injectInside(image);
		innerImage.src = imgBottom;
	}else{
		image.className = "takeAll max "+imgBottom;
	}
	image.set('text',' ');
	
	$(html).injectInside(inner);
	//$(img).src = $(img).src.replace(".png","_a.png");
	$(img).className = $(img).className.replace("selection","selectionHover");
	
	window.addEvent('domready', function() {
		document.body.addEvents({'click': function(){  
			if ($(id)) {
				if ($(id).style.display=='block'){
					//$(img).src = $(img).src.replace("_a.png",".png")
					$(img).className = $(img).className.replace("selectionHover","selection");
					$(id).setStyle('display', 'none');
				}
			}
		}});
	});
	
}

function toggleSelect(parent,id,img,html,imgBottom,addToTop){
	if ($(id)) {
		displaySelect(id,img);
		//setTimeout("displaySelect('"+id+"','"+img+"');",100);
	}else{	
		if (!addToTop) addToTop = 0; 
		setTimeout("createSelect('"+parent+"','"+id+"','"+img+"','"+html+"','"+imgBottom+"',"+addToTop+");",100);
	}
}

/*GOOGLE MAP*/
function createMap(id,lat,lng,zoom,mapTypeId) {
	var map = new google.maps.Map(document.getElementById(id), {
		center: new google.maps.LatLng(lat, lng),
		zoom: zoom,
		mapTypeId: mapTypeId
	});
	return map
}

function createMarker(lat,lng,map,type,html) {
	var icon = customIcons[type] || {};
	var latlng = new google.maps.LatLng(lat, lng);
	marker = new google.maps.Marker({				
		position: latlng,
		map: map,  
		draggable: false
		,icon: icon.icon
		//,shadow: icon.shadow
	});
	if (html!="") {
		bindInfoWindow(marker, map, infoWindow, html);	
		//customInfoWindow(marker, map, infoWindow, html);
	}		
	addMarker(marker,type);
	bounds.extend(latlng);
}

function createCustomMarker(lat,lng,map,type,html,show) {
	var icon = customIcons[type] || {};
	var latlng = new google.maps.LatLng(lat, lng);
	marker = new google.maps.Marker({				
		position: latlng,
		map: map,  
		draggable: false
		,icon: icon.icon
		//,shadow: icon.shadow
	});
	if (html!="") {
		//bindInfoWindow(marker, map, infoWindow, html);	
		customInfoWindow(marker, map, html,show);
	}		
	addMarker(marker,type);
	bounds.extend(latlng);
}

function openFirst(marker, map) {
	infoBox.open({latlng: marker.getPosition(), map: map, html: firstHtml, number:false, show:true});
}

function customInfoWindow(marker, map, html, show) {	
	//if (show ) setTimeout("openFirst("+marker+", "+map+", "+html+");",3000);
	google.maps.event.addListener(marker, 'click', function() {
		infoBox.open({latlng: marker.getPosition(), map: map, html: html, number:false, show:show});
	});
}

function bindInfoWindow(marker, map, infoWindow, html) {
	google.maps.event.addListener(marker, 'click', function() {
		infoWindow.setContent(html);
		infoWindow.open(map, marker);
	});
}

function hideMarkers(type) {
	if(infoWindow) {
	  infoWindow.close();
	}
	if (markersArray) {
		for (i=0; i<markersArray.length; i++) {					
			if (markersArray[i].type == type) {					
				//markersArray[i].marker.setMap(null);
				markersArray[i].marker.setVisible(false);
			}
		}
	}
}

function showMarkers(type, map) {
	if (markersArray) {
		for (i=0; i<markersArray.length; i++) {
			if (markersArray[i].type == type) {
				//markersArray[i].marker.setMap(map);
				markersArray[i].marker.setVisible(true);
			}
		}
	}
}

function addMarker(marker, type) {
	if (markersArray) {
		var markerObject = new Object();
		markerObject.marker = marker;
		markerObject.type = type;				
		markersArray.push(markerObject);
		markersClu.push(marker);
	}
}

function initialize(lat,lng,zoom,type,googleMapId) {
	var latlng = new google.maps.LatLng(lat,lng);
	var myOptions = {
		zoom: zoom,
		center: latlng,
		mapTypeId: type
	};
	return map = new google.maps.Map(document.getElementById(googleMapId), myOptions);
}

function readOptions(jsonStr){
	
	var jsonObj = eval("(" + jsonStr + ")");
	return {
		zoom: parseInt(jsonObj.zoom),
  		center: new google.maps.LatLng(jsonObj.lat, jsonObj.lng),
  		mapTypeId: jsonObj.mapTypeId
	};
}

function formSubmit(formName){
	if (Browser.Engine.trident && getInternetExplorerVersion() < 8) {
		eval("document."+formName+".submit();");
	}else{
		$(formName).submit();
	}
}

function changeToken(idToUpdate, url, token) {
	var req = new Request.HTML({url:url, 
		onSuccess: function(html) {
			$(idToUpdate).set('text', '');
			$(idToUpdate).empty().adopt(html);
		}
	});
	req.get({'ajax': 'true', 'randomToken': token});
}

function randomToken(){
	var random = "" + Math.random();
    random = random.replace("0.","");
    return random;
}

function getCookie(c_name){
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++){
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) {
    		return unescape(y);
    	}
	}
}

function setCookie(c_name,value,exdays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
