
	function ValueCheck(StrValue,CheckValue, strMsg)
	{
		if (StrValue == CheckValue)
		{ 
			if (fCheck)
			{                     
				alert(strMsg)
				fCheck = false
			}
		}
	}


	function IntCheck(IntValue, strMsg)
	{
		if (isNaN(IntValue))
		{   
			if (fCheck)
			{                    
				alert(strMsg)
				fCheck = false
			}
		}
	}


	function LengthCheck(StrValue, FieldName, MaxLength)
	{
		if (StrValue.length > MaxLength)
		{   
			if (fCheck)
			{   
				var substr = StrValue.substring(StrValue.length,MaxLength) 
             
				alert("you have exceeded the " + MaxLength + " character limit for the " + FieldName + " field\nthe following text will need to be removed:\n\n" + substr)
				fCheck = false
			}
		}
	}


	function SelectCheck(OptionValue,CheckValue, strMsg)
	{
		if (OptionValue == CheckValue)
		{ 
			if (fCheck)
			{                     
				alert(strMsg)
				fCheck = false
			}
		}
	}

	function UpdateFieldValue(which_element, final_value){
		with (window.document) {
			which_element.value = final_value
			//alert(which_element.name + " = " + which_element.value)
		}
	}

	function SubmitForm(which_form, field_str)
	{
		// CHECK FOR OPTIONAL ACTION OVERIDE
		my_arr = field_str.split("~#~")
		if (my_arr.length == 2){
			which_form.action = my_arr[0]
			field_str = my_arr[1]
		} else {
			field_str = my_arr[0]
		}

		field_arr = field_str.split("|")

		with (window.document) {
			for ( i=0; i < which_form.elements.length; i++ ) {
				current_name = which_form.elements[i].name

				for (j=0; j < field_arr.length; j++){
					data_arr = field_arr[j].split("~=~")
					if (current_name == data_arr[0]) {

						UpdateFieldValue(which_form.elements[i], data_arr[1]);
						break
					}
				}
			}
		}

		which_form.submit()
	}


	function SubmitIdSearch(which_form, which_field, field_name)
	{

		fCheck = true

		ValueCheck(which_field.value, "", "Please enter a property_id");
		IntCheck(which_field.value, "The " + field_name + " should contain numbers only.\nPlease remove any non numeric characters.");

		if (fCheck)
		{
			which_form.submit()
		}
	}
	

	function AtLeastOneSelected(which_form, element_name, check_mode, alert_message){
		if (fCheck) {
			fCheck = false;
			with (window.document) {
				for ( i=0; i < which_form.elements.length; i++ ) {
					current_name = which_form.elements[i].name
					if (current_name.substring(0,element_name.length) == element_name) {
						if ((check_mode == "checkbox" && which_form.elements[i].checked == true) || (check_mode == "text_field" && which_form.elements[i].value != "")) {
							fCheck = true;
							break;
						}
					}
				}
			}
			if (fCheck == false){
				alert(alert_message);
			}
		}
	}

	function FixedLengthNumber(intValue,fixedLength,element_name) {

		var StrMsg = "";

		if ( intValue.length != fixedLength) {  
			StrMsg = "\n" + element_name + " must be " + fixedLength + " digits long, The number you provided was " + intValue.length + " digits long";
		}

		if ( isNaN(intValue) ) { 
			StrMsg = StrMsg + "\n" + element_name + " may only contain numbers, please remove any punctuation or letters";
		}

		if (StrMsg.length > 0) {
			if (fCheck) { 
				alert(StrMsg);
				fCheck = false;
			}
		}
	}


	function ValueComparison(StrValue,ComparisonMode, CheckValue, strMsg)
	{
		if (fCheck) {
			if (ComparisonMode == "eq") {
			    if (StrValue != CheckValue) {
                    fCheck = false;
                }
            }
			if (ComparisonMode == "ne") {
			    if (StrValue == CheckValue) {
                    fCheck = false;
                }
            }
            if (ComparisonMode == "gt") {
			    if (StrValue <= CheckValue) {
                    fCheck = false;
                }
            }
            if (ComparisonMode == "lt") {
			    if (StrValue >= CheckValue) {
                    fCheck = false;
                }
            }
			if (!fCheck) {
				alert(strMsg);
			}
		}
	}


	function EmailCheck(StrValue)
	{

        if (fCheck)
        {   

			var disallowStr = ",!#$%^<>&*;:~` '\"\\|/"

			for ( var i = 0 ; i < StrValue.length ; i++ ){
				for ( var n = 0 ; n < disallowStr.length ; n++ ){
					if ( disallowStr.substring(n, n + 1) == StrValue.substring(i, i + 1) ) {
						alert("An illegal character [ " + disallowStr.substring(n, n + 1) + " ] was found in the email address");
						fCheck = false;
						return
					}
				}
			}

            var myArr = StrValue.split("@");

            if ( myArr.length != 2 ) {
                alert("there must be a single '@' symbol");
                fCheck = false;
				return;
            }

            if ( myArr[0].length == 0 ) {
                alert("no user has been specified");
                fCheck = false;
				return;
            }

            if ( myArr[1].length == 0 ) {
                alert("no domain has been specified");
                fCheck = false;
				return;
            }

            var dotArr = myArr[1].split(".")

            if ( dotArr.length < 2 ) {
                alert("please provide a suffix for this domain \( ie: .com, .org or country code\) ");
                fCheck = false;
				return;
            }

			for (i=0; i<dotArr.length; i++) {
				if ( dotArr[i].length < 1 ) {
					alert(error_prefix + "Each element in the domain must be at least one character long \( ie: @a.b.com\)");
					fCheck = false;
					return;
				}
			}

		}
	}
