
var bodyparts="Empty";
var id_bodyparts="";
var title_bodyparts="";
/*
function selectProcedure(){
    if(document.getElementById("s_procedures").value!=""){
        ajax(SELF_URL+"getLocations_ajax?id_procedure="+document.getElementById("s_procedures").value,on_selectProcedure);
    }
    document.getElementById("i_procedure").value=document.getElementById("s_procedures").value;
}
function on_selectProcedure(result){

	byid("d_locations").innerHTML=result.locations;
	//replacecurrentSelect(1,byid("s_locations"));

	if(result.id_procedure==2){
		jQuery.fn.nyroModalManual({
		content: result.bodyparts,
		width : (document.all ? 580 : 580),
		closeButton:'',
		height :  (document.all ? 396 : 395)
		});
	}
	else{
	  document.getElementById("d_bodyparts").style.display="none";
		document.getElementById("d_bodyparts").innerHTML="";
	}
}

function bodypartssave(){
	var parts_id="";
	var parts_title="";
	var numchecked=0;
	var count=document.getElementById("bp_i_count").value;
	document.getElementById("bodyparts").innerHTML;

	for(var i=0;i<count;i++){
		if(document.getElementById("part_"+i).value){
			if(document.getElementById("part_"+i).checked){
				parts_id=parts_id+","+document.getElementById("id_bodypart_"+i).value;
				parts_title=parts_title+", "+document.getElementById("title_bodypart_"+i).value;
			}
		}
	}

	if(parts_title.length>2){
		title_bodyparts=parts_title=parts_title.substr(2);
		id_bodyparts=parts_id=parts_id.substr(1);

		if(parts_title.length>24)
			parts_title=parts_title.substr(0,24)+"... ";
		else
			parts_title=parts_title+" ";
	}

	document.getElementById("d_bodyparts").innerHTML=parts_title+"<a href='javascript:chbodypart()'>change part</a>";
	document.getElementById("d_bodyparts").style.display="block";
	jQuery.nyroModalRemove();
}

function chbodypart(){
	ajax(SELF_URL+"chbodypart_ajax?id_bodyparts="+id_bodyparts,on_chbodypart);
}

function on_chbodypart(result){
	jQuery.fn.nyroModalManual({
	content: result.bodyparts,
		width : 580,
		closeButton:'',
		height : 395
	});
}

function selectLocation(){
	document.getElementById("i_location").value=document.getElementById("s_locations").value;
	ajax(SELF_URL+"setCalendar_ajax?id_procedure="+document.getElementById("i_procedure").value+"&id_city="+document.getElementById("i_location").value,on_selectLocation);
}

function on_selectLocation(result){
	$.datepicker.setDefaults($.datepicker.weekNamesMin=result);
}

function selectDate(wk){
	ajax(SELF_URL+"getTimes_ajax?id_wk="+wk+"&id_procedure="+document.getElementById("i_procedure").value+"&id_city="+document.getElementById("i_location").value,on_selectDate);
	document.getElementById("i_week").value=wk;
}
function on_selectDate(result){
	byid("d_times").innerHTML=result.responseText;
	//replacecurrentSelect(2,byid("s_times"));
}
function selectTime(){
    document.getElementById("i_time").value=document.getElementById("s_times").value;
}

function selectPContact(){
    document.getElementById("i_contact").value=document.getElementById("s_pcontacts").value;
}

function selectHdyhau(){
	if(document.getElementById("s_hdyhaus").value==""){
		document.getElementById("d_hdyhau").innerHTML="";
		document.getElementById("i_hdyhau").value="";
	}
	else{
		ajax(SELF_URL+"getHdyhau_ajax?id_hdyhau="+document.getElementById("s_hdyhaus").value,"d_hdyhau");
		document.getElementById("i_hdyhau").value=document.getElementById("s_hdyhaus").value;
	}
}
*/
function submit_bf(){
return submit();
}
//send bookapp request
function submit(){
    $("#i_name").validate.init(byid("i_name"));
    $("#i_email").validate.init(byid("i_email"));
    $("#i_phone").validate.init(byid("i_phone"));
    $("#i_procedure").validate.init(byid("i_procedure"));
    $("#i_location").validate.init(byid("i_location"));
    $("#i_patient_type").validate.init(byid("i_patient_type"));
    var i_name=$("#i_name").val();
    var i_email=$("#i_email").val();
  	var i_phone=$("#i_phone").val();
    var i_procedure=$("#i_procedure").val();
    var i_location=$("#i_location").val();
    var i_patient_type=$("#i_patient_type").val();    

    /*if(i_name=="" || i_email=="" || i_phone=="" || i_procedure=="" || i_location=="" || i_patient_type=="")
    */
    if ($("div#shedule_box .error").length>0)
    {
        alert("Error! Please fill all the required fields.");
        return false;
    }
    
    ajax(BASEURL+"bookapp/submit_ajax?name="+i_name+"&email="+i_email+"&phone="+i_phone+"&id_procedure="+i_procedure+"&id_location="+i_location+"&patient_type="+i_patient_type,on_bookapp_submit_top);
}

function on_submit(result){
	window.location=FULLURL+"bookappthanks";
}

function filter_by_proc(procid){
    ajax(SELF_URL+"get_filtered_ajax/"+procid,filter_ajax);
}

function filter_ajax(result){
	var cont=$("bookapp_table");
	cont.innerHTML=result.responseText;
}