<?php


if($_REQUEST['type'] == 'findcode' or $_REQUEST['type'] == 'code')
{
	$submit = '确定';
	$titte = '验证码';
	$bool = 6;
}else{
	$submit = '发送';
	$titte = '手机号码:';
	$bool = 6;
	
	
}

if($_REQUEST['type'] == 'sendMap')
{
	$submit = '发送';
	$titte = '手机号码';
	$bool = 7;
}

if($_REQUEST['cName'] == 'code')
{
	$submit = '发送';
	$titte = '验证码';
	$bool = 5;
}

if($_REQUEST['type'] == 'find')
{
	$submit = '提交订单';
//	$titte = '验证码';
	$bool = 2;
}

if($_REQUEST['type'] == 'cancelOrder')
{
	$submit = '撤销订单';
	$titte = '';
	$bool = 3;
	
}

if($_REQUEST['type'] == 'regsend')
{
	$submit = '注册';
//	$titte = '验证码';
	$bool = 4;
}



$path = explode('/' , $_SERVER['PHP_SELF']);
$path = $path[0] ? $path[0] : $path[1];
$path = '';
$s_name = $_SERVER['SERVER_NAME'];

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<style>
.sendsms_title{font-size:13px; color:#9D9D9D; font-family:"微软雅黑"; float:left}
.sendsms_text{border: 1px solid #009900;height: 25px;padding-left: 2px; float:left}
.btn{ background-color: #FF812E;
    border: medium none;
    color: #FFFFFF;
    cursor: pointer;
    height: 25px;
    line-height: 15px;
    padding: 5px;
    width: auto; float:left; margin-left:10px;}
</style>
<script type="text/javascript" src="../theme/simple/js/ktv/jquery.min.js"></script>
<script type="text/javascript">

$(function() {
	$('#new-pwd-btn').click(function(){
			
			var new_pwd = $('#new_pwd').attr('value');
			
		
			
			var new_pwd_checked = $('#chk_pwd').attr('value');
			
			var my_account = $("#find-mobile");
			var account = my_account.val();
			
			if(new_pwd != new_pwd_checked)
			{
				alert('两次密码不一致');
				return;
			}
		
			$.post("http://<?php echo $s_name .'/'. $path ;?>/?m=member.editpwdByAccount", {account:account ,  new_pwd:new_pwd , new_pwd_checked:new_pwd_checked, ktvFindCode:1 }, function(data) {
				alert('修改成功');
			parent.location.reload();   

			});
	});
	
	function isEmail(str){
			var reg1 = /([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
 			return reg1.test( str );
		}
	
	$('#mysub').click(function(){
	
		var bool = $(this).attr('bool');
		
		
		if(bool == 7)
		{
			var account = parent.$("#mobile").attr('value');

			$('#mobile').attr('value' , account);
			var info_phone = parent.$("#info_phone").html();
			var info_address = parent.$("#info_address").html();
			var ktvName = parent.$("#ktvName").attr('value');
			

			info_phone = info_phone.substr(info_phone.indexOf('</strong>') + 9 , info_phone.length);
			info_address = info_address.substr(info_address.indexOf('</strong>') + 9 , info_address.length);
			
			var str = '商家名称:' + ktvName + ';商家联系电话:' + info_phone + ';商家地址:'+ info_address;
			
			$('#order_title').attr('value',str);
			$('#formSend').submit();
			return;
		}
		
		
		if(bool == 5)
		{
			var account = parent.$("#mobile").attr('value');

			$('#mobile').attr('value' , account);
			$('#formSend').submit();
		}
				
		if(bool == 4)
		{
			
			var my_account = parent.$("#mobile");
			var my_password = parent.$("#reg-password");
			var my_repwd = parent.$("#reg-repwd");
			var my_name = parent.$("#reg-name");
			var my_mobile = parent.$("#mobile");
			var my_mail = parent.$("#reg-mail");
			var my_sex = parent.$("#reg-sex");
			
			var my_sendCode = parent.$("#sendCode");
			
			var account = my_account.val();//.replace(/ /g, '').replace(/'/g, '');
			var password = my_password.val();//.replace(/ /g, '').replace(/'/g, '');
			var repwd = my_repwd.val();//.replace(/ /g, '').replace(/'/g, '');
			var name = my_name.val();//.replace(/ /g, '').replace(/'/g, '');
			var mobile = my_mobile.val();//.replace(/ /g, '').replace(/'/g, '');
			var mail = my_mail.val();//.replace(/ /g, '').replace(/'/g, '');
			var send_code = my_sendCode.val();//.replace(/ /g, '').replace(/'/g, '');
			var sex = '女';
			
			
			if(my_sex.attr("checked")=='checked') 
			{
				sex = '男';
			}
			
		
			
			if(account == "") {
				alert("用户名不能为空！");
				my_account.val("").focus();
			} else if(password == "") {
				alert("密码不能为空！");
				my_password.val("").focus();
			} else if(repwd != password) {
				alert("两次密码不一样！");
				my_repwd.focus();
			} else if(name == "") {
				alert("姓名不能为空！");
				my_name.val("").focus();
			} else if(mail == "") {
				alert("email地址不能为空！");
				my_mail.val("").focus();
			} else if(isEmail(mail) == "") {
				alert("请填写正确的email地址");
				my_mail.val("").focus();
			} else if(account != "" && !/^(13|15|18)\d{9}$/.test(account)){
				alert("请输入正确的手机号码！");
				my_mobile.focus();
			}else if(send_code == "" ){
				alert("请输入验证码！");
				my_sendCode.focus();
			}
			
			 else {
				
				var mydata = parent.$("#formSend").serialize();
			
				
				$.ajax({
					type:'POST',
					url:'http://<?php echo $s_name .'/'. $path ;?>/msg/send_action.php?type=regcode&send_code=' + send_code,
					data:mydata,
					success: function (data) {	
						
						
						if(data == 1)
						{
							alert('手机验证码错误,请确认后再输入');	
							return;
						}else{
						
							var url = 'http://<?php echo $s_name .'/'. $path ;?>/?m=login.register&code=' + send_code + '&account=' + account + '&password='+password + '&name='+name + '&mobile=' + account+ '&sex='+ sex +'&email=' + mail;
							
							$.ajax({
								type:'POST',
								url:url,
								success: function (data) {
									var ary = eval("(" + data + ")");		
									if(ary[0] == "success") {
										/*alert(ary[1]);
										window.location.href = "http://<?php echo $s_name .'/'. $path ;?>/?m=ktv.ktvMmember";*/
										$('#member_name').attr('value' , mobile);
										$('#num').attr('value' , password);
										$('#formSend').submit();
										
									} else {
										alert(ary[1]);
										if(ary[2] == "account is null") {
											my_account.val("").focus();
										} else if(ary[2] == "password is null") {
											my_password.val("").focus();
										} else if(ary[2] == "member is exists") {
											my_account.focus();
										} else if(ary[2] == "name is null") {
											my_name.val("").focus();
										} else if(ary[2] == "mobile is null") {
											my_mobile.val("").focus();
										}
									}
									
								},
								cache: false
							});
						}
					},
					cache: false
				});
				
				
				
			}
		}
		

		if(bool == 3)
		{
			 var mobile = parent.$('#order_mobile').attr('value');
		
			
			 
		
			 if (confirm("是否撤销该订单？")) { 
			 	var url = 'http://<?php echo $s_name .'/'. $path ;?>/?m=order.del_Ktvorder&id=<?php echo $_GET['id']?>';

				$.ajax({
					type:'POST',
					url:url,
					success: function (data) {
						
						$('#num').attr('value' , '<?php echo $_GET['ordernum'];?>');
						$('#order_title').attr('value' , '<?php echo urldecode($_GET['order_title']);?>');
						$('#member_name').attr('value' , mobile);
						
						
						
						$('#formSend').submit();
						return;
						
					},	
					cache: false
				});
			 }
			
		}
	
		
		if(bool == 2)
		{
			
		
			var member_phone = parent.$('#member_phone').attr('value');
	
			var times = parent.$('#times').attr('value');
		
			var begin_time = parent.$('#begin_time').attr('value');
			
			var close_time = parent.$('#close_time').attr('value');
		
			var member_name = parent.$('#member_name').attr('value');
		
			var order_title = parent.$('#order_title_shirt').attr('value');
			
			var member_id = parent.$('#member_id').attr('value'); 	
			
			var O_PWD_TXT = parent.$('#O_PWD_TXT').attr('value'); 	
		
			var member_sex = parent.$("input['member_sex'][checked]").val();
			
			var number = parent.$('#number').attr('value');
			
			var remark = parent.$('#remark').attr('value');
			
			var ktv_id = parent.$('#ktv_id').attr('value');
			
			var room_id = parent.$('#room_id').attr('value');
			
			var other_name = parent.$('#other_name').attr('value');
		
			var other_sex = parent.$('#other_sex').attr('value');
		
			var other_phone = parent.$('#other_phone').attr('value');
		
			var all_price = parent.$('#all_price').attr('value');
			
			var numbers = parent.$('#number').attr('value');	
			
	
		
			if(member_name == '' || member_name == '请输入姓名')
			{
				alert('请输入姓名');
				parent.$('#member_name').focus();
				return;
			}
			
			if(member_phone == '' || member_phone == '请输入手机号')
			{
				alert('请输入手机号');
				parent.$('#member_phone').focus();
				return;
			}

			var query = '&member_sex='+member_sex+'&member_name=' + encodeURI(member_name) + '&member_id=' + member_id + '&member_phone='+member_phone+'&O_PWD_TXT='+O_PWD_TXT + '&times='+times+'&begin_time='+begin_time+'&close_time='+close_time+'&number='+number+'&remark='+encodeURI(remark)+'&ktv_id='+ktv_id+'&room_id='+room_id+'&other_name='+encodeURI(other_name)+'&other_sex='+other_sex+'&other_phone='+other_phone+'&all_price='+all_price;
			
			$.ajax({
				type:'POST',
				url:'http://<?php echo $s_name .'/'. $path ;?>?m=ktv.orderBook'+query,
	
				success: function (data) {
					
					if(data == 1)
					{
						alert('登录密码错误');
						$('#O_PWD_TXT').select();
						return;
					}
					
					var sp = data.split('|');
					
					$('#mobile').attr('value' , member_phone);
					$('#num').attr('value' , sp[0]);
					$('#num2').attr('value' , sp[1]);
					
					$('#times').attr('value' , times);
					$('#begin_time').attr('value' , begin_time);
					$('#close_time').attr('value' , close_time);
					$('#order_title').attr('value' , order_title);
					$('#num').attr('value' , data);
					
					$('#formSend').submit()
				
				},
					cache: false
			});
			return;	
		}
			
		
		if(bool == 1)
		{
			
			var mobile = parent.$('#mobile').attr('value');
			
			$('#mobile').attr('value' , mobile);
			
				$.post("http://<?php echo $s_name .'/'. $path ;?>?m=login.checkAccount&account=" + mobile, { }, function(data) {
							
						var ary = eval("(" + data + ")");											
						
						if(ary[0] == 'error')
						{
							alert('该账号已经存在,请从左侧进行登录');	
						}else{
							$('#formSend').submit();
						}
				});			

			
			
		}else{
			//$('#formSend').submit();
		}
		
	});
	
		
		
		

});
	
</script>
</head>

<body>



<?php if($_REQUEST['type'] == 'msgCode'){ ?>
	<div style="font-size:12px; *margin-top:-10px;">输入验证码</div>
<?php
exit;
 }?>

<form action="send_action.php?type=<?php echo $_REQUEST['type']?>" method="post" name="formSend" id="formSend" >



	
<?php if($_REQUEST['type'] == 'editpwd') { ?>
<span class="sendsms_title">&nbsp;&nbsp;&nbsp;新密码&nbsp;&nbsp;&nbsp;</span><input id="new_pwd" class="sendsms_text" style="width:120px;" type="password" value="" > 
<div style="clear:both; height:10px;"></div>
<span class="sendsms_title">确认密码&nbsp;&nbsp;</span><input id="chk_pwd" type="password" class="sendsms_text" style="width:120px;" value="" >
<input type="hidden"  name="find-mobile" id="find-mobile" value="<?php echo $_REQUEST['mobile'];?>">
<input type="button"  id="new-pwd-btn"   class="j_button" value="确认" style="margin-left:5px;"  >

	</form>
<?php
exit;
 }?>


<?php  
 if($_REQUEST['type'] != 'find') {

 	if($_REQUEST['type'] == 'findcode')
	{
		$id = 'findcode';
		$value = $_REQUEST['mobile'];
	}else if($_REQUEST['cName'])
	{
		$id = $_REQUEST['cName'];
	}else
	{
		$id = mobile;
	}
 
if($_REQUEST['cName'] != 'code' && $_REQUEST['type'] != 'cancelOrder' && $_REQUEST['type'] != 'regsend' ){ ?><span class="sendsms_title"><?php echo $titte ?>&nbsp;&nbsp;</span><input class="sendsms_text" style="width:120px;" name="<?php echo  $id;?>"  id="<?php echo  $id;?>"  <?php if($_REQUEST['cName'] == 'code'){ ?> style="display:none" <?php } ?>>


<?php } ?>
<input name="ext" class="sendsms_text"  type="hidden">

<?php if($_REQUEST['cName'] or $_REQUEST['type'] == 'findcode') { ?>
<span class="sendsms_title"></span>
<input name="mobile" id="mobile" style="width:90px;" class="sendsms_text" type="hidden"  value="<?php echo $_REQUEST['mobile']?>"  >
<?php }
}else{?>
	<input class="sendsms_text" style="width:120px;" name="mobile"  id="mobile" type="hidden">
	<input name="ext" class="sendsms_text"  type="hidden">
	
<? } ?>


<? if($_REQUEST['type'] == 'find') {?>
<input name="num2" id="num2"  style="width:90px;" type="hidden">
<? } ?>


<input name="stime" class="sendsms_text" style="width:90px;" type="hidden">
<input name="rrid" class="sendsms_text" style="width:90px;" type="hidden">
<input name="content"  class="sendsms_text" style="width:90px;" type="hidden">

<input name="times" id="times"  class="sendsms_text" style="width:90px;" type="hidden">
<input name="begin_time" id="begin_time"  class="sendsms_text" style="width:90px;" type="hidden">
<input name="close_time" id="close_time"  class="sendsms_text" style="width:90px;" type="hidden">
<input name="member_name" id="member_name"  class="sendsms_text" style="width:90px;" type="hidden">
<input name="order_title" id="order_title"  class="sendsms_text" style="width:90px;" type="hidden">
<input name="num" id="num"  class="sendsms_text" style="width:90px;" type="hidden">

<?php
/* $bool = $_REQUEST['cName'] == 'code' ? '1' : '0'; 
 
 if($_REQUEST['type'] == 'find')
 {
 	$bool = 2;
 }
*/

 ?>

<input name="send" class="btn" id="mysub" <?php echo $_REQUEST['cName'] == 'code' ? 'style="margin-top:-16px;*margin-top:-13px"' : '' ?>   type="button" bool="<?php echo $bool;?>" <?php echo $_REQUEST['type'] == 'cancelOrder' ? 'style="margin-top:-12px;*margin-top:-13px"' : '' ?> value="<?php echo $submit;?>">


</form>
</body>

</html>