var test=1;
var site_url="http://www.ladylucks.co.uk/";
var fullsite_url="http://www.ladylucks.co.uk/";


function IsNumeric(sText)

{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;

   }


	jQuery.fn.defaultText = function() {
		var self = this;
		$('form').submit(function() {
			$(self).each(function() {
				var t = $(this);
				if (t.val() == t.attr('title') && t.hasClass('default')) {t.val('');}
			});
		});
		return $(this).blur(function() {
			var t = $(this);
			if (t.val() == '') {
				t.val(t.attr('title'));
				t.addClass('default');
			}
		}).focus(function() {
		var t = $(this);
		if (t.val() == t.attr('title') && t.hasClass('default')) {
			t.val('');
			t.removeClass('default');
		}
		}).blur();
	};


	$(function() {



	// FORM FIELD DEFAULT TEXT CODE
		$('input[type="text"]').defaultText();

	// MOBILE DOWNLOAD NOW FORM
		$("#downloadnowinfo").hide();

		// turn the href into a submit trigger
		  $("#downloadnowsubmit").click(function() {
		    $("#downloadnowform").submit();
		    return false;
		  });

	   // check the mobile number format and submit or return error
	   $("#downloadnowform").submit(function() {
		var mobilenumber = $('[name=mobilenumber]').val()
		if (mobilenumber.length < 10 || mobilenumber.length > 11)
		{
			$("#downloadnowinfo").html("<div class='downloadnowinfo_title'>ERROR</div>Mobile number must be 10 or 11 digits, no spaces").show().fadeOut(3000);
			return false;
		}
		else if (mobilenumber.substring(0,2) != '07')
		{
			$("#downloadnowinfo").html("<div class='downloadnowinfo_title'>ERROR</div>Mobile number must begin with 07").show().fadeOut(5000);
			return false;
		}
		else if ( ! IsNumeric(mobilenumber) )
		{
			$("#downloadnowinfo").html("<div class='downloadnowinfo_title'>ERROR</div>Mobile number must be numbers only").show().fadeOut(5000);
			return false;
		}

		$("#downloadnowinfo").text("Sending...").show();

		$.post(
			$("#downloadnowform").attr("action"),
			$("#downloadnowform").serialize(),
			function(data){

				if (data=='Success')
					window.location = "/index_smsconfirm";
				else
					$("#downloadnowinfo").html(data).show();
			}
		);

		return false;
	    });






	// EMAIL UPDATES FORM
		// $("#emailsignupinfo").hide();

		// hide the error box when the input form is re-clicked
		//	$(".fadeerror").focus(function() {
		//		$("#emailsignupinfo").hide();
		//	});

		// turn the href into a submit trigger
		  $("#emailsignupsubmit").click(function() {
		   $("#emailsignupform").submit();
		    return false;
		  });




	   // check the mobile number format and submit or return error
	   $("#emailsignupform").submit(function() {


		var mobilenumber = $('[name=mobile]').val();


		if (mobilenumber.length < 10 || mobilenumber.length > 11)
		{
			$("#emailsignupinfo").html("<p><div class='downloadnowinfo_title'>ERROR</div>Mobile number must be 10 or 11 digits, no spaces.</p>").show();
			return false;
		}
		else if (mobilenumber.substring(0,2) != '07')
		{
			$("#emailsignupinfo").html("<p><div class='downloadnowinfo_title'>ERROR</div>Mobile number must begin with 07</p>").show();
			return false;
		}
		else if ( ! IsNumeric(mobilenumber) )
		{
			$("#emailsignupinfo").html("<p><div class='downloadnowinfo_title'>ERROR</div>Mobile number must be numbers only.</p>").show();
			return false;
		}


		$("#emailsignupinfo").text('Sending...').show();

		$.post(
			$("#emailsignupform").attr("action"),
			$("#emailsignupform").serialize(),
			function(data){
				if(data=="success")
				{
					$("#emailsignupinfo").html('<p><div class="downloadnowinfo_title">THANK YOU</div> Your details have been added to our mailinglist.</p>').show();
				}
			     	else
				{
					//there was an erro, so grab the relevant part of the return page
					$("#emailsignupinfo").html('<p><div class="downloadnowinfo_title">ERROR</div>Please ensure all fields have been filled in.</p>').show();

				}
			}
		);

		return false;
	    });





	});



