function ValidateSubscription(){
	var counter=0;
	$('#ServerResp').hide();
		
	
	if($.trim($('#firstName').val())==''){
	$('#FNameErr').html("<img  class='form_info_icon' src='"+base_url+"images/warn.gif' onmouseover='showFloatDesc(\"Enter your first name\")'  onmousemove='moveFloatDesc( event )' onmouseout='hideFloatDesc()'> ");
		$('#FNameErr').show();
		counter++;
	}else{
		$('#FNameErr').hide();
	}
	
	if($.trim($('#lastName').val())==''){
	$('#LNameErr').html("<img  class='form_info_icon' src='"+base_url+"images/warn.gif' onmouseover='showFloatDesc(\"Enter your last name\")'  onmousemove='moveFloatDesc( event )' onmouseout='hideFloatDesc()'> ");
		$('#LNameErr').show();
		counter++;
	}else{
		$('#LNameErr').hide();
	}
	
	if($.trim($('#userEmail').val())=='')
	{
		$('#MailErr').html("<img  class='form_info_icon' src='"+base_url+"images/warn.gif' onmouseover='showFloatDesc(\"Enter Email ID\")'  onmousemove='moveFloatDesc( event )' onmouseout='hideFloatDesc()'> ");
		$('#MailErr').show();
		counter++;
	}
	else if(!validateEmail($.trim($('#userEmail').val()))){
		$('#MailErr').html("<img  class='form_info_icon' src='"+base_url+"images/warn.gif' onmouseover='showFloatDesc(\"Enter Valid Email ID\")'  onmousemove='moveFloatDesc( event )' onmouseout='hideFloatDesc()'> ");
		$('#MailErr').show();
		counter++;
	}
	else{
		$('#MailErr').hide();
	}	
	
	if(counter>0){
		return false;	
	}else{
		return true;	
	}
}
//=================
function setupAjaxForm(form_id, form_validations){
	var form = '#' + form_id;
	var form_message = '#register-message';
	
	// en/disable submit button
	
	var disableSubmit = function(val){
		$(form + ' input[type=image]').attr('disabled', val);
	};
	
	// setup loading message
	$(form).ajaxSend(function(){
		//$(form_message).removeClass().addClass('loading').html('Loading...').fadeIn();
	});
	
	// setup jQuery Plugin 'ajaxForm' 	
	var options = {
		dataType:  'json',
		beforeSubmit: function(){
			// run form validations if they exist
			if(!ValidateSubscription()){
				return false;	
			}
			if(typeof form_validations == "function" && !form_validations()) {
				// this will prevent the form from being subitted
				return false;
			}
			disableSubmit(true);
		},
		success: function(json){
			$(form_message).hide();
			$(form_message).removeClass().addClass(json.type).html(json.message).fadeIn('slow');
			disableSubmit(false);
			if(json.type == 'success')
				$(form).clearForm();
		}
	};
	$(form).ajaxForm(options);
}

$(document).ready(function() {  
    new setupAjaxForm('subscribeUser');
});

//==============Email Validation
function validateEmail(email){
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}//end function
