// JavaScript Document
// Определяем браузер пользователя

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

//var today = new Date();
//var the_date = new Date("December 31, 2023");
/*var the_cookie_date = today.toGMTString();
var the_cookie = "width="+ screen.width +"height"+ screen.height;
var the_cookie = the_cookie + ";expires=" + the_cookie_date;
document.cookie=the_cookie;*/
// Функция выдаёт объект с указанным
// ей названием.

// Вход:
// myid - название объекта

// Выход: объект.

function getelementbyid(myid) {
   if (isNS4){
        objElement = document.layers[myid];
     }else if (isIE4) {
        objElement = document.all[myid];
     }else if (isIE5 || isNS6) {
             objElement = document.getElementById(myid);
     }
return(objElement);
}

function antispam() {
  var el = document.getElementsByTagName("a");
  var text = '';
  for (i=0; i < el.length+1; i++) {
    if (el[i] && el[i].toString().indexOf('mailto') !=-1) {
      url = base64Decode(el[i].toString().substring(7));
      if (base64Decode(el[i].innerHTML).match('^\\s*([-a-zA-Z0-9_.]+@[-a-zA-Z0-9_]+(\\.[-a-zA-Z_]+)+)+\\s*$'))
        text = base64Decode(el[i].innerHTML);
      else
        text = el[i].innerHTML;
      el[i].outerHTML = "<a href='mailto:"+url+"'>"+text+"</a>";
      el[i].innerHTML = text;
      el[i].href = "mailto:"+url;
    }
  }
}

function remove_option(name, table, id) {
  var el = getelementbyid(name);
  location.href='?action=removelink&id='+id+'&dbtable='+table+'&item='+el.value;
}

function selectall(id) {
  var el = getelementbyid(id);
  for(var i=0;i<el.length;i++)
    el[i].selected=true;
}

function appendToSelect(typeid, urlid, pdfid, titleid) {
  var theSel = getelementbyid("add_info");
  var type = getelementbyid(typeid);
  var url = getelementbyid(urlid);
  var pdf = getelementbyid(pdfid);
  var title = getelementbyid(titleid);
  var place = getelementbyid('ajax_addlink');
  
  if (type.value == 'pdf') {
    if (url.value != '') {
      path = url.value.split("\\");
      theSel.appendChild(new Option("PDF="+path[path.length-1]+","+title.value, "PDF="+path[path.length-1]+","+title.value));
    }
    else alert('Не выбран файл');
  }
  else if (type.value == 'url') {
    if (url.value != '')
      theSel.appendChild(new Option("URL="+url.value+","+title.value, "URL="+url.value+","+title.value));
    else alert('Не указан адрес ссылки');
  }
  else {
    if (url.value != '')
      theSel.appendChild(new Option(type.value.toUpperCase()+"="+url.value, type.value.toUpperCase()+"="+url.value));
    else alert('Не указано числовое значение');    
  }
  
  place.innerHTML = '';
}

function appendToSelect2(file, title) {
  var theSel = getelementbyid("add_info");
  theSel.appendChild(new Option("PDF="+file+","+title, "PDF="+file+","+title));
}

function removeFromSelect() {
  var theSel = getelementbyid("add_info");
  var selIndex = theSel.selectedIndex;
  if (selIndex != -1) {
    for(i=theSel.length-1; i>=0; i--)
    {
      if(theSel.options[i].selected)
      {
        theSel.options[i] = null;
      }
    }
    if (theSel.length > 0) {
      theSel.selectedIndex = selIndex == 0 ? 0 : selIndex - 1;
    }
  }
}

function viewHTML(id) {
  var theEl = getelementbyid(id);
  my_window= window.open ("","mywindow1","status=0,width=640,height=480");
  my_window.document.write('<link rel=\"stylesheet\" href=\"/styles/uni-index.v11.css\" type=\"text/css\">');
  my_window.document.write('<body style="background:#ffffff;padding:20px"><table><tr><td>'+theEl.value+'</td></tr></table></body>');
}

function insertImage(id, dbtable, recid) {
  var theEl = getelementbyid(id);
  my_window= window.open ("","mywindow1","status=1,width=500,height=200");
  my_window.document.write("<head><meta http-equiv='content-type' content='text/html; charset=windows-1251'></head><body><form enctype='multipart/form-data' action='/admin/?action=insertimage&dbtable="+dbtable+"&id="+recid+"'"+
      " method=post>Выберите файл: <input name=file type=file><br>"+
      "Описание: <input name=title><br>"+
      "<input value='Ok' type=submit>"+
      "</form></body>");
}

function insertPdf(id, dbtable, recid) {
  var theEl = getelementbyid(id);
  my_window= window.open ("","mywindow1","status=0,width=500,height=200");
  my_window.document.write("<form enctype='multipart/form-data' action='/admin/?action=insertpdf&dbtable="+dbtable+"&id="+recid+"'"+
      " method=post>Выберите файл: <input name=file type=file><br>"+
      "Описание: <input name=title><br>"+
      "<input value='Ok' type=submit>"+
      "</form>");
}

function run_movie(swf,w,h) 
{ 
text = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + w + "\" height=\"" + h + "\">\r\n";
text+= "<param name=\"allowScriptAccess\" value=\"sameDomain\">\r\n";
text+="<param name=\"movie\" value=\"" + swf + "\">\r\n";
text+="<param name=\"menu\" value=\"false\">\r\n";
text+="<param name=\"quality\" value=\"high\">\r\n";
text+="<param name=\"bgcolor\" value=\"#ffffff\">\r\n";
text+="<embed src=\"" + swf + "\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"" + w + "\" height=\"" + h + "\" menu=\"false\" bgcolor=\"#ffffff\" allowScriptAccess=\"sameDomain\">\r\n";
text+="</object>\r\n";

document.write(text);
return 1;
} 

function deleteprofile() {
  var answer = confirm('Вы уверены, что хотите удалить Ваш аккаунт?');
  if (answer) location.href = '?action=delprofile';
}

function fadetext(el, text) {
  setOpacity(el,0);
  getelementbyid(el).innerHTML = text;

	for (var i=0; i<100; i++)
		setTimeout('setOpacity("'+el+'",'+i+')',10*i);
	return false;
}

function setOpacity(el,value)
{
  getelementbyid(el).style.opacity = value/100;
	getelementbyid(el).style.filter = 'alpha(opacity=' + value + ')';
}

