function ws_readCookie(name){
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0)
return c.substring(nameEQ.length, c.length);
}
return null;
}
function ws_addEvent(obj, type, listener){
if (obj.addEventListener) {
obj.addEventListener(type, listener, false);
}
else
if (obj.attachEvent) {
obj.attachEvent('on' + type, function(){
listener.apply(obj);
});
}
}
var submit_path = '/admin/urlinfo.html?action=edit_save_json';
var get_path = '/admin/urlinfo.html?action=edit_json&url=';
var ws_stylesheet_url = '/share/js-css/seo/seo.css';
if (ws_readCookie('urlinfo') == 'verySecureKey') {
var req;
req = null;
if (window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
}
catch (e) {
}
}
else
if (window.ActiveXObject) {
try {
req = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e) {
try {
req = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {
}
}
}var ws_seo = new function(){
var _this = this;
this.absolute_urls = !(typeof ws_seo_absolute_urls == "undefined");this.page_url = (typeof ws_seo_absolute_urls == "undefined") ? location.href.toString().replace(/\w+:\/\/[^\/]*/, '') : location.href.toString();this.createForm = function(){
_this.upBls = document.createElement('div');
_this.upBls.setAttribute('id', 'ws_upBl');
_this.upBls.innerHTML = '
';
document.body.appendChild(_this.upBls);
content = '';
content += '';
content += '';
content += '';
content += '';
content += '';
_this.ws_status = document.getElementById('ws_status');
_this.sForm = document.getElementById('ws_sForm');
_this.sForm.innerHTML = content;
_this.fields = document.getElementById('ws_added_fields');
_this.sForm.onsubmit = _this.ajaxSubmit;
}
this.showForm = function(){
_this.upBls.style.display = 'block';
_this.sForm.style.display = 'none';
_this.ws_status.style.display = 'block';
_this.ws_status.innerHTML = "Загрузка данных.";
req.open("GET", get_path + encodeURIComponent(location.href), true);
req.onreadystatechange = getAnswer;
req.send(null);
function getAnswer(){
try {
if (req.readyState == 4) {
if (req.status == 200) {
eval('var data = ' + req.responseText);
content = "";
for (i = 0, count = data.values.length; i < count; i++) {
content += '';
}
_this.fields.innerHTML = content;
document.getElementById('ws_title').value = data.title ? data.title : "";
if (data.url)
document.getElementById('ws_url').value = data.url;
document.getElementById('ws_id').value = data.id ? data.id : "";
_this.ws_status.style.display = 'none';
_this.sForm.style.display = 'block';
}
else {
alert("Не удалось получить данные:\n" + req.statusText);
_this.close();
}
}
}
catch (e) {
alert('Ошибка передачи.');
_this.close();
}
}
return false;
}
this.close = function(){
_this.upBls.style.display = 'none';
}
this.ajaxSubmit = function(){
var post = "";
fd = _this.sForm.getElementsByTagName('textarea');
for (i = 0, count = fd.length; i < count; i++) {
post += fd[i].name.replace('ws_', '') + '=' + encodeURIComponent(fd[i].value) + '&';
}
fd = _this.sForm.getElementsByTagName('input');
for (i = 0, count = fd.length; i < count; i++) {
post += fd[i].name.replace('ws_', '') + '=' + encodeURIComponent(fd[i].value) + '&';
}
if (req) {
req.open("POST", submit_path, true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.setRequestHeader("x-requested-with", "XMLHttpRequest");
req.onreadystatechange = getAnswer;
req.send(post);
}
else {
alert('Ajax не поддерживается браузером.');
}
function getAnswer(){
try {
// только при состоянии "complete"
if (req.readyState == 4) {
// для статуса "OK"
if (req.status == 200) {
eval('var answer = ' + req.responseText);
if (answer.answer == true) {
_this.close();
}
else {
alert('Ошибка сохранения. \n' + answer.answer);
}
}
else {
alert("Не удалось отправить данные:\n" + req.statusText);
}
}
}
catch (e) {
alert('Ошибка передачи.');
}
}
return false;
}
}
if (req) {
ws_addEvent(window, 'load', function(){
var ws_stylesheet = document.createElement('link');
ws_stylesheet.setAttribute('rel', 'stylesheet');
ws_stylesheet.setAttribute('type', 'text/css');
ws_stylesheet.setAttribute('media', 'all');
ws_stylesheet.setAttribute('href', ws_stylesheet_url);
document.body.appendChild(ws_stylesheet);
var seoDiv = document.createElement('div');
seoDiv.setAttribute('id', 'ws_seoLink');
seoDiv.innerHTML = 'Редактировать мета-теги';
document.body.appendChild(seoDiv);
ws_seo.button = document.getElementById('ws_seoButt');
ws_seo.button_container = seoDiv;
ws_addEvent(ws_seo.button, 'click', ws_seo.showForm);
ws_seo.createForm();
});
}
else {
alert('Браузер не поддерживает Ajax');
}
function getValue4post(el){
if (el = document.getElementById(el)) {
return encodeURIComponent(el.value);
}
return false;
}
}