
sA = ''; // РЕЙСЫХИ

function searchSet(id){
 for(var i=0; i<sA.length; i++){
  document.getElementById('p' + i).className = 'm1';
 }
 document.getElementById('p' + id).className = 'm2';

// document.getElementById('sf').action = sA[id][3];
 document.getElementById('s').value = sA[id][3];

// document.getElementById('sq').name = sA[id][4];
 if (sA[id][4]) {
  document.getElementById('c').value = sA[id][4];
 } else {
  document.getElementById('c').value = '';
 }

 if (sA[id][5]) {
  document.getElementById('site_filter').style.display = 'block';
  document.getElementById('f').value = sA[id][5];
 } else {
  document.getElementById('site_filter').style.display = 'none';
  document.getElementById('f').value = '';
 }

 if (sA[id][2]) {
 document.getElementById('sl').style.display='';
 document.getElementById('st').innerHTML='';
 document.getElementById('sl').src = 'http://404img.ru/x.gif'; // пока не загрузился новый, сбрасываем предыдущий
 document.getElementById('sl').src = 'http://404img.ru/logos/' + sA[id][2];
 }else{
  document.getElementById('sl').style.display='none';
  document.getElementById('st').innerHTML=sA[id][0];
 }
 document.getElementById('sl').title = sA[id][0]; 
 document.getElementById('sh').href = sA[id][1];
 if (document.getElementById('sq').value) {} else {document.getElementById('sq').focus()};

}

function qAdd (q){
	var totalQ = getCookie('historySave');

	if (!totalQ) {totalQ = 0}
	q = q.replace("'", '%27');
	
	var qCookie = getCookie('history');
	currQList = new Array();
	if (qCookie) {
		currQList = qCookie.split("','");
	}
	if (q) {
		for(var i=0; i<currQList.length; i++){
			if (currQList[i].toLowerCase() == q.toLowerCase()){
				currQList.splice(i,1);
		       		break;
			}
		}
		        
		if (currQList.length == totalQ) {
			currQList.pop();
		}
		currQList.unshift(q);
		saveResult(currQList);
	///	currQList = currQList.join("','");
	//	setCookie('history',currQList, 77777);
	}
}

function qDelete (id) {
	var qCookie = getCookie('history');
	currQList = new Array();
	if (qCookie) {
		currQList = qCookie.split("','");
	}
	if (currQList[id]){
            currQList.splice(id,1);
            if (currQList.length) {
              saveResult(currQList);
            } else {
	      qDeleteAll();
            }
	}
}

function qDeleteAll () {
        saveResult();
}

function saveResult (result){
	if (result) {
		result = result.join("','");
		setCookie('history',result, 77777);
	} else {
		deleteCookie('history');
	}
}

  function sSubmit () {
    if (getCookie('historySave') > 0) {
      qAdd (document.getElementById('sq').value);
      show_history();
    }
    if (getCookie('target_blank') == 'yes') {
        document.getElementById('sf').target=Math.round(Math.random()*100000);
    } else {
        document.getElementById('sf').target='';
    }
    
    document.getElementById('sf').submit();
  }


function setCookie(cookieName, cookieContent, cookieExpireTime, cookiePath){
	if(cookiePath == undefined){cookiePath = '/'}
	var expires='Mon, 05 Oct 2037 09:24:00 GMT';
	document.cookie=cookieName+"="+escape(cookieContent)+";path="+escape(cookiePath)+";expires="+expires+";domain=www.404.ru;";
}

function getCookie(cookieName){
	var ourCookie=document.cookie
	if(!ourCookie || ourCookie=="")return ""
	ourCookie=ourCookie.split(";")
	var i=0
	var Cookie
	while(i<ourCookie.length){
		Cookie=ourCookie[i].split("=")[0]
		if(Cookie.charAt(0)==" ")
		Cookie=Cookie.substring(1)
		if(Cookie==cookieName){
			return unescape(ourCookie[i].split("=")[1])
		}
		i++
	}
	return ""
}

function deleteCookie(cookieName, cookiePath){
	if(cookiePath == undefined){cookiePath = '/'}
	document.cookie=cookieName+"="+getCookie(cookieName)+";path="+escape(cookiePath)+";expires=Thu, 01-Jan-1970 00:00:01 GMT;domain=www.404.ru";
}

function SKD(block, style){
 if(document.getElementById){
  if (style) {
   document.getElementById(block).style.display = style;
  } else if (document.getElementById(block).style.display == 'none') {
   document.getElementById(block).style.display = 'block';
  } else {
   document.getElementById(block).style.display = 'none';
  }
 }
}
function SKV(block, style){
 if(document.getElementById){
  if (style) {
   document.getElementById(block).style.visibility = style;
  } else if (document.getElementById(block).style.visibility == 'hidden') {
   document.getElementById(block).style.visibility = 'visible';
  } else {
   document.getElementById(block).style.visibility = 'hidden';
  }
 }
}
function doClick (url) {
var i=new Image; i.src='/click/?'+Math.random()+'&url='+url;
}

var DomainRef = document.referrer;
DomainRef = DomainRef.replace(/^https?:\/\/(www\.)?/i,'');
DomainRef = DomainRef.replace(/\/.*$/i,'');
if (DomainRef.indexOf('404') == -1 && DomainRef) {
    setCookie('domainRef', DomainRef, 77777);
}

if (String(document.location).indexOf("404.ru") == -1) {document.location = 'http://www.404.ru/'}
