//adc codes 2009-11

// JavaScript Document



function clearbox(selectId) {
	obj = document.getElementById(selectId);
	obj.options.length=0;
	}

function addOption(selectId, val, txt, selected) {
		var objOption = new Option(txt, val);
		objOption.selected = selected;
		
		 document.getElementById(selectId).options.add(objOption);
	}

function getResultCount()
{

var catid = document.getElementById('catid').value;
var searchkey = document.getElementById('searchkey').value;
var areaid = document.getElementById('areaid').value;
var apptdate = document.getElementById('apptdate').value;
var special = document.getElementById('SpecialtyID').value; 

var loading = document.getElementById('Loading');
loading.style.visibility = "visible";



window.setTimeout (function () { xajax_getResultCount(catid, searchkey, areaid, apptdate, special); }, 500);
}

function hiddenLoading()
{
var loading = document.getElementById('Loading');
loading.style.visibility = "hidden";
}

function onloadResult()
{
window.setTimeout (function () {getResultCount(); }, 1500);
}


function getResults(catid, searchkey, areaid, apptdate, special, nwstartday, pwstartday, language, insurance)
{
	var DoctorResults =  document.getElementById('DoctorResults'); 
	DoctorResults.innerHTML = "<div style='height:200px;'><p align=center>Loading<br><img src='http://www.doktoragit.com/images/loading.gif'></p></div>";
	xajax_getResults(catid, searchkey, areaid, apptdate, special, nwstartday, pwstartday, language, insurance);
}

function getAppointments(nwstartdate, pwstartdate)
{
	var Results =  document.getElementById('Results'); 
	Results.innerHTML = "<div style='height:200px;'><p align=center>Loading<br><img src='http://www.doktoragit.com/images/loading.gif'></p></div>";
	xajax_getAppointments(nwstartdate, pwstartdate);
}


function findY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

function findX(obj)
{
   var curleft = 0;
   if(obj.offsetParent)
   while(1) 
   {
      curleft += obj.offsetLeft;
      if(!obj.offsetParent)
         break;
      obj = obj.offsetParent;
   }
   else if(obj.x)
      curleft += obj.x;
   return curleft;
}

function newAppointment(linkid, stTime, EndTime, weekday, nwstartdate, pwstartdate)
{
	linkobj = document.getElementById(linkid);
	
	//alert(findY(linkobj));
	//alert(screen.availHeight);
	//alert(findY(linkobj) % screen.availHeight );
	
	obj = document.getElementById('PopDiv');
 obj.style.visibility = "visible";

	
	
	
	
	obj.innerHTML = "<div style='height:200px;'><p align=center>Loading<br><img src='http://www.doktoragit.com/images/loading.gif'></p></div>";

xajax_newAppointment(stTime, EndTime, weekday, nwstartdate, pwstartdate);
}

function showdeadcenterdiv(Xwidth,Yheight,divid) { 
// First, determine how much the visitor has scrolled

var scrolledX, scrolledY; 
if( self.pageYoffset ) { 
scrolledX = self.pageXoffset; 
scrolledY = self.pageYoffset; 
} else if( document.documentElement && document.documentElement.scrolltop ) { 
scrolledX = document.documentElement.scrollLeft; 
scrolledY = document.documentElement.scrolltop; 
} else if( document.body ) { 
scrolledX = document.body.scrollLeft; 
scrolledY = document.body.scrolltop; 
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY; 
if( self.innerHeight ) { 
centerX = self.innerWidth; 
centerY = self.innerHeight; 
} else if( document.documentElement && document.documentElement.clientheight ) { 
centerX = document.documentElement.clientWidth; 
centerY = document.documentElement.clientheight; 
} else if( document.body ) { 
centerX = document.body.clientWidth; 
centerY = document.body.clientheight; 
}

// Xwidth is the width of the div, Yheight is the height of the 
// div passed as arguments to the function: 
var leftoffset = scrolledX + (centerX - Xwidth) / 2; 
var topoffset = scrolledY + (centerY - Yheight) / 2; 
// the initial width and height of the div can be set in the 
// style sheet with display:none; divid is passed as an argument to // the function 
var o=document.getElementById(divid); 
var r=o.style; 
r.position='absolute'; 
r.top = topoffset + 'px'; 
r.left = leftoffset + 'px'; 
r.display = "block"; 
} 

function getAppointment(linkid, bookid, doctorid, nwstartdate, pwstartdate)
{
	linkobj = document.getElementById(linkid);

	//alert(findY(linkobj));

	obj = document.getElementById('PopDiv');
    obj.style.visibility = "visible";
	obj.style.top = findY(linkobj)+30+ 'px';
	obj.style.left = findX(linkobj)-250+ 'px';
	
	obj.innerHTML = "<div style='height:200px;'><p align=center>Loading<br><img src='http://www.doktoragit.com/images/loading.gif'></p></div>";

	xajax_getAppointment(bookid, doctorid, nwstartdate, pwstartdate);
}

function closeNewAppointment()
{
	obj = document.getElementById('PopDiv');
	obj.innerHTML = "";
    obj.style.visibility = "hidden";
}

function findPatient(keyword)
{
	comDetails = document.getElementById('patientlist');
	comDetails.innerHTML = "<div align=center><img src='http://www.doktoragit.com/images/loading.gif'></div>"; 	
	xajax_findPatient(keyword);
}

function cancelAppointment(bookingid, nwstartdate, pwstartdate)
{
		xajax_cancelAppointment(bookingid);
		closeNewAppointment();
		getAppointments(nwstartdate, pwstartdate);
}

function smsValidation()
{
	obj = document.getElementById('varMobile');
	xajax_smsValidation(obj.value);
}

function smsValidationCode()
{
	obj = document.getElementById('varMobileCode');
	xajax_smsValidationCode(obj.value);
}

function addAppointment(sonuc)
{
	if(sonuc == true)
	{
		var frm = document.frm_book;
		
		patientid = "";
		if(frm.patientid != null)
		patientid = frm.patientid.value;
		
		
		for (i=0; i < frm.rdo_booktype.length; i++)
	   	{
	   	if (frm.rdo_booktype[i].checked)
		  {
		  var booktype = frm.rdo_booktype[i].value;
		  }
	   	}

		txtpatientname = frm.txtpatientname.value;
		if (frm.txtpatientname.value == "")
			txtpatientname = frm.txtpatientname2.value;
		
		/*alert(
			"sttime"+frm.sttime.value+"\nendtime"+frm.endtime.value+"\nweekday"+
			frm.weekday.value+"\ndoctorid"+frm.doctorid.value+"\nrdo_booktype"+
			booktype+"\npatientid"+patientid+"\ntxtpatientname"+txtpatientname+"\ntxtpatientemail"+
			frm.txtpatientemail.value+"\ntxtotherreason"+frm.txtotherreason.value+"\ntxthealthcond"+
			frm.txthealthcond.value+"\ntxtsearch"+frm.txtsearch.value+"\nnwstartdate:"+frm.nwstartdate.value+
			"\npwstartdate"+frm.pwstartdate.value +"\ntxtvisitreason"+frm.txtvisitreason.value
			  );*/
		//alert(frm.txtvisitreason.value);
		xajax_addAppointment(frm.sttime.value, 
							 frm.endtime.value, 
							 frm.weekday.value, 
							 frm.doctorid.value, 
							 booktype, 
							 patientid, 
							 txtpatientname, 
							 frm.txtpatientemail.value, 
							 frm.txtotherreason.value, 
							 frm.txthealthcond.value, 
							 frm.txtsearch.value, 
							 frm.txtvisitreason.value);
		
		nwstartdate = frm.nwstartdate.value;
		pwstartdate = frm.pwstartdate.value;
		
		closeNewAppointment();
		getAppointments(nwstartdate, pwstartdate);
		
	
		
	}

}


