/* author: [EGOiST].[TeaM | TSRh].[ego1st.cjb.net] */
/* Creation date: 12.04.2008 */

// Ширина окна браузера
function sv_get_window_width() 
{
  var width = document.body.clientWidth;
  if (typeof(width)=="number") return width;
  else return 0;
}

// Получить все свойства объекта
function sv_dump(obj, obj_name) 
{
  var result = ""
  for (var i in obj)
    result += obj_name + "." + i + " = " + obj[i] + " ";
  return result;
}

function getObject(obj) { 
    var theObj 
    if (document.layers) { 
        if (typeof obj == "string") { 
            return document.layers[obj]
        } else { 
            return obj 
        } 
    } 
    if (document.all) { 
        if (typeof obj == "string") { 
		   if(document.all(obj)!=null) return document.all(obj);
		   else return null;
        } else { 
            return obj; 
        } 
    } 
    if (document.getElementById) { 
        if (typeof obj == "string") { 
            return document.getElementById(obj) 
        } else { 
            return obj 
        } 
    } 
    return null 
} 

// Отображение объекта
function show(obj) { 
  var theObj = getObject(obj);
  if (theObj != null && typeof theObj != "undefined" && typeof theObj.style != "undefined")
  {
    if (typeof theObj.style.visibility != "undefined")
    {
      theObj.style.visibility = "visible"
    }
    if (typeof theObj.style.display != "undefined") theObj.style.display = "block"
  }
}

// Функция для скрытия объектов
function hide(obj)
{ 
  var theObj = getObject(obj)
  if (theObj != null && typeof theObj != "undefined" && typeof theObj.style != "undefined")
  {
    if (typeof theObj.style.visibility != "undefined")
    {
      theObj.style.visibility = "hidden"
    }
    if (typeof theObj.style.display != "undefined") theObj.style.display = "none"
  }
} 
   
// Функция для скрытия объектов
function show_hide(obj)
{  
  var theObj = getObject(obj)
  if (typeof theObj.style.display != "undefined")
  {
    if(theObj.style.display=="none") theObj.style.display = "block"; 		 
	else theObj.style.display = "none";
  }	
  else if (typeof theObj.style.visibility != "undefined")
  {
    if (theObj.style.visibility=="hidden") theObj.style.visibility = "visible";
    else theObj.style.visibility = "hidden";
  }	
  
} 

var popup_img;
function show_image(img_url) {
  if (popup_img && !popup_img.closed)
  {
    popup_img.close(); 
  }	
  popup_img = window.open('/shared/img_popup.php?img='+img_url,'Image','width=700,height=670,scrollbars=no,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}

var popup_user_page;
function show_visitka(id_author) {

  if (popup_user_page && !popup_user_page.closed)
  {
    popup_user_page.close(); 
  }	
  popup_user_page = window.open('/forum/info.php?id_author='+id_author,'visitka','width=850,height=450,scrollbars=yes,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}

function show_child_visitka(id_user) {

  if (popup_user_page && !popup_user_page.closed)
  {
    popup_user_page.close(); 
  }	
  popup_user_page = window.open('/child/infochild.php?id_user='+id_user,'visitka','width=850,height=450,scrollbars=yes,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}

function open_in_new(url) {
  window.close();
  window.open(url);
}

function open_in_parent(url, close) {
  if (close)
  {
    window.close();
  }
  opener.location.replace(url);
  //popup_user_page = parent.open('/forum/info.php?id_author='+id_author,'visitka','width=850,height=450,scrollbars=yes,toolbar=no,location=no,status=no,resizable=yes,screenX=120,screenY=100');
}

function enterform(e) {	 
  if (typeof(e)=="undefined")  e = window.event; 
  if (typeof(e.pageX)!="undefined")
  {
	var x = 0+e.pageX;
	var y = 0+e.pageY;   
  }
  else
  {
	var x = 0+e.clientX;
	var y = 0+e.clientY;   
  }
  x = x-70;
  y = y+20;   
  
  frm = getObject("enterform");
  frm.style.cssText = "left: "+x+"px; top: "+y+"px";	
  show("enterform");
}

function resizeWindow(max_w, max_h)
{	
  var w = max_w;
  var h = max_h;
  var w_s = screen.width;
  var h_s = screen.height;
  if (max_w>w_s)w = w_s - 20; 
  if (max_h>h_s) h = h_s - 20;
  var l = (w_s-w)/2;
  var t = (h_s-h)/2;
  window.moveTo(l,t);
  window.resizeTo(w,h);
} 

function changeParentClass(obj, className)
{						
	obj.parentNode.className = className;	
}	

function getBrowserInfo() {
    var t,v = undefined;
    
    if (window.chrome) t = 'Chrome';
    else 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,title){
    var url = window.document.location;
    var b = getBrowserInfo();
    
    if (b.type == 'IE' && 8 >= 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;
}
