
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;

   }


	$(function() {

	// 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() {

		$('.circle-box').hide();

		var mobilenumber = $('[name=mobilenumber]').val()
		mobilenumber = mobilenumber.split(' ').join('');
		if (mobilenumber.length < 10 || mobilenumber.length > 11)
		{
			$("#downloadnowinfo").html("<center><br/><span class='big'>ERROR</span><br/><br/>Mobile number must be 11 digits long and start with 07.<br/><br/>Please check your number and try again!</center>").show();
			return false;
		}
		else if (mobilenumber.substring(0,2) != '07')
		{
			$("#downloadnowinfo").html("<center><br/><span class='big'>ERROR</span><br/><br/>Mobile number must be 11 digits long and start with 07.<br/><br/>Please check your number and try again!</center>").show();
			return false;
		}
		else if ( ! IsNumeric(mobilenumber) )
		{
			$("#downloadnowinfo").html("<center><br/><span class='big'>ERROR</span><br/><br/>Mobile number must be 11 digits long and start with 07.<br/><br/>Please check your number and try again!</center>").show();
			return false;
		}

		$("#downloadnowinfo").html("<center><br/><span class='big'>SENDING</span><br/><br/>Please wait</center>").show();

		$.post(
			$("#downloadnowform").attr("action"),
			$("#downloadnowform").serialize(),
			function(data){
				if (data=='Success')
				{
					if (typeof resultspage == "undefined")
						window.location = "/index_smsconfirm";
					else
						window.location = resultspage;
				}
				else
				{
					$("#downloadnowinfo").html(data).show();
				}
			}
		);

		return false;
	    });

		// close the downloadnowinfooverlay panel on click
	$('#downloadnowinfo').click(function () {
        	$('#downloadnowinfo').hide();
        	$('.circle-box').show();
	    });    
     

	});



