////Alex Gray, Moonshine Communications (alex@moonshinecorp.com) Feb 2004
/////////////////////////////////////////////////////////////////////
var uaString = navigator.userAgent.toLowerCase();
//Get rid of IE MAC ASAP!!
if (uaString.indexOf("msie")>0 && uaString.indexOf("mac")>0)
{
	document.location.href="/browser.html";
}

var currString
OffsetBrowser = "safari"
browserTestPassed = true

function findUAStr(string)
{
	loc = uaString.indexOf(string) + 1;
	return loc;
}
function browsersniff()
{
	//Supports DOM?
	if (!document.getElementById || !document.createElement)
	{
		document.location.href="/browser.html";
	}

	//DO some Safari sniffing
	if(findUAStr(OffsetBrowser) > 0)
	{
		version = parseInt(uaString.substr(findUAStr(OffsetBrowser)+OffsetBrowser.length, uaString.length));
		isSafari = true
		if (version < 120)
		{
			if (confirm("Since you are using an older release of Safari, we recommend that you ugrade your browser \nWould you like to ugrade?"))
			{
					
			}
			else
			{
			//The user is using an old version of Safari, but still wants to see the site.
				alert("I advises you that your version of Safari contains bugs that may render parts of the site unavailable")
				document.location.href="/browser.html";
			}
		}
		}
	
	//And throw this one in for good measure
	testTable = document.createElement('table');
	if (!testTable.insertRow)
	{
		document.location.href="/browser.html";
	}


}



function AddBookmark(url, description){ 
    if(navigator.userAgent.indexOf('MSIE') >= 0 && navigator.userAgent.indexOf('Opera') < 0 && window.external.AddFavorite){ 
        window.external.AddFavorite(url, description); 
    } 
    else if (getEl('processor').outerHTML){ 
        document.body.innerHTML = '<'+'a id="processor" href="'+url+'" title="'+description+'" rel="sidebar">Processor<'+'a>' + document.body.innerHTML; 
        getEl('processor').click(); 
        getEl('processor').outerHTML = ''; 
    }
	else{
		alert("we aplogize, but your browser does not support this function. Goto bookmarks and add our site")
	
	}
    
} 

function storeCursorLocation(eventObj)
{
	if (!eventObj) eventObj = (window.event)?window.event:window.Event;
	lastCursorX = (eventObj.pageX)?eventObj.pageX:eventObj.clientX;
	lastCursorY = (eventObj.pageY)?eventObj.pageY:eventObj.clientY;
}


function getEl(e)
{
  if(typeof(e)!="string") return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else 
  {
    e=null;
  }
  return e;
}

function determineXwin()
{
	var x
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;

	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;

	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
	}
return x
}

function determineYwin()
{
	var y
	if (self.innerHeight) // all except Explorer
	{
		y = self.innerHeight;

	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		y = document.documentElement.clientHeight;

	}
	else if (document.body) // other Explorers
	{
		y = document.body.clientHeight;
	}
	return y
}

function determineXRes()
{
	var ResolutionWidth = window.screen.availWidth
	ResolutionWidth = parseInt(ResolutionWidth)
	return ResolutionWidth;
}

function determineYRes()
{
	var ResolutionHeight = window.screen.availHeight
	ResolutionHeight = parseInt(ResolutionHeight)
	return ResolutionHeight;
}

function popup (Path , WindowName ,Toolbar, Scrollbars , Width, Height) {
	LeftPos=determineXRes()
	LeftPos = Math.round(LeftPos/2)-(Width/2)
	TopPos=determineYRes()
	TopPos = Math.round(TopPos/2)-(Height/2)
	params = 'toolbar='+Toolbar +',location=no,directories=no,status=no,menubar=no,scrollbars='+Scrollbars+',width='+ Width+',height='+ Height+',left='+LeftPos+',top='+TopPos

	WindowName = window.open (Path ,WindowName,params)
}

function mainWin(page)
{
		Width = determineXRes()-100
		Height = determineYRes()-100
		LeftPos=determineXRes()
		LeftPos = Math.round(LeftPos/2)-(Width/2)
		TopPos=determineYRes()
		TopPos = Math.round(TopPos/2)-(Height/2)
		protoWin = window.open ("newsite.html" ,"main",'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,width='+Width+',height='+Height+',left='+LeftPos+',top='+TopPos)

}

// -the following code is from the X lib.Cross-Browser---

var xVersion='3.10',xOp7=false,xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) xNN4=true;
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}


function xShow(e) {
  if(!(e=getEl(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='inherit';
  else if(xDef(e.visibility)) e.visibility='show';
}
function xHide(e) {
  if(!(e=getEl(e))) return;
  if(e.style && xDef(e.style.visibility)) e.style.visibility='hidden';
  else if(xDef(e.visibility)) e.visibility='hide';
}

// Position:
function xMoveTo(e,iX,iY) {
  xLeft(e,iX);
  xTop(e,iY);
}

function xLeft(e,iX) {
  if(!(e=getEl(e))) return 0;
  var css=xDef(e.style);
  if (css && xDef(e.style.left) && typeof(e.style.left)=="string") {
    if(arguments.length>1) e.style.left=iX+"px";
    else {
      iX=parseInt(e.style.left);
      if(isNaN(iX)) iX=0;
    }
  }
  else if(css && xDef(e.style.pixelLeft)) {
    if(arguments.length>1) e.style.pixelLeft=iX;
    else iX=e.style.pixelLeft;
  }
  else if(xDef(e.left)) {
    if(arguments.length>1) e.left=iX;
    else iX=e.left;
  }
  return iX;
}
function xTop(e,iY) {
  if(!(e=getEl(e))) return 0;
  var css=xDef(e.style);
  if(css && xDef(e.style.top) && typeof(e.style.top)=="string") {
    if(arguments.length>1) e.style.top=iY+"px";
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=0;
    }
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(arguments.length>1) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  else if(xDef(e.top)) {
    if(arguments.length>1) e.top=iY;
    else iY=e.top;
  }
  return iY;
}


function xWidth(e,uW) {
  if(!(e=getEl(e)) || (uW && uW<0)) return 0;
  uW=Math.round(uW);
  var css=xDef(e.style);
  if(css && xDef(e.style.width,e.offsetWidth) && typeof(e.style.width)=="string") {
    if(arguments.length>1) xSetCW(e, uW);
    uW=e.offsetWidth;
  }
  else if(css && xDef(e.style.pixelWidth)) {
    if(arguments.length>1) e.style.pixelWidth=uW;
    uW=e.style.pixelWidth;
  }
  else if(xDef(e.clip) && xDef(e.clip.right)) {
    if(arguments.length>1) e.clip.right=uW;
    uW=e.clip.right;
  }
  else if(e.width)
  {
    uW = e.width
  }
  return uW;
}
function xHeight(e,uH) {
  if(!(e=getEl(e)) || (uH && uH<0)) return 0;
  uH=Math.round(uH);
  var css=xDef(e.style);
  if(css && xDef(e.style.height,e.offsetHeight) && typeof(e.style.height)=="string") {
    if(arguments.length>1) xSetCH(e, uH);
    uH=e.offsetHeight;
  }
  else if(css && xDef(e.style.pixelHeight)) {
    if(arguments.length>1) e.style.pixelHeight=uH;
    uH=e.style.pixelHeight;
  }
  else if(xDef(e.clip) && xDef(e.clip.bottom)) {
    if(arguments.length>1) e.clip.bottom=uH;
    uH=e.clip.bottom;
  }
  else if(e.height)
  {
    uH = e.height
  }
  return uH;
}


// Event:
function xAddEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=getEl(e))) return;
  eventType=eventType.toLowerCase();
  if((!xIE4Up && !xOp7) && e==window) {

  }
  var eh="e.on"+eventType+"=eventListener";
  if(e.addEventListener) e.addEventListener(eventType,eventListener,useCapture);
  else if(e.attachEvent) e.attachEvent("on"+eventType,eventListener);
  else if(e.captureEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.captureEvents(eval("Event."+eventType.toUpperCase())); }
    eval(eh);
  }

  else eval(eh);
}
function xRemoveEventListener(e,eventType,eventListener,useCapture) {
  if(!(e=getEl(e))) return;
  eventType=eventType.toLowerCase();
  if((!xIE4Up && !xOp7) && e==window) {
    if(eventType=='resize') { window.xREL=null; return; }
    if(eventType=='scroll') { window.xSEL=null; return; }
  }
  var eh="e.on"+eventType+"=null";
  if(e.removeEventListener) e.removeEventListener(eventType,eventListener,useCapture);
  else if(e.detachEvent) e.detachEvent("on"+eventType,eventListener);
  else if(e.releaseEvents) {
    if(useCapture||(eventType.indexOf('mousemove')!=-1)) { e.releaseEvents(eval("Event."+eventType.toUpperCase())); }
    eval(eh);
  }
  else eval(eh);
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=="" || typeof(arguments[i])=="undefined") return false;}
  return true;
}
///------End of XLIB
function moveObj()
{
 if (loaded) 
 {
  stopmoving() ;
  if ( ((xTop(panObject) - ydist ) >= 0) && (ydist<0) ) 
  {
    ydist = 0; 
  } else
  if ( ((xTop(panObject) - ydist ) <= ( yviewport - xHeight(panImgOne) ) ) && (ydist>0) ) 
  {
    ydist = 0; 
  }

  xMoveTo(panObject, xLeft(panObject) - xdist, xTop(panObject) - ydist);
 
  if (xLeft(panObject) > 0 )
  {
    xLeft(panObject, 0 - xWidth(panImgOne));
  } else 
  if (xLeft(panObject) < (0 - xWidth(panImgOne) ) ) 
  {
    xLeft(panObject, 0);
  } 


  initialized == true;
  if ((xdist != 0) || (ydist != 0))
  {
    mytimer = setTimeout("moveObj()",defaulttimeout);
  }
 }
 //window.status = "LeftPanObj:"+panObject.style.left+" -- TopPanObj:"+panObject.style.top+" --  speed:"+defaulttravel+" -- scrollfreeze:"+scrollFreeze
}

function isValidEmail(incoming) {
	var emailstring = incoming;
	var ampIndex = emailstring.indexOf("@");
	var afterAmp = emailstring.substring((ampIndex + 1), emailstring.length);
		// find a dot in the portion of the string after the ampersand only
	var dotIndex = afterAmp.indexOf(".");
		// determine dot position in entire string (not just after amp portion)
	dotIndex = dotIndex + ampIndex + 1;
		// afterAmp will be portion of string from ampersand to dot
	afterAmp = emailstring.substring((ampIndex + 1), dotIndex);
		// afterDot will be portion of string from dot to end of string
	var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
	var beforeAmp = emailstring.substring(0,(ampIndex));
		//old regex did not allow subdomains and dots in names
		//var email_regex = /^[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[\w\d\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~])*\@(((\w+[\w\d\-]*[\w\d]\.)+(\w+[\w\d\-]*[\w\d]))|((\d{1,3}\.){3}\d{1,3}))$/;
	var email_regex = /^\w(?:\w|-|\.(?!\.|@))*@\w(?:\w|-|\.(?!\.))*\.\w{2,3}/ 
		// index of -1 means "not found"
	if ((emailstring.indexOf("@") != "-1") &&
		(emailstring.length > 5) &&
		(afterAmp.length > 0) &&
		(beforeAmp.length > 1) &&
		(afterDot.length > 1) &&
		(email_regex.test(emailstring)) ) {
		  return true;
	} else {
			//alert("Please check your email address!");
			return false;
	}
}
function rollOn(image) {
	image = (image.src)?image:getEl(image);
	theImageSrc = image.src
	image.src = theImageSrc.replace(/Off/g,"On"); 
}

function rollOff(image) {
	image = (image.src)?image:getEl(image);
	theImageSrc = image.src
	image.src = theImageSrc.replace(/On/g,"Off"); 
}



//Querysting functions
function PageQuery(q) {
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
	for(var j=0; j < this.keyValuePairs.length; j++) {
		if(this.keyValuePairs[j].split("=")[0] == s)
		return this.keyValuePairs[j].split("=")[1];
	}
	return false;
}

	this.getParameters = function() {
	var a = new Array(this.getLength());
	for(var j=0; j < this.keyValuePairs.length; j++) {
		a[j] = this.keyValuePairs[j].split("=")[0];
	}
	return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}

function queryString(key){
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
