	function open_window(link,w,h) //opens new window
	{
		var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'newWin',win);
		newWin.focus();
	}

	function open_printable_version(link) //opens new window
	{
		var win = "menubar=no,location=no,resizable=yes,scrollbars=yes";
		newWin = window.open(link,'perintableWin',win);
		newWin.focus();
	}

	function confirmDelete(id, ask, url) //confirm order delete
	{
		temp = window.confirm(ask);
		if (temp) //delete
		{
			window.location=url+id;
		}
	}



	function confirmUnsubscribe() //unsubscription confirmation
	{
		temp = window.confirm('{/literal}{$smarty.const.QUESTION_UNSUBSCRIBE}{literal}');
		if (temp) //delete
		{
			window.location="index.php?killuser=yes";
		}
	}

	function validate() // newsletter subscription form validation
	{
		if (document.subscription_form.email.value.length<1)
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_EMAIL}{literal}");
			return false;
		}
		if (document.subscription_form.email.value == 'Email')
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_EMAIL}{literal}");
			return false;
		}
		return true;
	}
	function validate_disc() // review form verification
	{
		if (document.formD.nick.value.length<1)
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_NICKNAME}{literal}");
			return false;
		}

		if (document.formD.topic.value.length<1)
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_MESSAGE_SUBJECT}{literal}");
			return false;
		}

		return true;
	}
	function validate_search()
	{

		if (document.Sform.price1.value!="" && ((document.Sform.price1.value < 0) || isNaN(document.Sform.price1.value)))
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_PRICE}{literal}");
			return false;
		}
		if (document.Sform.price2.value!="" && ((document.Sform.price2.value < 0) || isNaN(document.Sform.price2.value)))
		{
			alert("{/literal}{$smarty.const.ERROR_INPUT_PRICE}{literal}");
			return false;
		}

		return true;
	}


	function makeRequest(url, action)
	{
		var http_request = false;
		if (window.XMLHttpRequest)
		{ // Mozilla, Safari, ...
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType)
			{
				http_request.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject)
		{ // IE
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e)
				{}
			}
		}
		if (!http_request)
		{
			alert('Не вышло  Невозможно создать экземпляр класса XMLHTTP ');
			return false;
		}
		http_request.onreadystatechange = function() { alertContents(http_request, action); };
		http_request.open('GET', url, true);
		http_request.send(null);
	}

	function alertContents(http_request, action)
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				//alert(http_request.responseText);
				switch (action)
				{
				case "vendor":
					var text = http_request.responseText;
					var years = text.split('|');

					var year = document.getElementById('year');
					year.options.length = 0;
					year.options[0] = new Option('Год выпуска', -1);

					var model = document.getElementById('model');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in years)
					{
						year.options[year.options.length] = new Option(years[i], years[i]);
					}

    				break;

				case "year":
					var text = http_request.responseText;
					var models = text.split('|');

					var model = document.getElementById('model');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in models)
					{
						model.options[model.options.length] = new Option(models[i], models[i]);
					}
					break;

				case "model":
					var text = http_request.responseText;
					var modifs = text.split('|');

					var modif = document.getElementById('modification');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);
					for(var i in modifs)
					{
						modif.options[modif.options.length] = new Option(modifs[i], modifs[i]);
					}
					break;


				case "vendor_main":
					var text = http_request.responseText;
					var years = text.split('|');

					var year = document.getElementById('year_main');
					year.options.length = 0;
					year.options[0] = new Option('Год выпуска', -1);

					var model = document.getElementById('model_main');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification_main');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in years)
					{
						year.options[year.options.length] = new Option(years[i], years[i]);
					}
					$("#year_main").removeAttr("disabled");
					break;

				case "year_main":
					var text = http_request.responseText;
					var models = text.split('|');

					var model = document.getElementById('model_main');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification_main');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in models)
					{
						model.options[model.options.length] = new Option(models[i], models[i]);
					}
					$("#model_main").removeAttr("disabled");
					break;

				case "model_main":
					var text = http_request.responseText;
					var modifs = text.split('|');

					var modif = document.getElementById('modification_main');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);
					for(var i in modifs)
					{
						modif.options[modif.options.length] = new Option(modifs[i], modifs[i]);
					}
					$("#modification_main").removeAttr("disabled");
					break;

				case "vendor_disk":
					var text = http_request.responseText;
					var years = text.split('|');

					var year = document.getElementById('year_disk');
					year.options.length = 0;
					year.options[0] = new Option('Год выпуска', -1);

					var model = document.getElementById('model_disk');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification_disk');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in years)
					{
						year.options[year.options.length] = new Option(years[i], years[i]);
					}
					$("#year_disk").removeAttr("disabled");
					break;

				case "year_disk":
					var text = http_request.responseText;
					var models = text.split('|');

					var model = document.getElementById('model_disk');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);

					var modif = document.getElementById('modification_disk');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);

					for(var i in models)
					{
						model.options[model.options.length] = new Option(models[i], models[i]);
					}
					$("#model_disk").removeAttr("disabled");
					break;

				case "model_disk":
					var text = http_request.responseText;
					var modifs = text.split('|');

					var modif = document.getElementById('modification_disk');
					modif.options.length = 0;
					modif.options[0] = new Option('Модификация', -1);
					for(var i in modifs)
					{
						modif.options[modif.options.length] = new Option(modifs[i], modifs[i]);
					}
					$("#modification_disk").removeAttr("disabled");
					break;

				case "vendor_xenon":
					var text = http_request.responseText;
					var models = text.split('|');

					var model = document.getElementById('xen_model');
					model.options.length = 0;
					model.options[0] = new Option('Модель', -1);
					for(var i in models)
					{
						var curModel = models[i].split('~');
						model.options[model.options.length] = new Option(curModel[1], curModel[0]);
					}
					break;

			    case "diskSearch":
					var text = http_request.responseText;
					var disks = text.split('~');
					if (text != '0') {
					   wrap_disk_search( disks );
					} else {
					   wrap_disk_search();
					}
                    break;

                case "tyreSearch":
					var text = http_request.responseText;
					var tyres = text.split('~');
					if (text != '0') {
					   wrap_tyre_search( tyres );
					} else {
					   wrap_tyre_search();
					}
                    break;
				}
			}
			else
			{
				alert('С запросом возникла проблема.');
			}
		}
	}
	function OnVendorSelected()
	{
		var vendor = document.getElementById('vendor');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		if (vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID, "vendor");
		}
	}

	function OnYearSelected()
	{
		var vendor = document.getElementById('vendor');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year');
		var yearID = year.options[year.selectedIndex].value;

		if (yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID, "year");
		}
	}

	function OnModelSelected()
	{
		var vendor = document.getElementById('vendor');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year');
		var yearID = year.options[year.selectedIndex].value;

		var model = document.getElementById('model');
		var modelID = model.options[model.selectedIndex].value;

		if (modelID != -1  &&  yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID + '&model=' + modelID, "model");
		}
	}

	function OnMainVendorSelected()
	{
		var vendor = document.getElementById('vendor_main');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		if (vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID, "vendor_main");
		}
	}

	function OnMainYearSelected()
	{
		var vendor = document.getElementById('vendor_main');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year_main');
		var yearID = year.options[year.selectedIndex].value;

		if (yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID, "year_main");
		}
	}

	function OnMainModelSelected()
	{
		var vendor = document.getElementById('vendor_main');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year_main');
		var yearID = year.options[year.selectedIndex].value;

		var model = document.getElementById('model_main');
		var modelID = model.options[model.selectedIndex].value;

		if (modelID != -1  &&  yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID + '&model=' + modelID, "model_main");
		}
	}

	function OnDiskVendorSelected()
	{
		var vendor = document.getElementById('vendor_disk');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		if (vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID, "vendor_disk");
		}
	}

	function OnDiskYearSelected()
	{
		var vendor = document.getElementById('vendor_disk');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year_disk');
		var yearID = year.options[year.selectedIndex].value;

		if (yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID, "year_disk");
		}
	}

	function OnDiskModelSelected()
	{
		var vendor = document.getElementById('vendor_disk');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		var year = document.getElementById('year_disk');
		var yearID = year.options[year.selectedIndex].value;

		var model = document.getElementById('model_disk');
		var modelID = model.options[model.selectedIndex].value;

		if (modelID != -1  &&  yearID != -1  &&  vendorID != -1)
		{
			makeRequest('express.php?vendor=' + vendorID +'&year=' + yearID + '&model=' + modelID, "model_disk");
		}
	}

	function OnXenonVendorSelected()
	{
		var vendor = document.getElementById('xen_vendor');
		var vendorID = vendor.options[vendor.selectedIndex].value;

		if (vendorID != -1)
		{
			makeRequest('express.php?xen_vendor=' + vendorID, "vendor_xenon");
		}
	}

	function SearchDiskBySize(size, radius, et, pcd){
	    slide( 'variants' );
	    setTimer();
        makeRequest('express.php?size='+size+'&radius='+radius+'&et='+et+'&pcd='+pcd, 'diskSearch');
	}
	function SearchTyreBySize(vendor_id, width, height, radius, season){
	    slide( 'variants' );
	    setTimer();
        makeRequest('express.php?vendor_id='+vendor_id+'&width='+width+'&height='+height+'&radius='+radius+'&season'+season, 'tyreSearch');
	}
 
