//Display Load Files module or Display Slideshow module

function toggleDisp(mode){
    var params='mode='+mode;
    doajax('slidefiles.php','dispfiles',params);

}

//From Display Slideshow module - toggle Display/Hide captions (if there are any)
function toggleCaps(mode){
    if (mode == 'HC')
        alert('Captions will now be hidden. Click \'Play\' to view slideshow');
    else
        alert('Captions will now be displayed. Click \'Play\' to view slideshow');
    var params='mode='+mode;
    doajax('slidefiles.php','dispfiles',params);
}

function toggleLoadinst(){
    if (document.getElementById('loadinst').style.display =='block'){ 
        document.getElementById('loadinst').style.display='none';
        document.getElementById('instbtn').value='Display Loading Instructions';
        document.getElementById('instbtn').title='Display instructions for using the Uploader Tool';
    }else{
        document.getElementById('loadinst').style.display='block';
        document.getElementById('instbtn').value='Hide Loading Instructions';
        document.getElementById('instbtn').title='Hide instructions for using the Uploader Tool';
    }
}

function chgSpeed(){
    speed = document.getElementById('speed').options[document.getElementById('speed').selectedIndex].value;
    duration = document.getElementById('duration').options[document.getElementById('duration').selectedIndex].value;
    if (speed < duration){
        duration = speed;
        alert('The duration of each dissolve transition can\'t be longer than the speed between transitions.\nThey are both now set to '+speed+' seconds. Click \'Play\' to view slideshow.')
        var params='mode=CS&speed='+speed+'&duration='+duration;
    }else{
        alert('The time between each dissolve transition is now set to '+speed+' seconds when you click \'Play\'');
        var params='mode=CS&speed='+speed;
    }
    doajax('slidefiles.php','dispfiles',params);
}

function chgDuration(){	
    duration = document.getElementById('duration').options[document.getElementById('duration').selectedIndex].value;
    speed = document.getElementById('speed').options[document.getElementById('speed').selectedIndex].value;
    if (duration > speed){
        duration = speed;
        alert('The duration of each dissolve transition can\'t be longer than the speed between transitions.\nIt has been reduced to '+duration+' seconds. Click \'Play\' to view slideshow.')
    }else
        alert('The duration of each dissolve transition is now set to '+duration+' seconds. Click \'Play\' to view slideshow.');
    var params='mode=CD&duration='+duration;
    doajax('slidefiles.php','dispfiles',params);
}

//Invoke AJAX to display the Load Files module - srcmode 1:from slideshows.php srcmode 2: from uploader.swf
//function loadFiles(imgtot){
function loadFiles(){
    var params='mode=LF';
    doajax('slidefiles.php','dispfiles',params);
}

//from lightbox.php - signals create slideshow from lightbox
function loadLBFiles(){		
    var params='mode=LB';
    doajax('slidefiles.php','dispfiles',params);
}

//from slidefiles.php play button - just reinvoke the page via ajax with startshow=1 and display show
function playShow(){		
    var params='mode=DS';
    doajax('slidefiles.php','dispfiles',params);
}


//Invoke AJAX to display confirm upload in upload.php module (not slideshows)
function confirmUpload(){
    var params='mode=CN';
    doajax('upldfile.php','dispfiles',params);
}

//Invoke AJAX to remove a slideshow file
function remFile(loadfileid,fname){
    var params='mode=RM&loadfileid='+loadfileid+'&fname='+fname;
    doajax('slidefiles.php','dispfiles',params);
}

//Invoke AJAX to update caption text in slideshow module
function updCaption(loadfileid,caption){
    var params='mode=UC&loadfileid='+loadfileid+'&caption='+caption;
    doajax('slidefiles.php','dispfiles',params);
}

//Invoke AJAX to update the sequence of an image in the slideshow module
function updSequence(loadfileid1,seq1,loadfileid2,seq2){
    var params='mode=US&loadfileid1='+loadfileid1+'&seq1='+seq1+'&loadfileid2='+loadfileid2+'&seq2='+seq2;
    doajax('slidefiles.php','dispfiles',params);
}

//url=page formater,targid=div id/name, params=passed in vars
function doajax(url, targid, params){
    var page_request = false
    if (window.XMLHttpRequest) // if Mozilla, Safari etc
        page_request = new XMLHttpRequest()
    else if (window.ActiveXObject){ // if IE
        try {
            page_request = new ActiveXObject("Msxml2.XMLHTTP")
        } 
        catch (e){
            try{
                page_request = new ActiveXObject("Microsoft.XMLHTTP")
            }
             catch (e){}
            }
        }
    else
        return false
    page_request.onreadystatechange=function(){
    ldpage(page_request, targid)
    }
    //page_request.open('GET', url, true)
    page_request.open('POST', url, true)

//for POST Send the proper header information along with the request
page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
page_request.setRequestHeader("Content-length", params.length);
page_request.setRequestHeader("Connection", "close");
 
    //page_request.send(null)
    page_request.send(params)
    ajaxOnLoad();				//fires after the Ajax Page has loaded
}

function ldpage(page_request, targid){
    if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
    document.getElementById(targid).innerHTML=page_request.responseText
    
}

//equivalent of <body onload> fires at end of ajax page load
function ajaxOnLoad(){
    //document.getElementById('procmsg').style.visibility = 'hidden';
    document.getElementById('procmsg').style.display='none';
   //var t=setTimeout("document.getElementById('procmsg').style.visibility = 'hidden';",500);

}

//turned on when flash uploader.fla starts upload
function waitMsg(){
    //document.getElementById('procmsg').style.visibility = 'visible';
    document.getElementById('procmsg').style.display = 'block';
}

//Slide show controls

function startShow(delay) {
    var t=setTimeout("document.getElementById('slideshow').dostartShow()",delay);
}


function stopShow() {
    document.getElementById('slideshow').dostopShow();
}

function firstPage(){
    var swf = document.getElementById('slideshow');
    if (swf)
        swf.dofirstPage();
}


