//validateInputScript.js - © 2006 - last modified 25.06.2006 by Philip Sparke of sunny-properties.com
onerror=handleErr;
var txt="", errorDetailedMessage="",  inerror=0;

// create new Error objects
mandatoryFieldError = new Error ("Field cannot be blank or left empty!");
passwordError = new Error ("The confirmation Password you entered does not match the first password entered,\n please re-enter both, the case of each character entered must be the same!");
formReSubmissionError = new Error ("An attempt has been made to automatically re-submit a form without specifying the formID!");
internalASPError = new Error ("Internal ASP code error encountered!");
emailAddressError = new Error ("The confirmation Email Address you entered does not match the first Email Address entered,\n please re-enter both, the case of each character entered must be the same!");

function handleErr(msg,url,l)
{
	txt="There was an JS error on this page.\n\n";
	txt+="Error: '" + msg + "'\n";
	txt+="URL: '" + url + "'\n";
	txt+="Line: '" + l + "'\n\n";
	txt+="Please e-mail the above information to the web master at: \n\n";
	txt+="webmaster@sunny-properties.com \n\n";
	txt+="Click OK to continue.\n\n";
	alert(txt);
	return true;
}

function mainExceptionHandler(e)
{
	alert (e.message+"\n"+errorDetailedMessage);
	inerror=-1;
}

function ValidateInputString(stringToBeValidated, numberOrString, formFieldID, debugOption)
{
	//This function attempts to check for and then remove banned words from a form's input field (stringToBeValidated)
	//numberOrString signifies whether this is a text or number field
	//id is the id of the field form
	//debugOption ('xxx') determines whether debug information is alerted to the user
	errorDetailedMessage = "(jsfVIS): ";
	//Declaring varibales
	var re, rawInputString, rawInputStringUC, cleanString, testString, exitLoop, stringLength;
	var bannedKeyWords, arrayLength, arrayIndex, nonSpaceCharFound;
	//Here we execute the code within a try
	try
	{
		if ( (numberOrString == null)||(numberOrString == "")||(formFieldID == null)||(formFieldID == "") )
		{
			if (numberOrString == null)
			{
				numberOrString = "NULL";
			}
			if (formFieldID == null)
			{
				formFieldID = "NULL";
			}
			errorDetailedMessage = errorDetailedMessage + "stringToBeValidated:["+stringToBeValidated+"];numberOrString:["+numberOrString+"];formFieldID:["+formFieldID+"]";
			throw internalASPError;
		}
		else
		{
			if (debugOption == "Yes")
			{
				alert("stringToBeValidated:["+stringToBeValidated+"]; numberOrString:["+numberOrString+"];formFieldID:["+formFieldID+"]");
			}
		}

		//Here we check if field entry is manadatory depending on the type of data expected
		if ( ( (stringToBeValidated == null) || ( stringToBeValidated == "") || ( stringToBeValidated.toUpperCase() == "REQUIRED!") || ( stringToBeValidated.toUpperCase() == "PLEASE SELECT") ) && ( (numberOrString == "numberMandatory") || (numberOrString == "currencyMandatory")||(numberOrString == "stringMandatory")||(numberOrString == "checkboxMandatory") ||(numberOrString == "dropDownListMandatory")) )  
		{
			errorDetailedMessage = errorDetailedMessage + "Field '" + formFieldID.substring(3,formFieldID.length) + "' must be completed, it is mandatory as are all fields marked with an * ";
			alert(errorDetailedMessage);
			//throw mandatoryFieldError;
			//return "MandatoryError";
			cleanString = "MandatoryError";
		}
		else
		{
			bannedKeyWords = Array('"', "'", "*", "%", "SELECT", "DELETE", "TRUNCATE", "UPDATE", "INSERT", "=", "EXECUTE", "CUNT", "FUCK", "FUCKING", "BASTARD", " PRICK ", "SHIT", "OLD FART", "FARTTING", " ARSE", "ARSEHOLE", "WANKER", "FUCKER", "SWINE", "BLOODY", "FRIGGING", "PISS", "BUGGER");
			arrayLength = bannedKeyWords.length;
			if ( (debugOption == "Yes")||(debugOption == "IO") )
			{ 
				alert("Entering ValidateInputString with stringToBeValidated:["+stringToBeValidated+"],numberOrString:["+numberOrString+"],array length:["+arrayLength.toString()+"]");
			}
			rawInputStringUC = stringToBeValidated.toUpperCase();
			rawInputString = stringToBeValidated;
			arrayIndex = arrayLength; //Number of keyword strings in Array to check for
			//Loop through each word in array and replace evry occurence of banned word in field as required with " "
			//Then we remove extra spaces that were genereated as required
			while (arrayIndex > 0)
			{
				testString = bannedKeyWords[arrayIndex-1];//banned word to check
				if(debugOption == "IO")
				{ 
					alert("bannedKeyWords[" + (arrayIndex-1).toString() + "];current banned word:["+testString+"]");
				}
				while (rawInputStringUC.indexOf (testString,0) >= 0 )
				{
					rawInputString = ( rawInputString.substring (0,rawInputStringUC.indexOf (testString,0)) + rawInputString.substring (rawInputStringUC.indexOf (testString,0)+testString.length, rawInputStringUC.length) );
					rawInputStringUC = ( rawInputStringUC.substring (0,rawInputStringUC.indexOf (testString,0)) + rawInputStringUC.substring (rawInputStringUC.indexOf (testString,0)+testString.length, rawInputStringUC.length) );
				}
				arrayIndex -= 1;
			}
			//re = new RegExp(" ");
			//cleanString = rawInputString.replace(/ /, "");
			//Here we remove extra speaces previously generated as required
			stringLength = rawInputString.length;
			exitLoop = 0;
			nonSpaceCharFound = 0;
			if(debugOption == "Yes")
			{ 
				alert("rawInputString:["+rawInputString+"]"); //field prior to space removal
			}
			
			while (exitLoop <= (stringLength -1))
			{
				if(debugOption == "Yes")
				{ 
					alert("rawInputString.charCodeAt("+exitLoop+")["+rawInputString.charCodeAt(exitLoop)+"]");
				}

				if (rawInputString.charCodeAt(exitLoop) != 32)
				{
					nonSpaceCharFound += 1;
					//alert("nonSpaceCharFound("+nonSpaceCharFound+"]");
				}
				else if ( (rawInputString.charCodeAt(exitLoop) == 32) && (nonSpaceCharFound == 0) )
				{
					rawInputString = rawInputString.replace(/ /, "");
					stringLength = rawInputString.length;
					//alert("stringLength["+stringLength+"]");
				}
				exitLoop += 1;
			}
			cleanString = "";
			if ((numberOrString == "number")||(numberOrString == "numberMandatory"))
			{
				//We are not processing a string so remove all characters which are not numbers!
				stringLength = rawInputString.length;
				exitLoop = 0;
				while (exitLoop <= (stringLength -1))
				{
					if(debugOption == "Yes")
					{ 
						alert("Number-rawInputString.charCodeAt("+exitLoop+")["+rawInputString.charCodeAt(exitLoop)+"]");
					}
					//if number between ascii 48 and 57
					if ((rawInputString.charCodeAt(exitLoop) >= 48) && (rawInputString.charCodeAt(exitLoop) <= 57))
					{
						cleanString += rawInputString.charAt(exitLoop);
					}
					exitLoop += 1;
				}
				//If after cleaning we check to see if what we have left is indeed a number and if not we enter a zero
				if (isNaN(cleanString))
				{
					cleanString = "0";
				}
			}
			else if ((numberOrString == "currency")||(numberOrString == "currencyMandatory"))
			{
				//We are not processing a string so remove all characters which are not numbers or periods(.)!
				stringLength = rawInputString.length;
				exitLoop = 0;
				decimalpointcount = 0;
				while (exitLoop <= (stringLength -1))
				{
					if (debugOption == "Yes")
					{
						alert("currency-rawInputString.charCodeAt("+exitLoop+")["+rawInputString.charCodeAt(exitLoop)+"]");
					}
					//if number between ascii 48 and 57 or period(.)
					if ( ( (rawInputString.charCodeAt(exitLoop) >= 48) && (rawInputString.charCodeAt(exitLoop) <= 57) ) || (rawInputString.charCodeAt(exitLoop) == 46) )
					{
						//if (.) and at position string_length - 2 (i.e. 200234.00) then ok
						if(((exitLoop == (stringLength -3)) || (exitLoop == (stringLength -2))) && (rawInputString.charCodeAt(exitLoop) == 46) && decimalpointcount < 1 )
						{
							decimalpointcount += 1;
							cleanString += rawInputString.charAt(exitLoop);
						}
						else if (rawInputString.charCodeAt(exitLoop) != 46)
						{
							cleanString += rawInputString.charAt(exitLoop);
						}
					}
					//alert("currency-rawInputString.charCodeAt("+exitLoop+")["+rawInputString.charCodeAt(exitLoop)+"]");
					exitLoop += 1;
				}
				if (isNaN(cleanString))
				{
					cleanString = "0";
				}
			}
			else if ((numberOrString == "decimal")||(numberOrString == "decimalMandatory"))
			{
				//We are not processing a string so remove all characters which are not numbers or periods(.)!
				stringLength = rawInputString.length;
				exitLoop = 0;
				while (exitLoop <= (stringLength -1))
				{
					if (debugOption == "Yes")
					{
						alert("currency-rawInputString.charCodeAt("+exitLoop+")["+rawInputString.charCodeAt(exitLoop)+"]");
					}
					//if number between ascii 48 and 57 or period(.)
					if ( ( (rawInputString.charCodeAt(exitLoop) >= 48) && (rawInputString.charCodeAt(exitLoop) <= 57) ) || (rawInputString.charCodeAt(exitLoop) == 46) )
					{
						cleanString += rawInputString.charAt(exitLoop);
					}
					exitLoop += 1;
				}
				if (isNaN(cleanString))
				{
					cleanString = "0.0";
				}
			}
			else
			{
				cleanString = rawInputString;
			}		
		}
		
		if ((debugOption == "Log")||(debugOption == "Yes")) { alert("Pre Exit From ValidateInputString inerror["+ inerror.toString() + "], cleanString:[" +cleanString + "], numberOrString:["+numberOrString+"]"); }
			
		return cleanString;
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
	
}

function ValidateFormInputText(formID, numberOrString, debugOption)
{
	//This function attempts to check for and then remove banned words from every field of a form (referenced by formID)
	//numberOrString signifies whether this is a text or number field
	//debugOption ('xxx') determines whether debug information is alerted to the user
	errorDetailedMessage = "(jsfVFIT): ";
	//Declaring varibales
	var	formObject, CollectionOfFormObjectElements, totalNumberOfElements;
	var cleanInputText, indexCounter, stringObjectName;
	var specifiedAmount = "0.00", memberDonorType = "", rbamountIndex = 0, amountIndex = 0, itemNameIndex = 0;
	var email = "ABC", confirmemail = "ABC", rbAgreePPCCTC = true,  rbAgreeSOTC = true,  formAction = ""
	var captchaMismatch = "", captchaCodeValid = false
	//Here we execute the code within a try statement
	try
	{
		//Check to ensure we have not been passed nulls or empty strings
		if ( (numberOrString == null)||(numberOrString == "")||(formID == null)||(formID == "") )
		{
			if (numberOrString == null)
			{ 
				numberOrString = "NULL";
			}
			if (formID == null)
			{
				formID = "NULL";
			}
			errorDetailedMessageVFIT = errorDetailedMessageVFIT + "numberOrString:["+numberOrString+"];formID:["+formID+"]";
			throw internalASPError;
		}
		else
		{
			if(debugOption == "Yes")
			{
				alert("Entering ValidateFormInputText - Passed input params validation - numberOrString:["+numberOrString+"];formID1:["+formID+"]");
			}
		}
		
		//Get the collection of objects in specified form object
		formObject = document.getElementById(formID);
		
		//formObject = document.getElementById(formID);
		CollectionOfFormObjectElements = formObject.elements;

		//Get total number of objects
		totalNumberOfElements = CollectionOfFormObjectElements.length;

		//Zero based indexing so subtract one from total when used below
		indexCounter = 0;
		inerror = 0;
		rbAgreePPCCTC = true
		rbAgreeSOTC = true
		
		while(indexCounter <= (totalNumberOfElements - 1))
		{
			//alert("numberOrString:["+numberOrString+"];formID5:["+formID+"], indexCounter[" + indexCounter.toString() + "]");
			if((debugOption == "Yes")||(debugOption == "Log")) { alert("Entering While loop - formID:["+formID+"], Name(" + indexCounter.toString() + "):["+(CollectionOfFormObjectElements[indexCounter].name).substring(0,3).toUpperCase()+"], Name(full):[" +(CollectionOfFormObjectElements[indexCounter].name) + "], ID:[" +(CollectionOfFormObjectElements[indexCounter].id) + "], Type:[" +(CollectionOfFormObjectElements[indexCounter].type) + "], Value:["+(CollectionOfFormObjectElements[indexCounter].value)+"], Checked:["+(CollectionOfFormObjectElements[indexCounter].checked)+"],inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "]") };
						
			if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].id) == "rbMDMember") && ((CollectionOfFormObjectElements[indexCounter].checked) == true))
			{
				//Member option checked in form set this as memberType
				memberDonorType = "MemberShip Fee";
				//formObject.item_name.value = "MemberShip";
				if(debugOption == "Yes") { alert("Member - itemNameIndex["+ itemNameIndex.toString() + "], memberDonorType:[" + memberDonorType + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].id) == "rbMDDonor") && ((CollectionOfFormObjectElements[indexCounter].checked) == true))
			{
				//Donor option checked in form set this as memberType
				memberDonorType = "Donation";
				//formObject.item_name.value = "Donation";
				if(debugOption == "Yes") { alert("Donor - itemNameIndex["+ itemNameIndex.toString() + "], memberDonorType:[" + memberDonorType + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].id) == "rbMDBoth") && ((CollectionOfFormObjectElements[indexCounter].checked) == true))
			{
				//Member and Donor option checked in form set this as memberType
				memberDonorType = "Membership Fee and Donation";
				//formObject.item_name.value = "Membership and Donation";
				if(debugOption == "Yes") { alert("BothMD - itemNameIndex["+ itemNameIndex.toString() + "], memberDonorType:[" + memberDonorType + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "business") && ((CollectionOfFormObjectElements[indexCounter].type).toUpperCase() == "HIDDEN"))
			{
				//here is where we insert the CSP's business ID into the form
				CollectionOfFormObjectElements[indexCounter].value = "ZP32PN8FUNKN2";
				////specifiedAmount, memberDonorType, amountIndex, itemNameIndex
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "tbAmount") && ((CollectionOfFormObjectElements[indexCounter].value) != "0.00"))
			{
				//We are processing the specify amount box and an non 0.00 amount has been specified
				//so this is the Membership and/or Donation amount they wish to pay. We store this in specifiedAmount.
				specifiedAmount = CollectionOfFormObjectElements[indexCounter].value;
				if(debugOption == "Yes") { alert("rbAmount - rbamountIndex["+ rbamountIndex.toString() + "], amountIndex["+ amountIndex.toString() + "], specifiedAmount:[" + specifiedAmount + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "rbAmount") && ((CollectionOfFormObjectElements[indexCounter].checked) == true))
			{
				//Here we stoe in rbamountIndex the object's index within the CollectionOfFormObjects which
				//indicates the selected checked/selected amount for the Membership and/or Donation amount they wish to pay
				rbamountIndex = indexCounter;
				if(debugOption == "Yes") { alert("Pre Specify - rbamountIndex["+ rbamountIndex.toString() + "], amountIndex["+ amountIndex.toString() + "], specifiedAmount:[" + specifiedAmount + "]"); };
				
				//if an actual amount as opposed to the specify amount radio button has been selected/checked
				//then store this as the amount to use in specifiedAmount otherwise do nothing.
				if((CollectionOfFormObjectElements[indexCounter].value) != "specify")
				{
					specifiedAmount = CollectionOfFormObjectElements[indexCounter].value;
					if(debugOption == "Yes") { alert("Specify - rbamountIndex["+ rbamountIndex.toString() + "], amountIndex["+ amountIndex.toString() + "], specifiedAmount:[" + specifiedAmount + "]"); };
				}
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "item_name"))
			{
				//here we store the index pointing to the form object which will hold the final item_name
				//Membership Fee, Donation or Membership ( # nnnn) and Donation
				itemNameIndex = indexCounter;
				if(debugOption == "Yes") { alert("item_name - itemNameIndex["+ itemNameIndex.toString() + "], memberDonorType:[" + memberDonorType + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "amount"))
			{
				//Here we store the index pointing to the form object which  will hold the final amount
				amountIndex = indexCounter;
				if(debugOption == "Yes") { alert("Specify - rbamountIndex["+ rbamountIndex.toString() + "], amountIndex["+ amountIndex.toString() + "], specifiedAmount:[" + specifiedAmount + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "Email"))
			{
				//Here we store the email address for later comparison to the confirmation email entered
				email = CollectionOfFormObjectElements[indexCounter].value;
				if(debugOption == "Yes") { alert("email - email["+ email + "], confirmemail:[" + confirmemail + "]"); };
			}
			else if((formID == "CSPMembershipDonationform") && ((CollectionOfFormObjectElements[indexCounter].name) == "ConfirmEmail"))
			{
				//Here we store the confirmation email entered for later comparison to the email to ensure they are both the same
				confirmemail = CollectionOfFormObjectElements[indexCounter].value;
				if(debugOption == "Yes") { alert("email - email["+ email + "], confirmemail:[" + confirmemail + "]"); };
			}
			else if(((formID == "CSPMembershipDonationform")||(formID == "PollsForm")) && ((CollectionOfFormObjectElements[indexCounter].name) == "captchaMismatch") && ((CollectionOfFormObjectElements[indexCounter].type).toUpperCase() == "HIDDEN"))
			{
				//Here we store the confirmation email entered for later comparison to the email to ensure they are both the same
				// <input name="captchacode" type="text" id="smaCaptchacode" size="10" />
			 	// <input name="captchasession" type="hidden" id="strCaptchasession" size="10" value="<%=Request.Form("captchasession")%>"/>

				captchaMismatch = CollectionOfFormObjectElements[indexCounter].value;
				if(debugOption == "Yes") { alert("captchaMismatch:[" + captchaMismatch + "]"); };
			}
			
			
			
			//Here we check the current object's data type and whether it is mandatory
			if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "NUM")
			{
				numberOrString = "number";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "NMA")
			{
				numberOrString = "numberMandatory";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "CUR")
			{
				numberOrString = "currency";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "CMA")
			{
				numberOrString = "currencyMandatory";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "DEC")
			{
				numberOrString = "decimal";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "DMA")
			{
				numberOrString = "decimalMandatory";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,3)).toUpperCase() == "STR")
			{
				numberOrString = "string";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,2)).toUpperCase() == "DT")
			{
				numberOrString = "string";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,4)).toUpperCase() == "CBMA")
			{
				numberOrString = "checkboxMandatory";
			}
			else if (((CollectionOfFormObjectElements[indexCounter].id).substring(0,5)).toUpperCase() == "DDLMA")
			{
				numberOrString = "dropDownListMandatory";
			}
			else
			{
				numberOrString = "stringMandatory";
			}
			
			//If we are processing a Text box or Text area we send the contents for cleaning/validation
			if ( (((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "TEXT") || (((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "TEXTAREA" ) )
			{
				if(debugOption == "Yes") { alert ("Raw Before:" + (CollectionOfFormObjectElements[indexCounter].value))  };
								//ValidateInputString(stringToBeValidated, numberOrString, formFieldID, debugOption)
				cleanInputText = ValidateInputString(CollectionOfFormObjectElements[indexCounter].value, numberOrString, (CollectionOfFormObjectElements[indexCounter].id), debugOption);
				if (cleanInputText == "MandatoryError")
				{
					inerror = -1;
				}
				if((debugOption == "Log")||(debugOption == "Yes")) { alert("Return From ValidateInputString inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "]" ); };
			
				errorDetailedMessage = "(jsfVFIT): ";
				if ( cleanInputText == "MandatoryError" )
				{ 
					//Null or undefined data has been returned
					cleanInputText = "required!"; 
					CollectionOfFormObjectElements[indexCounter].value = cleanInputText;
					CollectionOfFormObjectElements[indexCounter].style.color="red";
					CollectionOfFormObjectElements[indexCounter].style.font="bold 12px arial,serif";
				}
				else
				{
					CollectionOfFormObjectElements[indexCounter].value = cleanInputText;
				}
				
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "RADIO") && (numberOrString == "checkboxMandatory") && ((CollectionOfFormObjectElements[indexCounter].checked) == false) && ((CollectionOfFormObjectElements[indexCounter].id).substring(4,(CollectionOfFormObjectElements[indexCounter].id).length) == "AgreeTAC"))
			{
				rbAgreePPCCTC = false
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "RADIO") && (numberOrString == "checkboxMandatory") && ((CollectionOfFormObjectElements[indexCounter].checked) == true) && ((CollectionOfFormObjectElements[indexCounter].id).substring(4,(CollectionOfFormObjectElements[indexCounter].id).length) == "AgreeTAC"))
			{
				rbAgreePPCCTC = true
				formAction = "SubmitMD.asp"
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "RADIO") && (numberOrString == "checkboxMandatory") && ((CollectionOfFormObjectElements[indexCounter].checked) == false) && ((CollectionOfFormObjectElements[indexCounter].id).substring(4,(CollectionOfFormObjectElements[indexCounter].id).length) == "AgreeTACSO"))
			{
				rbAgreeSOTC = false
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "RADIO") && (numberOrString == "checkboxMandatory") && ((CollectionOfFormObjectElements[indexCounter].checked) == true) && ((CollectionOfFormObjectElements[indexCounter].id).substring(4,(CollectionOfFormObjectElements[indexCounter].id).length) == "AgreeTACSO"))
			{
				rbAgreeSOTC = true
				//formObject.action="SubmitMDSO.asp"
				formAction = "SubmitMDSO.asp"
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "SELECT-ONE") && (numberOrString == "dropDownListMandatory") && ((CollectionOfFormObjectElements[indexCounter].value.toUpperCase()) == "PLEASE SELECT") && ((CollectionOfFormObjectElements[indexCounter].id).substring(5,(CollectionOfFormObjectElements[indexCounter].id).length) == "Title"))
			{
				errorDetailedMessage = errorDetailedMessage + "Field '" + (CollectionOfFormObjectElements[indexCounter].id).substring(5,(CollectionOfFormObjectElements[indexCounter].id).length) + "' must be selected, it is mandatory as are all fields marked with an * ";
				alert(errorDetailedMessage);
				//throw mandatoryFieldError;
				//return "MandatoryError";
				cleanInputText = "MandatoryError";
				inerror = -1;
			}
			else if ((((CollectionOfFormObjectElements[indexCounter].type).toUpperCase()) == "SELECT-ONE") && (numberOrString == "dropDownListMandatory") && ((CollectionOfFormObjectElements[indexCounter].value.toUpperCase()) == "PLEASE SELECT") && ((CollectionOfFormObjectElements[indexCounter].id).substring(5,(CollectionOfFormObjectElements[indexCounter].id).length) == "Gender"))
			{
				errorDetailedMessage = errorDetailedMessage + "Field '" + (CollectionOfFormObjectElements[indexCounter].id).substring(5,(CollectionOfFormObjectElements[indexCounter].id).length) + "' must be selected, it is mandatory as are all fields marked with an * ";
				alert(errorDetailedMessage);
				//throw mandatoryFieldError;
				//return "MandatoryError";
				cleanInputText = "MandatoryError";
				inerror = -1;
			}
			
			if((debugOption == "Yes")||(debugOption == "Log")) { alert("End of While loop - formID:["+formID+"], Name(" + indexCounter.toString() + "):["+(CollectionOfFormObjectElements[indexCounter].name).substring(0,3).toUpperCase()+"], Name(full):[" +(CollectionOfFormObjectElements[indexCounter].name) + "], ID:[" +(CollectionOfFormObjectElements[indexCounter].id) + "], Type:[" +(CollectionOfFormObjectElements[indexCounter].type) + "], Value:["+(CollectionOfFormObjectElements[indexCounter].value)+"], Checked:["+(CollectionOfFormObjectElements[indexCounter].checked)+"],inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "], numberOrString[" + numberOrString + "]") };
						
			indexCounter = indexCounter + 1;
		}
		
		if ((rbAgreePPCCTC == false)&&(rbAgreeSOTC == false))
		{
			errorDetailedMessage = errorDetailedMessage + "We are sorry, but you must check (select) the 'I have read and agree to the terms and conditions:' radio button before proceeding!";
			//errorDetailedMessage = errorDetailedMessage + "Field '" + (CollectionOfFormObjectElements[indexCounter].id).substring(4,(CollectionOfFormObjectElements[indexCounter].id).length) + " with current value:[" + CollectionOfFormObjectElements[indexCounter].value + "]' must be checked before proceeding! ";
			//throw mandatoryFieldError;
			alert(errorDetailedMessage);
			cleanInputText = "MandatoryError";
			inerror = -1;
			if(debugOption == "Log") { alert(" AggreeTC inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "]" ); };
		}
		
		if (email != confirmemail)
		{
			errorDetailedMessage = errorDetailedMessage + "We are sorry, but your email address is not the sme as the confirmed email address, please correct before proceeding!";
			alert(errorDetailedMessage);
			inerror = -1;
			if(debugOption == "Log") { alert("Email Mismatch inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "]" ); };
			
		}
		
		if(debugOption == "Log") { alert("inerror["+ inerror.toString() + "], cleanInputText:[" +cleanInputText + "]" ); };
			
		if ((cleanInputText != "MandatoryError" )&&(inerror!=-1))
		{
			//All field data entered as required and clean of banned words so submit form
			//specifiedAmount, memberDonorType, amountIndex, itemNameIndex
			if (formID == "CSPMembershipDonationform")
			{
				CollectionOfFormObjectElements[amountIndex].value = specifiedAmount;
				CollectionOfFormObjectElements[itemNameIndex].value = memberDonorType;
				
				if(debugOption == "Yes") { alert("amountIndex["+ amountIndex.toString() + "], Amount value:[" +CollectionOfFormObjectElements[amountIndex].value + "],specifiedAmount:["+specifiedAmount+"]" ); };
				if(debugOption == "Yes") { alert("itemNameIndex["+ itemNameIndex.toString() + "], Item Name value:[" +CollectionOfFormObjectElements[itemNameIndex].value + "],memberDonorType:["+memberDonorType+"]" ); };
			}
			
			if ((formID == "CSPMembershipDonationform") && (captchaMismatch == "N"))
			{
				//if captcha code entered is correct change formrObject.Action to appropriate asp.page
				//according to which terms and conditions radio button is selected
				captchaCodeValid = true;
				formObject.action = formAction;
			}
			else if ((formID == "CSPMembershipDonationform") && (captchaMismatch == "Y"))
			{
				captchaCodeValid = false;
			}
			if(debugOption == "Yes") { alert("captchaCodeValid["+ captchaCodeValid.toString() + "], captchaCode["+ captchaMismatch.toString() + "]" ); };
			//alert("captchaCodeValid["+ captchaCodeValid.toString() + "], captchaMismatch["+ captchaMismatch.toString() + "]" );
				
			formObject.submit();
			
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function disableControlByID(dependentControlID, dependentControlValue, disableControlID, debugOption)
{
	//This function will disable control specified by disableControlID when the value (dependentControlValue)
	//of the specified dependentControlID is encountered
	//id is the id of the field form
	//debugOption ('xxx') determines whether debug information is alerted to the user
	errorDetailedMessage = "(jsfdCBID): ";
	//Declaring varibales
	var	dependentControlObject, OptionsOfDependentControlObject, disableControlObject, OptionsOfDisableControlObject;
	//Here we execute the code within a try statement
	try
	{
		if ( (dependentControlID == null)||(dependentControlID == "" )||(dependentControlValue == null)||(dependentControlValue == "" )||(disableControlID == null)||(disableControlID == "") )
		{
			if (dependentControlID == null)
			{
				dependentControlID = "NULL";
			}
			if (dependentControlValue == null)
			{
				dependentControlValue = "NULL";
			}
			if (disableControlID == null)
			{
				disableControlID = "NULL";
			}
			errorDetailedMessage = errorDetailedMessage + "dependentControlID:["+dependentControlID+"];dependentControlValue:["+dependentControlValue+"];disableControlID:["+disableControlID+"]";
			throw internalASPError;
		}
		else
		{
			if (debugOption == "Yes")
			{
				alert("dependentControlID:["+dependentControlID+"];dependentControlValue:["+dependentControlValue+"];disableControlID:["+disableControlID+"]");
			}
			dependentControlObject = document.getElementById(dependentControlID);
			OptionsOfDependentControlObject = dependentControlObject.options;
			disableControlObject = document.getElementById(disableControlID);
			OptionsOfDisableControlObject = disableControlObject.options;
		}
		
		if ((OptionsOfDependentControlObject[dependentControlObject.selectedIndex].text.substring(0,10)).toUpperCase() == dependentControlValue.toUpperCase())
		{
			disableControlObject.selectedIndex = 2;
			if ( (OptionsOfDisableControlObject[0].text == "" ) || (OptionsOfDisableControlObject[0].text == null ) )
			{
				OptionsOfDisableControlObject[0].text = OptionsOfDisableControlObject[2].text;
			}
		
			if ( (OptionsOfDisableControlObject[1].text == "" ) || (OptionsOfDisableControlObject[1].text == null ) )
			{
				OptionsOfDisableControlObject[1].text = OptionsOfDisableControlObject[2].text;
			}
		
			disableControlObject.disabled = false;
		}
		else
		{
			disableControlObject.selectedIndex = 0;
			OptionsOfDisableControlObject[0].text = "" ;
			disableControlObject.disabled = true;
		}
		if (debugOption == "Yes")
		{
			alert("disable control(" + disableControlID +"); Currently selected index =(" + disableControlObject.selectedIndex.toString() + ")");
			alert("value: of currently disabled(" + OptionsOfDisableControlObject[disableControlObject.selectedIndex].text +")");
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function verifyPassword(passwordID1,passwordID2,debugOption)
{
	//This verifies that the password and confirmation password fields match
	errorDetailedMessage = "(jsfvP): ";
	//Declare varibales
	var	passwordObject1, passwordObject2;
	//Here we execute the code within a try statement
	try
	{
		passwordObject1 = document.getElementById(passwordID1);
		passwordObject2 = document.getElementById(passwordID2);
		
		if (debugOption == "Yes")
		{
			alert("Text for (" + passwordID1 + ") = (" + passwordObject1.value + ")\nText for (" + passwordID2 + ") = (" + passwordObject2.value + ")");
		}
		if (passwordObject1.value != passwordObject2.value)
		{
			passwordObject1.value = "" ;
			passwordObject2.value = "" ;
			passwordObject1.focus();
			throw passwordError;
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function verifyEmailAddress(emailAddressID1,emailAddressID2,debugOption)
{
	//This verifies that the password and confirmation password fields match
	errorDetailedMessage = "(jsfVEA): ";
	//Declare varibales
	var	emailAddressObject1, emailAddressObject2;
	//Here we execute the code within a try statement
	try
	{
		emailAddressObject1 = document.getElementById(emailAddressID1);
		emailAddressObject2 = document.getElementById(emailAddressID2);
		
		if (debugOption == "Yes")
		{
			alert("Text for (" + emailAddressID1 + ") = (" + emailAddressObject1.value + ")\nText for (" + emailAddressID2 + ") = (" + emailAddressObject2.value + ")");
		}
		if (emailAddressObject1.value != emailAddressObject2.value)
		{
			emailAddressObject1.value = "" ;
			emailAddressObject2.value = "" ;
			emailAddressObject1.focus();
			throw emailAddressError;
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function reSubmitFormAfterFormOptionChange(formID, debugOption, formInputIDToChange, newValue)
{
	//This function attempts to re-Submit a form (referenced by formID)
	//after an option has been changed
	//debugOption ('xxx') determines whether debug information is alerted to the user
	errorDetailedMessage = "(jsfrSFAFOC): ";
	//Declaring varibales
	var	formObject, formInputControlObject
	//Here we execute the code within a try statement
	try
	{
		if ( (formID == null)||(formID == "") )
		{
			if (formID == null)
			{
				formID = "NULL";
			}
			errorDetailedMessage = errorDetailedMessage + "formID:["+formID+"]";
			throw formReSubmissionError;
		}
		else if ( (formInputIDToChange == null)||(formInputIDToChange == "") )
		{
			if (formInputIDToChange == null)
			{
				formInputIDToChange = "NULL";
			}
			errorDetailedMessage = errorDetailedMessage + "formInputIDToChange:["+formInputIDToChange+"]";
			throw formReSubmissionError;
		}
		else
		{
			formInputControlObject = document.getElementById(formInputIDToChange)
			if (debugOption	== "Yes")
			{
				alert("formID:["+formID+"], formInputIDToChange:[" + formInputIDToChange + "], newValue:[" + newValue + "]");
			}
			formObject = document.getElementById(formID);
			formInputControlObject.value =  newValue;
			if(inerror!=-1)
			{
				formObject.submit();
			}
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}
//document.write(ValidateInputString("This is just to check that fucking sql characters such %, *, =, can be bloody well removed with words like Select, uPdate, INSERT, ExEcUtE and insert. ","string","IO"));
function DisplaySelectedImage(formID, imageSelectID, imageID, debugOption)
{
	//This function attempts to check for and then remove banned words from every field of a form (referenced by formID)
	//numberOrString signifies whether this is a text or number field
	//debugOption ('xxx') determines whether debug information is alerted to the user
	errorDetailedMessage = "(jsifDSI): ";
	//Declaring varibales
	var	formObject, ImageObject, CollectionOfFormObjectElements, totalNumberOfElements, imageSelectIDIndexValue;
	var cleanInputText, indexCounter, stringObjectName, displayImageIDIndexValue, newImagePath;
	//Here we execute the code within a try statement
	imageSelectIDIndexValue = -1;
	displayImageIDIndexValue = -1;
	try
	{
		if ( (formID == null)||(formID == "") )
		{
			if (formID == null)
			{
				formID = "NULL";
			}
			errorDetailedMessage = errorDetailedMessage + "formID:["+formID+"]";
			throw internalASPError;
		}
		else
		{
			if(debugOption == "Yes")
			{
				alert("formID:["+formID+"]");
				alert("document["+imageID+"].src:["+document[imageID].src+"]");
				
				totalNumberOfElements = document.images.length;
				indexCounter = totalNumberOfElements - 1;
				while(indexCounter >= 0)
				{
					if ( document.images[indexCounter].name == imageID )
					{
						alert("document.imageID["+indexCounter+"].name:["+document.images[indexCounter].name+"]");
						alert("document.imageID["+indexCounter+"].id:["+document.images[indexCounter].id+"]");
						alert("document.imageID["+indexCounter+"].src:["+document.images[indexCounter].src+"]");
						alert("document.imageID["+indexCounter+"].value:["+document.images[indexCounter].value+"]");
						alert("document.imageID["+indexCounter+"].alt:["+document.images[indexCounter].alt+"]");
						alert("document.imageID["+indexCounter+"].width:["+document.images[indexCounter].width+"]");
						alert("document.imageID["+indexCounter+"].height:["+document.images[indexCounter].height+"]");
					}
					indexCounter = indexCounter - 1;
				}
			}
		}
		formObject = document.getElementById(formID);
		CollectionOfFormObjectElements = formObject.elements;
		totalNumberOfElements = CollectionOfFormObjectElements.length;
		indexCounter = totalNumberOfElements - 1;
		while(indexCounter >= 0)
		{
			if(debugOption == "Yes") { alert("formID:["+formID+"]; Type:["+ (CollectionOfFormObjectElements[indexCounter].type) + "]; Name: [" + (CollectionOfFormObjectElements[indexCounter].name) + "]") };
			if ( ( CollectionOfFormObjectElements[indexCounter].id ) == imageSelectID ) //"ImageRef"
			{
			 	imageSelectIDIndexValue = indexCounter;
				if(debugOption == "Yes") { alert("imageSelectIDIndexValue:["+imageSelectIDIndexValue+"]") };
				newImagePath = CollectionOfFormObjectElements(imageSelectIDIndexValue).value;
				if(debugOption == "Yes") { alert("newImagePath:["+newImagePath+"]; ImageID:[" + imageID + "]") };
				//ImageObject = document.getElementById(imageID);
				document[imageID].src = newImagePath;
				//if(debugOption == "Yes") { alert("ImageObject.scr:["+ImageObject.scr+"]") };
				if(debugOption == "Yes") { alert("document.[imageID].src:["+document[imageID].src+"]") };
			}
			indexCounter = indexCounter - 1;
		}
	}
	catch (e)
	{
		// catch all thrown errors and forward ion to customised exception handler
		mainExceptionHandler(e); 
	}
}

function NavTo(url)
{
	window.location = url
}

function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function strcmp ( str1, str2 ) {
    // *     example 1: strcmp( 'waldo', 'owald' );
    // *     returns 1: 1
    // *     example 2: strcmp( 'owald', 'waldo' );
    // *     returns 2: -1
 
    return ( ( str1 == str2 ) ? 0 : ( ( str1 > str2 ) ? 1 : -1 ) );
}


