// Script for Alpinet.org.
// (c) 1999-2003 Alpinet.org, all rights reserved.

// www.alpinet.org
// v4.05 (c) 1999-2009 Ionut Nechita djonexx at alpinet dot org
// ------------------------------------------/

var ferShowFoto = null;
var ferView   = null;
var ferPopup    = null;


// ---- global site functions

function getById(formName, elementName) {
		
	try {		
		
		var rootDoc = window.document;
		var el = null;
		
		if(formName != null) {
			rootDoc = window.document.forms[formName];
			el = rootDoc[elementName];
		}	
		else
			el = rootDoc.getElementById(elementName);
				
		return el;
	} catch (e) {
		//
	}
}

function movr(obj, idx) {    
  if(obj.innerText)
    window.status = "Alpinet: " + obj.innerText;
  else
    window.status = "Alpinet";
  return true;
}

function mout(obj, idx) {
      
  window.status = "Alpinet";
  return true;
}

function cl(link) {
  window.status = "Loading ...";
  document.location.href = link;
  return true;
}

function Status(s) {
  if(s != null && s != "")
    s = ": "+s;
  window.status = "Alpinet" + s;
  return true;
}

function LoadPopup(doc) {
  WindowWidth= 300;
  WindowHeight= 200;

  ferPopup = window.open(doc, "AlpinetPopup", 'status=no,toolbar=0,scrollbars=no,menubar=0,titlebar=0,resizable=0,width='+WindowWidth+',height='+WindowHeight+',left='+((screen.width-WindowWidth)/2)+',top='+((screen.height-WindowHeight)/2));
  //fer.moveTo(screen.width/2-150, screen.height/2-100);
  ferPopup.focus();
}

function ClosePopup() {
  if(ferPopup && !ferPopup.closed)
  ferPopup.close();
}

function LoadPicture(doc)   {
  WindowWidth= 900;
  WindowHeight= 700;
  ferShowFoto=window.open(doc,"Foto",'status=no,toolbar=0,scrollbars=yes,menubar=0,titlebar=0,resizable=1,width='+WindowWidth+',height='+WindowHeight+',left='+((screen.width-WindowWidth)/2)+',top='+((screen.height-WindowHeight)/2));
  ferShowFoto.focus();
}

function ContactUser(doc) {
  WindowWidth= 400;
  WindowHeight= 408;
  ferContact=window.open(doc,"ContactUser",'status=no,toolbar=0,scrollbars=no,menubar=0,titlebar=0,resizable=1,width='+WindowWidth+',height='+WindowHeight+',left='+((screen.width-WindowWidth)/2)+',top='+((screen.height-WindowHeight)/2));
  ferContact.focus();  
}

function showCalendar(doc, frm, fld, year, month, day) {
  WindowWidth= 278;
  WindowHeight= 300;

  f= document.forms[frm];

  ferCalendar=window.open(doc+ "dta="+ escape(f.elements[fld].value)+ "&year="+ year+ "&month="+ month+ "&day="+ day+ "&frm="+ frm+ "&fld="+ fld,"datePicker",'status=no,toolbar=0,scrollbars=no,menubar=0,titlebar=0,resizable=0,width='+WindowWidth+',height='+WindowHeight+',left='+((screen.width-WindowWidth)/2)+',top='+((screen.height-WindowHeight)/2));
  ferCalendar.focus();  
}

function ViewPhoto(photo, awidth, aheight) {

  var scroll = "no";
  if(awidth > screen.width) {
    scroll="yes";
    awidth = screen.width;
    aheight = height+20;  
  }

  if(aheight > screen.height) {
    scroll="yes";
    aheight= screen.height;
  }
  
  var leftpos = (screen.width-awidth)/2;
  var toppos = (screen.height-aheight)/2;

  if(ferView && !ferView.closed)
  ferView.close();
  ferView = window.open(photo, "Foto", "status=no,toolbar=0,scrollbars="+scroll+",menubar=0,titlebar=0,resizable=0,width="+awidth+",height="+aheight+"top="+toppos+"left="+leftpos);
  ferView.focus();
}

function ViewFlash(flash) {
  var height = 400;
  var width  = 400;
  var leftpos = ((screen.width-width)/2);
  var toppos = ((screen.height-height)/2);  
  ferView = window.open(photo, "Foto", "status=no,toolbar=0,scrollbars=no,menubar=0,titlebar=0,resizable=1,width="+width+",height="+height+"top="+toppos+"left="+leftpos);
  ferView.focus();
}

function KillFloatingShit()
{  
  try
  {
    var max_banner_height = 90;
    var el = document.getElementsByTagName("div");
    var n = el.length;
    var toRemove = new Array();
    
    for(i = 0; i<n; i++)
    {
      var height = parseInt(el[i].style.height);
      if((el[i].style.zIndex > 10000) && (height > max_banner_height))
      {
        toRemove.push(el[i]);
      }
    }    
    for(i = 0; i<toRemove.length; i++)
    {
      toRemove[i].parentNode.removeChild(toRemove[i]);
    }
  }
  catch(e) 
  { }
}

function libAddEvent(obj, eventName, handler)
{
  // ie-style attachEvent
  if(typeof(obj.attachEvent) != "undefined")
  {
    obj.attachEvent("on"+eventName, handler);
    return;
  }
  // w3c style addEventListener
  if(typeof(obj.addEventListener) != "undefined")
  {
    obj.addEventListener(eventName, handler, false);
  }
}

function libRemoveEvent(obj, eventName, handler)
{
  // ie-style attachEvent
  if(typeof(obj.detachEvent) != "undefined")
  {
    obj.detachEvent("on"+eventName, handler);
    return;
  }
  // w3c style addEventListener
  if(typeof(obj.removeEventListener) != "undefined")
  {
    obj.removeEventListener(eventName, handler, false);
  }
}

// libAddEvent(window, "load", KillFloatingShit);

function addSearch(providerUrl)
{  
  if(window.external != null && typeof(window.external.AddSearchProvider) != "undefined")
  {
    window.external.AddSearchProvider(providerUrl);
  }
  else
  {
    window.alert('Your browser does not support search providers');
  }
}

function anchor_read()
{
  var parts = document.location.href.split('#');
  if(parts.length > 1)
    return parts[1];
    
  return '';
}
