function CheckFa()
{
	var fa=document.getElementById("fa");

	if(fa && fa.value=='') 
	{
		alert("Вы не выбрали тип конструкции или не ввели параметры профиля.");
		return false;
	}
	
	return true;
}

function round_mod(value, precision)
{
	var precision_number=Math.pow(10, precision);
	return Math.round(value * precision_number) / precision_number;
}

function FA()
{
	var fav=document.getElementById("fav");
	var fa=document.getElementById("fa");
	var temp=0;
	
	var a=document.getElementById("a");
	var b=document.getElementById("b");	
	var s=document.getElementById("s");
	
	var f1=document.getElementById("f1");
	var f2=document.getElementById("f2");
	var f3=document.getElementById("f3");
	var f4=document.getElementById("f4");
	var f5=document.getElementById("f5");

	if(a.value!='' && b.value!='' && s.value!='')
	{
		if(f1.checked==true)
		{
			temp=round_mod(parseFloat(s.value) / (2 * parseFloat(a.value) + 2 * parseFloat(b.value)) * 100, 2);
		}

		if(f2.checked==true)
		{
			temp=round_mod(2 * parseFloat(s.value) / (2 * parseFloat(a.value) + 2 * parseFloat(b.value)) * 100, 2);
		}
			
		if(f3.checked==true)
		{
			temp=round_mod(parseFloat(s.value) / (parseFloat(a.value) + 2 * parseFloat(b.value)) * 100, 2);
		}
			
		if(f4.checked==true)
		{
			temp=round_mod(parseFloat(s.value) / (2 * parseFloat(a.value) + 2 * parseFloat(b.value)) * 100, 2);
		}
			
		if(f5.checked==true)
		{
			temp=round_mod(parseFloat(s.value) / (parseFloat(a.value) + parseFloat(b.value)) * 100, 2);
		}
	}
	
	
	if(temp!=0) 
	{
		fav.innerHTML=temp;
		fa.value=temp;
	}
}

function NewWnd()
{
	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 - 350;
	var Newy=y / 2 - 80;

	window.open("tprint.php","wnd","width=700,height=370,resizable=yes,scrollbars=no,menubar=no,status=no,top="+Newy+",left="+Newx);
}

function Notice()
{
	if(document.getElementById('notice')) document.getElementById('notice').style.display='none';
	document.getElementById('sbm').style.display='block';
}

function ShowVideo(rd)
{
	DisplayShadow(1, 0.8, 'shadow');
	document.getElementById("video").innerHTML=document.getElementById("source"+rd).innerHTML;
}

function CloseVideo()
{
	DisplayShadow(-1, 0.2, 'shadow');
	document.getElementById("video").innerHTML='';
}

function pngdisplay(image, width, height) 
{
	if(navigator.appName=='Microsoft Internet Explorer') 
	{ 
		document.write('<img src="images/empty.gif" style="width: ' + width + '; height: ' + height + '; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + image + ', sizingMethod=scale)">');
	} 
	else 
	{
		document.write('<img src="' + image + '" style="width: ' + width + '; height: ' + height + ';">');
	}
}

function ShowDiv(obj)
{
	var o=document.getElementById(obj);
	
	if(o.style.display=='none') o.style.display='block';
	else o.style.display='none';
}

function Init()
{
	if(window.addEventListener) 
	{
		window.addEventListener('resize', PositionShadow, false);
	} 
	else if (window.attachEvent) 
	{
		window.attachEvent('onresize', PositionShadow);
	}
}

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 DisplayShadow(param, full, obj)
{
	if(param==1)
	{
		PositionShadow();
		document.getElementById(obj).style.display='block';
		setShadowOpacity(1, 0.2, full, obj);
	}
	else
	{
		setShadowOpacity(-1, 0.8, full, obj);
	}
}

function PositionShadow()
{
	if(document.getElementById('shadow'))
	{
		var arrayPageSize=getPageSize();

		document.getElementById('shadow').style.height=arrayPageSize[1];
		document.getElementById('shadow').style.width=arrayPageSize[0];
	}
}

function DisplayPhoto(param, full, obj)
{
	var o=document.getElementById(obj);
	
	if(param==1)
	{
		o.style.display='block';
		setShadowOpacity(1, 0.2, full, obj);
	}
	else
	{
		setShadowOpacity(-1, 0.8, full, obj);
	}
}

function ShowBigPhoto(param, pid)
{
	document.location.href='#top';
	document.getElementById('current-photo').value=pid;
	
	var nn=document.getElementById('current-photo').value;
	
	if(param=='y') DisplayShadow(1, 0.8, 'shadow');
	DisplayPhoto(1, 1.0, nn);
}

function CloseBigPhoto(param)
{
	var nn=document.getElementById('current-photo').value;
	
	DisplayPhoto(-1, -0.2, nn);
	if(param=='y') DisplayShadow(-1, 0.2, 'shadow');
}

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 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;
}
