﻿function tbd(){ alert("Еще не реализовано!");}

function getDomain(){
    dn = document.location.hostname;
    if(dn.indexOf(".") > 0)
	    return dn.split('.').slice(-2).join('.');
	else
	    return null;
}

function setCookie(name, value, expires){
	var domain=getDomain();
    document.cookie= name.toUpperCase() + "=" + escape(value) +
        ((expires) ? "; path=/; expires=" + expires.toGMTString() : "; path=/" ) +
        ((domain) ? "; domain=" + domain : "");
}


function getCookie(name){
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) { begin = dc.indexOf(prefix); if (begin != 0) return null; }
    else  begin += 2;
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) end = dc.length;
    return unescape(dc.substring(begin + prefix.length, end));
} 

function delCookie(name){
	var domain=getDomain();
	var name1 = name.toLowerCase();
	var name2 = name.toUpperCase();
	var addStr = "=; path=/; expires=Thu, 01-Jan-1990 00:00:01 GMT;domain="+domain;
    if (getCookie(name) != null) document.cookie = name + addStr;
    if (getCookie(name1) != null) document.cookie = name1 + addStr;
    if (getCookie(name2) != null) document.cookie = name2 + addStr;
}

function clearCookies() {
	var dc = document.cookie;
	var tempString = "";
	var tempChar;
	var count = 0;
	var cookieLength = dc.length;
	var cDel = new Array();
	while (count < cookieLength) {
	
		tempChar = dc.charAt(count);
		if (tempChar == '=') {
			cDel[cDel.length] = tempString;
			tempString = "";
		}
		if (tempChar == ';')tempString = "";
		if (tempChar != '=' && tempChar != ';' && tempChar != " ")
			tempString += tempChar;
		count += 1;
	}
	for(i=0; i < cDel.length; i++) delCookie(cDel[i]);
}

function setLang(lang){
    setCookie("lang", lang);
    document.location = document.location;
}

function openWin(scriptURL, height, width, left, top, status, menubar){
	if(width == null) width = 550;
	if(left == null) left = 160;
	if(top == null) top = 160;
	if(status == null) status = "no";
	if(menubar == null) menubar = "no";
	var wnd = window.open(scriptURL, 'wb_win', 'resizable=yes,scrollbars=yes,menubar='+menubar+',status='+status+',height='+height+',width='+width+',left='+left+',top='+top);
	wnd.focus();
}

function payment(brid){
    openWin('/Assist.aspx?id=' + brid, 535, 660, 100, 50, 'yes', 'no');
}

function sberbank(guid){
    openWin('/Blanks/Sberbank.aspx?guid=' + guid, 535, 690, 100, 50, 'yes', 'yes');
}

function schet(guid){
    openWin('/Blanks/Schet.aspx?guid=' + guid, 535, 690, 100, 50, 'yes', 'yes');
}

function cardPayment(brid) {
    openWin('/Payment.aspx?id=' + brid, 535, 660, 100, 50, 'yes', 'no');
}
