var AutoCreateCfgFlag=false;
var CurValuteName=''; // инициализируется вызовом из head.inc в функции Set_Check_And_Config
var CurValuteFlag='0'; // 0 - не установлен, 1-доллары, 2-рубли.
var	IDValute=CurValuteFlag;
var	DollarRateValueMax=1; // курс пересчета
var	CurCurse=DollarRateValueMax;
var scroll_pgn_num=1; // нумерация страниц для форумов
var	s_ch='';
var	s_cf='';
var RND=parseInt(Math.random()*100000);
var weight=0;
var index=0;
var IsIE = (window.navigator.appName.toLowerCase().indexOf('microsoft')!=-1)?true:false;
var IE_Ver = (window.navigator.appVersion.toLowerCase().indexOf('msie 7')!=-1)?7:6;

var SearchURL="" // используется для установки страницы поиска, т.к. шаблон поиска может использоваться в catalog.html
// *** ПОДСВЕЧИВАНИЕ ТЕКУЩЕГО ПУТИ В РУБРИКАТОРЕ СЛЕВА ***
// при желании можно сделать так, что бы выбранные рубрики в классификаторе слева от текущей до главной показывались другим цветом, для этого нужно переопределить цвета следующих переменных:
var cat_cur_color="#0095d9";
var cat_cur_bgcolor="";


function show_img(title,width,height,s_url){
	var imgnwin=window.open("","imgswin","resizable=yes,scrollbars=yes,toolbar=no,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height);
	imgnwin.document.write("<html><title>"+title+"</title><body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><center><img src='"+s_url+"' border=0></center></body></html>")
}

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:void(0);' onclick='fr_bask.document.location=\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\";document.getElementById(\"fr_bask_id\").style.display=\"block\";'><img src='/i/bask_goods.gif' width='18' height='14' border=0 alt='в корзину' align='absmiddle' class='g_bask_img'></a>");
}

function add_bask_img_text(idcat,idgoods){
	document.write("<a href='javascript:void(0);' onclick='fr_bask.document.location=\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\";document.getElementById(\"fr_bask_id\").style.display=\"block\";' class=bask_img_text><img src='/i/bask_goods.gif' width='18' height='14' border=0 alt='в корзину' align='absmiddle' class='g_bask_img'> в корзину</a>");
}

function add_bask_text(idcat,idgoods){
	document.write("<a href='javascript:void(0);' onclick='fr_bask.document.location=\"/basket_add.html?idc="+idcat+"&idg="+idgoods+"&c=addbask&ctype=showbask&r="+RND+"\";document.getElementById(\"fr_bask_id\").style.display=\"block\";' class=bask_img_text>выбрать в заказ</a>");
}

function bask_quan(f_quan,v_num){
	var v = parseInt(document.fbasket[f_quan].value);
	v+=v_num;
	if (v<=0) v=1;
	document.fbasket[f_quan].value=v;
}

function n_link(idr,idt,idn,actpage){
	document.write("<a href='/ncd-"+idr+"-"+idt+"-"+idn+"/"+actpage+"' class=bask_img_text><img src='/i/ic_link.gif' border=0 align=absmiddle class=ic_link> подробнее</a>");
}

var img_main=""
function r_link(idc,img_cat){
	if ((img_cat=="" || img_cat=="i/null.gif" || img_cat=="i/noimage.gif") && img_main!="") img_cat=img_main;
	document.write("<a href='/vcd-"+idc+"/catalog.html'><img src='/linkpics/"+img_cat+"' alt='Перейти в категорию' class=work_img></a>")
}

function c_link(idcat){
	document.write("<a href='/vcd-"+idcat+"/catalog.html' class=bask_img_text><img src='/i/ic_link.gif' border=0 align=absmiddle class=ic_link> подробнее</a>");
}

function g_link(idcat,page,idgoods){
	document.write("<nobr><a href='/vcd-"+idcat+"-"+page+"-"+idgoods+"/goodsinfo.html' class=bask_img_text><img src='/i/ic_li_child.gif' border=0 class=ic_link> подробнее</a></nobr>");
}

function g_valute() { document.write(CurValuteName); }

function g_sort(template_filename,idc,stype,s_name,s_name_sort){
	document.write("<a href='"+template_filename+"idc="+idc+"&stype="+stype+"&r="+RND+"' title='Сортировать по "+s_name_sort+"'>"+s_name+"</a>");
}

function g_sort_search(template_filename,pgsize,numpage,stype,s_name,s_name_sort,str_url){
	if (template_filename=="") template_filename="/search.html";
	document.write("<a href='javascript:SearchScroll(\""+template_filename+"\",\""+pgsize+"\",\""+numpage+"\",\""+stype+"\",\""+str_url+"\")' title='Сортировать по "+s_name_sort+"'>"+s_name+"</a>");
}

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;
	var IsOpera=(window.navigator.appName.toLowerCase().indexOf('opera')!=-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 && !IsOpera) 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 graph(r_img,r_img2,r_alt){
	if (r_img2!='' && r_img2.indexOf('noimage.gif')==-1 && r_img2.indexOf('null.gif')==-1) 
		document.write('<img src="/linkpics/'+r_img2+'" class=g_graph alt="'+r_alt+'">');
	else if (r_img!='' && r_img.indexOf('noimage.gif')==-1 && r_img.indexOf('null.gif')==-1) 
		document.write('<img src="/linkpics/'+r_img+'" class=g_graph alt="'+r_alt+'">');
}

function set_url(str_url){
	parent.document.location=str_url+'&r='+RND;
}

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 set_checked_all(p,set_val){
	for (i=0; i < p.length; i++) {
		if (p[i].type=="checkbox") p[i].checked=set_val;
	}
}

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_f_search_e(obj_link,obj_cat_select,v_sidc){
	obj_div=document.getElementById("f_search_e");
	if ( obj_link!=null ) obj_link.style.display="none";
	if ( obj_div!=null )
	{
		obj_div.style.display="block";
		set_selected(obj_cat_select,v_sidc);
	}	
}

function show_div(id_cur){
	var div_set = document.getElementById(id_cur);
	var obj_link = document.getElementById(id_cur+"_a");
	if (div_set!=null) {
		if (div_set.style.display=="block") {
			div_set.style.display="none";
			if ( obj_link!=null )
			{
				obj_link.setAttribute("className","cat0_off");
				obj_link.className = "cat0_off";
			}
		}
		else {	
			div_set.style.display="block";
			if ( obj_link!=null )
			{
				obj_link.setAttribute("className","cat0_on");
				obj_link.className = "cat0_on";
			}
		}
	}
	return false;
}

function show_cat_block(cat_id,link_id){
		var obj_cat=document.getElementById(cat_id);
		var obj_link=document.getElementById(cat_id+"_a");
		var obj_cur_link=document.getElementById(link_id+"_a");
		if (obj_cat!=null && obj_cat.style.display!="block") {
			obj_cat.style.display="block";
			if ( obj_link!=null )
			{
				obj_link.setAttribute("className","cat0_on");
				obj_link.className = "cat0_on";
			}
		}
		if (obj_cur_link!=null) { 
			obj_cur_link.setAttribute("className","cat_cur_link");
			obj_cur_link.className = "cat_cur_link";
		}
}

function show_parent_div(div_par){
    var IDParentElement="", NextParentElement="";
		var obj=null; 
		var obj1=document.getElementById(div_par);
		if (obj1 != null)
    {
			for(var i=0; i<10; i++) {
				obj=obj1;
				if (obj!=null) {
					if (obj.id!="" && obj.style.display!="block") {
						obj.style.display="block";
					}
					//if ( obj.id.indexOf('cat')!=-1 && cat_cur_bgcolor!="" ) obj.style.backgroundColor = cat_cur_bgcolor;
					if ( cat_cur_color!="" && document.getElementById(obj.id+'_a')!=null ) document.getElementById(obj.id+'_a').style.color = cat_cur_color;
				}
				else break;
				if (IsIE) obj1=eval("obj.parentElement");
				else obj1=eval("obj.parentNode");
				//parentNode 
			}// end for
		}
		else {
			obj1=document.getElementById(div_par+'_a');
			if ( cat_cur_color!="" && obj1!=null ) obj1.style.color = cat_cur_color;
		}
}

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 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;
	
	if (obj.idg==null) return;


	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 logoff(file_templ){
	RemoveCookie("login");
	RemoveCookie("pass");
	RemoveCookie("userid");
	str_RND = "";
	if (file_templ.indexOf('?')==-1) str_RND+="?";
	if (file_templ.indexOf('&')!=-1) str_RND+="&";
	str_RND+="r="+RND;
	document.location=file_templ + str_RND;
}

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 Set_Check_And_Config(cur_valute_name,id_valute,valute_rate,valute_cash,checkhash,AutoCreateGoodsConfigurationsEnabled) {
	CurValuteName=cur_valute_name;
	CurValuteFlag=id_valute;
	IDValute=id_valute; // 0 - USD?, 1 - USD, 2 - RUR
	DollarRateValueMax=parseFloat(valute_rate); // курс пересчета
	CurCurse=DollarRateValueMax;
	s_ch=checkhash;
	s_cf=valute_cash;
	if (AutoCreateGoodsConfigurationsEnabled!='' && AutoCreateGoodsConfigurationsEnabled!='0') AutoCreateCfgFlag=true;
}

function w_send(){
	document.write('<input type=hidden name=s_ch value=\"'+s_ch+'\"><input type=hidden name=s_cf value=\"'+s_cf+'\">');
}

var tr=1;

function s_tr(class_name){ 
	if (tr==2) { document.write("<tr class=\""+class_name+"\">"); tr=1; }
	else { document.write("<tr>"); tr=2; }
}

//------------------- функции для работы с выводом в несколько колонок
var cols=1;

function s_cols_auto(){ 
	var obj_tab=document.getElementsByTagName('table')[0];
	if ( obj_tab!=null ) return parseInt( ( obj_tab.clientWidth -300) / 300 );
	return 2; //parseInt( document.getElementsByTagName('work_area')[0].clientWidth / 300); 
}
function s_cols_1(num_cols){//start
	if (cols > num_cols) cols=1;
	if (cols==1) { document.write("<tr valign=top><td class=\"td"+cols+"\" width=\""+(100/num_cols)+"%\">"); } 
	else if (cols==num_cols) { document.write("<td class=\"end\">"); }
	else { document.write("<td>"); }
	
}
function s_cols_2(num_cols){//end
	if ( cols==num_cols ) { document.write("</td></tr>"); } 
	else { document.write("</td>"); }
	cols++;
}
function s_cols_final(num_cols){//end
	if (cols<=num_cols) {
		for (i=cols; i<=num_cols; i++) {
			document.write("<td width="+(100/num_cols)+"%>&nbsp;</td>");
		}// end for
	}// end if
	document.write("</tr>");
	cols=1;
}
//---------------------


function check_date(str_date){ // 1-ый вариант был: сравнивает текущую дату с датой в параметре в формате DD.MM.YY, переводя текущую дату в такой же формат, 2-ой вариант работает через <!--#CUR_DATE#--> в переменной str_cur_date
	if (str_cur_date==str_date)
		document.write("<span class=news_data>"+str_date+"</span><br>");
	else
		document.write("<span class=forum_annt>"+str_date+"</span><br>");
}

function scroll_pgn(){
	document.write(scroll_pgn_num++);
}

function Bookmark(shop_name){
	var s_href=location.href;
	var s_title=shop_name;
	if (IsIE) { window.external.AddFavorite(s_href,s_title); }
	else {
		 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (s_title, s_href, "");
		 else if (window.opera && document.createElement) {
			 var a = document.createElement('A');
			 if (!a) return false; //IF Opera 6
			 a.setAttribute('rel','sidebar');
			 a.setAttribute('href',s_href);
			 a.setAttribute('title',s_title);
			 a.click();
		 }
	}
}

function top_map_ico(e_mail,shop_name){
	document.write('<a href="/" title="Главная"><img src="/i/ic_home.gif" border=0 alt="Главная" align=absmiddle></a><img src="/i/0.gif" class="top_ico_sep"><a href="javascript:Bookmark(\''+shop_name+'\');" title="Добавить в избранное"><img src="/i/ic_favorite.gif" alt="Добавить в избранное" border=0 align=absmiddle></a><img src="/i/0.gif" class="top_ico_sep">');
}

function top_info(phone,e_mail,num_icq){
	document.write('<table><tr><td><img src="/i/ic_phone.gif" border=0 alt="Т" align=absmiddle> '+phone+'</td><td>' + show_icq(num_icq,"ICQ Консультант") + '</td><td><a href="mailto:'+e_mail+'" title="E-mail"><img src="/i/ic_email.gif" border=0 alt="Обратная связь" align=absmiddle> E-Mail</a></td></tr></table>');
}

function show_icq(num_icq,text_icq){
	return '<a href="http://wwp.icq.com/scripts/contact.dll?msgto='+num_icq+'" target="_blank"><img src="http://wwp.icq.com/scripts/online.dll?icq='+num_icq+'&img=5" border="0" alt="ICQ" align="absmiddle"> '+text_icq+'</a>';
}

function show_email(e_mail){
	return '<a href="mailto:'+e_mail+'" title="E-mail">'+e_mail+'</a>';
}

var array_day_of_week = new Array("Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота");

function get_day_of_week(){
	d = new Date();
	document.write( array_day_of_week[d.getDay()]);
}

top_ban_td=0;
function top_ban(){
	if (top_ban_td==0)
	{
		document.write("<th>&nbsp</th>")
		top_ban_td=1;
	}
}