<!--//
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,friendly,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { 
	friendly=args[i+1]; test=args[i+2]; val=MM_findObj(args[i]);
		if (val) { 
			nm=val.name; 
			if ((val=val.value)!="") {
				if (test.indexOf('isEmail')!=-1) { 
					p=val.indexOf('@');
					if (p<1 || p==(val.length-1)) {
						//document.getElementById(args[i]).style.background="#FF0000";
						errors+='- You did not specify a valid Email address.\n';
					}
				} else if (test.indexOf('D')!=-1) {
					if (isDate(val)==false) {
						//document.getElementById(args[i]).style.background="#FF0000";
						errors+='- '+friendly+' must be in the format YYYY-MM-DD.\n';
					}
				} else if (test.indexOf('N')!=-1) {
					if (checkInternationalPhone(val)==false){ 
						//document.getElementById(args[i]).style.background="#FF0000";
						errors+='- '+friendly+' is not valid.\n';
					}
					/*
					if (isNaN(val)){ 
						document.getElementById(args[i]).style.background="#FF0000";
						errors+='- '+friendly+' must contain a number.\n';
					}
					if (test.indexOf('maxmin') != -1) { 
						document.getElementById(args[i]).style.background="#FF0000";
						p=test.indexOf(':');
						min=test.substring(6,p); 
						max=test.substring(p+1);
						if (val<min || max<val) {errors+='- '+friendly+' must contain a number between '+min+' and '+max+'.\n';}
					}
					*/					
				} else if (test.indexOf('W')!=-1) {
					var alphaExp = /^[a-zA-Z ]+$/;
					if (!val.match(alphaExp)){
						//document.getElementById(args[i]).style.background="#FF0000";
						errors+='- '+friendly+' must be all letters.\n';
					}
				}
			} else if (test.charAt(0) == 'R') {
				//document.getElementById(args[i]).style.background="#FF0000";
				errors += '- '+friendly+' is required.\n';
			}
		}
  } 
  
  if (errors) 
	alert('ATTENTION!\n The system cannot accept your submission, please review the following errors:\n\n'+errors);
	
  if (!errors)
	alert('Thank you!\n' +val+' is now signed up for the Cornerstone Knowledge List');
	
  document.MM_returnValue = (errors == '');
}

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//-->


 
 
