// JavaScript Document
// Created by Raster Media - www.rastermedia.com


//shorthand for document.getElementById (BS)
/*********************************/
function $(id,d){
/*********************************/
	if(!d){
		d = document;
		return d.getElementById(id);
	}
}

// General Alert Box Confirmation---------------------------
function confirm_action ( message, action ) {
  input_box = confirm ( message );
  if ( input_box == true ) {
    window.location.href = action;
  }
 }

// Validate email address--------------------------------------
function validEmail(email) {
	invalidChars = " /:,;";

	if (email == "") {						// cannot be empty
		return false;
	}

	for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (email.indexOf(badChar,0) > -1) {
			return false;
		}
	}

	atPos = email.indexOf("@",1)			// there must be one "@" symbol

	if (atPos == -1) {
		return false;
	}

	if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
		return false;
	}

	periodPos = email.indexOf(".",atPos);

	if (periodPos == -1) {					// and at least one "." after the "@"
		return false;
	}

	if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
		return false
	}
	return true;
}

// General PopUp Window-------------------------------------
function new_window(url,wx,hx) {
    newwin = window.open(url,"win",'toolbar=0,location=0,directories=0,scrollbars=1,resizable=1,status=1,menubar=1,width='+wx+',height='+hx);
}

// DropDown Menu Script--------------------------------------
//var myMenu1 = new SlideOutMenu("menu1", "down", 0, 8, 180, 800)
//var myMenu2 = new SlideOutMenu("menu2", "down", 0, 8, 180, 800)
//var myMenu3 = new SlideOutMenu("menu3", "down", 0, 8, 180, 800)
//var myMenu4 = new SlideOutMenu("menu4", "down", 0, 8, 180, 800)
//var myMenu5 = new SlideOutMenu("menu5", "down", 0, 8, 180, 800)
//var myMenu6 = new SlideOutMenu("menu6", "down", 0, 8, 180, 800)
//var myMenu6 = new SlideOutMenu("menu7", "down", 0, 8, 180, 800)
//var myMenu6 = new SlideOutMenu("menu8", "down", 0, 8, 180, 800)
//var myMenu6 = new SlideOutMenu("menu9", "down", 0, 8, 180, 800)
//var myMenu6 = new SlideOutMenu("menu10", "down", 0, 8, 180, 800)
//
//SlideOutMenu.writeCSS();


// jump menu--------------------------------------------------
function jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=selObj.selectedIndex;
}


// preload images and rollover scripts------------------------
function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


document.getElementsByWhatever = function(whatever,includeTextNodes) {
	if(!document.getElementsByTagName("*")) {
		// safari has no idea what that asterix means - return an array who's first index is -1
		// so the calling function will know that the browser cant handle this
		return new Array(-1);
	}
	// change "whatever" to lowercase if its not an int.
	if(!parseInt(whatever))whatever = whatever.toLowerCase();
	// this array will contain all of the object references.
	objArray = new Array();
	// loop over the document
	for(_i=0;_i<document.getElementsByTagName("*").length;_i++) {
		// this variable set to 1 when an object is added to objArray so we
		// dont double/triple up on object references if they meet more than one condition
		inArray = 0;
		// assign this object to a reference variable
		obj = document.getElementsByTagName("*")[_i];
		// check attributes and values for "whatever"
		if(obj.tagName != "!") { // IE freaks out over HTML comments - dont check for attributes if that's what this tag is.
			for(_w=0;_w<obj.attributes.length;_w++) {
				// IE will list all attributes, regardless of if they defined in the HTML, so check that they are defined.
				if(obj.attributes[_w].value) {
					// if the objects attribute name or its value equal "whatever", add it to objArray
					if(obj.attributes[_w].name.toLowerCase() == whatever || obj.attributes[_w].value.toLowerCase() == whatever) {
						objArray[objArray.length] = obj;
						inArray=1;
						break;
					}
				}
			}
		}
		// check tag names for "whatever"
		if(obj.tagName.toLowerCase() == whatever && !inArray) {
				objArray[objArray.length]=obj;
				inArray=1;
		}
		// check text nodes for "whatever".
		if(obj.childNodes.length && !inArray && includeTextNodes) {
			for(_w=0;_w<obj.childNodes.length;_w++) {
				if(obj.childNodes[_w].nodeType == 3 && obj.childNodes[_w].data) {
					cData = obj.childNodes[_w].data.toLowerCase();
					if(cData.indexOf(whatever)>-1) {
						objArray[objArray.length] = obj;
						inArray=1;
						break;
					}
				}
			}
		}
	}
	// send the object reference array back to the caller
	return objArray;
}

// Enable/Disable form elements----------------------------------------
function disable_enable(id){
	z = document.getElementsByWhatever(id,0);
	for(i=0; i<z.length; i++){
	  daname = z[i];
	  if(daname.className != 'disabled'){
	    daname.className = 'disabled';
	  } else {
		  daname.className = '';
	  }
	  daname.disabled=!daname.disabled;
	}
}

function getElementsByClass(node,searchClass,tag) {
 var classElements = new Array();
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
 for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
   }
  }
  return classElements;
}

function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

//bookmark script
function addBookmark(title,url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) {
		window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
		return true;
	}
}


// toggles the visibility of a div
function toggle( targetId ){
  if (document.getElementById){
        target = document.getElementById( targetId );
           if (target.style.display == "none"){
              target.style.display = "block";
           } else {
              target.style.display = "none";
           }
   }
}