// General Popup function
var itemPopupWindow=null;
function itemPopup(itemPage,itemWindow,w,h,pos,infocus){
    LeftPosition=(screen.width)?(screen.width-w)/2:100;
    TopPosition=(screen.height)?(screen.height-h)/2:100;
    settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
    itemPopupWindow=window.open('',itemWindow,settings);
    itemPopupWindow.focus();
    itemPopupWindow.location = itemPage;
}

// focus to first form field
function formFocus() {
    if (document.forms.length > 0) {
    	var field = document.forms[0];
        for (i = 0; i < field.length; i++) {
        	if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
        		document.forms[0].elements[i].focus();
        		break;
            }
        }
	}
}

//If the browser is W3 DOM compliant, execute setImageSwaps function
if (document.getElementsByTagName && document.getElementById) {
	if (window.addEventListener) window.addEventListener('load', setImageSwaps, false);
		else if (window.attachEvent) window.attachEvent('onload', setImageSwaps);
}

function setImageSwaps() {
/*
foo_nm.jpg
    Our base image name
foo_hv.jpg
    Image name for hover
foo_md.jpg
    Image name for mouse-down
foo_ou.jpg
    Image name for mouse-out (when you want a separate image for mouse-out instead of restoring to original)
foo_mu.jpg
    Image name for mouse-up (when you want a separate image for mouse-up instead of restoring to original)
*/
	//Hover with restore
	prepareImageSwap(document.body);
}

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) {
//Do not delete these comments.
//Non-Obtrusive Image Swap Script V1.1 by Hesido.com
//Attribution required on all accounts
/*
Elem:
    Element passed as object or its ID as string
    Element || Element's ID (string)
mouseOver
    Do image swap on mouse hover?
    true || false (default: true)
mouseOutRestore
    Restore image on mouse-out?
    true || false (default: true)
mouseDown
    Do image swap on mouse-down?
    true || false (default: false)
mouseUpRestore
    Restore image on mouse-button-up?
    true || false (default: false)
mouseOut
    Use separate image for mouse-out?
    true || false (default: false)
mouseOut
    Use separate image for mouse-up?
    true || false (default: false)
*/
    if (typeof(elem) == 'string') elem = document.getElementById(elem);
    if (elem == null) return;
    var regg = /(.*)(_nm\.)([^\.]{3,4})$/
    var prel = new Array(), img, imgList, imgsrc, mtchd;
    imgList = elem.getElementsByTagName('img');
    for (var i=0; img = imgList[i]; i++) {
        if (!img.rolloverSet && img.src.match(regg)) {
            mtchd = img.src.match(regg);
            img.hoverSRC = mtchd[1]+'_hv.'+ mtchd[3];
            img.outSRC = img.src;
            if (typeof(mouseOver) != 'undefined') {
                img.hoverSRC = (mouseOver) ? mtchd[1]+'_hv.'+ mtchd[3] : false;
                img.outSRC = (mouseOut) ? mtchd[1]+'_ou.'+ mtchd[3] : (mouseOver && mouseOutRestore) ? img.src : false;
                img.mdownSRC = (mouseDown) ? mtchd[1]+'_md.' + mtchd[3] : false;
                img.mupSRC = (mouseUp) ? mtchd[1]+'_mu.' + mtchd[3] : (mouseOver && mouseDown && mouseUpRestore) ? img.hoverSRC : (mouseDown && mouseUpRestore) ? img.src : false;
                }
            if (img.hoverSRC) {preLoadImg(img.hoverSRC); img.onmouseover = imgHoverSwap;}
            if (img.outSRC) {preLoadImg(img.outSRC); img.onmouseout = imgOutSwap;}
            if (img.mdownSRC) {preLoadImg(img.mdownSRC); img.onmousedown = imgMouseDownSwap;}
            if (img.mupSRC) {preLoadImg(img.mupSRC); img.onmouseup = imgMouseUpSwap;}
            img.rolloverSet = true;
        }
    }
    function preLoadImg(imgSrc) {
        prel[prel.length] = new Image(); prel[prel.length-1].src = imgSrc;
    }
}
function imgHoverSwap() {this.src = this.hoverSRC;}
function imgOutSwap() {this.src = this.outSRC;}
function imgMouseDownSwap() {this.src = this.mdownSRC;}
function imgMouseUpSwap() {this.src = this.mupSRC;}
// custom submit buttons
var btn = {
    init : function() {
        if (!document.getElementById || !document.createElement || !document.appendChild) return false;
        as = btn.getElementsByClassName('btn(.*)');
        for (i=0; i<as.length; i++) {
            if ( as[i].tagName == "INPUT" && ( as[i].type.toLowerCase() == "submit" || as[i].type.toLowerCase() == "button" ) ) {
                var a1 = document.createElement("a");
                a1.appendChild(document.createTextNode(as[i].value));
                a1.className = as[i].className;
                a1.id = as[i].id;
                as[i] = as[i].parentNode.replaceChild(a1, as[i]);
                as[i] = a1;
                as[i].style.cursor = "pointer";
            }
            else if (as[i].tagName == "A") {
                var tt = as[i].childNodes;
            }
            else { return false };
            var i1 = document.createElement('i');
            var i2 = document.createElement('i');
            var s1 = document.createElement('span');
            var s2 = document.createElement('span');
            s1.appendChild(i1);
            s1.appendChild(s2);
            while (as[i].firstChild) {
              s1.appendChild(as[i].firstChild);
            }
            as[i].appendChild(s1);
            as[i] = as[i].insertBefore(i2, s1);
        }
        // The following lines submits the form if the button id is "submit_btn"
        btn.addEvent(document.getElementById('submit_btn'),'click',function() {
            var form = btn.findForm(this);
            form.submit();
        });
        // The following lines resets the form if the button id is "reset_btn"
        btn.addEvent(document.getElementById('reset_btn'),'click',function() {
            var form = btn.findForm(this);
            form.reset();
        });
    },
    findForm : function(f) {
        while(f.tagName != "FORM") {
            f = f.parentNode;
        }
        return f;
    },
    addEvent : function(obj, type, fn) {
        if (obj.addEventListener) {
            obj.addEventListener(type, fn, false);
        }
        else if (obj.attachEvent) {
            obj["e"+type+fn] = fn;
            obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
            obj.attachEvent("on"+type, obj[type+fn]);
        }
    },
    getElementsByClassName : function(className, tag, elm) {
        var testClass = new RegExp("(^|\s)" + className + "(\s|$)");
        var tag = tag || "*";
        var elm = elm || document;
        var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
        var returnElements = [];
        var current;
        var length = elements.length;
        for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                returnElements.push(current);
            }
        }
        return returnElements;
    }
}

btn.addEvent(window,'load', function() { btn.init();} );

function toggleDiv(divid,linkid,nlocation){
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
		document.getElementById(linkid).innerHTML = '&laquo; Hide';
	}else{
		document.getElementById(divid).style.display = 'none';
		document.getElementById(linkid).innerHTML = '&raquo; The details...';
	}
	if (nlocation) {
		document.location = nlocation;
	}
}
function toggleNavDiv(divid,linkid,nlocation){
	if(document.getElementById(divid).style.display == 'none'){
		document.getElementById(divid).style.display = 'block';
		document.getElementById(linkid).innerHTML = '&laquo; Hide';
	}
	if (nlocation) {
		document.location = nlocation;
	}
}