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('Required field "'+name+'" needs to be filled in.');
		}
		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('The email address you have provided isn\'t valid, please enter a valid email address.');
		}
		else if(id=='distribute' && val=='Choose a country')
		{
			send=0;
			alert('You must choose a distribution country');
		}

	});
	
	if(send==1)
	{
		return true;
	}
	else
	{
		return false;
	}
}