try{document.execCommand("BackgroundImageCache", false, true);} catch(err){};

function sethp(f)
{
	if (document.all) {
		f.style.behavior='url(#default#homepage)';
		f.setHomePage('http://www.date.bs');
		return true;
	}
	return false;
}

function ch_icon_on (id,sourse)
{
	if (img_tag = document.getElementById(id)) {
		img_tag = document.getElementById(id);
		img_tag.style.backgroundImage = 'url('+sourse+')';
	}
}

function ch_icon (id,sourse)
{
	if (img_tag = document.getElementById(id))
	{
		img_tag = document.getElementById(id);
		img_tag.style.backgroundImage = 'url('+sourse+')';
	}
}

function check_email(email)
{
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (! filter.test(email)) return false;
	return true;
}

function trim(str)
{
	str = new String(str);
	return str.replace(/(^\s+)|\s+$/g, "");
}

function $(el)
{
	return document.getElementById(el);
}

function thumbnails(id, init_array)
{
	this.id = id;
	this.thumbnails = init_array;
	this.thumbnail_pos = 0;
	this.thumbnail_length = 0;
	this.thumbnail_w = 550;
	this.thumbnail_h = 400;

	this.tn_set_full_size = function(w, h)
	{
		this.thumbnail_w = w;
		this.thumbnail_h = h;
	}

	this.tn_init = function()
	{
		if (typeof(this.thumbnails) != 'undefined') this.thumbnail_length = this.thumbnails.length;
		this.tn_disable_btn('right', true);
		this.tn_disable_btn('left', true);

		if (this.thumbnail_length == 0)
		{
			$(this.id + "tn_img1").innerHTML = "Изображения модели отсутствуют";
			return;
		}

		for (var i = 0; i < 3; i++)
		{
			if (typeof(this.thumbnails[i]) != 'undefined')
			{
				$(this.id + "tn_img" + i).innerHTML = '<div class="img-shadow"><img src="' + this.thumbnails[i][0] + '" width="' + this.thumbnails[i][1] + '" height="' + this.thumbnails[i][2] + '"></div>';// + i;
				$(this.id + "tn_img" + i).onclick = new Function("tn_show_image('" + this.thumbnails[i][0] + "'," + this.thumbnail_w + "," + this.thumbnail_h + ");");
			}
		}
		if (this.thumbnail_length > 3) this.tn_disable_btn('right', false);
	}

	this.tn_disable_btn = function(direction, flag)
	{
		$(this.id + "tn_" + direction + "_btn").disabled = flag;
		$(this.id + "tn_" + direction + "_img").src = "/img/i/" + direction + "arrow" + (flag ? "_dis" : "") + ".jpg";
	}

	this.tn_rotate = function(pos)
	{
		if (this.thumbnail_length == 0) return;

		this.thumbnail_pos = this.thumbnail_pos + pos;

		for (var i = 0; i < 3; i++)
		{
			var current = this.thumbnails[i + this.thumbnail_pos];
			if (typeof(current) != 'undefined')
			{
				$(this.id + "tn_img" + i).innerHTML = '<div class="img-shadow"><img src="' + current[0] + '" width="' + current[1] + '" height="' + current[2] + '"></div>';// + (i+this.thumbnail_pos);
				$(this.id + "tn_img" + i).onclick = new Function("tn_show_image('" + current[0] + "'," + this.thumbnail_w + "," + this.thumbnail_h + ");");
			}
		}

		if (this.thumbnail_pos + 3 == this.thumbnail_length) this.tn_disable_btn('right', true);
		else this.tn_disable_btn('right', false);

		if (this.thumbnail_pos == 0) this.tn_disable_btn('left', true);
		if (this.thumbnail_pos > 0) this.tn_disable_btn('left', false);
	}
}

function tn_show_image(img_src, w, h)
{
	var width = 550;
	var height = 400;
	if (typeof(w) != 'undefined') width = w;
	if (typeof(h) != 'undefined') height = h;
	$('tn_big_image').innerHTML = '<img align="absmiddle" title="Закрыть" onclick="hm(\'big_image_div\');return false;" src="' + String(img_src).replace("_tn", "") + '">';
	sm('big_image_div', width, height);
	return false;
}

function fire_element_event(el, evnt_name)
{
	if (typeof(el) != 'undefined')
	{
	    if (typeof(el.fireEvent) != 'undefined')
		{
			el.fireEvent("on" + evnt_name);
		}
		else
		{
			var evt = document.createEvent("HTMLEvents");
			evt.initEvent(evnt_name, true, true);
			el.dispatchEvent(evt);
		}
	}
}

function select_option(sel, val)
{
	for (var j = 0; j < sel.options.length; j++)
	{
		var val2 = sel.options[j].innerHTML;
		if (String(val).toLowerCase() == String(val2).toLowerCase())
		{
			sel.selectedIndex = j;
			fire_element_event(sel, "change");
			break;
		}
	}
}

function sleep(m)
{
	var then = new Date(new Date().getTime() + m);
	while (new Date() < then) {}
}

function $(id) { return document.getElementById(id) || null; }

var jsCookie =
{
	get_cookie : function (name, def)
	{
	    var arc = document.cookie.split(";");

	    for (var i = 0; i < arc.length; i++) {
	        ar = arc[i].split("=");

	        if (trim(ar[0]) == name) return unescape(trim(ar[1]));
	    }

	    return (def ? def : false);
	},

	set_cookie : function (name, value, expires, path, domain, secure)
	{
	    document.cookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires : "")
	                          + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "")
	                          + ((secure) ? "; secure" : "");
	},

	delete_cookie: function(name, path, domain)
	{
	    var exp = new Date();
	    exp.setTime(exp.getTime() - 1000);
	    this.set_cookie(name, '', exp.toGMTString(), path, domain);
	}
}

Array.prototype.in_array = function(search_term)
{
	var i = this.length;
	if (i > 0) {
		do {
			if (this[i] === search_term) return true;
		} while (i--);
	}
	return false;
}

function add_notepad_cookie(n, cookie_name)
{
	var cookies = [];
	var strCookies = jsCookie.get_cookie(cookie_name);
	if (strCookies) cookies = strCookies.split(',');

	for (var i = 0; i < cookies.length; i++) {
		if (cookies[i] == n) {
			alert("Вы уже добавили это объявление в свой блокнот!");
			return;
		}
	}

	cookies.push(n);
	set_notepad_cookie(cookie_name, cookies.join(','), cookies.length);
	alert("Объявление добавлено в Ваш блокнот");
}

function check_all_notepad(name)
{
	var els = document.getElementsByName(name);
	for (var i = 0; i < els.length; i++)
	{
		els[i].checked = true;
	}
}

function delete_notepad(name, cookie_name)
{
	var dels = new Array();
	var els = document.getElementsByName(name);
	for (var i = 0; i < els.length; i++)
	{
		if (els[i].checked) dels.push(els[i].value);
	}
	if (dels.length > 0)
	{
		if (!confirm("Вы уверены, что хотите удалить все выбранные объявления?")) return;
	}
	else
	{
		alert("Не выбраны элементы для удаления");
	}
	for (var i = 0; i < dels.length; i++)
	{
		var t = $('offer_table_' + dels[i]);
		t.parentNode.removeChild(t);
	}

	var ncookie = [];
	var cookie = [];
	var strCookie = jsCookie.get_cookie(cookie_name);
	if (strCookie) cookie = strCookie.split(',');

	for (var i = 0; i < cookie.length; i++)
	{
		if (!dels.in_array(cookie[i])) ncookie.push(cookie[i]);
	}

	set_notepad_cookie(cookie_name, ncookie.join(','), ncookie.length);
}

function set_notepad_cookie(cookie_name, cookie_val, cookie_len)
{
	if (cookie_len > 0)
	{
  		var exp = new Date();
		exp.setTime(exp.getTime() + 14*24*60*60*1000); //two weeks
		jsCookie.set_cookie(cookie_name, cookie_val, exp.toGMTString(), '/');
	}
	else
	{
		jsCookie.delete_cookie(cookie_name, '/', '');
	}
	if ($(cookie_name + "count")) $(cookie_name + "count").innerHTML = cookie_len;
	if ($(cookie_name + "count2")) $(cookie_name + "count2").innerHTML = cookie_len;
}
