//-----------------------------------------------
// ÊËÀÑÑ ÄËß ÐÀÁÎÒÛ Ñ ÏËÀÂÀÞÙÈÌÈ ÔÐÅÉÌÀÌÈ
//-----------------------------------------------
// êîíñòðóêòîð êëàññà
function FrameObj(v_fr_name, v_width, v_height, v_title, v_is_modal, v_css) {
    this.Name = v_fr_name;
    this.ID = v_fr_name + "_id";
    this.Width = parseInt(v_width);
    this.Height = parseInt(v_height);
    this.Title = v_title;
    this.IsModal = (v_is_modal!=null)?v_is_modal:false;
    this.CSS = v_css;
		
		var isIE_OLD = (window.navigator.appName.toLowerCase().indexOf('microsoft')!=-1)?true:false; //(/MSIE (5\.5|6).+Win/.test(navigator.userAgent));

    this.Init = function Init() 
			{
        if (this.Name != null && document.getElementById(this.ID) == null) {

          var _CSS = (this.CSS != null && this.CSS != '') ? this.CSS : ((isIE_OLD) ? "fr_dialog_IE_OLD" : "fr_dialog");
					var strVal = '';
          if (v_is_modal)
          {
						var style_modal = 'style="height:' + window.screen.height + 'px;"';
						var css_modal="fr_modal";
						if (isIE_OLD)
						{
							css_modal = "fr_modal_IE_OLD";
							style_modal = "";
						}
						strVal+='<div class="'+css_modal+'" id="' + this.ID + '_modal" '+style_modal+'>&nbsp;</div>';
          }
				strVal+='<div id="' + this.ID + '" class="' + _CSS + '">'
							+ '<table cellpadding="0" cellspacing="0" width="100%">'
							+ '<tr class="menu">'
							+ ' <td width="100%"><div id="' + this.ID + '_title">' + this.Title + '</div></td>'
							+ '	<td class="ic_close"><a href=\'javascript:FrameClose("' + this.ID + '")\'>Çàêðûòü&nbsp; õ</a></td>'
							+ '</tr>'
							+ '<tr>'
							+ '	<td colspan="2" class="cont">'
							+ '		<iframe marginheight="0" marginwidth="0" width="100%" name="' + this.Name + '" id="' + this.ID + '_fr" src="" frameborder="no" scrolling="no"></iframe>'
							+ ' </td>'
							+ '</tr>'
							+ '</table>'
							+ '</div>';

				document.write(strVal);
			}//end function Init()
    };

    this.Show = function Show(v_url, v_title) {

        var fr = document.getElementById(this.ID);
        var i_fr = document.getElementById(this.ID + "_fr");

        if (fr != null && v_url != '') {

            if (fr.style.display != "block") {
                if (this.CSS != null && this.CSS != '') {
                    fr.setAttribute("className", this.CSS);
                    fr.className = this.CSS;
                }
                else {
                    var c_width = 0, c_height = 0;

                    if (self.innerWidth && self.innerHeight) { // Mozilla, Firefox etc
                        c_width = self.innerWidth;
                        c_height = self.innerHeight;
                    }
                    else if (document.body) { // MS IE
                        c_width = window.screen.width;
                        c_height = window.screen.height - 100;
                    }

                    if (!isNaN(this.Width) && this.Width > 0) {
                        var p_left = (c_width - this.Width) / 2;
                        fr.style.width = this.Width + "px";
                        //i_fr.style.width = this.Width + "px";
                        fr.style.left = p_left + "px";
                    }

                    if (!isNaN(this.Height) && this.Height > 0) {
                        fr.style.height = this.Height + "px";
                        i_fr.style.height = (this.Height - 25) + "px";
                        if (!isIE_OLD) {
                            var p_top = (c_height - this.Height) / 5;
                            fr.style.top = p_top + "px";
                        }
                    }
                } //end else if (this.CSS != null && this.CSS != '') {
            } //end if (fr.style.display != "block") 

            if (i_fr.contentDocument != null) {
                i_fr.contentDocument.open();
            }

            if (v_title != null && v_title != '') {
                set_message(this.ID + "_title", v_title);
            }

            fr.style.display = "block";
						fr.style.display = "none";
						fr.style.display = "block";
            i_fr.src = v_url;

            if (this.IsModal) {
                var fr_modal = document.getElementById(this.ID + "_modal");
                if (fr_modal != null) fr_modal.style.visibility = "visible";
            }
        }
        return false;
    };

    this.Init();

		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 FrameClose(fr_id) {
    var fr = document.getElementById(fr_id);
    if (fr != null) fr.style.display = "none";
    var fr_modal = document.getElementById(fr_id + "_modal");
    if (fr_modal != null) fr_modal.style.visibility = "hidden";
}

function FrameClose_DOC(doc, fr_id) {
    var fr = doc.getElementById(fr_id);
    if (fr != null) fr.style.display = "none";
    var fr_modal = doc.getElementById(fr_id + "_modal");
    if (fr_modal != null) fr_modal.style.visibility = "hidden";
}
