
function checkWholeForm(theForm) {
    var why = "";
    why += checkName(theForm.name.value);
	why += checkEmail(theForm.email.value);
    why += checkInstall_ID(theForm.install_id.value);
    why += checkPayment_ID(theForm.payment_id.value);
	why += checkComments(theForm.comment.value); 
	if (why != "") {
       alert(why);
       return false;
    }
	return true;
}
//=================================================
function checkName(strng) {
	var illegalChars = /[^A-Za-z\.\W{1,2}]/; // allow only letters, dot, 1 or 2 spaces
	error = "";
	if (isWhitespace(strng))
	{		error = "You have not entered a Name.\n";
	}
    else if (illegalChars.test(strng)) 
	//else	if (strng.match(illegalChars))
	{
      error = "The Name contains illegal characters.\n";
    }

	return error;
}
//---------------------------------------------------------------------------
function checkEmail(strng) {
	error="";
	
	var emailFilter=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	//var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
	}

	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (strng.match(illegalChars)) {
		error = "The email address contains illegal characters.\n";
	}
	return error;
}

//--------------------------------------------------------------------------
function checkInstall_ID(strng) {
	error = "";
	if (isWhitespace(strng))
	{		error = "You have not entered an Installation ID.\n";
	}
	// else if (!IsNumeric(strng)) 
	//{ 
   //   error = "Please enter only numbers in the Install ID field.\n";
    // } 
	return error;
}

function checkComments(strng) {
	error = "";
	if (isWhitespace(strng))
	{		error = "You have not entered your comments.\n";
	}
	return error;
}

      // whitespace characters
      var whitespace = " \t\n\r";

    //--------------------------------------------------------------------------
function checkPayment_ID(strng) {
	error = "";
	if (isWhitespace(strng))
	{		error = "You have not entered a Payment ID.\n";
	}
	return error;
}
  
	  
	  /****************************************************************/

      // Check whether string s is empty.
      function isEmpty(s)
      { return ((s == null) || (s.length == 0)) }

      /****************************************************************/

      function isWhitespace (s)
      {
           var i;

           // Is s empty?
           if (isEmpty(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;
      }

function getIID(theForm) {
var iid = window.document.URL;							// find parameters
var parlen=iid.length;
var startOfSource=iid.indexOf ("iid=");					// get index of "iid="
if (startOfSource != -1)												// if "iid=" exists
	{result=iid.substring(startOfSource+4, parlen); // get IID
		if (result != "") 
		{theForm.install_ID.value = result;					// to the form
		}
	}
}

