/*
c. jeremy van winkle. 2008 - brothers van winkle  -> www.brothersvanwinkle.com
*/



   /*
AJAX c. jeremy van winkle. 2008 - brothers van winkle  -> www.brothersvanwinkle.com
*/

 
function ajaxFunction(func,url,post){
        var img_Http;
        try {
            // Firefox, Opera 8.0+, Safari
            img_Http=new XMLHttpRequest();
            }
        catch (e){
            // Internet Explorer
            try {
                img_Http=new ActiveXObject("Msxml2.XMLHTTP");
                }
              catch (e){
                    try {
                    img_Http=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                catch (e){
                    alert("error: please update your browser, in order to get full use of this website.");
                    return false;
                    }
                }
              }
             
                           
       
      img_Http.onreadystatechange=function(){   
        if(img_Http.readyState==4){
                    if(func === "retreive_password"){   
                        alert(img_Http.responseText);
                    //END RETREIVE PASSWORD
                    }else if(func === "post_note"){   // POST NOTE
                        if(img_Http.responseText ==="0"){
                            alert('your note did not post properly. please try again.');
                            }else{
                            //alert(img_Http.responseText);  
                                 var repsonse= img_Http.responseText.split("^^^^"); 
                                 var new_note_by = repsonse[0];
                                 var new_note_date= repsonse[1];
                                 var new_note= repsonse[2];  
                                 var new_note_id= repsonse[3];      
                                 var div_notes = document.getElementById("note_list");
                            var old_notes = div_notes.innerHTML;      
                            var added_note = "<table id=\"note_display\"><tr><td class=\"note_details_0\">\n<span class=\"note_from\">"+new_note_by+"</span><BR><span class=\"note_created\">"+new_note_date+"</span>\n</td>\n<td class=\"note_spacer\"> &nbsp;  &nbsp;</td>\n<td class=\"note_0\"><div id=\""+new_note_id+"\">"+new_note+"</div></td>\n<td class=\"edit_note\"><a href=\"#\">edit</a> | <a href=\"#\">completed</a></td></tr></table>\n"; 
                            var new_content =  added_note+"\n"+old_notes;
                            document.getElementById("note_list").innerHTML = new_content;
                            document.getElementById("notes_input").innerHTML = "";
                            document.getElementById("notes_input").value = "";
                            
                            window.location.reload(true);
                            window.opener.location.reload(true);
                            } 
                    //END POST NOTE           
                    }else if(func === "complete_note"){      // COMPLETE BOARD
                        if(img_Http.responseText == '1'){
                            alert('changes to your note did not post properly. please try again.');
                            }else if(img_Http.responseText == '4'){
                            //alert('11 again.');  
                            }else {                        
                            alert(img_Http.responseText); 
                            window.location.reload(true);
                            window.location.reload(true);
                            window.opener.location.reload(true);
                            }
                    //END EDIT NOTE              
                    }else if(func === "download_file"){ 
                          if(img_Http.responseText == '4'){  
                            alert(''); 
                          }  
                    //END DOWNLOAD FILE 
                    }else if(func === "upload_file"){ 
                          window.location.reload( true );
                          if(img_Http.responseText == '4'){  
                            alert(''); 
                          }  
                    //END UPLOAD FILE 
                    }else if(func === "delete_file"){ 
                          window.location.reload( true );
                          if(img_Http.responseText == '4'){  
                            alert(''); 
                          }  
                    //END DELETE FILE 
                    }else if(func === "delete_project_file"){ 
                          if(img_Http.responseText == '4'){  
                            alert('could not delete file'); 
                          } else {                        
                            //alert(img_Http.responseText);
                            window.location.reload( true ); 
                          }    
                    //END DELETE PROJECT FILE 
                    }else if(func === "move_project_file"){ 
                          if(img_Http.responseText == '4'){  
                            alert('could not move file'); 
                          } else {                        
                            //alert(img_Http.responseText);
                            window.location.reload( true ); 
                          }    
                    //END MOVE PROJECT FILE 
                    }else if(func === "addframes_to_board"){    // ADD FRAMES  
                        if(img_Http.responseText == '1'){
                            alert('error: frames could not be added. please try again.');
                        }else {                        
                            //alert(img_Http.responseText);
                            window.location.reload( true ); 
                        }   
                    //END ADD FRAMES TO BOARD              
                    }else if(func === "rollback_frame"){    // ROLLBACK FRAMES    
                        if(img_Http.responseText == '1'){
                            alert('error 326: could not rollback frame.');
                            }else if(img_Http.responseText == '2'){
                            alert('error 327: there was an error while trying to rollback the frame. please consult the site administrator for further help.');
                            }else{                          
                            //alert( img_Http.responseText );
                            window.location.replace( img_Http.responseText );
                            //alert('frame has been switched to older version. if page does not reload correctly, please close the window, refresh the parent window, and reopen this frame.') 
                            }   
                    //END ROLLBACK FRAMES             
                    }else if(func === "change_frame_approval_status"){    // change_frame_approval_status
                        if(img_Http.responseText != 'success'){
                            alert( img_Http.responseText );
                            }else{
                            window.location.reload();
                            window.opener.location.reload();
                            //alert('frame has been switched to older version. if page does not reload correctly, please close the window, refresh the parent window, and reopen this frame.') 
                            }   
                    //change_frame_approval_status
                    }else if(func === "change_frame_approval_status2"){    // change_frame_approval_status2
                        var response = img_Http.responseText.split("^^^^");
                        if(response[0] != '1'){
                            alert( 'error' ); 
                            alert( img_Http.responseText );
                        }else{                   
                            if ( document.getElementById('blockingApprovalIcon') != null){
                                document.getElementById('blockingApprovalIcon').src = response[1];
                            }               
                            if ( document.getElementById('pencilApprovalIcon') != null){
                                document.getElementById('pencilApprovalIcon').src = response[2];
                            }               
                            if ( document.getElementById('colorApprovalIcon') != null){
                                document.getElementById('colorApprovalIcon').src = response[3];
                            }
                            if ( document.getElementById('revisionApprovalIcon') != null){
                                document.getElementById('revisionApprovalIcon').src = response[4];
                            }     
                            if ( document.getElementById('blockingApprovalText') != null){
                                document.getElementById('blockingApprovalText').style.color = response[5];
                            }               
                            if ( document.getElementById('pencilApprovalText') != null){
                                document.getElementById('pencilApprovalText').style.color = response[6];
                            }               
                            if ( document.getElementById('colorApprovalText') != null){
                                document.getElementById('colorApprovalText').style.color = response[7];
                            }
                            if ( document.getElementById('revisionApprovalText') != null){
                                document.getElementById('revisionApprovalText').style.color = response[8];
                            }
                            //window.location.reload();
                            if (window.opener != null){
                                window.opener.location.reload();
                            }                                                                                                                                  
                        }   
                    //change_frame_approval_status2
                    }else if(func === "rename_board"){    // RENAME BOARD
                        if(img_Http.responseText != 'success'){
                            alert( img_Http.responseText );
                            }else{
                            window.location.reload(true);
                            }   
                    //RENAME BOARD
                    }else if(func === "get_ai"){    // GET AI
                        if(img_Http.responseText == 'xx'){
                            alert( 'all users that can have an VS account have their accounts set up. if you feel there is an error, please contact the site administrator.'  );
                        }else if(img_Http.responseText == '0'){
                            alert( 'error 3820: unknown issues. this may not result in any problems, but if you notice anything not working correctyl, please contact a VS administrator.'  );
                        }else{
                            var response = img_Http.responseText.split("^^^^");
                            var fname = response[1];
                            var lname = response[2];
                            var street = response[3];
                            var city = response[4];
                            var state = response[5];
                            var zip = response[6];
                            var email = response[7]; 
                            var vsn = response[8]; 
                            document.getElementById('first_name').value = fname; 
                            document.getElementById('last_name').value = lname;
                            document.getElementById('street').value = street;
                            document.getElementById('city').value = city;
                            document.getElementById('state').value = state;
                            document.getElementById('zip').value = zip; 
                            document.getElementById('email').value = email;
                            if(vsn == "0"){             
                                document.getElementById('ssn1').value = '';
                                document.getElementById('ssn2').value = '';
                                document.getElementById('ssn3').value = '';
                            } else {
                                document.getElementById('ssn1').value = '000';
                                document.getElementById('ssn2').value = '00';
                                document.getElementById('ssn3').value = '0000';
                            }
                            document.getElementById('first_name').style.backgroundColor=null; 
                            document.getElementById('last_name').style.backgroundColor=null; 
                            document.getElementById('street').style.backgroundColor=null; 
                            document.getElementById('city').style.backgroundColor=null; 
                            document.getElementById('state').style.backgroundColor=null;
                            document.getElementById('zip').style.backgroundColor=null; 
                            document.getElementById('email').style.backgroundColor=null;
                            document.getElementById('ssn1').style.backgroundColor=null; 
                            document.getElementById('ssn2').style.backgroundColor=null; 
                            document.getElementById('ssn3').style.backgroundColor=null
                            }   
                    //GET AI      
                    }else if(func === "get_assignedItems"){    // Assigned Items      
                        if(img_Http.responseText == 'xx'){
                            alert( 'there are no assigned items for this artist.'  );
                                document.getElementById('InvoiceAssignedItems').innerHTML = '';
                            document.getElementById('InvoiceAssignedItemsContainer').style.display = 'none';                            
                        }else if(img_Http.responseText == '0'){
                            alert( 'error 3821: unknown issues. this may not result in any problems, but if you notice anything not working correctyl, please contact a VS administrator.'  );
                            document.getElementById('InvoiceAssignedItems').innerHTML = '';
                            document.getElementById('InvoiceAssignedItemsContainer').style.display = 'none';                            
                        }else{
                            //var response = img_Http.responseText.split("^^^^");
                            var tableData = img_Http.responseText;                         
                            if(tableData == ""){
                                document.getElementById('InvoiceAssignedItems').innerHTML = tableData;
                                document.getElementById('InvoiceAssignedItemsContainer').style.display = 'none';
                                //alert ('no');           
                            }else{          
                                document.getElementById('InvoiceAssignedItems').innerHTML = tableData;
                                var conatiner = document.getElementById('InvoiceAssignedItemsContainerBlock').style.display = 'block';           
                                //alert ('yes');
                            }
                        }   
                    //GET Assigned Items      
                    } else if(func === "get_selected_boards"){    // GET BOARDS
                        if(img_Http.responseText == '0'){
                            var i=1;        
                            while (i<=20){                 
                                var objSelect = document.getElementById('board_'+i);      
                                var t;
                                for(t=objSelect.options.length-1;t>=0;t--){
                                    objSelect.remove(t);
                                }
                                objSelect.options[objSelect.options.length] = new Option( "select a different project from above", 0);
                                i=i+1;
                            }
                            alert( 'error 3820: unknown issues. this may not result in any problems, but if you notice anything not working correctyl, please contact a VS administrator.'  );
                        }else if(img_Http.responseText == '1'){
                            var i=1;        
                            while (i<=20){                 
                                var objSelect = document.getElementById('board_'+i);      
                                var t;
                                for(t=objSelect.options.length-1;t>=0;t--){
                                    objSelect.remove(t);
                                }
                                objSelect.options[objSelect.options.length] = new Option( "select a different project from above", 0);
                                i=i+1;
                            }
                            alert( 'this project does not have any boards. please double check the project ID# you worked on.'  );
                        }else{
                            var response = img_Http.responseText.split("***");
                            var x;
                            var num;
                            var i=1;        
                            while (i<=20){                 
                                var objSelect = document.getElementById('board_'+i);      
                                var t;
                                for(t=objSelect.options.length-1;t>=0;t--){
                                    objSelect.remove(t);
                                }
                                objSelect.options[objSelect.options.length] = new Option( "select board", 0);
                                i=i+1;
                            }
                            var i=1;  
                            while (i<=20){

                                for (x in response){     
                                    //alert(response[x]);
                                    //exit;
                                    var board_info = response[x].split("^^^^");
                                    var board_id = board_info[0];
                                    var board_title = board_info[1];
                                    var objSelect = document.getElementById('board_'+i);
                                    objSelect.options[objSelect.options.length] = new Option( board_info[1], board_info[0]);

                                }                                
                                //document.getElementById('board_'+i).style.backgroundColor= 'yellow';
                                i=i+1;
                            }
                        }   
                    //END GET BOARDS      
                    } else if(func === "get_selected_board"){    // GET 1 BOARD
                        if(img_Http.responseText == '0'){   
                            var objSelect = document.getElementById('board');      
                            var t;
                            for(t=objSelect.options.length-1;t>=0;t--){
                                objSelect.remove(t);
                            }
                            objSelect.options[objSelect.options.length] = new Option( "select a different project from above", 0); 
                            alert( 'error 3820: unknown issues. this may not result in any problems, but if you notice anything not working correctyl, please contact a VS administrator.'  );
                        }else if(img_Http.responseText == '1'){                 
                            var objSelect = document.getElementById('board');      
                            var t;
                            for(t=objSelect.options.length-1;t>=0;t--){
                                objSelect.remove(t);
                            }
                            objSelect.options[objSelect.options.length] = new Option( "select a different project from above", 0); 
                            alert( 'this project does not have any boards. please double check the project ID# you worked on.'  );
                        }else{
                            var response = img_Http.responseText.split("***");
                            var x;
                            var num;                   
                            var objSelect = document.getElementById('board');      
                            var t;
                            for(t=objSelect.options.length-1;t>=0;t--){
                                objSelect.remove(t);
                            }
                            objSelect.options[objSelect.options.length] = new Option( "select board", 0);        
                            

                            for (x in response){     
                                //alert(response[x]);
                                //exit;
                                var board_info = response[x].split("^^^^");
                                var board_id = board_info[0];
                                var board_title = board_info[1];
                                var objSelect = document.getElementById('board');
                                objSelect.options[objSelect.options.length] = new Option( board_info[1], board_info[0]);

                            }                                
                            //document.getElementById('board').style.backgroundColor= 'yellow';
                        }   
                    //END GET 1 BOARDD     
                    } else if(func === "delete_in_itm"){    // DELETE IN ITM
                        if(img_Http.responseText == '0'){
                            alert( 'error 3025: item could not be deleted.' );
                            window.location.reload(true);
                        }else if(img_Http.responseText == '1'){
                            window.location.reload(true);
                        }   
                    // END DELETE IN ITM       
                    } else if(func === "rename_screen"){    // RENAME_SCREEN
                        if(img_Http.responseText == '0'){
                            window.location.reload(true);
                        }else {                           
                            alert(img_Http.responseText);
                        }   
                    // RENAME_SCREEN
                    }    else if(func === "delete_screen"){    // DELETE_SCREEN
                        if(img_Http.responseText == '0'){
                            window.location.reload(true);
                        }else {                           
                            alert(img_Http.responseText);
                        }   
                    // DELETE_SCREEN            
                    }   else if(func === "create_dl_pass"){    // CREATE_DL_PASS
                        if(img_Http.responseText == '1'){
                            alert ('failed to change password');
                        }else {                           
                            alert(img_Http.responseText);
                            window.location.reload(true);
                        }   
                    // CREATE_DL_PASS                 
                    }   else if(func === "get_agency_clients"){    // GET_AGENCY_CLIENTS
                        if(img_Http.responseText == '0'){
                            var objDiv = document.getElementById('select_agency_clients'); 
                            objDiv.innerHTML = "";
                            document.getElementById('select_agency_clients').style.display = 'none';
                        }else {                           
                            document.getElementById('select_agency_clients').style.display = 'block';  
                            var response = img_Http.responseText.split("***");
                            
                            var objDiv = document.getElementById('select_agency_clients'); 
                            objDiv.innerHTML = "";
                            var t = 0;
                            for (x in response){ 
                                var data = response[x].split("^^^");
                                var uid = data[0];
                                var uname = data[1];
                                t++;
                                objDiv.innerHTML += "<input type='checkbox' name='track_agency_clients_" + t + "' value='" + uid + "' /> " + uname + "<br/>"; 
                            }
                            objDiv.innerHTML += "<input type='hidden' name='client_tracker_count' value='" + t + "' />";
                            //document.getElementById('select_agency_clients').innerHTML = img_Http.responseText;
                            //document.write("<input type='text' name='coba" + objd + "'>"); objd++;

                        }   
                    // GET_AGENCY_CLIENTS                 
                    }     else if(func === "delete_invoice_item_x"){    // DELETE_INVOICE_ITEM_X
                        if(img_Http.responseText == '1'){      
                            if(window.opener == null){
                                window.location.reload(true);
                            }else{
                                window.close();       
                                window.opener.location.reload(true);
                            }
                        }else {     
                            alert('error could not delete item.');   
                        }   
                    // DELETE_INVOICE_ITEM_X                 
                    }   else if(func === "change_amount"){    // CHANGE_AMOUNT
                        if( img_Http.responseText != 0){     
                            var response = img_Http.responseText.split("^^^");
                            if(response[0]!= 1) {
                                alert('error could not change amount.');   
                                return;
                            }
                            //alert('amount was changed');
                            document.getElementById(response[1]).value = response[2] ;
                            //window.location.reload(true);
                        }else {     
                            alert('error could not change amount.');   
                        }   
                    // CHANGE_AMOUNT                 
                    }   else if(func === "update_invoice_display_notes"){    // UPDATE_INVOICE_DISPLAY_NOTES
                        if( img_Http.responseText != 0){     
                            var response = img_Http.responseText.split("^^^");
                            if(response[0]!= 1) {
                                alert('error could not update note.');   
                                return;
                            }
                            //alert('amount was changed');
                            var r = confirm("note has been changed to:  \n" + response[2] + "\n do you want to reload page?") ;
                            if (r==true){
                                window.location.reload(true);
                            }
                        }else {     
                            alert('error could not update note.');   
                        }   
                    // UPDATE_INVOICE_DISPLAY_NOTES                 
                    } else if(func === "validateProjectFileName"){    // VALIDATE PROJECT FILENAME                
                        if( img_Http.responseText == '0'){    
                            alert('OK');   
                        }else {     
                            alert('file already exists.');   
                        }   
                    // VALIDATE PROJECT FILENAME                
                    }  else if(func === "fetchNewAssignment"){    // BEGIN FETCH NEW ASSIGNMENT
                        if( img_Http.responseText == '0'){    
                            alert('error');   
                        }else {
                            var response = img_Http.responseText.split("^^^"); 
                            /*
                            alert(response[0]);
                            alert(response[1]);
                            alert(response[2]);
                            alert(response[3]);
                            */
                            if(document.getElementById(response[0]) != null){
                                document.getElementById(response[0]).innerHTML = response[1] ;
                            }
                            if(document.getElementById(response[2]) != null){
                                document.getElementById(response[2]).value = response[3] ;
                            }
                        }   
                    // END fetch New Assignment       
                    }  else if(func === "getTaskRate"){    // BEGIN getTaskRate
                        //alert (img_Http.responseText);
                        return img_Http.responseText;
                        if( img_Http.responseText == '0'){    
                            alert('error');   
                        }else {
                            var response = img_Http.responseText.split("^^^");         
                            document.getElementById(response[2]).innerHTML = roundNumber( response[1], 2); 
                            
                        }   
                    // END getTaskRate
                    } else if(func === "changeItemCompletion"){    // BEGIN changeItemCompletion
                        //alert (img_Http.responseText);
                        //return img_Http.responseText;
                        //alert(img_Http.responseText);
                        if( img_Http.responseText == '0'){    
                            alert('error');   
                        }else {
                            var response = img_Http.responseText.split("^^^"); 
                            var label = 'itemCompletion'+response[1];        
                            document.getElementById(label).value = response[0]; 
                            alert(response[2]);
                            return;  
                        }   
                    // END changeItemCompletion
                    }
                }
       }                                                                 
      if(post === '0'){
        img_Http.open("GET",url,true);  
        img_Http.send(null);  
        }else{                 
       //img_Http.open("POST",url,true);
       // img_Http.send(post);     
            img_Http.open("POST",url,true);
            img_Http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            img_Http.setRequestHeader("Content-length", post.length);
            img_Http.setRequestHeader("Connection", "close");
            img_Http.send(post); //here i wana send 2 parameters ie name and password
        }                       
          //alert(img_Http.setRequestHeader);


}
        
    
function retreive_password(){
        var submit = document.getElementById("user_input").value;
        if(submit !=null &&submit != ""){
            var prompt_submit=submit;
        } else{
            var prompt_submit="your_email@domain.com";  
        }
    var email=prompt("Please enter your email",prompt_submit);
    if (email!=null && email!=""){
        var url = "includes/modules/ajax/retreive_password.php?email="+email;
        var func = "retreive_password";
        document.getElementById("user_input").value = email;    
        ajaxFunction(func,url,'0');  
    }
}

  
function posting_note(){   
    var note_text = document.getElementById("notes_input").value;
    var note = addslashes(note_text.replace(/\n/g,"<br>"));
    //var note = note_text.replace(/\n/g,"<br>");
    var frame = document.getElementById("frame_id").value;    
    var user = document.getElementById("user_id").value;   
    var action = document.getElementById("action").value;
    
    var post = note  
        if(note!=null && note!="" ){ 
            //alert(note+frame+user+action);  
            //var url = "includes/modules/ajax/post_note.php?frame_id="+frame+"user_id="+user+"action="+action+"note="+note;
            var url = "includes/modules/ajax/post_note.php";
            var func = "post_note";
            var post = "frame_id="+frame+"&user_id="+user+"&action="+action+"&note="+note; 
                    //alert(url+" "+func);                                
            ajaxFunction(func,url,post);                       
        }else{       
        alert('you did not enter a note');
        }
}



function edit_note(element){
    var note_id = element;   
    var note_text = document.getElementById(element).innerHTML;   
    var url = "includes/modules/ajax/edit_note.php";
    var func = "edit_note";
    var post = "note_id="+note_id+"&note="+note_text;
    var url = "includes/modules/ajax/edit_note.php?"+post
    open_window(url,'600','400','_edit',1,0,0,0,0,0,1);   
           // ajaxFunction(func,url,post);    
}


function complete_note(element,user){
    var note_id = element;                      
    var url = "includes/modules/ajax/complete_note.php?note_id="+note_id+"&user_id="+user; 
    var func = "complete_note";                           
           ajaxFunction(func,url,'0');    
}


function select_date(element){
    var return_to = element;                      
    var url = "includes/modules/calendar_small.php?return="+return_to; 
    var func = "select_date";                 
    open_window(url,'200','200','_blank',1,0,0,0,0,0,1);            
          // ajaxFunction(func,url,'0');    
}

function select_date2(element){
    var return_to = element;                      
    var url = "../calendar_small.php?return="+return_to; 
    var func = "select_date";                 
    open_window(url,'200','200','_blank',1,0,0,0,0,0,1);            
          // ajaxFunction(func,url,'0');    
}
function select_date3(element){
    var return_to = element;                      
    var url = "includes/modules/calendar_small.php?return="+return_to; 
    var func = "select_date";                 
    open_window(url,'200','200','_blank',1,0,0,0,0,0,1);            
          // ajaxFunction(func,url,'0');    
}
function select_date_mod(element){
    var return_to = element;                      
    var url = "../calendar_small.php?return="+return_to; 
    var func = "select_date";                 
    open_window(url,'200','200','_blank',1,0,0,0,0,0,1);            
          // ajaxFunction(func,url,'0');    
}



function download_file(file){
   var url = "includes/modules/ajax/download_file.php?file_key="+file; 
   var func = "download_file";  
   //open_window(url,'10', '10', '_blank', '0','0','0','0','0','0','0') ; 
   window.location = url;                    
           //ajaxFunction(func,url,'0');   
}                                                                                                




function link_file(file){                                             
   window.location = file;        
}                                                                                                


function delete_file(file){
   var url = "includes/modules/ajax/delete_file.php?file_key="+file; 
   var func = "delete_file";  
   //open_window(url,'10', '10', '_blank', '0','0','0','0','0','0','0') ; 
   //window.location = url;                    
           ajaxFunction(func,url,'0');   
}                                                                                                

function delete_project_file(file){
   var url = "includes/modules/ajax/delete_project_file.php?file_key="+file; 
   var func = "delete_project_file";  
   //open_window(url,'10', '10', '_blank', '0','0','0','0','0','0','0') ; 
   //window.location = url;                    
           ajaxFunction(func,url,'0');   
}                                                                                                

function move_project_file(file){
   var url = "includes/modules/project_files/move_project_file.php?file_key="+file; 
   var func = "move_project_file";  
   open_window(url,'400', '400', '_blank', '0','0','0','0','0','1','1') ; 
   //window.location = url;                    
   //        ajaxFunction(func,url,'0');   
}                                                                                                


 function addframes(id){
    var url = "pop_up_index.php?page=addframes&b="+id;
    var func = "addframes_to_board";                      
    //ajaxFunction(func,url,'0');     
    open_window(url,'200','200','_addframes',1,0,0,0,0,0,1);   
    }

function rollback_frame(element, current_frame, frame_number, board_id, project_id) {
    var div =document.getElementById(element);
    if (div.value == '0'){
        alert(' please select a previous frame ');
    } else {         
        var url = "includes/modules/ajax/rollback_frame.php?filename_id="+div.value+"&frame_id="+current_frame+"&frame_number="+frame_number+"&board_id="+board_id+"&project_id="+project_id; 
        var func = "rollback_frame";                   
        ajaxFunction(func,url,'0');  
    } 
  }
              
             
                                      

function change_frame_approval(element,id) {
    var status =document.getElementById(element).value;            
    var url = "includes/modules/ajax/change_frame_approval_status.php?frame_id="+id+"&status="+status; 
    var func = "change_frame_approval_status";                   
    ajaxFunction(func,url,'0');
  }
              
                               

function change_frame_approval2(id,status) {            
    var url = "includes/modules/frameApproval/change_frame_approval_status.php?frame_id="+id+"&status="+status; 
    var func = "change_frame_approval_status2";                   
    ajaxFunction(func,url,'0');
  }
              
                                      

function rename_board(id,name) { 
    var new_name=prompt("Please enter a new board title", name);               
    new_name = new_name.replace(/ /, "_");
    var url = "includes/modules/ajax/rename_board.php?board_id="+id+"&new_name="+new_name; 
    var func = "rename_board";                   
    ajaxFunction(func,url,'0');       
  }
     
     
 
function get_ai_ajax(id){
    var acc = document.getElementById(id).value;
    var url = "includes/modules/ajax/get_ai.php?id="+acc; 
    var func = "get_ai";                   
    var ai = ajaxFunction(func,url,'0');
    
    var url2 = "includes/modules/ajax/get_assignedItems.php?id="+acc; 
    var func2 = "get_assignedItems";                   
    var assigneditems = ajaxFunction(func2,url2,'0');
}

function get_ui_ajax(id){
    var acc = document.getElementById(id).value;
    var url = "includes/modules/ajax/get_ui.php?id="+acc; 
    var func = "get_ai";                   
    var ai = ajaxFunction(func,url,'0');
}



function get_selected_boards(id){
    var acc = document.getElementById(id).value;
    var url = "includes/modules/ajax/get_selected_boards.php?id="+acc; 
    var func = "get_selected_boards";                   
    var ai = ajaxFunction(func,url,'0');

}

function get_selected_board(id,fl){
    var acc = document.getElementById(id).value;
    var url = fl+"?id="+acc; 
    var func = "get_selected_board";                   
    var ai = ajaxFunction(func,url,'0');

}

    
function delete_in_itm(id){
    //var acc = document.getElementById(id).value;
    var url = "includes/modules/ajax/delete_in_itm.php?id="+id; 
    var func = "delete_in_itm";                   
    var ai = ajaxFunction(func,url,'0');
}




function rename_screen(type,file,id){     
    var newname=prompt("Rename Video - type new name",file);
    if (newname!=null && newname!=""){
        var url = "includes/modules/ajax/rename_screen.php?id="+id+"&file="+file+"&type="+type+"&newname="+newname; 
        var func = "rename_screen";                   
        var ai = ajaxFunction(func,url,'0');
    }else{
        alert ('you must enter a new name to rename video');
    }
   

}


function delete_screen(type,file,id){     
    var deleten=confirm("are you sure you want to delete the video:  "+file);
    if (deleten == true){
        var url = "includes/modules/ajax/delete_screen.php?id="+id+"&file="+file+"&type="+type; 
        var func = "delete_screen";                   
        var ai = ajaxFunction(func,url,'0');
    }else{
        alert ('there was an error. video was not deleted.');
    }
}



function create_dl_pass(id,old){             
    if (old==""){    
        var newpass=prompt("type a password","");
    }else{
        var newpass=prompt("type a password",old);
    }
    if (newpass==null || newpass==""){        
        var newpass = "^*delete*^";
    }
    var url = "includes/modules/ajax/create_dl_pass.php?id="+id+"&dl_new_pass="+newpass;
    var func = "create_dl_pass";                   
    var ai = ajaxFunction(func,url,'0');   
}

function get_select_agency_clients(id){
    var agency = document.getElementById(id).value;  
    //if  (agency==null || agency=="--" || agency=="" || agency=='0'){
    if  (agency==null || agency=="--" || agency=="" ){
        var objDiv = document.getElementById('select_agency_clients'); 
        objDiv.innerHTML = null;
        objDiv.style.display = 'none';
        return;
    }else{
        var url = "includes/modules/ajax/get_agency_clients.php?agency="+agency;
        var func = "get_agency_clients";                   
        var ai = ajaxFunction(func,url,'0');
    }
                        
}






function delete_invoice_item_x(ix,ux,loc){               
    if (ix!=null && ix!=""){   
        var verify=confirm("Are your sure you want to delete this item? \nThis action is not reversable.");
        if (verify!=true){                                     
            return;
        }
                       
        if (ux==null){
            var ux = '';
        }
        if(loc == '1'){
            var url = "delete_invoice_item.php?ix="+ix+"&ux="+ux; 
        }else{
            var url = "includes/modules/ajax/delete_invoice_item.php?ix="+ix+"&ux="+ux; 
        }
        var func = "delete_invoice_item_x";                                     
        var ai = ajaxFunction(func,url,'0');
    }else{
        alert ('no item selected');
    }
}
   

function edit_invoice_item(id){               
    if (id!=null && id!=""){
        var url = "includes/modules/ajax/edit_invoice_item.php?id="+id; 
        //var func = "delete_invoice_item_x";                                     
        //var ai = ajaxFunction(func,url,'0');
        open_window(url, '1000', '250', 'edit_item', 0,1,0,0,0,1,1);
    }else{
        alert ('item not found');
    }
}

function edit_invoice_item2(ix,ux){               
    if (ix!=null && ix!=""){
        var url = "includes/modules/ajax/edit_invoice_artist.php?ix="+ix+"&ux="+ux;  
        open_window(url, '1000', '250', 'edit_item', 0,0,0,0,0,1,1);
    }else{
        alert ('item not found');
    }
}   


function change_amount(amount,id){    
    var new_amount=prompt("enter a new amount",amount);
    if (new_amount!=null && new_amount!="" && new_amount!=amount){
        if (id!=null && id!=""){
            var url = "includes/modules/ajax/change_amount.php?id="+id+"&cost="+new_amount; 
            var func = "change_amount";                   
            var ai = ajaxFunction(func,url,'0');
        }else{
            alert ('no item selected');
        }
    }
}
   
   

function update_invoice_display_notes(text,id){    
    var div = document.getElementById(text);
    var note = div.value;
    if (note==null || note==""){
        var note = div.innerHTML;   
        if (note==null || note == ""){
            var rx = confirm ("are you sure you want to delete this note?");
            if (rx==false){
                return;
            }
        }
        var note = "";   
    }     
    if (id!=null && id!=""){
        var url = "includes/modules/ajax/update_invoice_display_notes.php"; 
        var func = "update_invoice_display_notes";   
        var post = "id="+id+"&note="+note;                                  
        var ai = ajaxFunction(func,url,post);
    }else{
        alert ('no item selected');
    }  
}
   
function add_invoice_display_notes(id){  
    var note=prompt("enter a note","");  
    if (note!=null && note!="" ){
        if (id!=null && id!=""){
            var url = "includes/modules/ajax/update_invoice_display_notes.php"; 
            var func = "update_invoice_display_notes";    
            var post = "id="+id+"&note="+note;                                                   
            var ai = ajaxFunction(func,url,post);
        }else{
            alert ('no item selected');
        }
    } else{
        alert ('no note was entered');
    }
}
   
   
function validateProjectFileName (project_id){
    if (project_id!=null && project_id!="" ){
        var filename = document.getElementById('upload_file').value;
        var filetype = document.getElementById('file_type').value;
        if (project_id!=null && project_id!="" ){
            //alert(project_id + filename);
            var url = "ajax/validateProjectFileName.php"; 
            var func = "validateProjectFileName";    
            var post = "project_id="+project_id+"&filename="+filename+"&filetype="+filetype;                                                   
            var ai = ajaxFunction(func,url,post);
        }
    }
}

function downloadFrameFile (id,URL){                  
    var link = document.getElementById('frame_files_download').value;                  
    if (link!=null && link!="" ){                            
        var split = link.split("&&&");  
        var flink = split[0];
        var fname  = split[1];
        var downloadURL = URL+'downloadFrameFiles.php?id='+flink+'&name='+fname;    
        open_window(downloadURL,'100', '100', id, 0,0,0,0,0,0,1)
    }else{
        alert('no file was selected.')
    }
}

function uploadFrameFile (id, URL, board, project){              
    if (board == null) {
        var board = "";
    }                                         
    if (project == null) {
        var project = "";
    }           
    var downloadURL = URL+'&id='+id+'&board='+board+'&project_id='+project;    
    open_window(downloadURL,'400', '400', id, 0,0,0,0,0,1,1)    
}


function fetchNewAssignment(label, frameID, boardID, frameNumber, form){   
    if (label!=null && label!="" ){  
    //alert(label);            
    var upload_type = document.getElementById(label).value;  
    var url = "assignFrames/fetchNewAssignments.php?upload_type="+upload_type+"&frameID="+frameID+"&boardID="+boardID+"&frameNumber="+frameNumber+"&upload_form="+form; 
    var func = "fetchNewAssignment";                      
    var ai = ajaxFunction(func,url,'0');      
    }   
}


function editAssignFrame (id){              
    var URL = 'editAssignFrames.php?assignedID='+id;    
    open_window(URL,'1100', '300', id, 0,0,0,0,0,1,1)    
}

function select_frameRate(id,dir,task){              
    var URL = dir+'frameRatesForm.php?input='+id+'&task='+task;    
    open_window(URL,'400', '400', id, 0,0,0,0,0,1,1)    
}

function getTaskRate(cost, taskID, returnID){
     var url = "getTaskRate.php?cost="+cost+"&taskID="+taskID+"&returnID="+returnID; 
     var func = "getTaskRate";                      
     var ai = ajaxFunction(func,url,'0');     
}


function calculateTotals(input1ID, input2ID, returnRushID, returnTotalID, inputTask){   
     var cost =Number(document.getElementById(input1ID).value);   
     var rushRate =Number(document.getElementById(input2ID).value); 
     var taskID = document.getElementById(inputTask).value;    
     
     // get task rate            
     if (taskID!=null && taskID!="" && taskID!="0"){
         var TaskCost = getTaskRate(cost, '0', returnTotalID);                           
     }   
     rushRate = rushRate/100; 
     var rushCost = cost * rushRate;
     var total = cost + rushCost;   
     
     document.getElementById(returnRushID).innerHTML = roundNumber( rushCost, 2);
     document.getElementById(returnTotalID).innerHTML= roundNumber( total, 2);
     return;
}

function applyRatesToAll(i, frameCount){
    var artist = document.getElementById(i+'userID').value;
    var task = document.getElementById(i+'taskID').value;
    var dueDate = document.getElementById(i+'_date').value;
    var cost = Number( document.getElementById(i+'cost').value);
    var rushRateDisplay = Number( document.getElementById(i+'rushRate').value); 
    rushRate = Number( rushRateDisplay/100 ); 
    var rushCost = cost * rushRate;
    var total = cost + rushCost;
    //alert (total);
    i=1;   
    while (i<=frameCount){
        if(document.getElementById(i+'userID').value != null){
            document.getElementById(i+'_date').value = dueDate;
            document.getElementById(i+'userID').value = artist;
            document.getElementById(i+'taskID').value = task;
            document.getElementById(i+'cost').value = roundNumber( cost, 2);
            document.getElementById(i+'rushRate').value = rushRateDisplay;
            document.getElementById(i+'RushTotal').innerHTML = roundNumber( rushCost, 2);
            document.getElementById(i+'Total').innerHTML = roundNumber( total, 2 );  
            i++;
        }
    }      
}

function checkAllApprove(i){
    var e = 0;   
    while (e<=i){ 
        if (document.getElementById(e+'approve') != null ){
            document.getElementById(e+'approve').checked = true;
        }
        e++;
    }
}

function paidView(URL,id){
    if(parseInt(id)==3){     
        open_window(URL,'400','200','pop_up',1,0,0,0,1,1,1);
    }else{
        js_redirect(URL);  
    }
}

function displayTypeView(id,URL){  
    if(parseInt(id)==0){ 
        js_redirect(URL);     
    }else if(parseInt(id)==837){   
        var r=confirm("your are about to view ALL Invoiced Items. \nThis may take a few minutes to load. \nDo you still wish to continue?");
        if (r==true){    
            js_redirect(URL);     
        }
    }else if(parseInt(id)>=1){
        open_window(URL,'400','400','pop_up',1,0,0,0,1,1,1);  
    }else{
        js_redirect(URL);  
    }   
}

function changeAssignmentCompletion(id,element,dir){
    var completion = document.getElementById(element).value;
    //alert(completion);
    if(parseInt(completion)==0){
        var URL = dir+'includes/modules/ajax/changeItemCompletion.php?id='+id+'&completion='+completion;
        //return;
    }else if(parseInt(completion)==1){
        var URL = dir+'includes/modules/ajax/changeItemCompletion.php?id='+id+'&completion='+completion;
    }else if(parseInt(completion)==2){
        var invoiceItemPrompt=prompt("Please enter an Invoice Item Number",'0');
        if (invoiceItemPrompt!=null && invoiceItemPrompt!=""&& invoiceItemPrompt!="0"){ 
            var URL = 'includes/modules/ajax/changeItemCompletion.php?id='+id+'&completion='+completion+'&invoiceItem='+invoiceItemPrompt;
        }else{
            alert('you need to enter an Invoice Item Number if you want to set an assigned item to "Invoiced"');
            document.getElementById('changeItemCompletion').value = '0';
            return;
        }   
    }                                                                           
    var func = "changeItemCompletion";                      
    var ai = ajaxFunction(func,URL,'0');     
    
}

function setChangeDisplayPicture(id){                       
    var hidden = document.getElementById(id);
    hidden.value = 1;
    return
}