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_map_ico(email, s_title) {
    SiteTitle = s_title;
    document.write('<a href="/" id="link_home">Главная</a><a href="/" onclick="return Bookmark(this);" id="link_favorite">Добавить сайт в избранное</a>');
    //<a href="mailto:' + email + '" id="link_email">Написать письмо</a>
}

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_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 show_img_link(s_url, isImage) {
    document.write("<a href=\"#\" onclick=\"if (fr_obj != null) { fr_obj.Width = 520; fr_obj.Height = 600; return fr_obj.Show('" + s_url + "','Титульный лист');}\"" + ((isImage) ? "" : " class=\"ico_page\"") + ">" + ((isImage) ? "<img src=\"" + s_url + "\" border=\"0\" class=\"work_img\"/>" : "Титульный лист") + "</a>");
}

function show_frame(width, height, s_url, title, lnk_text) {
    document.write("<a href=\"#\" onclick=\"if (fr_obj != null) { fr_obj.Width = " + width + "; fr_obj.Height = " + height + "; return fr_obj.Show('" + s_url + "','" + title + "');}\" class=\"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 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){
	if (p==null) return;
	for (i=0; i < p.length; i++) {
		if (p[i].value==v) { p[i].checked=true; break; }
	}
}

function set_checked(p,v){
	if (p==null) return;
	if (p.value==v) p.checked=true; 
}

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_link!=null )
			{
				obj_link.setAttribute("className","cat0_off");
				obj_link.className = "cat0_off";
			}
			*/
			if (obj_ico!=null && obj_ico.src!=null)
			{
				obj_ico.src = "/i/ic_plus.gif"
			}
		}
		else {	
			div_set.style.display="block";
			/*
			if ( obj_link!=null )
			{
				obj_link.setAttribute("className","cat0_on");
				obj_link.className = "cat0_on";
			}
			*/
			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 ( obj.id.indexOf('cat')!=-1 && cat_cur_bgcolor!="" ) obj.style.backgroundColor = cat_cur_bgcolor;
					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");
				//parentNode 
			}// end for
		}
//		else {
//			obj1=document.getElementById(div_par+'_a');
//			if ( cat_cur_color!="" && obj1!=null ) obj1.style.color = cat_cur_color;
//		}

}

CurCurse='1.0';

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(".,");
    //alert("num_str='" + num_str + "', parts[0] = '" + parts[0] + "', parts[1] = '" + parts[0] + "'");
    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 + ')';
        //ss = ss.replace(sp, "|");
        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 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')";
  }
}