//******************************************************************************************************
function ValidateEmailAddress(vTestEmail)
{
	var objFilter;
	
	objFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (objFilter.test(vTestEmail))
	{
		return true;
	}
	else
	{
		alert("Please enter a valid email address.");
		return false;
	}
}
//******************************************************************************************************
function OpenModalWindow(vPageToOpen)
{
	window.open(vPageToOpen,'','Height=600px,Width=520px,center=1,help=0,status=0,toolbars=0');
}
//******************************************************************************************************
function Search(vPageToGoTo)
{
	var strSearchCriteria;
	strSearchCriteria = document.getElementById('txtSearch').value;
	if(strSearchCriteria == '')
	{
		alert('Please enter a valid serch critera.');
		document.getElementById('txtSearch').focus();
		return false;
	}
	else
	{
		window.navigate(vPageToGoTo+strSearchCriteria)
	}
}
//******************************************************************************************************
function ValidateEnterKey(vKeyPressed, vPageToGoTo)
{
	var intCharacterCode;
	
	if(vKeyPressed && vKeyPressed.which)
	{
		vKeyPressed = vKeyPressed;
		intCharacterCode = vKeyPressed.which;
		alert('intCharacterCode = '+intCharacterCode);
	}
	else
	{
		vKeyPressed = event;
		intCharacterCode = vKeyPressed.keyCode;
	}
	
	if(intCharacterCode == 13)
	{
		Search(vPageToGoTo);
		return false;
	}
	else
	{
		return true;
	}
}
//******************************************************************************************************
function SubmitDeleteForm(vImage, vLink, vName)
{
	document.getElementById('hdnImage').value = vImage;
	document.getElementById('hdnLink').value = vLink;
	document.getElementById('hdnName').value = vName;
	document.forms[0].submit();
}
//******************************************************************************************************
function ValidateForgotUsernameAndPassword()
{
	if(document.getElementById('txtForgotUsername').value == '')
	{
		alert('Please enter a value in the username field.');
		document.getElementById('txtForgotUsername').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertAddressType()
{
	if(document.getElementById('txtAddressType').value == '')
	{
		alert('Please enter a value in the Address Type Field');
		document.getElementById('txtAddressType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertBaitType()
{
	if(document.getElementById('txtBaitType').value == '')
	{
		alert('Please enter a value in the Bait Type Field');
		document.getElementById('txtBaitType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertContactNumberType()
{
	if(document.getElementById('txtContactNumberType').value == '')
	{
		alert('Please enter a value in the Contact Number Type Field');
		document.getElementById('txtContactNumberType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertGenderType()
{
	if(document.getElementById('txtGenderType').value == '')
	{
		alert('Please enter a value in the Gender Type Field');
		document.getElementById('txtGenderType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertHorseBreedType()
{
	if(document.getElementById('txtHorseBreedType').value == '')
	{
		alert('Please enter a value in the Horse Breed Type Field');
		document.getElementById('txtHorseBreedType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertHorseDisiplineType()
{
	if(document.getElementById('txtHorseDisiplineType').value == '')
	{
		alert('Please enter a value in the Horse Disipline Type Field');
		document.getElementById('txtHorseDisiplineType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertHorseSexType()
{
	if(document.getElementById('txtHorseSexType').value == '')
	{
		alert('Please enter a value in the Horse Sex Type Field');
		document.getElementById('txtHorseSexType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertPeriodAndRate()
{
	if(document.getElementById('txtPeriod').value == '')
	{
		alert('Please enter a value in the Period Field');
		document.getElementById('txtPeriod').focus();
		return false;
	}
	
	if(isNaN(document.getElementById('txtPeriod').value))
	{
		alert('Please enter a numeric value in the Period Field');
		document.getElementById('txtPeriod').focus();
		return false;
	}
	
	if(document.getElementById('txtRate').value == '')
	{
		alert('Please enter a value in the Rate Field');
		document.getElementById('txtRate').focus();
		return false;
	}
	
	if(isNaN(document.getElementById('txtRate').value))
	{
		alert('Please enter a numeric value in the Rate Field');
		document.getElementById('txtRate').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertProvince()
{
	if(document.getElementById('txtProvince').value == '')
	{
		alert('Please enter a value in the Province Field');
		document.getElementById('txtProvince').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertUserType()
{
	if(document.getElementById('txtUserType').value == '')
	{
		alert('Please enter a value in the User Type Field');
		document.getElementById('txtUserType').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateRegisterUser()
{
    var strEmailValid;
	if(document.getElementById('selProvince').value == 0)
	{
		alert('Please select a value for Province');
		document.getElementById('selProvince').focus();
		return false;
	}
	
	if(document.getElementById('selGender').value == 0)
	{
		alert('Please select a value for Gender');
		document.getElementById('selGender').focus();
		return false;
	}
	
	if(document.getElementById('txtCellPhoneNumber').value == '')
	{
		alert('Please enter a value in the Cell Phone Number Field');
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(isNaN(document.getElementById('txtCellPhoneNumber').value))
	{
		alert('Please enter a numeric value in the Cell Phone Number Field.\nWith no spaces or (){}- characters.');
		document.getElementById('txtCellPhoneNumber').value = '';
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(document.getElementById('txtEmailAddress').value == '')
	{
		alert('Please enter a value in the Email Address Field');
		document.getElementById('txtEmailAddress').focus();
		return false;
	}
	
	strEmailValid = ValidateEmailAddress(document.getElementById('txtEmailAddress').value)
	if(strEmailValid == false)
	{
		document.getElementById('txtEmailAddress').focus();
		return false;
	}
	
	if(document.getElementById('txtCellPhoneNumber').value.length > 10)
	{
		alert('Please enter a value in the Cell Phone Number Field less than 10 characters');
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(document.getElementById('txtFirstName').value == '')
	{
		alert('Please enter a value in the First Name Field');
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if(document.getElementById('txtSurname').value == '')
	{
		alert('Please enter a value in the Surname Field');
		document.getElementById('txtSurname').focus();
		return false;
	}
	
	if(document.getElementById('txtUsername').value == '')
	{
		alert('Please enter a value in the Username Field');
		document.getElementById('txtUsername').focus();
		return false;
	}
	
	if(document.getElementById('txtPassword').value == '')
	{
		alert('Please enter a value in the Password Field');
		document.getElementById('txtPassword').focus();
		return false;
	}
		
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateEditRegisterDetails()
{
	var intLoopCount;
	var strEmailValid;
	
	if(document.getElementById('selProvince').value == 0)
	{
		alert('Please select a value for Province');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('selProvince').focus();
		return false;
	}
	
	if(document.getElementById('selGender').value == 0)
	{
		alert('Please select a value for Gender');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('selGender').focus();
		return false;
	}
	
	if(document.getElementById('txtCellPhoneNumber').value == '')
	{
		alert('Please enter a value in the Cell Phone Number Field');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(isNaN(document.getElementById('txtCellPhoneNumber').value))
	{
		alert('Please enter a numeric value in the Cell Phone Number Field.\nWith no spaces or (){}- characters.');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtCellPhoneNumber').value = '';
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(document.getElementById('txtCellPhoneNumber').value.length > 10)
	{
		alert('Please enter a value in the Cell Phone Number Field less than 10 characters');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtCellPhoneNumber').focus();
		return false;
	}
	
	if(document.getElementById('txtFirstName').value == '')
	{
		alert('Please enter a value in the First Name Field');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtFirstName').focus();
		return false;
	}
	
	if(document.getElementById('txtSurname').value == '')
	{
		alert('Please enter a value in the Surname Field');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtSurname').focus();
		return false;
	}
	
	if(document.getElementById('txtUsername').value == '')
	{
		alert('Please enter a value in the Username Field');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtUsername').focus();
		return false;
	}
	
	if(document.getElementById('txtPassword').value == '')
	{
		alert('Please enter a value in the Password Field');
		document.getElementById('divUserStandardDetails').style.display = 'block';
		document.getElementById('divUserEmailAddress').style.display = 'none';
		document.getElementById('divUserPhysicalAddress').style.display = 'none';
		document.getElementById('divPersonalInterests').style.display = 'none';
		document.getElementById('divComments').style.display = 'none';
		document.getElementById('txtPassword').focus();
		return false;
	}
	//VALIDATE ALL EMAIL ADDRESS'S OF PAGE
	for(intLoopCount = 0; intLoopCount <= (gintEmailAddressCount - 1); intLoopCount++)
	{
		if(document.getElementById('txtEmailAddress_'+intLoopCount).value != '')
		{
			strEmailValid = ValidateEmailAddress(document.getElementById('txtEmailAddress_'+intLoopCount).value)
			if(strEmailValid == false)
			{
				document.getElementById('divUserEmailAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserPhysicalAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtEmailAddress_'+intLoopCount).focus();
				return false;
			}
		}
	}
	//VALIDATE ALL POSTAL ADDRESS'S ON PAGE
	for(intLoopCount = 0; intLoopCount <= (gintPhysicalAddressCount - 1); intLoopCount++)
	{
		if(document.getElementById('txtAddressLine1_'+intLoopCount).value != 0 || 
			document.getElementById('txtAddressLine2_'+intLoopCount).value != '' ||
			document.getElementById('txtAddressLine3_'+intLoopCount).value != '' ||
			document.getElementById('txtAddressLine4_'+intLoopCount).value != '' ||
			document.getElementById('txtAddressPostalCode_'+intLoopCount).value != '')
		{
			if(document.getElementById('selAddressType_'+intLoopCount).value == 0)
			{
				alert('Please select a address type.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('selAddressType_'+intLoopCount).focus();
				return false;
			}
			
			if(document.getElementById('txtAddressLine1_'+intLoopCount).value == '')
			{
				alert('Please enter a value for the Address Line 1 Field.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtAddressLine1_'+intLoopCount).focus();
				return false;
			}
			
			if(document.getElementById('txtAddressLine2_'+intLoopCount).value == '')
			{
				alert('Please enter a value for the Address Line 2 Field.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtAddressLine2_'+intLoopCount).focus();
				return false;
			}
			
			if(document.getElementById('txtAddressLine3_'+intLoopCount).value == '')
			{
				alert('Please enter a value for the Address Line 3 Field.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtAddressLine3_'+intLoopCount).focus();
				return false;
			}
			
			if(document.getElementById('txtAddressPostalCode_'+intLoopCount).value == '')
			{
				alert('Please enter a value for the Address Postal Code Field.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtAddressPostalCode_'+intLoopCount).focus();
				return false;
			}
			
			if(isNaN(document.getElementById('txtAddressPostalCode_'+intLoopCount).value))
			{
				alert('Please enter a numeric value for the Address Postal Code Field.');
				document.getElementById('divUserPhysicalAddress').style.display = 'block';
				document.getElementById('divUserStandardDetails').style.display = 'none';
				document.getElementById('divUserEmailAddress').style.display = 'none';
				document.getElementById('divPersonalInterests').style.display = 'none';
				document.getElementById('divComments').style.display = 'none';
				document.getElementById('txtAddressPostalCode_'+intLoopCount).focus();
				return false;
			}
		}
	}
	//SET THE COUNT FIELDS ON THE PAGE TO REFERENCE FROM THE SAVE PAGE
	if(document.getElementById('hdnEmailAddressCount').value < (gintEmailAddressCount - 1))
	{
		document.getElementById('hdnEmailAddressCount').value = (gintEmailAddressCount - 1);
	}
	
	if(document.getElementById('hdnPhysicalAddressCount').value < (gintPhysicalAddressCount - 1))
	{
		document.getElementById('hdnPhysicalAddressCount').value = (gintPhysicalAddressCount - 1);
	}
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateInsertUsernameAndPassword()
{
	if(document.getElementById('txtUsername').value == '')
	{
		alert('Please enter a value in the Username Field');
		document.getElementById('txtUsername').focus();
		return false;
	}
	
	if(document.getElementById('txtPassword').value == '')
	{
		alert('Please enter a value in the Password Field');
		document.getElementById('txtPassword').focus();
		return false;
	}
	
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidateLogin()
{
	var strPassword;
	
	if(document.getElementById('txtLoginUsername').value == '')
	{
		alert('Please enter a value in the Username Field');
		document.getElementById('txtLoginUsername').focus();
		return false;
	}
	
	if(document.getElementById('txtLoginPassword').value == '')
	{
		alert('Please enter a value in the Password Field');
		document.getElementById('txtLoginPassword').focus();
		return false;
	}
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidatePlaceHorseAd()
{
	if(document.getElementById('selBreed') == undefined)
	{
		alert('Please note that you cannot submit this form as horse breed is a required field.\nThis field is not available at present.');
		return false;
	}
	
	if(document.getElementById('selSex') == undefined)
	{
		alert('Please note that you cannot submit this form as horse sex is a required field.\nThis field is not available at present.');
		return false;
	}
	
	if(document.getElementById('selDisipline') == undefined)
	{
		alert('Please note that you cannot submit this form as horse disipline is a required field.\nThis field is not available at present.');
		return false;
	}
	
	if(document.getElementById('selDisipline').value == '')
	{
		alert('Please select a value for disipline.');
		document.getElementById('selDisipline').focus();
		return false;
	}
	
	if(document.getElementById('txtName').value == '')
	{
		alert('Please enter a value in the horse name field');
		document.getElementById('txtName').focus();
		return false;
	}	
	if(document.getElementById('txtName').value.length > 250)
	{
		alert('Please enter a value for horse name less than 250 characters.\nYou are currently at '+ document.getElementById('txtName').value.length +' characters.');
		document.getElementById('txtName').focus();
		return false;
	}
	
	if(document.getElementById('txtColour').value == '')
	{
		alert('Please enter a value in the horse colour field');
		document.getElementById('txtColour').focus();
		return false;
	}	
	if(document.getElementById('txtColour').value.length > 250)
	{
		alert('Please enter a value for horse colour less than 250 characters.\nYou are currently at '+ document.getElementById('txtColour').value.length +' characters.');
		document.getElementById('txtColour').focus();
		return false;
	}
	
	if(document.getElementById('txtHeight').value == '')
	{
		alert('Please enter a value in the horse height field');
		document.getElementById('txtHeight').focus();
		return false;
	}
	if(document.getElementById('txtHeight').value.length > 50)
	{
		alert('Please enter a value for horse height less than 50 characters.\nYou are currently at '+ document.getElementById('txtHeight').value.length +' characters.');
		document.getElementById('txtHeight').focus();
		return false;
	}
	
	if(document.getElementById('txtAge').value == '')
	{
		alert('Please enter a value in the horse age field');
		document.getElementById('txtAge').focus();
		return false;
	}
	if(isNaN(document.getElementById('txtAge').value))
	{
		alert('Please enter a numeric value in the horse age field');
		document.getElementById('txtAge').focus();
		return false;
	}
	if(document.getElementById('txtAge').value.length > 2)
	{
		alert('Please enter a value for horse age less than 2 characters.\nYou are currently at '+ document.getElementById('txtAge').value.length +' characters.');
		document.getElementById('txtAge').focus();
		return false;
	}
	
	if(document.getElementById('txtPrice').value == '')
	{
		alert('Please enter a value in the horse price field');
		document.getElementById('txtPrice').focus();
		return false;
	}
	if(document.getElementById('txtPrice').value.length > 50)
	{
		alert('Please enter a value for horse price less than 50 characters.\nYou are currently at '+ document.getElementById('txtPrice').value.length +' characters.');
		document.getElementById('txtPrice').focus();
		return false;
	}
	
	if(document.getElementById('txtDescription').value == '')
	{
		alert('Please enter a value in the description field');
		document.getElementById('txtDescription').focus();
		return false;
	}
	
	if(document.getElementById('txtDescription').value.length > 8000)
	{
		alert('Please enter a value for description less than 8000 characters.\nYou are currently at '+ document.getElementById('txtDescription').value.length +' characters.');
		document.getElementById('txtDescription').focus();
		return false;
	}
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function ValidatePlaceTackAd()
{
	if(document.getElementById('txtTitle').value == '')
	{
		alert('Please enter a value in the ad title field');
		document.getElementById('txtTitle').focus();
		return false;
	}
	if(document.getElementById('txtTitle').value.length > 250)
	{
		alert('Please enter a value for title less than 250 characters.\nYou are currently at '+ document.getElementById('txtPrice').value.length +' characters.');
		document.getElementById('txtTitle').focus();
		return false;
	}
	if(document.getElementById('txtPrice').value == '')
	{
		alert('Please enter a value in the horse price field');
		document.getElementById('txtPrice').focus();
		return false;
	}
	if(document.getElementById('txtPrice').value.length > 10)
	{
		alert('Please enter a value for price less than 10 characters.\nYou are currently at '+ document.getElementById('txtPrice').value.length +' characters.');
		document.getElementById('txtPrice').focus();
		return false;
	}
	
	if(document.getElementById('txtDescription').value == '')
	{
		alert('Please enter a value in the description field');
		document.getElementById('txtDescription').focus();
		return false;
	}
	
	if(document.getElementById('txtDescription').value.length > 8000)
	{
		alert('Please enter a value for description less than 8000 characters.\nYou are currently at '+ document.getElementById('txtDescription').value.length +' characters.');
		document.getElementById('txtDescription').focus();
		return false;
	}
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************
function GoToPage(vPageToGoTo)
{
	window.location = vPageToGoTo;
	//DEFAULT RETURN VALUE
	return true;
}
//******************************************************************************************************

