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


function hide_id(layer)
{
	try {
		l = document.getElementById(layer);
		l.style.display = "none";
	} catch(e){
	}
	try {
		l = document.getElementById(layer);
		l.style.visibility = "hidden";
	} catch(e){
	}
	return true;
}

function show_id(layer)
{
	try {
		l = document.getElementById(layer);
		l.style.display = "block";
	} catch(e){
	}
	try {
		l = document.getElementById(layer);
		l.style.visibility = "visible";
	} catch(e){
	}
	return true;
}



function get_top(id)
{
	var y, obj;
	if (is.ns4) {
		if (id.container != null) {
			return id.container.pageY + img.y;
		} else {
			return id.y;
		}
	} else {
		y = 0;
		obj = id;
		while (obj.offsetParent != null) {
			y += obj.offsetTop;
			obj= obj.offsetParent;
		}
		y += obj.offsetTop;
		return y;
	}
	return -1;
}

function get_left(id)
{
	var x, obj;
	if (is.ns4) {
		if (id.container != null) {
			return id.container.pageX + img.x;
		} else {
			return id.x;
		}
	} else {
		x = 0;
		obj = id;
		while (obj.offsetParent != null) {
			x += obj.offsetLeft;
			obj= obj.offsetParent;
		}
		x += obj.offsetLeft;
		return x;
	}
	return -1;
}

function basket_reset(cz)
{
	var count = document.getElementsByName(cz);
	for (i = -1; ++i < count.length;) {
		document.getElementById('v'+i).value = '';
	}
	return false;
}

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


	if ((typeof txt) == 'undefined' ) {
		txt = '';
	}

	window.open('/?winup&img='+escape(img)+'&text='+escape(txt),'popUp','width='+w+',height='+h+',scrollbars=no,menubar=no,toolbar=no,status=no,left='+scrnx+',top='+scrny);
	return false;
}


main = true;
dmTimer = 0;
curMenu = null;
dmTimeOut = 1500;
myTT = 0;
function sm(el)//sm - Show Menu
{
	var x = get_left(document.getElementById('mm'+el));
	var y = get_top(document.getElementById('mm'+el));

	document.getElementById('m'+el).style.left= x;
	document.getElementById('m'+el).style.top = y + 28;

	if (curMenu == null) {
		curMenu = el;
	} else {
		var obj = document.getElementById('mm'+curMenu);
		obj.style.background = '#6D7AA4';
		if (is.ie) {
			var obj2 = document.getElementById('mt'+curMenu);
			obj2.style.background = '#99A2C4';
		}

		hide_id('m'+curMenu);
		curMenu = el;
	}


	var obj3 = document.getElementById('mm'+el);
	obj3.style.background = '#445078';

	if (is.ie && !is.opera) {
		obj2 = document.getElementById('mt'+el);
		obj2.style.background = '#445078';

		var ww = document.getElementById('mm'+el).clientWidth;
		document.getElementById('m'+curMenu).style.width = ww;
	}

	show_id('m'+curMenu);
	dmTimer = dmTimeOut;
	return;
}

function timer_over()
{
	dmTimer = 10000000;
	clearTimeout(myTT);
	return;
}
function timer_out()
{
	dmTimer = dmTimeOut;
	myTT = setTimeout("timer()", dmTimeOut);
	return;
}
function timer()
{
	if (null != curMenu) {
		hide_id('m'+curMenu);

		try {
			if (document.getElementById('mm'+curMenu)) {
				obj = document.getElementById('mm'+curMenu);
				obj.style.background = '#6D7AA4';
				obj2 = document.getElementById('mt'+curMenu);
				obj2.style.background = '#99A2C4';
			}
		}catch(e){}
	}
	curMenu = null;

	return;
}


function mbg(td, n)
{
	try {
		//td = eval(td);
		switch(n)
		{
			case 0:
				//td.firstChild.style.color = '#FFFFFF';
				td.style.background = '';
				break;
			case 1:
				//td.firstChild.style.color = '#E3D799';
				td.style.background = '#7E89AC';
				break;
		}
	} catch(e) {}
	return false;
}

function ov(tr) {tr.style.backgroundColor = '#232f33';}

function ou(tr){tr.style.backgroundColor = '';}

function chup(o)
{
	var x = o.src.substring(o.src.lastIndexOf('/'));
	if ('/ico-arrow-up_c.gif' == x) {
		o.src = '/design/ico-arrow-up_c_.gif';
	} else {
		o.src = '/design/ico-arrow-up_c.gif';
	}
	return;
}

function chdn(o)
{
	var x = o.src.substring(o.src.lastIndexOf('/'));
	if ('/ico-arrow-down_c.gif' == x) {
		o.src = '/design/ico-arrow-down_c_.gif';
	} else {
		o.src = '/design/ico-arrow-down_c.gif';
	}
	return;
}

function updn(o, a)
{
	var x = o.parentNode.firstChild;
	var val = parseInt(x.value);

	if (a) {
		x.value = !isNaN(++val)? val : 1;
	} else {
		x.value = !isNaN(--val)? val : 0;
		if (val <= 0) x.value = 0;
	}
	return;
}

function s(el)
{

	var x = get_left(document.getElementById('mm'+el));
	var y = get_top(document.getElementById('mm'+el));

	document.getElementById('m'+el).style.left= x;
	document.getElementById('m'+el).style.top = y + 30;

	if (curMenu == null) {
		curMenu = el;
	} else {
		var obj = document.getElementById('mm'+curMenu);
		obj.style.background = '#6D7AA4';

		hide_id('m'+curMenu);
		curMenu = el;
	}

	var obj2 = document.getElementById('mm'+el);
	obj2.style.background = '#445078';

	if (is.ie && !is.opera) {
		var ww = document.getElementById('mm'+el).clientWidth;
		document.getElementById('m'+curMenu).style.width = ww;
	}
	show_id('m'+curMenu);
	dmTimer = dmTimeOut;
	return;
}


function form(action, method, target, submit)
{
	if ('undefined' == typeof(method)) {
		method = 'post';
	}
	var targ = '';
	if ('undefined' != typeof(target)) {
		targ = ' target="' + target + '"';
	}
	var subm = '';
	if ('undefined' != typeof(submit)) {
		subm = ' onsubmit="'+submit+'" '
	}
	document.write('<form method="'+method+'" action="'+action+'" '+targ+' '+subm+' enctype="multipart/form-data">');
	return;
}

function getRecord()
{

	$.post("/?getRecord", {
			id: $('#mdot').val()
		},
		function(reply) {
			$('#setRecord').empty().append(reply);
		}
	);
	return;
}


function ac(sid) {
    if (0 > sid) {
        if (-100 == sid) {ajax_list_externalFile = '/?getSearch&sid=0';}
        else if (-200 == sid) {ajax_list_externalFile = '/?getKSearch&sid=0';}
        return;
    }
    ajax_list_externalFile = '/?getSearch&sid=' + sid;
    return;
}


function getKamaz()
{
	$.post("/?getKRecord", {
			id: $('#kdot').val()
		},
		function(reply) {
			$('#setKamaz').empty().append(reply);
		}
	);
	return;
}

function setKamazSel(sid)
{
	$.post("/?getKItem="+sid, {
			sid: sid
		},
		function(reply) {
			$('#sKdot').empty().append(reply);
		}
	);
	return;
}

function upBasket()
{
	$.post("/basket/?upBasket", {
			up: 1
		},
		function(reply) {
			$('#boxBasket').empty().append(reply);
			$('#resAdd').empty();
		}
	);
	return;
}

function sendCatalog()
{
	$.post("/basket/?set", {
			data: $('#cform').serialize()
		},
		function(reply) {
			$('#resAdd').empty().append('Товар добавлен в корзину');
			return true;
		}
	);
	return false;
}

$(document).ready(function() {
	$('a[class="group"]').fancybox({
		overlayOpacity: 0.6,
		overlayColor: '#000'
	});
});