var RND=parseInt(Math.random()*100000);

var weight=0;
var index=0;




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_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 add_bask2(idc,arr){

	var flag = 0;

	var ob = null;

	var newurl='/basket_add.html?idc='+idc+'&c=addbask&ctype=showbask';

	for ( var i=0; i < arr.length; i++ ){

					ob = document.getElementById(arr[i]);



					if ( ob != null && parseInt(ob.value) > 0 ){

						newurl+='&idg='+arr[i]+'&quan'+arr[i]+'='+ob.value;

						flag=1;

					}

	}

	if ( flag == 1 )

		show_win(500,200,newurl);

	else

		alert("Вы не указали количество.");

}





////////////////////////////////////////

















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;

				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";

	}

}



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;

	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 +'&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 MenuSet(ID_DivChild,Obj,level){

	if ( Obj.contains(window.event.fromElement)==true ) return;

	if (ID_DivChild!="" && Obj!=null) {

			this.DivHideAll();

			this.DivShow(ID_DivChild,ID_DivChild,Obj,level);

	}

}//end function



function MenuFree(){

	this.DivTimeoutHide=null;

	this.DivHideAll();

}//end function



function DivAdd(idDiv){

	var i=this.ArrayDiv.length;

	this.ArrayDiv[i]=idDiv;

}//end function



function DivHideAll() {

	this.DivCurrentSet="";

	var objDiv;

	var obj_search_form=null;

	for (var i=0; i<this.ArrayDiv.length; i++) {

		if (document.getElementById(this.ArrayDiv[i])!=null) document.all[this.ArrayDiv[i]].style.visibility="hidden";

	}

	obj_search_form=document.getElementById("search_form"); 

	if (obj_search_form!=null) obj_search_form.style.visibility="visible";







}//end function



function DivShow(ID_DivCurrent,ID_DivParent,Obj,level){

	var parent_obj;

	var obj_search_form=null;

	if ( !Obj.contains(window.event.toElement) || Obj.contains(window.event.fromElement) ) return; // это правильно

	

	obj_search_form=document.getElementById("search_form"); 

	if (obj_search_form!=null) obj_search_form.style.visibility="hidden";



	if ( level > 0 )

	Obj.style.background="#8c97b7";

	if (this.DivTimeoutHide!=null) {	clearTimeout(this.DivTimeoutHide); this.DivTimeoutHide=null; }

	if (this.DivCurrentSet!="" && ""+this.DivCurrentSet!=""+ID_DivCurrent && ""+this.DivCurrentSet!=""+ID_DivParent && document.getElementById(this.DivCurrentSet)!=null) {

		document.all[this.DivCurrentSet].style.visibility="hidden"; // скрыли текущий слой

	}

	if (document.getElementById(ID_DivCurrent)!=null) { 

		this.DivCurrentSet=ID_DivCurrent;

		document.all[ID_DivCurrent].style.visibility="visible";

	}

}//end function



//-------------------------------------- Дополнительные функции

function DivV(obj) { 

	if ( obj.contains(window.event.toElement)==true ) {	this.DivTimeoutHide=null; obj.style.visibility="visible";	}

}//end function



function MenuObj(ClassName){ 

	this.ClassName=ClassName;

	this.length=0;

	this.MenuSet=MenuSet;

	this.MenuFree=MenuFree;

	this.DivTimeoutHide=null;

	this.ArrayDiv = new Array();

	this.DivCurrentSet="";

	this.DivAdd=DivAdd;

	this.DivHideAll=DivHideAll;

	this.DivShow=DivShow;

	this.DivV=DivV;

}//end class



function r_color(obj,level) {

	if ( !obj.contains(window.event.toElement) && obj.contains(window.event.fromElement) ){

	if ( level>0 )

	obj.style.background="#576079";

}

}//end function



var MCat =  new MenuObj("MCat");





function changeClass(ug1,cat,ug2){



	var ob = document.getElementById(ug1);

	if ( ob != null ){

			if ( ob.className == 'ug1' )

					ob.className = "ug1over";

			else

					ob.className = "ug1";

	}

	ob = document.getElementById(cat);

	if ( ob != null ){

			if ( ob.className == 'cat' )

					ob.className = "catover";

			else

					ob.className = "cat";

	}

	ob = document.getElementById(ug2);

	if ( ob != null ){

			if ( ob.className == 'ug2' )

					ob.className = "ug2over";

			else

					ob.className = "ug2";

	}



}







function changeClassRight(ug1,cat,ug2){



	var ob = document.getElementById(ug1);

	if ( ob != null ){

			if ( ob.className == 'ug1' )

					ob.className = "ug1over";

			else

					ob.className = "ug1";

	}

	ob = document.getElementById(cat);

	if ( ob != null ){

			if ( ob.className == 'right' )

					ob.className = "rightover";

			else

					ob.className = "right";

	}

	ob = document.getElementById(ug2);

	if ( ob != null ){

			if ( ob.className == 'ug2' )

					ob.className = "ug2over";

			else

					ob.className = "ug2";

	}



}















/////////////////////////////// триады

function triada(n){

	var a = new Array();

	a = n.split(".");

	var j=0;

	var tri="";

	for ( var i = a[0].length-1; i >=0 ; i-- ){

					tri += a[0].charAt(i);

					if ( j == 2 && i >=1 ){

						tri += ",";

						j = -1;

					}

					j++;

	}

	n="";

	for ( var i = tri.length-1; i >=0 ; i-- ){

					n += tri.charAt(i);

	}

	n += "."+a[1];



	document.write(n);

}





function show_p4(v_price,valute){

	if (v_price!='&nbsp;' && v_price!='')

		document.write('<div style="clear:both; font-size:14px; color:black; position:relative; font-family: Tahoma; font-weight: bold; margin: 5px 0 10px 0;"><div style="position:absolute; border-top:2px solid red; top:8; left:0; width:85;"></div>'+v_price+' '+valute+'</div>')

}

