var IsIE = (window.navigator.appName.toLowerCase().indexOf('microsoft')!=-1)?true:false;
var isIE_OLD = (/MSIE (5\.5|6).+Win/.test(navigator.userAgent));
var RND=parseInt(Math.random()*100000);
var cat_cur_color="#CC0000";
var cat_cur_bgcolor="";

var pathID = new Array();
var SiteTitle;

function top_info(phone, e_mail, num_icq) {
    document.write('<span><img src="/i/ico_phone.gif" width="15" border="0" alt="" align="absmiddle"/> ' + phone + '</span>' + ((num_icq != '') ? ('<span>' + show_icq(num_icq, 'ICQ Консультант - ' + num_icq) + '</span>') : ('')) + '<span><a href="mailto:' + e_mail + '" title="E-mail"><img src="/i/ico_email.gif" width="13" border="0" alt="E-Mail" align="absmiddle"/>&nbsp; E-Mail</a></span>');
}

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" width="18" border="0" alt="ICQ" align="absmiddle"/> ' + text_icq + '</a>';
}

function top_map_ico(e_mail, shop_name) {
    document.write('<a href="/" title="Главная"><img src="/i/ico_home.gif" width="13" border="0" alt="Главная" align="absmiddle"/></a><img src="/i/0.gif" class="ico_sep"/><a href="javascript:Bookmark(\'' + shop_name + '\');" title="Добавить в избранное"><img src="/i/ico_favorite.gif" width="13" alt="Добавить в избранное" border="0" align="absmiddle"/></a><img src="/i/0.gif" class="ico_sep"/>');
}

function top_ico_home() {
    document.write('<a href="/" title="Главная"><img src="/i/ico_home.gif" width="13" border="0" alt="Главная" align="absmiddle"/></a>');
}

function top_ico_phone() {
    document.write('<a href="/contacts/" title="Контакты"><img src="/i/ico_phone13.gif" width="13" border="0" alt="Контакты" align="absmiddle"/></a>');
}

function top_ico_mail(e_mail) {
    document.write('<a href="mailto:' + e_mail + '" title="E-Mail"><img src="/i/ico_email.gif" width="13" border="0" alt="E-Mail" align="absmiddle"/></a>');
}

function top_ico_sep(){
    document.write('<img src="/i/0.gif" class="ico_sep"/>');
}


function getBrowserInfo() {
    var t, v = undefined;
    if (window.opera) t = 'Opera';
    else if (document.all) {
        t = 'IE';
        var nv = navigator.appVersion;
        var s = nv.indexOf('MSIE') + 5;
        v = nv.substring(s, s + 1);
    }
    else if (navigator.appName) t = 'Netscape';
    return { type: t, version: v };
}

function Bookmark(a) {
    var url = window.document.location;
    var title = SiteTitle;
    var b = getBrowserInfo();
    if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url, title);
    else if (b.type == 'Opera') {
        a.href = url;
        a.rel = "sidebar";
        a.title = url + ',' + title;
        return true;
    }
    else if (b.type == "Netscape") window.sidebar.addPanel(title, url, "");
    else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
    return false;
}


// Добавить в Избранное 
function add_favorite(a) {
    title = document.title;
    url = document.location;
    try {
        // Internet Explorer 
        window.external.AddFavorite(url, title);
    }
    catch (e) {
        try {
            // Mozilla 
            window.sidebar.addPanel(title, url, "");
        }
        catch (e) {
            // Opera 
            if (typeof (opera) == "object") {
                a.rel = "sidebar";
                a.title = title;
                a.url = url;
                return true;
            }
            else {
                // Unknown 
                alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
            }
        }
    }
    return false;
}
function add_bask_img(idcat, idgoods) {
    document.write("<a href='#' onclick='if (fr_obj != null) { fr_obj.Width = 400; fr_obj.Height = 200; return fr_obj.Show(\"/basket_add.aspx?idc=" + idcat + "&idg=" + idgoods + "&c=addbask&ctype=showbask&r=" + RND + "\", \"Краткая информаця о корзине\");}'><img src='/i/ico_basket_goods.png' width=131 height=28 border=0 alt='в корзину' align='absmiddle' class='g_bask_img'></a>");
}

function bask_quan(f_quan, v_num) {
    var obj_f = GetMianForm();
    if (obj_f != null) {
        var obj_quan = obj_f[f_quan];
        if (obj_quan != null) {

            var v = parseInt(obj_quan.value);
            v += v_num;
            if (v <= 0) v = 1;
            if (obj_quan.value != v) {
                obj_quan.value = v; PostBack('updbask', '', '');
            }
        } 
    }
}

function show_frame(width, height, s_url, title, lnk_text, id_link, class_link) {
    var str_id_link = '';
    if (id_link != null) str_id_link = "id=\"" + id_link + "\" ";
    document.write("<a href=\"#\" " + str_id_link + "onclick=\"if (fr_obj != null) { fr_obj.Width = " + width + "; fr_obj.Height = " + height + "; return fr_obj.Show('" + s_url + "','" + title + "');}\" class=\"" + ((class_link != null) ? class_link : "lnk_service") + "\">" + lnk_text + "</a>");
}


function show_img(width,height,s_url){
	var imgnwin=window.open(s_url,"imgswin","resizable=yes,scrollbars=yes,toolbar=yes,location=no,directoties=no,status=no,menubar=no,width="+width+",height="+height);
}

var win_obj = null;
function show_win(width,height,s_url){
	var p_top=(window.screen.height-height)/2, p_left=(window.screen.width-width)/2;
	if (win_obj != null) win_obj.close();
	win_obj = 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_obj.focus();
}
function close_win() {
    if (win_obj != null) win_obj.close();
}

function active_win(surl){
	window.opener.document.location=surl;
}

function img_set_error(img_obj) {
    img_obj.src = "/i/0.gif";
    img_obj.width = "1px";
}

function set_valueID(id_obj, v) {
    var p = document.getElementById(id_obj);
    if (p != null) p.value = v;
}

function set_selected(p,v){
    if (p == null || p.options == null) return;
	for (i=0; i < p.options.length; i++) {
		if (p.options[i].value==v) { p.options[i].selected=true; break; }
	}
}

function set_selectedID(id_obj, v) {
    set_selected(document.getElementById(id_obj), v);
}

function set_radio(p, v) {
    var obj_f = GetMianForm();
    if (obj_f == null || obj_f[p] == null) return;
    var obj_chek = obj_f[p];
    for (i = 0; i < obj_chek.length; i++) {
        if (obj_chek[i].value == v) { obj_chek[i].checked = true; break; }
	}
}

function set_radioID(id_obj, v) {
    set_radio(document.getElementById(id_obj), v);
}

function set_checked(p,v){
	if (p==null) return;
	if (p.value==v) p.checked=true; 
}

function set_checked_all(p, v) {
    var obj_f = GetMianForm();
    if (obj_f == null) return;
    for (var i = 0; i < obj_f[p].length; i++) obj_f[p][i].checked = v;
}

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";
    }
    return false;
}

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_cat(id_cur){
	var div_set = document.getElementById(id_cur);
	var obj_link = document.getElementById(id_cur+"_a");
	var obj_ico = document.getElementById(id_cur+"_ico");
	if (div_set!=null) {
		if (div_set.style.display=="block") {
			div_set.style.display="none";
			if (obj_ico!=null && obj_ico.src!=null)
			{
				obj_ico.src = "/i/ic_plus.gif"
			}
		}
		else {	
			div_set.style.display="block";
			if (obj_ico!=null && obj_ico.src!=null)
			{
				obj_ico.src = "/i/ic_minus.gif"
			}
		}
	}
	return false;
}


function show_parent_div(div_par){
    var IDParentElement="", NextParentElement="";
		var obj=null; 
		var obj1=document.getElementById(div_par);
		if (obj1 == null) obj1 = document.getElementById(div_par+"_a");

		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 ( cat_cur_color!="" && document.getElementById(obj.id+((obj.id.indexOf('_a')==-1)?'_a':'')) != null ) 
						document.getElementById(obj.id+((obj.id.indexOf('_a') == -1) ? '_a' : '')).style.color = cat_cur_color;
					obj_ico = null;
					if ( (obj_ico=document.getElementById(obj.id+'_ico'))!=null && obj_ico.src!=null ) 
						obj_ico.src = "/i/ic_minus.gif";

				}
				else break;
				if (IsIE) obj1=eval("obj.parentElement");
				else obj1=eval("obj.parentNode");
			}// end for
		}
}









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 GetNumString(num_str) {
    var parts = String(num_str).split(".,");
    parts[0] = parts[0].substr(0, parts[0].length % 3) + parts[0].substr(parts[0].length % 3).replace(/(\d{3})/g, ' \$1');
    return parts.join(",");
}

function ReplaceSearchWord(v_id, ss) {
    var obj_id = document.getElementById(v_id);
    if (obj_id != null) {
        var sp = /\s/gi;
        var sp2 = /\./gi;
        ss = ss.replace(sp2, "");
        if (ss == '' || ss == ' ' || ss == '  ' || ss == '   ') return;
        ss = "("+ss.replace(sp, ".{0,20} ") + ")(.{0,20} )";
        
        var rel = new RegExp(ss, "gi");
        
        var text = obj_id.innerHTML;
        text = text.replace(rel, "<font color=red>$1</font>$2");
        obj_id.innerHTML = text;
    }
}

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 set_url(str_url){
    parent.document.location = str_url;
	return false;
}

function set_url_rnd(str_url) {
    if (str_url.indexOf("?")>0)
        parent.document.location=str_url+'&r='+RND;
    else
        parent.document.location = str_url + '?r=' + RND;
    return false;
}

function GetMianForm() {
	var theForm = document.forms['aspnetForm'];
	if (!theForm) {
			theForm = document.aspnetForm;
	}
	if (!theForm.onsubmit || (theForm.onsubmit() != false)) return theForm;
	else return null;
}

function SetAction(url) {
	var theForm = GetMianForm();
	if (theForm != null) {
	    theForm.action = url;
	    if (theForm.IsPostForm != null) theForm.IsPostForm.value = 1;
	    if (theForm.__VIEWSTATE != null) theForm.__VIEWSTATE.value = '';
	}
}

function SetDefaultButton(event, target, action) {
    if (event.keyCode == 13) {
        var src = event.srcElement || event.target;
        if (!src || (src.tagName.toLowerCase() != "textarea")) {
            var defaultButton;
            if (!IsIE) {
                defaultButton = document.getElementById(target);
            }
            else {
                defaultButton = document.all[target];
            }
            if (defaultButton && typeof (defaultButton.click) != "undefined") {

                //SetAction(action);
                //SetPostСommand(command);
                
                defaultButton.click();
                event.cancelBubble = true;
                if (event.stopPropagation) event.stopPropagation();
                return false;
            }
        }
    }
    return true;
}


function SetPostBackInfo(command, command_type, command_data, IsKeepRequestParameters) {
	var theForm = GetMianForm();
	if (theForm != null) {
	    if (theForm.c != null
	        && !(IsKeepRequestParameters && command == '')) 
	            theForm.c.value = command;
	    if (theForm.ctype != null
		    && !(IsKeepRequestParameters && command_type == '')) 
		        theForm.ctype.value = command_type;
	    if (theForm.cdata != null
		    && !(IsKeepRequestParameters && command_data == '')) 
		        theForm.cdata.value = command_data;
	}
    return theForm;
}

function SetPostСommand(command) {
    var theForm = GetMianForm();
    if (theForm != null) {
        if (theForm.c != null) theForm.c.value = command;
    }
    return theForm;
}

function SetPostСommandType(command) {
    var theForm = GetMianForm();
    if (theForm != null) {
        if (theForm.ctype != null) theForm.ctype.value = command;
    }
    return theForm;
}

function PostBack(command, command_type, command_data) {
    var theForm;
    if ( (theForm=SetPostBackInfo(command, command_type, command_data, false))!=null ) 
    {
        if (theForm.IsPostForm != null) theForm.IsPostForm.value = 1;
        theForm.submit();
    }
    return false;
}

// отличается от PostBack установкой параметра IsKeepRequestParameters=true
// в SetPostBackInfo
function PostBackAction(command, command_type, command_data) {
    var theForm;
    if ((theForm = SetPostBackInfo(command, command_type, command_data, true)) != null) 
    {
        if (theForm.IsPostForm != null) theForm.IsPostForm.value = 1;
        theForm.submit();
    }
    return false;
}

function changeText(el, text) {
    if (el == null) return;
    if (el.firstChild) {
        if (el.firstChild.nodeValue != null)
            el.firstChild.nodeValue = text;
        else
            el.firstChild.innerHTML = text;
    }
    else el.appendChild(document.createTextNode(text));
}

function set_message(id_div,text){
	var obj = document.getElementById(id_div);
	if (obj!=null) changeText(obj,text);
}

function changeHTML(el, text) {
    if (el == null) return;
    
    if (el.innerHTML!=null) {
        el.innerHTML = text;
    }
    else if (el.firstChild!=null) {
        if (el.firstChild.nodeValue != null || IsIE)
            el.firstChild.nodeValue = text;
        else
            el.firstChild.innerHTML = text;
    }
    else
        el.appendChild(document.createTextNode(text));
}

function set_HTML(id_div, text) {
    var obj = document.getElementById(id_div);
    if (obj != null) changeHTML(obj, text);
}

function set_img(id_src,img_url){
	var obj = document.getElementById(id_src);
	if (obj!=null && obj.src!=null) {
		obj.src=img_url;
	}
}

function w_send(s_ch) {
    document.write('<input type="hidden" name="s_ch" value=\"' + s_ch + '\"/>');
}

function fixPNG(element) {
    //Если браузер IE версии 5.5-6
    if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
        var src;

        if (element.tagName == 'IMG') //Если текущий элемент картинка (тэг IMG)
        {
            if (/\.png$/.test(element.src)) //Если файл картинки имеет расширение PNG
            {
                src = element.src;
                element.src = "/i/0.gif"; //заменяем изображение прозрачным gif-ом
            }
        }
        else //иначе, если это не картинка а другой элемент
        {
            //если у элемента задана фоновая картинка, то присваеваем значение свойства background-шmage переменной src
            src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
            if (src) {
                src = src[1]; //берем из значения свойства background-шmage только адрес картинки
                element.runtimeStyle.backgroundImage = "none"; //убираем фоновое изображение
            }
        }
        //если, src не пуст, то нужно загрузить изображение с помощью фильтра AlphaImageLoader
        if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
  }
}

function view_obj(obj) {
    var str = new String();
    for (i in obj) { str += '\r\n' + i; }
    return str;
}
