// JavaScript Document

function toggle_details(id,conn_at)
{
	div = document.getElementById(id);
	if (div.innerHTML=="")
	{
		if (set_wait()) x_catalog_vinyl_details(conn_at,id,fill_html);
	}
	if (div.style.visibility == 'visible')
	{
		div.style.visibility = 'hidden';
		div.style.position = 'absolute';
	}
	else
	{
		div.style.visibility = 'visible';
		div.style.position = 'static';
	}
}	
function toggle_sleeve(image,code)
{
	if (image.width<=75)
	{
		image.src='assets/images/200x200/' + code + '.jpg';
	}
	else
	{
		image.src='assets/images/75x75/' + code + '.jpg';
	}
}

function do_catalog_play(id)
{
	if (!IE)
	{
		if (set_wait()) x_catalog_play(id,do_catalog_play_manager);	
	}
	else
	{
		window.open('play.php?id='+id,'url_for_winamp');
	}
}

function do_catalog_play_manager(z)
{
	for (i=0;i<z[0];i++)
	{
		title =  z[1][i][4] + ' (' + z[1][i][0]  +') ' + z[1][i][3];
		flashProxy.call('js_wimpy_appendPlaylist', 'track', z[1][i][1], z[1][i][2], title, false, false);
	}
	clear_wait();
}

function do_catalog_search(p,type,txt)
{
	if (txt=="" || txt=="catalog search") {document.getElementById('search').value = ''; return; }
	switch(page_var)
	{
		case 'catalog':
			if (set_wait()) x_catalog_search(p,"catalog",escape(txt),'holder_data',fill_html);
		break;
		case 'presale':
			if (set_wait()) x_catalog_search_presale(p,"presale",escape(txt),'holder_data',fill_html);
		break;
		default:
			if (set_wait()) x_catalog_search(p,"catalog",escape(txt),'holder_data',fill_html);
		break;
	}
	
	
}

function replace_sifr()
{
	if(typeof sIFR == "function")
	{
		sIFR.replaceElement("h3", "js/sifr/tahoma.swf", "#000000", null, null, null, 0, 0, 0, 0);
	};
}

function fill_html(z)
{
	what = z["where"];
//	if (!(z["msg"]==""))  {alert(z["msg"]); }
	obj = document.getElementById(what);
	obj.innerHTML = unescape(unescape(z["html"]));
	if (what=="holder_data")
	{ 
		replace_sifr(); 
	}
	clear_wait();
}

function fill_html_finish(z)
{
	what = z["where"];
//	if (!(z["msg"]==""))  {alert(z["msg"]); }
	obj = document.getElementById(what);
	obj.innerHTML = unescape(unescape(z["html"]));
	if (what=="holder_data") { replace_sifr(); }
	do_side_cart();
	do_side_presale();
	clear_wait();
}

function fill_html_update(z)
{
	what = z["where"];
//	if (!(z["msg"]==""))  {alert(z["msg"]); }
	obj = document.getElementById(what);
	obj.innerHTML = unescape(unescape(z["html"]));
	if (what=="holder_data") { replace_sifr(); }
	clear_wait();
	switch(page_var)
	{
		case 'continue_presale':
			do_continue_presale_list();
		break;
		case 'continue':
			do_continue_list();
		break;
	}

}
function fill_html_signin(z)
{
	what = z["where"];
//	if (!(z["msg"]==""))  {alert(z["msg"]); }
	obj = document.getElementById(what);
	obj.innerHTML = unescape(unescape(z["html"]));
	if (what=="holder_data") { replace_sifr(); }
	clear_wait();
	if (set_wait()) 
	{
//		alert(page_var);
		x_catalog_cart('side_cart',fill_html);
		x_catalog_wishes('side_wishes',fill_html);
		switch(page_var)
		{
			case 'presale':
				x_catalog_list_presale(1,'epicentar','exclusive','holder_data',fill_html);
			break;
			case 'catalog':
				x_catalog_list(1,'epicentar','exclusive','holder_data',fill_html);
			break;
		}
		
	}
}
function clear_wait()
{ //DOM

	if (document.getElementById)
	{
		document.getElementById('loading').style.visibility='hidden';
	}
	else
	{
		if (document.layers)
		{ //NS4
			document.loading.visibility = 'hidden';
		}
		else 
		{ //IE4
			document.all.loading.style.visibility = 'hidden';
		}
	}
	clearTimeout(tm);
	tm = setTimeout('null',1);
}
function truebody()
{
	return (document.compatMode!="BackCompat")? document.documentElement : document.body
}
function set_wait()
{ //DOM

	if (NS||NS6) {winY = window.pageYOffset;}
	if (IE) {winY = truebody().scrollTop;}
	
	nb = 5 - winY;
	lastY = 0;
		
	if (check_wait()=='visible') return 0;
	if (document.getElementById)
	{

		
		obj = document.getElementById('loading');
		obj.style.bottom= nb +'px';
		obj.style.right='5px';
		obj.style.visibility='visible';
		obj.style.position='absolute';
		tm = setTimeout('move_wait()', 500);

		return 1;
	}
	else
	{
		if (document.layers)
		{ //NS4
			document.loading.bottom = nb + 'px';
			document.loading.right = '5px';
			document.loading.visibility = 'visible';
			document.loading.position = 'absolute';
			tm = setTimeout('move_wait()', 500);
			return 1;
		}
		else 
		{ //IE4
			document.all.loading.bottom = nb + 'px';
			document.all.loading.right = '5px';
			document.all.loading.visibility = 'visible';
			document.all.loading.position = 'absolute';
			tm = setTimeout('move_wait()', 500);
			return 1;
		}
	}
}

function move_wait()
{
	if (NS||NS6) {winY = window.pageYOffset;}
	if (IE) {winY = truebody().scrollTop;}
	nb = 5 - winY;
	
	if (document.getElementById)
	{
		obj = document.getElementById('loading');
		if (IE)
		{
			obj.style.bottom= '6px';
			obj.style.bottom= '5px';
		}
		else
		{
			obj.style.bottom= nb +'px';
		}

		obj.style.right='5px';
		obj.style.visibility='visible';
		obj.style.position='absolute';
		tm = setTimeout('move_wait()', 500);

		return 1;
	}
	else
	{
		if (document.layers)
		{ //NS4
			document.loading.bottom = nb + 'px';
			document.loading.right = '5px';
			document.loading.visibility = 'visible';
			document.loading.position = 'absolute';
			tm = setTimeout('move_wait()', 500);
			return 1;
		}
		else 
		{ //IE4
			document.all.loading.bottom = '6px';
			document.all.loading.bottom = '5px';
			document.all.loading.right = '5px';
			document.all.loading.visibility = 'visible';
			document.all.loading.position = 'absolute';
			tm = setTimeout('move_wait()', 500);
			return 1;
		}
	}
	obj.style.right = '5px';
	tm = setTimeout('move_wait()', 500);
}

function check_wait()
{ //DOM
	if (document.getElementById)
	{
		return document.getElementById('loading').style.visibility;
	}
	else
	{
		if (document.layers)
		{ //NS4
			return document.loading.visibility;
		}
		else 
		{ //IE4
			return document.all.loading.style.visibility;
		}
	}
}

function disableEnterKey(e,what)
{
	 var key;
	 obj = document.getElementById(what);
	 if(window.event)
		  key = window.event.keyCode; //IE
	 else
		  key = e.which; //firefox

	 if(key == 13)
		{
			switch(what) 
			{
				case 'search':
					do_catalog_search(1,'epicentar',obj.value);
				break;	
			}
			return false;
		}
		else
		{
		  return true;
		}
}

function do_get_form_data(formid)
{
		var data = new Array(Array(),Array());
		obj = document.getElementById(formid);
		forma = document.forms[0].elements;
		n = forma.length;
		r=0;
		for (i=0;i<n;i++)
		{
			el = forma[i].id;
			if(el.substring(0,5)=="data_")
			{
				field = el.substring(5,el.length);
				data[0][r] = escape(forma[i].value);
				data[1][r] = field;
				
				if (field=="dostava")
				{
					data[0][r] = GetRadio("data_dostava");
				}
				r++;
			}
		}
		return data;
}

function GetRadio(radioname)
{
	grp = document.getElementsByName(radioname);
	for(a=0;a<grp.length;a++)
	{
		if(grp[a].checked) return grp[a].value;
	}
	return 0;
}