

var whitespace = " \t\n\r";

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 isEmpty(s)

{   return ((s == null) || (s.length == 0))

}

function ForceNumber(objField, FieldName)

{

	var strField = new String(objField.value);

	

	if (isWhitespace(strField)) return true;



	var i = 0;



	for (i = 0; i < strField.length; i++)

		if ((strField.charAt(i) < '0' || strField.charAt(i) > '9') && strField.charAt(i) != '(' && strField.charAt(i) != ')' && strField.charAt(i) != '-' && strField.charAt(i) != ',' && strField.charAt(i) != '+' ) {

			alert(FieldName + " must be a valid numeric entry.\nPlease do not use symbols, alphabets or whitespaces.\nCommas ',', Plus '+', Hyphen '-' and braces '()' are also allowed.");

			objField.focus();

			return false;

		}



	return true;

}

function isEmail(str) {

  // are regular expressions supported?

  temp = str.split('@');

  if(temp.length > 2) return false;

  var supported = 0;

  if (window.RegExp) {

   var tempStr = "a";

   var tempReg = new RegExp(tempStr);

   if (tempReg.test(tempStr)) supported = 1;

  }

  if (!supported)

  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0) ;



  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");

  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");

  return (!r1.test(str) && r2.test(str));

}

function check() { 

if(document.forms[0].fname.value=="")

{

alert("First name!");

document.forms[0].fname.focus();

return false;

}

if(document.forms[0].lname.value=="")

{

alert("Last name!");

document.forms[0].lname.focus();

return false;

}

if(document.forms[0].email.value=="")

{

alert("Email!");

document.forms[0].email.focus();

return false;

}

if(!isEmail(document.forms[0].email.value)){

alert("Check the Email field!");

document.forms[0].email.focus();

return false;

}

if(document.forms[0].address.value=="")

{

alert("Address!");

document.forms[0].address.focus();

return false;

}



if(isNaN(document.forms[0].ccoad.value))

{

alert("Please check country code!\nOnly numbers are allowed.");

document.forms[0].ccoad.focus();

return false;

}

if(!ForceNumber(document.forms[0].homeph,"Home Phone")) return false;

if(!ForceNumber(document.forms[0].workph,"Work Phone")) return false;

if(!ForceNumber(document.forms[0].mobileph,"Mobile Phone")) return false;

open("","apppop","top=150,left=100,width=600,height=300");

return true;

}



