function setStyle() {
	if (document.all) {
		if (window.XMLHttpRequest) {
			document.getElementById('shadow').style.top=0;
			document.getElementById('shadow').style.position="fixed";
			document.getElementById('order').style.position="fixed";
			document.getElementById('order').style.top="50%";
			document.getElementById('order').style.left="50%";
			document.getElementById('order').style.margin="-172px 0 0 -172px";
		}
	}
}

function closeWindow(id) {
 	document.getElementById(id).style.display = "none";
	document.getElementById('shadow').style.display = "none";
	return false;
}

function findBase() {
	var selectName = document.getElementById('name');
	var selectMark = document.getElementById('mark');
	if (selectMark.options.value.match('Э')=='Э') document.getElementById('base').innerHTML = 'полиэстр';
	if (selectMark.options.value.match('Х')=='Х') document.getElementById('base').innerHTML = 'стеклохолст';
	if (selectMark.options.value.match('Т')=='Т') document.getElementById('base').innerHTML = 'стеклоткань';
	return false;
}

function showForm(obj) {
	if (obj.readyState == 4) {
        if (obj.status == 200) {
			document.getElementById('order').innerHTML=obj.responseText;
			document.getElementById('order').style.display="block";
			document.getElementById('roll').value=1;
			var m = document.getElementById('area').value;
			m-=0;
			var price1m = document.getElementById('price1m').value;
			document.getElementById('sum').innerHTML=price1m*m;
		} else alert('Ошибка соединения! Проверьте подключение к сети и повторите попытку.');
	} else document.getElementById('shadow').style.display='block'; 
	return false;
}

function digFormat(dig) {
	dig+='';
    var digParts = dig.split('.');
    if (digParts.length == 1)
    {
         digParts[1] = '00';
    }
    else
    {
        if (digParts[1].length > 2)
            digParts[1].length = 2;
        else
            for (var i = 0; i<(2 - digParts[1].length); i++)
                digParts[1] += '0';
    }
    return digParts[0]+'.'+digParts[1];
}

function changePrice(key) {
	var priceb = document.getElementById('priceb').value.replace(new RegExp("до "),"");
	priceb-=0;
	var s=document.getElementById('area').value-0;
	var r=document.getElementById('roll').value-0;
	var price1m = document.getElementById('price1m').value-0;
	var p1=document.getElementById('price1').value-0;
	var p2=document.getElementById('price2').value-0;
	var mInR=document.getElementById('mInR').value-0;
	if (key==1) {
		if (s<=priceb) {
			document.getElementById('p1m').innerHTML=digFormat(p1);
			document.getElementById('roll').value=Math.ceil(s/mInR);
			r=document.getElementById('roll').value-0;
			document.getElementById('sum').innerHTML=r*mInR*p1;
		} else {
			document.getElementById('p1m').innerHTML=digFormat(p2);
			document.getElementById('roll').value=Math.ceil(s/mInR);
			r=document.getElementById('roll').value-0;
			document.getElementById('sum').innerHTML=r*mInR*p2;
		}
	}
	if (key==2) {
		s=r*mInR;
		if (s<=priceb) {
			document.getElementById('p1m').innerHTML=digFormat(p1);
			document.getElementById('area').value=s;
			document.getElementById('sum').innerHTML=r*mInR*p1;
		} else {
			document.getElementById('p1m').innerHTML=digFormat(p2);
			document.getElementById('area').value=s;
			document.getElementById('sum').innerHTML=r*mInR*p2;
		}
	}
}

function completeOrder() {
	var nameGood;
	if (document.all) {
		var i=0;
		while(document.getElementById('name').options[i]) {
			if (document.getElementById('name').options[i].selected==true) nameGood=document.getElementById('name').options[i].text;
			i++;
		}
	} else nameGood=document.getElementById('name').value;
	var nameMark;
	if (document.all) {
		var i=0;
		while(document.getElementById('mark').options[i]) {
			if (document.getElementById('mark').options[i].selected==true) nameMark=document.getElementById('mark').options[i].text;
			i++;
		}
	} else nameMark=document.getElementById('mark').value;
	var str='<div class="menuHead"><img src="img/titleDesign.gif" class="title" id="orderT" /><img src="img/close.jpg" alt="Закрыть окно" class="close" onclick="closeWindow(\'order\');" /></div><div class="body"><table cellspacing="6"><tr><td style="padding-bottom: 10px;" class="name">Материал:</td><td style="padding-bottom: 10px;" class="input" id="nameGood">'+nameGood+'&nbsp;'+nameMark+'</td></tr><tr><td style="padding-bottom: 10px;" class="name">Количество:</td><td style="padding-bottom: 10px;" class="input"><snan id="roll1">'+document.getElementById('roll').value+'</span>&nbsp;рулонов</td></tr><tr><td style="padding-bottom: 10px;" class="name">Цена:</td><td style="padding-bottom: 10px;" class="input"><span id="sum">'+document.getElementById('sum').innerHTML+'</span>&nbsp;руб.</td></tr><tr><td style="padding-bottom: 10px;" class="name">ФИО<span style="color: red;">*</span>:</td><td style="padding-bottom: 10px;" class="input1"><input id="namecl" onchange="checkStepOne()" onkeypress="checkStepOne()" onkeyup="checkStepOne()" onblur="checkStepOne()" class="inp" /></td></tr><tr><td style="padding-bottom: 10px;" class="name">Организация<span style="color: red;">*</span>:</td><td style="padding-bottom: 10px;" class="input1"><input id="org" onchange="checkStepOne()" onkeypress="checkStepOne()" onkeyup="checkStepOne()" onblur="checkStepOne()" class="inp" /></td></tr><tr><td style="padding-bottom: 10px;" class="name">Телефон<span style="color: red;">*</span>:</td><td style="padding-bottom: 10px;" class="input1"><input id="tel" onchange="checkStepOne()" onkeypress="checkStepOne()" onkeyup="checkStepOne()" onblur="checkStepOne()" class="inp" /></td></tr></table><div class="button grey" id="orderB" onclick="if (this.className==\'button green\') requestSendOrder()"></div></div><div class="footer header"></div>'
	document.getElementById('order').innerHTML=str;
}

function showBye(obj) {
	if (obj.readyState == 4) {
        if (obj.status == 200) {
			var str='\n<div class="menuHead">\n<img src="img/titleDesign.gif" class="title" id="orderT" /><img src="img/close.jpg" alt="Закрыть окно" class="close" onclick="closeWindow(\'order\');" />\n</div>\n<div class="body" style="margin: 0;">\n<div style="text-align: center; height: 300px; position: relative; top: 80px; margin: 0;">\n<p style="font: normal 24px Tahoma; color: #060; margin-top: 0;">Ваш заказ принят!</p>\n<p>Наш менеджер перезвонит Вам<br />в ближайшее время для подтверждения<br />заказа и выписки счёт-фактуры.</p>\n<div style="text-align: center; margin: 0 auto; width: 95px; height: 35px; background: url(\'/img/buttonClose.gif\'); cursor: pointer;" onclick="closeWindow(\'order\');"></div>\n</div>\n</div>\n<div class="footer header"></div>\n';
			document.getElementById('order').innerHTML=str;
		} else alert('Ошибка соединения! Проверьте подключение к сети и повторите попытку.');
	}
	return false;	
}

function refreshForm(obj) {
	if (obj.readyState == 4) {
        if (obj.status == 200) {
			document.getElementById('order').innerHTML=obj.responseText;
			document.getElementById('roll').value=1;
			var m = document.getElementById('area').value;
			m-=0;
			var price1m = document.getElementById('price1m').value;
			document.getElementById('sum').innerHTML=price1m*m;
		} else alert('Ошибка соединения! Проверьте подключение к сети и повторите попытку.');
	} else document.getElementById('shadow').style.display='block';
	return false;
}

function closeWindow1(obj) {
	if (obj.readyState == 4) {
        if (obj.status == 200) {
			document.getElementById('order').style.display = "none";
			document.getElementById('shadow').style.display = "none";
		} else alert('Ошибка соединения! Проверьте подключение к сети и повторите попытку.');
	} else document.getElementById('shadow').style.display='block';
	return false;
}

var massIn = new Array('namecl', 'org', 'tel')
function checkStepOne() {
	var full=1;
	for (i=0; i<massIn.length; i++) {
		(document.getElementById(massIn[i]).value=='') ? full*=0 : full*=1; 
	}
	if (full!=0) { 
		document.getElementById('orderB').className="button green";
	} else { 
		document.getElementById('orderB').className="button grey";			
	}
	return false;
}