//----------------------------------------------------------------------------|
// ЗАГАЛЬНІ ФУНКЦІЇ START =====================================================\
var request4 = null;
function checkCities(ctF, ctT) {
	var cityFrom	= getOptionText(document.getElementById(ctF));
	var cityTo		= getOptionText(document.getElementById(ctT));
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Житомир')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Львов')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Тернополь')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Черновцы')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Симферополь')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Житомир')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Львов')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Тернополь')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Черновцы')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Николаев')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Житомир')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Львов')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Тернополь')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Черновцы')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Одесса')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Житомир')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Львов')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Тернополь')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Черновцы')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Херсон')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Днепропетровск')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Донецк')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Запорожье')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Житомир')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Днепропетровск')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Донецк')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Запорожье')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Ужгород')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Днепропетровск')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Донецк')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Запорожье')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Львов')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Днепропетровск')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Донецк')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Запорожье')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Тернополь')&&(cityTo == 'Чернигов')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Днепропетровск')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Донецк')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Запорожье')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Мелитополь')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Полтава')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Кременчуг')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Харьков')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Черкассы')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Умань')) return 1;
	if ((cityFrom == 'Черновцы')&&(cityTo == 'Чернигов')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Житомир')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Львов')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Тернополь')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Черновцы')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Симферополь')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Житомир')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Львов')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Тернополь')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Черновцы')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Николаев')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Житомир')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Львов')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Тернополь')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Черновцы')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Одесса')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Житомир')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Львов')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Тернополь')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Черновцы')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Херсон')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Днепропетровск')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Донецк')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Запорожье')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Житомир')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Днепропетровск')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Донецк')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Запорожье')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Ужгород')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Днепропетровск')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Донецк')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Запорожье')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Львов')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Днепропетровск')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Донецк')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Запорожье')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Тернополь')&&(cityFrom == 'Чернигов')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Днепропетровск')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Донецк')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Запорожье')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Мелитополь')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Полтава')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Кременчуг')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Харьков')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Черкассы')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Умань')) return 1;
	if ((cityTo == 'Черновцы')&&(cityFrom == 'Чернигов')) return 1;
	return 0;
}
// формат дней
function checkDays(val) {
	var n = val/10;
	var cile = Math.floor(n);
	var drib = n - cile;
    var days = Math.round(drib*10)/10*10;
	if (days == 1) days1 = 'рабочего дня';
    if ((days > 1)&&(days < 5)) days1 = 'рабочих дней';
    if (days > 5) days1 = 'рабочих дней';
	if ((val > 10)&&(val < 20)) {
    	days1 = 'рабочих дней';
    }
	return days1;
}
function verifyVes(ves,n) {
	if (n == 2) {
		verifyFloat(ves);
		if (document.getElementById('goods').value == 'doc') {
			if (parseFloat(document.getElementById(ves).value) > 5) document.getElementById(ves).value = 5;
		}
	} else {
		if (parseFloat(document.getElementById(ves).value) > 5) document.getElementById(ves).value = 5;
	}
}
function createRequest4() {
	try {
		request4 = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request4 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request4 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				request4 = null;
			}
		}
	}
		if (request4 == null) alert("Error creating request object!");
}
function noIfNSF() {
	if (document.getElementById('townsFrom').value == '0') {
		document.getElementById('townsTo').options[0].selected = true;
		alert('Выберите пункт отправления!');
	}
}
function getTopCtrListFrom() {
	createRequest4();
	var ctr = document.getElementById('townsFrom').value;
	var url = "script/getTopCtrListFrom.php?ctr=" + escape(ctr);
	request4.open("GET", url, true);
	request4.onreadystatechange = updateTopCtrListTo;
	request4.send(null);
}
function updateTopCtrListTo() {
	if (request4.readyState == 4) {
		var newRegions = eval(request4.responseText);
		var regNumb = newRegions.length;
		var oRegList1 = document.getElementById('townsTo');
		oRegList1.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите страну...';
					newRegListOption.value = '0';
					(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
				} else {
					newRegListOption.text = newRegions[i].text;
					newRegListOption.value = newRegions[i].id;
					(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList1.options[i] = new Option('Выберите страну...', '0', false, false);
				} else {
					oRegList1.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
				}
			}
		}
		if (parseInt(document.getElementById('townsFrom').value) == 1) {			oRegList1.options[regNumb+1] = new Option('другая страна', 'other', false, false);		}
	}
}
// Бродим по закладкам
function varChange(id) {
	var varSel1 = document.getElementById('var01');
	var varSel2 = document.getElementById('var02');
	var varSel3 = document.getElementById('var03');
	var varCont1 = document.getElementById('var11');
	var varCont2 = document.getElementById('var12');
	var varCont3 = document.getElementById('var13');
	switch (id) {
		case 1:	varSel1.style.background = 'url(img/2ASheet.gif) top left no-repeat';
				varSel2.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel3.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel1.style.color = 'Black';
				varSel2.style.color = 'White';
				varSel3.style.color = 'White';
				varCont1.style.display = 'block';
				varCont2.style.display = 'none';
				varCont3.style.display = 'none';
				break;
		case 2:	varSel1.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel2.style.background = 'url(img/2ASheet.gif) top left no-repeat';
				varSel3.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel1.style.color = 'White';
				varSel2.style.color = 'Black';
				varSel3.style.color = 'White';
				varCont1.style.display = 'none';
				varCont2.style.display = 'block';
				varCont3.style.display = 'none';
				break;
		case 3:	varSel1.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel2.style.background = 'url(img/2NASheet.gif) top left no-repeat';
				varSel3.style.background = 'url(img/2ASheet.gif) top left no-repeat';
				varSel1.style.color = 'White';
				varSel2.style.color = 'White';
				varSel3.style.color = 'Black';
				varCont1.style.display = 'none';
				varCont2.style.display = 'none';
				varCont3.style.display = 'block';
				break;
	}
}
// Допоміжна функція - вертає текст вибраного елементу з випадаючого списку
function getOptionText(oListbox) {

	for (var i=0; i < oListbox.options.length; i++)
	{
    	if (oListbox.options[i].selected) arrIndex = i;
	}
	var res = oListbox.options[arrIndex].text;
	return res;
}
// Вертає вагу вантажу (максимальну, заокруглену в більшу сторону до цілого)
function weightP(weight, x, y, z) {
	var tType1	= document.form1.Type11.value;
	var x = parseInt(x);
	var y = parseInt(y);
	var z = parseInt(z);
	var weigth = parseFloat(weight);

	var xyz = x*y*z/6000;

	if (weight >= xyz) weight = weight;
	else weight = xyz;

	weight = Math.ceil(weight);

	return weight;
}
// Вертає вагу вантажу (максимальну, заокруглену в більшу сторону до дрібного з кроком 0.5)
function weightPD(weight, x, y, z) {
	var tType1	= document.form1.Type11.value;
	var x = parseInt(x);
	var y = parseInt(y);
	var z = parseInt(z);
	var weigth = parseFloat(weight);
	var xyz = x*y*z/6000;
	if (weight >= xyz) weight = weight;
	else weight = xyz;
	var cile = Math.floor(weight);
	var drib = weight - cile;
	if (drib == 0) {
		weight = weight;
	} else if (drib <= 0.5) {
		weight = cile + 0.5;
	} else {
		weight = cile + 1;
	}
	weight = (Math.round(weight*10)/10);
	return weight;
}
// Check if input is a float number
function verifyFloat(frm) {
	var element = document.getElementById(frm);
	if(isNaN(new Number(element.value)))
		element.value = element.value.substring(0, element.value.length - 1);
}
// Check if input is a int number
function verifyInt(frm) {
	var element = document.getElementById(frm);
	if(isNaN(new Number(element.value)))
		element.value = element.value.substring(0, element.value.length - 1);
	var val = parseInt(element.value);
	var str = '' + val;
	if (str != element.value)
		element.value = element.value.substring(0, element.value.length - 1);
}
function checkInt(field)
{
	var reg = /\d+/;
  	var tst = reg.test(field.value);
  	var val = parseInt(field.value,10);
	var str = '' + val;
	if ((str != field.value)||(tst == false)) return false;
 	if (isNaN(val))	return false;
  	if (val < 0)	return false;
  	return true;
}
// Min delivery date
function minDays(id1, id2, id3) {
	var fromC	= document.getElementById(id1);
	var toC		= document.getElementById(id2);
	var toDate	= document.getElementById(id3);
	var tarif1 = fromC.value.substring(0,2);
	var tarif2 = toC.value.substring(0,2);
	switch (tarif1) {
		case 'se':	days1 = 0;	break;
		case 'U2':	days1 = 1;	break;
		case 'U3':	days1 = 1;	break;
		case 'U4':	days2 = 1;	break;
		case 'U5':	days2 = 1;	break;
	}
	switch (tarif2) {
		case 'se':	days2 = 0;	break;
		case 'U2':	days2 = 1;	break;
		case 'U3':	days2 = 1;	break;
		case 'U4':	days2 = 1;	break;
		case 'U5':	days2 = 2;	break;
	}
	dateTrans(id3, days1 + days2);
}
// Transform date to required format
/*function dateTrans(id, n) {
	var sel	= document.getElementById(id);
	var da	= new Date();
	da.setTime(n*24*60*60*1000+da.getTime());
	day = da.getDate();
	month = da.getMonth() + 1;
	year = da.getFullYear();
	if (day < 10) {
		day = "0" + day;
	}
	if (month < 10) {
		month = "0" + month;
	}
	datetime = day + "." + month + "." + year;
	sel.value = datetime;
}*/
function dateTrans(id, n) {
	var sel	= document.getElementById(id);
	var datetime = "до " + n + " " + checkDays(n);
	sel.value = datetime;
}
// ЗАГАЛЬНІ ФУНКЦІЇ END =======================================================/
//----------------------------------------------------------------------------|
//																			  |
//----------------------------------------------------------------------------|
// TAB 1 START ================================================================\
// Create Request1
var request1 = null;

function createRequest1() {
	try {
		request1 = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request1 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request1 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				request1 = null;
			}
		}
	}
		if (request1 == null) alert("Error creating request object!");
}
// Якщо VIP - вивести час
function changeVIP(sel, t) {
	var hoursVIP	= parseInt(document.form1.VIPh.value);
	var vipT 		= document.getElementById(t);
	var vipS 		= document.getElementById(sel);
	var oType		= document.form1.time;
	var TypeD 		= document.form1.Type11;
	var nWeight		= document.form1.weight;
	var dFrom		= parseInt(document.form1.dateFrom1.value);
	var dTo			= parseInt(document.form1.dateTo1.value);
	oType.length = 0;
	document.getElementById('typeD1').style.color = 'black';
	if (isNaN(parseInt(nWeight.value))) nWeight.value = 0;
	if (parseInt(nWeight.value) > 5) nWeight.value = 5;
	if (vipS.value == '3') {
		if (parseInt(nWeight.value) > 3) nWeight.value = 3;
		switch (hoursVIP) {
			case 9:		oType.options[0] = new Option('9:00', '9', false, false);
						oType.options[1] = new Option('10:00', '10', false, false);
						oType.options[2] = new Option('12:00', '12', false, false);
						break;
			case 10:	oType.options[0] = new Option('10:00', '10', false, false);
						oType.options[1] = new Option('12:00', '12', false, false);
						break;
			case 12: 	oType.options[0] = new Option('12:00', '12', false, false);
						break;
		}
		vipT.style.display = 'inline';
		if (TypeD.value == 'box') TypeD.value = 'doc';
        dateTrans('date', 1 + checkCities('CityFrom1', 'CityTo1'));
	} else if (vipS.value == '2') {
		vipT.style.display = 'none';
		dateTrans('date', dFrom + dTo);
	} else if (vipS.value == '1') {
		vipT.style.display = 'none';
		dateTrans('date', dFrom + dTo);
	}
}
// Страхова сума не більше 5000 гривень
function strahChangeF1() {
	var sVal 	= document.form1.strah.value;
	var cVal 	= document.form1.curency.value;
	var cE		= document.form4.cEUR.value;
	var cR		= document.form4.cRUB.value;
	var cD		= document.form4.cUSD.value;
	var maxE	= Math.floor(parseInt(5000/cE));
	var maxR	= Math.floor(parseInt(5000/cR));
	var maxD	= Math.floor(parseInt(5000/cD));
	switch (cVal) {
		case "UAH": if (sVal > 5000) document.form1.strah.value = 5000; break;
		case "RUB": if (sVal > maxR) document.form1.strah.value = maxR; break;
		case "EUR": if (sVal > maxE) document.form1.strah.value = maxE; break;
		case "USD": if (sVal > maxD) document.form1.strah.value = maxD; break;
	}
    verifyInt('strah');
}
// Страховка в гривнях (0,15% від страхової суми - Україна)
function toHRN(val) {
	var cVal 	= document.form1.curency.value;
	var cE		= document.form4.cEUR.value;
	var cR		= document.form4.cRUB.value;
	var cD		= document.form4.cUSD.value;
	var val = parseFloat(val);
	switch (cVal) {
		case "UAH": val = Math.round(val*0.015*100)/100; break;
		case "RUB": val = Math.round(val*cR*0.015*100)/100; break;
		case "EUR": val = Math.round(val*cE*0.015*100)/100; break;
		case "USD": val = Math.round(val*cD*0.015*100)/100; break;
	}

	return val;
}
// Страховка в гривнях (0,15% від страхової суми - СНД)
function toHRN2(val) {
	var cVal 	= document.form2.curency2.value;
	var cE		= document.form4.cEUR.value;
	var cR		= document.form4.cRUB.value;
	var cD		= document.form4.cUSD.value;
	var val = parseFloat(val);
	switch (cVal) {
		case "UAH": val = Math.round(val*0.03*100)/100; break;
		case "RUB": val = Math.round(val*cR*0.03*100)/100; break;
		case "EUR": val = Math.round(val*cE*0.03*100)/100; break;
		case "USD": val = Math.round(val*cD*0.03*100)/100; break;
	}
	return val;
}
// Якщо тип "Дкументи" або "ВІП" обмежити максимальне значення ваги
function chWVIP(n) {
	var isVIP 	= document.form1.Type12.value;
	var TypeD 	= document.form1.Type11;
	var nX		= parseInt(document.form1.x.value);
	var nY		= parseInt(document.form1.y.value);
	var nZ		= parseInt(document.form1.z.value);
	var nWeight	= parseFloat(document.form1.weight.value);
	if (nX > 500) document.form1.x.value = 500;
	if (nY > 500) document.form1.y.value = 500;
	if (nZ > 500) document.form1.z.value = 500;
	document.getElementById('go1').style.color = 'black';
    document.getElementById('vo1').style.color = 'black';
	switch (n) {
		case 0: verifyFloat('weight'); break;
		case 1: verifyInt('x'); break;
		case 2: verifyInt('y'); break;
		case 3: verifyInt('z'); break;
	}

    if (TypeD.value == 'doc') {
		if (isNaN(nX)) nX = 0;
		if (isNaN(nY)) nY = 0;
		if (isNaN(nZ)) nZ = 0;
		if (isNaN(nWeight)) nWeight = 0;
		var weight	= weightPD(nWeight, nX, nY, nZ);
  		//alert(weight);
  		if (isVIP == '3') {
			if (weight > 3) {
			switch (n) {
				case 0: document.form1.weight.value = 3; break;
				case 1:
                    weightX = Math.floor(18000/(nY*nZ));
					yy = nY;
					xx = weightX;
					if (weightPD(nWeight, weightX, nY, nZ) > 3)
					{

						yy = Math.floor(18000/(weightX*nZ));

					}
					document.form1.x.value = xx;
					document.form1.y.value = yy;
					break;
					break;
				case 2:
                    weightY = Math.floor(18000/(nX*nZ));
					zz = nZ;
					yy = weightY;
					if (weightPD(nWeight, nX, weightY, nZ) > 3)
					{

						zz = Math.floor(18000/(weightY*nZ));

					}
					document.form1.y.value = yy;
					document.form1.z.value = zz;
					break;
				case 3:
                    weightZ = Math.floor(18000/(nX*nY));
					xx = nX;
					zz = weightZ;
					if (weightPD(nWeight, nX, nY, weightZ) > 3)
					{

						xx = Math.floor(18000/(weightZ*nY));

					}
					document.form1.x.value = xx;
					document.form1.z.value = zz;
					break;
			}
			}
		}
		else
		{
		if (weight > 5) {
			switch (n) {
				case 0: document.form1.weight.value = 5; break;
				case 1:
					weightX = Math.floor(30000/(nY*nZ));
					yy = nY;
					xx = weightX;
					if (weightPD(nWeight, weightX, nY, nZ) > 5)
					{

						yy = Math.floor(30000/(weightX*nZ));

					}
					document.form1.x.value = xx;
					document.form1.y.value = yy;
					break;
				case 2:
					weightY = Math.floor(30000/(nX*nZ));
					zz = nZ;
					yy = weightY;

					if (weightPD(nWeight, nX, weightY, nZ) > 5)
					{

						zz = Math.floor(30000/(weightY*nZ));

					}
					document.form1.y.value = yy;
					document.form1.z.value = zz;
					break;
				case 3:
					weightZ = Math.floor(30000/(nX*nY));
					xx = nX;
					zz = weightZ;
					if (weightPD(nWeight, nX, nY, weightZ) > 5)
					{

						xx = Math.floor(30000/(weightZ*nY));

					}
					document.form1.x.value = xx;
					document.form1.z.value = zz;
					break;
			}
		}
        }
	}
}
// При виборі типу вантажу "Документи" змінюєм вагу
// Якщо "Товар", то не ВІП
function changeTypeD() {
	var nX		= document.form1.x;
	var nY		= document.form1.y;
	var nZ		= document.form1.z;
	var nWeight	= document.form1.weight;
	var TypeD	= document.form1.Type11;
	var isVIP	= document.form1.Type12;
	var setTime	= document.form1.time;
	document.getElementById('typeO1').style.color = 'black';
	if (nWeight.value == '') w = 0;
	else w = parseInt(nWeight.value);
	if (nX.value == '') x = 0;
	else x = parseInt(nX.value);
	if (nY.value == '') y = 0;
	else y = parseInt(nY.value);
	if (nZ.value == '') z = 0;
	else z = parseInt(nZ.value);
	var weight	= weightP(w, x, y, z);
	if ((TypeD.value == 'doc')&&(weight > 5)) {
		nX.value = nY.value = nZ.value = '';
		nWeight.value = '5';
	}
	if (TypeD.value == 'box') {
		isVIP.value = '1';
		setTime.style.display = 'none';
	}
}
// Заповняємо списки областей з бази
function getRegionsList() {
	createRequest1();
	var url = "script/getRegList.php";
	request1.open("GET", url, true);
	request1.onreadystatechange = updateRegList;
	request1.send(null);
}
function updateRegList() {
	if (request1.readyState == 4) {
		var newRegions = eval(request1.responseText);
		var regNumb = newRegions.length;
		var oRegList1 = document.forms['form1'].elements['RegionFrom1'];
		oRegList1.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите область...';
					newRegListOption.value = '0';
					(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
				} else {
					newRegListOption.text = newRegions[i].text;
					newRegListOption.value = newRegions[i].id;
					(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList1.options[i] = new Option('Выберите область...', '0', false, false);
				} else {
					oRegList1.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
				}
			}
		}
		var oRegList2 = document.forms['form1'].elements['RegionTo1'];
		oRegList2.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите область...';
					newRegListOption.value = '0';
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				} else {
					newRegListOption.text = newRegions[i].text;
					newRegListOption.value = newRegions[i].id;
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList2.options[i] = new Option('Выберите область...', '0', false, false);
				} else {
					oRegList2.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
				}
			}
		}
		var oRegList3 = document.forms['form3'].elements['RegionFrom3'];
		oRegList3.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите область...';
					newRegListOption.value = '0';
					(oRegList3.options.add) ? oRegList3.options.add(newRegListOption) : oRegList3.add(newRegListOption, null);
				} else {
					newRegListOption.text = newRegions[i].text;
					newRegListOption.value = newRegions[i].id;
					(oRegList3.options.add) ? oRegList3.options.add(newRegListOption) : oRegList3.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList3.options[i] = new Option('Выберите область...', '0', false, false);
				} else {
					oRegList3.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
				}
			}
		}
	}
}
// Заповняємо список міст "Откуда" в залежності від обраної області
function getCF1() {
	var reg	 		= document.form1.RegionFrom1.value;
	var ctTo 		= document.form1.CityTo1.value;
	var ctFromStyle	= document.form1.CityFrom1;
	var url 		= "script/getCityList.php?region=" + escape(reg) + "&ctto=" + escape(ctTo);
	if (reg != 0) ctFromStyle.style.display = 'inline';
	else ctFromStyle.style.display = 'none';
	createRequest1();
	request1.open("GET", url, true);
	request1.onreadystatechange = updateCityListFrom;
	request1.send(null);
}
function updateCityListFrom() {
	if (request1.readyState == 4) {
		var newCities = eval(request1.responseText);
		var ctNumb = newCities.length;
		var oCityList1 = document.forms['form1'].elements['CityFrom1'];
		oCityList1.length = 0;
		for (i = -1; i < ctNumb; i++){
			if (document.createElement){
				var newCityListOption = document.createElement("OPTION");
				if (i == -1) {
					newCityListOption.text = 'Выберите город...';
					newCityListOption.value = '0';
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				} else {
					newCityListOption.text = newCities[i].text;
					newCityListOption.value = newCities[i].id;
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				}
			}else{
				if (i == -1) {
					oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
				} else {
					oCityList1.options[i] = new Option(newCities[i].text, newCities[i].id, false, false);
				}
			}
		}
	}
}
// Заповняємо список міст "Куда" в залежності від обраної області
function getCT1() {
	var reg 		= document.form1.RegionTo1.value;
	var ctTo 		= document.form1.CityFrom1.value;
	var ctToStyle	= document.form1.CityTo1;
	var url 		= "script/getCityList.php?region=" + escape(reg) + "&ctto=" + escape(ctTo);
	if (reg != 0) ctToStyle.style.display = 'inline';
	else ctToStyle.style.display = 'none';
    if ((ctTo == '0')&&(reg != 0)) {
		document.form1.error.value = 'Выберите пункт отправления!';
		document.form1.RegionTo1.value = '0';
	} else {
		createRequest1();
		request1.open("GET", url, true);
		request1.onreadystatechange = updateCityListTo;
		request1.send(null);
	}
}
function updateCityListTo() {
	if (request1.readyState == 4) {
		var newCities = eval(request1.responseText);
		var ctNumb = newCities.length;
		var oCityList1 = document.forms['form1'].elements['CityTo1'];
		oCityList1.length = 0;
		for (i = -1; i < ctNumb; i++){
			if (document.createElement){
				var newCityListOption = document.createElement("OPTION");
				if (i == -1) {
					newCityListOption.text = 'Выберите город...';
					newCityListOption.value = '0';
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				} else {
					newCityListOption.text = newCities[i].text;
					newCityListOption.value = newCities[i].id;
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				}
			}else{
				if (i == -1) {
					oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
				} else {
					oCityList1.options[i] = new Option(newCities[i].text, newCities[i].id, false, false);
				}
			}
		}
	}
}
// Змінюємо дату доставки в залежності від тарифу (БЕЗ врахування вихідних і святкових днів)
function funcCtFrom() {
	var ctFrom	= document.form1.CityFrom1.value;
	var ctTo	= document.form1.CityTo1.value;
	var url		= "script/getCtFrom3Val.php?ctto=" + escape(ctTo) + "&ctfrom=" + escape(ctFrom) + "&typeD=ukr";
	document.getElementById('from1').style.color = 'black';
	var oType	= document.form1.time;
	oType.style.display = 'none';
	if (ctFrom != '0') {
		document.getElementById('error').innerHTML = '';
		if (ctTo != '0') {
			dateTrans('date', parseInt(document.form1.dateTo1.value) + parseInt(document.form1.dateFrom1.value));
		}
	}
	createRequest1();
	request1.open("GET", url, true);
	request1.onreadystatechange = updateCtFrom3Val;
	request1.send(null);
}
function updateCtFrom3Val() {
	if (request1.readyState == 4) {
		var data = eval(request1.responseText);
		var newTFrom	= data[0];
		var newDateTo	= parseInt(data[1]);
		var newDateFrom = parseInt(data[2]);
		var newDV		= parseInt(data[3]);
		var newVIP		= parseInt(data[4]);
		var newVIPh		= parseInt(data[5]);
		var hoursVIP	= document.form1.VIPh;
		var dFrom		= document.form1.dateFrom1;
		var dTo			= document.form1.dateTo1;
		dFrom.value = newDateFrom;
        dTo.value = newDateTo;
		hoursVIP.value = newVIPh;
		dateTrans('date', newDateTo + newDateFrom);
		var oType = document.forms['form1'].elements['Type12'];
		oType.length = 0;
		oType.options[0] = new Option('Выберите тип доставки...', '0', false, false);
		oType.options[1] = new Option('Экспресс', '1', false, false);
        if (newDV != 0) {
        	oType.options[2] = new Option('До востребования', '2', false, false);
        	s = 3;
        } else s = 2;
        if (newVIP != 0) oType.options[s] = new Option('VIP', '3', false, false);
	}
}
// В залежності від обраного міста заповнюєм список типів доставки і міняєм дату доставки
function funcCtTo() {
	var ctFrom 	= document.form1.CityFrom1.value;
	var ctTo   	= document.form1.CityTo1.value;
	var url		= "script/getCtTo4Val.php?ctto=" + escape(ctTo) + "&ctfrom=" + escape(ctFrom) + "&typeD=ukr";
	document.getElementById('to1').style.color = 'black';
	var oType	= document.form1.time;
	oType.style.display = 'none';
	createRequest1();
	request1.open("GET", url, true);
	request1.onreadystatechange = updateCtTo4Val;
	request1.send(null);
}
function updateCtTo4Val() {
	if (request1.readyState == 4) {
		var data = eval(request1.responseText);
		var newDateTo	= parseInt(data[0].dateto);
		var newDateFrom = parseInt(data[0].datefrom);
		var newVIP		= parseInt(data[0].vip);
		var newDV		= parseInt(data[0].DV);
		var newVIPh		= parseInt(data[0].vipH);
		var hoursVIP	= document.form1.VIPh;
		var dFrom		= document.form1.dateFrom1;
		var dTo			= document.form1.dateTo1;
		dFrom.value = newDateFrom;
        dTo.value = newDateTo;
		hoursVIP.value = newVIPh;
        dateTrans('date', newDateTo + newDateFrom);
        var oType = document.forms['form1'].elements['Type12'];
		oType.length = 0;
		oType.options[0] = new Option('Выберите тип доставки...', '0', false, false);
		oType.options[1] = new Option('Экспресс', '1', false, false);
        if (newDV != 0) {
        	oType.options[2] = new Option('До востребования', '2', false, false);
        	s = 3;
        } else s = 2;
        if (newVIP != 0) oType.options[s] = new Option('VIP', '3', false, false);
	}
}
// Управління помилками для 1ої закладки
function errorHandler() {
	var fromP	= document.getElementById('from1').style;
	var toP		= document.getElementById('to1').style;
	var typeOP	= document.getElementById('typeO1').style;
	var typeDP	= document.getElementById('typeD1').style;
	var goP		= document.getElementById('go1').style;
	var voP		= document.getElementById('vo1').style;
	var error = '';
	var mark  = 0;
	var mark1 = 0;
	var mark2 = 0;
	var nn = 0;
	if (document.form1.CityFrom1.value == '0') {
		mark = 1;
		fromP.color = 'red';
	}
	if (document.form1.CityTo1.value == '0') {
		mark = 1;
		toP.color = 'red';
	}
	if (document.form1.Type11.value == '0') {
		mark = 1;
		typeOP.color = 'red';
	}
	if (document.form1.Type12.value == '0') {
		mark = 1;
		typeDP.color = 'red';
	}
	if (document.form1.x.value == '') mark1 = 1;
	if (document.form1.y.value == '') mark1 = 1;
	if (document.form1.z.value == '') mark1 = 1;
	if ((document.form1.weight.value == '')||(document.form1.weight.value == '0')) mark2 = 1;
	if ((mark1 == 1)&&(mark2 == 1)) {
		mark = 1;
		goP.color = 'red';
		voP.color = 'red';
	}
	if ((checkInt(document.form1.x)==false)&&(document.form1.x.value != '')) {
		nn = 1;
		mark = 2;
		goP.color = 'red';
	}
	if ((checkInt(document.form1.y)==false)&&(document.form1.y.value != '')) {
		mark = 2;
		goP.color = 'red';
	}
	if ((checkInt(document.form1.z)==false)&&(document.form1.z.value != '')) {
		mark = 2;
		goP.color = 'red';
	}

	if (mark == 1) {
		error = 'Заполнены не все поля!';
	}
	if (mark == 2) {
		error = 'Неверный формат данных!';
	}
	return error;
}
// Очистка формы 1
function clear1() {
	document.form1.RegionFrom1.value = "0";
	document.form1.CityFrom1.style.display = "none";
	document.form1.RegionTo1.value = "0";
	document.form1.CityTo1.style.display = "none";
	document.form1.Type11.value = "0";
	document.form1.Type12.value = "0";
	document.form1.date.value = "";
	document.form1.time.value = "";
	document.form1.strah.value = "";
	document.form1.x.value = "";
	document.form1.y.value = "";
	document.form1.z.value = "";
	document.form1.weight.value = "";
	document.form1.valUAH.value = "";
	document.getElementById("error").innerHTML = "";
	document.getElementById("from1").style.color = "Black";
	document.getElementById("to1").style.color = "Black";
	document.getElementById("typeO1").style.color = "Black";
	document.getElementById("typeD1").style.color = "Black";
	document.getElementById("go1").style.color = "Black";
	document.getElementById("vo1").style.color = "Black";
}
// Калькуляція для 1ї закладки
function calculate1() {
	var er = document.getElementById('error');
	if (errorHandler() == '') {
		var nX		= parseInt(document.form1.x.value);
		var nY		= parseInt(document.form1.y.value);
		var nZ		= parseInt(document.form1.z.value);
		var nWeight	= parseFloat(document.form1.weight.value);
		var nStrah	= parseInt(document.form1.strah.value);
		if (isNaN(nX)) nX = 0;
		if (isNaN(nY)) nY = 0;
		if (isNaN(nZ)) nZ = 0;
		if (isNaN(nWeight)) nWeight = 0;
		if (isNaN(nStrah)) nStrah = 0;
		var tFrom	= document.form1.CityFrom1.value;
		var tTo		= document.form1.CityTo1.value;
		var tType1	= document.form1.Type11.value;
		var tType2	= document.form1.Type12.value;
		var tStrah	= toHRN(nStrah);
        var tWeight = weightP(nWeight, nX, nY, nZ);
        if (parseInt(tType2) == 3) vipH	= document.form1.time.value;
        else vipH	= 0;
        //alert(nX + ", " + nY + ", " + nZ + ", " + tFrom + ", " + tTo + ", " + tType1 + ", " + tType2 + ", " + vipH + ", " + tStrah + ", " + tWeight);
		var url = "script/calcForm1.php?ctfrom=" + escape(tFrom) + "&ctto=" + escape(tTo) + "&type1=" + escape(tType1) + "&type2=" + escape(tType2) + "&vipH=" + escape(vipH) + "&strah=" + escape(tStrah) + "&weight=" + escape(tWeight);
		er.innerHTML = '<input type="button" value="Заказать доставку" onclick="onlineApp()">';
		createRequest1();
		request1.open("GET", url, true);
		request1.onreadystatechange = calcF1;
		request1.send(null);
	} else {
		er.innerHTML = errorHandler();
	}
}
function calcF1() {
	if (request1.readyState == 4) {
		var newResult	= eval(request1.responseText);
		var resText		= document.getElementById("result");
		var res		 	= document.form1.valUAH;
		var text		= newResult[0].text;
        newResult = Math.round(newResult[0].res*100)/100;
		res.value = newResult + ' грн.';
		if (resText) resText.innerHTML = text;
	}
}
// TAB 1 END ==================================================================/
//----------------------------------------------------------------------------|
//																			  |
//----------------------------------------------------------------------------|
// TAB 2 START ================================================================\

// Страхова сума не більше 5000$
function strahChangeF2() {
	var sVal 	= document.form2.strah2.value;
	var cVal 	= document.form2.curency2.value;
	var cE		= document.form4.cEUR.value;
	var cR		= document.form4.cRUB.value;
	var cD		= document.form4.cUSD.value;
	var maxD	= 5000;
	var maxH	= Math.floor(parseInt(5000*cD));
	var maxE	= Math.floor(parseInt(maxH/cE));
	var maxR	= Math.floor(parseInt(maxH/cR));
	switch (cVal) {
		case "UAH": if (sVal > maxH) document.form2.strah2.value = maxH; break;
		case "RUB": if (sVal > maxR) document.form2.strah2.value = maxR; break;
		case "EUR": if (sVal > maxE) document.form2.strah2.value = maxE; break;
		case "USD": if (sVal > maxD) document.form2.strah2.value = maxD; break;
	}
    verifyInt('strah2');
}
// Якщо тип "Дкументи" або "ВІП" обмежити максимальне значення ваги
function chWVIP2(n) {
	var isVIP 	= document.form2.Type22.value;
	var TypeD 	= document.form2.Type21;
	var nX		= parseInt(document.form2.x2.value);
	var nY		= parseInt(document.form2.y2.value);
	var nZ		= parseInt(document.form2.z2.value);
	var nWeight	= parseFloat(document.form2.weight2.value);
	var goP		= document.getElementById('go2').style;
	var voP		= document.getElementById('vo2').style;
	goP.color = 'Black';
	voP.color = 'Black';
	if (nX > 500) document.form2.x2.value = 500;
	if (nY > 500) document.form2.y2.value = 500;
	if (nZ > 500) document.form2.z2.value = 500;
	switch (n) {
		case 0: verifyFloat('weight2'); break;
		case 1: verifyInt('x2'); break;
		case 2: verifyInt('y2'); break;
		case 3: verifyInt('z2'); break;
	}

	if (TypeD.value == 'doc') {
		if (isNaN(nX)) nX = 0;
		if (isNaN(nY)) nY = 0;
		if (isNaN(nZ)) nZ = 0;
		if (isNaN(nWeight)) nWeight = 0;
		var weight	= weightPD(nWeight, nX, nY, nZ);
		if (isVIP == '3') {
			if (weight > 3) {
			switch (n) {
				case 0: document.form2.weight2.value = 3; break;
				case 1:
                    weightX = Math.floor(18000/(nY*nZ));
					yy = nY;
					xx = weightX;
					if (weightPD(nWeight, weightX, nY, nZ) > 3)
					{

						yy = Math.floor(18000/(weightX*nZ));

					}
					document.form2.x2.value = xx;
					document.form2.y2.value = yy;
					break;
				case 2:
                    weightY = Math.floor(18000/(nX*nZ));
					zz = nZ;
					yy = weightY;
					if (weightPD(nWeight, nX, weightY, nZ) > 3)
					{

						zz = Math.floor(18000/(weightY*nZ));

					}
					document.form2.y2.value = yy;
					document.form2.z2.value = zz;
					break;
				case 3:
                    weightZ = Math.floor(18000/(nX*nY));
					xx = nX;
					zz = weightZ;
					if (weightPD(nWeight, nX, nY, weightZ) > 3)
					{

						xx = Math.floor(18000/(weightZ*nY));

					}
					document.form2.x2.value = xx;
					document.form2.z2.value = zz;
					break;
			}
			}
		}
		else
		{
		if (weight > 5) {
			switch (n) {
				case 0: document.form2.weight2.value = 5; break;
				case 1:
                    weightX = Math.floor(30000/(nY*nZ));
					yy = nY;
					xx = weightX;
					if (weightPD(nWeight, weightX, nY, nZ) > 5)
					{
						yy = Math.floor(30000/(weightX*nZ));
					}
					document.form2.x2.value = xx;
					document.form2.y2.value = yy;
					break;
					break;
				case 2:
                    weightY = Math.floor(30000/(nX*nZ));
					zz = nZ;
					yy = weightY;
					if (weightPD(nWeight, nX, weightY, nZ) > 5)
					{
						zz = Math.floor(30000/(weightY*nZ));
					}
					document.form2.y2.value = yy;
					document.form2.z2.value = zz;
					break;
				case 3:
                    weightZ = Math.floor(30000/(nX*nY));
					xx = nX;
					zz = weightZ;
					if (weightPD(nWeight, nX, nY, weightZ) > 5)
					{
						xx = Math.floor(30000/(weightZ*nY));
					}
					document.form2.x2.value = xx;
					document.form2.z2.value = zz;
					break;
			}
		}
        }
	}
}
function changeTypeDB() {
	if (document.form2.Type21.value == 'box') {
		if (document.form2.Type22.value == '3') document.form2.Type22.options[1].selected = true;
	}
	document.getElementById('typeO2').style.color = 'Black';

	if (parseFloat(document.form2.weight2.value) > 5) document.form2.weight2.value = 5;
}
function changeTypeVIP() {
	if (document.form2.Type22.value == '3') {
		if (document.form2.Type21.value == 'box') document.form2.Type21.options[1].selected = true;
		dateTrans('date2', 2);
	} else {
		if ((document.form2.dateFrom2.value)&&(document.form2.dateTo2.value)) {
			dateTrans('date2', parseInt(document.form2.dateFrom2.value) + parseInt(document.form2.dateTo2.value) + 1);
		} else document.form2.date2.value = '';
	}
	document.getElementById('typeD2').style.color = 'Black';
}
// Create Request2
var request2 = null;
function createRequest2() {
	try {
		request2 = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request2 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request2 = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				request2 = null;
			}
		}
	}
	if (request2 == null) alert("Error creating request object!");
}
// Заповняємо списки країн СНД з бази
function getSNGList() {	if (document.form2.townsTo.value == 'other') {    	varChange(3);
    	document.form3.weight3.value = document.form2.ves.value;
	}
	createRequest2();
	var url = "script/getSNGList.php";
	request2.open("GET", url, true);
	request2.onreadystatechange = updateSNGList;
	request2.send(null);
}
function updateSNGList() {

	if (request2.readyState == 4) {
		var newRegions = eval(request2.responseText);
		var regNumb = newRegions.length;
		var oRegList1 = document.forms['form2'].elements['CountryFrom2'];
		oRegList1.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите страну...';
					newRegListOption.value = '0';
					(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
				} else {
					if ((newRegions[i].id == '1')||(newRegions[i].id == '2')||(newRegions[i].id == '3')||(newRegions[i].id == '4')||(newRegions[i].id == '14')) {
						newRegListOption.text = newRegions[i].text;
						newRegListOption.value = newRegions[i].id;
						(oRegList1.options.add) ? oRegList1.options.add(newRegListOption) : oRegList1.add(newRegListOption, null);
					}
				}
			}else{
				if (i == -1) {
					oRegList1.options[i] = new Option('Выберите страну...', '0', false, false);
				} else {
					if ((newRegions[i].id == '1')||(newRegions[i].id == '2')||(newRegions[i].id == '3')||(newRegions[i].id == '4')) {
						oRegList1.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
					}
				}
			}
		}
		var oRegList2 = document.forms['form2'].elements['CountryTo2'];
		oRegList2.length = 0;
		for (i = -1; i < regNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите страну...';
					newRegListOption.value = '0';
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				} else {
					newRegListOption.text = newRegions[i].text;
					newRegListOption.value = newRegions[i].id;
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList2.options[i] = new Option('Выберите страну...', '0', false, false);
				} else {
					oRegList2.options[i] = new Option(newRegions[i].text, newRegions[i].id, false, false);
				}

			}
		}
		if (document.form2.townsTo.value != 'other') {
			for (i=0; i<oRegList1.length; i++) {
				if (oRegList1.options[i].value == document.form2.townsFrom.value) oRegList1.options[i].selected = true;
			}
			if (oRegList1.value != '0') {
				getRF2();
			}
			for (i=0; i<oRegList2.length; i++) {
				if (oRegList2.options[i].value == document.form2.townsTo.value) oRegList2.options[i].selected = true;
			}
			/*if (oRegList2.value != '0') {
				getRT2();
			}*/
			for (i = 0; i < 3; i++){
				if (document.form2.Type21.options[i].value == document.form2.goods.value) document.form2.Type21.options[i].selected = true;
			}
			document.form2.weight2.value = document.form2.ves.value;
		}
	}
}
// Заповняємо списки областей "Откуда" обраної країни з бази
function getRF2() {
	var ctr	 = document.form2.CountryFrom2.value;
	var url = "script/getRegFromList2.php?ctr=" + escape(ctr);
	document.form2.RegionTo2.style.display = 'none';
	document.form2.CityTo2.style.display = 'none';
	document.form2.date2.value = '';
	if (ctr == '0') {
		getSNGList();
		document.form2.RegionFrom2.style.display = 'none';
		document.form2.CityFrom2.style.display = 'none';
	} else {
		createRequest2();
		request2.open("GET", url, true);
		request2.onreadystatechange = updateRegListFrom2;
		request2.send(null);
	}
}
function updateRegListFrom2() {
	if (request2.readyState == 4) {
		var ctr	 = document.form2.CountryFrom2.value;
		var newCTR = eval(request2.responseText);
		var newCities = newCTR[0].cities;
		var ctNumb = newCities.length;
		if (newCities[0].reg_id) {
			var oCityList1 = document.forms['form2'].elements['RegionFrom2'];
			oCityList1.length = 0;
			for (i = -1; i < ctNumb; i++){
				if (document.createElement){
					var newCityListOption = document.createElement("OPTION");
					if (i == -1) {
						newCityListOption.text = 'Выберите область...';
						newCityListOption.value = '0';
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					} else {
						newCityListOption.text = newCities[i].text;
						newCityListOption.value = newCities[i].reg_id;
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					}
				}else{
					if (i == -1) {
						oCityList1.options[i] = new Option('Выберите область...', '0', false, false);
					} else {
						oCityList1.options[i] = new Option(newCities[i].text, newCities[i].reg_id, false, false);
					}
				}
			}
			if (ctr != '0') {
				document.form2.RegionFrom2.style.display = 'inline';
				document.form2.CityFrom2.style.display = 'none';
			} else {
				document.form2.RegionFrom2.style.display = 'none';
				document.form2.CityFrom2.style.display = 'none';
			}
		} else if (newCities[0].ct_id) {
			var oCityList1 = document.forms['form2'].elements['CityFrom2'];
			oCityList1.length = 0;
			for (i = -1; i < ctNumb; i++){
				if (document.createElement){
					var newCityListOption = document.createElement("OPTION");
					if (i == -1) {
						newCityListOption.text = 'Выберите город...';
						newCityListOption.value = '0';
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					} else {
						newCityListOption.text = newCities[i].text;
						newCityListOption.value = newCities[i].ct_id;
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					}
				}else{
					if (i == -1) {
						oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
					} else {
						oCityList1.options[i] = new Option(newCities[i].text, newCities[i].ct_id, false, false);
					}
				}
			}
			if (ctr != '0') {
				document.form2.CityFrom2.style.display = 'inline';
				document.form2.RegionFrom2.style.display = 'none';
			} else {
				document.form2.CityFrom2.style.display = 'none';
				document.form2.RegionFrom2.style.display = 'none';
			}
		}
		var newCountries = newCTR[0].countries;
        var oRegList2 = document.forms['form2'].elements['CountryTo2'];
		var ctrNumb = newCountries.length;
		oRegList2.length = 0;
		for (i = -1; i < ctrNumb; i++){
			if (document.createElement){
				var newRegListOption = document.createElement("OPTION");
				if (i == -1) {
					newRegListOption.text = 'Выберите страну...';
					newRegListOption.value = '0';
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				} else {
					newRegListOption.text = newCountries[i].text;
					newRegListOption.value = newCountries[i].id;
					(oRegList2.options.add) ? oRegList2.options.add(newRegListOption) : oRegList2.add(newRegListOption, null);
				}
			}else{
				if (i == -1) {
					oRegList2.options[i] = new Option('Выберите страну...', '0', false, false);
				} else {
					oRegList2.options[i] = new Option(newCountries[i].text, newCountries[i].id, false, false);
				}
			}
		}
		for (i=0; i<oRegList2.length; i++) {
			if (oRegList2.options[i].value == document.form2.townsTo.value) oRegList2.options[i].selected = true;
		}
		if (oRegList2.value != '0') {
			getRT2();
		}
	}
}
// Заповняємо списки областей "Откуда" обраної країни з бази
function getRT2() {
	var ctr	 = document.form2.CountryTo2.value;
	var url = "script/getRegToList2.php?ctr=" + escape(ctr);
    //alert(document.form2.CityFrom2.value + ' - ' + document.form2.RegionFrom2.value + ' - ' + document.form2.CountryFrom2.value);
	if (ctr == '0') {
		document.form2.RegionTo2.style.display = 'none';
		document.form2.CityTo2.style.display = 'none';
	} else if (document.form2.CountryFrom2.value == '0') {
		document.form2.CountryTo2.options[0].selected = true;
		document.getElementById('error2').innerHTML = 'Выберите страну отправления!';
	} else if (document.form2.CountryFrom2.value != '0') {
		createRequest2();
		request2.open("GET", url, true);
		request2.onreadystatechange = updateRegListTo2;
		request2.send(null);
	}
	document.form2.date2.value = '';
}
function updateRegListTo2() {
	if (request2.readyState == 4) {
		var ctr	 = document.form2.CountryTo2.value;
		var newCTR = eval(request2.responseText);
		var newCities = newCTR[0].cities;
		var ctNumb = newCities.length;
	if (newCities.lenght != 0) {
		if (newCities[0].reg_id) {
			var oCityList1 = document.forms['form2'].elements['RegionTo2'];
			oCityList1.length = 0;
			for (i = -1; i < ctNumb; i++){
				if (document.createElement){
					var newCityListOption = document.createElement("OPTION");
					if (i == -1) {
						newCityListOption.text = 'Выберите область...';
						newCityListOption.value = '0';
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					} else {
						newCityListOption.text = newCities[i].text;
						newCityListOption.value = newCities[i].reg_id;
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					}
				}else{
					if (i == -1) {
						oCityList1.options[i] = new Option('Выберите область...', '0', false, false);
					} else {
						oCityList1.options[i] = new Option(newCities[i].text, newCities[i].reg_id, false, false);
					}
				}
			}
			if (ctr != '0') {
				document.form2.RegionTo2.style.display = 'inline';
				document.form2.CityTo2.style.display = 'none';
			} else {
				document.form2.RegionTo2.style.display = 'none';
				document.form2.CityTo2.style.display = 'none';
			}
		} else {
			var oCityList1 = document.forms['form2'].elements['CityTo2'];
			oCityList1.length = 0;
			for (i = -1; i < ctNumb; i++){
				if (document.createElement){
					var newCityListOption = document.createElement("OPTION");
					if (i == -1) {
						newCityListOption.text = 'Выберите город...';
						newCityListOption.value = '0';
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					} else {
						newCityListOption.text = newCities[i].text;
						newCityListOption.value = newCities[i].ct_id;
						(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
					}
				}else{
					if (i == -1) {
						oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
					} else {
						oCityList1.options[i] = new Option(newCities[i].text, newCities[i].ct_id, false, false);
					}
				}
			}
			if (ctr != '0') {
				document.form2.CityTo2.style.display = 'inline';
				document.form2.RegionTo2.style.display = 'none';
			} else {
				document.form2.CityTo2.style.display = 'none';
				document.form2.RegionTo2.style.display = 'none';
			}
		}
	}
	}
}
// Заповняємо списки міст "Откуда" обраної країни з бази
function getCF2() {
	var ctr = document.form2.CountryFrom2.value;
	var reg = document.form2.RegionFrom2.value;
	var url = "script/getCityFromList2.php?region=" + escape(reg) + "&ctr=" + escape(ctr);
	if (reg != '0') document.form2.CityFrom2.style.display = 'inline';
	else document.form2.CityFrom2.style.display = 'none';
    document.form2.date2.value = '';
	createRequest2();
	request2.open("GET", url, true);
	request2.onreadystatechange = updateCityListFrom2;
	request2.send(null);
}
function updateCityListFrom2() {
	if (request2.readyState == 4) {
		var newCities = eval(request2.responseText);
		var ctNumb = newCities.length;
		var oCityList1 = document.forms['form2'].elements['CityFrom2'];
		oCityList1.length = 0;
		for (i = -1; i < ctNumb; i++){
			if (document.createElement){
				var newCityListOption = document.createElement("OPTION");
				if (i == -1) {
					newCityListOption.text = 'Выберите город...';
					newCityListOption.value = '0';
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				} else {
					newCityListOption.text = newCities[i].text;
					newCityListOption.value = newCities[i].id;
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				}
			}else{
				if (i == -1) {
					oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
				} else {
					oCityList1.options[i] = new Option(newCities[i].text, newCities[i].id, false, false);
				}
			}
		}
	}
}
// Заповняємо списки міст "Откуда" обраної країни з бази
function getCT2() {
	var ctr = document.form2.CountryTo2.value;
	var reg = document.form2.RegionTo2.value;
	var url = "script/getCityToList2.php?region=" + escape(reg) + "&ctr=" + escape(ctr);
	if (reg != '0') document.form2.CityTo2.style.display = 'inline';
	else document.form2.CityTo2.style.display = 'none';
	createRequest2();
	request2.open("GET", url, true);
	request2.onreadystatechange = updateCityListTo2;
	request2.send(null);
}
function updateCityListTo2() {
	if (request2.readyState == 4) {
		var newCities = eval(request2.responseText);
		var ctNumb = newCities.length;
		var oCityList1 = document.forms['form2'].elements['CityTo2'];
		oCityList1.length = 0;
		for (i = -1; i < ctNumb; i++){
			if (document.createElement){
				var newCityListOption = document.createElement("OPTION");
				if (i == -1) {
					newCityListOption.text = 'Выберите город...';
					newCityListOption.value = '0';
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				} else {
					newCityListOption.text = newCities[i].text;
					newCityListOption.value = newCities[i].id;
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				}
			}else{
				if (i == -1) {
					oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
				} else {
					oCityList1.options[i] = new Option(newCities[i].text, newCities[i].id, false, false);
				}
			}
		}
	}
}
// Змінюємо дату доставки в залежності від тарифу (БЕЗ врахування вихідних і святкових днів)
function funcCtFrom2() {
	document.getElementById('error2').innerHTML = '';
    document.getElementById('from2').style.color = 'Black';
	var ctFrom 	= document.form2.CityFrom2.value;
	var ctTo   	= document.form2.CityTo2.value;
	var url		= "script/getCtFrom3Val.php?ctto=" + escape(ctTo) + "&ctfrom=" + escape(ctFrom) + "&typeD=sng";
	createRequest2();
	request2.open("GET", url, true);
	request2.onreadystatechange = updateCtFrom3Val2;
	request2.send(null);
}
function updateCtFrom3Val2() {
	if (request2.readyState == 4) {
		var data = eval(request2.responseText);
		var newDateTo	= parseInt(data[1]);
		var newDateFrom = parseInt(data[2]);
		var newDV		= parseInt(data[3]);
		var newVIP		= parseInt(data[4]);
		var hoursVIP	= document.form2.VIPh;
		var dFrom		= document.form2.dateFrom2;
		var dTo			= document.form2.dateTo2;
		dFrom.value = newDateFrom;
        dTo.value = newDateTo;
		dateTrans('date', newDateTo + newDateFrom);
		var oType = document.forms['form2'].elements['Type22'];
		oType.length = 0;
		oType.options[0] = new Option('Выберите тип доставки...', '0', false, false);
		oType.options[1] = new Option('Экспресс', '1', false, false);
        if (newDV != 0) {
        	oType.options[2] = new Option('До востребования', '2', false, false);
        	s = 3;
        } else s = 2;
        if (newVIP != 0) oType.options[s] = new Option('VIP', '3', false, false);
	}
}
// В залежності від обраного міста заповнюєм список типів доставки і міняєм дату доставки
function funcCtTo2() {
	var ctFrom 	= document.form2.CityFrom2.value;
	var ctTo   	= document.form2.CityTo2.value;
	var url		= "script/getCtTo4Val.php?ctto=" + escape(ctTo) + "&ctfrom=" + escape(ctFrom) + "&typeD=sng";
	document.getElementById('to2').style.color = 'Black';
	createRequest2();
	request2.open("GET", url, true);
	request2.onreadystatechange = updateCtTo4Val2;
	request2.send(null);
}
function updateCtTo4Val2() {
	if (request2.readyState == 4) {
		var data = eval(request2.responseText);
		var newDateTo	= parseInt(data[0].dateto);
		var newDateFrom = parseInt(data[0].datefrom);
		var newVIP		= parseInt(data[0].vip);
		var newDV		= parseInt(data[0].DV);
		var dFrom		= document.form2.dateFrom2;
		var dTo			= document.form2.dateTo2;
		dFrom.value = newDateFrom;
        dTo.value = newDateTo;
        dateTrans('date2', newDateTo + newDateFrom + 1);
        var oType = document.forms['form2'].elements['Type22'];
		oType.length = 0;
		oType.options[0] = new Option('Выберите тип доставки...', '0', false, false);
		oType.options[1] = new Option('Экспресс', '1', false, false);
        if (newDV != 0) {
        	oType.options[2] = new Option('До востребования', '2', false, false);
        	s = 3;
        } else s = 2;
        if (newVIP != 0) oType.options[s] = new Option('VIP', '3', false, false);
	}
}
// Управління помилками для 2ої закладки
function errorHandler2() {
	var fromP	= document.getElementById('from2').style;
	var toP		= document.getElementById('to2').style;
	var typeOP	= document.getElementById('typeO2').style;
	var typeDP	= document.getElementById('typeD2').style;
	var goP		= document.getElementById('go2').style;
	var voP		= document.getElementById('vo2').style;
	var error = '';
	var mark  = 0;
	var mark1 = 0;
	var mark2 = 0;
	if (document.form2.CityFrom2.value == '0') {
		mark = 1;
		fromP.color = 'red';
	}
	if (document.form2.CityTo2.value == '0') {
		mark = 1;
		toP.color = 'red';
	}
	if (document.form2.Type21.value == '0') {
		mark = 1;
		typeOP.color = 'red';
	}
	if (document.form2.Type22.value == '0') {
		mark = 1;
		typeDP.color = 'red';
    }
	if (document.form2.x2.value == '') mark1 = 1;
	if (document.form2.y2.value == '') mark1 = 1;
	if (document.form2.z2.value == '') mark1 = 1;
	if (document.form2.weight2.value == '') mark2 = 1;
	if ((mark1 == 1)&&(mark2 == 1)) {
		mark = 1;
		goP.color = 'red';
		voP.color = 'red';
	}
	if (mark == 1) {
		error = 'Заполнены не все поля!';
	}
	return error;
}
// Очистка формы 2
function clear2() {
	document.form2.CountryFrom2.value = "0";
	document.form2.RegionFrom2.style.display = "none";
	document.form2.CityFrom2.style.display = "none";
	document.form2.CountryTo2.value = "0";
	document.form2.RegionTo2.style.display = "none";
	document.form2.CityTo2.style.display = "none";
	document.form2.Type21.value = "0";
	document.form2.Type22.value = "0";
	document.form2.date2.value = "";
	document.form2.strah2.value = "";
	document.form2.x2.value = "";
	document.form2.y2.value = "";
	document.form2.z2.value = "";
	document.form2.weight2.value = "";
	document.form2.valUAH2.value = "";
	document.form2.valEUR2.value = "";
	document.getElementById("error2").innerHTML = "";
	document.getElementById("from2").style.color = "Black";
	document.getElementById("to2").style.color = "Black";
	document.getElementById("typeO2").style.color = "Black";
	document.getElementById("typeD2").style.color = "Black";
	document.getElementById("go2").style.color = "Black";
	document.getElementById("vo2").style.color = "Black";
}
// Калькуляція для 3ої закладки
function calculate2() {
	var er = document.getElementById("error2");
	if (errorHandler2() == '') {
		var nX		= parseInt(document.form2.x2.value);
		var nY		= parseInt(document.form2.y2.value);
		var nZ		= parseInt(document.form2.z2.value);
		var nWeight	= parseFloat(document.form2.weight2.value);
		var cD		= document.form4.cUSD.value*100;
		if (isNaN(nX)) nX = 0;
		if (isNaN(nY)) nY = 0;
		if (isNaN(nZ)) nZ = 0;
		if (isNaN(nWeight)) nWeight = 0;
		var tcFrom	= document.form2.CountryFrom2.value;
		var tFrom	= document.form2.CityFrom2.value;
		var tTo		= document.form2.CityTo2.value;
		var tType1	= document.form2.Type21.value;
		var tType2	= document.form2.Type22.value;
		var tStrah	= toHRN2(document.form2.strah2.value);
        var tWeight = weightPD(nWeight, nX, nY, nZ)*10;
        //alert(nX + ", " + nY + ", " + nZ + ", " + tFrom + ", " + tTo + ", " + tType1 + ", " + tType2 + ", " + vipH + ", " + tStrah + ", " + tWeight);
		var url = "script/calcForm2.php?ctrfrom=" + escape(tcFrom) + "&ctfrom=" + escape(tFrom) + "&ctto=" + escape(tTo) + "&type1=" + escape(tType1) + "&type2=" + escape(tType2) + "&strah=" + escape(tStrah) + "&weight=" + escape(tWeight) + "&cUSD=" + escape(cD);
		er.innerHTML = '<input type="button" value="Заказать доставку" onclick="onlineApp()">';
		createRequest2();
		request2.open("GET", url, true);
		request2.onreadystatechange = calcForm2;
		request2.send(null);
	} else {
		er.innerHTML = errorHandler();
	}
}
function calcForm2() {
	if (request2.readyState == 4) {
		var newResult	= eval(request2.responseText);
		var newValUAH2	= document.form2.valUAH2;
		var newValEUR2	= document.form2.valEUR2;
		var cD			= document.form4.cUSD.value;
		var resText		= document.getElementById("result");
		var text1		= '';
		var text2		= newResult[0].text;
        newResult = Math.round(newResult[0].res*100)/100;
		newValUAH2.value = newResult + ' грн.';
		newValEUR2.value = "(" + Math.round(parseFloat(newValUAH2.value)/cD*100)/100 + " $" + ")";
		if (resText) resText.innerHTML = text1 + text2;
	}
}
// TAB 2 END ==================================================================/
//----------------------------------------------------------------------------|
//																			  |
//----------------------------------------------------------------------------|
// TAB 3 START ================================================================\
// Create Request3
var request = null;
function createRequest() {
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (failed) {
				request = null;
			}
		}
	}
	if (request == null) alert("Error creating request object!");
}
// Заокруглення ваги (до цілого для України(сс=1); до дрібного для Міжнародної(сс=2))
function weightCC(weight, cc) {
	if (cc == 1) {
		weight = Math.ceil(weight);
	} else {
		cile = Math.floor(weight);
		drib = weight - cile;

		if (drib == 0) {
			weight = weight;
		} else if (drib <= 0.5) {
			weight = cile + 0.5;
		} else {
			weight = cile + 1;
		}
	}
	return weight;
}
// Fill the From/To Fields from DB
function getCountryListFrom() {
	createRequest();
	var url = "script/getCtrList.php";
	request.open("GET", url, true);
	request.onreadystatechange = updatePage;
	request.send(null);
}
function updatePage() {
	if (request.readyState == 4) {
		var newCountries = eval(request.responseText);
		var ctrNumb = newCountries.length;
		var oCtrList2 = document.forms['form3'].elements['CountryTo3'];
		oCtrList2.length = 0;
		for (i = -1; i < ctrNumb; i++){
			if (document.createElement){
				var newCtrListOption = document.createElement("OPTION");
				if (i == -1) {
					newCtrListOption.text = 'Выберите страну...';
					newCtrListOption.value = '0';
					(oCtrList2.options.add) ? oCtrList2.options.add(newCtrListOption) : oCtrList2.add(newCtrListOption, null);
				} else {
					newCtrListOption.text = newCountries[i].text;
					newCtrListOption.value = newCountries[i].id;
					(oCtrList2.options.add) ? oCtrList2.options.add(newCtrListOption) : oCtrList2.add(newCtrListOption, null);
				}
			}else{
				if (i == -1) {
					oCtrList2.options[i] = new Option('Выберите страну...', '0', false, false);
				} else {
					oCtrList2.options[i] = new Option(newCountries[i].text, newCountries[i].id, false, false);
				}
			}
		}
	}
}
// Заповняємо список міст "Откуда" в залежності від обраної області
function getCF3() {
	var reg		= document.form3.RegionFrom3.value;
	var CList	= document.form3.CityFrom3;
	var url 	= "script/getCityList3.php?region=" + escape(reg);
	if (reg != '0') {
		CList.style.display = 'inline';
	} else CList.style.display = 'none';
	createRequest();
	request.open("GET", url, true);
	request.onreadystatechange = updateCityListFrom3;
	request.send(null);
}
function updateCityListFrom3() {
	if (request.readyState == 4) {
		var newCities = eval(request.responseText);
		var ctNumb = newCities.length;
		var oCityList1 = document.forms['form3'].elements['CityFrom3'];
		oCityList1.length = 0;
		for (i = -1; i < ctNumb; i++){
			if (document.createElement){
				var newCityListOption = document.createElement("OPTION");
				if (i == -1) {
					newCityListOption.text = 'Выберите город...';
					newCityListOption.value = '0';
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				} else {
					newCityListOption.text = newCities[i].text;
					newCityListOption.value = newCities[i].id;
					(oCityList1.options.add) ? oCityList1.options.add(newCityListOption) : oCityList1.add(newCityListOption, null);
				}
			}else{
				if (i == -1) {
					oCityList1.options[i] = new Option('Выберите город...', '0', false, false);
				} else {
					oCityList1.options[i] = new Option(newCities[i].text, newCities[i].id, false, false);
				}
			}
		}
	}
}
// Weight not more than 5 kg
function weightChange() {
	verifyFloat('weight3');
	var wVal = document.form3.weight3.value;
	var weigthP	= document.getElementById('vaga3');
	if (wVal > 5) document.form3.weight3.value = 5;
	weigthP.style.color = 'black';
}
function selCityFrom3() {
	var fromP = document.getElementById('from');
	fromP.style.color = 'black';
}
function selCtrTo3() {
	var toP = document.getElementById('to');
	toP.style.color = 'black';
}
// Form 3 error handler
function errorHandler3() {
	var error = '';
	var mark  = 0;
	var nn = 0;
	var fromP	= document.getElementById('from');
	var toP		= document.getElementById('to');
	var weigthP	= document.getElementById('vaga3');
	if ((document.form3.CityFrom3.value == '0')||(document.form3.RegionFrom3.value == '0')) {
		mark = 1;
		fromP.style.color = 'red';
	} else fromP.style.color = 'black';
	if (document.form3.CountryTo3.value == '0') {
		mark = 1;
		toP.style.color = 'red';
	} else toP.style.color = 'black';
	if ((document.form3.weight3.value == '')|| (document.form3.weight3.value == '0')) {
		mark = 1;
		nn = 1;
		weigthP.style.color = 'red';
	} else {
		nn = 0;
		weigthP.style.color = 'black';
	}
	if (mark == 1) {
		error = 'Заполнены не все поля!';
	}
	if (mark == 2) {
		error = 'Неверный формат данных!';
	}
	return error;
}
// Очистка формы 3
function clear3() {
	document.form3.RegionFrom3.value = "0";
	document.form3.CityFrom3.style.display = "none";
	document.form3.CountryTo3.value = "0";
	document.form3.weight3.value = "";
	document.form3.valUAH3.value = "";
	document.form3.valEUR3.value = "";
	document.getElementById("error3").innerHTML = "";
	document.getElementById("from").style.color = "Black";
	document.getElementById("to").style.color = "Black";
	document.getElementById("vaga3").style.color = "Black";
}
// Калькуляція для 3ої закладки
function calculate3() {
	var ctrFrom	= document.form3.CityFrom3.value;
	var ctrTo	= document.form3.CountryTo3.value;
	var weight	= document.form3.weight3.value;
	var er 		= document.getElementById("error3");
    var cD		= document.form4.cUSD.value;
	var error = errorHandler3();
	var cile = Math.floor(weight);
	var drib = weight - cile;
	if (drib == 0) weight = weight;
	else if (drib <= 0.5) {
		if (drib <= 0.25) weight = cile + 0.25;
		else weight = cile + 0.5;
	} else {
		weight = cile + 1;
	}
	weight = (Math.round(weight*100)/100);
	if (error == '') {
		var url = "script/calcForm3.php?ctrf=" + escape(ctrFrom) + "&ctrt=" + escape(ctrTo) + "&weight=" + escape(weight) + "&cUSD=" + escape(cD);
		createRequest();
		request.open("GET", url, true);
		request.onreadystatechange = calcForm3;
		request.send(null);
		er.innerHTML = '<input type="button" value="Заказать доставку" onclick="onlineApp()">';
	} else {
		er.innerHTML = error;
	}
}
function calcForm3() {
	if (request.readyState == 4) {
		var newResult	= eval(request.responseText);
		var newValUAH3	= document.form3.valUAH3;
		var newValEUR3	= document.form3.valEUR3;
		var cD			= document.form4.cUSD.value;
        newResult = Math.round(newResult[0].res*100)/100;
		newValUAH3.value = newResult + ' грн.';
		newValEUR3.value = "(" + Math.round(parseFloat(newValUAH3.value)/cD) + " $" + ")";
	}
}
// TAB 3 END ==================================================================/
//----------------------------------------------------------------------------|
function onlineApp() {
	window.location = "http://www.vippost.com.ua/content/main/indent/on-lineCalling.php";
}




$(document).ready(function() {
	$('#stausfrm').ajaxForm({success:successForm, dataType : 'json', type:'post', url:'/content/get-status.php?ts=' + ( new Date() ).getMilliseconds()});
	$('#searchbtn').click(function(){
		$.mask();
		$('#stausfrm').submit();
		return false;
    });
});

function successForm(data, status){
	$.unmask();
	if(data && data.error) {
		var err = data.error;
		$.msgbox(err, {type: "error"}, function(){
			$('#stausfrm').resetForm();
			$('#statuscontainer').html('');
		});
	}else{
		$('#statuscontainer').html(data.html);
	}
}

