/* JavaScript Document */

function SMSPhoneReturn(JSONObj)

{
	 
	 
	
	if (JSONObj.MESSAGE != '')
	{
	
		/* alert(JSONObj.ERRORMESSAGE); */
		
		$("#dialog-sms-reverse-confirm").dialog('close');		
		
		/*$('#dialog-sms-reverse-error').html(JSONObj.ERRORMESSAGE); */
		
		alert(JSONObj.MESSAGE);
		
		$("#btn-cancel-mobile").show("slow");
		
		$("#btn-cancel-mobile").bind("click", cancelMobileAuthReverse);
		
		$("#subscribemessage").html("<br>You have confirmed for reverse charging via localsecrets.<br><b>Waiting for confirmation from mobile.</b>");
			
		$("#subscribemessage").show("slow");
		
		if ($("#spansmsheader").length > 0)
															
		{
		  
			
			$("#spansmsheader").show();
		
		}
		
		/*$$('#dialog-sms-reverse-error').dialog('open'); */
		
	
	} else 
	
	{
	
		alert(JSONObj.ERRORMESSAGE);
	}
	
	
}


function isNumeric(form_value) 
{ 
    if (form_value.match(/^\d+$/) == null) 
        return false; 
    else 
        return true; 
} 

var obj = new Object();


function cancelMobileAuthReverse()

{
	
	$("#dialog-sms-reverse-unsubscribe").html("Do you want unsubcribe your mobile from reverse billing");
	
	 
	$("#dialog-sms-reverse-unsubscribe").dialog({
											
				bgiframe: true,
				resizable: false,
				autoOpen: false,
				modal: true,
				height: 150,
				width: 400,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'Ok': function() {
						 
						 	$.ajax({
									type: "POST",
									url: websiteURL + "loaddynamic.cfm?template=unregistermobile",
									data: obj,									
									success: function () { 
															$("#subscribemessage").fadeOut("slow");
															$("#btn-cancel-mobile").hide();
															$("#dialog-sms-reverse-unsubscribe").dialog('close');
															
															alert("Your mobile is unsubcribed for reverse billing successfully");
															
															if ($("#spansmsheader").length > 0)
															
																{
																  
																	
																	$("#spansmsheader").hide();
																
																}
															
															
															}
								   });
							}
				}
					
	 
			});
			
	$('#dialog-sms-reverse-unsubscribe').dialog('open');
	
	 
}


function validateSMSPhoneNumber()
		
		
		{
		
			/* Call URL to validate ther phone number */			
			var mobilephonecode = $("#phonecode1").val();
			var mobilephonenumber = $("#phonenumber1").val();
			
			
			
			if (isNumeric(mobilephonecode) == false)
			
			{
				 
				
				$("#phone1errmsg").html("<br>Please enter number").show().fadeOut("slow");
			
				return false;
				
			} 
			
			if (isNumeric(mobilephonenumber) == false)
			
			{
				$("#phone1errmsg").html("<br>Please enter number").show().fadeOut("slow");
				return false;
			}
			
			
			
			obj.mobilephonecode = mobilephonecode;
			obj.mobilephonenumber = mobilephonenumber;
			var htmlString = 'Are you sure you want to update your mobile number';
			
			/*('+mobilephonecode+mobilephonenumber+') for reverse billing.'; */
		
		$('#dialog-sms-reverse-confirm').html(htmlString);
		
		 
		 
		$("#dialog-sms-reverse-confirm").dialog({
											
				bgiframe: true,
				resizable: false,
				autoOpen: false,
				modal: true,
				height: 150,
				width: 400,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'Update': function() {
						
							$.ajax({
						   type: "POST",
						   url: websiteURL + "loaddynamic.cfm?template=validatemembermobile",
						   data: obj,
						   dataType: "json",
						   success: SMSPhoneReturn
					 		});  
							
					},
					'Cancel this request': function() {
						$(this).dialog('close');
					}
				}
			});
			
			$('#dialog-sms-reverse-confirm').dialog('open');
		
			
			/*$('#dialog-sms-reverse-confirm').html(htmlString);*/
			/*  */
		 
		
		}
		
/*Book a table frontend*/

$(document).ready(function() {

	
	 
	/*$("#dialog-sms-reverse-confirm").dialog({
											
				bgiframe: true,
				resizable: false,
				autoOpen: false,
				modal: true,
				height:150,
				width: 400,
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'Update': function() {
						$(this).dialog('close');
					},
					'Cancel this request': function() {
						$(this).dialog('close');
					}
				}
			});*/
	
	
	$("#dialog-sms-reverse-error").dialog({
											
				bgiframe: true,
				resizable: false,
				autoOpen: false,
				modal: true,
				height:150,				
				overlay: {
					backgroundColor: '#000',
					opacity: 0.5
				},
				buttons: {
					'Ok': function() {
						$(this).dialog('close');
					}
				}
			});
	
	
	
	if ($("#btn-update-mobile").length > 0) {
			
			$("#btn-update-mobile").show("slow");
			$("#btn-update-mobile").bind("click", validateSMSPhoneNumber);
			
		}
	
	if ($("#hid_sms_reverse_billed_confirmed").length > 0) {
			
			$("#btn-cancel-mobile").show("slow");
			$("#btn-cancel-mobile").bind("click", cancelMobileAuthReverse);
			
			$("#subscribemessage").show("slow");
			
			$("#subscribemessage").html("<br>You have confirmed for reverse charging via localsecrets");
			
			if ($("#hid_sms_reverse_billed_authorised").length > 0)
			
			{
			
				$("#subscribemessage").append("<br><b>Successfully authorised from your mobile.</b>");
				
				
			} else {
				
				
				$("#subscribemessage").append("<br><b>Waiting for confirmation from mobile.</b>");
				
			}
			
		}
		
		$("#phonecode1").keypress(function(e) {
								 
								  	return keyCheck(e,'phone1errmsg');
								 
									});
		
		$("#phonenumber1").keypress(function(e) {
								 
								  	return keyCheck(e,'phone1errmsg');
								 
									});
		
		$("#phonecode2").keypress(function(e) {
								 
								  	return keyCheck(e,'phone2errmsg');
								 
									});
		
		$("#phonenumber2").keypress(function(e) {
								 
								  	return keyCheck(e,'phone2errmsg');
								 
									});
		
		function keyCheck(eobject,errorElement)
		{
		
			//if the letter is not digit then display error and don't type anything
		  if( eobject.which!=8 && eobject.which!=0 && (eobject.which<48 || eobject.which>57))
		  {
			//display error message
			$("#" + errorElement).html("<br>Digits Only").show().fadeOut("slow");
			return false;
		  }
			
		}
		
		
	/* Table booking auto refresh  */
	
	function statusBoxRotate(){
		
		
			//$("div#tablebookingbox").html("<span>Refreshing status box, please wait...</span>");
						
			//$("div#tablebookingbox").load('/localsecrets_mobile/loaddynamic.cfm?template=statusbox');	
			
			
			var obj = new Object();
			
						$.ajax({
									type: "POST",
									url: websiteURL + 'loaddynamic.cfm?template=statusbox&bookatablehtml=json',
									data: obj,
									dataType:'json',
									success: function (JSON) { 
															 
															 	if (JSON.HTMLDATA.length ==0)
																{
																
																	$("#tablebookingbox").hide();	
																
																} else {
																	
																	$("#tablebookingbox").html(JSON.HTMLDATA);
																	  
																	 
																	$("#tablebookingbox").show();
																}
					
																setTimeout(function(){statusBoxRotate()},20000);	
															 
															}
								   });
			
	}
	
	
	
	if($("#tablebookingbox").length > 0)
		setTimeout(function(){statusBoxRotate()},10000); 
		
		
	/* SMS status auto refresh  */
	
	function SMSstatusBoxRotate(){
		
		
			
			//$("div#smsbox").html("<span>Refreshing SMS status box, please wait...</span>");
			
			
			//$("div#smsbox").load('/localsecrets_mobile/loaddynamic.cfm?template=smsstatusbox');
			
			
			//setTimeout(function(){SMSstatusBoxRotate()},20000);
			
			
			var obj = new Object();
			
						$.ajax({
									type: "POST",
									url: websiteURL + 'loaddynamic.cfm?template=smsstatusbox&smshtml=json',
									data: obj,
									dataType:'json',
									success: function (JSON) { 
															 
															 	if (JSON.HTMLDATA.length ==0)
																{
																
																	$("#smsbox").hide();	
																
																} else {
																	
																	$("#smsbox").html(JSON.HTMLDATA);
																	  
																	 
																	$("#smsbox").show();
																}
					
																setTimeout(function(){SMSstatusBoxRotate()},20000);	
															 
															}
								   });
			
			
	}
	
	
	
	if($("#smsbox").length > 0)
		setTimeout(function(){SMSstatusBoxRotate()},20000);
		
	
	/* booking process auto refresh  */
	
	function bookingProcessBoxRotate(){
		
			
					var obj = new Object();
					
					obj.jsmemberbooklist = jsmemberbooklist;
			
						$.ajax({
									type: "POST",
									url: websiteURL + 'loaddynamic.cfm?template=bookingprocessbox&bookingprocesshtml=json',
									data: obj,
									dataType:'json',
									success: function (JSON) { 
															 
															 	if (JSON.HTMLDATA.length ==0)
																{
																
																	$("#bookingprocess").hide();	
																
																} else {
																	
																	$("#bookingprocess").html(JSON.HTMLDATA);
																	  
																	 
																	$("#bookingprocess").show();
																}
					
																setTimeout(function(){bookingProcessBoxRotate()},20000);	
															 
															}
								   });
			 
			
			
			}
	
	 
	if($("#bookingprocess").length > 0)
		setTimeout(function(){bookingProcessBoxRotate()},20000);
		
		
	
		
	
}); /* End Document.ready */



/* Ajax reference 



 
			$.post(websiteURL + "loaddynamic.cfm?template=validatemembermobile", { mobilephonecode: mobilephonecode,mobilephonenumber: mobilephonenumber},
  									function(data){
    								alert(data.name);  
    								 
  						}, "json");

			
			
			var obj = new Object();
			
			obj.mobilephonecode = mobilephonecode;
			obj.mobilephonenumber = mobilephonenumber;
			
			 
			
			 $.ajax({
					   type: "POST",
					   url: websiteURL+ "loaddynamic.cfm?template=validatemembermobile",
					   data: obj,
					   dataType: "json",
					   success: function(data){
						  alert( "Data Saved: " + data.NUMBER + ":" +  data.NAME);
					   }
					 });

			$("#sms-validate").html('Enter phonenumber');
			
			
			
			$("#sms-validate").show("slow");
			
*/
			