var RND=parseInt(Math.random()*100000);
var weight=0;
var index=0;

var lengthTD = 0;
var t = 0;
var a = 0;
var countNews=0;

var i = 0;
var j = 0;
var vse = 0;

var q=null;
var shippingarr = new Array(); // массив сумм доставки (инициализируется из скрипта)

function show_win(width,height,s_url){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	var win=window.open(s_url,"imgswin","resizable=yes,scrollbars=yes,toolbar=no,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height+",top="+p_top+",left="+p_left);
	win.focus();
}

function elistBeg(idf,n,n1,n2){
	if ( n == 0 )
		document.write("</table></td><td><table border=0 cellpadding=0 cellspacing=0><tr height=20 valign=top><td>");
	if ( n1 >= 0 &&  n1 <= n2-1 ){
				var s = ReadCookie(idf+"_vse");
				if ( s == null || s == "" )
					document.write('<div class=allEL>Все <input type=checkbox checked id="all'+idf+'" onClick="changeCheckInp(this.checked,'+idf+',t);">');
				else
					document.write('<div class=allEL>Все <input type=checkbox id="all'+idf+'" onClick="changeCheckInp(this.checked,'+idf+',t);">');
	}
	else
		document.write('<div class=allEL style="padding: 0;">');
	vse++;
}

function elistEnd(n,n2){
	if ( n == n2-1 ){
		document.write("</td></tr>");
		i = -1;
	}
	i++;
}


function elistBeg2(n,n1,n2){
	if ( n == 0 )
		document.write("</table></td><td><table border=0 cellpadding=0 cellspacing=0><tr height=20 valign=top><td>");
	if ( n1 >= 0 &&  n1 <= n2-1 )
		document.write('<div class=allEL style="height: 21px;">');
	else
		document.write('<div class=allEL style="padding: 0; height: 21px;">');
	vse++;
}

function changeText(el,text) {
	//alert(el.firstChild.nodeValue);
  //if (IsIE && IE_Ver<7) el.innerText=text;
	//else {
		if (el.firstChild) el.firstChild.nodeValue=text;
		else el.appendChild(document.createTextNode(text));
	//}
}
function show_divMODE(id_cur, mode){
	var div_set=null;
	div_set=document.getElementById(id_cur);
	if (div_set!=null)
		div_set.style.display=mode;
}

function show_divMODE_Doc(doc, id_cur, mode){
	var div_set=null;
	div_set=doc.getElementById(id_cur);
	if (div_set!=null)
		div_set.style.display=mode;
}

function ShippingItemObj(ID, Name, Price)
{
	this.ID = ID;
	this.Name = Name;
	this.Price = Price;
}


function allowEndorder(doc, my_shippingsumRUR)
{
	doc.myform.shippingsum.value = normalize(parseFloat(my_shippingsumRUR));
	var a=parseFloat(doc.getElementById("shippingsum").value);
    var b=parseFloat(doc.getElementById("ordersum").value);
    var totalcost=a+b;

		changeText(doc.getElementById("total"),"Итого к оплате: " + normalize(totalcost) + " руб.");
    //doc.getElementById("total").innerText="Итого к оплате: " + normalize(totalcost) + " руб.";

		changeText(doc.getElementById("shipsum"),"Стоимость доставки: " + normalize(doc.myform.shippingsum.value) + " руб.");
    //doc.getElementById("shipsum").innerText="Стоимость доставки: " + normalize(doc.myform.shippingsum.value) + " руб.";

	show_divMODE_Doc(doc, "shipsum", "block"); // показываем стоимость доставки
	show_divMODE_Doc(doc, "total", "block"); // показываем общую стоимость заказа
	show_divMODE_Doc(doc, "SUBMITbut", "block"); // показываем кнопку "Оформить заказ"
	return true;
}


function disallowEndorder(doc)
{
	doc.getElementById("shipsum").innerText = "Стоимость доставки пока не определена, необходимо выбрать способ доставки и рассчитать стоимость";
	show_divMODE_Doc(doc, "shipsum", "block"); // показываем стоимость доставки
	show_divMODE_Doc(doc, "total", "none"); // скрываем общую стоимость заказа
	show_divMODE_Doc(doc, "SUBMITbut", "none"); // убираем кнопку "Оформить заказ"
}




function show_win(width,height,s_url){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	var win=window.open(s_url,"imgswin","resizable=yes,scrollbars=yes,toolbar=no,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height+",top="+p_top+",left="+p_left);
	win.focus();
}

function show_print(width,height,s_url,idg){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	var win_name="win_"+idg;
	var win_print=window.open(s_url,win_name,"resizable=yes,scrollbars=yes,toolbar=yes,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height+",top="+p_top+",left="+p_left);
	win_print.focus();
}

function active_win(surl){
	window.opener.document.location=surl;
}

function add_bask_img(idcat,idgoods){
	document.write("<a href='javascript:show_win(500,200,\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\")'><img src='/i/basket.gif' width=12 height=15 hspace=4 border=0 alt='в корзину' align=absmiddle></a>");
}

function add_bask_text(idcat,idgoods){
	document.write("<a href='javascript:show_win(500,200,\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\")'><img src='/i/basket2.gif' width=106 height=20 hspace=20 vspace=2 border=0 alt='в корзину' align=absmiddle></a>");
}

function get_selected(p){
	if (p==null) return "";
	for (i=0; i < p.options.length; i++) {
		if (p.options[i].selected) { return p.options[i].value; }
	}
	return "";
}

function set_selected(p,v){
	if (p==null) return;
	for (i=0; i < p.options.length; i++) {
		if (p.options[i].value==v) { p.options[i].selected=true; break; }
	}
}

function set_radio(p,v){
	for (i=0; i < p.length; i++) {
		if (p[i].value==v) { p[i].checked=true; break; }
	}
}

function get_radio(p){
var res="";
	for (i=0; i < p.length; i++) {
		if (p[i].checked) { res=p[i].value; break; }
	}
	return res;
}


function set_checked(p,v){
	if (p.value==v) p.checked=true; 
}

function show_parent_div(div_par){
    var IDParentElement="", NextParentElement="";
		var obj=null; 
		var obj1=null;
    if (document.getElementById(div_par)!=null)
    {
			obj1=document.getElementById(div_par);
			for(var i=0; i<10; i++) {
				obj=obj1;
				if (obj!=null) {
					if (obj.id!="" && obj.style.display!="block") {
						obj.style.display="block";
					}
				}
				else break;
				obj1=eval("obj.parentElement");
			}
		}
}

function show_div(id_cur){
	var div_set=null;
	div_set=document.getElementById(id_cur);
	if (div_set!=null) {
		if (div_set.style.display=="block") div_set.style.display="none";
		else div_set.style.display="block";
	}
}

function show_div_metro(id_cur,chs){
	var div_set=null;
	div_set=document.getElementById(id_cur);
if (chs==1) div_set.style.display="none";
else {
	if (div_set!=null){
		
		div_set.style.display="block";
	}
}


}

CurCurse='1.0';
CurValuteFlag='0'; // 0 - не установлен, 1-доллары, 2-рубли.

function normalize(price)
{	var pr, str;
	price = parseFloat(price.toString().replace(",", "."));
	pr=parseInt(Math.round(price*100));
	str = new String(pr);
	pr="";
	if (str.length>2)
		pr += str.substring(0, str.length-2);
	else
		pr += "0";
	pr += ".";
	if (str.length>2)
		pr += str.substring(str.length-2, str.length);
	else
	{	if (str.length==1)
			pr += "0";
		pr += str;
	}
	return pr;
}


function price_alt(in_price,in_usd,in_rur){
	if (in_price=='' || (in_usd=='' && in_rur=='')) return;
	var normal_price=parseFloat("0"+in_price);
	if (in_usd!='') { document.write( normalize(normal_price*CurCurse)+" грн." ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
	if (in_rur!='') { document.write( normalize(normal_price/CurCurse)+" $" ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
}

function price_alt2(in_price){
	var normal_price=parseFloat("0"+in_price);
	if (CurValuteFlag=='1') { document.write( normalize(normal_price*CurCurse)+" грн." ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
	if (CurValuteFlag=='2') { document.write( normalize(normal_price/CurCurse)+" $" ); return; } // если цена товара в USD, то пересчитаем в рублях и отобразим альтернативную цену
}

function ico_img(graph)
{
	if (graph == '/i/null.gif') document.write('<img src="/i/ico_noimg.gif" width=30 height=30 border=0 alt="Изображение отсутствует">');
	else if (graph == '/i/noimage.gif') document.write('<img src="/i/ico_noimg.gif" width=30 height=30 border=0 alt="Изображение отсутствует">');
	else document.write('<img src="/i/ico_img.gif" width=30 height=30 border=0 alt="Описание с изображением">')
}

function CreateCookie(name,value,ex_date){
	var today=new Date();
	today.setDate(today.getDate()+ex_date);
	document.cookie=name+"="+value+"; expires="+today.toGMTString()+"; path=/;";
}

function CreateTmpCookie(name,value){
	document.cookie=name+"="+value+"; path=/;";
}

function RemoveCookie(name){
	CreateCookie(name,"",-1);
}

function ReadCookie(name){
	var tmpName=name+"=";
	if ((startName=atStr(tmpName,document.cookie))!=-1){
		var startVal=startName+tmpName.length;
		if ((endVal=document.cookie.indexOf(";",startVal))==-1) 
			endVal=document.cookie.length;
		return unescape(document.cookie.substring(startVal,endVal));
	}
	return null;
}

function atStr(sub,str){
	for (var i=0;i<=str.length-sub.length;i++) 
		if(str.substring(i,i+sub.length).toUpperCase()==sub.toUpperCase()) return i;
	return -1;
}

function SetCompare(obj,id_goods){
	if (!obj.checked) RemoveCookie("idg"+id_goods); else CreateTmpCookie("idg"+id_goods,id_goods);
}

function SpellCompare(obj){
	var str="";
	var start_IDG=0;
	var end_IDG=-1;
	var break_point=0;
	var flag;
	while (start_IDG!=-1){
		start_IDG=document.cookie.indexOf("idg",start_IDG);
		end_IDG=document.cookie.indexOf("=",start_IDG);
		if (start_IDG==-1 || end_IDG==-1) break;
		idg=unescape(document.cookie.substring(start_IDG+3,end_IDG));
		start_IDG=end_IDG;
		flag=false;
		//alert("idg="+idg+" , obj.idg.length="+obj.idg.length);
		if (isNaN(obj.idg.length)) { 
			if (obj.idg.value==idg) { obj.idg.checked=true; flag=true; }
		}
		else {
			for (i=0;i<obj.idg.length;i++) {
				if (obj.idg[i].value==idg) { obj.idg[i].checked=true; flag=true; break; }
			}
		}
		//alert("flag="+flag);
		if (!flag) { 
			//alert("!!! idg="+idg);
			str+="<input type=hidden name=idg value="+idg+">"
		}
		break_point++; if (break_point>10) break;
	}
	return str;
}

function SearchScroll(FileAction,pgsize,numpage,stype,str_url){
	var s1=new RegExp("pgsize=[^&]*&|pgsize=.*$", "gi");
	var s2=new RegExp("page=[^&]*&|page=.*$", "gi");
	var s3=new RegExp("stype=[^&]*&|stype=.*$", "gi");
	var str_url_r='';
	var ch='';
	var WWWWW=str_url;
	str_url=str_url.replace(s1,''); str_url=str_url.replace(s2,''); str_url=str_url.replace(s3,''); 
	for (i=0;i<str_url.length;i++) {
		ch=str_url.substr(i,1);
		if (ch!='=' && ch!='&' && ch!='%') str_url_r+=escape(ch);	else str_url_r+=ch;
	}
	if ( str_url_r.substr(str_url_r.length-1,1)=='&' ) str_url_r=str_url_r.substr(0,str_url_r.length-1);
	document.location = FileAction + '?c=search&pgsize=' + pgsize + '&page=' + numpage + '&stype=' + stype + '&' + str_url_r
}

function logoff(file_templ,idc,stype,page,idr,idt,idn,idg){
	RemoveCookie("login");
	RemoveCookie("pass");
	RemoveCookie("userid");
	document.location='/'+ file_templ +'?idc='+idc +'&stype='+stype +'&page='+page +'&idr='+idr +'&idt='+idt +'&idn='+idn +'&idg='+idg +'&ctype=showbask&r='+RND;
	//location.reload();
}

function ReadStatusOrder(val){
	var aStatus=val.split(";");
	for (i=0; i<aStatus.length-1; i++) {
		aVal=aStatus[i].split("=");
		document.write( " <br> " + aVal[0] + " : " + aVal[1]);
	}
}

function w_send(){
	document.write('<input type=hidden name=s_ch value=\"'+s_ch+'\"><input type=hidden name=s_cf value=\"'+s_cf+'\">');
}





function FIND(item){
	if( window.mmIsOpera ) return(document.getElementById(item));
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}




/* меню в шапке */
function beginTab(){
	if ( lengthTD == 0 )
		document.write("<table border=0 cellpadding=0 cellspacing=0><tr><td width=1 nowrap></td>");
}

function endTab(name){
	lengthTD = lengthTD + name.length + 100;
	if ( lengthTD > 790 ){
				document.write("</tr></table>");
				lengthTD = 0;
	}
}






// Установка даты
function strData(s){
if (s=='01')
 document.write(a.substring(0,2)+" января 20"+a.substring(6,8));
if (s=='02')
 document.write(a.substring(0,2)+" февраля 20"+a.substring(6,8));
if (s=='03')
 document.write(a.substring(0,2)+" марта 20"+a.substring(6,8));
if (s=='04')
 document.write(a.substring(0,2)+" апреля 20"+a.substring(6,8));
if (s=='05')
 document.write(a.substring(0,2)+" мая 20"+a.substring(6,8));
if (s=='06')
 document.write(a.substring(0,2)+" июня 20"+a.substring(6,8));
if (s=='07')
 document.write(a.substring(0,2)+" июля 20"+a.substring(6,8));
if (s=='08')
 document.write(a.substring(0,2)+" августа 20"+a.substring(6,8));
if (s=='09')
 document.write(a.substring(0,2)+" сентября 20"+a.substring(6,8));
if (s=='10')
 document.write(a.substring(0,2)+" октября 20"+a.substring(6,8));
if (s=='11')
 document.write(a.substring(0,2)+" ноября 20"+a.substring(6,8));
if (s=='12')
 document.write(a.substring(0,2)+" декабря 20"+a.substring(6,8));
}



// Проверка картинки
function hideImg(img){
	if ( img == "" )
		document.write("<div style='display: none; visibility: hidden;'>");
}

function hideImg1(img){
	if ( img == "" )
		document.write("</div>");
}

function hideImg2(img){
	if ( img != "" )
		document.write('<td><img src="'+img+'" border=0 width=134 class=imgN></td><td>');
	else
		document.write("<td colspan=2>");
}

function hideImg3(img){
	if ( img == "" )
		document.write("<div style='display: none; visibility: hidden;'>");
	else
		document.write("<div class=lineDefLeft></div><div class=bunDefLeft>");
}



// для новостей
function show_news(id){
	var obj = FIND(id);
	if ( obj != null ){
			if ( obj.style.display == "block" || obj.style.visibility == "visible" ){
				obj.style.display = "none";
				obj.style.visibility = "hidden";
			}
			else{
				obj.style.display = "block";
				obj.style.visibility = "visible";
			}
	}
}



///////////////////////////////////////////////////////////////////////// Для расш. св.
function changeClassEL(c,n){
	var obj;
	var obj1;
	var i = 0;

	for ( i=0; i<n; i++ ){
			obj = FIND("tdEL"+i);
			if ( obj != null ){
					if ( c == true ){
						obj.className = "tdELO";
						obj = FIND("extV"+i);
						obj1 = FIND("valEL"+i);
						if ( obj != null && obj1 != null )
							obj.value = obj1.value;
					}
					else{
						obj.className = "tdEL";
						obj = FIND("extV"+i);
						if ( obj != null )
							obj.value = "";
					}
			}
	}
}

//////////////////////////////////////////////////////// смена класса /////////////////////////////////////////////////////////////
function changeClass(id,level){
	var ob = document.getElementById("class"+id);
	var name = "cat"+level;
	if ( ob != null ){
			if ( ob.className != "catact" ){
						if ( ob.className == name )
							ob.className = name +"_over";
						else
							ob.className = name;
			}
	}
	ob = document.getElementById("act"+id);
	if ( ob != null )
		ob.className = "subcatact";
}

function RemoveInSelect(p,v){
	for (i=0; i < p.options.length; i++) {
		if (p.options[i].value==v)
		{	p.remove(i); break;
		}
	}
}

function RemoveAllInSelect(p){
	p.length=0;
	//while (p.options.length>0)
		//p.remove(0);
}

function AddInSelect(oSelect,MyValue,MyText){
	if (oSelect==null)
		return;
	//var oOption = document.createElement("OPTION");
	//oOption.innerText = MyText;
	//oOption.value = MyValue;
	//oSelect.options.add(oOption);// : 
	oSelect.options[oSelect.length] = new Option(MyText, MyValue);
	//oSelect.add(oOption, null);
	//alert(MyValue+' : '+MyText);
	//oSelect.options.add(new Option(MyText,MyValue));
}

function ShippingItemObj(ID, Name, Price)
{
	this.ID = ID;
	this.Name = Name;
	this.Price = Price;
}

function beginTab2(val,a,id){
	if ( lengthTD == 0 )
		document.write("<table border=0 height=25 cellpadding=0 cellspacing=0 class=tabEL width=100%><tr>");

	document.write("<input type=hidden value='"+val+"' id='valEL"+a+"'>");
	document.write("<td id='tdEL"+a+"' class=tdEL onClick=' document.searche.all.checked=false; if ( this.className == \"tdEL\" ){ this.className = \"tdELO\"; this.childNodes[0].value=\""+val+"\"; } else{ this.className = \"tdEL\"; this.childNodes[0].value=\"\"; } '><input type=hidden name='ext"+id+"' value='"+val+"' id='extV"+a+"'>");

}

function endTab2(val,l){
	lengthTD = l + val.length + 100;
	if ( lengthTD > 790 ){
		document.write("<td>&nbsp;</td></tr></table>");
		lengthTD = 0;
	}
a++;
}


function writeInput(n,val,id){
	var s = ReadCookie(id+"_"+val);
	if ( s == null || s == "" ){
		s = ReadCookie(id+"_vse");
		if ( s == null || s == "" )
			document.write("<input type=checkbox name='ext"+id+"' value='"+val+"' id='"+id+"inp"+n+"' onClick=' changeAll("+id+",this,\""+val+"\"); '> &nbsp;");
		else{
			document.write("<input type=checkbox checked name='ext"+id+"' value='"+val+"' id='"+id+"inp"+n+"' onClick=' changeAll("+id+",this,\""+val+"\"); '> &nbsp;");
			CreateTmpCookie(id+"_"+val,val);
		}
	}
	else{
		document.write("<input type=checkbox checked name='ext"+id+"' value='"+val+"' id='"+id+"inp"+n+"' onClick=' changeAll("+id+",this,\""+val+"\"); '> &nbsp;");
		CreateTmpCookie(id+"_"+val,val);
	}
	t++;
}

function changeAll(id,ob,val){
	var obj = FIND("all"+id);
	if ( obj != null )
		obj.checked = false;
	if ( ob.checked == true )
		CreateTmpCookie(id+"_"+val,val);
	else{
		RemoveCookie(id+"_"+val);
		RemoveCookie(id+"_vse");
	}
}
function changeCheckInp(flag,id,n){

	var s = new Array();
	var s1 = new Array();
	var str="";

	if ( flag == true)
		CreateTmpCookie(id+"_vse","vse");
	else
		RemoveCookie(id+"_vse");

	var obj = null;
	for ( var i=0; i< n; i++ ){
			obj = FIND(id+"inp"+i);
			if ( obj != null ){
					if ( flag == true)
						obj.checked = true;
					else{
						obj.checked = false;
						s = document.cookie.split(";");
						for ( var j = 0; j < s.length; j++ ){
										s1 = s[j].split(id+"_");
										if ( s1.length > 1 ){
												s1 = s[j].split("=");
												RemoveCookie(s1[0]);
										}
						}
					}
			}
	}
}



/////////////// Сопутствующие товары

function beginTab3(n){
	if ( n == -2 )
		document.write("<tr valign=top><td width=50% class=assocLI>");
	if ( n == 0 )
		document.write("<tr valign=top><td width=50% class=assocL>");
}

function endTab3(n){
	if ( n == -2 )
		document.write("</td><td width=50% class=assocRI>");
	if ( n == 0 )
		document.write("</td><td width=50% class=assocR>");
	if ( n == -1 )
		document.write("</td></tr>");
	if ( n == 1 ){
		document.write("</td></tr>");
		a = -1;
	}
	a++;
}
function endTab4(n){
	if ( n == -1 )
		document.write("&nbsp;</td></tr>");
	if ( n == 1 )
		document.write("&nbsp;</td></tr>");
}

function EndOrder_OnSubmit()
{
	var obj_form = document.getElementById("endorder");

	if (obj_form!=null)
	{
		if (obj_form.paymode.value==0)
		{
			alert("Необходимо выбрать способ оплаты")
			return false;
		}
		if (obj_form.shippmode.value==0)
		{
			alert("Необходимо выбрать способ доставки и рассчитать стоимость")
			return false;
		}
		if (obj_form.delivery_comment.value!="") {
			var p=obj_form.paymode;
			var res="";
			for (i=0; i < p.length; i++) {
				if (p[i].selected) { res="\r\nСпособ оплаты: "+p[i].text; break; }
			}
			obj_form.ordercomment.value = obj_form.ordercomment.value + obj_form.delivery_comment.value + res;
		}
		return true;
	}

}

function combine_address(obj2) {
	var comm='';
	if (obj2.shipping_city.value!='') comm=comm+obj2.shipping_city.value+'\; ';
	if (obj2.shipping_index.value!='') comm=comm+obj2.shipping_index.value+'\; ';
	if (obj2.shipping_address.value!='') comm=comm+obj2.shipping_address.value+'\; ';
	if (obj2.shipping_fio.value!='') comm=comm+obj2.shipping_fio.value+'\; ';
	if (obj2.ordercomment!=NULL) obj2.ordercomment.value=comm;
// alert(obj2.ordercomment.value);
}








/******************* Скрипт для подгруженя картинки в слой Предварительно просмотра картинки **************/
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[-650,-700]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.

var defaultimageheight = 10;	// maximum image size.
var defaultimagewidth = 25;	// maximum image size.

var timer;

function gettrailobj(){
	if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
}

function showtrail(imagename,title,width,height){
	i = imagename;
	t = title;
	w = width;
	h = height;
	timer = setTimeout("show('"+i+"',t,w,h);",200);
}
function show(imagename,title,width,height){
 
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>650 && docheight>500)) {
		( width == 0 ) ? width = defaultimagewidth: '';
		( height == 0 ) ? height = defaultimageheight: '';
			
		width+=30
		height+=55
		defaultimageheight = height
		defaultimagewidth = width
	

		newHTML = '<div class="border_preview" style="width:5px; height:5px; top: '+document.body.scrollTop+'px;"><div id="loader_container"><div id="loader"><div align="center">Загрузка изображения...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
    	newHTML = newHTML + '<div class="preview_temp_load"><img onclick="javascript: hidetrail()" onload="javascript:remove_loading();" src="' + imagename + '"></div>';
		newHTML = newHTML + '<p align="center" class="sxem" onclick="hidetrail()" style="margin: 5px 0 5px 80%; font: normal 12px Tahoma; float: right;">Закрыть Окно</p>'
		newHTML = newHTML + '</div>'; 

		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}



/*** Блок "Загрузка изображения" ***/
var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}

function headbottom() {
	var ranNum= Math.floor(Math.random()*4)+1;
	var left_img = document.getElementById('head_left_img');
	var right_img = document.getElementById('head_right_img');
	left_img.style.background = "background-image: url(/images/head_bot_left"+ranNum+".jpg)";
	right_img.style.background = "background-image: url(/images/head_bot_right"+ranNum+".jpg)";
}

function hideneedless(quan,line) {

quan=quan*1;
if (quan>0) document.write(line);

}

function ShowStatus (Quantity, Status)
{
	var st="???";
	if (Status==2)
		st = "<img src=/i/not.gif alt='Нет в наличии'>";
	else
	{
		if (Quantity>0)
			st = "<img src=/i/is.gif alt='В наличии'>";
		else
			st = "<img src=/i/preord.jpg alt='Ожидается или под заказ'>";
	}
	document.write(st);
}
function ShowStatus2 (Quantity, Status)
{
	var st="???";
	if (Status==2)
		st = "<img src=/i/not.gif alt='Нет в наличии'>";
	else
	{
		if (Quantity>0)
			st = "<img src=/i/nal.jpg width='83' height='28' hspace='2' alt='В наличии'>";
		else
			st = "<img src=/i/zakaz.jpg width='83' height='28' hspace='2' alt='Ожидается или под заказ'>";
	}
	document.write(st);
}
function ShowStatus3 (Quantity, Status)
{
	var st="???";
	if (Status==2)
		st = "<img src=/i/not.gif alt='Нет в наличии'>";
	else
	{
		if (Quantity>0)
			st = "В наличии";
		else
			st = "Под заказ";
	}
	document.write(st);
}

// получение названия статуса по ValueID для свойства FieldID=28 (см. табличку FieldsValuesDictionary)
function GetStatusNameByValueID(ValueID)
{
	var st="???";
	if (ValueID==193)
		st = "В наличии";
	else if (ValueID==194)
		st = "Под заказ";
	else if (ValueID==195)
		st = "Не ожидается";
	else if (ValueID==196)
		st = "Ожидается";
	else if (ValueID==867)
		st = "Нет";
	return st;
}

function roundprice(price){

if (price!='&nbsp;')
	{
	price=Math.ceil(price)
	xs=price+'';
	enter_space(xs);
	}
else
	{
document.write('По запросу');	
	}
}
function enter_space(text) {

var x=1;
var xx=0;
var buf='';
var xbuf=''; //выход цена

for (i=text.length; i>0; i--)
	{
	buf=buf+text.substring(i-1,i);
	if(x==3+xx) {buf=buf+' '; x=1; xx=xx+1;}
	x=x+1;
	}

for (i=buf.length; i>0; i--)
	{
	xbuf=xbuf+buf.substring(i-1,i);
	}

document.write(xbuf);
}

function v_price(p,p1){
if (p!=p1) document.write("<STRIKE>"+p1+"</STRIKE>") // или price1 там надо перечеркнуть?
else document.write(p1);
}

function insertstatimage(str) {
var truewords = ["В наличии", "Под заказ", "Ожидается","Нет","Предзаказ"];
var foundwords = new Array();

for (i=0; i<5.; i++) {

	foundwords[i] = str.indexOf(truewords[i], 0);

}

if (foundwords[0]!='-1') document.write('<img src="/i/buttons/nal.jpg" border=0>');
else if (foundwords[2]!='-1' && foundwords[0]=='-1') document.write('<img src="/i/buttons/ozh.jpg" border=0>');
else if (foundwords[1]!='-1' && foundwords[0]=='-1' && foundwords[2]=='-1') document.write('<img src="/i/buttons/zakaz.jpg" border=0>');
else if (foundwords[4]!='-1' && foundwords[0]=='-1' && foundwords[1]=='-1' && foundwords[2]=='-1') document.write('<img src="/i/buttons/preorder.jpg" border=0>');
else if (foundwords[3]!='-1' && foundwords[4]=='-1' && foundwords[0]=='-1' && foundwords[1]=='-1' && foundwords[2]=='-1') document.write('<img src="/i/buttons/no.jpg" border=0>');


}
function showhidebig(obj,act) {
var ob = document.getElementById(obj);

if (act=='show') {
	
	if (ob.style.display!='block') ob.style.display='block';
	
	}
if (act=='hide') {
	
	if (ob.style.display!='none') ob.style.display='none';
	
	}

}