
function jsloadDistrict(url)
{
 $('districtloader').style.visibility = 'visible';
   	var load_dist='action=DISTRICT&STATE_ID='+escape($('state_select').value);
   //alert(load_dist);
 	new Ajax.Request(url,{method:"get",parameters:load_dist,onSuccess:loadDistrict,onFailure:dispError})


}

function loadDistrict(reqObj)
	{
     // alert(reqObj.responseText);
        $('select_district').update(reqObj.responseText);
         $('districtloader').style.visibility = 'hidden';
	}


function jsloadHospital(url)
{
    $('hospitalloader').style.visibility = 'visible';
   var load_hospital='action=HOSPITAL&DISTRICT_ID='+escape($('select_district').value);
  // alert(load_hospital);
 	new Ajax.Request(url,{method:"get",parameters:load_hospital,onSuccess:loadHospital,onFailure:dispError})

}

function loadHospital(reqObj)
{
      //alert(reqObj.responseText);
        $('select_hospital').update(reqObj.responseText);
         $('hospitalloader').style.visibility = 'hidden';
}

function jsloadLocalBodywiseHospital(url)
{
    $('hospitalloader').style.visibility = 'visible';
   var load_hospital='action=HOSPITAL_LOCAL&LOCALBODY_ID='+escape($('localbody').value);
  // alert(load_hospital);
 	new Ajax.Request(url,{method:"get",parameters:load_hospital,onSuccess:loadHospitalLocal,onFailure:dispError})

}


function loadHospitalLocal(reqObj)
{
      //alert(reqObj.responseText);
        $('select_hospital').update(reqObj.responseText);
         $('hospitalloader').style.visibility = 'hidden';
}



function dispError()
	{

	 $('error_div').style.display='block';
	 $("error_div").innerHTML='Some errors occured';

	}


function jsloadLocalBody(typevalue,url)
 {
      $('localbodyloader').style.visibility = 'visible';
    //alert("patient manager");
    var load_lb='action=LOCALBODY&DISTRICT_ID='+escape($('select_district').value)+'&LB_TYPE='+typevalue;
    //var load_lb='action=LOCALBODY&DISTRICT_ID='+escape($('select_district').value)+'&LB_TYPE='+escape($('localbodytype').value);
    //alert(load_lb);
 	new Ajax.Request(url,{method:"get",parameters:load_lb,onSuccess:loadLocalBody,onFailure:dispError})
 }

function loadLocalBody(reqObj)
	{
    // alert(reqObj.responseText);
     $('localbody').update(reqObj.responseText);
 $('localbodyloader').style.visibility = 'hidden';

	}
function showDoctors(url,h_id)
    {
      var load_doctors='action=DOCTORS&SPEC_ID='+escape($('load_speciality').value)+'&HOSP_ID='+h_id;
   // alert(load_pin);
 	new Ajax.Request(url,{method:"get",parameters:load_doctors,onSuccess:loadDoctors,onFailure:dispError})
    }

function loadDoctors(reqObj)
	{
    //   alert(reqObj.responseText);
        $('doctors').style.display='block';
       if(reqObj.responseText!=0)
           {

        $('doctors').update(reqObj.responseText);
        $('addbutton').style.display='block';
           }
        else
            {
          $('doctors').innerHTML="<font color='red' size='2'>There are no doctors matching this selection</font>";
            }
        
	}







 function searchHosp()
    {
     
    thisForm.txtWhat2Do.value='HOSP_SEARCH';
    thisForm.action='patientsearchHospital.php';
    thisForm.submit();
    }

    function searchDoctors()
    {

     if(trim($("txtdoctorid").value)!='')
        {
        if(isNaN(trim($("txtdoctorid").value)) )
        {

         $('div3').style.display = 'none';
         //alert("Doctor id field should be a number");
         $("doctoriderror").style.display='block';
         $("doctoriderror").innerHTML='Doctor id field should be a number';
         $("txtdoctorid").focus();
        return;

        }
        if(trim($("txtdoctorid").value)<= 0)
        {
          $('div3').style.display = 'none';
         //alert("Doctor id must be greater than zero");
         $("doctoriderror").style.display='block';
         $("doctoriderror").innerHTML='Doctor id must be greater than zero';
         $("txtdoctorid").focus();
        return;
        }
        if(trim($("filt_name").value)!='')
        {
        if(!isValidName(trim($("filt_name").value)) )
        {

         $('div3').style.display = 'none';
          $("doctoriderror").style.display='none';
          $("doctorNameerror").style.display='block';
          $("doctorNameerror").innerHTML='Special characters are not allowed in name field';
         //alert("Special characters are not allowed in name field");
         $("filt_name").focus();
         
        return;

        }}

        }
 
   else
       {
       if( ( $('state_select').value=='') )
        {
            $('div3').style.display = 'block';
            $('div3').innerHTML="You must select a state";
           return false;
        }

        if(trim($("filt_name").value)!='')
        {


        if(!isValidName(trim($("filt_name").value)) )
        {

        $('div3').style.display = 'none';
          $("doctoriderror").style.display='none';
          $("doctorNameerror").style.display='block';
          $("doctorNameerror").innerHTML='Special characters are not allowed in name field';
         //alert("Special characters are not allowed in name field");
         
         $("filt_name").focus();
        return false;

        }
        }
       }
    thisForm.txtWhat2Do.value='DOCTOR_SEARCH';
     thisForm.submit();
    }


function AddtoFavorite()
{
 thisForm.txtWhat2Do.value='ADDTOFAV';
 thisForm.submit();
}

function __changepassword(url)
{
   
    $('divPasswordErr').style.display       = 'none';
    $('divNewPasswordErr').style.display    = 'none';
    $('divNewConfirmErr').style.display     = 'none';

	if($('oldpasswd').value=='')
    {
		$('divPasswordErr').style.display='block';
		$('oldpasswd').focus();
		$('divPasswordErr').innerHTML="Please Enter Current Password";
        return false;
	}else if($('newpasswd').value=='')
    {
		$('divNewPasswordErr').style.display='block';
		$('newpasswd').focus();
		$('divNewPasswordErr').innerHTML="Please Enter a New Password";
        return false;
	}
    else if ( $('newpasswd').value.length < 6)
    {
		$('divNewPasswordErr').style.display='block';
		$('newpasswd').focus();
		$('divNewPasswordErr').innerHTML="Minimum of 6 characters !";
        return false;
	}
    else if($('newpasswd').value=='')
    {
		$('divNewConfirmErr').style.display='block';
		$('newpasswd').focus();
		$('divNewConfirmErr').innerHTML="Enter the New Password Again.";
        return false;
	}

    else if($('newpasswd').value=='' || $('newpasswd').value	!=	$('confirm_password').value )
    {
		$('divNewConfirmErr').style.display='block';
		$('confirm_password').focus();
		$('divNewConfirmErr').innerHTML="Passwords are not matching";
        return false;
	}
    else if($('oldpasswd').value	==	$('newpasswd').value )
    {
		$('divPasswordErr').style.display='block';
		$('newpasswd').focus();
		$('divPasswordErr').innerHTML="Current Password and New Password are same";
        return false;
	}
   // $('imgpasswd').style.visibility ='visible';
    //var url='http://localhost/MeetDoctor/ajaxpassword.php';
    thisForm.txtWhat2Do.value='CHANGE_PASSWORD';
            thisForm.submit();

}

function __changeNumber(url)
{
  //  alert("in change Numb")
    $('div3').style.display = 'none';
    $('div4').style.display = 'none';
    if($("oldNumber").value=='' )
    {
        $('div3').style.display = 'block';
        $('div3').innerHTML="Enter old Number field";
        $("oldNumber").focus();
        return;
    }
    if($("newNumber").value=='' )
    {
        $('div4').style.display = 'block';
        $('div4').innerHTML="Enter new number field";
        $("newNumber").focus();
        return;
    }

    if(   ($("newNumber").value.length!=10 ) || (!isInteger($("newNumber").value)) )
    {
        $('div4').style.display = 'block';
        $('div4').innerHTML="The New number should be a 10 digit integer value";
        $("newNumber").focus();
        return;
    }
    
   $('imgpasswd').style.visibility ='visible';
    var oldnumber=$('oldNumber').value;
    var newnumber=$('newNumber').value;
    var postof='action=CHANGEMOB&old='+escape(oldnumber)+'&new='+escape(newnumber);
 //alert(postof);
    new Ajax.Request(url,{
        method:"get",
        parameters:postof,
        onSuccess:showChangenumber,
        onFailure:dispError
    })

}

function showChangepassword(reqObj)
{

   $('imgpasswd').style.visibility = 'hidden';
    
    $('messdiv').style.display='block';

    $('messdiv').innerHTML="<font color='red' size='2'>"+reqObj.responseText+"</font>";
    
    $('oldNumber').value='';
     $('newNumber').value='';
}

function showChangenumber(reqObj)
{

   // alert(reqObj.responseText);
    $('imgpasswd').style.visibility ='hidden';
    $('messdiv').style.display='block';
    
    $('messdiv').innerHTML="<font color='red' size='2'>"+reqObj.responseText+"</font>";
}

function __AddSecondaryNames(url)
{

    var secondaryname=$('secondaryname').value;
  //  alert(secondaryname);
    $('div3').style.display = 'none';
    if($("secondaryname").value=='' )
    {
        $('div3').style.display = 'block';
        $('div3').innerHTML="Enter secondaryname";
        $("secondaryname").focus();
        return false;
    }


     if(trim($("secondaryname").value)!='')
        {
         if(!isValidName(trim($('secondaryname').value)))
                {
                $('div3').style.display = 'block';
                $('div3').innerHTML="Special characters are not allowed  ";
                $("secondaryname").focus();
                return false;

                }

           
        }

    else if( !isNaN($("secondaryname").value) ||  (secondaryname.charAt(0)=="-"))
        {
          $('div3').style.display = 'block';
        $('div3').innerHTML="Secondaryname should be  alphabetic ";
        $("secondaryname").focus();
        return false;
        }


    
           thisForm.txtWhat2Do.value='ADDSECONDARYNAME';
            thisForm.submit();
   
        

}

function showSecondaryRegnumber(reqObj)
{

var str=reqObj.responseText;

$("secondarynameloader").style.visibility = 'hidden';

window.location="patient_secondary_names.php";

$('messdiv').innerHTML="<font color='red'>"+str+"</font>";
     
}


function __fncEditPatientDetails()
{
         $('div3').style.display = 'none';
         $('div4').style.display = 'none';

         var p_name=$('p_name').value;
         
        /* var p_add1=$('p_add1').value;
        
         var p_add2=$('p_add2').value;
      
         var p_add3=$('p_add3').value;
       
         var email=$('email').value;
       
         var sel_state=$('state_select').value;
       
         var sel_district=$('select_district').value;

         var sel_post_name=$('p_postofficename').value;*/

        if(trim($('p_name').value)!='')
            {
             
                if(!isValidName(trim($('p_name').value)))
                {
                $('div3').style.display = 'block';
                $('div3').innerHTML="Special characters are not allowed  ";
                $("p_name").focus();
                return false;    
                    
                }
           
            }



        var sel_pin=$('p_pincode').value;
      
        if( !isNaN(p_name) ||  (p_name.charAt(0)=="-"))
        {
        $('div4').style.display = 'block';
        $('div4').innerHTML="The name should be alphabetic  ";
        $("p_name").focus();
        return false;
        }

        if( !isInteger(sel_pin) )
        {
        $('div4').style.display = 'block';
        $('div4').innerHTML="The pincode must be an integer  ";
        $("sel_pin").focus();
        return false;
        }
          thisForm.txtWhat2Do.value='EDITPATIENTDETAILS';
            thisForm.submit();
//        var postof='action=EDITPATIENT&name='+escape(p_name)+'&add1='+escape(p_add1)+'&add2='+escape(p_add2)+'&add3='+escape(p_add3)+'&email='+escape(email)+'&state='+escape(sel_state)+'&district='+escape(sel_district)+'&pincode='+escape(sel_pin)+'&postofficename='+escape(sel_post_name);
//       /* alert(postof);*/
//            new Ajax.Request(url,{
//                method:"get",
//                parameters:postof,
//                onSuccess:showEditResult,
//                onFailure:dispError
//
//            })
 }



function showEditResult(reqObj)
{

    //alert(reqObj.responseText);
    $('messdiv').innerHTML="<font color='red' size='2'>"+reqObj.responseText+"</font>";

}


function __EditSecondaryNames(url,sec_id,sec_name)
{
    $('secondaryid').value=sec_id;
    $('secondaryname').value=sec_name;
    thisForm.txtWhat2Do.value='EDIT';
     thisForm.submit();


}

function __DeleteSecondaryNames(url,sec_id)
{
     $('editsecondarynameloader').style.visibility = 'visible';
     if(addNotification())
     {
 

      var postof='action=DELETESECNAME&secid='+escape(sec_id);
        //alert(postof);
            new Ajax.Request(url,{
                method:"get",
                parameters:postof,
                onSuccess:showDeleteResult,
                onFailure:dispError
            })
     }
     $('editsecondarynameloader').style.visibility = 'hidden';
}

function showDeleteResult(reqObj)
{

   // alert(reqObj.responseText);
 
    $('messdiv').innerHTML=reqObj.responseText;
    $('editsecondarynameloader').style.visibility = 'hidden';
    window.location="patient_secondary_names.php";

}

function addNotification()
{

    var agree=confirm("Are you sure you wish to delete this secondary name ?");
    if (agree)
        return true ;
    else
        return false ;

}

function enableLbtypeForHs(lbtype,url)
{
    $('hiddenLbTypeForHs').value=lbtype;

    loadLocalBodyForHospital(url);


}

function loadLocalBodyForHospital(url)
{
  //  alert(url);
   //alert($('hiddenLbTypeForHs').value);

    if ($('select_district').value != '')
    {
		$('localbodyloader').style.visibility = 'visible';

		var	params = 'action=LOAD_LOCAL_BODY&DISTRICT_ID='+ escape($('select_district').value)+'&LB_TYPE='+escape($('hiddenLbTypeForHs').value);
       // alert(params);
		new Ajax.Request(url,{method:"get",parameters:params,onSuccess:setLocalBodyNamesForHospital,onFailure:dispError})
	}else{
		return;
	}
}


function setLocalBodyNamesForHospital(reqObj)
{
    //alert(reqObj.responseText);
    if(reqObj.responseText=='')
        return false;
    else
        {
    $('localbody').update(reqObj.responseText);

    $('localbodyloader').style.visibility = 'hidden';
    return true;
        }
}

function deleteDetailofClient (clientId){

	Decision=confirm("Do you really want to delete the doctor from favourite list?");
	if(Decision){
		thisForm.txtWhat2Do.value='DELETEDOCTORS';
		$('clientId').value=clientId;
		thisForm.action	=	'patientfavoriteDoctors.php';
		thisForm.submit();
	}else{
		return;
	}
}

function jsloadAllDistrict(url,stype)
{
    var statevalue='';
    if(stype==1)
        {
       statevalue=$('state').value;
        $('districtloader1').style.visibility = 'visible';
            var load_dist='action=DISTRICT&STATE_ID='+statevalue;
   //alert(load_dist);
 	new Ajax.Request(url,{method:"get",parameters:load_dist,onSuccess:loadDistrictwise,onFailure:dispError})

       
        }
        else
            {
            statevalue=$('state_select1').value;

            $('districtloader1').style.visibility = 'visible';
       var load_dist='action=DISTRICT&STATE_ID='+statevalue;
   //alert(load_dist);
 	new Ajax.Request(url,{method:"get",parameters:load_dist,onSuccess:loadAllDistrict,onFailure:dispError})

            }
           

            
 
 

   	

}
// New function added by Jineesh Mani on 12.10.2009
function loadAllDistrict(reqObj)
	{
    
       $('select_district1').update(reqObj.responseText);
      
         $('districtloader1').style.visibility = 'hidden';
	}





function enableLbtypeForHospital(lbtype,url,stype)
{
    $('hiddenLbTypeForHs1').value=lbtype;


    loadLocalBodyForHsSearch(url,stype);


}
function  loadLocalBodyForHsSearch(url,stype)
{
  //  alert(url);
// alert($('hiddenLbTypeForHs').value);
var districttype='';
   if(stype==1)
{
 districttype= $('district').value;

}
else
    {
    
districttype=$('select_district1').value;
    }


    if ( districttype != '')
    {
		$('localbodyloader1').style.visibility = 'visible';

		var	params = 'action=LOAD_LOCAL_BODY&DISTRICT_ID='+ districttype+'&LB_TYPE='+escape($('hiddenLbTypeForHs1').value);
       // alert(params);
		new Ajax.Request(url,{method:"get",parameters:params,onSuccess:setLocalBodyNamesForHospitalSearch,onFailure:dispError})
	}else{
		return;
	}
}
function setLocalBodyNamesForHospitalSearch(reqObj)
{


   $('localbodyloader1').style.visibility = 'hidden';

    if(reqObj.responseText=='')
        return false;
    else
        {
    $('txtlocalbody1').update(reqObj.responseText);


    return true;
        }
}

function jsviewfields()
{

  $('district').style.display = 'block';


}


// New function aded on 09-11-2009 by Jinesh M Mani

function fncCancelAppointment(buttonid)
{
  if(confirm("Are you sure to cancel this appointment"))
      {
    $("appointid").value=buttonid.id;

thisForm.txtWhat2Do.value='CANCEL_APPOINTMENT';
thisForm.submit();
      }
      else
          return;
}


function __fncSearchClick(type)
{
    $("divdoctorsearch").style.display="none";
    $("divhospitalsearch").style.display="none";

    if(type==1)
        {
         $("divdoctorsearch").style.display="block";
        }
        else
            {
             $("divhospitalsearch").style.display="block";

            }

}

//new function added on 18_11_2009 by jinesh m and some function change


function loadDistrictwise(reqObj)
	{


        $('district').update(reqObj.responseText);
         $('districtloader1').style.visibility = 'hidden';
	}

    function fncPatientRegistrationpage()
    {

    window.location="clientregistration.php" ;
    }


// New functions added by   jinesh m on 20-11
function __fncAdvanceSearch()
{


    //thisForm.action='advancesearch.php';
    thisForm.txtWhat2Do.value='';
    window.location="advancesearch.php";

}



function fncAdvancehospitalSearch()
{
    if($("state_select1").value=='')
        {
            alert("Please select state in Hospital search");
            return;
        }

    thisForm.txtWhat2Do.value='HOSP_SEARCH';
    thisForm.submit();

}


     function searchHospitalbyAdmin()
    {

    thisForm.txtWhat2Do.value='HOSP_SEARCH';
thisForm.action="searchhospital.php ";
          thisForm.submit();
    }


    function editHospitalbyAdmin()
    {

   // alert("hai in searchHospitalbyAdmin");
    if( ( $('state_select').value=='') )
        {
            $('div3').style.display = 'block';
            $('div3').innerHTML="You must select a state";
           return false;
        }
    thisForm.txtWhat2Do.value='HOSP_SEARCH';

     thisForm.action='edithospital.php';

    thisForm.submit();

}

// New function added by  jinesh mani on 26-11-09

function __fncloadStreamwiseSpeciality(url)
{
      if ($("txtspecialitystream").value != '')
    {
        var stream=$("txtspecialitystream").value;
		$('streamloader1').style.visibility = 'visible';
       
		var	params ='action=STREAM&S_ID='+stream;
  
       new Ajax.Request(url,{method:"get",parameters:params,onSuccess:setStreamwiseSpeciality,onFailure:dispError})
		
	}


    else{
		return;
	}

}

function setStreamwiseSpeciality(reqObj)
{


   $('streamloader1').style.visibility = 'hidden';

    if(reqObj.responseText=='')
        return false;
    else
        {
    $('text_speciality').update(reqObj.responseText);


    return true;
        }
}

