function ImgShw(ID, width, height, alt) {
    var scroll = "no";
    var top=0, left=0;
    if(width > screen.width-10 || height > screen.height-28) scroll = "yes";
    if(height < screen.height-28) top = Math.floor((screen.height - height)/2-14);
    if(width < screen.width-10) left = Math.floor((screen.width - width)/2-5);
    width = Math.min(width, screen.width-10);
    height = Math.min(height, screen.height-28);
    var wnd = window.open("","","scrollbars="+scroll+",resizable=yes,width="+width+",height="+height+",left="+left+",top="+top);
    wnd.document.write(
	    "<html><head>"+
	    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"+
	    "<title>"+(alt == "" ? "" : alt)+"</title></head>"+
	    "<body topmargin=\"0\" leftmargin=\"0\" marginwidth=\"0\" marginheight=\"0\">"+
	    "<img src=\""+ID+"\" border=\"0\" alt=\""+alt+"\" />"+
	    "</body></html>"
	    );
    wnd.document.close();
}

function clickSitemap(e) {
    if (!e) var e = event;
    //
    if (e) {
	var theEl = e.target;
	if (!theEl) theEl = e.srcElement;
	if (theEl) {
	    var sEl = theEl.tagName.toUpperCase();
	    if (sEl === 'A') {
		document.location.href = theEl.href;
	    } else if (sEl === 'LI') {
		theUl = theEl.firstChild;
		while (!(theUl.tagName && theUl.tagName.toUpperCase() === 'UL') && theUl.nextSibling) {
		    theUl = theUl.nextSibling;
		}
		if (theUl && theUl.tagName && theUl.tagName.toUpperCase() === 'UL') {
		    var sState = 'expanded';
		    if (theUl.className === 'sitemap-group-expanded') sState = 'collapsed';
		    theUl.className = 'sitemap-group-' + sState;
		    theEl.className = 'sitemap-item-' + sState;
		}
	    }
	}
	if (e.stopPropagation) e.stopPropagation();
	e.cancelBubble = true; // deprecated
    }
    //
    return false;
}

function checkWebForm(obj) {
    var element, pattern;
    for (var i = 0; i < obj.elements.length; i++) {
	element = obj.elements[i];
	if (!element.getAttribute("required")) continue;
	if (pattern = element.getAttribute("check_pattern")) {
	    pattern = new RegExp(pattern, "g");
	    if (!pattern.test(element.value)) {
		var v_req = element.getAttribute("required");
		if (typeof(v_req) !== 'string' || v_req === "required") v_req = "Необходимо заполнить все обязательные поля";
		alert(v_req);
		element.focus();
		return false;
	    } 
	} else if (/^\s*$/.test(element.value)) {
	    var v_req = element.getAttribute("required");
	    if (typeof(v_req) !== 'string' || v_req === "required") v_req = "Необходимо заполнить все обязательные поля";
	    alert(v_req);
	    element.focus(); 
	    return false; 
	}
    }
    //
    return true; 
}

function toPrintable() {
    var sHref = document.location.href;
    sHref += ((sHref.indexOf('?') === -1) ? '?' : '&');
    sHref += "printable=1";
    document.location.href = sHref;
    return false;
}


function westcallVotePostDo(formName, inputName, nstext) {
    var fObjColl = document.getElementsByName(formName);

    var fObj = '';
    if (fObjColl) {
	fObj = fObjColl[fObjColl.length-1];
    }

    if(typeof(fObj) !== "object") return false;

    iObj = fObj.elements[inputName];

    if(typeof(iObj) === "undefined") return false;

    res = false;
    for(i = 0; i < iObj.length; i++)
	if(iObj[i].checked)
	    res = iObj[i].value;


    if(res) {
	sc = document.createElement("script");
	sc.src = "/vote/post/" + res + "/?m=" + new Date().getTime();

	fObj.appendChild(sc);
    } else {
	if(nstext) {
	    alert(nstext);
	}
    }
}

    // Search engine tracking

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-20299168-1']);
    _gaq.push(['_setDomainName', 'westcall.spb.ru']);
    _gaq.push(['_setAllowHash', 'false']);
    _gaq.push(['_trackPageview']);
    ( function() {
     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
     ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
     var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
     } )();


