function browseIt()
{
    this.ver = navigator.appVersion.toLowerCase();
    this.agent = navigator.userAgent.toLowerCase();
    this.dom = document.getElementById ? 1 : 0;
    this.opera = (navigator.userAgent.indexOf("opera")>-1 && document.getElementById) ? 1 : 0;
    this.opera7 = (this.opera && parseInt(navigator.appVersion) >= 7);
    this.ie = (this.ver.indexOf("msie") > -1 && this.dom && !this.opera) ? 1 : 0;
    this.macOS = this.agent.indexOf("mac") > -1;
    this.mac = (this.macOS && parseInt(this.ver) >= 7) ? 1 : 0;
    this.moz = (this.agent.indexOf("gecko")>-1)
    this.ns6 = (this.dom && this.agent.indexOf("netscape")>-1 && parseInt(this.ver) >= 5) ? 1 : 0;
    this.b = (this.ie || this.ns6 || this.opera7 || this.mac || this.moz || this.dom);
    return this;
}

function makeObj(obj)
{
    this.elem = document.getElementById(obj);
    this.css = this.elem ? this.elem.style : null;
    return this;
}

var px = window.opera ? "" : "px";
var b = new browseIt();

function previewIt(href, wW, wH)
{
    var wW = (!wW)? 100 : wW;
    var wH = (!wH)? 100 : wH;
    var winl = (screen.width - wW) / 2;
    var wint = (screen.height - wH) / 2;
    var winprops = navigator.appName == "Netscape" ? 'height='+wH+',width='+wW+',top='+wint+',left='+winl+',toolbar=no,'+'location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes' : 'height='+wH+',width='+wW+',top='+wint+',left='+winl+',toolbar=no,'+'location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=yes';
    var win = window.open(sp, 'popup', winprops);
    if (parseInt(navigator.appVersion) >= 4)
        win.window.focus();
}

function showFloatForm(act, formAct)
{
	// read BMS-cookie
	var cookieCrumbs = document.cookie.split(';');
	var nameToFind = 'BMS'+'=';
	for (var i = 0; i < cookieCrumbs.length; i++) {
		var crumb = cookieCrumbs[i];
		while(crumb.charAt(0) == ' ') {
			crumb = crumb.substring(1, crumb.length);
		}
		if (crumb.indexOf(nameToFind) == 0) {
			var BMS = crumb.substring(nameToFind.length, crumb.length);
			if(BMS) {
				var gotourl = formAct ? formAct : baseurl;
				window.location.href = gotourl;
				return false;
			}
		}
	}

    var oTmp = new makeObj("mainFloatForm");
    var oTmp1 = new makeObj("floatForm");
    if (!oTmp.elem || !oTmp1.elem)
        return true;
    var oTmpW = 400;
    var oTmpH = 260;
    var sW = (!b.ie) ? self.innerWidth : self.document.body.offsetWidth;
    oTmp.css.width = oTmp1.css.width = oTmpW + px;
    //oTmp.css.left = (sW - oTmpW)/2 + px;
    //oTmp.css.top = document.body.scrollTop + parseInt(sW * 0.07);
    oTmp.css.left = getCrossScrollLeft() + Math.round(getCrossClientWidth()/2) - parseInt(oTmpW/2)+ px;
    oTmp.css.top = getCrossScrollTop() + Math.round(getCrossClientHeight()/2) - parseInt(oTmpH/2) + px;
    if (act) {
        oTmp.css.display = 'none';
        toggleDisplay('SELECT', 'visible');
        toggleDisplay('OBJECT', 'visible');
        toggleDisplay('EMBED', 'visible');
    } else {
        if(b.ns6 && !b.opera) return true;
        oTmp.css.display = 'block';
        toggleDisplay('SELECT', 'hidden');
        toggleDisplay('OBJECT', 'hidden');
        toggleDisplay('EMBED', 'hidden');
            document.forms.login.url.value = formAct ? formAct : '';
            setTimeout("document.forms.login.login.focus();", 100);
    }

    return false;
}

function toggleDisplay(tag, value)
{
    var sel = document.getElementsByTagName(tag);
    for (var i = 0; i < sel.length; i++)
        sel[i].style.visibility = value;
}

function echoLoginForm(dom, img, auth) {
    var el = new makeObj('mainFloatForm');
    if (!el.elem)
        return;
    el.elem.innerHTML = '<table cellspacing="0" cellpadding="0" id="floatForm" onkeyup="if(event.keyCode==27)showFloatForm(1)">' +
    '<tr><td colspan="2" class="floatFormHeader"><span>Ваш паспорт</span><img src="' + img + 'img/close_.gif" width="16" height="14" border="0" onclick="showFloatForm(1);" class="close"></td></tr>' +
    '<tr><td class="tdRight">Логин</td><td><input type="hidden" name="rnd"/><input type="hidden" name="url"/><input type="text" name="login" size="13" class="width100pc" onchange="this.form.rnd.value=Math.random();"/><div style="color:#999;font-size:0.9em">Например, team@bigmir.net или team</div></td></tr>' +
    '<tr><td class="tdRight">Пароль</td><td><input type="password" name="pass" size="13" maxlength="32" class="width100pc" onchange="this.form.rnd.value=Math.random();"/><br>Пароль есть, но Вы его <a href="http://passport' + dom + '/remind/">забыли?</a><hr noshade size="1"><!-- если будет фича "чужого компьютера" - разремить строку --><input id="auth_type" type="checkbox" name="auth_type" value="1">&nbsp;<label for="auth_type" class="fixed11px">Запомнить меня на месяц.</label><hr noshade size="1"><br><input type="submit" name="subm" value="Войти">&nbsp;<input type="button" value="Закрыть" onclick="showFloatForm(1);" id="darkgrey">' +
    (auth ? '' : '<br><br><hr noshade size="1">Пройдите авторизацию. Впервые на сайте &mdash; <a href="http://passport' + dom + '/registration/">зарегистрируйтесь</a>!') +
    '<div class="spacer" style="height:0.5em"><spacer></div></td></tr></table>';
}

function titleMe(src)
{
    src.title = t ? 'Спрятать все разделы' : 'Показать все разделы';
}

function trim(s, p)
{
    if (typeof s != 'string')
        return s;
    return s.replace(p ? p : /^\s*|\s*$/g, '');
}

function stripTags(str)
{
    return str.replace(/(<([^>]*)>)/g, '');
}

function checkAll(val, p)
{
    if (!p)
        p = document.body;

    var arr = p.getElementsByTagName('INPUT');
    for (var i = 0; i < arr.length; i++) {
        if (arr[i].type == 'checkbox')
            arr[i].checked = val;
    }
}

function _fp()
{
    if (parent && parent != window && parent.location.hostname != "my.clickdensity.com")
        parent.location.href = window.location.href;
}

function my_confirm()
{
    if (confirm("Are you sure?"))
    {
        return true;
    }

    return false;
}

function show_alert_message_box(message)
{
    alert(message)
}

function show_props(obj, objName, recursive, showFunc)
{
	//if(!recursive)
		recursive = false;
	if(!showFunc)
		showFunc = false;
	if(!objName)
		objName = typeof(obj);
	var result = "";
	for (var i in obj)
	{
		if(recursive && typeof(obj[i]) == "object")
		{
			result += show_props(obj[i], i, recursive, showFunc);
		}
		if(!showFunc && typeof(obj[i]) == "function")
		{
			continue;
		}
		result += objName + "." + i + " = " + obj[i] + "\n";
	}
	return result;
}

// crossbrowser additional funcs
function getCrossClientWidth() {
	return execCrossFilterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function getCrossClientHeight() {
	return execCrossFilterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function getCrossScrollLeft() {
	return execCrossFilterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function getCrossScrollTop() {
	return execCrossFilterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function execCrossFilterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}