var IE_DETECTED = '';
var is_pop_moved = new Array();
var browser = navigator.appName;
var is_tree_template = false;
if (browser == "Microsoft Internet Explorer"){
	var b_version = navigator.appVersion;
	var re = /\MSIE\s+(\d\.\d\b)/;
	var res = b_version.match(re);
	if (res[1] <= 6){
	  IE_DETECTED = true;
	} else IE_DETECTED = false;
} else IE_DETECTED = false;
  
function QSTestKey(evt){
	a = (evt.which) ? evt.which : evt.keyCode;
	if (a==27){
		pop('close');
		return false;
	}
	return true;
}
  
function detectie6(){
	return IE_DETECTED;
}
// выстота и ширина браузера
function getClientHeight()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight;
}
function getClientWidth()
{
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

// Подсказка в форме (для ие)
function ie_help(id) {
	if (detectie6()) {
		if (document.getElementById(id).style.display == "block") {
			document.getElementById(id).style.display = "none";	
		} else {
			document.getElementById(id).style.display = "block";	
		}
	}
}
function redraw(){
var n = document.createTextNode(' ');
document.body.appendChild(n);
document.body.removeChild(n);
}
// Попы поиска и выбора страны и вобще поп с тенюшкой
var last_pop = '';
var id = '';
var active_body = 0;
var non_pop = true;
var ua = navigator.userAgent.toLowerCase();
function pop(id,active) {
	//alert(2);
	if (id == 'close' && active_body == 1) {non_pop = true;}
	if (active == 'mover' && non_pop == false) {
		return;
	}
	if (active=="disable") {
		active_body = 0;
	} else {
		if (id == 'force_close' && last_pop != '') {
			document.getElementById(last_pop).style.display = 'none';
			non_pop = true;
		} else {
			if (id != 'close') {
				if (document.getElementById(id).style.display == 'block') {
					document.getElementById(id).style.display = 'none';
					if (id == 'rst_cmp_search_pop') {
						inactive_search();
					}
					non_pop = true;
				}
				else {
					setTimeout("document.getElementById('"+id+"').style.display = 'block'",10)
					active_body = 0;
					if (last_pop!=id && last_pop != '' && last_pop != 'close') {
						document.getElementById(last_pop).style.display = 'none';
						if (last_pop == 'rst_cmp_search_pop') {
							inactive_search();
						}
					}
					if (id == 'rst_cmp_search_pop') {
						active_search();
					}
					non_pop = false;
				}
				last_pop = id;
			} else {
				if (active_body == '1') {
					if (last_pop != '' && last_pop != 'close') {
						document.getElementById(last_pop).style.display = 'none';
						document.body.oncontextmenu= function () {
							if (active_body == 0) {
							document.getElementById(last_pop).style.display = 'block';
							 active_body = 1;
							}
						}
						var tmp = document.documentElement.scrollTop;
						if (ua.indexOf("opera") != -1) { // трясем экран оперы xD (for fun);
							document.documentElement.scrollTop = (tmp + 1);
							document.documentElement.scrollTop = (tmp - 1);
							document.documentElement.scrollTop = (tmp);
						}
					}
					active_body = 0;
					inactive_search();
				} else {
					active_body = 1;
				}
			}
		}
	}
	if (is_tree_template == true && !is_pop_moved[id]) {
	var obj = document.getElementById(id);
	//alert(obj.left.strlen());
	//alert (obj.left.replace('px',''));
	if (obj) {
		is_pop_moved[id] = true;
		obj.style.left = (new Number(obj.style.left.replace('px','')) + 60)+'px';
	}
	}
}
// Ховер поиска
function active_search() {
	document.getElementById('rst_cmp_search_button').className = 'rst_cmp_search_button_hover';
}
function inactive_search() {
	if (document.getElementById('rst_cmp_search_pop').style.display == 'none' || document.getElementById('rst_cmp_search_pop').style.display == '') {
		document.getElementById('rst_cmp_search_button').className = 'rst_cmp_search_button';
	}
}
// антиробот для емыла
function create_email(mail,domain,region,id) {
	document.getElementById(id).innerHTML = '<a href="mailto:'+mail+'@'+domain+'.'+region+'">напишите нам</a>';
}
function clear_input (id,value) {
	if (document.getElementById(id).value == value) {
		document.getElementById(id).value = '';
	}
}
function rst_shop_height () {
	if (IE_DETECTED) {
		document.getElementById('wrap').style.height = 'auto'
		document.getElementById('wrap').style.height = (getClientHeight() - 40 - 142 - 55)+'px';
	} else {
		document.getElementById('wrap').style.height = 'auto'
		document.getElementById('wrap').style.minHeight = (getClientHeight() - 40 - 142 - 55)+'px';
	}
}