//---------------------------------------------------------------------------------------------------------------
// Для простого клонирования
//---------------------------------------------------------------------------------------------------------------
var father;
var child;
var clonechild;

function dynamicCloner(id1, id2) {
	// Сперва необходимо проверить поддержку W3C DOM в браузере
	if (document.getElementById && document.getElementsByTagName) {

		// Определение переменной
		father = document.getElementById(id1);
		child = document.getElementById(id2);

		// Клонирование 
		clonechild = child.cloneNode(true);
		
		dynamicDelete();
	}
}
//---------------------------------------------------------------------------------------------------------------
function dynamicAppend() {
	// Добавляем клона
	father.appendChild(clonechild.cloneNode(true));
}
//---------------------------------------------------------------------------------------------------------------
function dynamicDelete() {
	// Удаляем строку
	document.getElementById("search_cat").removeNode(true);
}
//---------------------------------------------------------------------------------------------------------------
function CheckAdvSearch() {
	if (document.getElementById("opt").checked){	
		dynamicAppend();
	}
	else {
		dynamicDelete();
	}
}
//---------------------------------------------------------------------------------------------------------------
window.onload = function() {
	dynamicCloner("advased_search", "search_cat");
}
//---------------------------------------------------------------------------------------------------------------



//---------------------------------------------------------------------------------------------------------------
// Функция для отображения всплывающих окон
//---------------------------------------------------------------------------------------------------------------
function info(page)	{
	var features, w=540, h=550;
	var top = (screen.height - h)/2, left = (screen.width - w)/2;
	if(top  < 0) top  = 0;
	if(left < 0) left = 0;
	features  = 'top='+top+',left='+left;
	features += ',height='+h+',width='+w+',resizable=no,status=no,scrollbars=yes';
	popupWin = window.open(page, 'Info', features);
	popupWin.focus();
}	
//---------------------------------------------------------------------------------------------------------------



//---------------------------------------------------------------------------------------------------------------
// Выделение проигрываемой мелодии
//---------------------------------------------------------------------------------------------------------------
var elem1 = new Object(), elem2 = new Object();

function SelectRow(id) {
	// Сперва необходимо проверить поддержку W3C DOM в браузере
	if (document.getElementById && document.getElementsByTagName) {
		if (typeof elem2.style != 'undefined')
		{
			elem2.style.backgroundColor = "#ffffff";
		}
		elem1 = document.getElementById("id_"+id);
		elem1.style.backgroundColor = "lightgrey";
		elem2 = elem1;
	}	
}
//---------------------------------------------------------------------------------------------------------------



//---------------------------------------------------------------------------------------------------------------
// 
//---------------------------------------------------------------------------------------------------------------
// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() {	
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	
	if(window.ActiveXObject) // if running Internet Explorer
	{
		try	{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch (e) {	xmlHttp = false; }
	}
	else // if running Mozilla or other browsers
	{
	  try { xmlHttp = new XMLHttpRequest(); }
	  catch (e) { xmlHttp = false; }
	}
	
	// return the created object or display an error message
	if (!xmlHttp) { alert("Error creating the XMLHttpRequest object."); }
	else { return xmlHttp; }
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function SendRequest(cat_id)
{
	// proceed only if the xmlHttp object isn't busy
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
	{
		// execute the statistics.php page from the server
		xmlHttp.open("GET", "http://"+domen+"/statistics.php?cat_id="+cat_id, true);  

		// make the server request
		xmlHttp.send(null);
	}
	else {
		// if the connection is busy, try again after one second  
		setTimeout('SendRequest()', 1000);	
	}
}
//---------------------------------------------------------------------------------------------------------------

