/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    function getProgressDatas() {
        var http_request = false;
        var target_url = "Upload.Status";

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/plain');
                // 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('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
        http_request.onreadystatechange = function() { processResponse(http_request); };
        http_request.open('GET', target_url, true);
        http_request.send(null);
        return true;
    }
    
    function processResponse(http_request) {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                displayUploadResponse(http_request.responseText);
                setTimeout("getProgressDatas()",500);
            } else {
                alert('There was a problem with the request: Status: '+http_request.status+" State: "+http_request.readyState);
            }
        }
    }

    function displayProgressbar(){
        document.upload.submit();
        toggleDisplay('uploadform');
        getProgressDatas();
        return true;
    }


    function displayUploadResponse(uploadtxt){
        response = uploadtxt.split("|");
        if(response.length > 1) document.getElementById('progressstatus').innerHTML = response[0]+"&nbsp;<b>"+response[3]+"%</b>&nbsp;<img src='images/balken.gif' width='"+(response[3]*3)+"' height='14'>" ;
        else document.getElementById('progressstatus').innerHTML = uploadtxt ;
    }
        
    function displaysubcategories(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                document.getElementById('subcategories').innerHTML = http_request.responseText;
            }
        }
    }

    function displaylightbox(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                document.getElementById('lightboxcontent').innerHTML = http_request.responseText;
            }
        }
    }

    function getGalleryThumbnails(value){
        $.cookie("gallerythumbs", value);
        fn = function() { displayGalleryThumbnails(); };
        nativeRequest("Gallery.Thumbnails?p="+value,fn);
    }
    
    function displayGalleryThumbnails(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                document.getElementById('gallerypicture').innerHTML = http_request.responseText;
            }
        }
    }

    function getEditCommentForm(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                document.getElementById('interactdialog').innerHTML = http_request.responseText;
            }
        }
    }

    function reloadPage(){
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                window.location.reload();
            }
        }
    }

    function getSubCategories(value){
        fn = function() { displaysubcategories(); };
        nativeRequest("Picture.Tags?p="+value,fn);
    }
    
    function getPictureSubCategories(value,picid){
        fn = function() { displaysubcategories(); };
        nativeRequest("Picture.Tags?p="+value+"&i="+picid,fn);
    }

    function addPictureToLightbox(picid){
        fn = function() { displaylightbox(); };
        nativeRequest("Lightbox.Add?picid="+picid,fn);
    }

    function displayEditCommentForm(iucid){
        $('#interactdialog').jqmShow();
        fn = function() { getEditCommentForm(); };
        nativeRequest("Member.Comment.Edit?iucid="+escape(iucid),fn);
    }

    function updateComment(formname){
        closeInteractionDialog();
        formobj = eval("document."+formname);
        poststr = "title=" + encodeURI(formobj.title.value);
        poststr += "&desc=" + encodeURI(formobj.desc.value);
        poststr += "&iucid=" + encodeURI(formobj.iucid.value);
        postRequest("Member.Comment.Update",poststr,reloadPage);
    }

    function closeInteractionDialog(){
        $('#interactdialog').jqmHide();
    }
