/////////////////////////////////
// BEGIN HR PRE-LOAD SCRIPT
// Pre-loads replaced "hr" elements after page load, so it doesn't interfere with other "onPageLoad" declarations
/////////////////////////////////
function fancyRules() { 
  if (!document.getElementsByTagName) return; 
          var hr = document.getElementsByTagName("hr");
  for (var i=0; i<hr.length; i++) { 
    var newhr = hr[i]; 
    var wrapdiv = document.createElement('div');
    wrapdiv.className = 'line';  
    newhr.parentNode.replaceChild(wrapdiv, newhr);  
    wrapdiv.appendChild(newhr);  
  } 
 } 

window.onload = fancyRules; 





/////////////////////////////////
// BEGIN EASY POPUP WINDOW SCRIPT
// Construct easier HTML Link like this:
// <a href="link.html" onClick="openWin('link.html','','150','100','#FFFFFF'); return false">LINK</a>
/////////////////////////////////
// For popup windows with URL, Title, Size (W,H) and Background-Color parameter (5 parameters)
var newwindow;
var wheight = 0, wwidth = 0;

function popup5(url, title, iwidth, iheight, colour) {
var pwidth, pheight;


if ( !newwindow || newwindow.closed ) {
	pwidth=iwidth+30;
	pheight=iheight+30;
	newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',scrollbars=no,resizable=1,top=50,left=50,status=1 ');
	wheight=iheight;
	wwidth=iwidth;
}
 
if (wheight!=iheight || wwidth!=iwidth ) {
	pwidth=iwidth+30;
	pheight=iheight+90;
	if (version.substring(0,1)>3) { 	// check browser v4+ supporting JavaScript 1.2	
		newwindow.resizeTo(pwidth, pheight);
	}
	wheight=iheight;
	wwidth=iwidth;
}

newwindow.document.clear();
newwindow.focus();
newwindow.document.writeln('<html> <head> <title>' + title + ' <\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
newwindow.document.writeln('<img src=' + url + '  title=\"' + title + '\"   alt=\"' + title + '\" />');
newwindow.document.writeln('<\/center> <\/body> <\/html>');
newwindow.document.close();
newwindow.focus();
}





/////////////////////////////////
// BEGIN 'SUBMIT ONCE, THEN DISABLE SUBMIT FORM' SCRIPT
// © Dynamic Drive (www.dynamicdrive.com)
// Construct HTML Link like this:
// <form method="POST" onSubmit="submitonce(this)">
/////////////////////////////////
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}





/////////////////////////////////
// BEGIN STANDARD EMAIL FORM VALIDATION SCRIPT
// © Dynamic Drive (www.dynamicdrive.com)
// Visit Nav Surf at http://navsurf.com
// Construct FORM Link like this:
// <form method="POST" onsubmit="return checkContactForm(this);">
/////////////////////////////////
function checkContactForm(formobj){
	// Enter name of mandatory fields
	var fieldRequired = Array("name", "email", "Comments");
	// Enter field description to appear in the dialog box
	var fieldDescription = Array("Name", "Email", "Comments");
	// dialog message
	var alertMsg = "Please complete the following fields:\n";
	
	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}





/////////////////////////////////
// BEGIN EMAIL VALIDATION SCRIPT
// © Dynamic Drive (www.dynamicdrive.com)
// Visit Nav Surf at http://navsurf.com
// Construct FORM Link like this:
// <form method="POST" onClick="return checkmail(this.form.email)">
/////////////////////////////////
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

function checkmail(e){
   var returnval=emailfilter.test(e.value)
   if (returnval==false){
      alert(" - Please enter a valid email address.")
      e.select()
   }
   return returnval
}





/////////////////////////////////
// BEGIN JAVASCRIPT ROLLOVER AUTO-DETECTION SCRIPT
// Non-Obtrusive Image Swap Script by Hesido.com
// >> http://www.hesido.com/web.php?page=imageswapping#header <<
// Construct Image Link like this:
// <img src="image_nm.gif">
// That's it. This script will handle the rest. Just be sure your images are named with:
//    image_nm.jpg - Base image name
//    image_hv.jpg - Image name for hover
//    image_md.jpg - Image name for mouse-down
//    image_ou.jpg - Image name for mouse-out (when you want a separate image for mouse-out instead of restoring to original)
//    image_mu.jpg - Image name for mouse-up (when you want a separate image for mouse-up instead of restoring to original)/////////////////////////////////
//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);
}

//When document loads, apply the prepareImageSwap function to various images with our desired settings
function setImageSwaps() {
//Mousedown, restore - for images in container with ID=example2
//prepareImageSwap('example2',true,true,true,true);
//Hover, mousedown, no restore - for images in container with ID=example3
//prepareImageSwap('example3',true,false,true,false);
//Hover with restore, most basic usage - for any image in document.body that are not yet processed (function accepts elements,too)
prepareImageSwap(document.body);
//Note that once an image is processed, it won't be processed again, so you should set more specific images first, e.g. document.body, as it is the grand
//container, has to be processed last.
}


//The following is the function that do the actual job

function prepareImageSwap(elem,mouseOver,mouseOutRestore,mouseDown,mouseUpRestore,mouseOut,mouseUp) {
//Do not delete these comments.
//Non-Obtrusive Image Swap Script by Hesido.com
//V1.1
//Attribution required on all accounts
	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;}





/////////////////////////////////
// BEGIN HIGHLIGHT & FADE-OUT ON MOUSEOVER (IE ONLY) SCRIPT
// From photo album script
// Call function within an "<a href... >" tag like this:
//    style="filter:alpha(opacity=100)"
//    onmouseout="gradualfade(this,100,30,4)"
//    onmouseover="gradualfade(this,40,50,100)"
/////////////////////////////////
gradualfadeObjects = new Object();
gradualfadeTimers = new Object();
function gradualfade(object, final, speed, change) {
if (!document.all)
return
    if (object != "[object]"){
        setTimeout("gradualfade("+object+","+final+","+speed+","+change+")",0);
        return;
    }
        
    clearTimeout(gradualfadeTimers[object.sourceIndex]);
    
    diff = final-object.filters.alpha.opacity;
    direction = 1;
    if (object.filters.alpha.opacity > final){
        direction = -1;
    }
    change=Math.min(direction*diff,change);
    object.filters.alpha.opacity+=direction*change;

    if (object.filters.alpha.opacity != final){
        gradualfadeObjects[object.sourceIndex]=object;
        gradualfadeTimers[object.sourceIndex]=setTimeout("gradualfade(gradualfadeObjects["+object.sourceIndex+"],"+final+","+speed+","+change+")",speed);
        gradualfadeTimers[object.sourceIndex]=setTimeout("gradualfade(gradualfadeObjects["+object.sourceIndex+"],"+final+","+speed+","+change+")",speed);
    }
}





/////////////////////////////////
// BEGIN MSIE FIX FOR ACTIVEX (CLICK TO ACTIVATE) PROBLEM
// Posted by http://sixtwothree.org/blog/archives/2006/05/07/activateactivex-a-standards-based-solution-to-internet-explorers-active-content-woes
// (Can also try this website for a fix that includes Opera as well, but may have bugs: http://www.thefutureoftheweb.com/blog/2006/8/work-around-click-to-activate-and-use-this-control
/////////////////////////////////
/*  activateActiveX 1.1
	Copyright 2006 Jason Garber and Tavis Tucker
	This software is licensed under the CC-LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

/*
onDomReady : Runs a specified function when DOM is loaded

@param {String} func : The name of the function to be called
	You may also include parameters to be passed to the function e.g. onDomReady(myFunction(param1,param2));
	This can also be a function literal as in onDomReady(function() { more code to run on page load });

Source : brothercake's domFunction <http://www.brothercake.com/site/resources/scripts/domready/>
	and Dave Rolsky's DOM.Ready <http://www.openjsan.org/doc/a/au/autarch/DOM/Ready/0.14/lib/DOM/Ready.html>
*/

function onDomReady(func) {
	var t = setInterval( function() {
		if ( typeof document.getElementsByTagName != "undefined" && typeof document.getElementById != "undefined" && ( document.getElementsByTagName( "body" )[0] != null || document.body != null ) ) {
			if ( typeof func == "function" ) {
				func();
				clearInterval(t);
			}
		}
	}, 250 );
}


/*
activateActiveX : Activates ActiveX content for Internet Explorer 6.0+ to avoid requiring a user to click before using an object

Source : <http://sixtwothree.org/blog/archives/2006/05/20/activateactivex-11/>
*/

function activateActiveX() {
	if ( !document.getElementsByTagName || !document.body.outerHTML || !document.compatMode ) return false;
	var elems = new Array( "object", "applet" );
	for ( i = 0, j = elems.length; i < j; i++ ) {
		var objects = document.getElementsByTagName(elems[i]);
		for ( k = 0, l = objects.length; k < l; k++ ) {
			var params = "";
			for ( m = 0, n = objects[k].childNodes.length; m < n; m++ ) {
				params += objects[k].childNodes[m].outerHTML;
			}
			objects[k].outerHTML = objects[k].outerHTML.replace( "</" + elems[i].toUpperCase() + ">", params + "</" + elems[i].toUpperCase() + ">" );
		}
	}
}

onDomReady(activateActiveX);





/////////////////////////////////
// BEGIN EXTERNAL WINDOW OPENER FOR REL ATTRIBUTES
// adapted from http://www.sitepoint.com/article/standards-compliant-world/3
// Construct HTML Link like this:
// <a href... rel="external" instead of target="_blank"
/////////////////////////////////
function externalLinks() { 
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 
  for (var i=0; i<anchors.length; i++) { 
    var anchor = anchors[i]; 
    if (anchor.getAttribute("href") && 
        anchor.getAttribute("rel") == "external") 
      anchor.target = "_blank"; 
  } 
} 
window.onload = externalLinks;





