﻿/**
 * This is the main JS file. It initializes some plugins and contains the functionality
 * for the send email form.
 * 
 * Author: Pexeto
 * http://pexeto.com/
 */
 
ddsmoothmenu.init({
 mainmenuid: "smoothmenu1", //menu DIV id
 orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
 classname: 'ddsmoothmenu', //class added to menu's outer DIV
 //customtheme: ["#1c5a80", "#18374a"],
 contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})

jQuery.ajaxSetup ({  
	cache: false  
});  
 
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 urlToPhp = "http://yourdomain/sendEmail.php";

var valid=true;

jQuery(function(){
 	Cufon.replace('h1');
	Cufon.replace('h2');
	Cufon.replace('h3');
	Cufon.replace('caption');
	Cufon.replace('#header #quote li');
		
	setSearchInputClickHandler();
	validateSendEmailForm();
	
	jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		theme: 'light_rounded' /* light_rounded / dark_rounded / light_square / dark_square */
	});
	
	setInfo();
	
});

//activate the submenu classes//
jQuery(function(){
	//jQuery(".submenu ul").parent().addClass("arrow");
});
jQuery(function(){
	jQuery('a[rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
});
jQuery(function(){
	jQuery('.date-pick').datePicker();

});


jQuery(function(){
	jQuery('#quote').innerfade({
		animationtype: 'fade',
		speed:2000,
		timeout: 6000,
		type: 'sequence',
		containerheight: 'auto',
		runningclass: 'innerfade'
	});
});

/**
 *	Removes the text in the search text box when clicked on it.
 */
function setSearchInputClickHandler(){
	jQuery("#searchInput").click(function(){
		if(searchClicked==false){
			this.value='';
			searchClicked=true;
		}
	});
}

/**
 *	Validates the send email form.
 */
function validateSendEmailForm(){
    jQuery("#sendButton").click(function(){
    
		
		//clear previous messages
		jQuery("#nameError").hide();
		jQuery("#emailError").hide();
		jQuery("#questionError").hide();
		valid=true;  
		
		//verify whether the name text box is empty
		if(document.getElementById("nameTextBox").value=="" || document.getElementById("nameTextBox").value==null){
			jQuery("#nameError").show();
			valid=false;
		}

		//verify whether the question text area is empty
		if(document.getElementById("questionTextArea").value=="" || document.getElementById("questionTextArea").value==null){
			jQuery("#questionError").show();
			valid=false;
		}
		
		//verify whether the inserted email address is valid
		var email = document.getElementById("emailTextBox").value;
		if(!isValidEmailAddress(email)) {
			jQuery("#emailError").show();
			valid=false;
		}
		
		//verify whether the email text box is empty
		if(document.getElementById("emailTextBox").value=="" || document.getElementById("emailTextBox").value==null){
			jQuery("#emailError").show();
			valid=false;
		}
		
		
		
		var name=document.getElementById("nameTextBox").value;
		var question=document.getElementById("questionTextArea").value;

		//if the inserted data is valid, then sumbit the form
		if(valid==true){
			urlToPhp=document.getElementById("url").value;
			var emailToSend=document.getElementById("emailToSend").value;
			
			var dataString = 'name='+ name + '&question=' + question + '&email=' + email + '&emailToSend=' + emailToSend;    

			jQuery.ajax({  
				type: "POST",  
				url: urlToPhp,  
				data: dataString,  
				success: function() {  
				jQuery("label#message").show();
				jQuery("label#message").append("<br/><br/>");
				jQuery("#submitForm").each(function(){
					this.reset();
				});
				}
			}); 
		}
    });
}

/**
 *	Positions the dropdown children of the menu.
 */

function setInfo(){
	jQuery("#portfolio div.portfolioItem").hover(function(){
		var info=jQuery(this).find("div.portfolioItemInfo");	
		info.stop().animate({bottom:"4px"}, 500);
	},
	function(){
		var info=jQuery(this).find("div.portfolioItemInfo");
		info.stop().animate({bottom:"-85px"}, 500);
	});
}
	function isValidEmailAddress(str) {

   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);

}

jQuery(function(){
	jQuery('#Board').change(function(event){
		resetloadUrl();
		loadUrl = loadUrl + "?Board=" + jQuery("#Board").val();
		jQuery("#Place").html("<option>loading...</option>").load(loadUrl); 
	});
});

	function toggleStatus() {
		if (jQuery('#all').is(':checked')) {
			jQuery('#Place').attr('disabled', true);
			jQuery('#Place option').attr('selected', false);
		}
		else {
			jQuery('#Place').removeAttr('disabled');
		}
	}

jQuery(document).ready(function(){
	
	
	resetloadUrl();
	loadUrl = loadUrl + "?Board=" + jQuery("#Board").val() + "&Selected=" + selected;
	jQuery("#Place").html("<option>loading...</option>").load(loadUrl);  
	jQuery("#Place").change(function(){
		jQuery("#Place option.group:selected").live('click', function(){
			var select = jQuery(this).text();
			jQuery(this).attr('selected', false);
			jQuery("#Place option."+select).attr('selected', true);

		});
	});
	
	if (jQuery('#all').is(':checked')) {
		jQuery('#Place').attr('disabled', true);
		jQuery('#Place option').attr('selected', false);
	}
	else {
		jQuery('#Place').removeAttr('disabled');
	}
	
	jQuery("input.#searchInput").each(function() {
		jQuery(this).val(jQuery(this).attr("title"));
		if(jQuery.trim(jQuery(this).val()) == "") jQuery(this).val(jQuery(this).attr("title"));
		
		jQuery(this).focus(function() {
			if(jQuery(this).val() == jQuery(this).attr("title")) jQuery(this).val("");
		})
		.blur(function() {
		  if(jQuery.trim(jQuery(this).val()) == "") jQuery(this).val(jQuery(this).attr("title"));
		});
	});
});

