function brw()
{
	var b=navigator.appName;
	if (b.indexOf('Netscape')!=-1) this.b="ns";
	else if ((b=="Opera") || (navigator.userAgent.indexOf("Opera")>0)) this.b = "opera";
	else if (b=="Microsoft Internet Explorer") this.b="ie";
	if (!b) {this.b="invalid"; this.invalid=true;}
	this.version=navigator.appVersion;
	this.v=parseInt(this.version);
	this.ns=(this.b=="ns" && this.v>=4);
	this.ie=(this.version.indexOf('MSIE')>0);
	this.opera=(this.b=="opera");
	this.dom=(document.createElement && document.appendChild && document.getElementsByTagName)?true:false;
	return;
}
var is = new brw();

var baseUrl = '/skin/simple/design/';




var myTT = 0;
var main = true;
var dmTimer = 0;
var curMenu = null;
var dmTimeOut = 1500;


function hide_id(layer)
{
	if (typeof(layer) != 'object') {
		var l = document.getElementById(layer);
	} else {
		var l = layer;
	}
	try {
		l.style.display = "none";
	} catch(e){
	}
	try {
		l.style.visibility = "hidden";
	} catch(e){
	}
	return true;
}

function show_id(layer)
{
	if (typeof(layer) != 'object') {
		var l = document.getElementById(layer);
	} else {
		var l = layer;
	}
	try {
		l.style.display = "block";
	} catch(e){
	}
	try {
		l.style.visibility = "visible";
	} catch(e){
	}
	return true;
}


function postView(w, h, img, txt)
{
	var scrnx = screen.width/2 - w/2;
	var scrny = screen.height/2- h/2;

	if (!txt || !isNaN(txt) || '' == txt) {
		window.open('../../../../?img='+escape(img),'popUp','width='+(w+50)+',height='+(h+50)+',scrollbars=no,menubar=no,toolbar=no,status=no,left='+scrnx+',top='+scrny);
	} else {
		window.open('../../../../?img='+escape(img)+'&text='+txt,'popUp','width='+w+',height='+h+',scrollbars=no,menubar=no,toolbar=no,status=no,left='+scrnx+',top='+scrny);
	}

	return false;
}

function m(id)
{

	if (null != curMenu) {
		document.getElementById('acim'+curMenu).src = '/skin/simple/design/ng/'+(curMenu+1)+'.gif';
		hide_id('m'+curMenu);
	}
	var o = document.getElementById('m'+id);
	var i = document.getElementById('acim'+id);
	if ('none' == o.style.display || '' == o.style.display) {
		show_id(o);
		curMenu = id;
		i.src = '/skin/simple/design/nr/'+(id+1)+'.gif';
	} else {
		hide_id(o);
	}

}
var curMenu = null;

window.onload = function() {
	try {
	var a = document.getElementById('nd');
	a.onmouseover= function(){this.src='/skin/simple/design/logo-r.gif';};
	a.onmouseout = function(){this.src='/skin/simple/design/logo-g.gif';};
	a.parentNode.target = "New_Design";

	var b = document.getElementById('new_design');
	b.onmouseover= function(){a.src='/skin/simple/design/logo-r.gif';};
	b.onmouseout = function(){a.src='/skin/simple/design/logo-g.gif';};
	b.target = "New_Design";

	} catch(e){}

}



function bg(tr, m)
{
    return;
    if (m) {
    	tr.style.background = '#eee';
    } else {
    	tr.style.background = '';
    }
    return;
}
function setTab(b) {
    for (var i = 0; ++i<5;) {
        $('block'+i).style.display = 'none';
        $('ttab'+i).style.borderBottom = 'solid 1px #333';
    }

    $('ttab'+b).style.borderBottom = 'solid 1px #fff';
    $('block'+b).style.display = 'block';

    return false;
}



//var $bx1 = $bx2 = $bx3 = $bx4 = false;
var emptyVal = 'Не заполнены все обязательные поля.<br />';

function rdBox(val, cnt, block, type, isOther) {

    if ('undefined' == typeof(type) || type.empty()) {type = 'radio';}
    if ('undefined' == typeof(isOther) || type.empty()) {isOther = true;}

    $(val).value = '';
    for (i=-1; ++i<cnt;) {
        id = val + "" + i;
        if ($(id).checked) {
            if ('checkbox' == type) {
                $(val).value += $(id).value + ', ';
            } else {
                $(val).value = $(id).value;
            }
        }
    }

    if (isOther) {
        if ($(val).value.empty() && !$(val + '_other').value.empty()) {
            $(val).value = $(val + '_other').value;
        } else {
            if ('checkbox' == type && !$(val + '_other').value.empty()) {
                $(val).value += $(val + '_other').value;
            }
        }
    }

    if ($(val).value.empty()) {
            $('msg').innerHTML = emptyVal;
            $(val + 'Box').style.border = 'solid 1px red';
            setTab(block);
            $(val+'0').focus();
            setTimeout("$('" + val + 'Box' + "').style.border = 'solid 1px #fff';$('msg').innerHTML='';", 2000);
            return false;
    }

    return true;
}

function isVal(s, numBlock) {
    if ($F(s).empty()) {
        $('msg').innerHTML = emptyVal;
        $(s).style.border = 'solid 1px red';
        setTab(numBlock);
        $(s).focus();
        setTimeout("$('"+s+"').style.border = 'solid 1px #333';$('msg').innerHTML='';", 3000);
        return false;
    }

    return true;
}


function pubValid() {

    var numBlock = 1;
    var fields = ['b1_nazvanie', 'b1_godnachala', 'b1_gorod', 'b1_tematika', 'b1_format', 'b1_tirag', 'b1_periodvihoda', 'b1_cvetnost', 'b1_redaktor_email'];
    for (var i=-1; ++i<fields.length;) {
        if (!isVal(fields[i], numBlock)) {return false;}
    }

    if (rdBox('b1_tip', 4, numBlock)) {
        if (rdBox('b1_ayditoriya', 3, numBlock, 'checkbox')) {
            if (!rdBox('b1_territory', 4, numBlock)) {
                return false;
            }
        } else {return false;}
    } else {return false;}

    // ---------------------

    numBlock = 2;
    fields = ['b2_nazvanie', 'b2_otrasl', 'b2_contact_web'];
    for (var i=-1; ++i<fields.length;) {
        if (!isVal(fields[i], numBlock)) {return false;}
    }

    if (rdBox('b2_razmerkompanii', 3, numBlock, 'radio', false)) {
        if (!rdBox('b2_kyrator_izdaniya', 4, numBlock)) {
            return false;
        }
    } else {return false;}

    return true;
}