var resources = new Array();

// load <lang>.js file for language resources

/*******************************************************
* load onerror handler (or not...)
*******************************************************/
window.onerror = customHandler;

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;

function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;
    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;
    // do stuff

    // BEGIN: round divs
    //Nifty("div#container");
    // Nifty("div#content,div#nav","same-height small"); */ // don't use div because autoflow doesn't work anymore!
    // Nifty("div#nav","small");
    //Nifty("div#header,div#content,div#footer","small");
    // END: round divs

    //document.getElementById('google').onclick = function() {alert('Google');};
    //document.getElementById('yahoo').onclick = function() {alert('Yahoo!');};

};

function defaultHandler() {return false}
function silentHandler()  {return true}
function customHandler(desc,page,line,chr)  {
 alert(
  'JavaScript error occurred! \n'
 +'\nError description: \t'+desc
 +'\nPage address:      \t'+page
 +'\nLine number:       \t'+line
 )
 return true
}

function setStyleSheet()
{
	var sw = screen.width;
	var sh = screen.height;
	var stylesheet = '';

    if (sw > 1280) stylesheet = 'std1600.css';
	else if (sw > 1024) stylesheet = 'std1280.css';
	else if (sw > 800) stylesheet = 'std1024.css';
	else stylesheet = 'standard.css';

	document.write('<link rel="stylesheet" href="/css/' + stylesheet + '">');
	//return '<link rel="stylesheet" href="./stylesheets/' + stylesheet + '">';
}

function urlExists(url)
{
	var localurl = "/faq/index.html";
	http.open("HEAD", url, true);
 http.onreadystatechange = function() {
  if (http.readyState==4) {
   if (http.status==200) alert("URL Exists!")
    else if (http.status==404) alert("URL doesn't exist!")
     else alert("Status is "+http.status)
  }
 }
 http.send(null)
}

function getHTTPObject() {
	if (typeof XMLHttpRequest != 'undefined') {
		return new XMLHttpRequest();
	}

	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		try {
			return new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e) {}
	}

	return false;
}

// Make requests using "create_http_object()"
// Also found on the net, but a bit changed
function makeHttpRequest(VUrl, VCallBack, VPostValues, UsePost)
{
    // Here we create xmlhttp the object
    var Http = getHTTPObject(); //create_http_object();

    // don't do make any request if the browser doesn't support AJAX
    if(!Http)
    {
        return false;
    }

		// If we received anything back call up the chosen function
    Http.onreadystatechange = function()
    {
        if(Http.readyState == 4)
        {
            // Call the function if the status is ok (200)
            if(Http.status == 200)
            {
								VCallBack(Http.responseText);
            }
            else
            {
                // Seems there was an error..
                alert('Error! ('+Http.status+')');
            }
        }
    }

		// Make sure the post values are filled out or on null..
    if(!VPostValues)
    {
        VPostValues = null;
    }
		if (UsePost) {
      // Open the appriopriate URL
      Http.open('POST', VUrl, true);
  		// Set the request header for a form sent by POST
      Http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      // send the post values
      Http.send(VPostValues);
		}
		else {
			Http.open('GET', VUrl, true);
			Http.send(null);
		}
}

// bubble up??
function doSomething2(e) {
	if (!e) var e = window.event
	// handle event
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();

	alert("doSomething2");
}

function doSomething1(e) {
	if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
}

/*  Prototype JavaScript framework, version 1.5.0_pre0
 *  (c) 2005 Sam Stephenson
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
 * The Dollar Function:
/*————————————————————————–*/

/*
function $() {
  var results = [], element;
  for (var i = 0; i < arguments.length; i++) {
    element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);
    results.push(Element.extend(element));
  }
  return results.length < 2 ? results[0] : results;
}
*/

/*
This script is copyright (c) 2006 Elliot Swan under the
Creative Commons Attribution-ShareAlike 2.5 license:
http://creativecommons.org/licenses/by-sa/2.5/

More information on this script can be found at:
http://www.elliotswan.com/2006/04/12/move-and-copy/
*/

var Move =	{

  copy	:   function(e, target)	{
	    var eId      = $(e);
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e+'-copy';

	    for(var i = 0; cLength >= i;  i++)	{
	    if(copyE.childNodes[i].id) {
	    var cNode   = copyE.childNodes[i];
	    var firstId = cNode.id;
	    cNode.id    = firstId+'-copy'; }
	    }
	    $(target).appendChild(copyE);
	    },
  element:  function(e, target, type)	{
	    var eId =  $(e);
	    if(type == 'move') {
	       $(target).appendChild(eId);
	    }

	    else if(type == 'copy')	{
	       this.copy(e, target);
	    }
	    }
}

//Move.element('e', target', 'type');

function switchMenu(obj) {
	var el = document.getElementById(obj);
    var img = document.getElementById('filters_fold_img');
    var openImg = '/img/minus.gif';
    var closedImg = '/img/plus.gif';
    try {
        /*
        if (img != null) {
            if (img.src.indexOf(closedImg) > 0) img.src = openImg;
            else if (img.src.indexOf(openImg) > 0) img.src = closedImg;
        }
        */
    	if (el.style.display != "none") {
    		el.style.display = 'none';
            if (img != null) img.src = closedImg;
    	}
    	else {
    		el.style.display = '';
            if (img != null) img.src = openImg;
    	}
    }
    catch (exc) { }
}

function isFF() {
    return (detectBrowser() == 'ff');
}

function isIE() {
    return (detectBrowser().substr(0,2) == 'ie');
}

function detectBrowser() {
    var browser = '';

    if (window.Iterator != undefined) browser = 'ff'; //alert("You're using FireFox 2+");
    else {
      if (document.documentElement && typeof document.documentElement.style.maxHeight!="undefined") browser = 'ie7';//alert("You're using IE7")
      else if (document.compatMode && document.all) browser = 'ie7';//alert("You're using IE6+");
    }
    return browser;
}

function printList(listType){
    try {
      var url = '/?a=lists&lid=' + listType + '&print=1';
      var options = 'width=800,height=600,resizable=1,status=0,menubar=0,scrollbars=1,toolbar=0,location=0';
      var printWindow = window.open(url, 'printWindow', options);
      if (printWindow == null) alert('Please allow popups for this system to operate correctly!');
      else printWindow.print();
    }
    catch (err) { }
}

function deleteItem(sTag, iId, sDescription) {
	if (iId == null || iId <= 0) return false;

	var agree = confirm(resources[0] + ' "' + sDescription + '"');

	if (agree) {
		var sBaseDir = document.getElementById('basedir').value;
		location.href = sBaseDir + 'delete/' + sTag + '/' + iId + '/';
	}

	//return false;
}
