var id;
var NewWin;
//---------------------------------------------------------------------
function load_img(id, h, w)
{
	var l = (screen.width  - w)/2;
 	var t = (screen.height - h)/2;
	window.open('/img.php?img='+id, '', 'resizable=yes,scrollbars=yes,height='+h+',width='+w+',top='+t+',left='+l);
}
//--------------------------------------------------------
function doLoad(url)
{
  document.body.style.cursor = 'wait';
  var req = new JsHttpRequest();
  req.caching = false;
  req.open(null, url, true);
  req.send(  );
}
//--------------------------------------------------------
function doo(txt)
{
	if (id == 'secure')
	{
		if (txt == 'true')
		{
			document.getElementById(id).style.color='#000000';
			document.getElementById('secure_key').value='1';
		}
		else
		{
			document.getElementById(id).style.color='#FF3300';
			document.getElementById('secure_key').value='0';
		}
		enable_button();
	}
	document.body.style.cursor = 'default';
}
//--------------------------------------------------------
function check_count (value)
{
	new_val = parseInt(value);
	if (new_val != value)
		return false;
	return true;
}
//--------------------------------------------------------
function add_goods(_id_)
{
	var id;
	id = document.forms[_id_].id.value;
	count = document.forms[_id_].count.value;
	goods_type = 'number';
	if (_id_.indexOf('tarif') == 0)
	{
		if (document.forms[_id_].type[1])
		{
			if (document.forms[_id_].type[1].checked)
				type = document.forms[_id_].type[1].value;
			else if (document.forms[_id_].type[0].checked)
				type = document.forms[_id_].type[0].value;
		}
		else if (document.forms[_id_].type)
			type = document.forms[_id_].type.value;
		else
			type = 0;

		goods_type = 'tarif';
	}
	var bool = true;
	if (isNaN(count) || count == '' || count < 1) bool = false;
	if (!bool)
	{
		document.forms[_id_].count.focus();
		delcookie_basket(id, goods_type, false);
		calc_basket();
		return true;
	}
	else if (bool && goods_type == 'tarif')
	{
		var old_cn = getCookie('basket['+goods_type+']['+id+'][count]');
		if (old_cn)
			if (!isNaN(old_cn))
			count = parseInt(count) + parseInt(old_cn);
		count = count + '';
		document.cookie='basket['+goods_type+']['+id+'][count]='+count+'; path=/';
		document.cookie='basket['+goods_type+']['+id+'][type]='+type+'; path=/';
	}
	else
		document.cookie='basket['+goods_type+']['+id+']='+id+'; path=/';
	calc_basket();
	document.location.href="/orders.php";
}
//--------------------------------------------------------
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
			return(setStr);
		}
	}
	return(false);
}
//--------------------------------------------------------
function calc_basket()
{
	var src = document.cookie;
	var src = src.match(/basket\[tarif\]\[[^\]]*?\]\[count\]=\d+/ig);
	var res;
	var cn = 0;
	if (src)
	for (i=0; i<src.length; i++)
	{
		res = src[i].match(/=(\d+)/i);
		if (res[1])
			if(parseInt(res[1]) > 0)
				cn++;
	}
	src = document.cookie.match(/basket\[number\]\[[^\]]*?\]=\d+/ig);
	if (src)
	for (i=0; i<src.length; i++)
	{
		res = src[i].match(/=(\d+)/i);
		if (res[1])
			if(parseInt(res[1]) > 0)
				cn++;
	}
	document.getElementById('basket').innerHTML = cn;
	return cn;
}
//--------------------------------------------------------
function delcookie_basket(_id_, goods_type, bool)
{
	if (goods_type == 'tarif')
	{
		document.cookie="basket["+goods_type+"]["+_id_+"][count]=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
		document.cookie="basket["+goods_type+"]["+_id_+"][type]=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
		//document.cookie="basket["+goods_type+"]["+_id_+"]=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
		//document.cookie="basket["+goods_type+"]=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
	else if (goods_type == 'number')
	{
		document.cookie='basket['+goods_type+']['+_id_+']=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
	else return false;
	calc_basket();
	if (bool)
		document.getElementById(goods_type+'['+_id_+']').innerHTML = '';
	return true;
}
//--------------------------------------------------------
function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
 
function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}

