function preRequest() {

                var http_request = false;

                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        // See note below about this line
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                            http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }
                if (!http_request) {
                  alert('Ошибка при создании XMLHTTP'); return false;
                }
		return http_request;
	    }

function tofind(a){var b=document.getElementById('find').value;var ur=a.href; var url=ur.replace("&q=&","&q="+b+"&");window.location.href=url;}
            function makeRequest(mysid,fav) {
if(fav==0){del='d' + mysid; document.getElementById(del).innerHTML='Подождите';}
url = 'http://' +document.domain+ '/js/to.php?sid=' + mysid + '&fav=' + fav;
http_request = preRequest();
mysid1='a' + mysid;
if(fav!=0) document.getElementById(mysid1).innerHTML= "Подождите";
                http_request.onreadystatechange = function() {
	// 4 - данные готовы для обработки
                if (http_request.readyState == 4) {
                      if (http_request.status == 200) {
if(fav!=0) document.getElementById(mysid1).innerHTML= 'Песня добавлена. > см. сбоку.';
var art= http_request.responseXML.getElementsByTagName('art').item(0).firstChild.data;
var id= http_request.responseXML.getElementsByTagName('id').item(0).firstChild.data;
var nam= http_request.responseXML.getElementsByTagName('name').item(0).firstChild.data;
if(fav==2){document.getElementById('al1').innerHTML=document.getElementById('al1').innerHTML + 'Добавлено новое видео, чтобы его увидеть нажмите сохранить';}
else{
if(art=="del"){del='d' + id; document.getElementById(del).innerHTML='';}
else document.getElementById('al1').innerHTML=document.getElementById('al1').innerHTML + '<i id="d' +id+ '">&nbsp;<b><a href="javascript:makeRequest(' + id +',0);">—</a></b> <a href="http://www.allmp.ru/' + art + '/" class="d' +id+ '">' + art + '</a> - <a href="http://www.allmp.ru/' + art + '/' + id +'.htm" class="d' +id+ '">' + nam + '</a><br></i>';
}
cltab('al');
                    } else {
                        document.getElementById(mysid).innerHTML='er';
                    }
            }
}
                http_request.open('POST', url, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
                http_request.send('u=1');

            }
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 ""
}
is_show='null';
function cltab(som){
var i=0;
var my= new Array();
my[1]='li';
my[2]='al';
my[3]='na';
while(i<3){
i++;
if(my[i]==som){


if((window.is_show=="null")&&(som=="al")&&(getCookie("allmp")!="")){ showall(); window.is_show="yes";}
document.getElementById(som).style.backgroundColor='5982b8';
document.getElementById(som).style.color='#ffffff';

id1=som + '1';
document.getElementById(id1).style.display="";}else{
var tob = new String(my[i]);
to1=tob + '1';

document.getElementById(tob).style.backgroundColor='ffffff';
document.getElementById(tob).style.color='#003399';
document.getElementById(to1).style.display='none';
}

}
}

 function showall() {

url = 'http://' +document.domain+ '/js/show.php';

http_request = preRequest();

document.getElementById('al1').innerHTML= "Подождите идет загрузка";
                http_request.onreadystatechange = function() {
	// 4 - данные готовы для обработки
                if (http_request.readyState == 4) {
                      if (http_request.status == 200) {

document.getElementById('al1').innerHTML=http_request.responseText + '<b><a href="http://www.allmp.ru/save.htm">Сохранить</a></b> beta версия.';


                    } else {
                        document.getElementById('al1').innerHTML='er';
                    }
            }
}
                http_request.open('POST', url, true);
                http_request.send('u=1');

            }

            function alertContents(sid) {

                if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                       alert(http_request.responseText);
document.getElementById(sid).innerHTML='er';
                    } else {
                        document.getElementById(sid).innerHTML='er';
                    }
                }

            }
function allmp_setCookie(cookieName, cookieContent, cookieExpireTime){
    if(cookieExpireTime>0){
        var expDate=new Date()
        expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60)
        var expires=expDate.toGMTString()
        document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"; expires="+expires
    }else{
        document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"";
    }
}



function setna(){
var ric=document.getElementById('wrich').checked;
var p=document.getElementById('wp').value;
document.getElementById('nasi').innerHTML="Настройки сохранены. Чтобы увидеть изменения перезагрузите страницу.";
allmp_setCookie("allmp_rich",ric,300);
allmp_setCookie("allmp_p",p,2400);
}

