	
function initColculate(o){	
	var res = 0;
	var errors = new Array();
	var fl = true;
	for(var i=0; i<o.length; i++)
	{	
		switch(o[i].type)
		{
			case 'text':
			var patt1=new RegExp("^\\d+$");
				if(patt1.test(o[i].value))
					res += parseInt(o[i].value) * parseInt(o[i].getAttribute('price'));
				else
					errors[o[i].name] = o[i].name;
			break;
			case 'radio':
				if(o[i].checked)
				{
					res += parseInt(o[i].value);
					errors[o[i].name] = 0;
				}
				else
					errors[o[i].name] = errors[o[i].name] != 0?o[i].name:0;
			break;
			case 'checkbox':
				if(o[i].checked)
				{
					if('max' == o[i].getAttribute('math'))
					{
						if(fl){
							res += getMaxOfGroup(o,o[i].getAttribute('group'));
							fl = false;
						}
					}
					else{
						res += parseInt(o[i].value);
					}
					errors[o[i].getAttribute('group')] = 0;
				}
				errors[o[i].getAttribute('group')] = errors[o[i].getAttribute('group')]!=0? o[i].getAttribute('group'):0;
			break;
			case 'hidden':
				if(o[i].name != 'percent' && o[i].getAttribute('group') != 'tarif')
					res += parseInt(o[i].value);
			break;
		}
	}
	if('undefined' != typeof o.percent)
	{
		res *= parseInt(o.percent.value)/100 +1;
	}
	e=0;
		for(x in errors)
		{
			if(errors[x])
				e=1;
			else
				e=!e?0:1;
		}
	if(e)
	{
		alert('Необходимо заполнить все поля формы')
	}
	else
		document.getElementById('result').innerHTML = "<b>Итоговая стоимость: </b>"+res;
}

function getMaxOfGroup(obj, groupName)
{
	var max = 0;
	for(var j=0; j<obj.length; j++)
	{
		if(obj[j].getAttribute('group') == groupName && obj[j].checked)
		{
				v = obj[j].name == 'gsm'?parseInt(obj[j].value)+500:parseInt(obj[j].value);
				max = max<v?v:max;
		}
	}
	//alert(max)
	return max;
}

function initColculate2(o){	
	var res = 0;
	var errors = new Array();
	var fl = true;
	for(var i=0; i<o.length; i++)
	{	
		switch(o[i].type)
		{
			case 'checkbox':
				if(o[i].checked)
				{
					if(o[i].name == 'phone2')
					{
						document.getElementById('unlimit').value = o.unlimitphone.value;
					}
					else if(o[i].name == 'gsm2')
					{
						document.getElementById('unlimit').value = o.unlimitgsm.value;
					}
					else
					{
						document.getElementById('unlimit').value = o.unlimitradio.value;
					}
					if('max' == o[i].getAttribute('math'))
					{
						if(fl){
							res += getMaxOfGroup(o,o[i].getAttribute('group'));
							fl = false;
						}
					}
					else{
						res += parseInt(o[i].value);
					}
					errors[o[i].getAttribute('group')] = 0;
				}
				errors[o[i].getAttribute('group')] = errors[o[i].getAttribute('group')]!=0? o[i].getAttribute('group'):0;
			break;
			case 'radio':
				if(o[i].checked)
				{
					res += parseInt(o[i].value);
					errors[o[i].name] = 0;
					percent = o[i].value;
				}
				else
					errors[o[i].name] = errors[o[i].name] != 0?o[i].name:0;
			
			break;
			case 'hidden':
				if(o[i].getAttribute('group') != 'tarif' && o.gsm2.checked)
					res += parseInt(o[i].value);
			break;
		}
	}
	if('undefined' != typeof o.percent)
	{
		res *= parseInt(o.percent.value)/100 +1;
	}
	e=0;
		for(x in errors)
		{
			if(errors[x])
				e=1;
			else
				e=!e?0:1;
		}
	if(e)
	{
		alert('Необходимо заполнить все поля формы')
	}
	else
		document.getElementById('result').innerHTML ="<b>Итоговая стоимость: </b>"+parseInt( percent * (res - percent) );
}