var TINY={};
TINY.box=function(){
	var j,m,b,g,v,p=0;
	return{
		show:function(o){
			v={opacity:70,close:1,animate:1,fixed:1,mask:1,maskid:'',boxid:'',topsplit:2,url:0,post:0,height:0,width:0,html:0,iframe:0};
			for(s in o){v[s]=o[s]}
			if(!p){
				j=document.createElement('div'); j.className='tbox';
				p=document.createElement('div'); p.className='tinner';
				b=document.createElement('div'); b.className='tcontent';
				m=document.createElement('div'); m.className='tmask';
				g=document.createElement('div'); g.className='tclose'; g.v=0;
				document.body.appendChild(m); document.body.appendChild(j); j.appendChild(p); p.appendChild(b);
				m.onclick=g.onclick=TINY.box.hide; window.onresize=TINY.box.resize
			}else{
				j.style.display='none'; clearTimeout(p.ah); if(g.v){p.removeChild(g); g.v=0}
			}
			p.id=v.boxid; m.id=v.maskid; j.style.position=v.fixed?'fixed':'absolute';
			if(v.html&&!v.animate){
				p.style.backgroundImage='none'; b.innerHTML=v.html; b.style.display='';
				p.style.width=v.width?v.width+'px':'auto'; p.style.height=v.height?v.height+'px':'auto'
			}else{
				b.style.display='none'; 
				if(!v.animate&&v.width&&v.height){
					p.style.width=v.width+'px'; p.style.height=v.height+'px'
				}else{
					p.style.width=p.style.height='100px'
				}
			}
			if(v.mask){this.mask(); this.alpha(m,1,v.opacity)}else{this.alpha(j,1,100)}
			if(v.autohide){p.ah=setTimeout(TINY.box.hide,1000*v.autohide)}else{document.onkeyup=TINY.box.esc}
		},
		fill:function(c,u,k,a,w,h){
			if(u){
				if(v.image){
					var i=new Image(); i.onload=function(){w=w||i.width; h=h||i.height; TINY.box.psh(i,a,w,h)}; i.src=v.image
				}else if(v.iframe){
					this.psh('<iframe src="'+v.iframe+'" width="'+v.width+'" frameborder="0" height="'+v.height+'"></iframe>',a,w,h)
				}else{
					var x=window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
					x.onreadystatechange=function(){
						if(x.readyState==4&&x.status==200){p.style.backgroundImage=''; TINY.box.psh(x.responseText,a,w,h)}
					};
					if(k){
    	            	x.open('POST',c,true); x.setRequestHeader('Content-type','application/x-www-form-urlencoded'); x.send(k)
					}else{
       	         		x.open('GET',c,true); x.send(null)
					}
				}
			}else{
				this.psh(c,a,w,h)
			}
		},
		psh:function(c,a,w,h){
			if(typeof c=='object'){b.appendChild(c)}else{b.innerHTML=c}
			var x=p.style.width, y=p.style.height;
			if(!w||!h){
				p.style.width=w?w+'px':''; p.style.height=h?h+'px':''; b.style.display='';
				if(!h){h=parseInt(b.offsetHeight)}
				if(!w){w=parseInt(b.offsetWidth)}
				b.style.display='none'
			}
			p.style.width=x; p.style.height=y;
			this.size(w,h,a)
		},
		esc:function(e){e=e||window.event; if(e.keyCode==27){TINY.box.hide()}},
		hide:function(){TINY.box.alpha(j,-1,0,3); document.onkeypress=null; if(v.closejs){v.closejs()}},
		resize:function(){TINY.box.pos(); TINY.box.mask()},
		mask:function(){m.style.height=this.total(1)+'px'; m.style.width=this.total(0)+'px'},
		pos:function(){
			var t;
			if(typeof v.top!='undefined'){t=v.top}else{t=(this.height()/v.topsplit)-(j.offsetHeight/2); t=t<20?20:t}
			if(!v.fixed&&!v.top){t+=this.top()}
			j.style.top=t+'px'; 
			j.style.left=typeof v.left!='undefined'?v.left+'px':(this.width()/2)-(j.offsetWidth/2)+'px'
		},
		alpha:function(e,d,a){
			clearInterval(e.ai);
			if(d){e.style.opacity=0; e.style.filter='alpha(opacity=0)'; e.style.display='block'; TINY.box.pos()}
			e.ai=setInterval(function(){TINY.box.ta(e,a,d)},20)
		},
		ta:function(e,a,d){
			var o=Math.round(e.style.opacity*100);
			if(o==a){
				clearInterval(e.ai);
				if(d==-1){
					e.style.display='none';
					e==j?TINY.box.alpha(m,-1,0,2):b.innerHTML=p.style.backgroundImage=''
				}else{
					if(e==m){
						this.alpha(j,1,100)
					}else{
						j.style.filter='';
						TINY.box.fill(v.html||v.url,v.url||v.iframe||v.image,v.post,v.animate,v.width,v.height)
					}
				}
			}else{
				var n=a-Math.floor(Math.abs(a-o)*.5)*d;
				e.style.opacity=n/100; e.style.filter='alpha(opacity='+n+')'
			}
		},
		size:function(w,h,a){
			if(a){
				clearInterval(p.si); var wd=parseInt(p.style.width)>w?-1:1, hd=parseInt(p.style.height)>h?-1:1;
				p.si=setInterval(function(){TINY.box.ts(w,wd,h,hd)},20)
			}else{
				p.style.backgroundImage='none'; if(v.close){p.appendChild(g); g.v=1}
				p.style.width=w+'px'; p.style.height=h+'px'; b.style.display=''; this.pos();
				if(v.openjs){v.openjs()}
			}
		},
		ts:function(w,wd,h,hd){
			var cw=parseInt(p.style.width), ch=parseInt(p.style.height);
			if(cw==w&&ch==h){
				clearInterval(p.si); p.style.backgroundImage='none'; b.style.display='block'; if(v.close){p.appendChild(g); g.v=1}
				if(v.openjs){v.openjs()}
			}else{
				if(cw!=w){p.style.width=(w-Math.floor(Math.abs(w-cw)*.6)*wd)+'px'}
				if(ch!=h){p.style.height=(h-Math.floor(Math.abs(h-ch)*.6)*hd)+'px'}
				this.pos()
			}
		},
		top:function(){return document.documentElement.scrollTop||document.body.scrollTop},
		width:function(){return self.innerWidth||document.documentElement.clientWidth||document.body.clientWidth},
		height:function(){return self.innerHeight||document.documentElement.clientHeight||document.body.clientHeight},
		total:function(d){
			var b=document.body, e=document.documentElement;
			return d?Math.max(Math.max(b.scrollHeight,e.scrollHeight),Math.max(b.clientHeight,e.clientHeight)):
			Math.max(Math.max(b.scrollWidth,e.scrollWidth),Math.max(b.clientWidth,e.clientWidth))
		}
	}
}();
/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};
/*  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;
}
function prependElement(parentID,child) {
	// Create The Element Dynamically. Here we are creating  Div   
	//var ele=document.createElement("div");
	// Assume our Parent Element  ID is  container
	// So  function  goes like below 
	//prependElement('container',ele)
	parent=document.getElementById(parentID);
	parent.insertBefore(child,parent.childNodes[0]);
}
function appendElement(parentID,child) {
	// Create The Element Dynamically. Here we are creating  Div   
	//var ele=document.createElement("div");
	// Assume our Parent Element  ID is  container
	// So  function  goes like below 
	//appendElement('container',ele)
	parent=document.getElementById(parentID);
	parent.appendChild(child);
}
/*
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/
Move.element('e', 'target', 'type');
*/
var Move =	{
  copy	:   function(e, target)	{
	    var eId      = document.getElementById(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'; }
	    }
	    document.getElementById(target).appendChild(copyE);
	},
  element:  function(e, target, type)	{
	    var eId =  document.getElementById(e);
	    if(type == 'move') {
	       document.getElementById(target).appendChild(eId);
	    }

	    else if(type == 'copy')	{
	       this.copy(e, target);
	    }
	}
}
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    };
  }
}
function concat_collection(obj1, obj2) {
	var i;
	var arr = new Array();
	var len1 = obj1.length;
	var len2 = obj2.length;
	for (i=0; i<len1; i++) {
		arr.push(obj1[i]);
	}
	for (i=0; i<len2; i++) {
		arr.push(obj2[i]);
	}
	return arr;
}
function visirMe() {
	var anchors = getElementsByClassName("hider");
	for (var i=0; i<anchors.length; i++) {
		anchors[i].style.display = 'inline-block';
	}
} addLoadEvent(visirMe);
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var atags = document.getElementsByTagName("a");
	var areas = document.getElementsByTagName("area");
	var anchors = concat_collection(atags, areas);
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if( (anchor.rel == "externalLink") || (anchor.getAttribute("class") == "externalLink") ) {
			anchor.onclick = function(){
				if (this.href.match(/^http\:/i)) {
					var awr = "/cgi-bin/awredir.pl?url=";
					//var openMe = window.open(awr + this.href,'externalLink');
					window.location = awr + this.href;
					return false;
				}
			}
		}
	}
} addLoadEvent(externalLinks);
function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name) { return unescape(y); }
	}
}
function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function setNavigators() {
	if (document.getElementById("premon")) {
		var premon = document.getElementById("premon");
		premon.onclick = function() {
			var myDate = this.rel;
			//console.log(myDate);
			ajaxChangeCalendar( myDate );
			return false;
		};
	}
	if (document.getElementById("nexmon")) {
		var nexmon = document.getElementById("nexmon");
		nexmon.onclick = function() {
			var myDate = this.rel;
			ajaxChangeCalendar( myDate );
			return false;
		};
	}
	return;
}
function checkCal() { 
	if (!document.getElementById('eventCal')) return;
	var myCalDate=getCookie("calDate"); 
	if (myCalDate!=null && myCalDate!="") { 
		ajaxChangeCalendar( myCalDate );
	}
}
function ajaxChangeCalendar( date ) {
	var loader = dhtmlxAjax.getSync("/" + "calendar" + ".xml?MY=" + date);
	if(loader.xmlDoc.responseXML!=null) {
		document.getElementById("eventCal").innerHTML = loader.xmlDoc.responseXML.getElementsByTagName("calendar")[0].childNodes[0].nodeValue;
		setCookie("calDate",date,1);
	}
	setNavigators();
	openBox();
	return false;
}
function openBox() {
	var areas1 = getElementsByClassName("evc","a");
	var areas2 = getElementsByClassName("mi","a");
	var areas = concat_collection(areas1, areas2);
	for (var i=0; i<areas.length; i++) {
		areas[i].onclick = function(){
			TINY.box.show({url:this.href+'?ID=sm',width:600,height:400,boxid:'eventBox'});
			return false;
		};
	}
	var adPops = getElementsByClassName("ads","a");
	for (var i=0; i<adPops.length; i++) {
		adPops[i].onclick = function(){
			TINY.box.show({image:this.href});
			return false;
		};
	}
}
function cancelButton() {
	if (!document.getElementById("cancelButton")) return;
	if (!document.getElementById("contactform")) return;
	var myButton = document.getElementById("cancelButton");
	myButton.style.display = "inline-block";
	myButton.onclick = function(){
		var myForm = document.getElementById("contactform");
		if ( myForm.cancel_return.value.length > 0 )
			window.location = myForm.cancel_return.value;
		return false;
	};
}
function updateInstructions() {
	if (document.getElementById("payType")) {
		var selectIst = document.getElementById("payType");
		selectIst.onchange = function() {
			var myOption = this.options[this.selectedIndex];
			var myDiv = 'ist_'+myOption.value;
			var myDivs = getElementsByClassName("payInstructions","div");
			for (var i=0; i<myDivs.length; i++) myDivs[i].style.display='none';
			if (document.getElementById(myDiv)) document.getElementById(myDiv).style.display='block';
			return false;
		};
	}
	return;
}
function autotab(){
	var phoneFields = getElementsByClassName("phonenumber","input");
	for (var i=0; i<phoneFields.length; i++) {
		phoneFields[i].onkeyup = function(){
			if(this.getAttribute("maxlength")&&this.getAttribute("rel")) {
				destination=this.getAttribute("rel");
				if(document.getElementById(destination)) {
					if (this.value.length==this.getAttribute("maxlength")) document.getElementById(destination).focus();
				}
			}
		};
	}
}
