var d = document;

function addClass(id, aclass) {
	aclass = aclass.replace(/\s+/, '');
	if (d.getElementById(id) && aclass.length) {
		var classStr = d.getElementById(id).className;
		var classArr = classStr.split(' ');
		var addSW = 1;
		classStr = '';
		for (i=0; i<classArr.length; i++) {
			classArr[i] = classArr[i].replace(/\s+/, '');
			if (classArr[i].length) classStr += ' ' + classArr[i];
			if (classArr[i] == aclass) addSW = 0;
		}
		if (addSW) classStr += ' ' + aclass;
		if (classStr.length) classStr = classStr.substr(1);
		d.getElementById(id).className = classStr;
	}
}

function removeClass(id, aclass) {
	aclass = aclass.replace(/\s+/, '');
	if (d.getElementById(id) && aclass.length) {
		var classStr = d.getElementById(id).className;
		var classArr = classStr.split(' ');
		var addSW = 1;
		classStr = '';
		for (i=0; i<classArr.length; i++) {
			classArr[i] = classArr[i].replace(/\s+/, '');
			if (classArr[i].length && classArr[i] != aclass) classStr += ' ' + classArr[i];
		}
		if (classStr.length) classStr = classStr.substr(1);
		d.getElementById(id).className = classStr;
	}
}

var catMenuI = 0, catMenuT;

function catMenuSh(id) {
	if (d.getElementById('cm' + id)) {
		window.clearTimeout(catMenuT);
		if (catMenuI != id) catMenuHi_(catMenuI);
		addClass('cm' + id, 'selected');
		if (d.getElementById('cmul' + id) && d.getElementById('cmif' + id)) {
			d.getElementById('cmif' + id).style.width = d.getElementById('cmul' + id).offsetWidth;
			d.getElementById('cmif' + id).style.height = d.getElementById('cmul' + id).offsetHeight;
		}
		catMenuI = id;
	}
}

function catMenuHi_(id) {
	if (d.getElementById('cm' + id)) {
		removeClass('cm' + id, 'selected');
		catMenuI = 0;
	}
}

function catMenuHi(id) {
	catMenuT = window.setTimeout('catMenuHi_(' + id + ')', 100);
}

var topMenuI = 0, topMenuT;

function topMenuSh(id) {
	if (d.getElementById('tm' + id)) {
		window.clearTimeout(topMenuT);
		if (topMenuI != id) topMenuHi_(topMenuI);
		addClass('tm' + id, 'selected');
		if (d.getElementById('tmul' + id) && d.getElementById('tmif' + id)) {
			d.getElementById('tmif' + id).style.width = d.getElementById('tmul' + id).offsetWidth;
			d.getElementById('tmif' + id).style.height = d.getElementById('tmul' + id).offsetHeight - 1;
		}
		topMenuI = id;
	}
}

function topMenuHi_(id) {
	if (d.getElementById('tm' + id)) {
		removeClass('tm' + id, 'selected');
		topMenuI = 0;
	}
}

function topMenuHi(id) {
	topMenuT = window.setTimeout('topMenuHi_(' + id + ')', 100);
}

function changeInputText(obj, text, /*type,*/ sw) {
	sw = Math.ceil(sw);
	var textF = sw ? '' : text;
	var textR = sw ? text : '';
	if (obj.value == textF) {
		obj.value = textR;
		//if (typeof(type) && type.length) obj.type = type;
	}
}

function iitemF(sw) {
	if (d.getElementById('iitemfl') && d.getElementById('iitemolt') && d.getElementById('iitemolb') && d.getElementById('iitem_fii') && d.getElementById('iitem_sii') && d.getElementById('iitem_fi') && typeof('iitemArr') != 'undefined') {
		if(d.getElementById('iitem_fii').innerHTML.length < 20) {
			d.getElementById('iitem_fii').innerHTML = '';
			for (i=0; i<iitemArr.length; i++) {
				d.getElementById('iitem_fii').innerHTML = d.getElementById('iitem_fii').innerHTML + '<div class="bimg"><img src="' + iitemArr[i] + '" alt="" /></div>';
			}
		}
		d.getElementById('iitemfl').style.display = sw ? 'none' : 'block';
		d.getElementById('iitemolt').style.display = sw ? 'block' : 'none';
		d.getElementById('iitemolb').style.display = sw ? 'block' : 'none';
		d.getElementById('iitem_fi').style.display = sw ? 'none' : 'block';
		d.getElementById('iitem_sii').style.display = sw ? 'none' : 'block';
		d.getElementById('iitem_fii').style.display = sw ? 'block' : 'none';
	}
}

function iitemSW(num) {
	if (d.getElementById('iitem_image_main') && d.getElementById('iitem_image_main_' + num) && typeof('iitemArr') != 'undefined' && typeof('iitemArr[' + num + ']') != 'undefined') {
		for (i=0; d.getElementById('iitem_image_main_' + i); i++) {
			d.getElementById('iitem_image_main_' + i).className = '';
		}
		d.getElementById('iitem_image_main').src = iitemArr[num];
		d.getElementById('iitem_image_main_' + num).className = 'selected';
	}
}

function customPUA(html) {
	html = html.replace("\r", '');
	html = html.replace("\n", '');
	html = '<table cellpadding="0" cellspacing="0" border="0" style="margin:0px auto;"><tr>' + 
				'<td style="background:url(/images/_abz/__pua_tl.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_bg_e7e7e7.gif) left top repeat-x;"><img src="/images/i.gif" width="300" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_tr.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x;"><img src="/images/i.gif" width="11" height="85" alt="" /></td>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x; padding:10px;">' + html + '</td>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x;"><img src="/images/i.gif" width="11" height="85" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:#e7e7e7; padding:10px 5px 0px 0px; text-align:right; font-size:11px;"><a href="/" onclick="hbPUAhide(); return false;">закрыть</a></td>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:url(/images/_abz/__pua_bl.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="300" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_br.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr></table>';
	hbPUAshow(html);
}

function customPUAimages(html) {
	html = html.replace("\r", '');
	html = html.replace("\n", '');
	html = '<table cellpadding="0" cellspacing="0" border="0" style="margin:0px auto;"><tr>' + 
				'<td style="background:url(/images/_abz/__pua_tl.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_bg_e7e7e7.gif) left top repeat-x;"><img src="/images/i.gif" width="500" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_tr.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x;"><img src="/images/i.gif" width="11" height="85" alt="" /></td>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x; padding:10px;">' + html + '</td>' +
				'<td style="background:#e7e7e7 url(/images/_abz/__pua_bg_e7e7e7.gif) 0px -11px repeat-x;"><img src="/images/i.gif" width="11" height="85" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:#e7e7e7; padding:10px 5px 0px 0px; text-align:right; font-size:11px;"><a href="/" onclick="hbPUAhide(); return false;">закрыть</a></td>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr>' +
				'<tr>' +
				'<td style="background:url(/images/_abz/__pua_bl.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' +
				'<td style="background:#e7e7e7;"><img src="/images/i.gif" width="500" height="11" alt="" /></td>' +
				'<td style="background:url(/images/_abz/__pua_br.gif) left top no-repeat;"><img src="/images/i.gif" width="11" height="11" alt="" /></td>' + 
				'</tr></table>';
	hbPUAshow(html);
}

function onLoad(action) {
	/*var rand = sh_rand_str(8);
	var evalStr = 'function HTMLHttpOnLoadInit_' + rand + '() { ' + 
							'if (window.addEventListener) { window.addEventListener(\'load\', this.onloadListener, false); } ' + 
							'else if (window.attachEvent) { window.attachEvent(\'onload\', this.onloadListener); } ' + 
							'else if (window.onload) { window.onload = this.onloadListener; } ' + 
						'} ' + 
						'HTMLHttpOnLoadInit_' + rand + '.prototype.onloadListener = function() { ' + action + '}; ' +
						'OnLoadInit_' + rand + ' = new HTMLHttpOnLoadInit_' + rand + '();';
	eval(evalStr);*/
}

function ajaxGet(URL, link, repl, evalStart, evalEnd) {
	var rand = sh_rand_str(8);
	URL += (URL.indexOf('?') > 0 ? '&' : '?') + 'rand=' + rand;
	var evalCode = 'var ajaxReq_' + rand + ' = new HTMLHttpRequest(\'ajaxReq_' + rand + '\', ajaxReq_' + rand + '_callback);';
	if (typeof(repl) != 'undefined' && repl.length) evalCode = evalCode + link + ' = \'' + repl + '\';';
	if (typeof(evalStart) != 'undefined' && evalStart.length) evalCode = evalCode + evalStart;
	evalCode = evalCode + 'ajaxReq_' + rand + '.load(\'' + URL.replace("'", "\\\'") + '\');';
	evalCode = evalCode + 'function ajaxReq_' + rand + '_callback(DOM) { var xmldata = this.getXML(); var data = xmldata.getElementsByTagName(\'data\')[0] ? (xmldata.getElementsByTagName(\'data\')[0].childNodes[0] ? xmldata.getElementsByTagName(\'data\')[0].childNodes[0].nodeValue : \'\') :\'\'; var scriptdata = xmldata.getElementsByTagName(\'scriptdata\')[0] ? (xmldata.getElementsByTagName(\'scriptdata\')[0].childNodes[0] ? xmldata.getElementsByTagName(\'scriptdata\')[0].childNodes[0].nodeValue : \'\') :\'\'; eval(scriptdata); ' + link + ' = unescape(data); ' + (typeof(evalEnd) != 'undefined' && evalEnd.length ? evalEnd : '') + ' }';
	eval(evalCode);
}

function ajaxPost(URL, link, linkForm, repl) {
	var rand = sh_rand_str(8);
	URL += (URL.indexOf('?') > 0 ? '&' : '?') + 'rand=' + rand;
	var evalCode = 'var ajaxReq_' + rand + ' = new HTMLHttpRequest(\'ajaxReq_' + rand + '\', ajaxReq_' + rand + '_callback);';
	evalCode = evalCode + 'var POST = ajaxReq_' + rand + '.parseForm(' + linkForm + ');';
	if (typeof(repl) != 'undefined' && repl.length) evalCode = evalCode + link + ' = \'' + repl + '\';';
	evalCode = evalCode + 'ajaxReq_' + rand + '.xmlhttpSend(\'' + URL.replace("'", "\\\'") + '\', POST);';
	evalCode = evalCode + 'function ajaxReq_' + rand + '_callback(DOM) { var xmldata = this.getXML(); var data = xmldata.getElementsByTagName(\'data\')[0] ? (xmldata.getElementsByTagName(\'data\')[0].childNodes[0] ? xmldata.getElementsByTagName(\'data\')[0].childNodes[0].nodeValue : \'\') :\'\'; var scriptdata = xmldata.getElementsByTagName(\'scriptdata\')[0] ? (xmldata.getElementsByTagName(\'scriptdata\')[0].childNodes[0] ? xmldata.getElementsByTagName(\'scriptdata\')[0].childNodes[0].nodeValue : \'\') :\'\'; eval(scriptdata); ' + link + ' = data; }';
	eval(evalCode);
}

function buildGetValue(string) {
	var plus = '++'.substring(0,1); // CodeTrim fix.
	return encodeURIComponent(string).replace(plus, '%2B');
}

function catPrint() {
	if (d.getElementById('print_area')) {
		//alert('print');
		
		var header = '<!DOCTYPE html PUBLIC ' + '"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' +
				'<' + 'html>' + '<' + 'head>' +
				'<' + 'meta http-equiv="Content-Type" content="text/html;charset=utf-8" />' +
				
				'<' + 'title>Версия для печати<' + '/title>' +
				
				'<' + 'link rel="icon" type="image/vnd.microsoft.icon" href="/favicon.ico" />' + 
				'<' + 'script type="text/javascript" src="/js/lib/funclib.js"><' + '/script>' + 
				'<' + 'script type="text/javascript" src="/js/lib/htmlhttprequest.js"><' + '/script>' + 
				'<' + 'script type="text/javascript" src="/js/lib/cookies.js"><' + '/script>' + 
				'<' + 'script type="text/javascript" src="/js/_abz/custom.js"><' + '/script>' + 
				'<' + 'script type="text/javascript" src="/js/_abz/pua.js"><' + '/script>' + 
				'<' + 'script type="text/javascript" src="/js/_abz/scap.js"><' + '/script>' + 
				'<' + 'link href="/styles/_abz/main.css" rel="stylesheet" type="text/css" />' + 
				
				'<' + 'style type="text/css">' + '<!-- ' +
				'.pp { padding:10px; }' +
				'.ppp { background:#ffffff; padding:10px; }' +
				'.catitemf_pn { display:none; }' +
				'.iistring div.print { display:none; }' +
				'.iistring { width:350px; }' +
				'.iiteml { width:370px; }' +
				'.iiteml .bimg img { width:366px; height:275px; }' +
				'#iitem_fi img { width:366px; height:275px; }' +
				'#iitem_fi { width:370px; height:280px; }' +
				'.iitemr { width:250px; }' +
				' -->' + '<' + '/style>' +
				
				
				
				'<' + '/head>' + '<' + 'body>';

		var footer = '<' + '/body>' + '<' + '/html>';
		
		printPage = window.open('','printPage',"width=680, height=500, toolbar=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, top=10, left=10");
		printPage.document.open();
		printPage.document.write(header + 
												'<div class="pp"><div class="ppp iblock">' + d.getElementById('print_area').innerHTML + '<div class="clear"><!-- --></div></div></div>' + 
												'<script type="text/javascript">' +
												'iitemF(0);' + 
												'document.getElementById(\'iitem_sii\').style.display = \'none\';' + 
												'document.getElementById(\'iitemfl\').style.display = \'none\';' + 
												'' + 
												'</script>' +
												footer);
		window.setTimeout('printPage.document.close()', 1000);
		window.setTimeout('printPage.iitemF(0)', 1001);
		window.setTimeout('printPage.document.getElementById(\'iitem_sii\').style.display = \'none\'', 1002);
		window.setTimeout('printPage.document.getElementById(\'iitemfl\').style.display = \'none\'', 1002);
		printPage.focus();
		printPage.window.print();
		
	}
}



