// JavaScript Document


//    function makeRequest(url,value_conteiner,name_c,type_d) {
    function GetDoctors(value_conteiner,name_c,type_d,type_sub_d,selected) {    	
        var http_request = false;
        var url = 'doctors.php' ; 
		
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Browser is not competible to for this page !');
            return false;
        }
		
        http_request.onreadystatechange = function() { alertContents(http_request,value_conteiner,selected); };
        url = url + '?ms=' + new Date().getTime();
        http_request.open('POST', url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		var post_st = 'name_c=' + name_c + '&type_d=' + type_d + '&type_sub_d=' + type_sub_d ;
		
//		alert(post_st) ;

        http_request.send(post_st);
		
//        http_request.open('GET', url, true);  
//        http_request.send(null);        
    }

    function alertContents(http_request,loc_sel,selected) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
				
            	var doctors_array = http_request.responseText.split('@@') ;
            	var doctor,single_option ,i ,j ;
        	    var x = loc_sel.form ;
				
			    x.m.value = "" ;
  		        x.m1.value = ""	;			
			
				
			    RemoveSelect(loc_sel,1) ;
			    doctors_details = [] ;
				
				if (isArray(doctors_array)){
                  for (i in doctors_array){

                    if ((doctors_array[i] != 'undefined') && (doctors_array[i] != '')){	
              	
                   	   doctor = doctors_array[i].split('@') ;
                       single_opiton = document.createElement('option') ;
                       
                       single_opiton.value = doctor[0] ;
                       single_opiton.text = unescape(doctor[1]) ;

                       if (doctor[0] == selected){
                       	  single_opiton.selected = true ;
                       }

                       if (single_opiton.text.indexOf("diese") != -1){ 
					      x.m.value = "Fur diese Kategorie haben wir momentan keine Daten."
 					      x.m1.value = "Wir bitten um  Entschuldigung!"
						  single_opiton.text = "-------------------------" ;
					   }
                       //if (single_opiton.value == 0 ){  single_opiton.text = "Fur diese Kategorie haben wir momentan keine Daten. Wir bitten um  Entschuldigung!" ; }
                       
					  doctors_details[doctor[0]] = new Array(doctor[2],doctor[3]) ;
                       
					   try {
					      loc_sel.add(single_opiton,null);
					   }
					   catch(ex) {
 					      loc_sel.add(single_opiton);					 
					   }
					  
                    }
                  }
				  
				  Fill_Info(document.details,document.details.doctors_choice);
				  
				}
      	
            } else {
                alert('There was a problem  while finding doctors for this city .');
            }
        }
    }
    
    
    function GetDoctors_Services(value_conteiner,doc_id,selected) {    	
        var http_request = false;
        var url = 'doctors_services.php' ; 
		
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Browser is not competible to for this page !');
            return false;
        }
		
        http_request.onreadystatechange = function() { alertContents_Services(http_request,value_conteiner,selected); };
        url = url + '?ms=' + new Date().getTime();
        http_request.open('POST', url, true);
        http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		var post_st = 'doc_id=' + doc_id ;
		
		//alert(post_st) ;

        http_request.send(post_st);
		
//        http_request.open('GET', url, true);  
//        http_request.send(null);        
    }

    function alertContents_Services(http_request,loc_sel,selected) {

        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
            	
            	var doctors_array = http_request.responseText.split('@@') ;
            	var doctor,single_option ,i ,j ;
		        var x = loc_sel.form ;
				
			    x.m2.value = "" ;
				
			    RemoveSelect(loc_sel,1) ;
				
				if (isArray(doctors_array)){
                  for (i in doctors_array){

                    if ((doctors_array[i] != 'undefined') && (doctors_array[i] != '')){	
              	
                   	   doctor = doctors_array[i].split('@') ;
                       single_opiton = document.createElement('option') ;
                       
                       single_opiton.value = doctor[0] ;
//                       alert(doctor[1]) ;
//                       alert(unescape(doctor[1])) ;
                       single_opiton.text = unescape(doctor[1]) ;

                       if (doctor[0] == selected){
                       	  single_opiton.selected = true ;
                       }

                       if (single_opiton.text.indexOf("Besuches") != -1){ 
					      x.m2.value = "Keine Daten! Bitte teilen Sie den Grund des Besuches unter Sonstiges mit !"
						  single_opiton.text = "-------------------------" ;
					   }
                       //if (single_opiton.value == 0 ){  single_opiton.text = "Fur diese Kategorie haben wir momentan keine Daten. Wir bitten um  Entschuldigung!" ; }
                       
					  
					   try {
					      loc_sel.add(single_opiton,null);
					   }
					   catch(ex) {
 					      loc_sel.add(single_opiton);					 
					   }
					  
                    }
                  }
				}
      	
            } else {
                alert('There was a problem  while finding doctors for this city .');
            }
        }
    }    

    
    function isArray(obj){
       if(isNaN(obj.size)){
           return true;
       }
       else if(obj.size == 0){
           return false;
       }
    }
    
    function RemoveSelect(loc_sel,first_row){
       var single_option ;
		
       if (loc_sel.length != 0){
		 var count =  loc_sel.length - 1 ;
		 for (j=count; j >= 0 ; j--){
		     loc_sel.remove(j) ;
		 }
	   }
   
	   
	   if (first_row == 0){
	   
         single_opiton = document.createElement('option') ;
         single_opiton.value = 0 ;
         single_opiton.text = " ------------------------- " ; 
       
         try {
		    loc_sel.add(single_opiton,null);
	     }
	     catch(ex) {
 		    loc_sel.add(single_opiton);					 
	     }       
	   }
    }
    
    function RemoveCity(loc_txt){
	   loc_txt.value = "" ;
	   
	   var x = loc_txt.form ;
	   x.versicher.value = "" ;  
       x.behandlung.value = "" ;  

    }
    
  	function ChangeDirection(form,direction){
	   form.action = direction ;
	   form.submit() ;
	} 
	
	function ChangeOnlyDirection(form,direction){
	   form.action = direction ;
	} 
	
	function SetValue(obj,val){
	    obj.value = val ;
	}
	
	function collectinfo(my,infoplace,operationtype){

       var stname = "" ;
       var i,result,tempresult,delch,usech,textvalue;

     result = "" ;


	 for (i=0;i < my.elements.length ;i++){
		//alert (my.elements[i].name)
		
		if (my.elements[i].type == "text" && my.elements[i].name != "new_element_name"){
			stname = my.elements[i].name ;
			tempresult = ""; 
			textvalue = my.elements[i].value ;
			
            if (my.elements[i+1].checked){ delch = "1"; textvalue = "x" } else { delch = "0" ; }	
//            if (my.elements[i+2].checked){ usech = "1"; } else { usech = "0" ; }	
             
			tempresult = tempresult + stname.substring(4) + "/#/" + delch + "/#/" + textvalue + "/##/" ;                          
///		tempresult = tempresult + stname.substring(4) + "/#/" + delch + "/#/" + usech + "/#/" + textvalue + "/##/" ;                          			

			result = result + tempresult ;
			i = i + 1;
//			i = i + 2;			
		}		 
     }
    
     result = result.substring(0,result.length-4);  
    
     infoplace.value = result ;  
     //operationtype.value = 4 ;
    }
    
    function myget(loc_form,infoplace){
	
       var result = "" ;
       var stname = "" ;
       var check_ind ;       


         for (var j=0;j < loc_form.length; j++){
            if (loc_form.elements[j].type == "checkbox"){
                if (loc_form.elements[j].checked){ check_ind = 1 ; }
                else{ check_ind = 0 ; } ;
                	
     	        stname = loc_form.elements[j].name + check_ind ;
     	       
     	        result += stname.substring(6)  + ',' ;
	        }
         }
  
         infoplace.value = result.substring(0,result.length-1); 
       }
	   
	   
	 function show_doc_details(doc_details){
	   var doc = doc_details.options[doc_details.selectedIndex].value ;		
        if (doc != 0){
			
           window.open( "doc_details.php?doc=" + doc, "myWindow", 
            "status = 1, left = 120, height = 425, width = 575, resizable = 0" )			
		}	
	 }  
	 
	 function show_doctors_change(doc_details){
	   		  
         var vWinTree = window.open( "doctors_change.php?" + doc_details, "myWindow",
            "status = 1, left = 120, height = 150, width = 614, resizable = 0" ) ;
		 
	     vWinTree.opener = self ;  
	 }  
	 
	 function show_doctors_write_reason(chb,doc_details){
	 	
	 	var kk ;

        kk = 'reason' + chb.name.substring(6) ;        
 		
        doc_details = doc_details+ '&chbn=' + kk ;  
	 	
	 	
	 	if (chb.checked) {
          var vWinTree = window.open( "doctors_reason.php?" + doc_details, "myWindow",
            "status = 1, left = 120, height = 125, width = 314, resizable = 0" ) ;
		 
	      vWinTree.opener = self ; 
		
	 	}
	 	else{
          Set_Visibile(document,kk,'.style.visibility',"'hidden'") ;	 		
	 	}  
	 }  	 
	 	 	 
	 function free_hours_check(chb, doc){
	 	
		var i, j, chb_array, stname ;

		if (chb.checked == true){
			
  		  chb_array = document.getElementsByTagName("input") ;
		 
		
		  for (i=0;i < chb_array.length;i++){
		  	
			  stname = chb_array[i].name ;
			  j = stname.length - 2 ;

			  
			  if ((chb_array[i].type == "checkbox") && (stname.substring(j) == "_d")){
			//  alert(stname.length + '   ' + j + '  ' + stname.substring(j) + '   ' + chb_array[i].type) ;			  	
			  	  chb_array[i].checked = true ;
			  }
			
		  }
		}
	 }
	 
	 
     function myreload(){
         window.opener.location.reload() ;   
     }	 
     
     
     function Fill_Info(f,sel){
 
     	var i = sel.options[sel.selectedIndex].value ;

		f.versicher.value = doctors_details[i][0] ;
		f.behandlung.value = doctors_details[i][1] ;
     	
     	
     }
     
     function Set_Visibile(doc,id,my_property,status){
     	var el, ev ; 
     	
        if (doc.getElementById) {
          el = doc.getElementById(id);
        } else if (document.all) {
          el = doc.all[id];
        }     
        
        ev = 'el' + my_property + "=" + status + ";" ;
      
        eval(ev) ;
        
  //     el.style.visibility = status ;
     	
     }
     
     
     function Update_Reason(doc,id,txt){
     	
     	var status, current_txt ; 
     	
       
     	if (txt.value == '') {
     	   status = "'hidden'" ;	
 	       current_txt = "'0'" ;
     	}
     	else{
           status = "'visible'" ;	     		
 	       current_txt = "'" + txt.value + "'" ;           
     	}
     	
 	      Set_Visibile(doc,id,'.style.visibility',status) ;
	      Set_Visibile(doc,id + '_h','.value',current_txt) ;     		
    	
     }     

