// <SCRIPT LANGUAGE="Javascript">
// the previous line is to get around a MAC quirk
// the next section is a bit of generic JavaScript that will populate the
// fields on the form with previously captured data. It can be used as
// is, on any form that uses the hidden fields to hold previously entered
// data

// function:	getNext
// purpose:	the getNext function grabs hidden fields from the dataStructure
//		form and places them in a field name dataStore on the sumbitting
//		form
// in:		Form submitObject:
// out:		NA
// returns:	NA
// effect:	this function allows us to package up the hidden details and pass 
//		them to the server as part of the submitted form.

	function getNext(submitObject)
	{
		var	objs;
		var	field;
		var	aform;
		var	params="";
		
                if(submitObject == null)
                {
                      alert("This page has not been completely loaded.\nPlease wait.");
                      return false;
                }
		// get a pointer to the dataStructure Form object
		objs = document.dataStructure;
		
		// for each object on the form
		for ( field = 0; field < objs.length; field++ )
		{
			// depending on the object type add details to the string params
			if ( objs[field].type == "text" ||  objs[field].type == "hidden" )
			{
				// for text or hidden fields just add the value
				params=params + "&" + objs[field].name + "=" + objs[field].value;
			}
			else if ( objs[field].type == "checkbox" )
			{
				// for a check box add either the value, if its checked or an empty string
				params=params + "&" + objs[field].name + "=";
				if ( objs[field].checked )
				{
					params=params + objs[field].value;
				}
			}
			else if ( objs[field].type == "radio" )
			{
				// for a radio button add the value if it is checked
				if ( objs[field].checked )
				{
					params=params + "&" + objs[field].name + "=" + objs[field].value;
				}
			}
			else if ( objs[field].type == "select-one" )
			{
				// for a combo box add the text displayed in the text box
				params=params + "&" + objs[field].name + "=" + objs[field].value;
			}
		}

		// lets make sure that the field is not completely empty
		if ( params.length == 0 )
		{
			params="&";
		}

		// store the values in the sumitted form dataStore object
		submitObject.dataStore.value=params;
		return true;
	}

	// function:	getValue
	// purpose:	searches the hidden fields for a matching object
	//		and depending on its type populates it
	// in:		Object target
	// out:		NA
	// returns:	NA
	// effect:	if there is a matching hidden field the target field is populated
	//		with the value

	function getValue(target)
	{
		var	targetName = "e_" + target.name;
		var	objs = top.document.dataStructure;
		var	field;
		var	postfix;
		var	optionIndex;
		var	found=false;

		// for each field on the dataStructure Form
		for ( field = 0; field < objs.length; field++ )
		{
			// get the name of the field minus the default 'e_' string
			postfix = objs[field].name.substring( 2, objs[field].name.length );

			// if the name of the target object matches the hidden field
			if ( postfix == target.name )
			{
				// then populate the target field depending on its type
				found=true;

				if ( target.type == "text" )
				{
					target.value = objs[field].value;
				}
				else if ( target.type == "checkbox" )
				{
					if ( objs[field].value != "" && objs[field].value != "off" )
					{
						target.checked = true;
					}
					else
					{
						target.checked = false;
					}
				}
				else if ( target.type == "radio" )
				{
					if ( target.value == objs[field].value )
					{
						target.checked = true;
					}
					else
					{
						target.checked = false;
					}
				}
				else if ( target.type == "select-one" )
				{
//				debugger;
					for ( optionIndex = 0; optionIndex < target.options.length; optionIndex++ )
					{
						if ( target.options[optionIndex].value == objs[field].value )
						{
							target.selectedIndex = optionIndex;
						}
					}
				}
                                else if ( target.type == "hidden" )
                                {
                                       // repopulate hidden fields 
                                       if ( objs[field].name=="e_acctuse" ||
					    objs[field].name=="e_CSRID"  ||
					    objs[field].name=="e_ChannelID" )
                                       {  
                                          target.value = objs[field].value;
                                       }
                                }
				else if ( target.type == "password" )
				{
					// dont repopulate password fields
				}
				else if ( target.type == "submit" )
				{
					// dont repopulate submit fields
				}
				else if ( target.type == "textarea" )
                                {
					target.value = objs[field].value;
                                }
				else
				{
					document.write( "<br>The field '", postfix, "' of type '", target.type, "' could not be parsed<br>" );
				}
			}
		}
	}

	// function:	getData
	// purpose:	searches the document for forms and for each
	//		object on the form it calls getValue. The
	//		dataStructure form holds the data and therefore
	//		does not get updated
	// in:		NA
	// out:		NA
	// returns:	NA
	// effect:	populates forms on a page depending on values stored
	//		in the dataStructure Form

	function getData()
	{
		var	objs;
		var	field;
		var	aform;

		for ( aform = 0; aform < document.forms.length; aform++ )
		{
			if ( document.forms[aform].name != "dataStructure" )
			{
				objs = document.forms[aform];
				for ( field = 0; field < objs.length; field++ )
				{
				        // alert("objs="+objs.name+" length="+objs.length+" field="+field); - debugging, remove
				        // alert("objs["+field+"]="+objs[field].name); - debugging, remove
					getValue( objs[field] );
				}
			}
		}
	}

	function showButton(theString)
	{
		top.document.write( theString );
	}

	function Help(helpfile,x,y)
	{
		window.open(helpfile,'helpwindow','width='+x+', height='+y);
	}

	// function:	printValue
	// purpose:	searches the dataStructure form for an embedded field
	//		called 'target', then prints the value out to the screen.
	// in:		target
	// out:		NA
	// returns:	NA

	function printValue(target)
	{
		var	objs = top.document.dataStructure;
		var	field;

		for ( field = 0; field < objs.length; field++ )
		{
			if ( objs[field].name == target )
			{
				top.document.write( objs[field].value );
			}
		}
	}


	function showTextProgress()
	{
		if ( top.document.forms[0].name == "dataStructure" )
		{
			document.write("<h1>Step ");
			printValue("e_progress_num");
			document.write(" of ");
			printValue("e_total_pages");
			document.write("</h1>");
		}
	}

	function showProgress()
	{		
		if ( top.document.forms[0].name == "dataStructure" )
		{
			document.write("<IMG SRC=/pictures/progress");
			printValue("e_progress_num");
			document.write("of");
			printValue("e_total_pages");
			document.write(".gif>");
		}
		else
		{
			document.write("<IMG SRC=/pictures/noprogress.gif>");
		}
	}

	// Writes the current year and the five next years to a 'select' menu.

	function selectYear()
	{
		var year = new Date();
		var thisYear = year.getFullYear();

		for(var i=0; i<21; i++)
    		{
			document.write('<option value="'+(thisYear+i)+'">'+(thisYear+i)+'</option>\n');
    		}		
	}

	function installDate()
        {
                var date = new Date();
                var thisMonth = date.getMonth();
		var thisYear = date.getFullYear();

		document.write( '<td><select name="installday">' );
		for(var i=1; i<32; i++)
                {
                        document.write('<option value="'+i+'">'+i+'</option>\n');
                }
		document.write( "</select></td>" );

		document.write( '<td><select name="installmonth">' );
                document.write('<option value="01">January</option>\n');
		document.write('<option value="02">February</option>\n');
		document.write('<option value="03">March</option>\n');
		document.write('<option value="04">April</option>\n');
		document.write('<option value="05">May</option>\n');
		document.write('<option value="06">June</option>\n');
		document.write('<option value="07">July</option>\n');
		document.write('<option value="08">August</option>\n');
		document.write('<option value="09">September</option>\n');
		document.write('<option value="10">October</option>\n');
		document.write('<option value="11">November</option>\n');
		document.write('<option value="12">December</option>\n');
		document.write( "</select></td>" );

		document.write( '<td><select name="installyear">' );
		for(var i=0; i<21; i++)
                {
                        document.write('<option value="'+(thisYear+i)+'">'+(thisYear+i)+'</option>\n');
                }
		document.write( "</select></td>" );
        }


	function validate_email(f)
	{
		var msg = "";
		var email = "";
		var userchoice = "";
                var at = false;

		for(var i=0; i< f.elements.length; i++)
    		{
       		 	var e = f.elements[i];
                       
			if ( e.name == "emailchoice")
			{
            			email = e.value;
			}

			if ( e.name == "emailtext" )
			{
		            	userchoice = e.value;

				for(var j=0; j< e.value.length; j++)
				{
					if (userchoice.charAt(j) == '@')
					{
						at = true;
					}		
				}
			}
    		}

	   	if ( userchoice != "" )
		{
       			email = userchoice;
		}

   		if ( email == "")
   		{
       			alert("You must select an email address.");
       			return false;
   		}
   		else
   		{
                        if (at == true)
                        {
                                alert("You should only enter the first part of the e-mail address, eg joe.bloggs (NOT joe.bloggs@btopenworld.com)"); 
                                return false;
                        }
		       	else
		       	{
		           	email += "@btopenworld.com";
		          	msg = "You have selected the email name '" + email + "'.";
		       	}

		       	msg += "\n\n(registration is your last opportunity to change it)\n\nDo you wish to proceed ?";

		       	if (confirm(msg))
			{
		           	return true;
			}
		       	else
			{
           			return false;
			}
   		}
	}

	function doHelp( helpPage, width, height )
        {
                var openOptions='toolbar=no,width='+width+',height='+height;

                window.open(helpPage, 'helpwindow', openOptions );
        }

	function showHelpButton( helpPage, width, height ) 
	{
                top.document.write( '<A HREF="javascript:doHelp(', "'", helpPage, "',", width, ",", height, ')"><IMG SRC="/pictures/help.gif" LOWSRC="/pictures/help.gif" ALT="Help" BORDER="0"></A>' );
        }

	function showOWHelpButton( helpPage, width, height )
        {
                top.document.write( '<A HREF="javascript:doHelp(', "'", helpPage, "',", width, ",", height, ')"><IMG SRC="/pictures/bb_help.gif" ALT="Help" BORDER="0"></A>' );
        }

	function Referral()
	{
		var referred = false;
		var idx;
		var objs = top.document.dataStructure;
		var field;

		// first lets check that the e_version field is available
		for ( field = 0; field < objs.length && referred != true; field++ )
		{
		    if ( objs[field].name == "e_version" )
		    {
			var regVersion;
			regVersion = top.document.dataStructure.e_version.value;

			for ( idx = 0; idx < regVersion.length; idx++ )
			{
				if ( regVersion.substring(idx,idx+1) == "r" || 
				     regVersion.substring(idx,idx+1) == "R" )
				{
					referred = true;
					break;
				}
			}
		    }
		}

		return referred;
	}

        function Enhanced()
        {
                var enhanced = false;
                var idx;
                var objs = top.document.dataStructure;
                var field;

                // first lets check that the e_special_user field is available

                for ( field = 0; field < objs.length && enhanced != true; field++ )
                {
                    if ( objs[field].name == "e_special_user" )
                    {
                        var regVersion;
                        regVersion = top.document.dataStructure.e_special_user.value;

                        for ( idx = 0; idx < regVersion.length; idx++ )
                        {
                                if ( regVersion.substring(idx,idx+1) == "P" ||
                                     regVersion.substring(idx,idx+1) == "L" )
                                {
                                        enhanced = true;
                                        break;
                                }
                        }
                    }
                }

                return enhanced;
        }

	function Portal()
	{
		var formString = location.search;
		var returned = 0;
		var objs = document.dataStructure;
		var fieldIndex;

		if ( formString.indexOf("portal_status=1") == -1)
		{
			// ex=1 is not in the URL now check for the field in 
			// the dataStructure form
			for ( fieldIndex=0; 
			      fieldIndex < objs.length; 
			      fieldIndex++ )
			{
				if ( objs[fieldIndex].name == "e_portal_status" )
				{
					returned = 1;
					break;
				}
			}
		}
		else
		{
			returned = 1;
		}

		return returned;
	}
	
	function Expert()
	{
		var formString = location.search;
		var returned = 0;
		var objs = document.dataStructure;
		var fieldIndex;

		if ( formString.indexOf("ex=1") == -1)
		{
			// ex=1 is not in the URL now check for the field in 
			// the dataStructure form
			for ( fieldIndex=0; 
			      fieldIndex < objs.length; 
			      fieldIndex++ )
			{
				if ( objs[fieldIndex].name == "e_ex" )
				{
					returned = 1;
					break;
				}
			}
		}
		else
		{
			returned = 1;
		}

		return returned;
	}
	
	function Sales_Channel()
        {
                var formString = location.search;
		var SalesChannelFound = 0;
                var objs = document.dataStructure;
                var fieldIndex;

                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( ((objs[fieldIndex].name == "e_sreg") || 
                                      (objs[fieldIndex].name == "sreg")) &&
                                     (objs[fieldIndex].value == "1"))
                                {
                                        SalesChannelFound = 1;
                                        break;
                                }
                        }

                return SalesChannelFound;
        }

/* DRH - is it a windows OS? */
function BrowserDetectWindows()
   {
   var BrowserVersion = navigator.appVersion;
 
   if ((BrowserVersion.indexOf("Win16", 1) != -1) || (BrowserVersion.indexOf("Windows 3.1", 1) != -1))
      {  
      return false;
      }  
 
   if ((BrowserVersion.indexOf("Win95", 1) != -1) || (BrowserVersion.indexOf("Windows 95", 1) != -1))
      {  
      return true;
      }  
 
   if ((BrowserVersion.indexOf("Win98", 1) != -1) || (BrowserVersion.indexOf("Windows 98", 1) != -1))
      {  
      return true;
      }  
 
   if ((BrowserVersion.indexOf("WinNT", 1) != -1) || (BrowserVersion.indexOf("Windows NT", 1) != -1))
      {  
      return true;
      }  
 
   if (BrowserVersion.indexOf("Macintosh", 1) != -1)
      {  
      return false;
      }
 
   return false; 
   } 

// DRH - is it an anytime change?
	function Changeto_Anytime()
        {
                var formString = location.search;
                var returned = 0;
                var objs = document.dataStructure;
                var fieldIndex;
		var changetofound = 0;
		var anytimefound = 0;

                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "e_changeto" )
                                {
                                        changetofound = 1;
                                        if ( objs[fieldIndex].value == "anytime" )
                                           anytimefound=1;
                                        break;
                                }
                        }

                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "changeto" )
                                {
                                        changetofound = 1;
                                        if ( objs[fieldIndex].value == "anytime" )
                                           anytimefound=1;
                                        break;
                                }
                        }
			
			if ( changetofound == 1 && anytimefound == 1 )
			{
				returned = 1;		
			}

                return returned;
        }

	function Online_Broadband()
        {
                var formString = location.search;
		var telnofound = 0;
                var broadband = 0;
		var productidfound = 0;
                var bandwidthfound = 0;
                var returned = 0;
                var objs = document.dataStructure;
                var fieldIndex;
                
                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "e_telNo" )
                                {
                                        telnofound = 1;
                                        break;
                                }
                        }

                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "telNo" )
                                {
                                        telnofound = 1;
                                        break;
                                }
                        }
			
			for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "e_productID" )
                                {
                                        productidfound = 1;
                                        break;
                                }
                        }

			for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "productID" )
                                {
                                        productidfound = 1;
                                        break;
                                }
                        }

			for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "bandwidth" )
                                {
					if(objs[fieldIndex].value =="B")
					{
                                           broadband = 1;
					}
                                        break;
                                }
                        }

                        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "e_bandwidth" )
                                {
					if(objs[fieldIndex].value =="B")
					{
                                           broadband = 1;
                                        }
                                        break;
                                }
                        }
		
			if ( telnofound == 1 && productidfound == 1 )
			{
				returned = 1;		
			}
			else if(broadband == 1)
			{
				returned = 1;
			}

                return returned;
        }

	function Surftime(myform)
        {
                var formString = location.search;
                var returned = 0;
                var objs = myform.document.dataStructure;
                var fieldIndex;

                if ( formString.indexOf("st=1") == -1)
                {
                        // st=1 is not in the URL now check for the field in
                        // the dataStructure form
                        for ( fieldIndex=0;
                              fieldIndex < objs.length;
                              fieldIndex++ )
                        {
                                if ( objs[fieldIndex].name == "e_st" )
                                {
                                        returned = 1;
                                        break;
                                }
                        }
                }
                else
                {
                        returned = 1;
                }

                return returned;
        }

	function Broadband()
        {
                var broadband = false;
                var idx;
                var objs = top.document.dataStructure;
                var field;

                // first lets check that the e_version field is available
                for ( field = 0; field < objs.length && broadband != true; field++ )
                {
                    if ( objs[field].name == "e_bandwidth" )
                    {
                        var bandwidth;
                        bandwidth = top.document.dataStructure.e_bandwidth.value;

                        for ( idx = 0; idx < bandwidth.length; idx++ )
                        {
                                if ( bandwidth.substring(idx,idx+1) == "b" ||
                                     bandwidth.substring(idx,idx+1) == "B" )
                                {
                                        broadband = true;
                                        break;
                                }
                        }
                    }
                }

                return broadband;
        }

	function OldCd()
        {
                var oldcd = false;
                var cdtype;
		for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler")
                        {
				cdtype = top.document.dataStructure.e_dialler.value;
				break;
                        }
                        else
                        {
                                 cdtype = 'na';       
                        }
                }

                if ( cdtype == "0")
                {
                       oldcd = true;
                }
		else
		{
			oldcd = false;	
		}

                return oldcd;
        }

// DRH - Anytime compatible Smart CD detected from dialler==2
	function SmartCd()
        {
                var smartcd = false;
                var cdtype;
		for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler")
                        {
				cdtype = top.document.dataStructure.e_dialler.value;
				break;
                        }
                        else
                        {
                                 cdtype = 'na';       
                        }
                }

                if ( cdtype == "2")
                {
                       smartcd = true;
                }
		else
		{
			smartcd = false;	
		}
                return smartcd;
        }

	function Payasugo()
        {
                var result = false;
                var prodtype;
		for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler_code")
                        {
                                prodtype = top.document.dataStructure.e_dialler_code.value;
				break;
                        }
                        else
                        {
                                 prodtype = 'na';       
                        }
                }

                if ( prodtype == "p" || prodtype == "P" )
                {
                       result = true;
                }
                else
                {
                        result = false;  
                }

                return result;
        }

	function Freecall()
        {
                var result = false;
                var prodtype;
		 for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler_code")
                        {
                                prodtype = top.document.dataStructure.e_dialler_code.value;
				break;
                        }
                        else
                        {
                                 prodtype = 'na';       
                        }
                }

                if ( prodtype == "f" || prodtype == "F" )
                {
                       result = true;
                }
                else
                {
                        result = false;  
                }

                return result;
        }

// DRH - Anytime detected from dialler_code
	function Anytime()
        {
                var result = false;
                var prodtype;
		 for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler_code")
                        {
                                prodtype = top.document.dataStructure.e_dialler_code.value;
				break;
                        }
                        else
                        {
                                 prodtype = 'na';       
                        }
                }

                if ( prodtype == "a" || prodtype == "A" )
                {
                       result = true;
                }
                else
                {
                        result = false;  
                }

                return result;
        }

	function Surf()
        {
                var result = false;
                var prodtype;
		for(var i=0; i< document.dataStructure.elements.length; i++)
                {
                        var e = document.dataStructure.elements[i];

                        if (e.name == "e_dialler_code")
			{
				prodtype = top.document.dataStructure.e_dialler_code.value;
				break;
			}
			else
			{
				 prodtype = 'na';	
			}
                }

                if ( prodtype == "s" || prodtype == "S" )
                {
                       result = true;
                }
                else
                {
                        result = false;  
                }

                return result;
        }


       function Direct()
         {
                 var result = false;
                 var prodtype;
               for(var i=0; i< document.dataStructure.elements.length; i++)
                 {
                         var e = document.dataStructure.elements[i];
 
                         if (e.name == "e_dialler_code")
                         {
                                 prodtype = top.document.dataStructure.e_dialler_code.value;
                               break;
                         }
                         else
                         {
                                  prodtype = 'na';       
                         }
                 }
 
                 if ( prodtype == "d" || prodtype == "D" )
                 {
                        result = true;
                 }
                 else
                 {
                         result = false;  
                 }
 
                 return result;
         }

       function isDD()
         {
                 var result = false;
                 var paytype;
               for(var i=0; i< document.dataStructure.elements.length; i++)
                 {
                         var e = document.dataStructure.elements[i];
 
                         if ( e.name == "e_anypay" )
                         {
                               paytype = top.document.dataStructure.e_anypay.value;
                               break;
                         }
                         else if ( e.name == "anypay")
                         {
                               paytype = top.document.dataStructure.anypay.value;
                               break;
                         }
                         else
                         {
                               paytype = 'C';       
                         }
                 }
 
                 if ( paytype == "d" || paytype == "D" )
                 {
                        result = true;
                 }
                 else if ( paytype == "DDP" || paytype == "DDO" )
                 {
                        result = true;
                 }
                 else
                 {
                         result = false;  
                 }
 
                 return result;
         }

       function isGeneva()
         {
                 var result = false;
                 var billsys;
               for(var i=0; i< document.dataStructure.elements.length; i++)
                 {
                         var e = document.dataStructure.elements[i];
 
                         if ( e.name == "e_billsys" )
                         {
                               billsys = top.document.dataStructure.e_billsys.value;
                               break;
                         }
                         else if ( e.name == "billsys")
                         {
                               billsys = top.document.dataStructure.billsys.value;
                               break;
                         }
                         else
                         {
                               billsys = 'B';       
                         }
                 }
 
                 if ( billsys == "g" || billsys == "G" )
                 {
                        result = true;
                 }
                 else
                 {
                         result = false;  
                 }
 
                 return result;
         }



	function PersonalInfo(message)
	{
		if (confirm(message))
		{
			getNext(document.personal);
			document.personal.submit();
		}
	}

	function CorporateInfo(message)
	{
		if (confirm(message))
		{
			getNext(document.corporate);
			document.corporate.submit();
		}
	}

	function ReregInfo(message)
	{
		if (confirm(message))
		{
			getNext(document.rereg);
			document.rereg.submit();
		}
	}

	function ChargeInfo()
	{
		getNext(document.charges);
		document.charges.submit();
	}

	function QuitConfirm(message)
	{
		if (confirm(message))
		{
			top.close();
		}
	}

	function freeIsp()
	{
      		return document.dataStructure.e_special.value;
	}

	function Corporate()
	{
      		return top.document.dataStructure.e_corp_reg.value;
	}


	function oldNetscape()
	{
		result=false;

		if (navigator.appName == "Netscape")
		{
			if (parseInt(navigator.appVersion.substring(0,1)) < 3)
			{
				result=true;
			}
			if ( (parseInt(navigator.appVersion.substring(0,1)) < 4)  && (navigator.appVersion.indexOf("Macintosh", 1) != -1) )
			{
				result=true;
			}
		}

		return result;
	}

	function IEandMac()
	{
		if ( (navigator.userAgent.indexOf("MSIE")!=-1)  && ( navigator.appVersion.indexOf("Macintosh", 1) != -1) )
		{
			result=true;
		}
		else
		{
			result=false;
		}
        
		return result;
	}

	function netscape()
	{
		if (navigator.appName == "Netscape")
		{
			result=true;
		}
		else
		{
			result=false;
		}
        
		return result;
	}

 	function goGetNext(formname)
	{
		if (IE2or3()==false)
		{
			getNext(formname);	
		}
	}

 	function digitalidGetNext(formname)
	{
		if ( (IE2or3()==false) && (oldNetscape()==false) && (IEandMac()==false) )
		{
			getNext(formname);
		}
	}

	function getFields()
	{

		top.document.write("<INPUT TYPE='hidden' NAME='remote_host' VALUE='https://register.btinternet.com/cgi-bin/load_page?page=register/digitalid_done.html&head=templates/digitalid_header'>");

		top.document.write("<INPUT TYPE='hidden' NAME='operation' VALUE='C1Submit'>");
		top.document.write("<INPUT TYPE='hidden' NAME='class' VALUE='CLASS1'>");
		top.document.write("<INPUT TYPE='hidden' NAME='common_name' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='embed_email' VALUE='yes'>");
		top.document.write("<INPUT TYPE='hidden' NAME='commercial' VALUE='yes'>");
		top.document.write("<INPUT TYPE='hidden' NAME='embed_czag' VALUE='NO'>");
		top.document.write("<INPUT TYPE='hidden' NAME='pers_country' VALUE='GB'>");
		top.document.write("<INPUT TYPE='hidden' NAME='pers_zip' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='pers_age' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='pers_gender' VALUE='M'>");
		top.document.write("<INPUT TYPE='hidden' NAME='payment_type' VALUE='Visa'>");
		top.document.write("<INPUT TYPE='hidden' NAME='debit_number' VALUE='4444111122223333'>");
		top.document.write("<INPUT TYPE='hidden' NAME='cardExpire_month' VALUE='12'>");
		top.document.write("<INPUT TYPE='hidden' NAME='cardExpire_year' VALUE='04'>");
		top.document.write("<INPUT TYPE='hidden' NAME='card_name' VALUE='BTopenworld'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_addr_number' VALUE='1234'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_addr_name' VALUE='BTopenworld Address 1'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_addr_unit' VALUE='1234'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_city' VALUE='BTopenworld City'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_state' VALUE='BTopenworld County'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_postal' VALUE='Post Code'>");
		top.document.write("<INPUT TYPE='hidden' NAME='bill_country' VALUE='GB'>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_homePhone' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_addr_number' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_addr_name' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_addr_unit' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='unstructured_addr' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_city' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_state' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_postal' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='mail_country' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='originator' VALUE='BT'>");
		top.document.write("<INPUT TYPE='hidden' NAME='unverified_field1' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='unverified_field2' VALUE=''>");
		top.document.write("<INPUT TYPE='hidden' NAME='token' VALUE='1704628888'>");

		if (navigator.appName == "Netscape")
		{
			top.document.write("<INPUT TYPE='hidden' NAME='enroll_track' VALUE='Netscape'>");
			top.document.write("<INPUT TYPE='hidden' NAME='form_file' VALUE='../fdf/BT/class1Netscape.fdf'>");
		}
		else
		{
			top.document.write("<INPUT TYPE='hidden' NAME='enroll_track' VALUE='MSIE'>");
			top.document.write("<INPUT TYPE='hidden' NAME='form_file' VALUE='../fdf/BT/class1MS.fdf'>");
			top.document.write("<INPUT TYPE='hidden' NAME='cryptProv' VALUE='1'>");
			top.document.write("<INPUT TYPE='hidden' NAME='public_key' VALUE=''>");
		}
	}

	// Allows letters, apostrophes and hyphens only.
	function checkField(field_name)
        {

	    	if ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion.substring(0,1)) < 4) )
	    	// Netscape 3 does not support regular expressions so we just do field-length validation.
	    	{
			full_check=false;
	    	}
		else
		{
			full_check=true;
		}

	    	if (field_name == "mail_firstName")
		{
			if (full_check==true)  
			{ 
				re = new RegExp("^[-'a-zA-Z]*$");
			}
			message = 'The First Name field accepts letters, hyphens and apostrophes only. Please change this before proceeding.';
			emptymessage = 'You must enter some text in the First Name field.';
			val = document.proform.mail_firstName.value;
		}
		else if (field_name == "mail_lastName")
		{
			if (full_check==true)  
			{
				re = new RegExp("^[-'a-zA-Z0-9]*$");
			}
			message = 'The Last Name field accepts letters, digits, hyphens and apostrophes only. Please change this before proceeding.';
			emptymessage = 'You must enter some text in the Last Name field.';
			val = document.proform.mail_lastName.value;
		}
		else if (field_name == "challenge")
		{
			if (full_check==true)  
			{
				re = new RegExp("^[-'a-zA-Z0-9 ]*$");
			}
			message = 'The Challenge Phrase field accepts letters, digits, spaces, hyphens and apostrophes only. Please change this before proceeding.';
			emptymessage = 'You must enter some text in the Challenge Phrase field.';
			val = document.proform.challenge.value;
		}

		var leng = val.length;

                if (leng == 0)
                {
                	alert (emptymessage);
                	return false;
                }
                else
                {
			if (full_check==true)  
			{
                        	for (Count = 0; Count < leng; Count++)
                        	{
                                	if (re.test(val.charAt(Count)) == 0)
                                	{
                                		alert (message);
                                		return false;
                                	}
                        	}
			}
 
                        return true;
                }
        }

	function checkThenSubmit()
	{
		if ( 	(checkField("mail_firstName")==true) && 
			(checkField("mail_lastName")==true) && 
			(checkField("challenge")==true) )
		{
			top.document.proform.submit();
		}
	}

	function checkAllFields()
	{
		checkField("mail_firstName");
		checkField("mail_lastName");
		checkField("challenge");
	}

	// This submits the Trustwise enrolment form for Netscape only. Necessary because can't
	// get N3 to do a document.proform.submit properly.
	function submitNetscape()
	{
		result=false;

		if (parseInt(navigator.appVersion.substring(0,1)) < 4)
		{
			document.write("<INPUT type='submit' NAME='accept' VALUE='Accept' onClick='checkAllFields()'>");	
		}
		else
		{
			document.write("<INPUT type='button' NAME='accept' VALUE='Accept' onClick='checkThenSubmit()'>");	
		}

		return result;
	}

	function removeSpaces(string) 
	{
		var temp = "";
		string = '' + string;
		splitstring = string.split(" ");
		for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
		return temp;
	}

	function IsMacOS()
   	{
        	var BrowserVersion = navigator.appVersion;

        	if (BrowserVersion.indexOf("Macintosh", 1) != -1)
        	{
                	return(true);
        	}
        	return(false);
   	}
   	
function rebuildDates(objs,leadOffset,holidayDates,startOffset,listLength,day,month,year)
{
   var dateOffset = leadOffset[0];
   
   if (objs[objs.selectedIndex].value == "Later ...")
   {
        dateOffset = dateOffset + 5;
        buildDates(objs,dateOffset,holidayDates,startOffset,listLength,day,month,year,"");
   }
   else
   {
   	if (objs[objs.selectedIndex].value == "Earlier ...")
   	{
   	       if (dateOffset > 8)
   	       {
   	              dateOffset = dateOffset - 5;
   	              buildDates(objs,dateOffset,holidayDates,startOffset,listLength,day,month,year,"");
   	       }
	       else
	       {
	              objs.selectedIndex=0;
     	       }
 	 }
  	 else
  	 {
  	 	if (objs[objs.selectedIndex].value == "")
		{	alert("Please choose a date that is not a bank holiday.");
		   	objs.selectedIndex = 0;
		   	var lag = 1;
			while (objs[objs.selectedIndex].value == "")
			{
			     objs.selectedIndex=lag;
			     lag++;
                        }
		}
		else if (objs[objs.selectedIndex].value == " ")
		{
		        objs.selectedIndex=0;
		}
   	 }
   }
   leadOffset[0] = dateOffset;
}

function buildDates(objs,dateOffset,holidayDates,startOffset,listLength,day,month,year,datePickedIn)
{
	var bankDateArray = holidayDates.split(",");
	var i = 0;
	var datePicked;
	
       /*This sets the bankDateArray in the format dd/mm/yyyy, allowing it to accept the dd/mm/yy format*/
	while(bankDateArray[i] != "")
	{
		var testArray = bankDateArray[i].split("/");
		var j = 0;
		while (j < 2)
		{
			var temp = testArray[j].split("0");
			if((temp[0] < "1" || temp[0] > "9") && temp[0] != null)
			{
				testArray[j] = temp[1];
			}
			j++;
				
		}
		bankDateArray[i] = testArray[0] + "/" + testArray[1] + "/" + testArray[2];
		i++;
	}
	
        var workingdays = dateOffset;
        var dateArray= new Array();
        var today = new Date(), afterLead = new Date();
        var counter = 0, countlength = 0, leadingby = 0;

  	while ( countlength < listLength )
        {
                var afterLead = new Date(year, month,day+counter);

                if ( ( afterLead.getDay()!=0 ) && (afterLead.getDay()!=6) )
                {
                        leadingby++;
                        if ( leadingby > workingdays )
                        {
                                dateArray[countlength] = afterLead;
                                countlength++;
                        }
                }
                counter++;
        }

        var j = 0;
        for (i=0;i< listLength; i++)
        {
        	if(displayDate(dateArray[i], bankDateArray) == "Bank Holiday - unavailable")
        	{
			newEnt = new Option(displayDate(dateArray[i], bankDateArray),"");
		}
		else
		{
			newEnt = new Option(displayDate(dateArray[i], bankDateArray),valueDate(dateArray[i]));
		}
                objs.options[j]=newEnt;
                j = j + 1;
        }
        
        if (dateOffset > startOffset)
        {
           var newEnt = new Option("Earlier ...","Earlier ...");
        }
        else
        {
           var newEnt = new Option(" "," ");
        }
        objs.options[5]=newEnt;
        var newEnt = new Option("Later ...","Later ...");
        objs.options[6]=newEnt;

       /*This bit of code regenerates the time the user picked originally.
         if the datePicked is equal to "", rebuildDates is the calling program, and we want to allow
                                           earlier dates if this is the case and
         if the datePicked is equal to null no date has been picked*/
        if (datePickedIn != null && datePickedIn != "")
  	{
  	   var userDate = datePickedIn.split("/");
  	   userDate[1]--;
  	   datePicked = new Date(userDate[2], userDate[1], userDate[0]);
  	   testDate = new Date(dateArray[listLength-1]);
           
          /*if the final date in the week about to be shown is less than the date picked by the user,
            we need to move on one week (the date we seek is past the end of the week)*/
           if(testDate < datePicked)
           {
               var leadOffset = dateOffset[0];
   	       leadOffset = leadOffset + 5;
   	       dateOffset[0] = leadOffset;
               buildDates(objs,dateOffset,holidayDates,startOffset,listLength,day,month,year, datePickedIn);
               return;
           }
          /*else the date about to be shown is somewhere in the week, so we need to find the specific day*/
           else
           {
               var userCounter = 0;
               while(dateArray[userCounter] < datePicked)
                   userCounter++;
               objs.selectedIndex=userCounter;
           }
    	}
    	
       /*Increments the selectedIndex by however much is needed to get past the bank holidays.
         We should only do this if a date (see above) has not been picked as this also effects the selectedIndex*/
        if (datePickedIn == "" || datePickedIn == null)
        {
             objs.selectedIndex = 0;
             var lag = 1;
	     while (objs[objs.selectedIndex].value == "")
	     {
	          objs.selectedIndex=lag;
	          lag++;
             }
        }
}

function displayDate(tmpDate,bankDateArray)
{
	var passDate = new Date(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate());
	if (validDate(passDate, bankDateArray))
	{
        	var inDate = new Date(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate());
        	inDate.setHours(12);
        	return inDate.toGMTString().substr(0,11) + " " + inDate.getFullYear();
        }
        else
        {
       		return "Bank Holiday - unavailable";
        }
}
 
function valueDate(inDate)
{
        var day,month,year;
        day=inDate.getDate();
        month=inDate.getMonth()+1;
        year=inDate.getFullYear();
        return day.toString()+"/"+month.toString()+"/"+year.toString();
}

function validDate(inDate, bankDateArray)
{
	var i = 0;
	var testDate = valueDate(inDate);
	
	while(bankDateArray[i] != null)
	{
		if(bankDateArray[i] == testDate)
			return false;
		i++;
	}
	return true;
}

function affinity_deal()
{
	var adfound = 0;
        var returned = 0;
        var objs = document.dataStructure;
        var fieldIndex;

        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
        {
                if ( objs[fieldIndex].name == "e_ad" )
                {
                        adfound = 1;
                        break;
                }
        }

        for ( fieldIndex=0; fieldIndex < objs.length; fieldIndex++ )
        {
                if ( objs[fieldIndex].name == "ad" )
                {
                        adfound = 1;
                        break;
                }
        }
		
	if ( adfound == 1 )
	{
		returned = 1;		
	}

        return returned;
}

function isIE4up()
        {
        var agt=navigator.userAgent.toLowerCase();
        var version = parseInt(navigator.appVersion);

                if ((agt.indexOf("msie") != -1) && (version >= 4) )
                {
                        return true;
                }
                else
                {
                        return false;
                }
        }

/*
 * This will fill in the "county" feild for a limited number of entries to the
 * town field. Text fields only.
 * In: thisForm: the form on the calling page.
 */
function countyComplete(thisForm) {
       /* disabling all functionality of this with the following line */
        return true;
        var objs = thisForm;
        with(objs) {
                var town = address3.value.toLowerCase();
                if (town=='bristol') {
                        objs.address3.value='Bristol';
                        objs.county.value = 'Bristol';
                } else if (town=='glasgow') {
                        objs.address3.value='Glasgow';
                        objs.county.value = 'Glasgow';
                } else if (town=='london') {
                        objs.address3.value='London';
                        objs.county.value = 'London';
                } else if (town=='manchester') {
                        objs.address3.value='Manchester';
                        objs.county.value = 'Manchester';
                }
        }
        return true;
}

/*
 * Validates the county selected from a list of drop down values.
 * This function will only validate values from drop down lists. 
 * In: thisForm: the form on the calling page.
 *     countyList: a comma seperated list of counties.
 */
function validateCountyDropDown(thisForm, countyList)
{
        var objs = thisForm;
        var userCounty = objs.county.options[objs.county.selectedIndex].value.toLowerCase();
        var bandWidth = checkFieldPresent("e_bandwidth");

        if (userCounty=="" || userCounty == null)
        {
                if (bandWidth != "B")
                       return true;
                else
                       return false;
        }
        userCounty = spaceStrip(userCounty);

        var countyArray = countyList.split(",");
        var i = 0;

        while (countyArray[i] != "" && countyArray[i] != null )
        {
                if (countyArray[i] == userCounty)
                {
                        objs.county.value=capitalWord(userCounty);
                        return true;
                }
                i++;
        }
        return false;
}

/*
 * Validates the county typed in by the user. Text fields only.
 * In: thisForm: the form on the calling page.
 *     countyList: a comma seperated list of counties.
 */
function validateCounty(thisForm, countyList)
{
        var objs = thisForm; 
        var userCounty = objs.county.value.toLowerCase();
        var bandWidth = checkFieldPresent("e_bandwidth");
          
        if (userCounty=="" || userCounty == null)
        {
                if (bandWidth != "B")
                       return true;
                else
                       return false;
        }
        userCounty = spaceStrip(userCounty);

        var countyArray = countyList.split(",");
        var i = 0;      

        while (countyArray[i] != "" && countyArray[i] != null )
        {
                if (countyArray[i] == userCounty)
                {
                        objs.county.value=capitalWord(userCounty);
                        return true;
                }
                i++;
        }
        return false;
}

/*
 * Sets the country in a drop down list to the appropriate value. Change personal details.
 * In: thisForm: the form on the calling page.
 *     in_country: the user's selected country
 */
function SetCountry(thisform,in_country)
{
	var country = in_country.toLowerCase();
	var objs;
	var length;
	var found = false;
	objs = thisform;
	
	length = objs.country.length;
	for ( elementIndex = 0; elementIndex < length; elementIndex++ )
	{
		if ( objs.country[elementIndex].value.toLowerCase() == country )
		{
			objs.country.selectedIndex = elementIndex;
			found = true;
		}
	}
	if(!found)
	{
		for(elementIndex = 0; elementIndex < length && objs.country[elementIndex].value.toLowerCase() != "united kingdom"; elementIndex++)
			;
		objs.country.selectedIndex = elementIndex;
	}
}

/*
 * Portal registration country. Address1, county and postcode should be set to not required
 * if the user is from outside the UK, or cleared to indicate requirement if they change back to
 * UK as their country. Text fields.
 * In: thisForm: the form on the calling page.
 */
function checkCountry(thisForm, whichCheck) {
	var objs = thisForm;
	var country = objs.country.value.toLowerCase();
	if (country != 'united kingdom' && country != "u.k." && country != "uk") {
                with (objs) {
                        address1.value = 'not required';
                        county.value = 'outside uk';
                        postcode.value = 'not req';
                }
        } else {
                with (objs) {
                        address1.value = '';
                        county.value = '';
                        postcode.value = '';
                }
        }
}

/*
 * Change personal details country. Address1, county and postcode should be set to not required
 * if the user is from outside the UK, or cleared to indicate requirement if they change back to
 * UK as their country. Drop down lists.
 * In: thisForm: the form on the calling page.
 */
function checkDropDownCountry(thisForm) {
        var objs = thisForm;
        if (objs.country.options[objs.country.selectedIndex].value.toLowerCase() != 'united kingdom') {
                with (objs) {
                        address1.value = 'not required';
                        county.value='outside uk';
                        county.selectedIndex = '98';
                        postcode.value = 'not req';
                }
        } else {
                with (objs) {
                        if(address1.value == 'not required')
                            address1.value = '';
                        if(county.value == 'outside uk')
                            county.value = '';
                        if(county.selectedIndex == '98')
                            county.selectedIndex = '0';
                        if(postcode.value=='not req')
                            postcode.value = '';
                }
        }
}

/*
 * Sets the county field in change personal details and change broadband product.
 * Drop down list.
 * In: thisForm: the form on the calling page.
 *     in_county - the user's choice of county take from database.
 *     whichSet - 0=broadband change product, 1=change personal details
 */
function SetCounty(thisform,in_county,whichSet)
{
        var county  = in_county.toLowerCase();
        var objs;
        var length;
        var found = false;
        objs = thisform;

        length = objs.county.length;


        for ( elementIndex = 0; elementIndex < length; elementIndex++ )
        {
                if ( objs.county[elementIndex].value.toLowerCase() == county )
                {
                        objs.county.selectedIndex = elementIndex;
                        found = true;
                }
        }
        if(!found)
        {
                objs.county.selectedIndex = '0';
        }
        if(whichSet == 0)
        {
                if(objs.county.options[objs.county.selectedIndex].value == 'OUTSIDE UK')
                        objs.county.selectedIndex = '0';
                if(objs.address1.value == 'NOT REQUIRED')
                        objs.address1.value = '';
                if(objs.postcode.value == 'NOT REQ')
                        objs.postcode.value = '';
        }
}

/*
 * Checks the county field in change personal details and broadband change product. Drop down list.
 * In: thisForm: the form on the calling page.
 *     whichReg - 0=broadband change product, 1=change personal details
 */
function checkCounty(thisForm,whichReg)
{
        var objs = thisForm;
        if (whichReg == 1)
                var country = objs.country.options[objs.country.selectedIndex].value.toLowerCase();
        else
                var country = 'united kingdom';

        if (country == 'united kingdom' && objs.county.options[objs.county.selectedIndex].value.toLowerCase() == 'outside uk')
             objs.county.selectedIndex = '0';
        else if (country != 'united kingdom')
             objs.county.selectedIndex = '98';
}

function parseCookie(name) {

  // if there's no cookie, return false else get the value and return it
  var returnValue = "";

  if(document.cookie == '')
  {
	return false;
  }
  else
  {
	 returnValue = unescape(getCookieValue(name));
  }
  
  /*The unescape above unescapes the boolean value false to the string
    "false", so we also have to check for that. This occurs when there
    was no matching cookie*/
  if("false" == returnValue)
  {
     return false;
  }
  return returnValue;
}

function getCookieValue(name)
{
  // Declare variables.
  var firstChar, lastChar;

  // Get the entire cookie string. (This may have other name=value pairs in it.)
  var theBigCookie = document.cookie;

  // Grab just this cookie from theBigCookie string.

  // Find the start of 'name'.
  firstChar = theBigCookie.indexOf(name);

  // If you found it,
  if(firstChar != -1)
{
  // skip 'name' and '='.
  firstChar += name.length + 1;

// Find the end of the value string (i.e. the next ';').
    lastChar = theBigCookie.indexOf(';', firstChar);

    if(lastChar == -1) lastChar = theBigCookie.length;

    // Return the value.
    return theBigCookie.substring(firstChar, lastChar);

  } else {
    // If there was no cookie, return false.
    return false;
  }
}

function markCookieUsed(name)
{
   document.cookie = name+"=used;path=/";
}

function isUKAffiliate()
{
   var refer = parseCookie("ref");
   if ((refer == "UKA") || (refer == "uka"))
   {
      return true; 
   }
   return false;
}

function isTradeDoubler()
{
   var refer = parseCookie("ref");
   if ((refer == "TDN") || (refer == "tdn"))
   {
      return true; 
   }
   return false;
}

function clearEmailtext()
   {
        document.details.emailtext.value="";
   }
   
/*
 * This checks to see if a field is present in the dataStructure.
 * in checkField: the name of the field to check for
 * out: returns the value of the field if it is found and null otherwise
 */
function checkFieldPresent(checkField)
{
   var objs;
   var field;
   var foundField = null;

   objs = document.dataStructure;

   for (field = 0; field < objs.length; field++)
   {
      if (objs[field].name == checkField)
      {
         foundField = objs[field].value;
         break;
      }
   }
   return foundField;
}

/*
 * If a field is present it is updated.
 * in: fieldname - the name of the field to be updated
 *     invalue - the value to update the field to
 */
function updateField(fieldname, invalue)
{
    var objs;
    var field;
    objs = document.dataStructure;
    
       for (field = 0; field < objs.length; field++)
       {
          if (objs[field].name == fieldname)
          {
             objs[field].value = invalue;
          }
   }
}


/*
 * Inputs a chunk of text, and strips off the leading and trailing spaces
 * in: textField - the chunk of text to be stripped
 * out: returns the stripped text
 */
function spaceStrip(textField)
{
    var newText = textField;

    /* trim off the trailing spaces */
    while(newText.charAt(newText.length-1)== ' ')
    {
          newText = newText.substring(0, newText.length-1);
    }

    /* now trim off the leading spaces */
    while(newText.charAt(0) == ' ')
    {
         newText = newText.substring(1, newText.length);
    }
    return newText;
}


/*
 * Capitalises the first letter of the provided word
 * in: lowercase word
 * out: returns the word with the first letter capitalised.
 */
function capitalWord(lowerword)
{
    var firstLetter = lowerword.substring(0,1).toUpperCase();
    var restOfWord = lowerword.substring(1, lowerword.length);

    lowerword = firstLetter + restOfWord;
    return lowerword;
} 

/*
 * Displays a drop-down list of values, and when an option is picked, populates the original HTML field
 * in: name - the name of the field to be populated
 *     output - the name and path to the field to be populated
 *     inputList - a comma seperated list of counties
 */
function displayDropDownList(name, output, inputList)
{
     var valueArray = new Array();
     var i = 0;
     var BrowserVersion = navigator.appVersion;
     
     if (BrowserVersion.indexOf("Macintosh", 1) != -1)
           alert("Please use list of suggestions we are about to supply to select a valid county or region.");
           
     var valueArray = inputList.split(",");
     
     /* added space in window.open command for PR 3031 */
     newwin = window.open(' ','','top=150,left=150,width=325,height=300');
     
     if (!newwin.opener)
          newwin.opener = self;
     
     with (newwin.document)
     {
          open();
          write('<html>');
          write('<body bgcolor="white" onLoad="document.form.box.focus()"><form name=form><br>');
          write('<p>Please allow a moment for this page to load.</p>');
          write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
          write('<p><center>' + name + ':  <select name=box onChange=' + output + '=this[selectedIndex].value>');
          write('<OPTION VALUE="">Select</OPTION>');
          
          while (valueArray[i] != "" && valueArray[i] != null)
          {
               write('<OPTION VALUE="');
               write(valueArray[i]);
               write('">');
               write(valueArray[i]);
               write('</OPTION>');
               i++;
          }
          
          write('</SELECT>');
          write('<p><a href="javascript:window.close();"><img src="/register/images/county_close.gif" border="0" alt="Close window"></a>');
          write('</center></form></body></html>');
          close();
     }
}

function setupLeadDays()
{
    var testDateArray;
    var dayCounter=0;
    var loopCounter=0;

    /*If the leadDate is 0, this means no date was selected from the database. However the C code should
      then have populated the lead days itself*/
    if ("0" == leadDate)
    {
        if(isdn_days != 0)
        {
            leadDays[0] = leadDays[0] + isdn_days;
            startOffset[0]= startOffset[0] + isdn_days;
        }
        return;
    }

    testDateArray=leadDate.split("/");
    
    /*Each time a new date is created, we use mid-day as there were some problems with using the default
      midnight when it comes time to change the clocks*/
    thisDate = new Date(year, month, day, 12);
    testDate = new Date(testDateArray[2], (testDateArray[1]-1), testDateArray[0], 12);

    /*If the input date is less than or equal to today, offer ten days in the future as days in the past are invalid*/
    if(testDate <= thisDate)
        dayCounter=10;

    /*Find out how far in advance we have to set the lead days - we don't need an else here, as if the above
      if is true, the following while will never be true*/
    while(thisDate < testDate)
    {
        if(thisDate.getDay() != 0 && thisDate.getDay() != 6)
            dayCounter++;
        loopCounter++;
        thisDate = new Date(year, month, (day + loopCounter), 12);
    }

    /*If there are extra isdn days add them on*/
    if(isdn_days != 0)
        dayCounter = dayCounter + isdn_days;

    /*Now set up the values used by the javascript*/
    leadDays[0] = dayCounter;
    startOffset[0]= dayCounter;
}


 function callGrabkey(e)
 {
     // Call grabkey if telNoRetype input box generated the event

     if (e.target.name == "telNoRetype")
     {
 	return grabkey(e, e.target);
     }
 }

 function grabkey(e, objText)
 {
     // A function to examine the keystrokes in an input
     // box to see if the backspace or delete key was pressed
     // Other keypresses are passed straight through
     // e holds the event object for the keypress
     // objText is the text entry field that generated the keypress

     var intKey = 0;
     keytracker = 1;

     if (document.all)
     {
         // MSIE - set e equal to the event object
         e = window.event;
         intKey = e.keyCode;
     }
     else if (document.layers)
     {
         // NN - e already contains the event object
         intKey = e.which;
     }

     if (intKey == 8 || intKey == 46)
     {
         objText.value = objText.value.slice(1);
         return false;
     }
     else
     {
         return true;
     }
 }

 function callReversit(e)
 {
     // Call reversit if telNoRetype input box generated the event

     if (e.target.name == "telNoRetype")
     {
 	return reversit(e, e.target);
     }
 }

 function reversit(e, objText)
 {
     // A function to reverse the order of the keystrokes for
     // text entered into an input box
     // e holds the event object for the keypress
     // objText is the text entry field that generated the keypress

     var intKey = 0;

     if (document.all)
     {
         // MSIE - set e equal to the event object
         e = window.event;
         intKey = e.keyCode;
     }
     else if (document.layers)
     {
         // NN - e already contains the event object
         intKey = e.which;
     }

     if (intKey >=32 && intKey <=126)
     {
         objText.value = String.fromCharCode(intKey) + objText.value;
     }
     else if (intKey == 8)
     {
         objText.value = objText.value.slice(1);
     }

     return false;
 }

 function reverseString(strText)
 {
     var intCount = 0;
     var strBuffer = "";
     
     for (intCount = strText.length; intCount > 0; intCount--)
     {
         strBuffer = strBuffer + strText.charAt(intCount - 1);
     }
     return strBuffer;
 }

// </SCRIPT>
