<!doctype html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="../css/scrollstyle.css"  type="text/css" />
    <link rel="stylesheet" href="speech.css" type="text/css" />
    <style type="text/css">
    	body{
    		margin: 0 0;
    		padding: 0 0;
    		background: transparent;
    		font-family:微软雅黑,Verdana,sans-serif,宋体;
    		color:#555;
    		border: none;
    		-webkit-user-select: none;
    		overflow:hidden;

    	}
    	.arial{font-family:Arial;}
    	button{
    		color:#fff;
    		font-size: 12px;
    		border: none;
    		width:65px; height:25px;
	        background-color:#257fd3;
	        cursor:pointer;
		 }
    	button:not(:disabled):hover{
	        background-color:#439ef6;
    	}
    	button:not(:disabled):active{
	        background-color:#096ac6;
    	}
    	button:disabled{
	        cursor:default;
	        color:#FFFFF;
	        background-color:#E6E6E6;
    	}
    	#selContact{
	        color:#555;
	        border:#DEDEDE solid 1px;
	        background-color:#E6E6E6;
		 }
    	#selContact:not(:disabled):hover{
	        color:#555;
	        text-decoration:underline;
	        background-color:#F0F0F0;
    	}
    	#selContact:not(:disabled):active{
	        color:#555;
	        background-color:#D7D7D7;
    	}
    	
		button[disabled],button[disabled]:hover,button[disabled]:focus,button[disabled]:active{color:#B6B6B6;}
		.tips{
			position: absolute;
			left: 58%;
			bottom: 8px;
			height: 20px;
			margin-left: -80px;
			background-color: transparent;
			text-align: center;
			font-size: 12px;
			color:red;
			display: none;

		}


    	.top{
    		position: absolute;
    		left: 0px;
    		top: 0px;
    		width: 598px;
    		height: 30px;
    		border: #ccc solid 1px;
    		background-color: #EBEBEB;
    		font-weight:bold;
			font-size: 12px;
    	}
    	.topicon{
    		float: left;
    		padding-left: 25px;
    		background:transparent url(../images/Icon/smssend.png) 5px 6px no-repeat;
    		height: 30px;
    		line-height: 30px;
    	}
    	.close{
    		float: right;
    		width: 20px;
    		height: 30px;
    		cursor:pointer;
    		background:transparent url(../images/close.png) 0px center no-repeat;
    	}
    	.close:hover{
    		background:transparent url(../images/close_hover.png) 0 center no-repeat;
    	}
    	.close:active{
    		background:transparent url(../images/close_active.png) 0 center no-repeat;
    	}
    	.mid{
    		position: absolute;
    		left: 0px;
    		top: 32px;
    		width: 598px;
    		height: 80px;
    		background: #F6F6F6;
    		border-bottom: #ccc solid 1px;
			border-left: #ccc solid 1px;
			border-right: #ccc solid 1px;
    	}



    	.addressContainerBg{
    		position: absolute;
    		left: 5px;
    		top: 8px;
			width:450px;
			height:50px;
			overflow-x:hidden;
			background:#FFF;
			padding: 2px 4px;
            background:#FFF;
            border: #DEDEDE solid 1px;
    	}
    	.addressContainer{
    		position: absolute;
    		left: 2px;
    		top: 2px;
    		right: 2px;
    		bottom: 2px;
			overflow:auto;
			background-color: transparent;
    	}
    	.addressContainer li{
    		float: left;
    		background-color: #F9F9F9;
    		border: #F1F1F1 solid 1px;
    		font-size: 12px;
    		list-style: none;
    		display: inline-block;
    		border-radius: 2px;
    		padding: 0 20px 0 10px;
    		margin-left: 5px;
    		margin-top: 5px;
    		position: relative;
    	}
    	.addressContainer li:hover div{
    		display: block;
    		cursor: pointer;
    	}
    	.delete-contact{
	    	cursor: default;
			height: 15px;
			width: 12px;
			margin-top: -8px;
			position: absolute;
			right: 2px;
			top: 50%;
			background:transparent url(../images/button/delete-contact.png) 0 center no-repeat;
    	}
    	.delete-contact:hover{
			background:transparent url(../images/button/delete-contactOn.png) 0 center no-repeat;
    	}

    	.addressContainer input{
    		float: left;
    		margin-left: 5px;
    		margin-top: 5px;
    		width: 90px;
			border: none;
			outline: none;
			resize: none;
			background-color: transparent;
    	}

		input{
			font-family:微软雅黑,Verdana,sans-serif,宋体;
		}
		textarea{
			font-family:微软雅黑,Verdana,sans-serif,宋体;
		}
    	#selContact{
			position: absolute;
    		left: 480px;
    		top: 8px;
			width:80px;
			text-align:center;
		}

		#selectedCount{
			position: absolute;
    		left: 480px;
    		top: 40px;
			height:14px;
			width:110px;
			font-size:75%;
		}
		.session{
			position: absolute;
    		left: 0px;
    		top: 115px;
			width:598px;
			height:288px;
			padding-bottom:10px;
			overflow-x:hidden;
			overflow-y:auto;
			border-left: #ccc solid 1px;
			border-right: #ccc solid 1px;
			list-style:none;
			font-size: 12px;
		}

		.session li{min-height:35px; width:100%; padding: 10px 0 30px 30px;}

		.bottom{
    		position: absolute;
    		left: 0px;
    		top: 400px;
    		width: 598px;
    		height: 98px;
    		background-color:#F6F6F6;
    		border: #ccc solid 1px;
		}

		#body{
			float:left;
			width:580px;
			height:50px;
			margin-top:6px;
			margin-left:5px;
			line-height:20px;
			background:#fff;
			border: none;
			outline: none;
			resize: none;
			border:#DEDEDE solid 1px;box-shadow:inset 0 0px 5px #F1F1F1;
		}
		
		#body:focus{border:#439EF6 solid 1px;box-shadow:inset 0 0px 5px #BDCAF1;}

		.bottom .panel{
    		position: absolute;
    		left: 0px;
    		top: 60px;
    		width: 598px;
    		height: 38px;
    		padding-top:8px;
		}
		.panel label{
    		font-size: 12px;
    		margin-left: 10px;
    		margin-top: 10px;
		}

		.panel button{
			float:right; 
			margin:0px 5px; 
		 }





		/**联系人选择**/


		.searchresult{
		    position:absolute;
		    left:100px;
		    top:105px;
		    width:300px;
		    background-color: #F8F9FB;
		    border: #989EAD solid 1px;
		    list-style: none;
		    font-size: 14px;
		    text-align: left;
		    display: none;
		}
		.searchresult label{
			width: 140px;
			padding: 2px 2px;
			display: inline-block;
			white-space:nowrap;
			text-overflow:ellipsis;
			overflow: hidden;
		}
		.searchresult li:hover{
			background-color: #B7DBEB;
			color:red;
		}

		.coverScreen{
			position:absolute;
		    left:1px;
		    top:30px;
		    bottom:1px;
		    right:1px;
		    z-index:100;
		    background:rgba(248,249,251, 0.5);
		    text-align:center;
		    display: none;
		}

		.coverScreen>div
		{
		    position:absolute;
		    left:50%;
		    top:50%;
		    height:350px;
		    width:400px;
		    margin-left:-200px;
		    margin-top:-190px;
		    background-color: #F8F9FB;
		    border: #ccc solid 1px;
		}
		.selPromptTop
		{
			position:absolute;
			left:0px;
			top:0px;
			height:30px;
			right:0px;
			background-color:#EBEBEB;
		    border-bottom: #ccc solid 1px;
		
		}
		.prompticon{
			padding-left:27px;
			font-size: 12px;
			font-weight: bold;
			background:transparent url(../images/selContactIcon.png) 5px center no-repeat;
		}
		.selgroup{
			position:absolute;
			left:12px;
			top:45px;
			height:25px;
			width:179px;
			border:#DEDEDE solid 1px;
			font-size: 12px;
			cursor:pointer;
			background:#FFF url(../images/categoryDown.png) 160px center no-repeat;
		}
		.selgroup div{
			height:25px;
			white-space:nowrap;
			text-overflow:ellipsis;
			text-align: left;
			text-indent: 10px;
			line-height: 25px;
			max-width: 140px;
			font-size: 12px;
			overflow: hidden;
		}

		.search{
			position:absolute;
			left:210px;
			top:45px;
			height:27px;
			width:179px;
			padding-left:20px;
			border:#DEDEDE solid 1px;
			outline: none;
			color:#555;
			font-size: 12px;
			-webkit-appearance: none;
			background:#FFF url(../images/search_bg.png) 2px center no-repeat;
		}

		.grouplist{
			position:absolute;
			left:12px;
			top:74px;
			height:200px;
			width:179px;
			border:#DEDEDE solid 1px;
			z-index:4;
			background-color:#FFF;
			overflow-x:hidden;
			overflow-y:auto;
			display: none;
		}

		.grouplist li{
			list-style: none;
			white-space:nowrap;
			text-overflow:ellipsis;
			overflow: hidden;
			font-size: 14px;
			text-align: left;
			text-indent: 10px;
			height: 25px;
			line-height: 25px;
		}
		.grouplist li:hover,.contactslist li:active{
			background-color: #D7EDF3;
		}



		.contactslist{
			position:absolute;
			width:375px;
			left:12px;
			top:80px;
			height:225px;
			border:#DEDEDE solid 1px;
			font-size: 13px;
			padding: 0 0;
			margin: 0 0;
			text-align: left;
		}

		.content-inner{
			position:absolute;
			width:375px;
			left:0px;
			top:22px;
			height:203px;
			background-color:#FFF;
			overflow-x:hidden;
			overflow-y:auto;
			
			list-style: none;
		}

		.content-inner li{
			width: 100%;
			height: 20px;
		}
		.content-inner li:hover,.contactslist ul li:active{
			background-color: #D7EDF3;
		}

		.contactslist  header{
			background-color: #F6F6F6;
			color:#B6B6B6;
			line-height:20px;
			border-bottom:#DEDEDE solid 1px;
		}

		.content-inner li label, .contactslist header label{
			width: 100px;
			background-color:transparent;
			padding-left:5px;
			white-space:nowrap;
			text-overflow:ellipsis;
			overflow: hidden;
			display: inline-block;

		}

		.contactslist .sim0
		{		
    		width: 12px;
    		height: 12px;
    		float: left;
    		display: block;
    		background: transparent url(../images/Icon/sim.png) center center no-repeat;
			margin-right: 4px;
			margin-top: 4px;
		}

		.contactslist .sim1
		{
		    width: 12px;
		    height: 12px;
		    float: left;
		    display: block;
		    background: transparent url(../images/Icon/sim1.png) center center no-repeat;
			margin-right: 4px;
			margin-top: 4px;
		}
		.contactslist .sim-1
		{
		    width: 12px;
		    height: 12px;
		    float: left;
		    display: block;
			margin-right: 4px;
			margin-top: 4px;
		}
		.contactslist .sim2
		{
		    width: 12px;
		    height: 12px;
		    float: left;
		    display: block;
		    background: transparent url(../images/Icon/sim2.png) center center no-repeat;
			margin-right: 4px;
			margin-top: 4px;
		}
		
		.content-inner li input{
		    margin-top:2px;
		    border:#000 solid 1px;

		}



		.selected{
			position:absolute;
			width:100px;
			left:12px;
			top:320px;
			height:20px;
			font-size: 12px;
			text-align: left;
		}

		#promptok{
			position:absolute;
			left:325px;
			top:315px;
		}
		#inputhint {
			position: absolute;
			top: 64px;
			text-align: left;
			color: #ff0000;
			font-size: 12px;
			width: 100%;
			left: 10px;
		}


    </style>
</head>
<body>
    <div id="top" class="top">
    	<div class="topleft"></div>
    	<div class="topcenter">
	      	<label class="topicon">{{smssendpop_topic_send_lang}}</label>
      		<div id="close" class="close"></div>
    	</div>
    	<div class="topright"></div>

    </div>
    <div class="mid">
  		<div class="addressContainerBg">
  			<div class="addressContainer">
  				<input id="address" type="text" autofocus="true" >
  			</div>
  		</div>
  		<button id="selContact">{{smssendpop_selcontact_lang}}</button>
		<label id="selectedCount"><span>0</span>{{smssendpop_slectedcount_people_lang}}{{smssendpop_selectedcount_add_lang}}</label>
		<div id="inputhint">{{smssendpop_contactinput_hint_lang}}</div>
  	</div>
  	<div id="session" class="session">
  		
  	</div>
  	<div class="bottom">
  		<textarea id="body" cols="5" placeholder="{{smssendpop_bottom_input_tip_lang}}"></textarea>
  		<div class="panel">
            <label>{{smssendpop_panel_haveinput_lang}}<span id="charNum">0</span>{{smssendpop_charNum_lang}}[<span id="smsNum">0</span>{{smssendpop_total_message_lang}}]</label> 
      		<!--<button id="cancel">取消</button>-->
      		<button id="sim2" disabled="disabled" data-slot="1"><span class="arial">SIM2</span>{{smssendpop_sim2_send_lang}}</button>
      		<button id="sim1" disabled="disabled" data-slot="0"><span class="arial">SIM1</span>{{smssendpop_sim1_send_lang}}</button>
  		</div>
  	</div>
  	<label id="tips" class="tips"></label>
  	<div id="selPrompt" class="coverScreen">
  		<div>
  			<div class="selPromptTop">
  			    <div class="topicon prompticon">{{smssendpop_selPromptTop_selcetpeople_lang}}</div>
      		    <div id="promptclose" class="close"></div>
      		</div>
            <div id="selgroup" class="selgroup" data-groupId='all'>
            	<div>{{smssendpop_selgroup_allpeople_lang}}</div>
            </div>
            <input class="search" id="searchinput" type="search" onsearch="onSearch(this)" placeholder="{{smssendpop_search_input_lang}}">
            <div  id="grouplist" class="grouplist"></div>

            <div id="contactslist" class="contactslist">
        		<header>
					<input type="checkbox" id="all"/>
					<label class="name">{{smssendpop_contactlist_checkname_lang}}</label>
					<label class="phoneNumber">{{smssendpop_contactlist_checknumber_lang}}</label>
					<!-- LOCN --><label class="area">{{smssendpop_contactlist_address_lang}}</label>
		    	</header>
		    	<div class="content-inner">
				</div>
            </div>
            <label class="selected">{{smssendpop_contactlist_slected_lang}} <span id="Num">0</span>{{smssendpop_contactlist_slectedperson_lang}} </label>
            <button id="promptok" >{{smssendpop_contactlist_promptok_lang}}</button>
  		</div>
  	</div>

  	<div id="searchresult" class="searchresult">
  	</div>

    <script src="../js/template.js"></script>
	<script src="../js/jquery-2.0.3.min.js"></script>
	<script src="../js/util.js"></script>

    <script type="text/javascript">
    	(function () {

			document.oncontextmenu = function(e){
				var text =  window.getSelection().toString();
				if (e.srcElement.id == 'searchinput' || e.srcElement.id == 'body') {
					return true;
				};
				if (text != "") {
					return true;
				};
				return false;
			}
    		$(document).ready(function() {

				$charNum = $("#charNum");
				$smsNum = $("#smsNum")


				$('#body').bind('input change', function (e) {
					$charNum.text(this.value.length)
					$smsNum.text(Util.getSmsCount(this))
				})

				$('#body').bind('paste', function(e){
				  var data = e.originalEvent.clipboardData.getData('text/plain') + this.value;
					if(escape(data).indexOf("%u")<0){
						$(this).prop("maxlength", 1224);

					} else {
						$(this).prop("maxlength", 536);
					}
	  		})


    			$('#top').mousedown(function(event){
    				if (event.button == 2) return true;
    				window.ncHit(event.clientX, event.clientY);
    			})

    			$('#close,#cancel').mousedown(function(event){
    				event.stopPropagation();
    			}).click(function(){
    				window.showSendPop(false);
    			});


    			$('#Num').bind("onCheck", function(){
					//var num = window.getSelectCount(window.getGuid());
					
                    var selectedList = window.getSelectContacts(window.getGuid());
                    var num  = 0;
                    if (selectedList != null) {
                        num = selectedList.length;
                    }
    				$(this).text(num);
    			});
				
				new WebKitMutationObserver(function(mutations) {
					var list = document.querySelectorAll('.addressContainer li');
					$('#selectedCount span').text(list.length);
				}).observe(document.querySelector('.addressContainer'), {childList:true});
		


    			$('#selContact').click(function(){
    				$('#selPrompt').show();
    				$('#selgroup div').text(langs["smsendpop_selContact_all_lang"]);
    				$('#searchinput').val('');
					$.ajax({
						url: "http://vivozs/mmssms/getContacts",
						type: "POST",
						data: {
							group : "all",
							guid : window.getGuid()
						},
						success: function (msg) {
							FillList(msg);
							$('#Num').trigger('onCheck');
						}
					})
					$.ajax({
						url: "http://vivozs/mmssms/getContactsGroup",
						success: function (msg) {
	
							var json = JSON.parse(msg);
							if (json === null) {
							//	$('.content-inner').html('');
								return;
							};

							var	html = template('groupsinfo', {
								list: json,
								CefSimInfo: CefSimInfo
							});


							$('#grouplist').html(html);
						}
					})
    			});

    			$('#promptclose').click(function(){
    				$('.content-inner').empty();
    				$('#selPrompt').hide();
    			});

    			$('#selgroup').click(function(){
    				var grouplist = $('#grouplist')
    				if ($('#grouplist').is(":visible")) {
    					grouplist.hide();
    				}else{
    					grouplist.show();
    				}
    			});

    			$('#grouplist').on("click", "li", function(e){
    				var group_ = $(this).attr("data-groupId");
    				$('#selgroup div').text($(this).text());
    				$('#selgroup').attr('data-groupId', group_);
    				$(this).parent().hide();
    				
    				$.ajax({
						url: "http://vivozs/mmssms/getContacts",
						type: "POST",
						data: {
							group : group_,
							guid : window.getGuid()
						},
						success: function (msg) {
							FillList(msg);
						}
					})

    			});


    			$('.content-inner').on("click", "li", function(e){
    				if (e.originalEvent.srcElement.type == "checkbox") return;
    				$(this).children('input').click();
    			});

    			$('.content-inner').on("change", "input", function(e){

					if ($('.content-inner li:visible input:not(:checked)').length === 0) {
						$('#all').prop("checked", true);
					} else {
						$('#all').prop("checked", false);
					}
					var dataId = $(this).parent().attr("id");
					window.selectContact(window.getGuid(), parseInt(dataId), $(this).prop('checked'));
    				$('#Num').trigger('onCheck');

    			});

    			$('#all').change(function(){
    				$('.content-inner li input').prop('checked', $(this).prop('checked'));

    				var dataIdArray = new Array();
    				$('.content-inner li').each(function(){
    					dataIdArray.push(parseInt($(this).attr('id')))
    				})

					window.selectContacts(window.getGuid(), dataIdArray, $(this).prop('checked'));
					$('#Num').trigger('onCheck');

    			});

    			$('#promptok').click(function(){
    				$('#selPrompt').hide();

                    $('.addressContainer li').each(function(){
                      var dataId = parseInt($(this).attr('data-dataId'));
                      if (dataId == -1) {
                        return;
                      };
                      $(this).remove();
                    })
                    var selectedList = window.getSelectContacts(window.getGuid());
                    var addrElement = $('#address');

                    for(var i=0 ; i<selectedList.length ; i++){
                      var dataId = selectedList[i]["dataId"];
                      var address = selectedList[i]["address"];
                      var name = selectedList[i]["name"];
					  if( address == "" || !address.isPhoneNumber()){
						window.selectContact(window.getGuid(), parseInt(dataId), false);
						$('#tips').text(langs["smssendpop_isphonenumber_error_lang"]);
						$("#tips").fadeIn(500).fadeOut(2000);
						continue;
					  }
                      var item = '<li data-dataId="' + dataId +  '"><label title="' + address + '">' + name + 
                            '</label><div class="delete-contact"></div></li>'
                      $(item).insertBefore(addrElement);
                    }

                    $('.content-inner').empty();
                    addrElement.focus();
    			});


    			$('#searchresult').on("click", "li", function(){
    				var dataId = $(this).attr("data-dataId");
    				var address = $(this).children()[1].innerHTML;
    				var name = $(this).children()[0].innerHTML;
					if(address != "" && address.isPhoneNumber()){
						var obj = $('.addressContainer').find('li[data-dataId="' + dataId + '"]');
						if (obj.length === 0) {
							var item = '<li data-dataId="' + dataId +  '"><label title="' + address + '">' + name + 
								'</label><div class="delete-contact"></div></li>'
							$(item).insertBefore($('#address'));
							window.selectContact(window.getGuid(), parseInt(dataId), true);
						};
					}else{
						$('#tips').text(langs["smssendpop_isphonenumber_error_lang"]);
						$("#tips").fadeIn(500).fadeOut(2000);
					}

    				$('#address').val('').focus();
    				$('#searchresult').hide();
    			})



    			$('.addressContainer').on("input", "input", function(e){
    				if (this.value.trim() == "") {
    					$('#searchresult').html("");
    					$('#searchresult').hide();
    					return;
    				};
    				$.ajax({
						url: "http://vivozs/mmssms/searchContactsMin",
						type: "POST",
						data: {
							key : this.value,
						},
						success: function (msg) {
							var json = JSON.parse(msg);
							if (json === null) {
								$('#searchresult').html("");
								$('#searchresult').hide();
								return;
							}
							var	html = template('searchresult_', {
								list: json
							});
							$('#searchresult').html(html);
							$('#searchresult').show().focus();
						}
					})
    			});

    			$('.addressContainer').on("keydown", "input", function(e){
    				if ((e.which == 8)  && ($(this).val() == "")) {
    					var dataId = $(this).prev().attr('data-dataId');
    					if (dataId !== undefined) {
    						window.selectContact(window.getGuid(), parseInt(dataId), false);
    						$(this).prev().remove();
    					};
    				} else if (e.which == 13) {

					  	var vals = $(this).val();
					  	vals = vals.trim();
					  	var numbers = vals.split(/，|,/);
					  	if(numbers.length == 0) return;
					  	for(var i=0 ; i<numbers.length ; ++i){
					  		var val = numbers[i];
							val = val.trim();
					  		if(val=="") {
					  			continue;
					  		}
					  		if (!val.isPhoneNumber()) {
					  			$.ajax({
									url: "http://vivozs/mmssms/getContactNumbers",
									type: "POST",
									data: {
										key : val,
									},
									success: function (msg) {
										var root = msg;
										if(typeof msg == "string"){
											root = JSON.parse(msg);
										}
										var name = root["name"];
										var json = root["addrs"];
										if(json == null || json.length == 0) {
											$('#tips').text(langs["smssendpop_isphonenumber_error_lang"]);
											$("#tips").fadeIn(500).fadeOut(2000);
											return ;
										}
										for (var i = 0; i<json.length; i++){
											if(json[i]["addr"] == "" || !json[i]["addr"].isPhoneNumber()){
												$('#tips').text(langs["smssendpop_isphonenumber_error_lang"]);
												$("#tips").fadeIn(500).fadeOut(2000);
												continue ;
											}
											//InsertContact(json[i]["addr"],json[i]["dataId"]);
											var obj = $('.addressContainer').find('label[title="' + json[i]["addr"] + '"]');
											if(obj.length === 0) {
												window.selectContact(window.getGuid(), parseInt(json[i]["dataId"]), true);
												var item = '<li data-dataId="'+json[i]["dataId"]+'"><label title="' + json[i]["addr"] + '">' + name + '</label><div class="delete-contact"></div></li>'
	    										$(item).insertBefore($('#address'));
											}
										}
									}
								})
								continue;
					  		};
							InsertContact(val);
					  	}
	    				$('#address').val('').focus();

	    				$('#searchresult').hide();
    				};
    			});


				
    			$('.addressContainer').on("click", "li .delete-contact", function(e){
    				var dataId = $(this).parent().attr('data-dataId');
					window.selectContact(window.getGuid(), parseInt(dataId), false);
    				$(this).parent().remove();
    				e.stopPropagation();
    			})

    			$('.addressContainer').click(function(){
    				$('#address').focus();
    			})

				$('#sim1, #sim2').bind('simStateChange', function(){
					if (CefSimInfo.slot0 == 1) {
						$("#sim1").removeAttr("disabled");
					} else {
						$("#sim1").attr("disabled", "disabled");
					}

					if (CefSimInfo.slot1 == 1) {
						$("#sim2").removeAttr("disabled").show();
					} else {
						$("#sim2").attr("disabled", "disabled");
					}

					if (CefSimInfo.gemini_support == false) {
						$("#sim1").text(langs["smssendpop_cefsiminfo_send_lang"]);
						$("#sim2").hide();
					} else {
						$("#sim1").html("<span class=\"arial\">SIM1</span>" + langs["smssendpop_cefsiminfo_sim1send_lang"]);
						$("#sim2").show();
					}
				});

				$('#sim1, #sim2').bind("click", function(){

					var obj = $('.addressContainer').find('li');
					if (obj.length === 0) {
						$('#tips').text(langs["smssendpop_addressContainer_unperson_lang"]);
						$("#tips").fadeIn(500).fadeOut(2000);
						return ;
					};

					var body = $('#body').val();
					if (body == ""){
						$('#tips').text(langs["smssendpop_body_none_tip_lang"]);
						$("#tips").fadeIn(500).fadeOut(2000);
						return;
					}
					var slot = $(this).attr("data-slot");

					var items = [];
					obj.each(function(){
						items.push($(this).find('label').attr('title'));
					})
					
					
					var postData = {
						guid : window.getGuid(),
						body : body,
						address : items,
						slot : slot
					}

					$.ajax({
						url: "http://vivozs/mmssms/sendsms",
						type: "SEND",
						data: encodeURI(JSON.stringify(postData)),
						success: function (msg) {
							if (msg == "error") { console.error("SendSmsCall")};
							var obj = JSON.parse(msg);
							$.each(obj["sms"], function(i, _id){
								var sms = window.getSmsObject(_id);
								if (sms) {
									var html = template('OneSms', {
										sms: sms
									});
									$("#session").append(html);
								};
							})

							var elem = document.getElementById('session');
							elem.scrollTop = elem.scrollHeight;
						}
					});

					$('#body').val("");
					$('#body').trigger('change');
				});

				$('#sim1, #sim2').trigger('simStateChange');

				var location_search = decodeURI(window.location.search) + window.location.hash;
				var json = location_search.substring(1, location_search.length);
				try{
					var obj = JSON.parse(json);
					if (obj["type"] === "newSms") {
						var item = '<li data-dataId=' + obj["dataId"] 
									+ '><label title="' + obj["address"] + 
									'">' + window.getNameByAddress(obj["address"]) 
									+ '</label><div class="delete-contact"></div></li>'
						$(item).insertBefore($('#address'));
						var sms = window.getSmsObject(obj['_id']);
						if (sms) {
							var html = template('OneSms', {
								sms: sms
							});
							$("#session").append(html);
						};
						if (obj["dataId"] !== -1) {
							window.selectContact(window.getGuid(), obj["dataId"], true);
						};
					} 
					else if (obj["type"] === "sendto") {
						var list = obj["datas"].split(',');
						if(obj["way"]==="id"){
							$.each(list, function(i, key){
								if(key=="")
									return;
								var address = window.getAddressByDataId(key);
								if (address !== "") {
									window.selectContact(window.getGuid(), parseInt(key), true);
								};
								var item = '<li data-dataId=' +  key
									+ '><label title="' + address + '">' + window.getNameByDataId(key) 
									+ '</label><div class="delete-contact"></div></li>'
									$(item).insertBefore($('#address'));
							})
						}
						else if(obj["way"]==="num"){
							$.each(list, function(i, key){
								var dataId = window.getDataIdByAddress(key);
								if (dataId !== -1) {
									window.selectContact(window.getGuid(), parseInt(dataId), true);
								};
								var item = '<li data-dataId=' +  dataId
									+ '><label title="' + key + '">' + window.getNameByAddress(key) 
									+ '</label><div class="delete-contact"></div></li>'
									$(item).insertBefore($('#address'));
							})
						}
					} 
					else if (obj["type"] === "forward") {
						var text = obj["body"];
						var $body = $('#body');
						if(escape(text).indexOf("%u")<0) {
							$body.prop("maxlength", 1224);
						} 
						else {
							$body.prop("maxlength", 536);
						}
						$body.text(text);
						$body.trigger('change');
					};
				} catch(err){
					console.log(err)
				}
				
				$('#Num').trigger('onCheck');
    		});
    	})();

    	function JSOnSimStateChange(json){
			if (json["slot0"] == 1) {
				$("#sim1").removeAttr("disabled");
			} else {
				$("#sim1").attr("disabled", "disabled");
			}

			if (json["slot1"] == 1) {
				$("#sim2").removeAttr("disabled").show();
			} else {
				$("#sim2").attr("disabled", "disabled");
			}
		}


    	function onSearch(obj){
    		if (obj.value === '') {
    			var groupId = $('#selgroup').attr('data-groupId');
    			$('#grouplist li[data-groupId='+groupId+']').trigger('click');
    			return;
    		};
			$.ajax({
				url: "http://vivozs/mmssms/searchContacts",
				type: "POST",
				data: {
					key : obj.value,
					guid : window.getGuid()
				},
				success: function (msg) {
					FillList(msg);
				}
			})
    	}


		function JSSendSmsResult(id, success){
			var elem = document.getElementById(id);
			if (success) {
				$(elem).find('.status').text("");
			}
			else {
				$(elem).find('.status').text(langs["smssendpop_jssend_fail_lang"]).attr("data-status", "5");
			}
		}

		function JSNewSms(sms_id){
			var sms = window.getSmsObject(sms_id);
			if (sms) {

				var html = template('OneSms', {
					sms: sms
				});

				$("#session").append(html);

				var contentelem = document.getElementById('session');
				contentelem.scrollTop = contentelem.scrollHeight;
			};
		}

		function FillList(msg){

			var json = JSON.parse(msg);
			if (json === null) return;
			$('#all').prop('checked', json['all']);
			if (json['list'] === undefined || json['list'] === null) {
				$('.content-inner').empty();
				return ;
			};
			
			var	html = template('contactsinfo', {
				list: json['list']
			});
			$('.content-inner').html(html);
		}

		function InsertContact(val) {
			var searchresult = $('#searchresult li:first-child');
			var obj = $('.addressContainer').find('label[title="' + val + '"]');
			var dataId =-1;
			var name="";
			if (obj.length === 0) {
				if(searchresult.length !=0 ){
					dataId = searchresult.attr("data-dataId");
					val = searchresult.children()[1].innerHTML;
					var name = searchresult.children()[0].innerHTML;
					window.selectContact(window.getGuid(), parseInt(dataId), true);
					var item = '<li data-dataId="'+dataId+'"><label title="' + val + '">' + name + '</label><div class="delete-contact"></div></li>'
	    			$(item).insertBefore($('#address'));
	    			return
				}
				$.ajax({
					url: "http://vivozs/mmssms/getContactName",
					type: "POST",
					data: {
						key : val,
					},
					success: function (msg) {
					    dataId = window.getDataIdByAddress(val);
						window.selectContact(window.getGuid(), parseInt(dataId), true);
						var item = '<li data-dataId="'+dataId+'"><label title="' + val + '">' + msg + '</label><div class="delete-contact"></div></li>'
	    				$(item).insertBefore($('#address'));
					}
				});
			}
		}
    </script>


    <script id="OneSms" type="text/html">
    	<% if(sms["encrypted"]==true) {%>
			<li id="<%= sms["_id"] %>" style="display:none">
		<%} else {%>
			<li id="<%= sms["_id"] %>">
		<%}%>
			<div class="speech" cssType="<%= sms["cssType"]%>">
				<input type="checkbox" />
				<div class="time" ><%= sms["date"].toMyString()%></div>
				<div class="body"><%=#sms["body"].escape()%></div>
				<div class="status" data-status="<%= sms["type"]%>"><%= sms["status"]%></div>
				<div class="slot" data-slot="<%= sms["slot"]%>"></div>
				<% if (sms["type"] != 3) { %>
					<span class="copy">{{smssendpop_onesms_started_lang}}</span>
				<% } %>
				<span class="forward">{{smssendpop_onesms_sendpost_lang}}</span>
				<span class="del">{{smssendpop_onesms_delete_lang}}</span>
			</div>
		</li>
	</script>

	<script id="searchresult_" type="text/html">
		<% for (var i = 0; i < list.length; i++) { %>
			<li data-dataId="<%= list[i]["dataId"]%>">
				<label><%= list[i]["name"]%></label>
				<label><%= list[i]["addr"]%></label>
			</li>
		<% } %>
	</script>

	<script id="contactsinfo" type="text/html">
		<% for (var i = 0; i < list.length; i++) { %>
			<li id="<%= list[i]["dataId"]%>">
				<input type="checkbox" <%= list[i]["checked"]%>/>
				<label>
					<span class=<%= list[i]["nSimId"]%>></span>
					<span><%= list[i]["name"]%></span>
				</label>
				<label class="phoneNumber"><%= list[i]["addr"]%></label>
				<label class="area"><%= list[i]["area"]%></label>
			</li>
		<% } %>
	</script>

    <script id="groupsinfo" type="text/html">
        <li data-groupId="all">{{smssendpop_groupsinfo_allpeople_lang}}</li>
        <li data-groupId="starred">{{smssendpop_groupsinfo_started_lang}}</li>
        <% for (var i = 0; i < list.length; i++) { %>
            <li data-groupId="<%= list[i]["groupId"]%>"><%= list[i]["name"]%></li>
        <% } %>

		<% if (CefSimInfo.gemini_support == false) { %>
			<li data-groupId="sim1">SIM</li>
		<% } else  { %>
			<li data-groupId="sim1">SIM1</li>
			<li data-groupId="sim2">SIM2</li>
		<% } %>
		
	</script>


	<script id="MmsSms" type="text/html">
		<% for (var i = 0; i < list.length; i ++) { %>
			<li id="<%= list[i]["_id"] %>" >
				<div class="speech" cssType="<%= list[i]["cssType"]%>">
					<input type="checkbox" />
					<div class="time" ><%= list[i]["date"].toMyString()%></div>
					<div class="body"><%=#list[i]["body"].escape()%></div>
					<div class="status" data-status="<%= list[i]["type"]%>"><%= list[i]["status"]%></div>
					<div class="<%= list[i]["slot"]%>"></div>
				</div>
			</li>
		<% } %>
	</script>

    <script type="text/javascript">
        var langs = [];
        langs["smsendpop_selContact_all_lang"] = '{{smsendpop_selContact_all_lang}}';
        langs["smssendpop_isphonenumber_error_lang"] = '{{smssendpop_isphonenumber_error_lang}}';
        langs["smssendpop_cefsiminfo_send_lang"] = '{{smssendpop_cefsiminfo_send_lang}}';
        langs["smssendpop_cefsiminfo_sim1send_lang"] = '{{smssendpop_cefsiminfo_sim1send_lang}}';
        langs["smssendpop_addressContainer_unperson_lang"] = '{{smssendpop_addressContainer_unperson_lang}}';
        langs["smssendpop_body_none_tip_lang"] = '{{smssendpop_body_none_tip_lang}}';
        langs["smssendpop_jssend_fail_lang"] = '{{smssendpop_jssend_fail_lang}}';
    </script>

</body>  
</html>  
