
function showDeleteDialog(){$('#delete').dialog({hide:'slide',resizable:false,autoOpen:false,modal:true,buttons:{'Ok':function(){$.ajax({type:'post',url:'index.php?'+Math.random(),data:"command=DoDeleteArticle&id="+articleId});$(this).dialog('close');loadMainPage();},'Отмена':function(){$(this).dialog('close');}}});$('#delete').html('<p>Вы уверены, что хотите удалить статью?</p>');$('#delete').dialog('open');}
function showEditDialog(action){$('#edit').dialog({show:'fold',hide:'fold',autoOpen:false,resizable:false,width:840,height:650,modal:true});$('#edit').load('static/html/editArticle.html?'+Math.random(),function(){if(action=='add'){$('#j_id').attr("value","0");}
if(action=='edit'){$('#j_id').attr("value",dataArticle.id);$('#j_articleName').attr("value",dataArticle.name);$('#j_articleDescription').attr("value",dataArticle.description);$('#j_articleBody').attr("value",dataArticle.body);if(dataArticle.image0!=undefined||dataArticle.image0!='0'){var imageSrc='index.php?'+Math.random()+'&command=GetArticleImage&id='+dataArticle.image0;$('#j_image0').attr("src",imageSrc).attr("height","100");}
$('input[name="fileName0"]').after(dataArticle.fileName0);$('input[name="fileName1"]').after(dataArticle.fileName1);$('input[name="fileName2"]').after(dataArticle.fileName2);$('input[name="fileName3"]').after(dataArticle.fileName3);$('input[name="fileName4"]').after(dataArticle.fileName4);$('input[name="fileName5"]').after(dataArticle.fileName5);$('input[name="fileName6"]').after(dataArticle.fileName6);$('input[name="fileName7"]').after(dataArticle.fileName7);$('input[name="fileName8"]').after(dataArticle.fileName8);$('input[name="fileName9"]').after(dataArticle.fileName9);}
$('#edit').dialog('open');$('#j_articleDescription').focus();var options={url:"index.php?"+Math.random(),timeout:10000,success:function(data,textStatus){$('#edit').dialog('close');$.historyLoad("main");}};});}
function showError(caption,message,width,height){$('#error').dialog({hide:'fold',resizable:false,autoOpen:false,modal:true,buttons:{'Ok':function(){$(this).dialog('close');}}});$('#error').load('static/html/error.html',function(){$('#error').data("width.dialog",width).data("height.dialog",height);$('#caption').html(caption);$('#message').html(message);$('#error').dialog('open');$("#error").effect("pulsate");});}
function showMap(){$('#map').dialog({autoOpen:false,show:'fold',hide:'fold',position:[300,-500],resizable:false,width:525,height:400,modal:true,buttons:{'Закрыть':function(){$(this).dialog('close');}}});$('#map').dialog('open');var html='<div id="YMapsID1" style="height:300px; width:500px;"></div>';$('#map').html(html);var map=new YMaps.Map(document.getElementById("YMapsID1"));map.setCenter(new YMaps.GeoPoint(30.485488,50.451410),18,YMaps.MapType.MAP);map.addControl(new YMaps.TypeControl());map.addControl(new YMaps.ToolBar());map.addControl(new YMaps.Zoom());map.addControl(new YMaps.ScaleLine());var content=document.createElement('span');content.innerHTML="Издательский Дом Асс Медиа";map.openBalloon(new YMaps.GeoPoint(30.485488,50.451410),content);}
function showRegistration(){$('#registration').dialog({hide:'fold',resizable:false,autoOpen:false,width:340,height:360,modal:true,buttons:{'Регистрация':function(){$.ajax({type:'post',url:'index.php?'+Math.random(),dataType:"json",data:"command=DoSaveAccount"+"&name="+encodeURIComponent($('#j_name').val())+"&password="+$.md5(encodeURIComponent($('#j_password').val()))+"&confirmPassword="+$.md5(encodeURIComponent($('#j_confirmPassword').val()))+"&email="+encodeURIComponent($('#j_email').val())+"&firstName="+encodeURIComponent($('#j_firstName').val())+"&lastName="+encodeURIComponent($('#j_lastName').val())+"&captchaResponse="+$('#j_captcha_response').val(),success:function(data,textStatus){update();$('#registration').dialog('close');},error:function(){showError("Ошибка:","Неправильно введены данные или не заполнены обязательные поля!",400,170);}});},'Отмена':function(){$(this).dialog('close');$(this).html('');}}});$('#registration').load('static/html/registration.html',function(){$('#CaptchaCodeImage').attr("src","index.php?"+Math.random()+"&command=GetCaptchaImage");$('#registration').dialog('open');$('#name').focus();});}
function showSignon(){$('#signon').dialog({autoOpen:false,hide:'fold',resizable:false,width:340,height:160,modal:true,bgiframe:true,buttons:{'Войти':function(){$.ajax({type:'post',url:'index.php?'+Math.random(),dataType:"json",data:"command=DoSignon&name="+encodeURIComponent($('#name').val())+"&password="+$.md5($('#password').val()),success:function(data,textStatus){$('#signon').dialog('close');update();},error:function(){showError("Ошибка:","Неправильно введены имя или пароль!",400,100);}});},'Отмена':function(){$(this).dialog('close');$(this).html('');}}});$('#signon').load('static/html/signon.html',function(){$('#signon').dialog('open');$('#name').focus();});}
function showProfile(){$('#profile').dialog({hide:'fold',autoOpen:false,resizable:false,width:340,height:160,modal:true,buttons:{'Изменить':function(){$.ajax({type:'post',url:'index.php?'+Math.random(),data:"command=DoUpdateAccount&firstName="+encodeURIComponent($('#j_firstName').val())+"&lastName="+encodeURIComponent($('#j_lastName').val()),success:function(data,textStatus){update(data.username);$('#profile').dialog('close');}});},'Отмена':function(){$(this).dialog('close');$(this).html('');}}});$('#profile').load('static/html/profile.html',function(){$.ajax({type:'post',url:'index.php?'+Math.random(),data:'command=GetAccount',dataType:"json",success:function(data,textStatus){$('#j_firstName').attr("value",data.firstname);$('#j_lastName').attr("value",data.lastname);}});$('#profile').dialog('open');});}
function showUsers(){$('#users').dialog({hide:'fold',autoOpen:false,resizable:false,width:700,height:500,modal:true,buttons:{'Отмена':function(){$(this).dialog('close');$(this).empty();}}});$('#users').load('static/html/users.html',function(){$('#users').dialog('open');$.ajax({url:'index.php?'+Math.random(),type:'post',async:false,data:"command=GetAccounts",dataType:"json",success:function(data,textStatus){var table='<table width="100%"><tbody>';for(var i=0;i<data.totalCount;i++){table+='<tr>';table+='<td align="left" width="80px">'+data.accountsInfo[i].name+'</td>';table+='<td align="left" width="150px">'+data.accountsInfo[i].email+'</td>';table+='<td align="left" width="150px">'+data.accountsInfo[i].date+'</td>';table+='<td align="left" width="100px">'+data.accountsInfo[i].firstname+'</td>';table+='<td align="left" width="150px">'+data.accountsInfo[i].lastname+'</td>';table+='</tr>';}
$('#users_data').html(table);}});});}
