<!--

/* -----------------------------------------------------------------------------------------------
   Begin - maximum length catcher - used by:
   1Hotel registration Form
   
   ----------------------------------------------------------------------------------------------- */

function maximumLength(formField)
{
	var maxiLength = formField.getAttribute('maxlength')
	var input = formField.value.length

	if (input > maxiLength)
		{
		alert ('The maximum number of characters is 225. Please email additional information to the hotel coordinator. Thank you.');
		return false;	
		}
	else
		return true;
}

/* -----------------------------------------------------------------------------------------------
   Begin - validate is number field - onkeypress / also validate not zero onblur
   ----------------------------------------------------------------------------------------------- */
function isNumberInput(field, event)
{

var key, keyChar;
if (window.event)
key = window.event.keyCode;
else if (event)
key = event.which;
else
return true;
// Check for special characters like backspace
if (key == null || key == 0 || key == 8 || key == 13 || key == 27)
return true;
// Check to see if it.s a number
keyChar = String.fromCharCode(key);
if (/\d/.test(keyChar))
{
return true;
}
else if (key = "")
{key = "0";
alert(key.value);
}

else
{
alert("This field accepts numbers only.");
return false;
}
}


function mask(f){
tel='(';
var val = f.value.split('');
for(var i=0;i<val.length;i++){
if(i==2){val[i]=val[i]+')'}
if(i==5){val[i]=val[i]+'-'}
tel=tel+val[i]
}
f.value=tel;
}


function needZero(field)
{
if (field.value == "")
{field.value = "0";
}
}
/* -----------------------------------------------------------------------------------------------
   Begin - separate hotel name from per day commission and calculate total commission
   USED BY: AlbionHotelReg/default & AlbionHotelReg/update_tournHotelReg
   ----------------------------------------------------------------------------------------------- */
function format(value)
{
/* Format to have only two decimal digits
   IMPORTANT to keep here as next function uses this function! */
var temp = Math.round(value * 100);
temp = temp / 100;
return temp;
}

function calc(hotel)
{
with (document.tournHotelReg)	
{
	totalNo.value = format (
	parseFloat(thursday.value) +
	parseFloat(friday.value) +
	parseFloat(saturday.value) +
	parseFloat(sunday.value) +
	parseFloat(monday.value) +
	parseFloat(tuesday.value)  +
	parseFloat(wednesday.value) );

	/* finds 1 to 3 digits followed by decimal followed by 1 to 3 digits */
	var objDecimalNumber = /\d{1,3}\.\d{1,3}/;
	var strHotel = hotel;
	/* finds everything within brackets - brackets escaped */
	var objWithinBrackets = /[\w\s\/\\\.\*\&\?]+/;
	var strCost = strHotel.match(objDecimalNumber); 
	var strHotelName = strHotel.match(objWithinBrackets);	
	
	commission.value = (totalNo.value * strCost).toFixed(2); /* need toFixed to limit to two decimal places */
	hotelNameOnly.value = strHotelName;

}
}

/* -------------------------------------------------------------
	Start Validation A utility function that returns true if a string contains only whitespace characters - 
	runs through all fields in form, but bypasses any that are set as optional in the "onsubmit" call in the form
	---------------------------------------------------------------*/
function isblank(s) {
    for(var i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
    }
    return true;
}

/*  This is the function that performs form validation. 
	It is invoked from the onsubmit event handler. 
	Used by:
	AlbionReg/Albion_reg.asp
	AlbionHotelReg/default & update_tournHotelReg.asp
	AlbionCupTshirtOrder/default
	The handler should return whatever value this function returns. 
	IMPORTANT - the notification of missing info is derived from the "Title" of the form field that is missing */
function verify(f) 
{
    var msg;
    var empty_fields = "";
	var empty_fieldsName ="";
    var errors = "";

/* this is the spam catcher */
if(f.elements[0].value.length > 0)
{
alert ('you are spam!!');
return false;

}

else
{
    /* 	Loop through the elements of the form, looking for all text and textarea elements that don't have an "optional" property defined. 
		Then, check for fields that are empty and make a list of them.
      	Also, if any of these elements have a "min" or a "max" property defined, verify that they are numbers and in the right range.
    	If the element has a "numeric" property defined, verify that it is a number, but don't check its range.
  		Put together error messages for fields that are wrong. */
    for(var i = 0; i < f.length; i++) 
	{
        var e = f.elements[i];
		/* specify field types to check and if they are NOT optional as noted in the onsubmit statement */
        if (((e.type == "select-one") || (e.type == "text") || (e.type == "textarea")) && !e.optional) 
		{
            // check if the field is empty
            if ((e.selectedIndex == 0 ) || (e.value == null) || (e.value == "") || isblank(e.value)) 
			{
				e.className="required";
				empty_fields += "\n" + e.title + " is required.";				
                continue;
            }

         }
      }
}
    

    // Now, if there were any errors, display the messages, and
    // return false to prevent the form from being submitted. 
    // Otherwise return true.
    if (!empty_fields) return true;

    msg  = "_______________________________________________________________________________\n\n"
    msg += "The form was not submitted because some required information was not provided.\n";
    msg += "Please correct the following errors (highlighted in red) and resubmit the form.\n";
    msg += "________________________________________________________________________________\n\n";

    if (empty_fields) 
	{
		msg += empty_fields + "\n";
			if(document.getElementById('pleaseWait'))
			{document.getElementById('pleaseWait').className='hidden';}
    }
    //document.getElementById('errorMessage').firstChild.nodeValue=msg;	
	alert(msg);		
    return false;
}


/* -----------------------------------------------------------------------------------------------
   Begin - spam catcher - also used in validation above - hidden div that if filled in proves it's a spammer it's not visible
   ----------------------------------------------------------------------------------------------- */
function validateForm(theForm)
{
  if (theForm.trapper.value.length > 0)
  {
    alert ('you are spam!!');
    return false;
	
  }
  else
  return true;
}

// Define whitespace characters
var whitespace = " \t\n\r";
function isEmpty(s)
{
var i;
if((s == null) || (s.length == 0))
return true;
// Search string looking for characters that are not whitespace
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);
if (whitespace.indexOf(c) == -1)
return false;
}
// At this point all characters are whitespace.
return true;
}
function validate()
{
if (isEmpty(document.myform.username.value))
{
alert("Error: Username is required.");
document.myform.username.focus();
return false;
}
if (isEmpty(document.myform.userpass.value))
{
alert("Error: Non-empty password required.");
document.myform.userpass.focus();
return false;
}
return true;
}


//function to check valid email address
function isValidEmail(strEmail)
{
  
  	validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
 	var strEmail = document.forms['tournHotelReg'].email.value;

   // search email text for regular exp matches
   if (strEmail.search(validRegExp) == -1) 
   {
      alert('Please enter a valid e-mail address, and remove extra spaces.');
      return false;
    } 
    return true; 
}

function isSameEmail(email, emailVerify)
{
	var strEmail = document.forms['tournHotelReg'].email.value;
	var strEmailSame = document.forms['tournHotelReg'].email_verify.value;
	var strEmailSameClass = document.forms['tournHotelReg'].email_verify;
	
	if (strEmail != strEmailSame)
		{
		alert('Your email entries must be identical. Please review and correct your entry.');
		strEmailSameClass.className='fixIt';
		emailVerify.value="";
		emailVerify.focus();
		return false;
		}
		return true;
}



/***********************************************
* Textarea Maxlength script- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length > mlength)
obj.value=obj.value.substring(0,mlength)
alert('This field is limited to 225 characters. Please limit your comment. If you are listing confirmation numbers, please note that it is not necessary to list how many nights for each confirmation. You man contact the coordinator for assistance. ')
}

//-->

