var prev = -1;
var next = -1;
var maincount = -1;
function viewList(id, key, count){
	maincount = count;
	if ((key == 0) && (count>1))
	{
		next=1;
		prev=0;
	}
	if (key>0)
	{
		prev = key-1;
		if (key<(count-1))
			next=key+1;
		else next=key
	}
	JsHttpRequest.query('include/core/ajax_list.php',{id: id}, 
  	function(result, errors) {changeList(result, id, key, count);}, true);
	return false;
}
function changeList(result, id, key, count){
	var obj = document.getElementById("list");
	if(!result){
			list.innerHTML = "";
	}
	else{
		var buf = document.getElementById("ind"+key);	
		var bufkey = buf.value;
		
		list.innerHTML = "<span style='color: #B41292; font-weight: bold;'>"+bufkey+"</span><b>"+".</b> "+result['list'];
		for (i=0; i<count; i++)
		{
			var target = "num"+i;
			var buf = document.getElementById(target);
			buf.style.color = "#414D43";
		}

		var buf = document.getElementById("num"+key);
		buf.style.color = "#B41292";
		var buf = document.getElementById("playbut");
		buf.href = "/playlist.php?id="+id;
		var buf = document.getElementById("favorite");
		buf.href = "?op=make_favorite&playlist="+id;
		var buf = document.getElementById("inOpen");
		buf.href = "?op=play_open&playlist="+id;
	}
	return false;
}

function ChangeLinksPrev()
{
	var target = "radio"+prev;
	var buf = document.getElementById(target);
	var id = buf.value;
	viewList(id, prev, maincount);
}

function ChangeLinksNext()
{
	var target = "radio"+next;
	var buf = document.getElementById(target);
	var id = buf.value;
	viewList(id, next, maincount);
}

var buf1=0,buf2=0;
function viewNews(){
	obj = document.getElementById("news");
	if(!obj) return false;
	
		obj.style.display = 'block';


}

function HideAllMenu()
{
	buf1 = 0; 
	setTimeout('HideAllMenuNext()',1000);
}

function HideAllMenuNext()
{
	obj = document.getElementById("news");
	if(!obj) return false;
	if(buf1 == 0)
		obj.style.display = 'none';
}

function ClearFlags()
{
	buf1 = 1; 
}

function ClearFlagsNotice()
{
	buf2 = 1; 
}

function viewNotice(){
	obj = document.getElementById("notice");
	if(!obj) return false;
	obj.style.display = 'block';

}

function HideAllMenu_Notice()
{
	buf2 = 0; 
	setTimeout('HideAllMenuNext_Notice()',1000);
}

function HideAllMenuNext_Notice()
{
	obj = document.getElementById("notice");
	if(!obj) return false;
	if(buf2 == 0)
		obj.style.display = 'none';
}

function setStartPage(elem,mainurl)
{
	elem.style.behavior="url(#default#homepage)"; 
	elem.setHomePage(mainurl); 
	return false;
}	
function setFavorities(mainurl,setFavorities)
{
	window.external.addFavorite(mainurl, setFavorities); return false; 
}
function ViewForgotDiv()
{
	el = document.getElementById('divforgot');
	if (el.style.display == 'none')
		el.style.display  = "block";
	else	
		el.style.display  = "none";

}
function checkNum(toCheck) {
  var isNum = true;


  if ((toCheck == null) || (toCheck == "")) {
    isNum = false;
    return isNum;
  }

  for (j = 0; j < toCheck.length; j++) {
    if ((toCheck.substring(j,j+1) != "0") &&
        (toCheck.substring(j,j+1) != "1") &&
        (toCheck.substring(j,j+1) != "2") &&
        (toCheck.substring(j,j+1) != "3") &&
        (toCheck.substring(j,j+1) != "4") &&
        (toCheck.substring(j,j+1) != "5") &&
        (toCheck.substring(j,j+1) != "6") &&
        (toCheck.substring(j,j+1) != "7") &&
        (toCheck.substring(j,j+1) != "8") &&
        (toCheck.substring(j,j+1) != "9") &&

        (toCheck.substring(j,j+1) != ".") &&
        (toCheck.substring(j,j+1) != "-")) {
      isNum = false;
    }
  }

  return isNum;

}

function CheckIsNum(lang,toCheck)
{	
	if (checkNum(toCheck.value) == false)
		{
			toCheck.value = "0";
			if (lang == 'ru')
				alert('Поле должно быть числовое.');
			else
				alert('This field must Numeric.');
		}	
}

function ChangeLang()
{
	document.changeLang.submit();
}

function SubListOff(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "none";
		if (hidden_count.value > 0)
			SubListff(hidden.value, hidden_count.value);
	}
}

function SubListOn(parent, count)
{
	var i;
	for (i=1; i<=count; i++)
	{
		var div=document.getElementById("div"+parent+"_"+i);
		var hidden = document.getElementById("hidden"+parent+"_"+i);
		var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
		div.style.display = "";
		var img=document.getElementById("img"+hidden.value);
		var buf = img.src.substring(img.src.length-7, img.src.length);
		if (buf != "off.gif")
			SubListOn(hidden.value, hidden_count.value);
	}
}

function SubList(parent, count)
{
	var img=document.getElementById("img"+parent);	
	var buf = img.src.substring(img.src.length-7, img.src.length);

	if (buf == "off.gif")
	{
		img.src = "aimages/blueon.gif";
		img.alt = "Скрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			div.style.display = "";
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			var img=document.getElementById("img"+hidden.value);
			var buf = img.src.substring(img.src.length-7, img.src.length);
			if (buf != "off.gif")
				SubListOn(hidden.value, hidden_count.value);
		}
	}
	else 
	{
		img.src = "aimages/blueoff.gif";
		img.alt = "Раскрыть";
		var i;
		for (i=1; i<=count; i++)
		{
			var div=document.getElementById("div"+parent+"_"+i);
			var hidden = document.getElementById("hidden"+parent+"_"+i);
			var hidden_count = document.getElementById("hidden"+parent+"_"+i+"_count");
			div.style.display = "none";
			if (hidden_count.value > 0)
				SubListOff(hidden.value, hidden_count.value);
		}
	}
}

function MakeOn(url)
{
	var expand = document.getElementById('expand');
	url = url+"&expand="+expand.value;
	location.href=url;
}

function DopImg()
{
        targetId="dopimg";
        targetElement = document.getElementById(targetId);
	if (targetElement.style.display == "none")
	        targetElement.style.display= "";
	else targetElement.style.display = "none";
	location.href = "#dopimg";
}

var curid;
function ContextMenu(event, id){
	if (event.button == 3) return false;

	if (curid)
	{
	        var o = document.getElementById(curid);
	       	o.style.visibility ='';
	}
	curid = id;
        var o = document.getElementById(id);
		o.style.left = event.clientX+document.body.scrollLeft;
        o.style.top = event.clientY+document.body.scrollTop;
        o.style.visibility ='visible';
		preventBubble();
}
function ContextMenuHide(){
	if (curid)
	{
	        var o = document.getElementById(curid);
        	o.style.visibility ='';
	}
}

function highlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor="highlight"
event.srcElement.style.color="white"
}
}

function lowlightie5(){
if (event.srcElement.className=="menuitems"){
event.srcElement.style.backgroundColor=""
event.srcElement.style.color="black"
window.status=''
}
}

function jumptoie5(){
if (event.srcElement.className=="menuitems"){
if (event.srcElement.getAttribute("target")!=null)
window.open(event.srcElement.url,event.srcElement.getAttribute("target"))
else
window.location=event.srcElement.url
}
}

function showImage(src){document.getElementById("bigimage").src=src;}

var u=navigator.userAgent;
var isIE=(u.indexOf("MSIE")>0);
var isMoz=(u.indexOf("Gecko")>0);
var isOp=(u.indexOf("Opera")>0);
if(isOp) isIE=false;

function preventBubble(E){
	if(isIE){
		event.cancelBubble=true;
		event.returnValue=false
	}
	else if(isOp){
		if(DocumentEvent.stopPropagation)DocumentEvent.stopPropagation();
		 else DocumentEvent.preventBubble()
	}
	else {
		if(E.stopPropagation)E.stopPropagation();
		 else E.preventBubble()
	}
}

function showIgor()
{
	var buf = document.getElementById("igor");
	buf.style.visibility="";
}

function ResForm()
{
var buf = document.getElementById("res");
buf.value="add";
document.fAdd.submit();
}
function ResForm2()
{
var buf = document.getElementById("res");
buf.value="add2";
document.fAdd.submit();
}

function ShowForm()
{
	var buf = document.getElementById('orderform');
	var buf2 = document.getElementById('orderformlink');
	if (buf.style.display == "none")
	{
		buf.style.display = "";
		buf2.innerHTML = "Свернуть";
	}
	else
	{
		buf.style.display = "none";	
		buf2.innerHTML = orderformlink;
	}
}


