// SMS js - cc.sms.js - beaver6813 - sam cleaver
  $(function() {
		$.ui.dialog.defaults.bgiframe = true;
		$("#dialog").dialog({ resizable: false, minHeight: 0, autoOpen: false });
		$('.sms-open').live('click',function() {
											 $("#dialog").dialog('close');
											 $('input[name=sms_couponid]').val($(this).parent().siblings('.couponiddata').val());
											 $("#dialog").dialog('open');
											 });
		$('.sendsms').bind('click',function() {
											var combinephone = $('input[name=sms_phone1]').val()+$('input[name=sms_phone2]').val()+$('input[name=sms_phone3]').val();
											if(combinephone.length<10)
												$('.sms-error').show().text('Invalid cell number.');
											else
												{
												if(parseInt($('select[name=sms_Carrier]').val())>0)
													{
													$('.sms-error').hide().text('');
													$('.sms-start').hide();
													$('.sms-loading').show();
													$.ajax({
													 type: "POST",
													 url: "/smsmailer.php",
													 data: "number="+combinephone+"&carrier="+$('select[name=sms_Carrier]').val()+"&coupon="+$('input[name=sms_couponid]').val(),
													 success: function(msg){
														 var response = msg.split('||');
														 switch(response[0])
														 	{
															case 'ERROR':
															$('.sms-loading').hide();
															$('.sms-start').show();
															$('.sms-error').show().text(response[1]);
															break;
															case 'OK':
															$('.sms-loading').hide();
															$('.sms-finish').show();
															setTimeout(function(){$("#dialog").dialog('close');$('.sms-start').show();$('.sms-finish').hide();},1000);
															break;
															default:
															alert("Unexpected message "+msg);
															setTimeout(function(){$("#dialog").dialog('close');$('.sms-start').show();$('.sms-finish').hide();},500);
															break;
															}
													 },
													 error: function(msg){
														 $('.sms-error').show().text('Internal error, could not send message.');
														 
													 }
												   });

													}
												else
													$('.sms-error').show().text('Select a carrier.');
													
												}
											
											});
		
		
	});
