// JavaScript Document


$(document).ready(
	function() {
		
		$(".login .btn a").click( function() { 
			$(".login .win").show();
			return false;
		});
		
		$(".login .close").click( function() { 
			$(".login .win").hide();
		});
		
		$(".ico a").hover(function(){
			$(this).children("img").css('margin-top', '-10px');
			},function(){
			$(this).children("img").css('margin-top', '0');
		});
		
		$(".news").hover(function(){
			$(this).children(".news_top").addClass("hover");
			},function(){
			$(this).children(".news_top").removeClass("hover");
		});
		
		
		$(".nav_head").hover(function(){
			$(this).children(".nav_body").show();
			},function(){
			$(this).children(".nav_body").hide();
		});
		
		
		$(".darker").height($(document).height());
		
		
		$(".arrows").click( function() { 
			$(".center_big").hide("slow");
			$(".center").show("slow");
		} );
		
		$(".basket .close").click(function(){
			$(this).parents(".item").animate({ opacity: 'hide' }, "slow");
		});
		
		$(".table tr:nth-child(even)").addClass("chet");
		
		$(".expanded_link").toggle(function(){
			$(this).text("");
			$(this).addClass("close");
			$(".expanded_search").slideDown();
			},function(){
			$(this).text(" ");
			$(this).removeClass("close");
			$(".expanded_search").slideUp();
		});
		
		$(".photo_gallery a").hover(function(){
			$(this).parents(".item").addClass("hover");
			},function(){
			$(this).parents(".item").removeClass("hover");
		});
		
		$(".job_title").click(function(){
		  job_description_id = $(this).attr('id') + '_description';
		  $('#' + job_description_id).toggle();
		});
				
});
	
function email_is_valid(string) {
  return (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
};

function check_subscription_form() {
  var valid = email_is_valid($('#subscribedclient_contactemail').val());
  if(!valid) alert('Inserted email is not valid');
  return valid;
};

function check_contact_form() {
  var valid = email_is_valid($('#contact_contactemail').val());
  if(!valid) alert('Inserted email is not valid');
  return valid;
};

function support_login_to_support() {
	window.location = base_url + 'support';
}

function support_do_login()
{
	var support_login_url = $('#support_form').attr('action');
	var support_login_login = $('#support_login').val();
	var support_login_password = $('#support_password').val();

	var datas = '';
	datas = 'login=' + encodeURI(support_login_login);
	datas += '&password=' + encodeURI(support_login_password);
	datas += '&submit=' + encodeURI('sign in');	

	$.ajax({
		type: "POST",
   		url: support_login_url,
   		data: datas,
   		success: function(response) {
			if(response=='logged in')
			{
				$('#support_message').html('Logged in. Redirecting to support area ...');
				window.setInterval(support_login_to_support, 3000);
			}
			else
			{
				$('#support_message').html('Login or password wrong.');				
			}
   		}
 	});	
};


