/////////////////////////////////
// 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 POPUP WINDOW SCRIPT
// Construct HTML Link like this:
// <a href="link.html" onClick="openWin('link.html','','scrollbars=no,resizable=yes,location=no,menubar=no,width=150,height=100,top=50,left=50'); return false">LINK</a>
/////////////////////////////////
function openWin(location,winName,features) {
window.open(location,winName,features);
}





/////////////////////////////////
// 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 SWITCH MENU SCRIPT
// Switch Menu script- by Martial B of http://getElementById.com/
// Modified by Dynamic Drive for format & NS4/IE4 compatibility
// Visit http://www.dynamicdrive.com/ for full source code
/////////////////////////////////
var persistmenu="yes" //"yes" or "no". Make sure each SPAN content contains an incrementing ID starting at 1 (id="sub1", id="sub2", etc)
var persisttype="sitewide" //enter "sitewide" for menu to persist across site, "local" for this page only

if (document.getElementById){ //DynamicDrive.com change
document.write('<style type="text/css">\n')
document.write('.submenu{display: none;}\n')
document.write('</style>\n')
}

function SwitchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("masterdiv").getElementsByTagName("span"); //DynamicDrive.com change
		if(el.style.display != "block"){ //DynamicDrive.com change
			for (var i=0; i<ar.length; i++){
				if (ar[i].className=="submenu") //DynamicDrive.com change
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}else{
			el.style.display = "none";
		}
	}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function onloadfunction(){
if (persistmenu=="yes"){
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=get_cookie(cookiename)
if (cookievalue!="")
document.getElementById(cookievalue).style.display="block"
}
}

function savemenustate(){
var inc=1, blockid=""
while (document.getElementById("sub"+inc)){
if (document.getElementById("sub"+inc).style.display=="block"){
blockid="sub"+inc
break
}
inc++
}
var cookiename=(persisttype=="sitewide")? "switchmenu" : window.location.pathname
var cookievalue=(persisttype=="sitewide")? blockid+";path=/" : blockid
document.cookie=cookiename+"="+cookievalue
}

if (window.addEventListener)
window.addEventListener("load", onloadfunction, false)
else if (window.attachEvent)
window.attachEvent("onload", onloadfunction)
else if (document.getElementById)
window.onload=onloadfunction

if (persistmenu=="yes" && document.getElementById)
window.onunload=savemenustate





/////////////////////////////////
// DO NOT USE THIS SCRIPT!!! USE NEXT ONE BELOW, MUCH MORE EFFICIENT THAN THIS ONE!
// BEGIN MSIE FIX FOR ACTIVEX (CLICK TO ACTIVATE) PROBLEM
// Posted by http://computerscorp.com/ie_cbx_fix/ie_cbx_fix.html
// Does not require extra javascript below last </object> tag, 
// and does not interfere with other onload functions.
/////////////////////////////////
// window.attachEvent( "onload", function() { document.body.innerHTML = document.body.innerHTML } );





/////////////////////////////////
// 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
// Less JavaScript intensive than previous method above
/////////////////////////////////
/*  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);



