if ( $('.messages.error').length > 0 ){
      $('body').addClass("errorpage");
}

$(document).ready(function(){

$('#webform-client-form-46').appendTo('.emailinfo_wrapper .info_fetch');
$('#webform-client-form-46').appendTo('.mobileinfo_wrapper .info_fetch');
$('#submitted-textfield').val('MOBILE');
$('#submitted-textfield').each(function() {
var default_value = this.value;
$(this).focus(function(){
 	 if(this.value == default_value){ 
		 this.value = ''; 
		 } 
}); 
$(this).blur(function() { 
		 if(this.value == '') { 
	 	this.value = default_value;
	     }
});
});
$('#edit-submitted-email').val('Enter your email address');
$('#edit-submitted-email').each(function() {
var default_value = this.value;
$(this).focus(function(){
 	 if(this.value == default_value){ 
		 this.value = ''; 
		 } 
}); 
$(this).blur(function() { 
		 if(this.value == '') { 
	 	this.value = default_value;
	     }
});
});
	$("form#mobileform").submit(function() {
       var mobileno= $('#submitted-textfield').attr('value');
	var mobileFilter = /^[.]{0}$|^\d{10,15}$/;
	var mobileFilterUS = /^[.]{0}$|^\d{10}$/;
	var mobileFilterOTHER = /^[.]{0}$|^\d{10,15}$/;
		    if (mobileno.length == 0 ||!mobileFilter.test(mobileno)||!mobileFilterUS.test(mobileno) ||!mobileFilterOTHER.test(mobileno)) {
		
	 		    $('#mobvalmsg').css('display','block');
				$('#submitted-textfield').each(function() {
					$(this).focus(function(){
 	 				if(this.value == ''){ 
		 			 $('#mobvalmsg').css('display','none');
		 			} 
					});
					$(this).blur(function(){
 	 				if(this.value == 'MOBILE'){ 
		 			 $('#mobvalmsg').css('display','none');
		 			} 
					});
				});
				return false;
	 	    }
			
		    //registerForMobile(mobileno);
	 		return false;
	 });

  var emailId="";
	 $("form#emailform").submit(function() {
	        emailId= $('#edit-submitted-email').attr('value');
			
		    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	 	    if (emailId.length == 0 || !filter.test(emailId)) {
	 		    $('#emailvalmsg').css('display','block');
				$('#edit-submitted-email').each(function() {
					$(this).focus(function(){
 	 				if(this.value == ''){ 
		 			 $('#emailvalmsg').css('display','none');
		 			} 
					});
					$(this).blur(function(){
 	 				if(this.value == 'Enter your email address'){ 
		 			 $('#emailvalmsg').css('display','none');
		 			} 
					});
				});
				return false;
	 	    }						
			callAgree();		    
	 		return false;
	 });

});
function agreed(){
				$('.firstbox.hide').hide();
				 emailId= $('#edit-submitted-email').attr('value');				 
				registerForEmail(emailId);
			}
			
			function callAgree(){
				$('.firstbox.hide').show();
			}
var callback_completed = false;

   function registerForMobile (mobileno) {
	

	var script = document.createElement('script');
	script.type = 'text/javascript';
	var src = 'http://sms.wmg.com/sms/register?js=true&mobile='+ mobileno+ '&keywordId=livvifranc&signuptype=any';
	script.src = src;
	try {
		$(".info_fetch").append(script);
	} catch (err) {
	// Skip error as this will be take care by the alertTimeoutError method.
	// alert(err);
	}
	setTimeout("alertTimeoutError()", 10000); // wait for 10 seconds

}


function registerForEmail (emailId) {

	var script = document.createElement('script');
	script.type = 'text/javascript';
	var src = 'http://sms.wmg.com/sms/register?js=true&email=' + emailId + '&newsletterId=livvifranc&signuptype=any';
	script.src = src;
	try {
		$(".info_fetch").append(script);		 
	} catch (err) {
	// Skip error as this will be take care by the alertTimeoutError method.
	
	
	}
	setTimeout("alertTimeoutError()", 10000); // wait for 10 seconds

}

	     
function callback(status, response) {
   if(status=='success'){
   	
		$("#TB_ajaxContent").remove();
		$("#TB_window .form2").remove();
		$("#TB_window").append("<div class='form2'>Thanks for signing up!</div>");
		$(".form2").fadeIn("slow");
		setTimeout( function() {
			$("#TB_overlay").remove()
			$("#TB_window").remove()
		}, 2000);

   	    $('.emailinfo_wrapper #successmessage').css("display","block");
		$('.emailinfo_wrapper #error').css("display","none");
		$('.emailinfo_wrapper .info_fetch').css("display","none");
		$('.emailinfo_wrapper .emailquery_statement').css("display","none");
		$('.emailinfo_wrapper .privacy_statement').css("display","none");
		$('#emailvalmsg').css("display","none");
		
   }
   else{
      		$('.errmsg').css("display","block");
		$('#successmessage').css("display","none");
   }		
	callback_completed = true;
}

function alertTimeoutError() {

	if (!callback_completed) {
		setError("Unable to process your request at this time");
	}

}












