﻿// ----------------------------------------------------------------------

// Javascript form validation routines.

// Author: Stephen Poley

//

// Simple routines to quickly pick up obvious typos.

// All validation routines return true if executed by an older browser:

// in this case validation must be left to the server.

//

// Update Jun 2005: discovered that reason IE wasn't setting focus was

// due to an IE timing bug. Added 0.1 sec delay to fix.

//

// Update Oct 2005: minor tidy-up: unused parameter removed

//

// Update Jun 2006: minor improvements to variable names and layout

// ----------------------------------------------------------------------



var nbsp = 160;		// non-breaking space char

var node_text = 3;	// DOM text node-type

var emptyString = /^\s*$/ ;

var global_valfield;	// retain valfield for timer thread



// --------------------------------------------

//                  trim

// Trim leading/trailing whitespace off string

// --------------------------------------------



function trim(str)

{

  return str.replace(/^\s+|\s+$/g, '');

}





// --------------------------------------------

//                  setfocus

// Delayed focus setting to get around IE bug

// --------------------------------------------



function setFocusDelayed()

{

  global_valfield.focus();

}



function setfocus(valfield)

{

  // save valfield in global variable so value retained when routine exits

  global_valfield = valfield;

  setTimeout( 'setFocusDelayed()', 100 );

}





// --------------------------------------------

//                  msg

// Display warn/error message in HTML element.

// commonCheck routine must have previously been called

// --------------------------------------------



function msg(fld,     // id of element to display message in

             msgtype, // class to give element ("warn" or "error")

             message) // string to display

{

  // setting an empty string can give problems if later set to a 

  // non-empty string, so ensure a space present. (For Mozilla and Opera one could 

  // simply use a space, but IE demands something more, like a non-breaking space.)

  var dispmessage;

  if (emptyString.test(message)) 

    dispmessage = String.fromCharCode(nbsp);    

  else  

    dispmessage = message;



  var elem = document.getElementById(fld);

  elem.firstChild.nodeValue = dispmessage;  

  

  elem.className = msgtype;   // set the CSS class to adjust appearance of message

}



// --------------------------------------------

//            commonCheck

// Common code for all validation routines to:

// (a) check for older / less-equipped browsers

// (b) check if empty fields are required

// Returns true (validation passed), 

//         false (validation failed) or 

//         proceed (don't know yet)

// --------------------------------------------



var proceed = 2;  



function commonCheck    (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  if (!document.getElementById) 

    return true;  // not available on this browser - leave validation to the server

  var elem = document.getElementById(infofield);

  if (!elem.firstChild) return true;  // not available on this browser 

  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node  



  if (emptyString.test(valfield.value)) {

    if (required) {

      msg (infofield, "error", "ERROR: required");  

      setfocus(valfield);

      return false;

    }

    else {

      msg (infofield, "warn", "");   // OK

      return true;  

    }

  }

  return proceed;

}



// --------------------------------------------

//            validatePresent

// Validate if something has been entered

// Returns true if so 

// --------------------------------------------



function validatePresent(valfield,   // element to be validated

                         infofield ) // id of element to receive info/error msg

{

  var stat = commonCheck (valfield, infofield, true);

  if (stat != proceed) return stat;



  msg (infofield, "warn", "");  

  return true;

}



// --------------------------------------------

//               validateEmail

// Validate if e-mail address

// Returns true if so (and also if could not be executed because of old browser)

// --------------------------------------------



function validateEmail  (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off

  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;

  if (!email.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid e-mail address");

    setfocus(valfield);

    return false;

  }



  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;

  if (!email2.test(tfld)) 

    msg (infofield, "warn", "Unusual e-mail address - check if correct");

  else

    msg (infofield, "warn", "");

  return true;

}





// --------------------------------------------

//            validateTelnr

// Validate telephone number

// Returns true if so (and also if could not be executed because of old browser)

// Permits spaces, hyphens, brackets and leading +

// --------------------------------------------



function validateTelnr  (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off

  var telnr = /^\+?[0-9 ()-]+[0-9]$/  ;

  if (!telnr.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid telephone number. Characters permitted are digits, space ()- and leading +");

    setfocus(valfield);

    return false;

  }



  var numdigits = 0;

  for (var j=0; j<tfld.length; j++)

    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;



  if (numdigits<6) {

    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");

    setfocus(valfield);

    return false;

  }



  if (numdigits>14)

    msg (infofield, "warn", numdigits + " digits - check if correct");

  else { 

    if (numdigits<10)

      msg (infofield, "warn", "Only " + numdigits + " digits - check if correct");

    else

      msg (infofield, "warn", "");

  }

  return true;

}



// --------------------------------------------

//             validateAge

// Validate person's age

// Returns true if OK 

// --------------------------------------------



function validateAge    (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);

  var ageRE = /^[0-9]{1,3}$/

  if (!ageRE.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid age");

    setfocus(valfield);

    return false;

  }



  if (tfld>=200) {

    msg (infofield, "error", "ERROR: not a valid age");

    setfocus(valfield);

    return false;

  }



  if (tfld>110) msg (infofield, "warn", "Older than 110: check correct");

  else {

    if (tfld<7) msg (infofield, "warn", "Bit young for this, aren't you?");

    else        msg (infofield, "warn", "");

  }

  return true;

}





// --------------------------------------------

//             validateZip

// Validate Zip Code

// Returns true if OK 

// --------------------------------------------



function validateZip    (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off

  

  var numdigits = 0;

  for (var j=0; j<tfld.length; j++)

    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;



  if (numdigits<5) {

    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");

    setfocus(valfield);

    return false;

  }

  if (numdigits>5 && numdigits <9) {

    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");

    setfocus(valfield);

    return false;

  }





  var zipnr = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  if (!zipnr.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid zip code. Characters permitted are digits and/or -");

    setfocus(valfield);

    return false;

  }





  if (numdigits>9)

    msg (infofield, "warn", numdigits + " digits - check if correct");

  else { 

    if (numdigits<9)

      msg (infofield, "warn", "Only " + numdigits + " digits - check if correct");

    else

      msg (infofield, "warn", "");

  }

  return true;

}



// --------------------------------------------

//               validateDate

// Validate if Date

// Returns true if so (and also if could not be executed because of old browser)

// --------------------------------------------



function validateDate   (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off

  var ddate = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/  ;

  if (!ddate.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid date");

    setfocus(valfield);

    return false;

  }

  else {

      msg (infofield, "warn", "");

  }

  return true;

}

// --------------------------------------------

//             validateNum

// Validate Zip Code

// Returns true if OK 

// --------------------------------------------



function validateNum    (valfield,   // element to be validated

                         infofield,  // id of element to receive info/error msg

                         required)   // true if required

{

  var stat = commonCheck (valfield, infofield, required);

  if (stat != proceed) return stat;



  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off

  

  var numdigits = 0;

  for (var j=0; j<tfld.length; j++)

    if (tfld.charAt(j)>='0' && tfld.charAt(j)<='9') numdigits++;



  if (numdigits<1) {

    msg (infofield, "error", "ERROR: " + numdigits + " digits - too short");

    setfocus(valfield);

    return false;

  }

  if (numdigits>4) {

    msg (infofield, "error", "ERROR: " + numdigits + " digits - too long");

    setfocus(valfield);

    return false;

  }


  var fldnr = /(^\d{1}$)|(^\d{2}$)|(^\d{3}$)/;

  if (!fldnr.test(tfld)) {

    msg (infofield, "error", "ERROR: not a valid number. Must be digits and less than 999");

    setfocus(valfield);

    return false;

  }

  if (numdigits>3)

    msg (infofield, "warn", numdigits + " digits - check if correct");

  else { 

    if (numdigits<1)

      msg (infofield, "warn", "Only " + numdigits + " digits - check if correct");

    else

      msg (infofield, "warn", "");

  }

  return true;

}


// ----------------------------------------------------------------------
// Javascript form validation routines.
// Author: Stephen Poley
//
// File 2: checkboxes
// Uses the msg routine from formval.js
// ----------------------------------------------------------------------


// -----------------------------------------
//            commonCheck2
// Common code for checkbox validation routines to
// check for older / less-equipped browsers
// Returns true (validation passed) or
//         proceed (don't know yet)
// -----------------------------------------

var proceed = 2;  

function commonCheck2   (vfld,   // element to be validated
                         ifld)   // id of element to receive info/error msg
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(ifld);
  if (!elem.firstChild)
    return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text)
    return true;  // ifld is wrong type of node  

  msg (ifld, "warn", "");  // clear any previous error message
  return proceed;
}



// -----------------------------------------
//            validateCheckbox
// Validate that the correct number of checkboxes has been checked.
// Returns true if valid (and also if could not be executed because 
// of old browser)
// -----------------------------------------

function validateCheckbox  (vfld,   // checkboxes to be validated
                            ifld,   // id of element to receive info/error msg
                            nr,     // number of checkboxes to be checked. >=2
                            cond)   // condition: -1 = less than or equal to nr
                                    //             0 = equal to nr (default)
                                    //             1 = greater than or equal to nr
{
  if (!nr || nr<2) {
    alert('Programming error in validateCheckbox: nr<2'); 
       // for nr=1 use radio buttons or validateConfirm
    return true;
  }
  if (!cond) cond = 0;

  var stat = commonCheck2(vfld, ifld);
  if (stat != proceed) return stat;

  // count how many boxes have been checked by the reader
  var count = 0;
  for (var j=0; j<vfld.length; j++)
     if (vfld[j].checked) count++;

  if (count==nr) return true;
  if (count<nr && cond==-1) return true;
  if (count>nr && cond==1)  return true;

  // if we get here then the validation has failed

  var suffix='';
  if (count>1) suffix='es';

  var errorMsg;

  if (count<nr) errorMsg = 'Only ' + count + ' box' + suffix + ' checked: ' + nr + ' required';
  if (count>nr) errorMsg = '' + count + ' boxes checked: maximum ' + nr + ' allowed';
  if (count==0) errorMsg = 'No boxes checked: ' + nr + ' required';

  msg (ifld, "error", errorMsg);
  return false;
}


// -----------------------------------------
//            validateConfirm 
// Usually one doesn't want to validate if 1 checkbox of a set has been
// checked, because in this case one would use radio buttons instead.
// But sometimes one wants a reader to check a single box to confirm that 
// he or she agrees to something. That is covered by this routine.
//
// Returns true if valid (and also if could not be executed because 
// of old browser)
// -----------------------------------------

function validateConfirm   (vfld,   // checkbox to be validated
                            ifld)   // id of element to receive info/error msg
{
  var stat = commonCheck2(vfld, ifld);
  if (stat != proceed) return stat;

  if (vfld.checked) return true;

  // if we get here then the validation has failed

  var errorMsg = 'Please read the above message and confirm you agree to it';

  msg (ifld, "error", errorMsg);
  return false;
}

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- (c) http://www.wyka-warzecha.com -->

<!-- Begin

		// THESE VARIABLES CAN BE CHANGED //
		var myMainMessage="  Try this out! The message just keeps repeating. Use it for announcements, news and other items! ";
		var speed=150;
		var scrollingRegion=50;
		// END CHANGEABLE VARIABLES //

var startPosition=0;
function mainTextScroller() {
        var mainMessage=myMainMessage;
        var tempLoc=(scrollingRegion*3/mainMessage.length)+1;
        if (tempLoc<1) {tempLoc=1}
        var counter;
        for(counter=0;counter<=tempLoc;counter++)
           mainMessage+=mainMessage;
document.mainForm.mainTextScroller.value=mainMessage.substring(startPosition,startPosition+scrollingRegion);
        startPosition++;
        if(startPosition>scrollingRegion) startPosition=0;
        setTimeout("mainTextScroller()",speed); }
//  End -->

// Andrew Urquhart : CountDown Timer : http://andrewu.co.uk/clj/countdown/
function CD_T(id,e)
{
	var n=new Date();
	CD_D(+n,id,e);
	setTimeout("CD_T('"+id+"',"+e+")",1100-n.getMilliseconds())
}

function CD_D(n,id,e)
{
	var ms=e-n;
	if(ms<=0) ms*=-1;
		var d=Math.floor(ms/864E5);
		ms-=d*864E5;
		var h=Math.floor(ms/36E5);
		ms-=h*36E5;
		var m=Math.floor(ms/6E4);
		ms-=m*6E4;
		var s=Math.floor(ms/1E3);
		CD_OBJS[id].innerHTML=d+" day"+(d==1?" ":"s ")+CD_ZP(h)+"h "+CD_ZP(m)+"m "+CD_ZP(s)+"s"
}

function CD_ZP(i)
{
	return(i<10?"0"+i:i)
}

function CD_Init()
{
	var pref="countdown";
	var objH=1;if(document.getElementById||document.all)
	{
		for(var i=1;objH;++i)
		{
			var id=pref+i;
			objH=document.getElementById?document.getElementById(id):document.all[id];
			if(objH&&(typeof objH.innerHTML)!='undefined')
			{
				var s=objH.innerHTML;
				var dt=CD_Parse(s);
				if(!isNaN(dt))
				{
					CD_OBJS[id]=objH;
					CD_T(id,dt.valueOf());
					if(objH.style)
					{
						objH.style.visibility="visible"
					}
				}
				else 
				{
					objH.innerHTML=s+"<a href=\"http://andrewu.co.uk/clj/countdown/\" title=\"Countdown Error:Invalid date format used,check documentation (see link)\">*</a>"
				}
			}
		}
	}
}

function CD_Parse(strDate)
	{
		var objReDte=/(\d{4})\-(\d{1,2})\-(\d{1,2})\s+(\d{1,2}):(\d{1,2}):(\d{0,2})\s+GMT([+\-])(\d{1,2}):?(\d{1,2})?/;
		if(strDate.match(objReDte))
		{
			var d=new Date(0);
			d.setUTCFullYear(+RegExp.$1,+RegExp.$2-1,+RegExp.$3);
			d.setUTCHours(+RegExp.$4,+RegExp.$5,+RegExp.$6);
			var tzs=(RegExp.$7=="-"?-1:1);
			var tzh=+RegExp.$8;
			var tzm=+RegExp.$9;
			if(tzh)
			{
				d.setUTCHours(d.getUTCHours()-tzh*tzs)
			}
			if(tzm)
			{
				d.setUTCMinutes(d.getUTCMinutes()-tzm*tzs)
			};
				return d
			}
			else 
			{
				return NaN
			}
		}
		var CD_OBJS=new Object()
		if(window.attachEvent)
		{
			window.attachEvent('onload',CD_Init)
		}
		else
		if(window.addEventListener)
		{
			window.addEventListener("load",CD_Init,false)
		}
		else 
		{
			window.onload=CD_Init
		}

	

//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
		if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
			ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
		}
		else{ //else if this is a sub level menu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    	ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
		}
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.visibility="visible"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.visibility="hidden"
    }
    }
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)

/***********************************************
* DHTML Billboard script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

//List of transitional effects to be randomly applied to billboard:
var billboardeffects=["GradientWipe(GradientSize=1.0 Duration=0.7)", "Inset", "Iris", "Pixelate(MaxSquare=5 enabled=false)", "RadialWipe", "RandomBars", "Slide(slideStyle='push')", "Spiral", "Stretch", "Strips", "Wheel", "ZigZag"]

//var billboardeffects=["Iris"] //Uncomment this line and input one of the effects above (ie: "Iris") for single effect.

var tickspeed=7000 //ticker speed in miliseconds (2000=2 seconds)
var effectduration=500 //Transitional effect duration in miliseconds
var hidecontent_from_legacy=1 //Should content be hidden in legacy browsers- IE4/NS4 (0=no, 1=yes).

var filterid=Math.floor(Math.random()*billboardeffects.length)

document.write('<style type="text/css">\n')
if (document.getElementById)
document.write('.billcontent{display:none;\n'+'filter:progid:DXImageTransform.Microsoft.'+billboardeffects[filterid]+'}\n')
else if (hidecontent_from_legacy)
document.write('#contentwrapper{display:none;}')
document.write('</style>\n')

var selectedDiv=0
var totalDivs=0

function contractboard(){
var inc=0
while (document.getElementById("billboard"+inc)){
document.getElementById("billboard"+inc).style.display="none"
inc++
}
}

function expandboard(){
var selectedDivObj=document.getElementById("billboard"+selectedDiv)
contractboard()
if (selectedDivObj.filters){
if (billboardeffects.length>1){
filterid=Math.floor(Math.random()*billboardeffects.length)
selectedDivObj.style.filter="progid:DXImageTransform.Microsoft."+billboardeffects[filterid]
}
selectedDivObj.filters[0].duration=effectduration/1000
selectedDivObj.filters[0].Apply()
}
selectedDivObj.style.display="block"
if (selectedDivObj.filters)
selectedDivObj.filters[0].Play()
selectedDiv=(selectedDiv<totalDivs-1)? selectedDiv+1 : 0
setTimeout("expandboard()",tickspeed)
}

function startbill(){
while (document.getElementById("billboard"+totalDivs)!=null)
totalDivs++
if (document.getElementById("billboard0").filters)
tickspeed+=effectduration
expandboard()
}

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

/*
JSTarget function by Roger Johansson, www.456bereastreet.com
*/
var JSTarget = {
	init: function(att,val,warning) {
		if (document.getElementById && document.createElement && document.appendChild) {
			var strAtt = ((typeof att == 'undefined') || (att == null)) ? 'class' : att;
			var strVal = ((typeof val == 'undefined') || (val == null)) ? 'non-html' : val;
			var strWarning = ((typeof warning == 'undefined') || (warning == null)) ? ' (opens in a new window)' : warning;
			var oWarning;
			var arrLinks = document.getElementsByTagName('a');
			var oLink;
			var oRegExp = new RegExp("(^|\\s)" + strVal + "(\\s|$)");
			for (var i = 0; i < arrLinks.length; i++) {
				oLink = arrLinks[i];
				if ((strAtt == 'class') && (oRegExp.test(oLink.className)) || (oRegExp.test(oLink.getAttribute(strAtt)))) {
					oWarning = document.createElement("em");
					oWarning.appendChild(document.createTextNode(strWarning));
					oLink.appendChild(oWarning);
					oLink.onclick = JSTarget.openWin;
				}
			}
			oWarning = null;
		}
	},
	openWin: function(e) {
		var event = (!e) ? window.event : e;
		if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
		else {
		    var oWin = window.open(this.getAttribute('href'), '_blank');
			if (oWin) {
				if (oWin.focus) oWin.focus();
				return false;
			}
			oWin = null;
			return true;
		}
	},
	/*
	addEvent function from http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html
	*/
	addEvent: function(obj, type, fn) {
		if (obj.addEventListener)
			obj.addEventListener(type, fn, false);
		else if (obj.attachEvent) {
			obj["e"+type+fn] = fn;
			obj[type+fn] = function() {obj["e"+type+fn]( window.event );}
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	}
};
JSTarget.addEvent(window, 'load', function(){JSTarget.init("rel","external","");});
/*
Slideshow function
*/

var slideShowSpeed = 3000
var crossFadeDuration = 3

var Pic = new Array() // don't touch this

Pic[0] = '../images/1-hot-summer/03-karaokeinthebarsls.jpg'
Pic[1] = '../images/1-hot-summer/99-SimplyTheBest.jpg'
Pic[2] = '../images/1-hot-summer/00-TheFoothillsClub.jpg'


var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
   preLoad[i] = new Image()
   preLoad[i].src = Pic[i]
}

function runSlideShow(){
   if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=2)"
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
      document.images.SlideShow.filters.blendTrans.Apply()      
   }
   document.images.SlideShow.src = preLoad[j].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   j = j + 1
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)
}

