// JavaScript Document

function trim(s)

{

  return s.replace(/^\s+|\s+$/, '');

} 



function validateEmail(fld) {

    var error="";

    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off

    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;

    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

    

    if (fld.value == "") {

        fld.style.background = 'Yellow';

    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters

        fld.style.background = 'Yellow';

        alert("Please enter a valid email address.");

		fld.focus();

    } else if (fld.value.match(illegalChars)) {

        fld.style.background = 'Yellow';

        alert("The email address contains illegal characters.");

		fld.focus();

    } else {

		fld.style.background = 'White';

	}

}



function validatePhone(fld) {

    var error = "";

    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');     



   if (fld.value == "") {

        fld.style.background = 'Yellow';

    } else if (isNaN(parseInt(stripped))) {

        alert("The phone number contains illegal characters.");

        fld.style.background = 'Yellow';

		fld.focus();

    } else if (!(stripped.length == 10)) {

        alert("The phone number is the wrong length. Make sure you included an area code.");

        fld.style.background = 'Yellow';

		fld.focus();

    } else {

		fld.style.background = 'White';

	}

}

function validatePassword(fld) {

   strpass = document.getElementById("ipassword");
      
   if (fld.value == "") {

        fld.style.background = 'Yellow';

    } else if (strpass.value==fld.value) {
		fld.style.background = 'White';
	} else {

        alert("The Passwords do not match");

        fld.style.background = 'Yellow';

		fld.focus();

    }
   
   


   

}



function IsEmpty(aTextField) {

   if ((aTextField.value.length==0) ||

   (aTextField.value==null)) {

      return true;

   }

   else { return false; }

}	

function IsNumeric(sText)

{

   var ValidChars = "0123456789.-()";

   var IsNumber=true;

   var Char;



   for (i = 0; i < sText.length && IsNumber == true; i++) 

      { 

      Char = sText.charAt(i); 

      if (ValidChars.indexOf(Char) == -1) 

         {

         IsNumber = false;

         }

      }

   return IsNumber;

   

   }

 // 

 

 function isEmpty2(s)

{   return ((s == null) || (s.length == 0))

}



// whitespace characters

var whitespace = " \t\n\r";



// Returns true if string s is empty or

// whitespace characters only.



function isWhitespace (s)



{   var i;



    // Is s empty?

    if (isEmpty2(s)) return true;



    // Search through string's characters one by one

    // until we find a non-whitespace character.

    // When we do, return false; if we don't, return true.



    for (i = 0; i < s.length; i++)

    {

        // Check that current character isn't whitespace.

        var c = s.charAt(i);



        if (whitespace.indexOf(c) == -1) return false;

    }



    // All characters are whitespace.

    return true;

}



// fieldList is comma separated, no whitespace

function chkReqdFields(formName, fieldList) {

	var arrFields;

	var i = 0

	var isvalid=true;

	//alert('Checking ' + formName);



	arrFields = fieldList.split(',');

	for(i = 0; i<arrFields.length; i++) {

		//alert('Checking ' + arrFields[i]);

		if(isWhitespace(eval('document.forms["' + formName + '"].' + arrFields[i] + '.value'))) {

			//alert("Please fill in all required fields.");		

			isvalid=false;

		}

	}

	if (isvalid) {

		document.forms[formName].submit();

	} else {

		alert("Please fill in all required fields.");			

	}

}



function createWindow(url,name,features){

		var xwin=window.open(url,name,features);

	}
