var gBajax = createRequest();

function createRequest() {
	var obj;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        obj = new XMLHttpRequest();
    }
    return obj;
}

/***********************************************************
* select folder in rte_image pop-up window
***********************************************************/
function selectedDate(ele) {
	var serviceDate = ele.value;
	
	if (serviceDate)
	{
		gBajax.open('get','ajax.php?id='+serviceDate);
		gBajax.onreadystatechange = selectedDateResponse;
		gBajax.send(null);
	}
	else
	{
		document.getElementById('service_time').style.display = "none";	
	}
}
function selectedDateResponse() {
	if(gBajax.readyState == 4){
		// this is the content of the called page
        var response = gBajax.responseText;

       	//process the response
       	if( response ) {
       		document.getElementById('service_time').innerHTML = response;
       		document.getElementById('service_time').style.display = "block";	
       	}
    }
}


function loadCalendar(direction) {
	
	var month = parseInt(currMonth);
	var year = parseInt(currYear);
	
	if (direction=="next")
	{
		if (month==12)
		{
			month = 1;
			year = parseInt(year)+1;
		}
		else
		{
			month = parseInt(month)+1;			
		}
		
	}
	else
	{
		if (month==1)
		{
			month = 12;
			year = parseInt(year)-1;
		}
		else
		{
			month = parseInt(month)-1;
		}		
	}
	//alert('ajax.php?m='+month+'&y='+year);
	gBajax.open('get','ajax.php?m='+month+'&y='+year);
	gBajax.onreadystatechange = loadCalendarResponse;
	gBajax.send(null);
	
}
function loadCalendarResponse() {
	if(gBajax.readyState == 4){
		// this is the content of the called page
        var response = gBajax.responseText;
        
       	//process the response
       	if( response ) {
       		//alert(response);
       		var arrResponse = response.split('~|~');
       		document.getElementById('cal_1').innerHTML = arrResponse[0];
       		document.getElementById('cal_2').innerHTML = arrResponse[1];
       		document.getElementById('cal_3').innerHTML = arrResponse[2];
       		currMonth = arrResponse[3];
       		currYear = arrResponse[4];
       		date = document.getElementById('appointment_date').value;
       		markDay(date);
       	}
    }
}

function scheduleSelected(scheduleId, timeSelected) {
	
	timeSelected = timeSelected.replace(" ", "_");
	timeSelected = timeSelected.replace(":", "_");
	
	//alert('ajax.php?action=time&s='+scheduleId+'&t='+timeSelected);
	gBajax.open('get','ajax.php?action=time&s='+scheduleId+'&t='+timeSelected);
	gBajax.onreadystatechange = scheduleSelectedResponse;
	gBajax.send(null);
	
}

function scheduleSelectedResponse() {
	if(gBajax.readyState == 4){
		// this is the content of the called page
        var response = gBajax.responseText;
        
       	//process the response
       	if( response ) {
       		//alert(response);
       		var arrResponse = response.split('~|~');
       		
       		document.getElementById('lightboxContent').innerHTML = arrResponse[0];
       		
       		if (!arrResponse[1])
       		{
       			document.getElementById("appt_time").innerHTML = '';
				document.getElementById('appointment_time').value = '';
       		}
       	}
    }
}