<!-- Hide from old browsers
// Unless otherwise noted, all JavaScript is copyright 
// (c) SilverDisc Ltd 1996-2003: all rights reserved. 

// Handle screen redraw problems in Navigator
if (navigator.appName=="Netscape")
{
  window.captureEvents(Event.RESIZE);
  window.onresize=function (evt){location.reload(); };
}

function newWindow(name,url,width,height,controls) 
{
  var param="width="+width+",height="+height;
  var winref;
  param=param+",resizable";
  if (controls =="SCROLL")
  {
    param=param+",scrollbars";
  }
  if (controls =="ALL")
  {
    param=param+",menubar,toolbar,location,status,scrollbars";
  }
  if (controls =="PRINT")
  {
    param=param+",menubar,scrollbars";
  }
  winref=window.open(url,name,param);
}

function doMailto()
{
var str="%0d%0d";
if (navigator.appName.indexOf("Microsoft Internet Explorer") != -1)
{
 //alert("Version:"+navigator.appVersion+" , "+navigator.appName);
 
 if (navigator.appVersion.indexOf("5.5") == -1) str="%250d%250d";
}
document.write('<A HREF="mailto:?subject=Auridian Consulting&body=Hi, '+str+'I think you will find this IT training company of interest: '+str+'http://www.auridian.com/ '+str+'The page I was looking at was called: '+str+'\''+document.title+'\' '+str+'and is at: '+str+escape(window.location.href)+' '+str+'Regards">');

}

function add2FavoritesHome(rootURL)
{
    if ((navigator.appName.indexOf("Microsoft Internet Explorer") != -1) && 
        (parseInt(navigator.appVersion) > 3)) 
    {
        document.write('<A class="spmenuentry" HREF="#" onclick="window.external.AddFavorite(window.location.href,document.title);return false;">Add to Favorites</A>');
    }
}

function add2Favorites(rootURL)
{
    if ((navigator.appName.indexOf("Microsoft Internet Explorer") != -1) && 
        (parseInt(navigator.appVersion) > 3)) 
    {
        document.write('<A HREF="#" onclick="window.external.AddFavorite(window.location.href,document.title);return false;"><IMG SRC="'+rootURL+'gifs/add2fav.gif" BORDER="0" ALT="Click here to add this page to your favorites"></A>');
    }
}

function showUKTime()
{
  var now= new Date();
  var ukTime=now.toGMTString();

  document.write("<CENTER>UK TIME<BR>" + ukTime + "</CENTER>");
}
function selectAll(theForm)
{
 for (var i=0; i < theForm.elements.length; i++)
 {
  if ( theForm.elements[i].type=="checkbox" )
  {
       theForm.elements[i].checked=true;
  }
 }
 return false;
}

function invertAll(theForm)
{
 for (var i=0; i < theForm.elements.length; i++)
 {
  if ( theForm.elements[i].type=="checkbox" )
  {
       if (theForm.elements[i].checked)
       {
           theForm.elements[i].checked=false;
       }
       else
       {
           theForm.elements[i].checked=true;
       }
  }
 }
 return false;
}

var nextVacantSlot=0;
var maxImageSlots=4;
var theSlotMapping= new Array(maxImageSlots);
var maxImageRange=8;
var thePictureNames= new Array(maxImageRange);
var preloadedImages = new Array();

var theDoc = null;
var timerID = null;
var timerRunning = false;
var timerInt = 1; // Timer interval in seconds

function findImages(doc, theImageName, clientID)
{
  // Look for the optional additional images
  var theBaseURL="http://www.motorplexuk.com:8080/motorplex/imgupload/servers/"+clientID+"/uploads/img/";
  var splitImageName = theImageName.split("-");
  var imageNum=parseInt(splitImageName[0],16);
  var imageNumStr="";
  var imgIdx=0;
  if ((theImageName != "") && (theImageName != "nopic.jpg"))
  {
  if ((navigator.appName.indexOf("Microsoft Internet Explorer") != -1)&&(parseInt(navigator.appVersion) >= 4))
  {
    // IE4 or greater so go ahead and support multi image
    preloadedImages[imgIdx]=new Image;
    thePictureNames[imgIdx]=theBaseURL+theImageName;
    preloadedImages[imgIdx].src=theBaseURL+theImageName;
    for (imgIdx=1; imgIdx<maxImageRange; imgIdx++)
    {
      imageNum=imageNum+1;
      imageNumStr=imageNum.toString(16);
      splitImageName[0] = (imageNumStr.length < 8) ? '0'+imageNumStr:imageNumStr;
      //alert(splitImageName[0]);
      thePictureNames[imgIdx]=splitImageName.join("-");
      preloadedImages[imgIdx]=new Image;
      preloadedImages[imgIdx].src=theBaseURL+thePictureNames[imgIdx];
      //alert(thePictureNames[imgIdx]);
    }
    theDoc=doc;
    checkPictures();
    timerRunning = true;
    timerID = setInterval("checkPictures()",timerInt*1000)
  }
  }
}

function setImage(doc,num)
{
  if (nextVacantSlot > num)
  {
    if ((navigator.appName.indexOf("Microsoft Internet Explorer") != -1)&&(parseInt(navigator.appVersion) >= 4))
    {
      doc.images["picMain"].src=preloadedImages[theSlotMapping[num]].src;
    }
  }
  return false;
}

function checkPictures()
{
  if ((nextVacantSlot < maxImageSlots) && (preloadedImages[0].complete!=null))
  {
   for (imgIdx=0; imgIdx<maxImageRange; imgIdx++)
   {
     //alert(preloadedImages[imgIdx].complete)
     if (preloadedImages[imgIdx].complete)
     {
       if ((thePictureNames[imgIdx] != "") && (nextVacantSlot < maxImageSlots))
       {
        var imgName="pic"+nextVacantSlot.toString(10);
        var imgRef=theDoc.images[imgName];
        //alert(imgName);
        imgRef.src=preloadedImages[imgIdx].src;
        theSlotMapping[nextVacantSlot] = imgIdx;
        nextVacantSlot=nextVacantSlot+1;
        thePictureNames[imgIdx] = "";
       }
     }
   }
  }
  else
  {
    // Found 4 images so stop timer
    timerRunning = false;
    clearInterval(timerID);
    timerID = null;
  }
}

// Data validation functions:

// Check whether string is empty or all white-space
function IsEmptyString(s)
{
    var i;

    // Quick checks for complete emptiness
    if(s == null) return true;
    if(s.length == 0) return true;
    
    // Look for non-whitespace in the string
    for(i = 0; i < s.length; i++)
    {
        // Check next character isn't empty
        var c = s.charAt(i);
        if(c != " " || c != "\t" || c != "\n" || c != "\r")
        {
            // Non-white space found - it's non-empty
            return false;
        }
    }
    // No non-space characters found - string is empty
    return true;
}


// Check for valid email address. Expect to see something like
// [A-Za-z0-9.]@[A-Za-z0-9].[A-Za-z0-9.] (i.e. xxx@yyy.zzz will do
// fine). To check this quickly, walk through looking for an '@'.
// Once found, start looking for a '.'.
function IsValidEmail(s)
{
    var i;
    
    // Quick check - is it empty?
    if(IsEmptyString(s))
    {
        return false;
    }

    // Look for @ 
    for(i = 0; i < s.length; i++)
    {
        if(s.charAt(i) == "@") break;
    }
    // Then look for .
    for( ; i < s.length; i++)
    {
        if(s.charAt(i) == ".") return true;

    }
    // Off the end? Missed either @ or .
    return false;
}

// Check for valid phone number. First character can be "+" (for
// international dialling). After that we only allow [0-9()[]- ]
function IsValidPhone(s)
{
    var i;

    // Quick check...
    // if(IsEmptyString(s)) return false;  // Check if empty

    // Check first character...
    i = 0;
    if(s.charAt(i) == "+")
    {
        i = 1;      // That's OK, don't check it again
    }

    // Check the rest...
    var validChars = "0123456789 -()[]";
    for( ; i < s.length; i++)
    {
        var c = s.charAt(i);
        if(validChars.indexOf(c) == -1)
        {
            return false;       // Invalid character
        }       
    }

    return true;    // If we get here the number is OK
}

function ValidatePhone(number, prompt, item)
{
    if(!IsValidPhone(number))
    {
        // Get the user to confirm he has no such number
        var msg;
        msg = "You have not entered a valid " + 
                    prompt + " number. ";
        msg += "Press 'OK' if you want to " +
                    (IsEmptyString(number) ? "enter" : "edit") +
                    " the number " +
                    "before submitting your details";

        if(confirm(msg))
        {
            if(item != null)
            {
                item.focus();
                item.select();
            }
            return false;
        }
    }
    return true;    // OK if we get out here
}


function validateContact(frm)
{

    // Check that some sensible data has been entered
    // in key fields

    if(IsEmptyString(frm.username.value))
    {
        alert("Please tell us your name.");
        frm.username.focus();
        frm.username.select();
        return false;
    }

    if ((IsEmptyString(frm.telephone.value)) && (IsEmptyString(frm.email.value)))
    {
        alert("Please specify an email address and/or phone number.");
        return false;
    }

    // If phone number given, check it.
    if (!IsEmptyString(frm.telephone.value))
    {
        if(!ValidatePhone(frm.telephone.value, "phone number", frm.telephone))
        {
            return false;
        }
    }

    // If email given, check it.
    if (!IsEmptyString(frm.email.value))
    {
        if(!IsValidEmail(frm.email.value))
        {
            alert("Please specify a valid email address. e.g. yourname@company.com");
            frm.email.focus();
            frm.email.select();
            return false;
        }
    }

    // OK! Let the form submit itself
    return true;
}

var nextPic = 1;
var pauseTime = 3000;
var imageDirectory = "";
var thumbDirectory = "";
var numPics=0;
	
function createPlayer() {
	noOfArguments = arguments.length;
	rotatorFlag = arguments[noOfArguments - 1];
	numPics= noOfArguments - 2;
	imageDirectory=arguments[noOfArguments - 2];
	thumbDirectory=arguments[noOfArguments - 2];
	if ((!(document.getElementById)) | (numPics==1))
	{
          // Support older browsers with plain image
	  document.write('<img src="'+imageDirectory+arguments[0]+'.med">');
	  return;
	}
	document.write('<div id="player">');
	document.write('<span id="playpause"></span>');
	document.write('<span id="thumbs"></span>');
	document.write('<span id="mainwin"></span>');
	document.write('</div>');

	thumbsWin = document.getElementById("thumbs");
	mainWin = document.getElementById("mainwin");

			
	rotatorImages = new Array()
	rotatorThumbs = new Array()
	for (f=0; f<(noOfArguments - 2); f++) {
		rotatorImages[f] = new Image()
		rotatorImages[f].src = imageDirectory + arguments[f] + ".lrg"
		rotatorThumbs[f] = new Image()
		rotatorThumbs[f].src = thumbDirectory + arguments[f] + ".thm"
	}

	
	thumbHTML = ""
	for (f=0; f<this.rotatorThumbs.length; f++) {
		thumbHTML += "<a href=\"javascript:swapPicAndPause(" + f + ")\"><img align=\"right\" src=\"" + rotatorThumbs[f].src + "\" width=\"64\"></a>"
		if ((this.rotatorThumbs.length > 5) && ((f+1) == ((this.rotatorThumbs.length - (this.rotatorThumbs.length % 2))/2))) 
		{
			thumbHTML += "<br style=\"clear: right;\">"
		}
	}
	// alert(thumbHTML)
	thumbsWin.innerHTML = thumbHTML
	
	mainWinHTML = "<img src=\"" + rotatorImages[0].src + "\" id=\"mainpic\" width=\"400\" height=\"300\">"
	mainWin.innerHTML = mainWinHTML
	
	objholder = document.getElementById("mainpic")
	if (objholder.filters) {
		objholder.filters[0].apply()
		objholder.style.visibility="visible"
		objholder.filters[0].play()
	} else {
		objholder.style.visibility="visible"
	}
	if (rotatorFlag) {
		xxx = setTimeout("swapPic(" + nextPic + ")",pauseTime)
	} else {
		xxx = setTimeout("pausePic()",5)
	}
}

function swapPic(x) {
	clearTimeout(xxx)
	document.getElementById("playpause").innerHTML = "<a href=\"javascript:pausePic()\">Pause</a>"
	objholder = document.getElementById("mainpic")
	if (objholder.filters) {
		objholder.filters[0].apply()
		objholder.src = rotatorImages[x].src
		objholder.filters[0].play()
	} else {
		objholder.setAttribute("src",rotatorImages[x].src)
	}
	y = (x + 1) % numPics;
	nextPic = (y + 1) % numPics;
	xxx = setTimeout("swapPic(" + y + ")",pauseTime)
}

function swapPicAndPause(x) {
	clearTimeout(xxx)
	document.getElementById("playpause").innerHTML = "<a href=\"javascript:pausePic()\">Pause</a>"
	objholder = document.getElementById("mainpic")
	if (objholder.filters) {
		objholder.filters[0].apply()
		objholder.src = rotatorImages[x].src
		objholder.filters[0].play()
	} else {
		objholder.setAttribute("src",rotatorImages[x].src)
	}
	y = (x + 1) % numPics;
	nextPic = (y + 1) % numPics;
	pausePic()
}

function pausePic() {
	clearTimeout(xxx)
	document.getElementById("playpause").innerHTML = "<a href=\"javascript:swapPic(nextPic)\">Play</a>"
}
function createCookie(name,value,secs)
{
        if (secs)
        {
                var date = new Date();
                date.setTime(date.getTime()+(secs*1000));
                var expires = "; expires="+date.toGMTString();

        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
        var nameEQ = name + "=";

        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);

                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name)
{
        createCookie(name,"",-1);



}

		function validateComplete(formObj) {
			if (!validateTextField(formObj, "contact", "Your name")) { return false }
			if (!validateOneOfTwo(formObj, "phone", "email", "Telephone", "Email")) { return false }
			return true
		}

		function validateCompleteParts(formObj) {
			if (!validateTextField(formObj, "contact", "Your name")) { return false }
			if (!validateTextField(formObj, "phone", "Telephone")) { return false }
			if (!validateTextField(formObj, "registration", "Registration")) { return false }

			return true
		}
	
// End hiding -->
