// JavaScript Document

	function open_window(link,w,h) //opens new window
	{
		var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
		if (arguments.length>=4) {
			if (arguments[3] instanceof Array) {
				for (var n=0; n<arguments[3].length; ++n) {
					if (arguments[3][n]=='centred') {
						var left = Math.ceil((screen.width - w) / 2);
						var top  = Math.ceil((screen.height - h) / 2);
						win+= ',left='+left+',top='+top;
					}
				}
			} else if (arguments[3] instanceof Object) {
				for (var n in arguments[3]) {
					win+= ','+n+'='+arguments[3][n];
				}
			}
		}
		newWin = window.open(link,'newWin',win);
		newWin.focus();
		return false;
	}

	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('Вы уверены, что хотите отменить регистрацию в магазине?');
		if (temp) //delete
		{
			window.location="index.php?killuser=yes";
		}
	}

	function validate() // newsletter subscription form validation
	{
		if (document.subscription_form.email.value.length<1)
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		if (document.subscription_form.email.value == 'Email')
		{
			alert("Пожалуйста, вводите email правильно");
			return false;
		}
		return true;
	}
	function validate_disc() // review form verification
	{
		if (document.formD.nick.value.length<1)
		{
			alert("Пожалуйста, введите Ваш псевдоним");
			return false;
		}

		if (document.formD.topic.value.length<1)
		{
			alert("Пожалуйста, введите тему сообщения");
			return false;
		}

		return true;
	}
	function validate_search()
	{

		if (document.Sform.price1.value!="" && ((document.Sform.price1.value < 0) || isNaN(document.Sform.price1.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}
		if (document.Sform.price2.value!="" && ((document.Sform.price2.value < 0) || isNaN(document.Sform.price2.value)))
		{
			alert("Цена должна быть положительным числом");
			return false;
		}

		return true;
	}


function shipping_amount_request(shipping_type, zone_id, shServiceID){
	var req = new JsHttpRequest();
	req.onreadystatechange = function(){
	if (req.readyState == 4)
		{
		document.getElementById('shipping_amount').innerHTML = req.responseJS.shipping_amount;
		document.getElementById('total_amount').innerHTML = req.responseJS.total_amount;
	  }
	}
	req.caching = false;
	req.open("POST", "ajax.php", true);
	req.send({type:"getShippingAmount", shipping_type:shipping_type, zone_id:zone_id, shServiceID:shServiceID});
	}

function devices_request(deviceCatID, deviceID, offsetID){
	var req = new JsHttpRequest();
	req.onreadystatechange = function(){
	if (req.readyState == 4)
		{
		document.getElementById('devices_html').innerHTML = req.responseJS.devices_html;
		document.getElementById('devices_select').innerHTML = req.responseJS.devices_select;
		document.getElementById('right').innerHTML = req.responseJS.result;
		dd.elements.diz.del();
		ADD_DHTML("diz"+CURSOR_MOVE+MAXOFFLEFT+20+MAXOFFRIGHT+20+MAXOFFTOP+20+MAXOFFBOTTOM+20);
		alert("4");
	  }
	
	}
	req.caching = false;
	req.open("POST", "ajax.php", true);
	var designID = document.getElementById('designID').value;
	req.send({type:"getDevices", deviceCatID:deviceCatID, deviceID:deviceID, designID:designID, offsetID:offsetID});
	
	}

function designs_request(designCatID, designID, offsetID){
	RemoveTT();
	var req = new JsHttpRequest();
	req.onreadystatechange = function(){
	if (req.readyState == 4)
		{
		document.getElementById('designs_html').innerHTML = req.responseJS.designs_html;
		document.getElementById('designs_select').innerHTML = req.responseJS.designs_select;
		document.getElementById('right').innerHTML = req.responseJS.result;
		dd.elements.diz.del();
		ADD_DHTML("diz"+CURSOR_MOVE+MAXOFFLEFT+20+MAXOFFRIGHT+20+MAXOFFTOP+20+MAXOFFBOTTOM+20);
		RemoveTT();
	  }
	}
	req.caching = false;
	req.open("POST", "ajax.php", true);
	var deviceID = document.getElementById('deviceID').value;
	req.send({type:"getDesigns", designCatID:designCatID, designID:designID, deviceID:deviceID, offsetID:offsetID});
	}


