var xmlHttp=createXmlHttpRequestObject(); 

function DownLoadReal(fidv, param)
{
	window.open("catalog.php?fid="+fidv,"tiecontents","width=100,height=100,resizable=no,scrollbars=no,menubar=no,status=no,top=10,left=10");
}

function CloseDownload()
{
	DisplayShadow(-1, 0.2, 'shadow');
	
	var duf=document.getElementById('duf');
	if(duf)
	{
		duf.style.display='none';
	}
}

function SetFid(fidv)
{
	if(fid!=0)
	{
		var o=document.getElementById('fid');
		o.value=fidv;
		
		var o=document.getElementById('fida');
		o.value=fidv;
	}
}

function Download(fidv, param)
{
	if(param==1)
	{
		DownLoadReal(fidv, '');
	}
	else
	{
		var x=(window.innerWidth)?window.innerWidth:((document.all)?document.body.offsetWidth:null);
		var y=(window.innerHeight)?window.innerHeight:((document.all)?document.body.offsetHeight:null);

		var Newx=x / 2 - 250;
		var Newy=y / 2 - 150;

		PositionShadow();
		DisplayShadow(1, 0.8, 'shadow');
	
		var duf=document.getElementById('duf');
		if(duf)
		{
			duf.style.left=Newx+'px';
			duf.style.top=Newy+'px';
			duf.style.display='block';
		}
	}
}

function PositionShadow()
{
	if(document.getElementById('shadow'))
	{
		var arrayPageSize=getPageSize();

		document.getElementById('shadow').style.height=arrayPageSize[1];
		document.getElementById('shadow').style.width=arrayPageSize[0];
	}
}

function DisplayShadow(param, full, obj)
{
	if(param==1)
	{
		document.getElementById(obj).style.display='block';
		setShadowOpacity(1, 0.2, full, obj);
	}
	else
	{
		setShadowOpacity(-1, 0.8, full, obj);
	}
}

function setShadowOpacity(param, start, full, obj)
{
	if(param==1)
	{
		if(start <= full)
		{
			setElementOpacity(obj, start);
			start=start+0.2;
			setTimeout('setShadowOpacity(1, '+start+', '+full+', "'+obj+'")', 0.5);
		}
	}
	
	if(param==-1)
	{
		if(start > full)
		{
			setElementOpacity(obj, start);
			start=start-0.2;
			setTimeout('setShadowOpacity(-1, '+start+', '+full+', "'+obj+'")', 0.5);
		}
		else document.getElementById(obj).style.display='none';
	}
}

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ 
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else 
	{ 
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) 
	{	
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		} 
		else 
		{
			windowWidth = self.innerWidth;
		}
		
		windowHeight = self.innerHeight;
	} 
	else if (document.documentElement && document.documentElement.clientHeight) 
	{ 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} 
	else if (document.body) 
	{ 
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	} 
	else 
	{
		pageWidth = windowWidth;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 

	return arrayPageSize;
}

function getOpacityProperty()
{
	if(typeof document.body.style.opacity == 'string') return 'opacity';
	else if(typeof document.body.style.MozOpacity == 'string') return 'MozOpacity';
	else if(typeof document.body.style.KhtmlOpacity == 'string') return 'KhtmlOpacity';
	else if(document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) return 'filter';

	return false;
}

function setElementOpacity(sElemId, nOpacity)
{
	var opacityProp=getOpacityProperty();
	var elem=document.getElementById(sElemId);

	if(!elem || !opacityProp) return;
  
	if(opacityProp=="filter")
	{
		nOpacity *= 100;
	
		var oAlpha=elem.filters['DXImageTransform.Microsoft.alpha'] || elem.filters.alpha;
		if(oAlpha) oAlpha.opacity=nOpacity;
		else elem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";
	}
	else elem.style[opacityProp]=nOpacity;
}

function createXmlHttpRequestObject() 
{	
	var xmlHttp;
	
	if(window.ActiveXObject)
	{
		try
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e) 
		{
			xmlHttp=false;
		}
	}
	else
	{
		try 
		{
			xmlHttp=new XMLHttpRequest();
		}
		catch(e) 
		{
			xmlHttp=false;
		}
	}

	if(!xmlHttp) alert("Error creating the XMLHttpRequest object.");
	else return xmlHttp;
}

function Reg()
{
	if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	{
		var fio=document.getElementById("fio").value;
		var email=document.getElementById("email").value;
		var phone=document.getElementById("phone").value;
		var chicken=document.getElementById("chicken").value;
		var reg=document.getElementById("reg").value;
		
		xmlHttp.open("GET", "catalog.php?fio="+name+"&email="+email+"&phone="+phone+"&checken="+chicken+"&reg="+reg, true);  
		xmlHttp.onreadystatechange = handleServerResponse;
		xmlHttp.send(null);
	}
	
	return false;
}

function handleServerResponse() 
{
	if(xmlHttp.readyState==4) 
	{
		if(xmlHttp.status==200) 
		{
			xmlResponse=trim11(xmlHttp.responseText);
			if(xmlResponse!='')
			{
				document.getElementById("livesearch_container").style.display='block';
				document.getElementById("livesearch_container").innerHTML=xmlResponse;
			}
			else
			{
				document.getElementById("livesearch_container").style.display='none';
			}
			
			setTimeout('LiveSearch()', 1000);
		} 
		else 
		{
			alert("There was a problem accessing the server: " + xmlHttp.statusText);
		}
	}
}
