// JavaScript Document
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//-->
<!--
	function trim(s) {
		while (s.substring(0,1) == ' ') {
		s = s.substring(1,s.length);
	  	}
		while (s.substring(s.length-1,s.length) == ' ') {
	 	s = s.substring(0,s.length-1);
	  	}
		 return s;		
	}	
	
	function validate()
	{	
		
		if (trim(document.dr2kids.pfirstname.value)=="")
		 {
 			alert("Please enter Patient’s First Name");
			document.dr2kids.pfirstname.focus();
			return false; 
		 }
	/*
		if (!checkName(trim(document.dr2kids.pfirstname.value)))
		{
			alert("First Name field should be in Alphabets");
			document.dr2kids.pfirstname.focus();
			return false; 
		}*/
		
		
		/*if (trim(document.dr2kids.pmi.value)!="")
		{ 
			if (!checkName(trim(document.dr2kids.pmi.value)))
			{
				alert("M.I Field should be in Alphabets");
				document.dr2kids.pmi.focus();
				return false; 
			}
		}*/	
		
		if(trim(document.dr2kids.plastname.value)=="")
		{
 			alert("Please enter Patient’s Last Name");
			document.dr2kids.plastname.focus();
			return false; 
		
		}
/*		
		if (trim(document.dr2kids.plastname.value) != ""){
			if (!checkName(trim(document.dr2kids.plastname.value)))
			{
				alert("Patient’s Last Name field should be in Alphabets");
				document.dr2kids.plastname.focus();
				return false; 
			}
		}*/
		
		myOption = -1;
		for (i=0; i<document.dr2kids.psex.length; i++) {
			if (document.dr2kids.psex[i].checked) {
			myOption = i;
		}
		}
		if (myOption == -1) {
			alert("You must select a sex (male/female)");
			return false;
		}

	 	if (trim(document.dr2kids.pmonth.value)==0)
		 {
 			alert("Please select your Month of Birth");
			document.dr2kids.pmonth.focus();
			return false; 
		 } 
		 
		if (trim(document.dr2kids.pday.value)==0)
		 {
 			alert("Please select your Day of Birth");
			document.dr2kids.pday.focus();
			return false; 
		 } 
		 
		if (trim(document.dr2kids.pyear.value)==0)
		 {
 			alert("Please select your Year of Birth");
			document.dr2kids.pyear.focus();
			return false; 
		 } 
		
		if (trim(document.dr2kids.pssn.value) != ""){
			if (isNaN(trim(document.dr2kids.pssn.value)))
			{
				alert("SSN field should be in Numeric value");
				document.dr2kids.pssn.focus();
				return false; 
			}
		}		 
/*		 
		if (trim(document.dr2kids.planguage.value) != ""){
			if (!checkName(trim(document.dr2kids.planguage.value)))
			{
				alert("Language field should be in Alphabets");
				document.dr2kids.planguage.focus();
				return false; 
			}
		}		*/

		if (trim(document.dr2kids.paddress.value) == "")
			{
				alert("Please enter your Address");
				document.dr2kids.paddress.focus();
				return false; 
			}	
			
		if (trim(document.dr2kids.pcity.value)=="")
		 {
 			alert("Please enter your city!");
			document.dr2kids.pcity.focus();
			return false; 
		 }
		 		
/*
		if (!checkName(trim(document.dr2kids.pcity.value)))

			{
				alert("City field should be in Alphabets");
				document.dr2kids.pcity.focus();
				return false; 
			}
	*/			
		if (trim(document.dr2kids.pzip.value) == "")
			{
				alert("Please enter Zip!");
				document.dr2kids.pzip.focus();
				return false; 
			}
	
		var ch_OK = "0123456789-";
		var ch_Str = trim(document.dr2kids.pzip.value);
		var all_Valid = true;
		var Char; 
		
		for (i = 0; i < ch_Str.length; i++)
		{
			ch = ch_Str.charAt(i);
			
			for (j = 0; j < ch_OK.length; j++)
				if (ch == ch_OK.charAt(j))
					break;
				if (j == ch_OK.length)
				{
					all_Valid = false;
					break;
				}
		}
		
		for (k = 0; k < ch_Str.length; k++) 
	      { 
	      Char = ch_Str.charAt(k); 
	      if ((Char == "-") && (k < 5))   
		  {
		  	all_Valid = false;
			break;
		  }
		  if ((Char == "-") && (k != 5))   
		  {
		  	all_Valid = false;
			break;
		  }
		  if (ch_OK.indexOf(Char) == -1) 
	         {
	        	all_Valid = false;
				break;
	         }
	      }
		
		if (!all_Valid)
		{
			alert("Please enter valid zip code");
			return false;
		}
		
		if ((ch_Str.length < 5) || (ch_Str.length > 10)){
			alert("Please enter valid zip code")
			document.dr2kids.pzip.focus()
			return false;
		}		
	
		//Work Phone Validation
		if (trim(document.dr2kids.phphone.value) != false){
			if (checkInternationalPhone(document.dr2kids.phphone.value)==false){
				alert("Please Enter a Valid Home Phone Number")
				document.dr2kids.phphone.focus()
				return false;
			}
		}
		
		//Work Phone Validation
		if (trim(document.dr2kids.pwphone.value) != false){
			if (checkInternationalPhone(document.dr2kids.pwphone.value)==false){
				alert("Please Enter a Valid work Phone Number")
				document.dr2kids.pwphone.focus()
				return false;
			}
		}

		//Cell Phone Validation
		if (trim(document.dr2kids.pcellular.value) != false){
			if (checkInternationalPhone(document.dr2kids.pcellular.value)==false){
				alert("Please Enter a Cell Phone Number")
				document.dr2kids.pcellular.focus()
				return false;
			}
		}
			
		if (trim(document.dr2kids.pemail.value) == ""){
				alert("Enter your email-id");
				document.dr2kids.pemail.focus();
				return false; 
		}
		
		if (trim(document.dr2kids.pemail.value) != ""){
			if( isEmail(trim(document.dr2kids.pemail.value)) == false )
			{
				alert("Invalid email");
				document.dr2kids.pemail.focus();
				return false; 
			}
		}	
		
		
		//Mom Details Validation
		//		Name validation
		if (trim(document.dr2kids.mname.value) != ""){
			if (!checkName(trim(document.dr2kids.mname.value)))
			{
				alert("Patient’s mother's Name field should be in Alphabets");
				document.dr2kids.mname.focus();
				return false; 
			}
		}
		
		
		//Age Validation
		
		if (trim(document.dr2kids.mage.value) != ""){
			
			if (isNaN(trim(document.dr2kids.mage.value)))
			{
				alert("Enter the valid age for Patient’s mother");
				document.dr2kids.mage.focus();
				return false; 
			}
		}	
		
		
		//SSN Validation
		if (trim(document.dr2kids.mssn.value) != ""){
			if (isNaN(trim(document.dr2kids.mssn.value)))
			{
				alert("SSN field should be in Numeric values");
				document.dr2kids.mssn.focus();
				return false; 
			}
		}	
		
		//worke / cell phone validation
		if (trim(document.dr2kids.mwphone.value) != false){
			if (checkInternationalPhone(document.dr2kids.mwphone.value)==false){
				alert("Please Enter a Valid work/Cell Phone Number")
				document.dr2kids.mwphone.focus()
				return false;
			}
		}
				
		//Mom Validation End		
		//Father Details Validation
		//		Name validation
		if (trim(document.dr2kids.fname.value) != ""){
			if (!checkName(trim(document.dr2kids.fname.value)))
			{
				alert("Patient’s father's Name field should be in Alphabets");
				document.dr2kids.fname.focus();
				return false; 
			}
		}
		
		
		//Age Validation
		
		if (trim(document.dr2kids.fage.value) != ""){
			
			if (isNaN(trim(document.dr2kids.fage.value)))
			{
				alert("Enter the valid age for Patient’s father");
				document.dr2kids.fage.focus();
				return false; 
			}
		}	
		
		
		//SSN Validation
		if (trim(document.dr2kids.fssn.value) != ""){
			if (isNaN(trim(document.dr2kids.fssn.value)))
			{
				alert("SSN field should be in Numeric values");
				document.dr2kids.fssn.focus();
				return false; 
			}
		}	
		
		//worke / cell phone validation
		if (trim(document.dr2kids.fwphone.value) != false){
			if (checkInternationalPhone(document.dr2kids.fwphone.value)==false){
				alert("Please Enter a Valid work/Cell Phone Number")
				document.dr2kids.fwphone.focus()
				return false;
			}
		}
		
		//Father Validation End		
		//Emergency 1
		
			//Contact validation
			if (trim(document.dr2kids.emergency1.value) != ""){
				if (!checkName(trim(document.dr2kids.emergency1.value)))
				{
					alert("Enter the valid name for emergency contact");
					document.dr2kids.emergency1.focus();
					return false; 
				}
			}

				
			//worke / cell phone validation
			if (trim(document.dr2kids.emphone1.value) != false){
				if (checkInternationalPhone(document.dr2kids.emphone1.value)==false){
					alert("Please Enter a Valid Phone Number")
					document.dr2kids.emphone1.focus()
					return false;
				}
			}	
			
		//Relationship Validation
			if (trim(document.dr2kids.childrelation1.value) != ""){
				if (!checkName(trim(document.dr2kids.childrelation1.value)))
				{
					alert("Enter the valid relation with the child");
					document.dr2kids.childrelation1.focus();
					return false; 
				}
			}			
			
		//Emergency1 end
		//Emergency 2
		//Contact validation
			if (trim(document.dr2kids.emergency2.value) != ""){
				if (!checkName(trim(document.dr2kids.emergency2.value)))
				{
					alert("Enter the valid name for emergency contact");
					document.dr2kids.emergency2.focus();
					return false; 
				}
			}

			//worke / cell phone validation
			if (trim(document.dr2kids.emphone2.value) != false){
				if (checkInternationalPhone(document.dr2kids.emphone2.value)==false){
					alert("Please Enter a Valid Phone Number")
					document.dr2kids.emphone2.focus()
					return false;
				}
			}	
		
			
			//Relationship Validation
			if (trim(document.dr2kids.childrelation1.value) != ""){
				if (!checkName(trim(document.dr2kids.childrelation1.value)))
				{
					alert("Enter the valid relation with the child");
					document.dr2kids.childrelation1.focus();
					return false; 
				}
			}			
			
		//Emergency2 end
			
		document.dr2kids.action="sendmail.php" 
		document.dr2kids.method="Post" 
		document.dr2kids.submit();
	}
	
	function isEmail(email) {
	invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;";
    // Check for invalid characters as defined above
    for (i=0; i<invalidChars.length; i++) {
        badChar = invalidChars.charAt(i);
        if (email.indexOf(badChar,0) > -1) {
            return false;
        }
    }
    lengthOfEmail = email.length;
    if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) {
        return false;
    }
    Pos = email.indexOf("@",1);
    if (email.charAt(Pos + 1) == ".") {
        return false;
    }
    while ((Pos < lengthOfEmail) && ( Pos != -1)) {
        Pos = email.indexOf(".",Pos);
        if (email.charAt(Pos + 1) == ".") {
            return false;
        }
        if (Pos != -1) {
            Pos++;
        }
    }
    // There must be at least one @ symbol
    atPos = email.indexOf("@",1);
    if (atPos == -1) {
        return false;
    }
 
    // But only ONE @ symbol
    if (email.indexOf("@",atPos+1) != -1) {
        return false;
    }
	 
    // Also check for at least one period after the @ symbol
    periodPos = email.indexOf(".",atPos);
    if (periodPos == -1) {
        return false;
    }
    if (periodPos+3 > email.length) {
        return false;
    }
    return true;
}

// 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);
}


function trimString (str)
 {
	var str1;
	str1=str;
	return str1.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function stripCharsNotInBag (s, bag)
{
   var i;
    var returnString = "";
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) != -1) returnString += c;
    }
    return returnString;
}


function inputPhone(oControl,lExt)
{
	// strip out any non-valid characters
	cPhone = stripCharsNotInBag(oControl.value,'0123456789()-');

	// check for empties
	if (cPhone == '')
	{
		oControl.value = cPhone;
		return null;
	}
	
	// check if the first char is a 1, remove it after there are 2 chars
	if ((cPhone.length == 2) && (cPhone.substring(0,1) == '1'))
		cPhone = cPhone.substring(1,cPhone.length);

	// strip all formatting chars
	cPhone = stripCharsNotInBag(cPhone,'0123456789');

	if (cPhone != '1')
	{
		// add the formatting chars back in
		cPhone = '('+cPhone;

		if (cPhone.length > 3)
			cPhone = cPhone.substring(0,4)+')'+cPhone.substring(4,cPhone.length);

		if (cPhone.length > 7)
			cPhone = cPhone.substring(0,8)+'-'+cPhone.substring(8,cPhone.length);

		// check for extension
		if ((cPhone.length > 13) || ((cPhone.length==13) && (lExt) && (oControl.value.substring(oControl.value.length-1,oControl.value.length).toLowerCase()=='x')))
		{
			if (lExt)
				cPhone = cPhone.substring(0,13)+' x'+cPhone.substring(13,cPhone.length);
			else
				cPhone = cPhone.substring(0,13);
		}

	}

	// return the new value
	oControl.value = cPhone;
}
//-->