var flag;
var impflag=true;
var cpower1 = 0;
var cpower2 = 0;

function verify(obj,targetId,vtype,vglobal)
{
	impflag=true;
	var pattern;
	var message='';
	
	function Verify_Numerical()
	{
	pattern=/^[0-9\.,]*$/;
	message="Данное поле может содержать только числовую информацию";
	}
	function Verify_Numerical_Quan()
	{
	pattern=/^\d*$/;
	message="Данное поле может содержать только цифры";
	}
	
	if (document.getElementById)
	{
		target = document.getElementById(targetId);
		switch(vtype)
		{
			case "numerical":
				Verify_Numerical();
				break
			case "numerical_quan":
				Verify_Numerical_Quan();
				break
			default:
				break;
		}
		if (vglobal)
		{
			if (!(pattern.test(obj.value)))
			{
				target.innerHTML="&nbsp;<a title='"+message+"'><i style='font-size:90%;'>Ошибка</i></a>";
				impflag = false;
			}			
		}
		else
		{
			if ((pattern.test(obj.value))||(obj.value=='')) target.innerHTML="";
			else
			{
				target.innerHTML="&nbsp;<a title='"+message+"'><i style='font-size:90%;'>Ошибка</i></a>";
				impflag = false;
			}
		}
	}
return impflag;
}

function ClearFill(th,arg)
{
	if (th.value=='') th.value=arg;
}

function ReClearFill(th,arg)
{
	if (th.value==arg) th.value='';
}

function Verify_AllEmpty(flag)
{
var fl=impflag;
return (fl&&flag);
}

function Go_BM(bm,bm_cur)
{
if (document.getElementById) {
	aexact1 = document.getElementById('aexact');
	arough1 = document.getElementById('arough');
	exact1 = document.getElementById('exact');
	rough1 = document.getElementById('rough');
}
}

function CommaToPoint(number) {
var modified;
modified = '';
for (var i = 0; i<number.value.length; i++) {
	if (number.value.charAt(i)==',') modified += '.';
	else modified += number.value.charAt(i);
	}
return modified;
}

function UnitsCh(type,num,t) {
if (t == 1) {
cpower1 = (num == 'BTU') ? cpower1/0.293 : cpower1*0.293;
type.power1.value = cpower1.toFixed(0);	
}
else {
	cpower2 = (num == 'BTU') ? cpower2/0.293 : cpower2*0.293;
	type.power2.value = cpower2.toFixed(0);	
	}
}

function Go_Calc(type,t)
{
var result=0;
if (t == 1) {
	result = CommaToPoint(type.square1)*CommaToPoint(type.pheight1)*CommaToPoint(type.orient1)+300*CommaToPoint(type.comp1)+0.6*CommaToPoint(type.dep1)+CommaToPoint(type.bulbs1)*0.9+CommaToPoint(type.people1)*100;
	if (type.units1.value == 'BTU') result = result/0.293;
	cpower1 = result;
	type.power1.value = cpower1.toFixed(0);
	}
	else {
	result = CommaToPoint(type.square2)*CommaToPoint(type.pheight2)*CommaToPoint(type.orient2)+0.5*CommaToPoint(type.comp2)+0.5*CommaToPoint(type.digit)+0.7*CommaToPoint(type.radio)+CommaToPoint(type.bulbs2_1)*0.9+CommaToPoint(type.bulbs2_2)*0.55+CommaToPoint(type.brain)*100+CommaToPoint(type.manual1)*150+CommaToPoint(type.manual2)*200+CommaToPoint(type.manual3)*290;
	if (type.units2.value == 'BTU') result = result/0.293;
	cpower2 = result;
	type.power2.value = cpower2.toFixed(0);		
	}
}
