var isIE = (navigator.appName == "Microsoft Internet Explorer");
var isFireFox = (navigator.appName == "Netscape");
var isOpera = (navigator.appName == "Opera");

var site_url;

if (navigator.appVersion.indexOf('Safari')>0){
	var isSafari = true; isFireFox = false;
}

var Mouse={x:0, y:0, target:null};

if (isFireFox || isSafari){
	document.onmousemove=function(e){ 
		Mouse.x = e.pageX; 
		Mouse.y = e.pageY;
		Mouse.target = e.target;
	}
}

if(isIE){
	document.onmousemove=function(e){
		Mouse.x = event.clientX;
		Mouse.y = event.clientY;
	}
}



function openWindow(addr){
	helpWindow = window.open(addr, '', 'width=480,height=460,resizable');
	helpWindow.focus();
}

function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

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);
}

function getCSSValue(val){
	return val.substring(0, val.length-2);
}

//------------------------------------------------------------------------------------

function showPlayer(trackname, width){
//	alert(site_url);
	document.getElementById("player").innerHTML = "<object id = 'playerObject' type='application/x-shockwave-flash' data='"+site_url+"/lo-fi/player_mp3_maxi.swf' width='"+width+"' height='"+width/6+"'>		<param name='movie' value='"+site_url+ "/lo-fi/player_mp3_maxi.swf' />	<param name='FlashVars' value='mp3="+site_url+"/previews/" + trackname + "&amp;loop=1&amp;autoplay=1&amp;volume=75&amp;showvolume=1&amp;showloading=always&amp;loadingcolor=ff0005&amp;bgcolor1=ffffff&amp;bgcolor2=ffffff&amp;slidercolor1=ff0000&amp;slidercolor2=c51d23&amp;sliderovercolor=797979&amp;buttoncolor=e41700&amp;buttonovercolor=797979&amp;textcolor=797979'/>  </object>";
}

function getXmlHttp(){
  xmlhttp=null;
  try {
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      xmlhttp = false;
    }
  }
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

var screenMessage={
	tm:null,
	msgbox:null
};

screenMessage.show = function(text){
	this.msgbox = document.getElementById("messagebox");
//	clearInterval(this.tm);
//	this.msgbox.style.display="none";
	with (this.msgbox){
		innerHTML = text + "<BR><img src='img/2_computers.gif'>";
		style.display="block";
		if(!isIE){
			style.left= (window.innerWidth - clientWidth)/2 + "px";
			style.top= (window.innerHeight - clientHeight)/2 + "px";
		}else{
			style.pixelWidth=400;
			style.left= (document.body.clientWidth - clientWidth)/2 + "px";
			style.top= 200 + "px";
		}
	}
}

screenMessage.hide = function(duration){
//	clearInterval(this.tm);
	this.msgbox.style.display="none";
//	this.tm = setInterval("screenMessage.cutMessage()", duration);
}

screenMessage.cutMessage = function(){
//	clearInterval(this.tm);
//	this.msgbox.style.display="none";
}


//-----------------------------------------------------------------------------------
function doVote(container, track_id,mark){
    var req = getXmlHttp();
    req.onreadystatechange = function(){ 
       if (req.readyState == 4) {
			if(req.status == 200) {
				alert(document.getElementById(container));
                document.getElementById(container).innerHTML = req.responseText;
            }
        }
    }
    req.open('GET', "ajax.php?menu=DoVote&elem_id="+container+"&track_id="+track_id+"&mark="+mark, true); 
    req.send(null);  // отослать запрос
}
function setDocumentTitle(title){
	document.title = "Plaund.com - " + title;
}
//---------------------------------------------------------------------------------------
var ReturnValue;

function doAJAX(query_string, elem, retFunc){
    var req = getXmlHttp();
    req.onreadystatechange = function(){ 
       if (req.readyState == 4) {
			if(req.status == 200) {
                document.getElementById(elem).innerHTML = req.responseText;
				retFunc.apply();
            }
        }
    }
    req.open('GET', query_string, true);
    req.send(null);  // отослать запрос
}
function doPostAJAX(query_string, elem, retFunc){
    var req = getXmlHttp();
    req.onreadystatechange = function(){ 
       if (req.readyState == 4) {
			if(req.status == 200) {
                document.getElementById(elem).innerHTML = req.responseText;
				retFunc.apply();
            }
        }
    }
    req.open('POST', query_string, true);
    req.send(null);  // отослать запрос
}


function showRightholderInfo(obj, id){
	msg = document.getElementById("messagebox");
	msg.style.display="none";
	var div = document.createElement("DIV");
	div.style.fontWeight="normal";
	div.id='rh_info';
	div.style.position = "absolute";
	doAJAX("infos.php?ajax=1&menu=rightholder&id="+id, "message");
	
	shiftY = (isIE)?document.documentElement.scrollTop:0;
//	if (isSafari) shiftY = document.body.scrollTop;
	
	msg.style.left = Mouse.x+10+"px";
	msg.style.top = (Mouse.y+shiftY+10)+"px";
	msg.style.display="block";
		
	obj.insertBefore(div, obj.nextSibling);
}
function hhh(obj, orderID){
	tbl = document.getElementById("users");
	while (obj.tagName!="TR"){
		obj = obj.parentNode;
	}
	
	rwIdx = obj.sectionRowIndex+1
	rw = tbl.insertRow(rwIdx);
	
	if(typeof lastObj!="undefined") {
		lastObj.innerHTML='';
		lastObj.style.display="none";
	}
	cl = rw.insertCell(0);
	cl.colSpan=10; cl.style.padding="0px 10px 30px 100px";
	cl.id="row"+rwIdx; cl.style.background = "url(../img/niz_alter.png) repeat-x bottom";
	doAJAX(site_url+"/infos.php?menu=order2&id="+orderID+"&items_per_page=1000", "row"+rwIdx);
	lastObj = cl;
//	tbody = document.getElementById('users').getElementsByTagName("TBODY");
//	td = document.getElementById('users').getElementsByTagName("TR");
//	alert(td.length);
//	for(i=0;i<td.length;i++){
//		if(td[i]==s=obj){
//			td[i].style.width="100%";
//		}
//	}

//	for(i=0;i<obj.childNodes.length;i++){
//		alert(obj.cols);
//	}
}

function getOffsetTop(elem){
	height=0;
	while (elem.tagName!='BODY'){
		elem = elem.parentNode;
		height += elem.offsetTop;
	}
	return height;
}

function getOffsetLeft(elem){
	left=0;
	while (elem.tagName!='BODY'){
		left+= elem.offsetLeft;
		elem = elem.parentNode;
		alert(elem.tagName);
	}
	return left;
}

function centerElem(elem){
	elem.style.left = (elem.clientLeft + document.documentElement.clientWidth)/2 + "px";
	elem.style.top = (elem.clientTop + document.documentElement.clientHeight)/2 + "px";
}

function getFormQueryString(frm){
	inputs = frm.getElementsByTagName("INPUT");
	str="";
	for(i=0;i<inputs.length;i++){
		str = str + inputs[i].name + "=" + inputs[i].value + "&";
	}
	inputs = frm.getElementsByTagName("SELECT");
	for(i=0;i<inputs.length;i++){
		str = str + inputs[i].name + "=" + inputs[i].value + "&";
	}
	inputs = frm.getElementsByTagName("TEXTAREA");
	for(i=0;i<inputs.length;i++){
		str = str + inputs[i].name + "=" + inputs[i].value + "&";
	}
	alert(str);
	return str;
}

function displayElem(id){
	document.getElementById(id).style.display = "block";
}

function hideElem(id){
	document.getElementById(id).style.display = "none";
}