// <!-- 
/*
 * IFI Shared JS	
 */
var name_default = "Your name";
var email_default = "Your e-mail";
// 
//	on focus text clear method
//
function checkInputVal(e,d){
	if($(e).val() == d){
		$(e).val("");
		$(e).removeClass('inactive');
	}
	
}
//
//	call ajax script
//
function ajaxCall( _url, _successfunction, _data  ){
	// create data object
	alert(d.serialize());
	return;
	var d = { type:'post', url:_url , success: _successfunction, data:d.serialize() };
	// make ajax call
	ajx_rqst = $.ajax( d );
}
//
//	return msg from signup
//
function sendComplete( response ){
	var sent = new Boolean( response );
	if( sent ){
		// did send
		$('#sent_message').html("<p><strong>Thank you.</strong></p><p>We will keep you updated with the latest news from IFI.</p>");
	}else{
		// didn't send
		$('#sent_message').html("<p><strong>It's not been possible to sign you up.</strong></p><p>Please <a href='/'>try again</a>.</p>");
	}
}
//
//	check signup form is valid and ok to send
//
function checkValid(){
	// check name
	if( !checkMailSafe( $('#your_name').val() ) || $('#your_name').val().length < 3 || $('#your_name').val() == name_default ){
		$('#your_name').focus();
		alert('Please enter your name');
		return false;
	} 
	// check email
	if ( !checkMailSafe( $('#your_email').val() ) || !isEmailAddr( $('#your_email').val() ) || $('#your_email').val() == email_default ){
		$('#your_email').focus();
		alert('Please enter your full email address');
		return false;
	}
	// if ok send to email form
	$.ajax( { type:'post', url: "resources/scripts/sender.php" , success: sendComplete, data: $("#signup form").serialize() } );
	return true;
}
// jQuery init
$( document ).ready(function() { 
	// form validation
	function checkName(){ checkInputVal($(this), name_default); }
	function checkEmail(){ checkInputVal($(this), email_default);}
	// check default name/email not supplied
	if($('#your_name').val() == name_default ){ $('#your_name').addClass('inactive'); }
	if($('#your_email').val() == email_default ){ $('#your_email').addClass('inactive');}
	// set focus clear checker
	$('#your_name').focus( checkName );
	$('#your_email').focus( checkEmail );
	// add send form functionality
	$('#signup form').submit(function(){
		if( checkValid()){
			$('#signup form').slideUp();
			$('#sent_message').html("<p>Sending your information.</p>");
			return false; // return false to stop page refresh
		}
		return false;
	})
});
// -->