//validation function for Child growth form
function growthform36validate()
{
	var childname=document.growthchart36form.childname.value;
	var childweight=document.growthchart36form.childweight.value;
	var childheight=document.growthchart36form.childheight.value;
	var childgender=document.growthchart36form.childgender.value;
	var day=document.growthchart36form.day.value;
	var month=document.growthchart36form.month.value;
	var year=document.growthchart36form.year.value;
	
	if(childname=="")
	{
    	alert("Enter your child's name");
	document.growthchart36form.childname.focus();
        return false;
	}

	// allow only letters, numbers, and underscores
	var illegalChars = /\W/;
	if (illegalChars.test(childname)) {
        alert("The child's name must use only letters");
	document.growthchart36form.childname.focus();
	return false;
    	} 
	
	var dob=new Date();
	var dob_3years=new Date();
	dob.setDate(day);
	dob.setMonth(month-1);
	dob.setFullYear(year);

	var today=new Date();

        if (dob > today)
        {
        alert("Date of birth cannot be in the future");
        document.growthchart36form.day.focus();
        return false;
        }

	dob_3years.setDate(dob.getDate());
	dob_3years.setMonth(dob.getMonth());
	dob_3years.setYear(dob.getYear());
	dob_3years.setFullYear(dob.getFullYear()+3);	

	if(dob_3years < today) 
	{
	alert("Your child is more than 3 years old. Please use the chart for children older than 3. You will find the link on the right sidebar of the page.");
	document.growthchart36form.year.focus();
	return false;
	}

	if(isNaN(childheight) || (childheight==""))
	{
    	alert("Use numbers to enter your child's height in centimeters");
	document.growthchart36form.childheight.focus();
        return false;
	}
	else if(childheight < 40 || childheight > 120)
	{
    	alert("Child's height must be between 40 and 120 cms");
	document.growthchart36form.childheight.focus();
        return false;
	}

	if(isNaN(childweight) || (childweight==""))
	{
    	alert("Use numbers to enter your child's weight in kilograms");
	document.growthchart36form.childweight.focus();
        return false;
	}
	else if(childweight < 1 || childweight > 20)
	{
    	alert("Child's weight must be between 1 and 20 kgs");
	document.growthchart36form.childweight.focus();
        return false;
	}

        url=site_url+"index.php?action=growthchart_ajax&do=babies&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight;
	
                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}

//validation function for Child growth form
function growthform18validate()
{
	var childname=document.growthchart18form.childname.value;
	var childgender=document.growthchart18form.childgender.value;
	var childweight=document.growthchart18form.childweight.value;
	var childheight=document.growthchart18form.childheight.value;
	var day=document.growthchart18form.day.value;
	var month=document.growthchart18form.month.value;
	var year=document.growthchart18form.year.value;
	
	if(childname=="")
	{
    	alert("Enter your child's name");
	document.growthchart18form.childname.focus();
        return false;
	}
	
	// allow only letters, numbers, and underscores
	var illegalChars = /\W/;
	if (illegalChars.test(childname)) {
        alert("The child's name must use only letters");
	document.growthchart18form.childname.focus();
	return false;
    	} 

	var dob=new Date();
	var dob_3years=new Date();
	var dob_18years=new Date();
	dob.setDate(day);
	dob.setMonth(month-1);
	dob.setFullYear(year);

	dob_3years.setDate(dob.getDate());
	dob_3years.setMonth(dob.getMonth());
	dob_3years.setYear(dob.getYear());
	dob_3years.setFullYear(dob.getFullYear()+3);	

	var today=new Date();

	if(dob_3years > today) 
	{
	alert("Your child is less than 3 years old. Please use the chart exclusively for children up to the age of 3 years. You will find the link on the right sidebar of the page.");
	document.growthchart18form.year.focus();
	return false;
	}

	dob_18years.setDate(dob.getDate());
	dob_18years.setMonth(dob.getMonth());
	dob_18years.setYear(dob.getYear());
	dob_18years.setFullYear(dob.getFullYear()+18);	

	if(dob_18years < today) 
	{
	alert("Your child is more than 18 years old. Charts are only for children 18 years or below");
	document.growthchart18form.year.focus();
	return false;
	}


        if (dob > today)
        {
        alert("Date of birth cannot be in the future");
        document.growthchart18form.day.focus();
        return false;
        }

	if(isNaN(childheight) || (childheight==""))
	{
    	alert("Use numbers to enter your child's height in centimeters");
	document.growthchart18form.childheight.focus();
        return false;
	}
	else if(childheight < 40 || childheight > 200)
	{
    	alert("Child's height must be between 40 and 200 cms");
	document.growthchart18form.childheight.focus();
        return false;
	}

	if(isNaN(childweight) || (childweight==""))
	{
    	alert("Use numbers to enter your child's weight in kilograms");
	document.growthchart18form.childweight.focus();
        return false;
	}
	else if(childweight < 1 || childweight > 100)
	{
    	alert("Child's weight must be between 1 and 100 kgs");
	document.growthchart18form.childweight.focus();
        return false;
	}

        url=site_url+"index.php?action=growthchart_ajax&do=children&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight;

                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}

function zoomin36()
{

	var childname=document.growthchart36form.childname.value;
	var childweight=document.growthchart36form.childweight.value;
	var childheight=document.growthchart36form.childheight.value;
	var childgender=document.growthchart36form.childgender.value;
	var day=document.growthchart36form.day.value;
	var month=document.growthchart36form.month.value;
	var year=document.growthchart36form.year.value;

        url=site_url+"index.php?action=growthchart_ajax&do=babies&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight+"&zoom=ON";
                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
//                      alert("Response - "+response);
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}

function zoomout36()
{

	var childname=document.growthchart36form.childname.value;
	var childweight=document.growthchart36form.childweight.value;
	var childheight=document.growthchart36form.childheight.value;
	var childgender=document.growthchart36form.childgender.value;
	var day=document.growthchart36form.day.value;
	var month=document.growthchart36form.month.value;
	var year=document.growthchart36form.year.value;

        url=site_url+"index.php?action=growthchart_ajax&do=babies&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight;
                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
//                      alert("Response - "+response);
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}

function zoomin18()
{

	alert("In zoomin18");
	var childname=document.growthchart18form.childname.value;
	var childweight=document.growthchart18form.childweight.value;
	var childheight=document.growthchart18form.childheight.value;
	var childgender=document.growthchart18form.childgender.value;
	var day=document.growthchart18form.day.value;
	var month=document.growthchart18form.month.value;
	var year=document.growthchart18form.year.value;

        url=site_url+"index.php?action=growthchart_ajax&do=children&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight+"&zoom=ON";
	alert(url);
                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
//                      alert("Response - "+response);
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}

function zoomout18()
{

	var childname=document.growthchart18form.childname.value;
	var childweight=document.growthchart18form.childweight.value;
	var childheight=document.growthchart18form.childheight.value;
	var childgender=document.growthchart18form.childgender.value;
	var day=document.growthchart18form.day.value;
	var month=document.growthchart18form.month.value;
	var year=document.growthchart18form.year.value;

        url=site_url+"index.php?action=growthchart_ajax&do=children&ok=1&childname="+childname+"&childgender="+childgender+"&day="+day+"&month="+month+"&year="+year+"&childweight="+childweight+"&childheight="+childheight;
                new Ajax.Request(url,
                 {
                        method:'post',
                parameters: {ajax: 1},
                onSuccess: function(transport)
                {
                                 var response = transport.responseText || "no response text";
//                      alert("Response - "+response);
                        document.getElementById("growthcharts").innerHTML=response;  

                }
                });

	return false;
}
