function attachFile(url) {
    var newwin = window.open(url, 'Attach', 'resizable=no,scrollbars=yes,left=180,top=180,width=420,height=210');
    newwin.focus();
}

function closeWindow(Ourl) {
    window.opener.showAttachments(Ourl)
    window.close()
}

function showAttachmentsDivision(Ourl) {
       showAttachments(Ourl)
}

function hideAttachmentsDivision(Ourl) {
   var  attachdiv = document.getElementById("AttachDiv");	
   while(attachdiv.childNodes.length){
       	attachdiv.removeChild(attachdiv.firstChild);
   } 
}

function showAttachments(Ourl) {   
    if (window.XMLHttpRequest) {
        httpReqAttach = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject){
    //for IE5 and IE6
         httpReqAttach = new ActiveXObject("Microsoft.XMLHTTP");
    }
    httpReqAttach.open("GET", Ourl, true);
    httpReqAttach.onreadystatechange = stateChangeAttach;
    httpReqAttach.send(null);
}

function stateChangeAttach(){
    if (httpReqAttach.readyState == 4) { 
       showResultAttach(httpReqAttach.responseText);
    }
}

function showResultAttach(result) {
    var attachdivnew = document.getElementById("AttachDiv").hasChildNodes();
    var newdiv = document.createElement("div");
    newdiv.innerHTML = result; 
    newdiv.setAttribute('id', 'attachlist');
    var  attachdiv = document.getElementById("AttachDiv");	
    if(attachdivnew==true){
    	while(attachdiv.childNodes.length){
        	attachdiv.removeChild(attachdiv.firstChild);
        } 
    }
    attachdiv.appendChild(newdiv);
}

function uploadFileForm(action, Ourl) {
   if(action=='upload_appointmentattachment') {
         if(document.upload_form.attachment.value.lastIndexOf(".pdf")>=0 || document.upload_form.attachment.value.lastIndexOf(".doc")>=0) {
             document.upload_form.button_value.value='upload_appointmentattachment';
          }
         else {
              alert("Only PDF or DOC files can be uploaded");
              return false;
         } 
    }	    
    else {
        document.upload_form.button_value.value='';
    }
     
    document.upload_form.submit();
}

function deleteAttachmentForm(action, Ourl) {
    if(action=='delete_appointmentattachment') {
document.delete_attachment_form.button_value.value='delete_appointmentattachment';
    }	    
    else {
        document.delete_attachment_form.button_value.value='';
    }
     
    document.delete_attachment_form.submit();
    window.opener.showAttachments(Ourl);
    window.close();
}


function deleteAttachment(url) {
    var newwindow = window.open(url, 'Delete', 'resizable=no,scrollbars=yes,left=180,top=180,width=420,height=210');
    newwindow.focus();
}


function exportAllforDay(url, type, today_date) {
    URL = url+'/@@exportday_view?today_date='+today_date+'&type='+type;
    window.open(URL);
}


function exportAllforWeek(url, type, today_date) {
    URL = url+'/@@exportweek_view?today_date='+today_date+'&type='+type;
    window.open(URL);
}


function exportAllforMonth(url, type, today_date) {
    URL = url+'/@@exportmonth_view?today_date='+today_date+'&type='+type;
    window.open(URL);
}

function importForm(action) {
    if(action=='import_appointments') {
        document.import_appointments_form.button_value.value='import_appointments';
    }	    
    else {
        document.import_appointments_form.button_value.value='';
    }
     
    document.import_appointments_form.submit();
}

function refreshCategory(url, view, t_date, type) {
    if(view=='day') {
        URL=url+'/@@dayappointments_view?d_date='+t_date+'&type='+type;
    }
    else if(view=='week') {
        URL=url+'/@@weekappointments_view?d_date='+t_date+'&type='+type;
    }
    else if(view=='month') {
        URL=url+'/@@monthappointments_view?d_date='+t_date+'&type='+type;
    }
    else {
        URL=url+'/@@dayappointments_view?d_date='+t_date+'&type='+type;
    }
    window.location=URL
}



function callShowSharingDivision(Ourl, actionType) {
    var spinner=document.getElementById('loading');
    spinner.style.display='inline';
    document.getElementById('actionType').value=actionType;
    Ourl = Ourl+'?actionType='+actionType;
    showSharingDivision(Ourl);
}

function showSharingDivision(Ourl) {   
    if (window.XMLHttpRequest) {
        httpReqAttach = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject){
    //for IE5 and IE6
         httpReqAttach = new ActiveXObject("Microsoft.XMLHTTP");
    }
    httpReqAttach.open("GET", Ourl, true);
    httpReqAttach.onreadystatechange = stateChangeShare;
    httpReqAttach.send(null);
}

function stateChangeShare(){
    if (httpReqAttach.readyState == 4) { 
       showResultShare(httpReqAttach.responseText);
    }
}

function showResultShare(result) {
    var sharedivnew = document.getElementById("ShareDiv").hasChildNodes();
    var newdiv = document.createElement("div");
    newdiv.innerHTML = result; 
    newdiv.setAttribute('id', 'sharelist');
    var  sharediv = document.getElementById("ShareDiv");	
    if(sharedivnew==true){
    	while(sharediv.childNodes.length){
        	sharediv.removeChild(sharediv.firstChild);
        } 
    }
    sharediv.appendChild(newdiv);
    var spinner=document.getElementById('loading');
    spinner.style.display='none';
}


function showEmailDivision(Ourl) {   
    if (window.XMLHttpRequest) {
        httpReqAttach = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject){
    //for IE5 and IE6
         httpReqAttach = new ActiveXObject("Microsoft.XMLHTTP");
    }
    httpReqAttach.open("GET", Ourl, true);
    httpReqAttach.onreadystatechange = stateChangeEmail;
    httpReqAttach.send(null);
}

function stateChangeEmail(){
    if (httpReqAttach.readyState == 4) { 
       showResultEmail(httpReqAttach.responseText);
    }
}

function showResultEmail(result) {
    var emaildivnew = document.getElementById("emailDiv").hasChildNodes();
    var newdiv = document.createElement("div");
    newdiv.innerHTML = result; 
    newdiv.setAttribute('id', 'emaillist');
    var  emaildiv = document.getElementById("emailDiv");	
    if(emaildivnew==true){
    	while(emaildiv.childNodes.length){
        	emaildiv.removeChild(emaildiv.firstChild);
        } 
    }
    emaildiv.appendChild(newdiv);
}



function showSMSDivision(Ourl) {   
    if (window.XMLHttpRequest) {
        httpReqAttach = new XMLHttpRequest();
    } 
    else if (window.ActiveXObject){
    //for IE5 and IE6
         httpReqAttach = new ActiveXObject("Microsoft.XMLHTTP");
    }
    httpReqAttach.open("GET", Ourl, true);
    httpReqAttach.onreadystatechange = stateChangeSMS;
    httpReqAttach.send(null);
}

function stateChangeSMS(){
    if (httpReqAttach.readyState == 4) { 
       showResultSMS(httpReqAttach.responseText);
    }
}

function showResultSMS(result) {
    var smsdivnew = document.getElementById("smsDiv").hasChildNodes();
    var newdiv = document.createElement("div");
    newdiv.innerHTML = result; 
    newdiv.setAttribute('id', 'smslist');
    var  smsdiv = document.getElementById("smsDiv");	
    if(smsdivnew==true){
    	while(smsdiv.childNodes.length){
        	smsdiv.removeChild(smsdiv.firstChild);
        } 
    }
    smsdiv.appendChild(newdiv);
}


