var searchClicked=false;

var nullNameError="Please insert your name";
var nullEmailError="Please insert your email";
var nullQuestionError="Please insert your question";
var invalidEmailError="Please insert a valid email address";

var valid=true;

$(function(){
setSearchInputClickHandler();
validateSendEmailForm();
$('.obfuscated').defuscate();
});


jQuery(function( $ ){
	/**
	 * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option.
	 * @see http://flesler.demos.com/jquery/scrollTo/
	 * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll.
	 */
	
	// The default axis is 'y', but in this demo, I want to scroll both
	// You can modify any default like this
	//$.localScroll.defaults.axis = 'xy';
	
	// Scroll initially if there's a hash (#something) in the url 
	$.localScroll.hash({
		target: '#content', // Could be a selector or a jQuery object too.
		queue:true,
		duration:1500
	});
	
	/**
	 * NOTE: I use $.localScroll instead of $('#navigation').localScroll() so I
	 * also affect the >> and << links. I want every link in the page to scroll.
	 */
	// $.localScroll({
	// 	target: '#content', // could be a selector or a jQuery object too.
	// 	queue:true,
	// 	duration:1000,
	// 	hash:true,
	// 	onBefore:function( e, anchor, $target ){
	// 		// The 'this' is the settings object, can be modified
	// 	},
	// 	onAfter:function( anchor, settings ){
	// 		// The 'this' contains the scrolled element (#content)
	// 	}
	// });
	
	$('.sidebarMenu').localScroll()
});


/**
 *	Removes the text in the search text box when clicked on it.
 */
function setSearchInputClickHandler(){
	$("#searchInput").click(function(){
		if(searchClicked==false){
			this.value='';
			searchClicked=true;
		}
	});
}

/**
 *	Validates the send email form.
 */
function validateSendEmailForm(){
    $("#sendButton").click(function(){
		
		//clear previous messages
		$("#nameError").text("");
		$("#emailError").text("");  
		$("#questionError").text("");  
		valid=true;  
		
		//verify whether the name text box is empty
		if(document.getElementById("nameTextBox").value=="" || document.getElementById("nameTextBox").value==null){
			$("#nameError").text(nullNameError);
			valid=false;
		}
		
		//verify whether the question text area is empty
		if(document.getElementById("questionTextArea").value=="" || document.getElementById("questionTextArea").value==null){
			$("#questionError").text(nullQuestionError);
			valid=false;
		}
		
		//verify whether the inserted email address is valid
		var reg = "/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/";
		var email = document.getElementById("emailTextBox").value;
		if(!(email.indexOf(".") > 2) || !(email.indexOf("@") > 0)) {
			$("#emailError").text(invalidEmailError); 
			valid=false;
		}
		
		//verify whether the email text box is empty
		if(document.getElementById("emailTextBox").value=="" || document.getElementById("emailTextBox").value==null){
			$("#emailError").text(nullEmailError);
			valid=false;
		}

		//if the inserted data is valid, then sumbit the form
		if(valid==true){
			$("#sumbitForm").submit();
		}
    });
}


