﻿function isCharsInBag (s, bag)
{  
    var i;

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1)
        return false;
    }
    return true;
}

function getvalidate()
  {
  
  if((document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value==""))
  {
    alert("Please enter shortest menstrual cycle");
	document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').focus();
	return false;
  }
  if((document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value=="") && (document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value==""))
  {
    alert("Please enter longest menstrual cycle");
	document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').focus();
	return false;
  }
  if((document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value!=""))
  {
        //validation for shortest menstrual cycle.
        if((document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value>44) || (document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').value<20))
		{
		        alert("The Average cycle length is from 20 to 44 days. The values provided by you are beyond this and we would request you to please consult your doctor before planning a pregnancy.");
				//alert( "shortest menstrual cycle must contain days between 18 and 40 Days");
				document.getElementById('ctl00_ContentPlaceHolder1_txtshortday').focus();
				return false;
		}
  }
  if((document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value!=""))
  {
      if((document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value>44) || (document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value<20))
	  {
	            alert("The Average cycle length is from 20 to 44 days. The values provided by you are beyond this and we would request you to please consult your doctor before planning a pregnancy.");
				//alert( "longest menstrual cycle must contain days between 18 and 40 Days");
				document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').focus();
				return false;
	   }
  }
      return getResult();
  }
  
function getResult()
{
    
    var shortestdays,longestdays; 
    if(document.getElementById("ctl00_ContentPlaceHolder1_txtshortday").value != "")
    {
        shortestdays=document.getElementById("ctl00_ContentPlaceHolder1_txtshortday").value;
    }
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value!="")
    {
        longestdays=document.getElementById('ctl00_ContentPlaceHolder1_txtlongday').value;
    }
    
    var sServerName=new String(document.location);

    if (window.XMLHttpRequest) 
    {
        var XML = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) 
    {
        var XML = new ActiveXObject("Microsoft.XMLHTTP");
    }

    var URL = "FertilityCalculatorAjax.aspx?short=" + shortestdays  + "&long=" + longestdays;
    Type = "Type=";
    XML.open("POST", URL, false);
    XML.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    XML.send(Type);
    var s=XML.responseText;
    if(s != "")
    {
       document.getElementById("divResult").innerHTML = s;
       window.location.href="#result";
    }
    return false;
}

function Reset()
{
    document.getElementById("ctl00_ContentPlaceHolder1_txtshortday").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_txtlongday").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_txtlongday").className = "box1"; 
    document.getElementById("ctl00_ContentPlaceHolder1_txtshortday").className = "box1";
     document.getElementById("divResult").innerHTML = "";
    return false;
}




