// Top of Javascript routines used in Two Hoots Software Web Site

// Function - changebackground()
// Description - Changes the Background Colour of the current document

function changebackground(){
// initialise the colours() Array
colours=new Array();
// Set values to a range of colours
colours[0]="aqua";
colours[1]="gray";
colours[2]="navy";
colours[3]="silver";
colours[4]="black";
colours[5]="green";
colours[6]="olive";
colours[7]="teal";
colours[8]="blue";
colours[9]="lime";
colours[10]="purple";
colours[11]="fuchsia";
colours[12]="maroon";
colours[13]="red";
colours[14]="yellow";
// Set last colour to white
colours[15]="white";

// Loop round all the items in the Colours Array
for (count=0;count<colours.length;count++){
// Set the background colour of the document
	document.bgColor=colours[count];
	// cause a delay before setting the next colour
	delay();
	}
}

// Function - Delay()
// Description - Cause a brief delay, called from the FadeIn function 
function delay(){
// initialise counter, count to 500 and return
for (count2=0;count2<=5000;count2++)
// do nothing in loop
{}
return;
}

// Double Combo Script - used on addsite page

// Setup arrays holding options for second combo box
// The contents of the second combo will change depending on the selection on the first combo
Developtext=new Array();
Developtext[1]="asp";
Developtext[2]="html";
Developtext[3]="javascript";
Developtext[4]="ms office";
Developtext[5]="web site services";
Developtext[6]="sql server";
Developtext[7]="visual basic";
Developtext[8]="web site builder";

Computingtext=new Array();
Computingtext[1]="clipart";
Computingtext[2]="desktop"
Computingtext[3]="fonts";
Computingtext[4]="sounds";
Computingtext[5]="tips/reference";

UsefulText=new Array();
UsefulText[1]="art";
UsefulText[2]="books";
UsefulText[3]="cars";
UsefulText[4]="cd's/videos and dvd's";
UsefulText[5]="concerts";
UsefulText[6]="diy";
UsefulText[7]="eCommerce";
UsefulText[8]="England";
UsefulText[9]="financial";
UsefulText[10]="food/drink";
UsefulText[11]="gardening";
UsefulText[12]="hobbies";
UsefulText[13]="holidays & travel";
UsefulText[14]="humour";
UsefulText[15]="jobs";
UsefulText[16]="local";
UsefulText[17]="media";
UsefulText[18]="music";
UsefulText[19]="pop groups";
UsefulText[20]="reference";
UsefulText[21]="shopping";
UsefulText[22]="training";
UsefulText[23]="world";

// Function - SelectCategory
// Description - Called on the onChange() event of the first combo box
function selectcategory(){
// Set num to the index of the selected item on the first combo
var num=document.myform.category.selectedIndex;
// Depending on which option selected on first combo, populate the contents of the second combo
if (num==1) {populateCategory(Developtext);}
if (num==2) {populateCategory(Computingtext);}
if (num==3) {populateCategory(UsefulText);}
}

// Function - PopulateCategory
// Description - Populates the second combo on the addsite page from the selection on the first combo
function populateCategory(mySitestext){
// First clear the current entries in the second combo box
for (count=document.myform.subcategory.options.length-1;count>0;count--){
document.myform.subcategory.options[count].text="";
}
// Set first entry in the second combo, this is displayed initially
document.myform.subcategory.options[0].text = "select a category          ";
// Now loop through all the elements of the passed array to populate the second combo
for (count=1;count<mySitestext.length;count++){
document.myform.subcategory.options[count].text=mySitestext[count];
}
// Set the first entry as selected
document.myform.subcategory.options[0].selected=true;
}

// Function CVPassword()
// Description - Get Resume Password
function CVPassword() {
		varPassword = prompt("Enter supplier password to view resume","");
		// Check entered password, set to lower case to ensure no problems with Capitals
		if (varPassword!="mousetrap") 
		    // Invalid Password
		 	alert('Access Denied - Password Incorrect, Please Try Again.');
		else {
			// Valid Password - open CV.HTML in new window
			myvar="top=0,left=0,resizable=yes";
		 	myvar = myvar + ",width=" + (screen.width-30);
		 	myvar = myvar + ",height=" + (screen.height-100);
		 	myvar = myvar + ",toolbar=yes";
			myvar = myvar + ",location=yes";
			myvar = myvar + ",directories=yes";
			myvar = myvar + ",status=yes";
			myvar = myvar + ",scrollbars=yes";
			myvar = myvar + ",menubar=yes";
			window.open("cv.html","cv",myvar);
			}
} 

// Function - getBrowser
// Description - get Name of Browser
function getBrowser(){
		 // indexOf returns position of search string within string being searched
		 // Set to lowercase for comparisons
		 var agent=navigator.appName.toLowerCase();
		 if(agent.indexOf("netscape")>-1){return "Netscape Navigator";}
		 if(agent.indexOf("microsoft internet explorer")>-1){return "Microsoft Internet Explorer";}
		 if(agent.indexOf("opera")>-1){return "Opera";}
		 return "Unknown";}

// Function - getVersion
// Description - get the Browser Version		 
function getVersion(){
		 // Get the Browser name
		 browserName=navigator.appName.toLowerCase();
		 // Get the Browser Version
		 browserVersion=parseInt(navigator.appVersion);
		 // Now check for differing versions
		 if (browserName=="netscape" && browserVersion==5)	 
		 	return "Version 6";
		 else if (browserName=="netscape" && browserVersion==4)
		 	return "Version 4";
		 else if (browserName=="netscape" && browserVersion==3)
		 	return "Version 3";
		 else if (browserName=="Netscape" && browserVersion==2)
		 	return "Version 2";
		 else if (browserName=="microsoft internet explorer" && browserVersion==4 && navigator.appVersion.indexOf("MSIE 6.0") != -1)
		    return "Version 6.0";
		 else if (browserName=="microsoft internet explorer" && browserVersion==4 && navigator.appVersion.indexOf("MSIE 5.5") != -1)
		    return "Version 5.5";
		 else if (browserName=="microsoft internet explorer" && browserVersion==4 && navigator.appVersion.indexOf("MSIE 5.0") != -1)
		    return "Version 5.0";
		 else if (browserName=="microsoft internet explorer" && browserVersion==4)
		    return "Version 4.0";
		 else if (browserName=="microsoft internet explorer" && browserVersion<4)
		 	return "Version 3.0";
		 else if (browserName=="opera" && browserVersion==2)
		    return "Version 2.0";
		 else if (browserName=="opera" && browserVersion==3)
		    return "Version 3.0";
		 else if (browserName=="opera" && browserVersion==4)
		    return "Version 4.0";
		 else if (browserName=="opera" && browserVersion==5)
		    return "Version 5.0";
		 // If here then not NN or IE or Opera
		 else return "Unknown";
		 }						
		 
// Function - getPlatform
// Description - get the Computer operating system		 
function getPlatform(){
		 var platform=navigator.appVersion.toLowerCase();
         if((platform.indexOf("win16")>-1) || (platform.indexOf("windows 3.1")>-1)){return "Windows 3.1";}
		 if((platform.indexOf("windows 98")>-1) || (platform.indexOf("win98")>-1)){return "Windows 98";}
		 if((platform.indexOf("windows 95")>-1) || (platform.indexOf("win95")>-1)){return "Windows 95";}
 		 if((platform.indexOf("windows nt")>-1) || (platform.indexOf("winnt")>-1)){return "Windows NT";}
		 if(platform.indexOf("win 9x 4.90")>-1){return "Windows ME";}
		 if(platform.indexOf("windows nt 5.0")>-1){return "Windows 2000";}
 		 if(platform.indexOf("windows")>-1){return "Windows";}
		 if(platform.indexOf("macintosh")>-1){return "Macintosh";}
		 if(platform.indexOf("x11")>-1){return "Unix";}
 		 if(platform.indexOf("unix")>-1){return "Unix";}
		 return "Unknown";}		

// Function - popUp()
// Description - Opens a new Window, with the passed URL with no menubars etc		 
function popUp(URL){
	var props;		
	props=window.open(URL,"popup","toolbar=no,scrollbars=yes,location=no,status=no,menubar=no,resizable=no,width=300,height=200");
	}

// Function - Welcome()
// Used to return a welcome message depending on the current time	
function Welcome(){
		 // Declare local parameters
		 var now;
		 var hour;
		 // Get the current Date and Time
		 now = new Date();
		 // Get the Hours field of the Current Date Object
		 hour = now.getHours();
		 // Set the greeting message depending on the current hour
		 if (hour > 0 && hour < 12){
		 	return "Good morning";
			}
		 else if (hour > 11 && hour <18){
		 	return "Good afternoon";
		 }
		 else 
		 	return "Good evening";
		}

// Function - DisplayDateTime
// Description - Displays Current Date and Time on the Home Page
function DisplayDateTime(){
		 // Create array of Days of the Week
		 var dayarray = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		 // Create array of Months of the year
		 var montharray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		 
		 // Set now as a Date object to current date and time
		 var now = new Date();
		 // Get the year of the now date object
		 var myyear = now.getFullYear();
		 // Get the month of the now date object - values from 0 (January) to 11 (December)
		 var mymonth = now.getMonth()
		 // Get the day of the now date object - values from 0 (Sunday) to 6 (Saturday)
		 var myday = now.getDay();
		 // Get the day of the month of the now date object - values between 1 and 31
		 var mydate = now.getDate();
		 // Get the hours of the now date object - values between 0 (midnight) and 11 (11 p.m.)
		 var myhour = now.getHours();
		 // Get the minutes of the now date object - values between 0 and 59
		 var myminute = now.getMinutes();
		 // Get the seconds of the now date object - values between 0 and 59
		 var mysecond = now.getSeconds();
		 // Overcome bug where IE 3 returns the year minus 1900, and where Netscape 2 and 3 returns year minus 1900 for dates between 1900 and 1999
		 if (myyear<1000){myyear+=1900};
		 // Set midday to either "am" or "pm"
		 if (myhour>=12){mymidday="pm"} else {mymidday="am"}
		 // Set hours from 1 to 12 and not 24 hour clock
		 if (myhour>12){myhour=myhour-12};
		 // If zero then must have been 12
		 if (myhour==0){myhour=12};
		 // Add zero to hour if less than 10 to get "03" for example
		 if (myhour<10){myhour="0"+myhour};
		 // Add zero to minute if less than 10 to get "03" for example
		 if (myminute<10){myminute="0"+myminute};
		 // Add zero to second of less than 10 to get "03" for example
		 if (mysecond<10){mysecond="0"+mysecond};
		
		 // If date is 1,21 or 31 set date identifier to be st, e.g. 1st - put st as superscript 
		 if (mydate==1 || mydate==21 || mydate==31){ender="<sup>st</sup>"}
		 // If date is 2 or 22 set date identifier to be nd, e.g. 2nd - put nd as superscript
		 if (mydate==2 || mydate==22){ender="<sup>nd</sup>"}
		 // If date is 3 or 23 set date identifier to be rd, e.g. 3rd - put rd as superscript
		 if (mydate==3 || mydate==23){ender="<sup>rd</sup>"}
		 // All others set date identifier to be th, e.g. 5th - put th as superscript
		 else {ender="<sup>th</sup>"} 
		 
		 // Create variable for return value
		 var timetext; 
		 // Add Day of the week
		 timetext = dayarray[myday];
		 // Add Month
		 timetext+=", " + montharray[mymonth];
		 // Add day and date identifier
		 timetext+=" " + mydate+ender;
		 // Add year
		 timetext+=" " + myyear;
		 // Add Hour
		 timetext+=", " + myhour;
		 // Add Minute
		 timetext+=":" + myminute;
		 // Add Second
		 timetext+=":" + mysecond;
		 // Add am/pm
		 timetext+=mymidday;
		 // Return text
		 return timetext;
		 }
	
// Function - List Anchors
// Description - opens new page with a list of all the links on a links page		 
function listanchors(){
		 // Create the HTML for the Page Header - using the title of the current page
		 var myheader = "<head><title>Links In "+document.title+"</title>";
		 // Add javascript to center form
		 myheader = myheader + "<script language='javascript' type='text/javascript'>function resizer(){var x=(screen.availWidth-789)/2;var y=(screen.availHeight-549)/2;self.resizeTo(300,549);self.moveTo(x,y);}</script>"
		 // Add </head> to header
		 myheader = myheader + "</head>";
		 // Add <body> tag to header
		 myheader = myheader + "<body onLoad='resizer();'>";
		 // Create <font> tag
		 var myfont = "<font style=\"font: 8pt Verdana, Arial, Helvetica, Sans-serif;line-height:18pt;\" face=\"verdana, tahoma, geneva\" size=\"-1\" >";
		 // Add page header text
		 var mytext = "<center><b>Links in " + document.title + "</b><ol></center>";
		 // Add </font> tag
		 var myendfont = "</font>";
		 // Add </body> tag
		 var myendheader = "</body>";
		 // Variable to store site URL
		 var SiteURL;

		 // First, determine what browser we're using
		 // Assume Navigator, but check for IE
		 listanchors.nav=true;
		 if (navigator.appName.indexOf("Microsoft") != -1) listanchors.nav = false;
		 // Open a new window, with name "navwin", status bar, scroll bars
		 var newwin=window.open("","navwin","status=yes,menubar=no,scrollbars=yes,resizable=yes");
		 // Write initial html
		 newwin.document.write(myheader + myfont + mytext);
		 // List all anchors - document.links is an array of all the hypertext links in the document
		 for(var i=0;i<document.links.length;i++)
		 {
    		 siteURL = document.links[i].href;
			 // Remove http:// bit
			 if (listanchors.nav==false){siteURL=siteURL.substring(7,siteURL.length-1)}
				else if(listanchors.nav==true) {siteURL=siteURL.substring(7,siteURL.length)}				
			 // See if string starts with www, if so write to page
			 if (siteURL.search(/www/) != -1) {
		     	// For each anchor object, determine the text to display.
			 	// First, try to get the text between the <A> and </A> using a
			 	// browser dependent property. If none, use the name instead.
			 	if (listanchors.nav==false) {
			 	   // Internet Explorer - create List Item HTML
				   newwin.document.write('<LI><A HREF="' + document.links[i] + '\">');
			 	   newwin.document.write(siteURL);
			 	   newwin.document.writeln('</A><BR>');
				   }
			 	else if (listanchors.nav==true) {
    		 	   // Netscape navigator - create List Item HTML
				   newwin.document.write('<LI><A HREF="' + document.links[i] + '\">');
			 	   newwin.document.write(siteURL);
			 	   newwin.document.writeln('</A><BR>');
				   }
			    }			  
		}
		// Add Print Page to Document
		newwin.document.write("</ol><center><input class='HideOnPrint' type='image' src='../buttons/print.gif' alt='print page' onclick='window.print()'</center>");
		// Add close text to close the window when clicked
		newwin.document.write("<center><input class='HideOnPrint' type='image' src='../buttons/close.gif' alt='close' onclick='window.close()'></center><BR>");
		// Write </body> to close document
        newwin.document.write(myendfont + myendheader);
		newwin.document.close();
		}

// Script routines for cookies

function setCookie(){
		// prompt for cookie value
		 var myvalue=prompt("Enter cookie value", "cookie value here");
		 var mycookie="myvalue="+escape(myvalue);
		 var myexpires=new Date();
		 myexpires.setTime(myexpires.getTime()+365*24*60*60*1000);
		 // expire after one year
		 mycookie=mycookie+";myexpires="+myexpires.toGMTString();
		 document.cookie=mycookie;
		 }
		 
function getCookie(myname){
		 // pass name of cookie to be retrieved
		 // read the entire cookie
		 var mycookie=document.cookie;
		 var myname=myname+"=";
		 var mystart=mycookie.indexOf(myname);
		 // found it - if null return empty
		 alert(mystart);
		 if(mystart<0){return null;}
		 var myend=document.cookie.indexOf(";",mystart);
		 if(myend<0){myend=mycookie.length;}
		 // return thge value requested
		 return unescape(mycookie.substring(mystart+myname.length,myend));
		 }
		 
function deleteCookie(myname){
		 if (getCookie(myname)){
		 	// set expire date to immediately so that the browser deletes it for us
		 	document.cookie=myname+"="+";expires=0";
			}
		 }

// Function - mySubmit()
// Description - Processes user input on the contact us form
// Set the already clicked variable to no 		 
var alreadyclicked="no";
// Set the cookiename variable to "date submitted"
var cookiename="datesubmitted";

function mySubmit(form){
		 // Routine uses the names of the fields as defined on the contact.html document
		 // If no name entered, display alert and set focus to the name field
		 if (form.name.value=="") { 
		 	  alert ("Please enter your name");
			  form.name.focus();
			  return false;}
         // If no email entered, display alert and set focus to the email field			  			  
		 else if (form.email.value=="") { 
		 	  alert ("Please enter your email address");
			  form.email.focus();
    		  return false;}
		 // If no message entered, display alert and set focus to the message field
		 else if (form.message.value==""){
		 	  alert ("Please enter a message");
			  form.message.focus();
			  return false;}
		 else {
		 // Don't submit the same form more than once
		 if (alreadyclicked=="yes"){
		 	alert("Form already being processed.");
			return;
		 }
		 // See if we already have a cookie called datesubmitted - i.e. we've already processed the form
		 if (document.cookie.indexOf(cookiename)>-1){
		 	// Get position of cookie name
			var mystart=document.cookie.indexOf(cookiename);
			// Get Value of Cookie
			var mydate=document.cookie.substring(mystart+cookiename.length+1,33);
			// Build return string to be displayed in the browser
			var myconfirm="You submitted this form at ";
			myconfirm=myconfirm+mydate;
			myconfirm=myconfirm+", Submit Again?";
			ret=confirm(myconfirm);
			if(ret==false){
			    return;
			}
			}
		// Create new Cookie DateSubmitted and current Date
		mydate=new Date();
		document.cookie=cookiename+"="+mydate;
		alreadyclicked="yes";
		// Now Submit the form
		document.myform.submit();
		}
		}

// Function - Shake()
// Description - shake the screen
function shake(n) {
	 for (i = 10; i > 0; i--) {
	 	 for (j = n; j > 0; j--) {
		 	 // Shake the window
			 // Moveby (x,y) where x = number of pixels to move the window to the right
			 // and y is the number of pixels to move the window down
	 	 	 self.moveBy(0,i);
			 self.moveBy(i,0);
			 self.moveBy(0,-i);
			 self.moveBy(-i,0);
       		 }
   		 }
	 }
	
// Copyright (c) 1996 Tomer Shiran. All rights reserved.
// Permission given to use this script provided that the copyright
// notice remains as is. Additional scripts and information are 
// available at http://www.geocities.com/SiliconValley/9000/

// set speed of banner (pause in milliseconds between characters)
var speed = 150 // decrease value to increase speed (must be positive)

// set pause between completion of message and beginning of following message
var pause = 1000 // increase value to increase pause

// set initial values
var timerID = null
var bannerRunning = false

// create global array
var ar = new Array()

// assign the strings to the array's elements
ar[0] = "Welcome to Two Hoots Software"
ar[1] = "Please take your time and have a good look around"
ar[2] = "Here you will find a good selectionoff Javascripts"
ar[3] = "Including full working examples"
ar[4] = "As well as loads of links to useful websites"
ar[5] = "Join the mailing list for site updates"
ar[6] = "Or suggest a site to be included here"
ar[7] = "The URL Is: http://www.twohootssoftware.co.uk"
ar[8] = "Let me know what you think of this website"
ar[9] = "Thank You for visiting, see you again soon."
// set index of first message to be displayed first
var currentMessage = 0

// set index of last character to be displayed first
var offset = 0

// stop the banner if it is currently running
function stopBanner() {
        // if banner is currently running
        if (bannerRunning)
                // stop the banner
                clearTimeout(timerID)

        // timer is now stopped
        bannerRunning = false
}

// start the banner
function startBanner() {
        // make sure the banner is stopped
        stopBanner()

        // start the banner from the current position
        showBanner()
}

// type-in the current message
function showBanner() {
        // assign current message to variable
        var text = ar[currentMessage]

        // if current message has not finished being displayed
        if (offset < text.length) {
                // if last character of current message is a space
                if (text.charAt(offset) == " ")
                        // skip the current character
                        offset++                        

                // assign the up-to-date to-be-displayed substring
                // second argument of method accepts index of last character plus one
                var partialMessage = text.substring(0, offset + 1) 

                // display partial message in status bar
                window.status = partialMessage

                // increment index of last character to be displayed
                offset++ // IE sometimes has trouble with "++offset"

                // recursive call after specified time
                timerID = setTimeout("showBanner()", speed)

                // banner is running
                bannerRunning = true
        } else {
                // reset offset
                offset = 0

                // increment subscript (index) of current message
                currentMessage++

                // if subscript of current message is out of range
                if (currentMessage == ar.length)
                        // wrap around (start from beginning)
                        currentMessage = 0

                // recursive call after specified time
                timerID = setTimeout("showBanner()", pause)

                // banner is running
                bannerRunning = true
        }
}

function initMail(form) {
		 text = "Check out this page:  " + window.location;
		 form.message.value = "Hi " + form.sendto.value + " (" + form.to.value + "):\n\n"  + text + "\n\nYour Friend,\n" + form.sendername.value + "(" + form.senderemail.value + ")";
		 return (form.to.value != "");
		 }

function doquiz(){
	alert('What do you put in a toaster ?');
	alert('Answer:- Bread....If you said "toast" then give up now and go and find yourself a shoe box as you cant handle life... If you said "Bread" then please progress on to question 2');
	alert('Say "Silk" 5 times, Now Spell "Silk".... What do cows drink ?');
	alert('Answer:- "Water" If you said "Milk", then may I suggest that you not try the next question, as it may seem that your brain cell is over - texed, you need a holiday...may I suggest Childrens world? If you said "water" then you may go onto question 3');
	alert('If a red house is made from red bricks, a blue house is made out of blue bricks, a pink house is made out of pink bricks, a black house is made out of black bricks....what is a green house made out of ?');
	alert('Answer:- "Glass" If you said "green bricks" then wgar the hell are you still doing here reading these questions!!!! If you said "glass" then please progress onto question 4');
	alert('20 years ago a plane is flying at 20,000 ft, over the old conntry germany when 2 of the engines fail, the pilot realising that the last remaining engine was failing, he decided a crash landing procedure, but unfortunately the engine fails before time and the plane crashes smack bank in the middle of "No mans land" the land between East Germany and West Germany In the middle of the berlin wall, ..... where would you bury the survivors East Germany, West Germany or in "No Mans Land"?');
	alert('Answer:- You dont bury "Survivors" If you said anything other than the sentence above then please never fly, you may cause more damage should the plane crash!!! IF you said the sentence above then carry on to question 5.');
	alert('If on a clock the hour hand moves 1/60th of a degree every minutes then how many degress will the hour hand travel in 1 hour?');
	alert('Answer:- "1 degree" If you said "360 degrees", or anything other than the answer, may I congratulate you on getting this far...But be honest with yourself, Do you think you can handle the last and final question? If you said "1 degree" then please go on to the last question');
	alert('You are driving a bus from London to Milford Haven (Wales). In London 17 people get on the bus, in Reading 6 people get off, 9 people get on, in Swindon 2 people get off, 4 people get on, in Cardiff 11 people get off,16 people get on, in Swanses 3 people get off,5 people get on, in Carmarthen, 6 people get off,3 people get on the bus then pulls into Milford Haven bus depot..... what was the name of the bus driver?');
	alert('Answer:-"your name". read the first line...');
	}
	
function frogloan(){
	alert('youre gonna love this');
	alert('its a real treat');
	alert('masterpiece');
	alert('wait for it');
	alert('The bank manager looks back at her and says...');
	alert('ready');
	alert('"Its a knickknack, Pattie Whack. Give the frog a loan. His old mans a Rolling Stone."');
	}

