var RND=parseInt(Math.random()*100000);
var weight=0;
var index=0;
var IsIE = (window.navigator.appName.toLowerCase().indexOf('microsoft')!=-1)?true:false;



function ShowDiv(obj,obj2,url){
	
	

	
	var div = document.getElementById(obj);
	
	
	if (url != '1' )
	{
		
		var gh = document.getElementById(obj2);
		gh.src = url;
		div.style.display = "block";
		
		var hi = gh.offsetHeight;
		hi = '-'+hi+'px';
		div.style.bottom=hi;
	}
	else
	{
	div.style.display = "none";
	}
}




var reg1 = new Array(); // массив 1
var setcity = '';
var setmetro = '';


function showcpecimg(im) {
var j=0;
if (im==5) { document.write("<img class=immarg src=/specimg/ixbt_small.png>"); j=1; }
	else if (im==4) { document.write("<img class=immarg src=/specimg/robik_small.png>"); j=1; }
		else if (im==6) { document.write("<img class=immarg src=/specimg/spec4_small.png>"); j=1; }
			else if (im==1) { document.write("<img class=immarg src=/specimg/demping_small.png>"); j=1; }
				else if (im==2) { document.write("<img class=immarg src=/specimg/new2_small.png>"); j=1; }
					else if (im==3) { document.write("<img class=immarg src=/specimg/hit_small.png>"); j=1; }
						else if (im==7) { document.write("<img class=immarg src=/specimg/dzhek_small.png>"); j=1; }
							else if (im==8) { document.write("<img class=immarg src=/specimg/nodrink_small.png>"); j=1; }
						
}

function showcpecimgbig(im) {
var j=0;
if (im=='5') { document.write("<img class=immarg src=/specimg/ixbt_big.png>"); j=1; }
	else if (im=='4') { document.write("<img class=immarg src=/specimg/robik_big.png>"); j=1; }
		else if (im=='6') { document.write("<img class=immarg src=/specimg/spec4_big.png>"); j=1; }
			else if (im=='1') { document.write("<img class=immarg src=/specimg/demping_big.png>"); j=1; }
				else if (im=='2') { document.write("<img class=immarg src=/specimg/new2_big.png>"); j=1; }
					else if (im=='3') { document.write("<img class=immarg src=/specimg/hit_big.png>"); j=1; }
						else if (im=='7') { document.write("<img class=immarg src=/specimg/dzhek_big.png>"); j=1; }
							else if (im=='8') { document.write("<img class=immarg src=/specimg/nodrink_big.png>"); j=1; }
}



function add_item(name,idpar,level,id,url,annt) {
	//заполняем массив
	len = reg1.length;
	reg1[len] = new Array();
	reg1[len][0] = name;
	reg1[len][1] = idpar;
	reg1[len][2] = level;
	reg1[len][3] = id;
	reg1[len][4] = url;
	reg1[len][5] = annt;

	if (annt=='1')	{
		if (reg1[len][2]=='2') setcity = id+'!';
		if (reg1[len][2]=='3') setmetro = id+'!';
		
	}	
}


function write_select() {
len = reg1.length; // кол-во строк в массиве
var country = document.getElementById('cntry');
// добавляем в первый и
		for (i=1; i<len; i++) {

			if (reg1[i][2]=='1') {
				if (document.createElement){
					var newOption = document.createElement("OPTION");
					newOption.text = reg1[i][0];
					newOption.value = reg1[i][3]+'!'+reg1[i][4];
					if (reg1[i][5]=='1') newOption.selected='true';
					
					(country.options.add) ? country.options.add(newOption) :country.add(newOption, null);
				}	
			}
		}




}



function selectcountry(ind) {
var country = document.getElementById('cntry');
var city = document.getElementById('cty');
var rayon = document.getElementById('rayon');
var ind = country.options[ind].value; // получаем id  по которому нужно фильтровать массив




ind = ind.split('!');

if (ind[1]=='') {

	if (ind[0]!='' && ind[0]!=0 && ind[0]!='null') {
		len = reg1.length; // кол-во строк в массиве
		city.length = 0;	
		rayon.length = 1;		
				if (document.createElement){
					var newOption = document.createElement("OPTION");
					newOption.text = 'Не выбрано';
					newOption.value = 'null!';
					
					(city.options.add) ? city.options.add(newOption) :city.add(newOption, null);
				}			
		
		
		
		for (i=1; i<len; i++) {

			if (reg1[i][1]==ind[0]) {
				if (document.createElement){
					var newOption = document.createElement("OPTION");			
					newOption.text = reg1[i][0];
					newOption.value = reg1[i][3]+'!'+reg1[i][4];
					if (reg1[i][5]=='1') newOption.selected='selected';
					(city.options.add) ? city.options.add(newOption) :city.add(newOption, null);
				}	
			}
		}		
		

	}

	else {
		// обнуляем второй и третий списки
		city.length = 1;
		rayon.length = 1;		
	}
}

else location.replace(ind[1]); // фигачим тут релод


}



function selectcity(ind) {
var country = document.getElementById('cntry');
var city = document.getElementById('cty');
var rayon = document.getElementById('rayon');

var ind = city.options[ind].value; // получаем id  по которому нужно фильтровать массив

ind = ind.split('!');



if (ind[1]=='') {

	if (ind[0]!='' && ind[0]!=0 && ind[0]!='null') {
		len = reg1.length; // кол-во строк в массиве
		rayon.length = 0;	
				if (document.createElement){
					var newOption = document.createElement("OPTION");
					newOption.text = 'Не выбрано';
					newOption.value = 'null!';
					(rayon.options.add) ? rayon.options.add(newOption) :rayon.add(newOption, null);
				}	

		
		for (i=1; i<len; i++) {

			if (reg1[i][1]==ind[0]) {
				if (document.createElement){
					var newOption = document.createElement("OPTION");			
					newOption.text = reg1[i][0];
					newOption.value = reg1[i][3]+'!'+reg1[i][4];
					if (reg1[i][5]=='1') newOption.selected='selected';
					(rayon.options.add) ? rayon.options.add(newOption) :rayon.add(newOption, null);
				}	
			}
		}		
		

	}

	else {
		// обнуляем второй и третий списки
		rayon.length = 1;	
	}
}
else location.replace(ind[1]);



}


function selectmetro(ind) {

var rayon = document.getElementById('rayon');
var ind = rayon.options[ind].value; // получаем id  по которому нужно фильтровать массив
ind = ind.split('!');
if (ind[1].length!=0) location.replace(ind[1]);

}








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';
	
	}

}


function up_val (doit,objt)
{
var inpt = document.getElementById(objt);

var x = eval(inpt.value);

if (doit=='+') inpt.value = x+1;

if (doit=='-')
	{
		if (eval(inpt.value)-1<0) {}
		else  inpt.value = x-1;

	}


}

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=19 height=16 hspace=4 border=0 alt='в канистру' align=absmiddle></a>");
}

//------------------------------------------------------------------------------------добавление в корзину товаров
function add_ext_bask_img(idcat,idgoods){
	document.write("<a href='javascript: send_to_bask("+idcat+","+idgoods+");'><img src='/i/basket.gif' width=19 height=16 hspace=4 border=0 alt='в канистру' align=absmiddle></a>");
}

function send_to_bask(idcat,idgoods){
var quan=document.getElementById("inquan"+idgoods).value;
var spn=document.getElementById("commt"+idgoods);
show_win(500,200,"/basket_add.html?quan"+idgoods+"="+quan+"&idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND);
if (eval(quan)<0) quan = 0;
spn.innerHTML = "В канистре: "+quan+" шт.";
}
//------------------------------------------------------------------------------------



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+"\")' class=abasket><img src='/i/kanistra.gif' border=0 width=98 height=28></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+"\")'>в канистру</a> ]");
//}

function set_selected(p,v){
	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;
				if (IsIE) obj1=eval("obj.parentElement");
				else obj1=eval("obj.parentNode");
			}
		}
}

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";
	}
}

CurCurse='1.0';
CurValuteFlag='0'; // 0 - не установлен, 1-доллары, 2-рубли.

function normalize(price)
{	var pr, str;
	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;
	var IsNetscape=(window.navigator.appName.toLowerCase().indexOf('netscape')!=-1)?true:false;

	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!='%' && !IsNetscape) 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 +'&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+'\">');
}
