/*------------------------------------------------------------------
[Global Javascript]

Copyright: Codefor 2009
Client: Fuzion
Project: Fuzion blog
Created by: Adam Foster
Last Updated: 03 - 11 - 09
-------------------------------------------------------------------*/

$j = jQuery.noConflict();

/* When dom is ready ----------------------------------------------*/

$j(document).ready(function(){
	init();	
	screenshots();
	scrollbar();
	form();
});

/* Init -----------------------------------------------------------*/

function init(){
	$j('body').addClass('js');
	$j('a[rel="external"]').attr("target", "_blank");	
}


/* Screenshot lightbox --------------------------------------------*/

function screenshots() {
	$j('#screens li a').lightBox({});	
}


/* Scrollbar-------------------------------------------------------*/

function scrollbar() {
	$j('#news').jScrollPane({showArrows:true, scrollbarWidth:18, arrowSize:19});
}

/* submit form ----------------------------------------------------*/

function form() {
	
	// Cancel form submition, return false
	$j('#emailupdates').submit(function(){
		return false;
	});
	
	
	// Manage submit button click event
	$j("#sign-button").click(function(){
		// Call some function to handle Ajax request
		formAjax();
	});


	function formAjax(){
		var newsE = $j("#email").attr("value");

		$j("#error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		 if(!emailReg.test(newsE)) {	
			$j("#error").html('Please enter a valid email address');
			hasError = true;
			$j("#error").show();
		}


		if(hasError == false) {
			
			jQuery.ajax({
				type: "POST",
				url: "saveform.php",
				dataType: "html",
				data: "newsE=" + newsE,
				success: function(response){
				$j("#searchbox").html("<p id='msg'>" + response + "</p>");
			},
				error: function(){
				$j("#searchbox").html("<p id='msg'>Error occured during Ajax request...</p>");
			}
			});
		
		}
		
	}
	
}

/* Clear text -----------------------------------------------------*/

function clearText(thefield){
	if (thefield.defaultValue==thefield.value){
		thefield.value = "";
	}
}
function replaceText(thefield){
	if (thefield.value == ""){
		thefield.value = thefield.defaultValue;
	}
}
