/* author: Sergey Golyshev */

var messenger = false;
var thanks = false;

// Ширина окна браузера
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);
  //alert(theObj);
  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_user) {

  if (popup_user_page && !popup_user_page.closed)
  {
    popup_user_page.close(); 
  }	
  popup_user_page = window.open('/forum/info.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 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 resizeHeightModalWindow(min_height)
{
  if (window.jQuery)
  {
    $( document ).ready( function(){
      var h = $("body").height() + 100;
      //alert(h);
      if (h < min_height) h = min_height;

      var w = (window.outerWidth || $(window).width()+22);
      var w_s = screen.width;
      var top = (window.screenY || window.screenTop)
      var h_s = screen.height - top - 40;
      if (w > screen.width) w = w_s - 22;
      if (h > h_s) h = h_s;
      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;
}


function newMessageWindow(to_user) {
  openMessenger("to_user="+to_user);
}

function newMessageWindowFromForum(to_forum_user) {
  openMessenger("to_forum_user="+to_forum_user);
}

function openMessenger(param)
{
  if (window.jQuery)
  {
    $( '#user_profile' ).remove();
  }

  if (messenger.closed == false && typeof(messenger) == "object")
  {
    messenger.document.write("<div style='text-align: center; margin: 50px 0px 0px 0px'><img src='/images/ajax-loader.gif' /></div>");
  }

  var w = 800;
  var h = 600;
  var l = Math.ceil((screen.width - w)/2);
  var t = Math.ceil((screen.height - h)/3);
  messenger = window.open("/messanger/messanger.php?"+param,'messengerWindow','dependent=1,resizable=1,height='+h+',width='+w+',left='+l+',top='+t);
  messenger.focus();
}

function showThanks(to_user)
{
  //alert(1);
  if (window.jQuery)
  {
    $( '#user_profile' ).remove();
  }
  var w = 800;
  var h = 600;
  var l = Math.ceil((screen.width - w)/2);
  var t = Math.ceil((screen.height - h)/3);
  if (thanks.closed == false && typeof(thanks) == "object")
  {
    thanks.document.write("<div style='text-align: center; margin: 50px 0px 0px 0px'><img src='/images/ajax-loader.gif' /></div>");
  }
  //alert(l+" "+ t);
  thanks = window.open("/messanger/thanks.php?to_user="+to_user,'thanksWindow','dependent=1,resizable=1,height='+h+',width='+w+',left='+l+',top='+t);
  thanks.focus();
  //alert(3);
}


