function toggle_expand()
{
	if (!$("#lm_expand").is(':visible')) 
		$("#lm_expand").show("blind", { direction: "vertical" }, 500);
	else 
		$("#lm_expand").hide("blind", { direction: "vertical" }, 500);
}

function selected_menu( m )
{
	$("#m"+m).removeClass("m"+m);	
	$("#m"+m).addClass("m"+m+"_active");	
	if ( m > 3 && m < 8 ) $("#lm_expand").show();	
}


function validateEmail(emailad) 
{
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return true;
	}
	else {
		return false;
	}
}

function tipsheet_check_email( email )
{	
	returnVal = "-1";
	
	$.ajax
	({
		type: "POST",
		url: "ajax/ajax_tipsheet_check_email.php",
		data: "email="+escape(email),
		async: false,
		success: function(msg)
		{
			// debug mode 0 or 1	
			var debug = 0;
			if ( debug == 1 ) alert(msg);
			
			 returnVal = msg;
		},
		error: function(msg) 
		{
            returnVal = "-1";
		}
	});
	
	return returnVal;
}

function add_tipsheet()
{
	// definim variabilele
	var tsFullName = $("#tsFullName").val();
	var tsVenue    = $("#tsVenue").val();
	var tsEmail    = $("#tsEmail").val();
	
	// facem validarile
	if ( tsFullName.lengh == 0 || tsFullName == "" || tsFullName == " " ) 
	{
		inlineMsg("label_name","Please specify your name!",3);
		$("#tsFullName").focus();
		return false;
	}
	
	if ( tsVenue.lengh == 0 || tsVenue == "" || tsVenue == " " ) 
	{
		inlineMsg("label_venue","Please specify venue!",3);
		$("#tsVenue").focus();
		return false;
	}
	
	if ( tsEmail.lengh == 0 || tsEmail == "" || tsEmail == " " ) 
	{
		inlineMsg("label_email","Please specify your email address!",3);
		$("#tsEmail").focus();
		return false;
	}
	
	if ( tsEmail.lengh == 0 || tsEmail == "" || tsEmail == " " ) 
	{
		inlineMsg("label_email","Please specify your email address!",3);
		$("#tsEmail").focus();
		return false;
	}
		
	if ( validateEmail(tsEmail) || tipsheet_check_email( tsEmail ) == "-1") 
	{
		inlineMsg("label_email","Invalid email address!",3);
		$("#tsEmail").focus();
		return false;
	}
	
	if ( tipsheet_check_email( tsEmail ) == "1")
	{
		inlineMsg("label_email","The email address already exists in our DB!",3);
		$("#tsEmail").focus();
		return false;		
	}

	// Ajax
	var sendData = "";
	sendData += "&tsFullName="+escape(tsFullName);
	sendData += "&tsVenue="+escape(tsVenue);
	sendData += "&tsEmail="+escape(tsEmail);

	$.ajax
	({
		type: "POST",
		url: "ajax/ajax_tipsheet_add.php",
		data: sendData,
		async: false,
		success: function(msg)
		{
			// debug mode 0 or 1	
			var debug = 0;
			if ( debug == 1 ) alert(msg);
			
			if (msg == "1")
				 $("#tipsheet_msg").html("Thank you for your interest, your subscription has been saved!");
			else
				$("#tipsheet_msg").html("Your email address already exists in our DB!");

			$("#tipsheet").hide();
			$("#tipsheet_msg").show();
						
		},
		error: function(msg) 
		{
			 $("#tipsheet").hide();
			 $("#tipsheet_msg").html("An error occured while submitting the form, please refresh this window and try again!");
			 $("#tipsheet_msg").show();
		}
	});

}

