﻿//DOM加载完成时执行
(function($) {
$(function(){
	$.ajax({
		type: "POST",
		url: "/ModulePage.aspx?Module=User&Action=ServiceInfo",
		data: '',
		dataType: "json",
		success: function(response){
			if(response.Status!="0") {
				$('.BtnCNetService').click(function() {
					alert(response.Message);
				});
			}else{
				//window.location.href = 'UserCenter/';
				
				$('.BtnCNetService').click(function() {
					$("#ServiceTabs").tabs();
					$("#ServiceDialog").dialog({
						bgiframe: true,
						autoOpen: false,
						height: 576,
						width: 550,
						modal: true,
						open: function(event, ui) {
							$('#RTOFrame').attr('src', '/usercenter/VoiceClient.htm');
							$('#ServiceFrame').attr('src', '/Chat/Chats.aspx');
							$("#CloseDialog").unbind()
							$('#CloseDialog').click(function(event){
								if(confirm('确实要离开该页面吗?\n\n按“确定”继续，或按“取消”留在当前页面。')){
									$("#ServiceDialog").dialog('close');
								}
								return false;
							});
						},
						close: function(event, ui) {
							$('#ServiceFrame').attr('src', 'about:blank');
							$('#RTOFrame').attr('src', 'about:blank');
							$("#ServiceDialog").dialog( 'destroy' );
						}
					}).dialog('open');
				});//服务卡
				
				try{
					/**
					 * chat=no不显示chat工具
					 */
					/*alert(parseInt($('#UserCount').html(), 10));*/
					if(location.href.indexOf('chat=no')==-1) {
						if(parseInt($('#UserCount').html(), 10)>0) {
							$('#BtnNetStart').trigger('click');
						}
					}
				}catch(e){}

				$('.BtnMNetService').click(function() {
					$("#ServiceTabs").tabs();
					$("#ServiceDialog").dialog({
						bgiframe: true,
						autoOpen: false,
						height: 576,
						width: 550,
						modal: true,
						open: function(event, ui) {
							$('#RTOFrame').attr('src', '/usercenter/VoiceClient.htm');
							$('#ServiceFrame').attr('src', '/Chat/Chat.aspx');
							$("#CloseDialog").unbind()
							$('#CloseDialog').click(function(event){
								if(confirm('确实要离开该页面吗?\n\n按“确定”继续，或按“取消”留在当前页面。')){
									$("#ServiceDialog").dialog('close');
								}
								return false;
							});
							//
						},
						close: function(event, ui) {
							$('#ServiceFrame').attr('src', 'about:blank');
							$('#RTOFrame').attr('src', 'about:blank');
							$("#ServiceDialog").dialog( 'destroy' );
						}
					}).dialog('open');
				});//主机

				
				//注册新服务
				$('#BtnNewCard').click(function(e) {
					$("#NewCardDialog").dialog({
						bgiframe: true,
						autoOpen: false,
						/*height: 10,*/
						width: 350,
						modal: true,
						open: function(event, ui) {
							//$("#NewCardDialog").show();
						},
						close: function(event, ui) {
							
						}
					}).dialog('open');
				});
				
				
				//新注册服务卡号
				$('#BtnAddNewCard').click(function(e) {
					var CardNo = $('#NewCardNo').val();
					
					if(!/^[a-zA-Z0-9]+$/.test(CardNo)){
						alert("请先输入服务卡号");
						return;
					};
					$.ajax({
						type: "POST",
						url: "/ModulePage.aspx?Module=Card&Action=NewCard",
						data: 'CardNo='+CardNo,
						dataType: "json",
						success: function(response){
							if(response.Status=="103") {
								alert(response.Message);
								//window.location.href = '../Login.html';
							}else if(response.Status!="0") {
								alert(response.Message);
								
							}else{
								$.ajax({
									type: "POST",
									url: "/ModulePage.aspx?Module=User&Action=ServiceInfo",
									data: '',
									dataType: "json",
									success: function(response){
										if(response.Status=="103") {
											alert(response.Message);
											//window.location.href = '../Login.html';
										}else if(response.Status!="0") {
											alert(response.Message);
										}else{
											$('#ServiceInfo').html(response.ResponseData);
										}
									}
								});
								var option = new Option(CardNo, CardNo);
//								$('#DropDownList2')[0].options[$('#DropDownList2')[0].options.length] = option;
//								$('#DropDownList2').val(CardNo);
                                alert(response.Message);
								$("#NewCardDialog").dialog('close');

//								$('#DropDownList2').trigger("change");
								
								window.location.reload();
							}
						},
						error: function(response){
							//alert('系统繁忙，请稍候再试。。。');
						}
					});
				});

                //注册主机编号
                $('#BtnAddNewProduct').click
                (
                function(e)
                {
                    var ProductNo=$('#NewProduct').val();
                    
                    //if (!/^[a-zA-Z]{2}[0-9]{8}$/.test(ProductNo))
                    //{
                     //   alert("请输入正确的主机编号");
                    //    return;
                    //};
                    
                    
                                        
                   //if (!/^[a-zA-Z]{2}[0-9]{8}$/.test(ProductNo))
                    //{
                     //   alert("请输入正确的主机编号");
                    //    return;
                    //};
                                   
                    if (ProductNo.length<1)
                    {
                        alert("请输入主机编号");
                        return;
                    };
                    
                    $.ajax({
                            type:"POST",
                            url:"/ModulePage.aspx?Module=Product&Action=NewProduct",
                            data:"ProductNo="+ProductNo,
                            dataType:"json",
                            success:function(response)
                            {
                                if(response.Status=="103") {
								alert(response.Message);
								//window.location.href = '../Login.html';
							}else if(response.Status!="0") {
								alert(response.Message);
								
							}else{
								$.ajax({
									type: "POST",
									url: "/ModulePage.aspx?Module=User&Action=ServiceInfo",
									data: '',
									dataType: "json",
									success: function(response){
										if(response.Status=="103") {
											alert(response.Message);
											//window.location.href = '../Login.html';
										}else if(response.Status!="0") {
											alert(response.Message);
										}else{
											$('#ServiceInfo').html(response.ResponseData);
										}
									}
								});
								var option = new Option(ProductNo, ProductNo);
//								$('#DropDownList2')[0].options[$('#DropDownList2')[0].options.length] = option;
//								$('#DropDownList2').val(CardNo);
                                alert(response.Message);
								$("#NewCardDialog").dialog('close');

//								$('#DropDownList2').trigger("change");
								
								window.location.reload();
							}
						},
						error: function(response){
							//alert('系统繁忙，请稍候再试。。。');
						}
					});
				});
				
				//注册体验码
                $('#BtnAddNewExprienceCode').click
                (
                function(e)
                {
                    var Code=$('#NewExprienceCode').val();
                                   
                    if (Code.length<1)
                    {
                        alert("请输入体验码");
                        return;
                    };
                    
                    $.ajax({
                            type:"POST",
                            url:"/ModulePage.aspx?Module=ExprienceCode&Action=NewExprienceCode",
                            data:"Code="+Code,
                            dataType:"json",
                            success:function(response)
                            {
                            if (response.Status=="100")
                            {
                            alert(response.Message);
                            window.location.reload();
                            }
                            else
                            {
                            alert(response.Message);
                            }
                                
						    },
						    error: function(response){
							    alert('系统繁忙，请稍后再试！');
						    }
					});
				});


				//服务卡切换
				$('#CardList').bind('change', function(e) {
					
					$('#BtnNetStart').attr('disabled', 'disabled');
					$('#BtnNetStart').attr('src', '/Images/UserCenter/NetStartOff.png');

					var CardNo = $(this).val();
					$.ajax({
						type: "POST",
						url: "/ModulePage.aspx?Module=User&Action=CardChange",
						data: 'CardNo='+CardNo,
						dataType: "json",
						success: function(response){
							if(response.Status=="103") {
								alert(response.Message);
								//window.location.href = '../Login.html';
							}else if(response.Status!="0") {
								alert(response.Message);
							}else{
								$('#UserCount').html(response.ResponseData[0]);
								$('#UserTime').html(response.ResponseData[1]);

								if(response.ResponseData[2]=="1"){
									$('#BtnNetStart').removeAttr('disabled', 'disabled');
									$('#BtnNetStart').attr('src', '/Images/UserCenter/NetStartOn.png');
								}
							}
						},
						error: function(response){
							//alert('系统繁忙，请稍候再试。。。');
						}
					});
				});//服务卡切换结束

				
				//BtnEditAccount
				$('#BtnEditAccount').click(function(event) {
					$.ajax({
						type: "POST",
						url: "/ModulePage.aspx?Module=User&Action=EditAccount",
						data: '',
						dataType: "json",
						success: function(response){
							if(response.Status=="103") {
								alert(response.Message);
								//window.location.href = '../Login.html';
							}else if(response.Status!="0") {
								alert(response.Message);
							}else{
								return;
								$("#AccountDialog").dialog({
									bgiframe: true,
									autoOpen: false,
									height: 576,
									width: 550,
									modal: true,
									open: function(event, ui) {
										$('#AccountFrame').attr('src', response.ResponseData);
									},
									close: function(event, ui) {
										$('#AccountFrame').attr('src', 'about:blank');
										$("#AccountDialog").dialog( 'destroy' );
									}
								}).dialog('open');
							}
						},
						error: function(response){
							//alert('系统繁忙，请稍候再试。。。');
						}
					});
				});//BtnEditAccount
			}
		}
	});
	$("#FeedbackAccordion").accordion();
	$('#RTOFrame').attr('src', 'about:blank');
	$('#ServiceFrame').attr('src', 'about:blank');
	$('#AccountFrame').attr('src', 'about:blank');

	//安装控件使用
	if(location.href.indexOf('Install')!=-1) {
		$("#ServiceTabs").tabs();
		$("#ServiceDialog").dialog({
			bgiframe: true,
			autoOpen: false,
			height: 576,
			width: 550,
			modal: true,
			open: function(event, ui) {
				$('#RTOFrame').attr('src', '/usercenter/VoiceClient.htm');
				$('#ServiceFrame').attr('src', '/Chat/Chats.aspx');
				$("#CloseDialog").unbind()
				$('#CloseDialog').click(function(event){
					if(confirm('确实要离开该页面吗?\n\n按“确定”继续，或按“取消”留在当前页面。')){
						$("#ServiceDialog").dialog('close');
					}
					return false;
				});
			},
			close: function(event, ui) {
				$('#ServiceFrame').attr('src', 'about:blank');
				$('#RTOFrame').attr('src', 'about:blank');
				$("#ServiceDialog").dialog( 'destroy' );
			}
		}).dialog('open');
	};

	//在线反馈
	$('#FeedbackForm').bind('submit', function(event) {
		var data = $("form[id=FeedbackForm]").serialize();
		$.ajax({
			type: "POST",
			url: "/ModulePage.aspx?Module=Feedback&Action=New",
			data: data,
			dataType: "json",
			success: function(response){
				if(response.Status=="103") {
					alert(response.Message);
					//window.location.href = '../Login.html';
				}else if(response.Status!="0") {
					alert(response.Message);
				}else{
					alert(response.Message);
					$('#FeedbackForm').get(0).reset();
				}
			},
			error: function(response){
				//alert('系统繁忙，请稍候再试。。。');
			}
		});
		return false;
	});//在线反馈

});//}}END:onDOMReady
})(jQuery);
