$(document).ready(function() {
	var imgs	=	{
					'step1':'/assets/img/cvStep1.gif' ,
					'step2': '/assets/img/cvStep2.gif',
					'step3':'/assets/img/cvStep3.gif'
					};
	var stage = 1;
	$('#step').html('<img src="'+imgs.step1+'" />');
	if ($('tr.step2').length > 0)
	{
		$('tr.step2').css({'display':'none'});
		$('#ss_submit2').click(function(){
			$('#inputName').val(stripSpaces($('#inputName').val()));
			$('#inputEmail').val(stripSpaces($('#inputEmail').val()));
			var inputname = stripSpaces($('#inputName').val());
			var inputemail = stripSpaces($('#inputEmail').val());
			if (stage == 1)
			{
				if ($('#selectCountry').val() == '')
				{
					$.prompt(countryErr);
					return false;
				}
				if ($('#selectPos').val() == '')
				{
					$.prompt(posErr);
					return false;
				}
				$('tr.step1').css({'display':'none'});
				$('tr.step2').css({'display':'block'});
				$('#step').html('<img src="'+imgs.step2+'" />');
				stage = 2;
				
				return false;
			}
			if (stage == 2)
			{
				if (inputname == '')
				{
					$('#inputName').val('');
					$.prompt(nameErr);
					return false;
				}
				if (inputemail == '')
				{
					$('#inputEmail').val('');
					$.prompt(emailErr);
					return false;
				}
				$(this).parents('form').submit();
				return false;
			}
			return false;
		});
	}
	else
	{
		$('#step').html('<img src="'+imgs.step3+'" />');
		$('#contractlocal , #contractabroad' ).css({"display":'none'});
		
		$('.tablinks li')
			.hover(function () {
				$(this).css({"cursor":"pointer"});
				})
			.click(function(){
				var $this = $(this);
				var section = $this.parents('.section');
				section.children('div:not(#expfilter)').css({"display":'none'});
				$this.siblings('li').removeClass('here');
				$this.addClass('here');
				$('#'+$this.attr('id').replace('-tab','')).css({"display":'block'});
			});
	}
	if ($('li.exp-2,li.exp-3,li.exp-4').length > 0)
	{
		var $exp2 = $('li.exp-2');
		var $exp3 = $('li.exp-3');
		var $exp4 = $('li.exp-4');
		$('#expfilter').css({"display":"block"});
		if ($exp2.length > 0)
		{
			$default = $exp2;
		}
		else if ($exp3.length > 0)
		{
			$default = $exp3;
		}
		else
		{
			$default = $exp4;
		}
		$('li.exp-2,li.exp-3,li.exp-4').hide();
		$default.show();
		var expIDre = new RegExp(/(.*)\-(\d)(.*)?/g);
		var expID = $default.attr('class').replace(expIDre,"$2");
		$('a#expfilter-'+expID).addClass('grey');
		
		$('#expfilter a').click(function(){
			var $this = $(this);
			if(!$this.hasClass('grey'))
			{
				var texpID = $(this).attr('id').replace(expIDre,"$2");
				$('#expfilter a').removeClass('grey');
				$(this).addClass('grey');
				$('li.exp-2,li.exp-3,li.exp-4').hide();
				$('li.exp-'+texpID).show();
			}
			return false;
		});
	}
	
	
});

function stripSpaces(str) {
    while (str.substring(0,1) == ' ') str = str.substring(1);
    while (str.substring(str.length-1,str.length) == ' ') str = str.substring(0,str.length-1);
    return str
}

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
}
