function GetOpCookie(name) {
  var cookies = document.cookie.split( ';' );
  var cookie = '';
  for(var i=0; i<cookies.length; i++) {	
    cookie = cookies[i].split('=');//alert(cookie[0]+"="+name+":"+cookie[0].indexOf(name));
    c=cookie[0];
    if(c.indexOf(name)>=0 && ((c.indexOf(name)+ name.length) == c.length)) {//alert(c.indexOf(name)+"+"+ name.length+"="+c.length);
      return (cookie.length <= 1) ? "" : unescape(cookie[0]+"="+cookie[1].replace(/^\s+|\s+$/g, ''));
    }
  }
  return null;
}

function notChecked(radio_button, strBodyHeader) {
// set var radio_choice to false
	var radio_choice = false;
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < radio_button.length; counter++)
	{
	// If a radio button has been selected it will return true
	// (If not it will return false)
		if (radio_button[counter].checked) {
			radio_choice = true; 
			//alert ('district nurse '+counter);
		}	
	}
	if (!radio_choice)
	{
	// If there were no selections made display an alert box 
		alert("\"" + strBodyHeader + "\" is a required field. Please make a selection.");
		return true;		
	}
	return false;
}

function isChecked(field, strBodyHeader) {
	for (counter = 0; counter < field.length; counter++)
	{
		if (field[counter].checked)
		{ return true; }
	}

	alert("\"" + strBodyHeader + "\" is a required field. ");
	
	return false;	
}

function isSelected(field, strBodyHeader) {
	for(i=0; i < field.length; i++) { if (field[i].selected && (trim(field[i].value).length > 0)) return true; }
	alert("\"" + strBodyHeader + "\" is a required field. Please choose a selection.");
	field.focus();
	return false;

}

function trimLeft(s) {
	var whitespaces = " \t\n\r";
	for(n = 0; n < s.length; n++) { if (whitespaces.indexOf(s.charAt(n)) == -1) return (n > 0) ? s.substring(n, s.length) : s; }
	return("");
}

function trimRight(s){
	var whitespaces = " \t\n\r";
	for(n = s.length - 1; n  > -1; n--) { if (whitespaces.indexOf(s.charAt(n)) == -1) return (n < (s.length - 1)) ? s.substring(0, n+1) : s; }
	return("");
}

function trim(s) {return ((s == null) ? "" : trimRight(trimLeft(s))); }

function isBlank(field, strBodyHeader) {
strTrimmed = field.value;
if (strTrimmed.length > 0) return false;
alert("\"" + strBodyHeader + "\" is a required field. Please type a value.");
field.focus();
return true;
}

function isEmail(field, strBodyHeader){
emailStr = field.value;
if(emailStr.length == 0) return false;
if(!complexEmailCheck(emailStr)) {
alert("Error: Invalid email address. Please type a valid email address for field " + strBodyHeader + ".");
field.focus();
return false;
}

document._mktf.submit();
}

function complexEmailCheck(emailStr){
if(emailStr == "") return false;
if(emailStr.indexOf("@")==-1) return false;
if(emailStr.indexOf(".")==-1) return false;
if(emailStr.indexOf(" ")!=-1) return false;
if(emailStr.indexOf(",")!=-1) return false;
return true;
}
	function PageQuery(q) {
		if(q.length > 1) this.q = q.substring(1, q.length);
		else this.q = null;
		this.keyValuePairs = new Array();
		if(q) {
			for(var i=0; i < this.q.split("&").length; i++) {
				this.keyValuePairs[i] = this.q.split("&")[i];
			}
		}
	
		this.getKeyValuePairs = function() { return this.keyValuePairs; }
	
		this.getValue = function(s) {
			for(var j=0; j < this.keyValuePairs.length; j++) {
				if(this.keyValuePairs[j].split("=")[0] == s)
					return this.keyValuePairs[j].split("=")[1];
				}
				return false;
				}
			this.getParameters = function() {
			var a = new Array(this.getLength());
			for(var j=0; j < this.keyValuePairs.length; j++) {
				a[j] = this.keyValuePairs[j].split("=")[0];
			}
			return a;
		}
		this.getLength = function() { return this.keyValuePairs.length; } 
	}
	
	function queryString(key){
		var page = new PageQuery(window.location.search); 
		return unescape(page.getValue(key)); 
	}
	
		function displayItem(key){
		if(queryString(key)=="false") 
		{
			return false;
		}else{
			var myhbxref = queryString(key);
			return myhbxref;
		}
	}

function  isStandardDomain( domainIn )  {

	/// The value to return, start out assuming invalid domain.
	var  isStandardReturn = false;
	
	/// Holds the last 5 characters of domain name.
	var  last5chars  =  domainIn.substring( domainIn.length-5, domainIn.length );	

	/// Holds the last 4 characters of domain name.
	var  last4chars  =  domainIn.substring( domainIn.length-4, domainIn.length );

	/// Holds the last 3 characters of domain name.
	var  last3chars  =  domainIn.substring( domainIn.length-3, domainIn.length );

	/// Uppercase it for comparison purposes.
	last4chars = last4chars.toUpperCase();
	last5chars = last5chars.toUpperCase();	

	/// A regular expression pattern to match country code domains.
	///  In otherwords a Dot character followed by two alphabetic characters.
	/// NOTE:  This line doesn't work at all in Opera3.5 and prevents the
	///  entire script from running!!!  BUMMER!!!
	///  It also seems to not work in Opera4.02 but only prevents
	///  the 2 letter codes from working but doesn't crash the script.
	var  countryCodePattern = /\.[a-zA-Z][a-zA-Z]/;

	if      ( last4chars == ".COM" ) isStandardReturn = true;
	else if ( last4chars == ".EDU" ) isStandardReturn = true;
	else if ( last4chars == ".GOV" ) isStandardReturn = true;
	else if ( last4chars == ".NET" ) isStandardReturn = true;
	else if ( last4chars == ".MIL" ) isStandardReturn = true;
	else if ( last4chars == ".INT" ) isStandardReturn = true;	
	else if ( last4chars == ".ORG" ) isStandardReturn = true;
	else if ( last4chars == ".BIZ" ) isStandardReturn = true;	
	else if ( last4chars == ".NOM" ) isStandardReturn = true;		
	else if ( last4chars == ".PRO" ) isStandardReturn = true;			
	else if ( last4chars == ".WEB" ) isStandardReturn = true;	
	else if ( last4chars == ".CAT" ) isStandardReturn = true;	
	else if ( last4chars == ".TEL" ) isStandardReturn = true;	
	else if ( last5chars == ".INFO" ) isStandardReturn = true;		
	else if ( last5chars == ".NAME" ) isStandardReturn = true;		
	else if ( last5chars == ".COOP" ) isStandardReturn = true;			
	else if ( last5chars == "STORE" ) isStandardReturn = true;			
	else if ( last5chars == ".FIRM" ) isStandardReturn = true;				
	else if ( last5chars == ".ARPA" ) isStandardReturn = true;		
	else if ( last5chars == "USEUM" ) isStandardReturn = true;			
	else if ( last5chars == ".AERO" ) isStandardReturn = true;				
	else if ( last5chars == ".NATO" ) isStandardReturn = true;	
	else if ( last5chars == ".JOBS" ) isStandardReturn = true;		
	else if ( last5chars == ".MOBI" ) isStandardReturn = true;			
	else if ( last5chars == ".ASIA" ) isStandardReturn = true;				
	else if ( last5chars == "RAVEL" ) isStandardReturn = true;		
	else if ( last3chars.search( countryCodePattern )   !=  -1 )
		isStandardReturn = true;
		
	return  isStandardReturn;

} // Ends isStandardDomain( domainIn ).


/// Checks basic validity of an email address that's passed in.
///  Requires proper configuration of the '@' character lack of Spaces
///  and calls function "isStandardDomain()" to check on the form of the
///  domain name part.
/// Used an alert box to display it's answer.
/// This function needs JS1.2 [because isStandardDomain() does] and does not work in Opera3.5.
function  validateEmailAddress2( emailIn )  {

	var  isStandardReturn = false;

	/// Number of '@' chars present in input string.
	var  numAtChars;

	/// The part of input address before the '@' character.
	var  userNameIn;

	/// The part of input address after the '@' character.
	var  domainNameIn;

	/// Holds the fields of the entered address, delimitted by '@' chars.
	var  addressFields = new Array();

	// Concatenate all alert output to here.
	var  alertString = "";


	/// Divide the input email address into fields.
	///  Note that the array "addressFields" will have one more element
	///  than the number of '@' signs in the input string.
	/// IE4 handles this OK with '@' as last character but NS4,4.5 and Opera 3.5 don't.
	addressFields = emailIn.split( '@' );

	numAtChars = addressFields.length - 1;
	
	var filter  = /^([a-zA-Z0-9_\.\-\'\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	

	alertString += "The contents of the Email Address field:   \"" + emailIn + "\" - ";


	if ( emailIn == "" )
		alertString += "is EMPTY.";

	else if ( numAtChars  ==  0 )
		alertString += "contains no '@' character and is therefore Not a valid Email Address.";

	else if ( numAtChars  >  1 )
		alertString += "contains " + numAtChars + " '@' characters and is therefore Not a valid Email Address.";

	else if ( addressFields[0] == "" )
		alertString += "has no Username before the '@' character and is therefore Not a valid Email Address.";

	else if ( addressFields[1] == "" )
		alertString += "has no Domain Name after the '@' character and is therefore Not a valid Email Address.";
		

	else
		{
		userNameIn   = addressFields[0];
		domainNameIn = addressFields[1];

		if ( userNameIn.indexOf( " " ) != -1 )
			alertString += "has one or more Spaces in the Username before the '@' character and is therefore Not a valid Email Address.";
		else if ( domainNameIn.indexOf( " " ) != -1 )
			alertString += "has one or more Spaces in the Domain Name after the '@' character and is therefore Not a valid Email Address.";

		else if ( isStandardDomain( domainNameIn ) == false )
			alertString += "does not end with a '.com' style domain or two letter country code domain and is therefore Not a valid Email Address.";

		else if (!filter.test(emailIn)) 	
			alertString += "contains invalid characters.";

		else
			alertString = "";

	} // Ends else from outer string of if-then-else's.

	// Post the alert box.

	if (alertString == "")
		isStandardReturn = true;
	else
		alert( alertString );		
		
	
	return  isStandardReturn;
	

} // Ends validateEmailAddress2().
   

