var newWindow = null;
function menuClick(id, liId, cssClass)
{	
	obj = document.getElementById(id);
	li = document.getElementById(liId);
	
	if (obj.style.display == 'none') 
	{
		obj.style.display = 'block';
		li.className = cssClass + '_active';
	}
	else 
	{
		obj.style.display = 'none';
		li.className = cssClass;
	}
	
	//return false;
}



function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	leftVal = (screen.width - strWidth ) / 2;
	topVal = (screen.height - strHeight) / 2;	
	
	var tools="";	
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	if (type == "scroll") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left="+leftVal+",top="+topVal+"";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function setPhone(id)
{
	o = document.getElementById('visitors_phone');
	if(o.value.length < 6) o.value = pArr[id];
}


function invoiceTable()
{
	o = document.getElementById('invoice_dif_table');
	
	if(document.getElementById('orders_invoice_dif').checked)
	{
		o.style.display = 'block';
	}
	else
	{
		o.style.display = 'none';
	}
}

function send_xmlhttprequest(obsluha, method, url, content, headers) 
{ 
 var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
 if (!xmlhttp) return false; 
 xmlhttp.open(method, url); 
 xmlhttp.onreadystatechange = function() { 
     obsluha(xmlhttp); 
 }; 
 if (headers)
 { 
      for (var key in headers) 
     { 
    xmlhttp.setRequestHeader(key, headers[key]); 
    }
 }
 xmlhttp.send(content);
 return true;
}



function rate(id, rate, mode)
{
    // odeslání požadavku na aktualizaci dat
    if (!send_xmlhttprequest(rate_callback, 'GET', '/rate.php?m=' + mode + '&id=' + id + '&rate=' + rate)) {
        return false;
    }
    //document.getElementById('rate-buttons').innerHTML = 'děkujeme za hodnocení';
    
    return true;
}

function rate_callback(xmlhttp)
{
    if (xmlhttp.readyState == 4) {
        // aktualizace odpovědí na základě aktuálního stavu
          var voted = xmlhttp.responseXML.getElementsByTagName('voted');
          //hideddrivetip();
          if (voted[0].firstChild.data == 0)
          {
              var odpovedi = xmlhttp.responseXML.getElementsByTagName('html');
            document.getElementById('rate').innerHTML = odpovedi[0].firstChild.data;
            //document.getElementById('rate-top').innerHTML = odpovedi[0].firstChild.data;
            var odpovedi = xmlhttp.responseXML.getElementsByTagName('rate');
            //document.getElementById('ratebuttons').innerHTML = odpovedi[0].firstChild.data;
          }
          if (voted[0].firstChild.data == 1)
          {
              alert('Nelze hodnotit vícekrát.');
          }
          if (voted[0].firstChild.data == 2)
          {
              alert('Nelze hodnotit vícekrát z jedné IP adresy!');
          }
    }
}
