isDOM=document.getElementById //DOM1 browser (MSIE 5+, Netscape 6, Opera 5+)
isOpera=isOpera5=window.opera && isDOM //Opera 5+
isOpera6=isOpera && window.print //Opera 6+
isOpera7=isOpera && document.readyState //Opera 7+
isMSIE=document.all && document.all.item && !isOpera //Microsoft Internet Explorer 4+
isMSIE5=isDOM && isMSIE //MSIE 5+
isNetscape4=document.layers //Netscape 4.*
isMozilla=isDOM && navigator.appName=="Netscape" //Mozilla или Netscape 6.*

function _height()
{
	if(isMSIE || isOpera7)
	{
		return document.body.scrollHeight;
	}
	if(isNetscape4 || isMozilla)
	{
		return document.height;
	}
	if(isOpera6 || isOpera)
	{
		return document.body.style.pixelHeight;
	}
}

function _width()
{
	if(isMSIE || isOpera7)
	{
		return document.body.scrollWidth;
	}
	if(isNetscape4 || isMozilla)
	{
		return document.width;
	}
	if(isOpera6 || isOpera)
	{
		return document.body.style.pixelWidth;
	}
}

function $(n)
{
	return document.getElementById(n);
}

var msxmls = new Array("Msxml2.XMLHTTP.3.0", "Microsoft.XMLHTTP" )

function createRequestObject(){
	var browser=navigator.appName;
	if(window.XMLHttpRequest){return new XMLHttpRequest();} // Mozilla, Safari, ...
	else if(window.ActiveXObject){ // IE
		for(var n in msxmls){
			try{return new ActiveXObject(msxmls[n]);}
			catch(e){ }
		}
	}
	return false;
}

/*
-{1234yo!}-test
fCallBack('test','1234yo!');
*/
function HTTPsend(fCallBack, u, d){
	document.body.style.cursor='wait';
	var xmlhttp=createRequestObject();
	if(xmlhttp){
		if(u.indexOf('?')>-1){u+='&';}else{u+='?';}u+='rnd='+Math.ceil(Math.random()*10000);
		
		xmlhttp.open("POST",u);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange=function(){
			document.body.style.cursor='default';
			if(xmlhttp.readyState==4){
				try{
					if(xmlhttp.status==200){
						text=xmlhttp.responseText;
						text=text.replace(/^\s+/,"");
						text=text.replace(/\s+$/,"");
						if(text.indexOf('-{')==0)
						{
							var code=text.substr(2,text.indexOf('}-')-2);
							text=text.substr(text.indexOf('}-')+2,text.length);
							eval(fCallBack+"(text,code)");
						}
						else
						{
							eval(fCallBack+"(text)");
						}
						xmlhttp=null;
						try{CollectGarbage();} catch (e) {}
					}else{
						alert(xmlhttp.status+" HTTP Error: "+xmlhttp.statusText+"\n\nPlease check yout connection and try again.");
						xmlhttp=null;
					}
				}catch(e){
					alert("HTTP Error: Unknown\n\nPlease check yout connection and try again.");
					xmlhttp=null;
				}
			}
		}
		xmlhttp.send(d);
		return true;
	}
}

function show_popup(o,code)
{
	var el=$('ajax_popup_block');
	if(el)
	{
		if(o)
		{
			el.innerHTML='<div id="overlay"></div>'+o;
			var overlay=$('overlay');
			if(overlay)
			{
				var new_height = 0;
				if(window.height>_height())
				{
					new_height = window.height;
				}
				else
				{
					new_height = _height();
				}
				//set black block height
				overlay.style.height=new_height+'px';
				//width
				overlay.style.width=_width()+'px';
			}			
			var block=$('vote-block');
			if(block)
			{
				block.style.left=((_width()/2)-(396/2))+'px';
			}
			/*var loadingImage=$('loadingImage');
			if(loadingImage)
			{
				loadingImage.style.display='none';
			}*/
			var preload_block=$('ajax_preload_block');
			if(preload_block)
			{
				preload_block.style.display='none';
			}
			el.style.display='block';
		}
		else
		{
			el.style.display='none';
			el.innerHTML='';
		}
	}
	if(code){eval(code);}else{window.location = "#";}
}

function show_preload(id,type,str)
{
	var el=$('ajax_preload_block');
	if(el)
	{
		el.innerHTML='<div id="overlay"></div><a href="#"><img id="loadingImage" src="-images/loading.gif"/></a>';
		var overlay=$('overlay');
		if(overlay)
		{
			var new_height = 0;
			if(window.height>_height())
			{
				new_height = window.height;
			}
			else
			{
				new_height = _height();
			}
			//set black block height
			overlay.style.height=new_height+'px';
			//width
			overlay.style.width=_width()+'px';
		}
		var loadingImage=$('loadingImage');
		if(loadingImage)
		{
			loadingImage.style.left=((_width()/2)-130/2)+'px';
		}
		el.style.display='block';
	}
	HTTPsend('show_popup', '/gallery/rating.html', 'ajax_popup=1&id='+id+'&type='+type+str);
	//if(code){eval(code);}else{window.location = "#";}
	
}

function show_without_popup(o,code)
{
	var el=$('ajax_block');
	if(el)
	{
		if(o)
		{
			el.innerHTML=o;
		}
	}
	//if(code){eval(code);}else{window.location = "#";}
}

function ajax_show(page,competition)
{
	if(competition==true)
	{
		HTTPsend('show_without_popup', '/gallery/competition.html', 'ajax=1&page='+page);
	}
	else
	{
		HTTPsend('show_without_popup', '/gallery/show.html', 'ajax=1&page='+page);
	}
}

function ajax_show_popup(id,type,id_hidden)
{
	var str='';
	var rating;
	if (id_hidden!='')
	{
		rating = document.getElementById(id_hidden).value;
		str='&rating='+rating;
	}
	//HTTPsend('show_popup', '/gallery/rating.html', 'ajax_popup=1&id='+id+'&type='+type+str);
	show_preload(id,type,str);
}