//External scripts in this file:
//   (a) Functions for totalling the Quanity and Amount in the Order form page
//   (b) Countries menu script
//   (c) Default values for Order forms
//   (d) Function to validate NOCHEX Order form
//   (e) Function to validate client's e-mail address
//   (f) This is a blank function used to stop call errors in pages where toForm() is not used
//   (g) Function to use the Return or Enter key as the Tab key
//   (h) Functions to calculate the postage charge based on Qty and Country
//   (i) Function to validate Cheque Order form
//   (j) Function to validate UK Postcodes
//   (k) Dreamweaver roll over functions
//   (l) Open new window functions
//   (m) Roll over status bar functions

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

// (a) Functions for totalling the Quanity and Amount in the Order form page

//Define function to manipulate the form total per item selected/deselected:
function checkChoice(whichbox) {
	with (whichbox.form) 
	{
	//Ensure negative or non-numeric values were not entered:
	//Otherwise, set field back to prior value.
	if (isNaN(whichbox.value)) 
		{ 
		whichbox.value=whichbox.priorval;
		whichbox.focus();
		}
	whichbox.value=Math.abs(whichbox.value);

	//Ensure a decimal place was not keyed, otherwise set field back to prior value,
	// show error and leave function while passing current (unchanged) total value:
	var dec = whichbox.value.indexOf('.', 1)
	if (dec > 0)
		{ 
		alert('No decimal places allowed in Quantity box!');
		whichbox.value=whichbox.priorval;
		whichbox.focus();
		}

	//First, back out the prior qty from the total:
	total_qty.value =eval(total_qty.value) - eval(whichbox.priorval);
	hiddentotal.value = eval(hiddentotal.value) - eval(whichbox.price * whichbox.priorval);
	amount.value = eval(amount.value) -  eval(amount.value);
	postage.value=eval(postage.value) -  eval(postage.value);

	//Then, save the current qty:
	whichbox.priorval=whichbox.value;		
	
	//Now, apply the current qty to the total:
	total_qty.value = eval(total_qty.value) + eval(whichbox.value);
	hiddentotal.value = eval(hiddentotal.value) + eval(whichbox.price * whichbox.value);
	
	//Now, recalculate the postage:
	postage.value = setPostage()
		
	//Finally, sets and formats the amount & postage fields
	amount.value=eval(hiddentotal.value) + eval(postage.value);
	amount.value=formatCurrency(amount.value);
	postage.value=formatCurrency(postage.value);
	
	return(formatCurrency(hiddentotal.value));
	}
}

//Define function to setup form fields/buttons/checkbox that..
//..have non-HTML compliant properties (Netscrape requires this, however
//..IE works by simply specifying these properties directly on the
//..INPUT specification):
function setInput(whichbox,myprice) {
	with (whichbox.form) 
	{
		//Only do this once per input field:
		if (!whichbox.price) 
			{ 
			whichbox.price = myprice; 
			whichbox.priorval = 0;
			}
	}
}

//Define function to format value in the proper currency:
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+num.substring(num.length-(4*i+3));
	return (num + "." + cents);
}

//Define function to initialise the form on reload and-or refresh button:
function InitForm() {

	//Reset the displayed total on form:
	document.form1.amount.value='0';
	document.form1.postage.value='0';
	document.form1.subtotal.value='0';
	document.form1.hiddentotal.value=0;
	document.form1.total_qty.value=0;
	 
	//Reset all text fields prior values to zero:
	for (xx=0; xx < document.form1.elements.length; xx++)
	{
	if (document.form1.elements[xx].type == 'text')
		{ 
		document.form1.elements[xx].priorval = 0;
		}
	}
	
	// jumps to first field in form
	document.form1.client_email.focus()
	
	//Reset the Country lists  
	document.form1.region.selectedIndex = 0
	document.form1.country.selectedIndex = 0

}

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

// (b) Countries menu script

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;
}

function KW_updateItems(d,o,fn) { //v2.6 By Paul Davis www.kaosweaver.com
var i,s,l=MM_findObj(d),b,z=o.options[o.selectedIndex].value;
l.length=0;l.options[0]=new Option('Select country','Select country');b=(z!='nil')?eval(z+'_items'):0;
for(i=0;i<b.length;i++){s=b[i].split("|");l.options[i]=new Option(s[1],s[0]);}
l.selectedIndex=0;if (!fn) return;eval(fn)
}

function vallidateCountry(selected) { //my function to validate the Country entry
	if (selected == 'Select country') {
		alert ("Please select the name of your country!");		
	}
	if (selected == 'Other') {
		newCountry = "";
		while (newCountry == ""){
		newCountry=prompt ("Please enter the name of your country.", "");
	}
	if (newCountry != null) {
		document.form1.country.options[(document.form1.country.options.length-1)]=new Option(newCountry,newCountry,false,true);
		document.form1.country.options[document.form1.country.options.length]=new Option('Other','Other');
	}
	else {
		alert("Please select the name of your country!")
		document.form1.country.selectedIndex = 0
	}
  }
}

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

// (c) Default values for Order forms

tddPrice=12.00
tddText="Tutha de Danann CD's: "
sodPrice=12.00
sodText="Stone of Destiny CD's: "
isrPrice=12.00
isrText="In the Shadow of the Ruins CD's: "
pndPrice=12.00
pndText="The Promise of a New Day CD's: "
rsPrice=12.00
rsText="River Spirits CD's: "

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

// (d) Function to validate NOCHEX Order form

function validateNOCHEXForm() {
	
	//  validates e-mail entry:
	if (!emailCheck(document.form1.client_email.value)) {
		document.form1.client_email.focus()
		return false
	}

	//validates name and address fields:
	if (document.form1.name.value == 0) {
		alert("Please type in your name")
		document.form1.name.focus()
		document.form1.name.select()
		return false
	}
	if (document.form1.street.value == 0) {
		alert("Please type in your house number & street name")
		document.form1.street.focus()
		document.form1.street.select()
		return false
	}
	if (document.form1.town.value == 0) {
		alert("Please type in the name of your town")
		document.form1.town.focus()
		document.form1.town.select()
		return false
	}
	if (document.form1.county.value == 0) {
		alert("Please type in the name of your county or state")
		document.form1.county.focus()
		document.form1.county.select()
		return false
	}
	if (document.form1.post_code.value == 0) {
		alert("Please type in the postal code")
		document.form1.post_code.focus()
		document.form1.post_code.select()
		return false
	}
	//validates UK postcodes
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "United Kingdom") {
		postit()
		if (invalidFlag==1){return false}
	}

	//  validates the Region & Country selection
	if (document.form1.region.options[document.form1.region.selectedIndex].text == "Select Region") {
		alert("Please select the region of the world you live in")
		document.form1.region.focus()
		return false
	}
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "Select country") {
		alert("Please select the country you live in")
		document.form1.country.focus()
		return false
	}
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "Other") {
		alert("Please select the country you live in")
		document.form1.country.focus()
		return false
	}
		
	//  validates order quantity is > 0:
	if (document.form1.total_qty.value == 0) {
		alert("You have not ordered anything!")
		document.form1.tddQty.focus()
		return false
	}
	
	//  sets the description value:
	document.form1.description.value=document.form1.description.value+tddText+document.form1.tddQty.value+" • "+sodText+document.form1.sodQty.value+" • "
	document.form1.description.value=document.form1.description.value+isrText+document.form1.isrQty.value+" • "+pndText+document.form1.pndQty.value+" • "
	document.form1.description.value=document.form1.description.value+rsText+document.form1.rsQty.value+" • "
	document.form1.description.value=document.form1.description.value+"Total order is £ "+document.form1.amount.value+" • Name & address details: "+document.form1.name.value+","
	document.form1.description.value=document.form1.description.value+document.form1.street.value+","+document.form1.town.value+","+document.form1.county.value+","+document.form1.post_code.value+","
	document.form1.description.value=document.form1.description.value+document.form1.country.options[document.form1.country.selectedIndex].text+","+document.form1.region.options[document.form1.region.selectedIndex].text
	document.form1.description.value=document.form1.description.value+" • Your e-mail address:"+document.form1.client_email.value
	
	// If we made it to here, everything's valid, so return true
	return true
}

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

// (e) Function to validate client's e-mail address

function emailCheck(emailStr) {
//my code
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name contains invalid characters.");
return false;
   }
}
// See if "user" is valid 
if (user.match(userPat)==null) {
// user is not valid
alert("The username doesn't seem to be valid.");
return false;
}
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP address is invalid!");
return false;
   }
}
return true;
}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The domain name does not seem to be valid.");
return false;
   }
}
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}
if (len<2) {
alert("This address is missing a hostname!");
return false;
}
return true;
}

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

// (f) This is a blank function used to stop call errors in pages where this function is not used
//     (the call is in the BODY onLoad tag in the Template file)
//     Where it is used the function sends the focus to the first form field

function toForm() {
}

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

// (g) Function to use the Return or Enter key as the Tab key 
//     (doesn't work with Netscape 7.02)

nextfield = "tddQty"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) { // handles keypress
// determines whether Netscape or Internet Explorer
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 13) { // enter key pressed
		if (nextfield == 'done') return true; // submit, we finished all fields
		else { // we're not done yet, send focus to next box
		eval('document.form1.' + nextfield + '.select()');
		return false;
		}
	}
}
document.onkeydown = keyDown; // work together to analyze keystrokes
if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

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

// (h) Functions to calculate the postage charge based on Qty and Country
	
function setPostage() {
	postage=0;
	total_qty_order = document.form1.total_qty.value
	
	//checks if country or region selected yet:
	if(document.form1.region.selectedIndex == 0){
		postage=0}	
	else{	
	
	//check for UK postage first
	if (document.form1.country.options[document.form1.country.selectedIndex].text=="United Kingdom") { 
		if(total_qty_order==1) postage=1.25
		if(total_qty_order==2) postage=1.50
		if(total_qty_order==3) postage=1.75
		if(total_qty_order==4) postage=2.00
		if(total_qty_order==5) postage=2.25
		if(total_qty_order>5) postage=1.50+0.25*total_qty_order}
		
	else{	//checks for European postage
	if (document.form1.region.options[document.form1.region.selectedIndex].text =="Europe") { 
		postage=0.50+0.50*total_qty_order}
		
	else{	//else uses Rest of World postage (based on World Zone 2)
		postage=1.20*total_qty_order}
	}
	}	
	return postage
}
	
function resetPostage() {
	//removes the previous values
	document.form1.amount.value = eval(document.form1.amount.value) -  eval(document.form1.amount.value);
	document.form1.postage.value=eval(document.form1.postage.value) -  eval(document.form1.postage.value);

	//Now, recalculate the postage:
	document.form1.postage.value = setPostage()	
	
	//Now, apply the current qty to the total
	document.form1.amount.value=eval(document.form1.hiddentotal.value) + eval(document.form1.postage.value);
	document.form1.amount.value=formatCurrency(document.form1.amount.value);
	document.form1.postage.value=formatCurrency(document.form1.postage.value);
}	

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

// (i) Function to validate Cheque Order form

function validateChequeForm() {
	
	//  validates e-mail entry:
	if (!emailCheck(document.form1.client_email.value)) {
		document.form1.client_email.focus()
		return false
	}

	//validates name and address fields:
	if (document.form1.name.value == 0) {
		alert("Please type in your name")
		document.form1.name.focus()
		document.form1.name.select()
		return false
	}
	if (document.form1.street.value == 0) {
		alert("Please type in your house number & street name")
		document.form1.street.focus()
		document.form1.street.select()
		return false
	}
	if (document.form1.town.value == 0) {
		alert("Please type in the name of your town")
		document.form1.town.focus()
		document.form1.town.select()
		return false
	}
	if (document.form1.county.value == 0) {
		alert("Please type in the name of your county or state")
		document.form1.county.focus()
		document.form1.county.select()
		return false
	}
	if (document.form1.post_code.value == 0) {
		alert("Please type in the postal code")
		document.form1.post_code.focus()
		document.form1.post_code.select()
		return false
	}
	//validates UK postcodes
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "United Kingdom") {
		postit()
		if (invalidFlag==1){return false}
	}

	//  validates the Region & Country selection
	if (document.form1.region.options[document.form1.region.selectedIndex].text == "Select Region") {
		alert("Please select the region of the world you live in")
		document.form1.region.focus()
		return false
	}
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "Select country") {
		alert("Please select the country you live in")
		document.form1.country.focus()
		return false
	}
	if (document.form1.country.options[document.form1.country.selectedIndex].text == "Other") {
		alert("Please select the country you live in")
		document.form1.country.focus()
		return false
	}
	
	//  validates order quantity is > 0:
	if (document.form1.total_qty.value == 0) {
		alert("You have not ordered anything!")
		document.form1.tddQty.focus()
		return false
	}
	
	// If we made it to here, everything's valid, so calls print window
	//tests if IE5 on Mac which doesn't print out:
	var browser = navigator.appName
	var version = navigator.appVersion	
	if(browser=="Microsoft Internet Explorer"){
		if(version=="4.0 (compatible; MSIE 5.0; Macintosh; I; PPC)"){
			alert("Select Print from the File menu.")
		} else { window.print() }    //for all other Internet Explorer browsers (PC and earlier Mac versions)
		} else { window.print() }    //for all other browsers

}

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

//  (j) Function to validate UK Postcodes

// UK Postcode Format Validation
// Postcodes must conform to the following rules:-
//
//  The total length must be 6,7, or 8 characters, a gap (space character) must be included
//  The inward code, the part to the right of the gap, must always be 3 characters
//  The first character of the inward code must be numeric
//  The second and third characters of the inward code must be alpha
//  The outward code, the part to the left of the gap, can be 2,3, or 4 characters
//  The first character of the outward code must be alpha

function postit(){ //check postcode format is valid
 invalidFlag = 1
 test = document.form1.post_code.value; size = test.length
 test = test.toUpperCase(); //Change to uppercase
 while (test.slice(0,1) == " ") //Strip leading spaces
  {test = test.substr(1,size-1);size = test.length
  }
 while(test.slice(size-1,size)== " ") //Strip trailing spaces
  {test = test.substr(0,size-1);size = test.length
  }
 document.form1.post_code.value = test; //write back to form field
 if (size < 6 || size > 8){ //Code length rule
  alert(test + " is not a valid postcode - wrong length");
  document.form1.post_code.focus();
  return false;
  }
 if (!(isNaN(test.charAt(0)))){ //leftmost character must be alpha character rule
   alert(test + " is not a valid postcode - cannot start with a number");
   document.form1.post_code.focus();
   return false;
  }
 if (isNaN(test.charAt(size-3))){ //first character of inward code must be numeric rule
   alert(test + " is not a valid postcode - alpha character in wrong position");
   document.form1.post_code.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-2)))){ //second character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.form1.post_code.focus();
   return false;
  }
 if (!(isNaN(test.charAt(size-1)))){ //third character of inward code must be alpha rule
   alert(test + " is not a valid postcode - number in wrong position");
   document.form1.post_code.focus();
   return false;
  }
 if (!(test.charAt(size-4) == " ")){//space in position length-3 rule
   alert(test + " is not a valid postcode - no space or space in wrong position");
   document.form1.post_code.focus();
   return false;
   }
 count1 = test.indexOf(" ");count2 = test.lastIndexOf(" ");
 if (count1 != count2){//only one space rule
   alert(test + " is not a valid postcode - only one space allowed");
   document.form1.post_code.focus();
   return false;
  }
 invalidFlag = 0
return true;
}

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

// (k) Dreamweaver roll over functions

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
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;
}

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

// (l) Open new window functions
function QTPlayerWindow(qt_player_window){
    QTWindow = window.open(qt_player_window,"QuickTime","width=240,height=90,left=20,top=120,scrollbars=no,toolbar=no,resizable=no,location=no")
    QTWindow.focus()
}

function TermsWindow(){
    termsWindow = window.open("terms.html","","width=625,height=425,left=25,top=50")
    termsWindow.focus()
}	

function LinkWindow(link_window){
    URLWindow = window.open(link_window,"Link","width=700,height=400,left=30,top=30,scrollbars=yes,toolbar=yes,resizable=yes,location=yes")
    URLWindow.focus()
}

function TestWindow(link_window){
    NewTestWindow = window.open(link_window,"QuickTime","width=350,height=350,left=30,top=30, scrollbars=yes, toolbar=no, resizable=yes, location=no")
    NewTestWindow.focus()
}

function FeedbackWindow(link_window){
    NewFeedbackWindow = window.open(link_window,"Feedback","width=340,height=420,left=20,top=100, scrollbars=no, toolbar=no, resizable=no, location=no")
    NewFeedbackWindow.focus()
}

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

// (m) Roll over status bar functions

function setStatus(text) {
	window.status = text
	return true
}

function clearStatus() {
	window.status=""
}

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

// (n) Functions for detecting browser plug-ins

var javascriptVersion1_1 = false;

javascriptVersion1_1 = true;

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;

function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
	window.location.replace(daURL);
    } else {
	window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) || 
	(!pluginFound && !redirectIfFound)) ) {
	// go away
	goURL(redirectURL);
	return pluginFound;
    } else {
	// stay here and return result of plugin detection
	return pluginFound;
    }	
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
	return true;
    } else {
	return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) { 
    pluginFound = detectPlugin('Shockwave','Director'); 
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') ||
		       detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') ||
		       detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
    }	
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectWindowsMedia(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Windows Media');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
	pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
		// if desired plugin name is found in either plugin name or description
		if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
		    // this name was found
		    numFound++;
		}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
// -->