function window_open(url, win_width, win_height) {
	
	var screen_width = window.screen.width;
	var screen_height = window.screen.height;
	
	var win_left = screen_width / 2 - win_width / 2;
	var win_top = screen_height / 2 - win_height / 2;
	
	var win = window.open(url, "popup", "width=" + win_width + ", height=" + win_height + ", scrollbars=1, location=0, menubar=0, resizable=0, status=0, titlebar=0, toolbar=0, screenX=100, left=" + win_left + ", screenY=30, top=" + win_top);
 	
	win.focus();
	
}

function popupWindow(w, h) {
	
	var sw = window.screen.width;
	var sh = window.screen.height;
	
	var l = sw / 2 - w / 2;
	var t = sh / 2 - h / 2;
	
	window.resizeTo(w, h);
	window.moveTo(l, t);
	
}

/*
cookie
*/


function setCookie(name, value, expires) {
	var dt = new Date();
	var dtt = "";
	dt.setTime(dt.getTime() + expires * 24 * 60 * 60 * 1000);
	dtt = dt.toGMTString();
	document.cookie = name + "=" + value + ";expires = " + dtt + ";path=/";
}

function getCookie(name) {
	var prefix = name + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if (cookieStartIndex == -1) {
		return null;
	}
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if (cookieEndIndex == -1) {
		cookieEndIndex = document.cookie.length;
	}
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie(name) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ";expires=Thu, 01-Jan-70 00:00:01 GMT;path=/";
	}
}

function deleteCart(table, value) {
	var cart = getCookie('cart_' + table);
	if (cart == null) {
		return;
	}
	var values = cart.split(",");
	cart = "";
	for (var i = 0; i < values.length; i += 1) {
		if (value != values[i]) {
			cart = cart + values[i] + ",";
		}
	}
	cart = cart.substring(0, cart.length - 1);
	setCookie('cart_' + table, cart, 100);
	window.location.reload();
}

function addCart(table, value) {
	var cart = getCookie('cart_' + table);
	if (cart == null) {
		cart = "";
	}
	var values = cart.split(",");
	for (var i = 0; i < values.length; i += 1) {
		if (value == values[i]) {
			if (table == 'service') {
				alert('Эта услуга уже есть в Вашей корзине');
			}
			if (table == 'package') {
				alert('Этот пакет уже есть в Вашей корзине');
			}
			return;
		}
	}
	if (cart != "") {
		cart += ",";
	}
	cart += value;
	setCookie('cart_' + table, cart, 100);
	if (table == 'service') {
		alert('Услуга была добавлена в Вашу корзину');
	}
	if (table == 'package') {
		alert('Пакет был добавлен в Вашу корзину');
	}
}


function setCookie (name, value, expires, path, domain, secure) {
      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

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);
}

function selectRegion(sReg) {
  var aSrc = {
    "msk": "ad-tel-msk.gif",
    "tmb": "ad-tel-tmb.gif",
    "spb": "ad-tel-piter.gif",
    "nvg": "ad-tel-nvg.gif",
    "ekat": "ad-tel-ekat.gif",
    "novosib": "ad-tel-novosib.gif",
    "samara": "ad-tel-samara.gif",
    "almaty": "ad-tel-almaty.gif",
    "rostov": "ad-tel-rostov.gif",
    "kiev": "ad-tel-kiev.gif",
    "kazan": "ad-tel-kazan.gif"
  }, j = 0;
	document.getElementById('tel').setAttribute("src", "/img/" + aSrc[sReg]);
  for (var i in aSrc) {
    document.getElementById(i).style.display = (sReg != i) ? "none" : "block"; 
    document.getElementById(i + "1").style.display = (sReg == i) ? "none" : "block"; 
    if (sReg == i) {
      document.cookie = "dreg=" + j + ";expires=Mon, 28-Dec-2020 00:00:01 GMT;path=/;domain=.demis-advert.ru";
    }
    j++;
  }
  return false;
}

function checkphone() {
}

