var RND=parseInt(Math.random()*100000);
var weight=0;
var index=0;
var IsIE = (window.navigator.appName.toLowerCase().indexOf('microsoft')!=-1)?true:false;


var assocarray = new Array(); //массив сопов
var dindex=0; // индекс массива

function add_assocarray(idgood,idcat,name,graph2,expired,price,test) {
			
			assocarray[dindex] = new Array(6);
			assocarray[dindex][0]=idgood;
			assocarray[dindex][1]=idcat;
			assocarray[dindex][2]=name;
			assocarray[dindex][3]=graph2;
			assocarray[dindex][4]=expired;
			assocarray[dindex][5]=price;
			dindex=dindex+1;


}

function assoc_show(id) {
if (dindex>0) {
numcol=1;
for (var i=0; i<=dindex; i++) {

price=Math.ceil(assocarray[i][5]);
if (numcol==1) document.write('<tr>');
//if (assocarray[i][0]==id) {
x='';
x='<td><div class="book" style="float: left; border: 2px solid #b69a62; border-left: none; margin: 0 11px 0 0; position: relative; padding-left: 7px; background: url(/i/book_fon.gif) repeat-y;">';
x=x+'<img width=60 src="/linkpics/'+assocarray[i][3]+'"><div class="book_top">&nbsp;</div></div><div class="autr">Автор <b>'+assocarray[i][4]+'</b></div>'+assocarray[i][2]+'';
x=x+'<div style="clear: left"></div><div class="spec_1_content"><div class="price">';
x=x+'<script>roundprice(\''+price+'\');</script> руб. <div class="price_l_t">&nbsp;</div><div class="price_r_t rpx">&nbsp;</div>';
x=x+'<div class="price_l_b">&nbsp;</div><div class="price_r_b rpx">&nbsp;</div>';
x=x+'</div><div class="buy"><input id="q'+assocarray[i][0]+'" type="text" value="1">	<span>шт.</span>';
x=x+'<a href="javascript: add_bask_ext2(\''+assocarray[i][1]+'\',\''+assocarray[i][0]+'\')"><img src=\'/i/in_bask.gif\' alt=\'Добавить в корзину\'></a>';
x=x+'</div></div></td>';
document.write(x);

if (numcol==2) document.write('</tr><tr><td class="catalogr" colspan="2"  height="1" style="margin: 0; padding: 0;"></td></tr>');


if (numcol==2) numcol=1;
else numcol=2;

if (numcol==2&&i==dindex-1) document.write('<td>&nbsp;</td>');



//}

}
}
}

function clear_emtpy(form) {

if (form.sexpired.value=='Автор') {

form.sexpired.value='';

}
if (form.searchword.value=='или название книги') form.searchword.value='';

}





function add_bask_ext(idcat,idgoo){
fd=idgoo+'';
fq="&quan"+fd;
forfop="q"+fd;
fop=document.getElementById(forfop);
show_win(500,200,"/basket_add.html?c=addbask&ctype=showbask&idc="+idcat+"&idg="+idgoo+fq+"="+fop.value);	
//show_win(500,200,"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"&"+f+"="+quan);	
}

function add_bask_ext2(idcat,idgoo){
fd=idgoo+'';
fq="&quan"+fd;
forfop="q"+fd;
fop=document.getElementById(forfop);
show_win(500,200,"/basket_add2.html?c=addbask&ctype=showbask&idc="+idcat+"&idg="+idgoo+fq+"="+fop.value);	
//show_win(500,200,"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"&"+f+"="+quan);	
}

function be_cur(id){

var a = document.getElementById(id);
a.style.fontWeight="Bold";
a.style.width="200px";
a.style.textDecoration="None";
}


function roundprice(price){
price=Math.ceil(price);

xs=price+'';
document.write(xs);
}
function retroundprice(price){
price=Math.ceil(price)

xs=price+'';
return xs;
}

function subthis(idform)
{

 obj = document.getElementById(idform); 
 obj.submit(); 

}

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_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/in_bask.gif></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_p_ul(id_cur_rub) {
	var x=null; 1
	var y=null;
	
	if (document.getElementById(id_cur_rub)!=null) {
		x=document.getElementById(id_cur_rub);
		x.className='cur_rub_cat';
		for (var i=0; i<10; i++) {
			y=x;
			if (y!=null) {
				if (y.id!="" && y.style.display!="block") {
					y.style.display="block";
					x=y.parentNode;
				}
			} else break;
				if (y.firstChild.className=="plus") {
					y.firstChild.className="minus";
				}
				x=y.parentNode;
		}
	}
}



function show_parent_div(div_par,mainid){
    
		var x=null; 
		var y=null;
		var last=null;
    if (document.getElementById(div_par)!=null)
    {
	
			x=document.getElementById(div_par);
			zmain=document.getElementById('link'+mainid);
			
			if (zmain!=null) zmain.style.backgroundPosition='0 -68px';
			
			for(var i=0; i<10; i++) {
			
				y=x;
				if (y!=null) {
					if (y.id!="" && y.style.display!="block") {
						y.style.display="block";
					}
					last=y;
				}
				else {
				
				break;
				
				}
				if (IsIE) x=eval("y.parentElement");
				else x=eval("y.parentNode");
				
				x=y.parentNode;
			}
		}
}



function show_div_0(id_cur,id){
	var div_set=null;
	div_set=document.getElementById(id_cur);
	sidc=document.getElementById('sidcel');
	sidc.value=id;
	
	x='link'+id;
	div_set_a=document.getElementById(x);
	
	if (div_set!=null) {
		if (div_set.style.display=="block") 
		{
		div_set.style.display="none";
		div_set_a.style.backgroundPosition='0 0';
		}
		else {
		div_set.style.display="block";
		div_set_a.style.backgroundPosition='0 -68px';
		}
	}
}



function show_div(id_cur,id){
	var div_set=null;
	div_set=document.getElementById(id_cur);
	sidc=document.getElementById('sidcel');
	sidc.value=id;
	
	if (div_set!=null) {
		if (div_set.style.display=="block") div_set.style.display="none";
		else div_set.style.display="block";
	}
}

function show_div_no(id_cur){
	var div_set=null;
	
	x='link'+id_cur.substring(3);
	div_set_a=document.getElementById(x);
	
	div_set=document.getElementById(id_cur);

	if (div_set!=null) {
		if (div_set.style.display=="block") 
		{
		div_set.style.display="none";
		div_set_a.style.backgroundPosition='0 0';
		}
		else {
		div_set.style.display="block";
		div_set_a.style.backgroundPosition='0 -68px';
		}
	}
}

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+'\">');
}