window.addEvent('domready', function() {

	//INPUTS GLOBAL
	
	$$('.selectClicker').addEvents({
		'mouseover':function(){
			var id = this.get('id').substr(14);
			$('select_'+id).setStyle('background-position','right bottom');
		},
		'mouseout':function(){
			var id = this.get('id').substr(14);
			$('select_'+id).setStyle('background-position','right top');
		},
		'click':function() {
			var id				= this.get('id').substr(14);
			var parent			= $(this.get('id')).getParents('div');
			var selectCoords	= $(this.get('id')).getCoordinates(parent[1].get('id'));
			var dropState		= $('selectDrop_'+id).getStyle('display');
			if(dropState == 'none')
			{
				var newState = 'block';
			}
			else
			{
				var newState = 'none';
			}
			
			$('selectDrop_'+id).setStyles({
				'display':newState,
				'top':selectCoords.top+selectCoords.height+1,
				'left':selectCoords.left
			});
		}
	});
	$$('a.selectDropOption').addEvents({
		'click':function(){
			var parent		= this.getParent('div');
			var valId		= parent.get('id').substr(11);
			$(valId).set('value',this.get('href'));
			$(parent.get('id')).setStyle('display','none');
			return false;
		}
	});
	
	
	
	if($('retailcountry'))
	{
		$$('a.selectDropOption').addEvents({
			'click':function(){
				getRetailers(this.get('href'));
				return false;
			}
		});
	}
	if($('resellercountry'))
	{
		$$('a.selectDropOption').addEvents({
			'click':function(){
				getResellers(this.get('href'));
				return false;
			}
		});
	}
});

//VALIDATION
function validateForm()
{
	var send = 1;

	$each($$('.inpReq'),function(el){		
		
		var id		= el.get('id');		
		var name	= $(id).get('rel');
		var val		= $(id).value;
		if(val=='')
		{
			send = 0;
			alert(replaceChars('Obligatoriskt fält "'+name+'" måste fyllas i.'));
		}
		else if(id=='email' && val.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
		{
			send=0;
			alert(replaceChars('Mailadressen du har angett är inte korrekt.'));
		}
		else if(id=='distribute' && val=='V\u00E4lj land')
		{
			send=0;
			alert(replaceChars('Välj ett distributionsland.'));
		}

	});
	
	if(send==1)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function replaceChars(str)
{	
	str = str.replace(/ä/, "\u00E4");
	str = str.replace(/å/, "\u00E5");
	str = str.replace(/ö/, "\u00F8");	
	
	str = str.replace(/Ä/, "\u00C4");
	str = str.replace(/Å/, "\u00C5");
	str = str.replace(/Ö/, "\u00D6");
	
	return str;
}