


function calculate(price, num, div) {
	var reg_2 = new RegExp("^([0-9]*)$");
	if (reg_2.test(num)) {
		if (num == 0) num = 1;
		var val = price * num;
		if (num > 1000) alert("Шутим-с?");
		document.getElementById(div).innerHTML = val;
	}
	else alert("Недопустимое значение! Количество должно быть целым положительным числом.");

}




function CHStat(id) {
	if (document.getElementById(id).className == "") {
		document.getElementById(id).className = 'select_order';
		document.getElementById(id + '_item').value = '1';

	}
	else {
		document.getElementById(id).className = '';
		document.getElementById(id + '_item').value = '0';

	}
}





function CHType(id) {

	if (id == "office_cat") {

		document.getElementById("home_cat_butt").className = '';
		document.getElementById("home_cat").className = 'closed';

		document.getElementById("office_cat_butt").className = 'select_order';
		document.getElementById("office_cat").className = '';

		document.search_form.catalog_thread.value = 'office';
	}
	else {

		document.getElementById("office_cat_butt").className = '';
		document.getElementById("office_cat").className = 'closed';

		document.getElementById("home_cat_butt").className = 'select_order';
		document.getElementById("home_cat").className = '';

		document.search_form.catalog_thread.value = 'home';
	}
}


var A = 0;
var B = 100;

var MaxPrice = 21000;
function setPositions() {
	//document.getElementById('txt').innerHTML=Math.round(MaxPrice*(A)/10000)*100+'р. \n'+Math.round(MaxPrice*(B)/10000)*100+' р.';
	document.search_form.start_price.value = Math.round(MaxPrice * (A) / 10000) * 100;
	if (Math.round(MaxPrice * (B) / 10000) * 100 == 21000) var f_p = '21000 >';
	else var f_p = Math.round(MaxPrice * (B) / 10000) * 100;
	document.search_form.finish_price.value = f_p;
}


$(window).bind("load", function() {


	$('#slider').slider({ steps: 10, minValue: 0, maxValue: 1000, range: true, slide: function(e, ui) {
		A = $('#slider').slider('value', 0);
		B = $('#slider').slider('value', 1);
		setPositions();
	}
	});
});

function ValidateOrderForm() {
	if (document.forms.namedItem("order") == null)
	{ return false; }

	var orderForm = document.order;
	var formElements = orderForm.elements;

	var isValid = true;

	var firstNameTextBox = formElements["order[name]"];
	var firstName = firstNameTextBox.value;
	if (firstName.length == 0) {
		isValid = false;
		firstNameTextBox.className = "inp_text_invalid";
	}
	else {
		firstNameTextBox.className = "inp_text";
	}

	var phoneTextBox = formElements["order[phone]"];
	var phone = phoneTextBox.value;
	if (phone.length == 0) {
		isValid = false;
		phoneTextBox.className = "inp_text_invalid";
	}
	else {
		phoneTextBox.className = "inp_text";
	}

	var volumeTextBox = formElements["order[num]"];
	var volume = parseInt(volumeTextBox.value);
	if (volume == 0 || isNaN(volume)) {
		isValid = false;
		volumeTextBox.className = "inp_count_invalid";
	}
	else{
		volumeTextBox.className = "inp_count";
	}

	var legalPersonAdditionalDataRegion = document.getElementById("add_fields");
	var additionalRegionDisplay = legalPersonAdditionalDataRegion.style.display;
	var isLegalPerson = additionalRegionDisplay == "block";
	if (isLegalPerson) {
		var legalAddressTextBox = formElements["order[address]"];
		var legalAddress = legalAddressTextBox.value;
		if (legalAddress.length == 0) {
			isValid = false;
			legalAddressTextBox.className = "invalid";
		}
		else {
			legalAddressTextBox.className = "";
		}

		var innTextBox = formElements["order[inn]"];
		var inn = innTextBox.value;
		if (inn.length == 0) {
			isValid = false;
			innTextBox.className = "inp_text_invalid";
		}
		else {
			innTextBox.className = "inp_text";
		}

		var korrscetTextBox = formElements["order[korrscet]"];
		var korrscet = korrscetTextBox.value;
		if (korrscet.length == 0) {
			isValid = false;
			korrscetTextBox.className = "inp_text_invalid";
		}
		else {
			korrscetTextBox.className = "inp_text";
		}

		var bikTextBox = formElements["order[bik]"];
		var bik = bikTextBox.value;
		if (bik.length == 0) {
			isValid = false;
			bikTextBox.className = "inp_text_invalid";
		}
		else {
			bikTextBox.className = "inp_text";
		}
		
	}
	if(!isValid)	{		document.getElementById("orderFormValidationHint").style.display="block";	}
	return isValid;
}
	
	
