﻿// browser detection
var w3c=(document.getElementById)?true:false;
var ns4=(document.layers)?true:false;
var ie4=(document.all && !w3c)?true:false;
var ie5=(document.all && w3c)?true:false;
var ns6=(w3c && navigator.appName.indexOf("Netscape")>=0)?true:false;

// DHTML functions
var DHTML = (document.getElementById || document.all || document.layers);

// photo viewer
function showPic(obj, photo, caption, pcount) {
	 this.id = obj.id;
	 this.photo = obj.href;
	 this.caption = obj.title;
	 this.photocount = pcount;
	 
	 if(this.photocount) {				  
		 changeStyle(this.id, this.photocount);
		 
		 if (document.getElementById) {
			  document.getElementById(photo).src = this.photo;
			  document.getElementById(caption).innerHTML = this.caption;
			  
		  } // for ie
		  else if (document.all) {
			  document.all[photo].src = this.photo;
			  document.all[caption].innerHTML = this.caption;
			  
		  }	else { return true; }		  
	  }
		   
	  return false
}
// change active status
function changeStyle(obj, count) {
	
	var photoid = obj.split("_");
	 
	for(var i=1; i<=count; i++) {
		
		if(obj != (photoid[0]+"_"+i)) {
			var id = photoid[0]+"_"+i;
			if((document.getElementById && document.getElementById(id).className == "active") || document.all && document.all[id].className == "active") {
				document.getElementById(id).className = "";
			}							
		}
	}
	document.getElementById(obj).className = "active";												
}
					
//// print function testing for pc or mac
function printPage() 
{
	if (window.print) {	window.print();	} 
	else
	{ alert('To print on a Mac, use Command + P.');	}
}

function lightup(imgName)
 {
   if (document.images)
    {
      imgOn=eval(imgName + "_on.src");
      document[imgName].src= imgOn;
    }
 }

function turnoff(imgName)
 {
   if (document.images)
    {
      imgOff=eval(imgName + "_off.src");
      document[imgName].src= imgOff;
    }
 }

function getObj(name) {
	if (document.getElementById) {
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	} else
	if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	} else
	if (document.layers) {
		this.obj = document.layers[name];
		this.style = document.layers[name];
	}
}

// return document object by id;
function getobject(obj){
if (document.getElementById)
	return document.getElementById(obj)
else if (document.all)
	return document.all[obj]
}

// set obj class style
function setStyle(obj, className) {		
	if(getobject(obj).className != className) {
	getobject(obj).className = className;
	}
}

/// popup window function
function popup(URL,w,h) {

day = new Date();
id = day.getTime();

var width = w;
var height = h;

var left = ((screen.width-width)/2);
var top = ((screen.height-height)/2);

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');");
}

/// popup window function with name
function wpopup(URL,n,w,h) {

day = new Date();

var name = n;
var width = w;
var height = h;

var left = ((screen.width-width)/2);
var top = ((screen.height-height)/2);

var features = 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top;

//eval("page" + name + " = window.open(URL, '" + name + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + '');");
    
var popWin = window.open(URL, name, features);
popWin.focus();

}

function popWindow(url, name, features) 
{
    var host = location.hostname;
	window.top.name = "opener";
	var popupWin = window.open( url, name, features );
	
	if ( popupWin && popupWin.opener ) {
		if ( openerUrl )
		{
			popupWin.opener.location = openerUrl;
			popupWin.focus();
		}
	}
}


function enable_other()
{
	if (document.getElementById('clubs_other_check').checked)
	{
		document.getElementById('clubs_other').disabled = false;
		document.getElementById('clubs_other').focus();
	}
	else
	{
		document.getElementById('clubs_other').disabled = true;
		document.getElementById('clubs_other').value = "";
	}
}


/////
///onKeyPress="return numbersonly(this, event)";
/////

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;
	if (window.event){
		key = window.event.keyCode;
	}else if (e){
		key = e.which;
	}else{
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ){
		return true;
	}else if ((("+1234567890").indexOf(keychar) > -1)){
		return true;
	}else if (dec && (keychar == ".")){
		myfield.form.elements[dec].focus();
		return false;
	}else{
		return false;
	}
}

///// onKeyUp="numTyped(this.value,p3,'3')"
/// jump phone number fields
function numTyped(current, next,maxlen) {
  var len = current.length;
  if (len==maxlen) {
    next.focus();
  }
}

//// form validation
 
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
	{
		return (true)
	}
	else
	{
		return (false)
	}
}

 

/// functions for form validation script

function count_checkboxes(element_name)
{ 
	box_checked = 0;
	with (document.form) { 
		for (var i=0; i < elements.length; i++) { 
			if (elements[i].name == element_name)
				if (  elements[i].checked )
				{ 
						box_checked += 1;
				}
		}
	}
	return box_checked;
}
 
function chkAll(frm, arr, mark) {
  for (i = 0; i <= frm.elements.length; i++) {
   try{
     if(frm.elements[i].name == arr) {
       frm.elements[i].checked = mark;
     }
   } catch(er) {}
  }
}


function MM_findObj(n, d) { //v4.01
	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;
}



// news scroller 

function Scroll(LPos){
	var obj = MM_findObj('scroll');
	LPos = -1*(LPos-1)*siteOffset;
	moveScroll(obj,LPos)
}

function moveScroll(obj,pos){
	if(obj != null) {
		window.moveScrollAgain=function() {
			var currPos = parseInt(obj.style.left);
			var posDiff = currPos-Math.abs(pos);
			posDiff = Math.floor(posDiff/jump);
			obj.style.left=posDiff+"px";
			if(currPos!=pos){
				setTimeout("moveScrollAgain()",40);
			}
		}
		moveScrollAgain();
	}
}

var nIndex = 1;
var timerID = null;
function rotateNews(){
	var len = sites;
	if(nIndex > len)
		nIndex = 1;
	//document.getElementById('stories').innerHTML = newsArray[nIndex];
	Scroll(nIndex);
	nIndex++;
	timerID = setTimeout('rotateNews()',3600);
}
function pauseNews() {
	if (timerID != null) {
		clearTimeout(timerID);
		timerID = null;
	}
}

function playNews() {
	if (timerID == null) {
		timerID = setTimeout('rotateNews()', 3600);
	}
}
