
function verifyLink(tbl,id,fld){
    
    var ajObj = new ajaxObject('/admin/ajax2/singlefield') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                url = responseText.replace('http://','') ;
                url = 'http://' + url ;
                window.open(url) ;
                //alert(responseText) ;
            }
        }
        ajObj.update('tbl/' + tbl + '/id/' + id + '/fld/' + fld + '/' ) ;
}



//=============================================================================== ARTIST PAGE

function swapForNameFields(elmnt,tbl,id,view)
{

    var ajObj = new ajaxObject('/admin/ajax/swapfornamefields') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/view/' + view + '/' ) ;
}

function updateName(elmnt,tbl,id,fname,lname)
{

    var ajObj = new ajaxObject('/admin/ajax/updatename') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/fname/' + fname + '/lname/' + lname + '/' ) ;
}



function swapForTextField(elmnt,tbl,id,fld,view)
{

    var ajObj = new ajaxObject('/admin/ajax/swapfortextfield') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/field/' + fld +'/view/' + view + '/' ) ;
}


function updateField(elmnt,tbl,id,fld,value,view)
{

    var ajObj = new ajaxObject('/admin/ajax/updatefield') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/field/' + fld + '/value/' + value + '/view/' + view + '/' ) ;
}



function swapForDateSet(elmnt,tbl,id,fld,view)
{

    var ajObj = new ajaxObject('/admin/ajax/swapfordateset') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/field/' + fld +'/view/' + view + '/' ) ;
}

function updateDateSet(elmnt,tbl,id,fld,yr,month,day,view)
{

    var ajObj = new ajaxObject('/admin/ajax/updatedateset') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/field/' + fld + '/year/' + yr + '/month/' + month + '/day/' + day + '/view/' + view + '/' ) ;
}


function swapForTextArea(elmnt,tbl,id,fld,view)
{

    var ajObj = new ajaxObject('/admin/ajax/swapfortextarea') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/fld/' + fld + '/view/' + view + '/' ) ;
}

function updateTextArea(elmnt,tbl,id,fld,value,view)
{
    var ajObj = new ajaxObject('/admin/ajax/updatetextarea') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/fld/' + fld + '/view/' + view + '/value/' + encodeURI(value) + '/') ;
}



function swapForSelect(elmnt,tbl,id,order,keyFld,valFld,view)
{

    var ajObj = new ajaxObject('/admin/ajax/swapforselect') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/order/' + order + '/keyFld/' + keyFld + '/valFld/' + valFld + '/view/' + view + '/' ) ;
}

function updateSelect(elmnt,tbl,id,fld,value,view)
{
    var ajObj = new ajaxObject('/admin/ajax/updateselect') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('table/' + tbl + '/id/' + id + '/fld/' + fld + '/view/' + view + '/value/' + value + '/') ;
}


function swapForPhoto(elmnt,id,action)
{

    var ajObj = new ajaxObject('/admin/ajax/swapforphoto') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.parentNode.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update("id/" + id + "/act/" + action + "/") ;
}


//=== UNUSED ====================================================================
                    function updatePhoto(elmnt,id) // currently unused
                    {
                        var ajObj = new ajaxObject('/ajax/updatephoto') ;
                            ajObj.callback = function(responseText, responseStatus, rsponseXML) {
                                if (responseStatus==200) {
                                    elmnt.parentNode.innerHTML = responseText ;
                                    //alert(responseText) ;
                                }
                            }
                            ajObj.update("id/" + id + "/") ;
                    }
//==================================================================================



function deleteArtist(id)
{
    if (confirm("This will completely delete this artist and all of his/her work from the site.  Are you sure you want to continue?"))
    {    
        elmnt = document.getElementById('artistList') ;
        
        var ajObj = new ajaxObject('/admin/ajax/deleteartist') ;
            ajObj.callback = function(responseText, responseStatus, rsponseXML) {
                if (responseStatus==200) {
                    elmnt.innerHTML = responseText ;
                    //alert(responseText) ;
                }
            }
            ajObj.update("id/" + id + "/") ;
    }
}



function deleteExhibit(id)
{
    if (confirm("Are you sure you want to delete this exhibit?  The artwork will remain on the site, categorized under its respective artists."))
    {    
        elmnt = document.getElementById('exhibitList') ;
        
        var ajObj = new ajaxObject('/ajax/deleteexhibit') ;
            ajObj.callback = function(responseText, responseStatus, rsponseXML) {
                if (responseStatus==200) {
                    elmnt.innerHTML = responseText ;
                    //alert(responseText) ;
                }
            }
            ajObj.update("id/" + id + "/") ;
    }
}



function Zend_ProgressBar_Update(data)
{
    document.getElementById('zend-progressbar-done').innerHTML = data.percent + '%';
}


function uploading()
{
    elmnt = document.getElementById('uploading') ;
    txt = "Uploading..." ;
    i = 0 ;
    
    //elmnt.innerHTML = txt ;
    
    setInterval(subProg,100) ;

    function subProg()
    {
        elmnt.innerHTML = txt.substring(0,i) ;
        i = (i <= txt.length + 5) ? i+1 : 1 ;
    }

}


function artworkChange()
{
    var a_id = document.getElementById('artistSelect').value ;
    var e_id = document.getElementById('exhibitSelect').value ;
    
    loc = '/admin/admin/artwork/e_id/' + e_id + '/a_id/' + a_id + '/' ;
    window.location = loc ;
    
/*    var ajObj = new ajaxObject('/ajax/artworkchange') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                document.getElementById('artworkSelect').innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update("a_id/" + a_id + "/e_id/" + e_id + "/") ;
*/
}


function incPiece(id, tbl)
{
    var a_id = document.getElementById('artistSelect').value ;
    var e_id = document.getElementById('exhibitSelect').value ;

    var ajObj = new ajaxObject('/admin/ajax/incpiece') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                document.getElementById('artworkSelect').innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        //alert(tbl) ;
        ajObj.update("id/" + id + "/tbl/" + tbl + "/a_id/" + a_id + "/e_id/" + e_id + "/") ;
}


function decPiece(id, tbl)
{
    var a_id = document.getElementById('artistSelect').value ;
    var e_id = document.getElementById('exhibitSelect').value ;

    var ajObj = new ajaxObject('/admin/ajax/decpiece') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                document.getElementById('artworkSelect').innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update("id/" + id + "/tbl/" + tbl + "/a_id/" + a_id + "/e_id/" + e_id + "/") ;
}


function editArt(id)
{
    var ajObj = new ajaxObject('/admin/ajax/editart') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                document.getElementById('artEdit').innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update("id/" + id + "/") ;
}



function swapForSelectArtist(elmnt,a_id,p_id)
{

    var ajObj = new ajaxObject('/admin/ajax/swapforselectartist') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('a_id/' + a_id + '/p_id/' + p_id + '/' ) ;
}

function updateArtistSelect(elmnt,a_id,p_id)
{

    var ajObj = new ajaxObject('/admin/ajax/updateartistselect') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('a_id/' + a_id + '/p_id/' + p_id + '/' ) ;
}


function swapForSelectExhibit(elmnt,p_id)
{

    var ajObj = new ajaxObject('/admin/ajax/swapforselectexhibit') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('p_id/' + p_id + '/' ) ;
}

function updateExhibitSelect(elmnt,e_id,p_id)
{

    var ajObj = new ajaxObject('/admin/ajax/addtoexhibit') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('e_id/' + e_id + '/p_id/' + p_id + '/' ) ;
}

function removeFromExhibit(p_id,e_id)
{
    elmnt = document.getElementById('pieceExList') ;
    var ajObj = new ajaxObject('/admin/ajax/removefromexhibit') ;
        ajObj.callback = function(responseText, responseStatus, rsponseXML) {
            if (responseStatus==200) {
                elmnt.innerHTML = responseText ;
                //alert(responseText) ;
            }
        }
        ajObj.update('e_id/' + e_id + '/p_id/' + p_id + '/' ) ;
}

function deletePiece(elmnt,id,a_id,e_id)
{
    if (confirm("This will completely remove this piece from all exhibits and artists on the site. Are you sure you want to continue?"))
    {
        var ajObj = new ajaxObject('/admin/ajax/deletepiece') ;
            ajObj.callback = function(responseText, responseStatus, rsponseXML) {
                if (responseStatus==200) {
                    elmnt.innerHTML = responseText ;
                    //alert(responseText) ;
                }
            }
            ajObj.update('id/' + id + '/a_id/' + a_id + '/e_id/' + e_id + '/' ) ;
    }
}





function ajaxObject(url, callbackFunction) {
    var that=this;      
    this.updating = false;
    this.abort = function() {
        if (that.updating) {
            that.updating=false;
            that.AJAX.abort();
            that.AJAX=null;
        }
    }
    this.update = function(passData,postMethod, stamp) {
        if (stamp == null) {
            stamp = true ;
        }
        
        if (that.updating) { return false; }
        that.AJAX = null;                          
        if (window.XMLHttpRequest) {              
            that.AJAX=new XMLHttpRequest();              
        } else {                                  
            that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
        }                                             
        if (that.AJAX==null) {                             
            return false;                               
        } else {
            that.AJAX.onreadystatechange = function() {  
                if (that.AJAX.readyState==4) {             
                    that.updating=false;                
                    that.callback(that.AJAX.responseText,that.AJAX.status,that.AJAX.responseXML);        
                    that.AJAX=null;                                         
                }                                                      
            }                                                        
            that.updating = new Date();
            
            if (stamp)
            {
                if ((/post/i.test(postMethod))) {
                    var uri=urlCall+'/'+that.updating.getTime();
                    that.AJAX.open("POST", uri, true);
                    that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    that.AJAX.setRequestHeader("Content-Length", passData.length);
                    that.AJAX.send(passData);
                } else {
                    var uri=urlCall+'/'+passData+'&timestamp='+(that.updating.getTime()); 
                    that.AJAX.open("GET", uri, true);                             
                    that.AJAX.send(null);                                         
                }              

            } else {

                if ((/post/i.test(postMethod))) {
                    var uri=urlCall+'/' ;
                    that.AJAX.open("POST", uri, true);
                    that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    that.AJAX.setRequestHeader("Content-Length", passData.length);
                    that.AJAX.send(passData);
                } else {
                    var uri=urlCall+'/'+passData ; 
                    that.AJAX.open("GET", uri, true);                             
                    that.AJAX.send(null);                                         
                }              
                
            }
        
            return true;                                             
        }                                                                           
    }
    var urlCall = url;        
    this.callback = callbackFunction || function () { };
}

function processData(responseText, responseStatus) {
  if (responseStatus==200) {
    alert(responseText);
  } else {
    alert(responseStatus + ' -- Error Processing Request');
  }
}


