var loadingPopup;
var dataEntered;
var uploader;
var lockEl, unLockEl;
var panelCount;
var lockedSections = 0;

/**** PROPRIETARY CONTENT EDITOR FORMS ****/

function NthDay(n) {
    return n + ["th","st","nd","rd"][(!( ((n%10) >3) || (Math.floor(n%100/10)==1)) ) * (n%10)];  
}

/* Setup the awards entry form */
function awardSetup() {
    /* give dropdown extra functionality */
    $('#cItemForm_awardNo').change(function() {
        checkIfAwardExistsForEdit( $('#award' + $('#cItemForm_awardNo').val()) );
    });

    /* setup add/delete functionality */
    $('#addAward').click(function(e) {
        e.preventDefault();
        dataEntered = false;
        var callBack = function(data, status) {
            if (status == "success") {
                var awardId = $('#cItemForm_awardNo').val();
                
                var newEl = '<li class="clear" id="award'+awardId+'"><ul>'
                + '<li class="left">#'+awardId+':</li>'
                + '<li class="left"><strong class="data">'+$('#cItemForm_award').val()+'</strong>'
                + '<br/><span class="data">'+$('#cItemForm_winner').val()+'</span></li>'
                + '<li class="right"><span class="btn btnEditSmall">'
                + '<a class="edit" href="'+awardId+'">Edit</a></span>'
                + '<span class="btn btnDeleteSmall">'
                + '<a class="del" href="'+data.cItemId+'">Delete</a></span></li></ul></li>';

                
                /* if submitted award exists in list replace */
                if ($('#existingAwards #award' + awardId).length) {
                    $('#existingAwards #award' + awardId).replaceWith(newEl);
                } else {
                    /* insert in correct place */
                    if ($('#existingAwards li').size() == 0) {
                        /* append a ul to the existing days */
                        $('#existingAwards').append(newEl);
                    } else {
                        var beforeEl = null, afterEl = null;
                        $('#existingAwards > li').each(function() {
                            if ( parseInt( $(this).attr('id').substr(5)) < parseInt(awardId) ) {
                                beforeEl = $(this);
                            } else {
                                afterEl = $(this);
                                return false;
                            }
                        });
                        if (beforeEl != null) {
                            $(beforeEl).after(newEl);
                        } else if (afterEl != null) {
                            $(afterEl).before(newEl);
                        }
                    }
                }

                setupDeleteAward( $('#award' + $('#cItemForm_awardNo').val() + ' a.del') );
                setupEditAward( $('#award' + $('#cItemForm_awardNo').val() + ' a.edit') );

                $('#cItemForm_award').val('');
                $('#cItemForm_winner').val('');
                if ( (parseInt($('#cItemForm_awardNo').val())-1) < $('#cItemForm_awardNo').children('option').length ) {
                    $('#cItemForm_awardNo').val((parseInt($('#cItemForm_awardNo').val())+1));
                    checkIfAwardExistsForEdit( $('#award'+$('#cItemForm_awardNo').val()) );
                } else {
                    $('#cItemForm_awardNo').val('1');
                    checkIfAwardExistsForEdit( $('#award1') );
                }
                
                
            }
        };
        ajaxSubmit($('.editablePopup form'), callBack);
    });
    
    /* Enable Delete Links */
    $('#existingAwards li a.del').each(function() {
        setupDeleteAward($(this));
    });
    /* Enable Edit Links */
    $('#existingAwards li a.edit').each(function() {
        setupEditAward($(this));
    });
        
    checkIfAwardExistsForEdit( $('#award' + $('#cItemForm_awardNo').val()) );
}

function setupEditAward(el) {
    $(el).click(function(e) {
        e.preventDefault();
        var editVals = $(el).parent().parent().parent().find('.data');
        $('#addAward').html('Edit');
        $('#cItemForm_awardNo').val( $(el).attr('href') );
        $('#cItemForm_award').val($(editVals[0]).html());
        $('#cItemForm_winner').val($(editVals[1]).html());
    });
}

/* If this award exists change the usual 'add' type inputs to 'edit' */
function checkIfAwardExistsForEdit(awardEl) {
    $('#addAward').html('Add and Save');
    $('#cItemForm_award').val('');
    $('#cItemForm_winner').val('');
    if ($(awardEl).length) {
        var editVals = $(awardEl).find('.data');
        $('#addAward').html('Edit and Save');
        $('#cItemForm_award').val($(editVals[0]).html());
        $('#cItemForm_winner').val($(editVals[1]).html());
    }
}

function setupDeleteAward(el) {
    /* setup its delete button */
    $(el).click(function(e) {
        e.preventDefault();
        $.post('/sections/popupDelete', {
            'cItemId' : $(this).attr('href')
        }, function(c, d) {
            if (d == "success") {
                $(el).parent().parent().parent().parent().remove();
            }
        }, 'json');
    });
}

/* Set up the calendar multiple day data form */
function dayBoxSetup() {
    /* give dropdown extra functionality */
    $('#cItemForm_day').change(function() {
        checkIfDayExistsForEdit( $('#existingDays #day' + $('#cItemForm_day').val()) );
    });

    /* setup add/delete functionality */
    $('#addDayBox').click(function(e) {
        e.preventDefault();
        dataEntered = false;
        var callBack = function(data, status) {
            if (status == "success") {
                var dayId = $('#cItemForm_day').val();
                var dayNth = NthDay(dayId);

                var newEl = '<li class="clear" id="day'+dayId+'"><ul>'
                + '<li class="left">'+dayNth+':</li>'
                + '<li class="left"><strong class="data">'+$('#cItemForm_data').val()+'</strong></li>'
                + '<li class="right"><span class="btn btnEditSmall">'
                + '<a class="edit" href="'+dayId+'">Edit</a></span>'
                + '<span class="btn btnDeleteSmall">'
                + '<a class="del" href="'+data.cItemId+'">Delete</a></span></li></ul></li>';
                
                /* if submitted day exists in list replace */
                if ($('#existingDays #day' + dayId).length) {
                    $('#existingDays #day' + dayId).replaceWith( newEl );
                } else {
                    /* insert in correct place */
                    if ($('#existingDays li').size() == 0) {
                        /* append a ul to the existing days */
                        $('#existingDays').append(newEl);
                    } else {
                        var beforeEl = null, afterEl = null;
                        $('#existingDays > li').each(function() {
                            if ( parseInt( $(this).attr('id').substr(3)) < parseInt(dayId) ) {
                                beforeEl = $(this);
                            } else {
                                afterEl = $(this);
                                return false;
                            }
                        });

                        if (beforeEl != null) {
                            $(beforeEl).after(newEl);
                        } else if (afterEl != null) {
                            $(afterEl).before(newEl);
                        }
                    }
                }

                setupDeleteLink( $('#day' + $('#cItemForm_day').val() + ' a.del') );
                setupEditDay( $('#day' + $('#cItemForm_day').val() + ' a.edit') );

                $('#cItemForm_data').val('');
                if ( (parseInt($('#cItemForm_day').val())-1) < $('#cItemForm_day').children('option').length ) {
                    $('#cItemForm_day').val((parseInt($('#cItemForm_day').val())+1));
                    checkIfDayExistsForEdit( $('#day'+$('#cItemForm_day').val()) );
                } else {
                    $('#cItemForm_day').val('1');
                    checkIfDayExistsForEdit( $('#day1') );
                }                
            }
        };
        ajaxSubmit($('.editablePopup form'), callBack);
    });
    
    /* Setup the delete links */
    $('#existingDays li a.del').each(function() {
        setupDeleteLink($(this));
    });
    /* Enable Edit Links */
    $('#existingDays li a.edit').each(function() {
        setupEditDay($(this));
    });
    
    checkIfDayExistsForEdit($('#existingDays #day' + $('#cItemForm_day').val()));
}

function setupEditDay(el) {
    $(el).click(function(e) {
        e.preventDefault();
        var editVals = $(el).parent().parent().parent().find('.data');
        $('#addDay').html('Edit and Save');
        $('#cItemForm_day').val( $(el).attr('href') );
        $('#cItemForm_data').val($(editVals[0]).html());
    });
}


/* if this day already has data, set it up for edit */
function checkIfDayExistsForEdit(dayEl) {
    $('#addDayBox').html('Add and Save');
    $('#cItemForm_data').val('');
    if ($(dayEl).length) {
        var editVals = $(dayEl).find('.data');
        $('#addDayBox').html('Edit and Save');
        $('#cItemForm_data').val($(editVals).html());
    }
}

/* setup the delete link of a multiple contentitem */
function setupDeleteLink(el) {
    /* setup its delete button */
    $(el).click(function(e) {
        e.preventDefault();
        $.post('/sections/popupDelete', {
            'cItemId' : $(this).attr('href')
        }, function(c, d) {
            if (d == "success") {
                $(el).parent().parent().parent().parent().remove();
            }
        }, 'json');
    });
}

function fileUploadSetup( extRegex ) {
    if ( extRegex == undefined || extRegex == "" || extRegex == null ) {
        var extRegex = /^(jpg|png|jpeg|gif)$/i;
    }
    var uploader = new AjaxUpload(
        'upload',
        { 
            action : $('#saveSection').parents('form').attr('action'),
            autoSubmit: false,
            responseType : "json",
            onChange : function(file, ext) {
                /* Check for valid file extensions */
                if ( !( ext && extRegex.test(ext) ) ) { 
                    alert('Error: invalid file extension'); // cancel upload
                    return false; 
                }
                $('#upload').val(file);
                
            },
            onSubmit : function(file, ext) {
                /* Check for valid file extensions */
                if ( !( ext && extRegex.test(ext) ) ) { 
                    alert('Error: invalid file extension'); // cancel upload
                    return false; 
                }   
                
                /* If there's a tinymce editor involved, provoke it to transfer its content back to this form */
                if ( $('#saveSection').parents('form').find('.mceEditor').length ) {
                    tinyMCE.triggerSave(true, true);
                }

                var params = {};
                $('#saveSection')
                    .parents('form')
                    .find(":input, input[checked], input[type='password'], textarea")
                    .each(function() {
                        params[this.name || this.id || this.parentNode.name || this.parentNode.id] = this.value;
                    }
                );
                    
                uploader.setData(params);

                $('#upload').replaceWith( '<img src="/images/icons/notice-load.gif" alt="Uploading File" id="loading"/>' );
            },
            onComplete : function(a, b) {
                sortOutSection(b, "success");
                $('#loading').replaceWith('<p>DONE</p>');
                disablePopup();
            }
        }
    );
    return uploader;
}





/**** PERSONALISE SLIDE INTERFACE ****/

/** io = true to show lock, false to show unlock **/
function lockSwitch(io, el) {
    if ( io )  {
        lockedSections++;
        lockSection(el);
    }else{
        lockedSections--;
        unLockSection(el);
    }
    
}

/* Product Section Check if mark as complete is available */
function checkIfLock(slideEl, io) {
    if ((io) && (!$(slideEl).find('a.lockSection').length) && parseInt($(slideEl).find('.min').html()) <= parseInt($(slideEl).find('a.hasContent').length) ) {
        var lockUrl = $(slideEl).find('span.lockUrl').html() + '?sId=' + $(slideEl).find('span.sId').html();

        var lock = $('<li class="btnGallery btnSection btnSectionLock">Finished with this Section?<a href="' + lockUrl + '" class="lockSection" >click to lock</a></li>');
        $(lock).find('a').click(function(e) {
            e.preventDefault();
            lockSwitch(true, this);
        });
        $(slideEl).find('.sectionList').append(lock);
    } else if (!$(slideEl).find('a.lockSection').length) {
        $(slideEl).find('a.lockSection').remove();
    }
}

/* Product Section increment count of content items attached */
function incrementCItemCnt(slideItem, cnt) {
    var slide = $(slideItem).parent().parent().parent().parent().parent();
    $(slide).find('span.cItemCnt').html(
            parseInt($(slide).find('span.cItemCnt').html()) + parseInt(cnt));
    checkIfLock(slide, 1);
}

/* function to run after a content item is created from the popup */
function sortOutSection(data, textStatus) {
    $(data).each(function() {
        if (this.save && this.value != "") {
            if (!$(clickedItem).hasClass('hasContent')) {
                $(clickedItem).addClass('hasContent');
                if (this.cItemId != "" && this.cItemId >= 0 ) {
                    $(clickedItem).attr( 'href', $(clickedItem).attr('href') + this.cItemId );
                }
                incrementCItemCnt(clickedItem, 1);
            }
        } else if ( this.value == "" ) {
            $(clickedItem).removeClass('hasContent');
        }
        if (this.value != "") {
            $(clickedItem).attr('title', this.value);
        }
    });
}

/* how to lock a product section */
function lockSection(lockEl) {
    var sectionId = $(lockEl).parents('div.panel').find('span.sId').html();
    var href = ($(lockEl).attr('href') == undefined) ? $(lockEl).find('a').attr('href') : $(lockEl).attr('href');
    
    $.post(
        href,
        {
            sId : sectionId
        },
        function(data, textStatus) {
            if (textStatus == "success") {
                var unLockUrl = $(lockEl).parents('div.panel').find('span.unLockUrl').html();
                
                var unLockEl = $('<a href="' + unLockUrl + '" class="unLockSection">click to edit</a>');
                $(unLockEl).click(function(e) {
                    e.preventDefault();
                    lockSwitch(false, this);
                });
//                $(unLockEl).css( { lineHeight : "17px" });
                var parent = $(lockEl).parent();
                $(parent).removeClass('btnSectionLock').addClass( 'btnSectionUnLock' );
                $(parent).empty();
                $(parent).append('Section completed/locked');
                $(parent).append(unLockEl);
                
                if ( lockedSections == panelCount ) {
                    $('#reviewIt').removeClass('hidden');
                }
            }
        }
    );
}

/* how to unlock a product section */
function unLockSection(unLockEl) {
    var sId = $(unLockEl).parents('div.panel').find('span.sId').html();
    var href = ($(unLockEl).attr('href') == undefined) ? $(unLockEl).find('a').attr('href') : $(unLockEl).attr('href');
    
    $.post(
        href,
        {
            sId : sId
        },
        function(data, textStatus) {
            if (textStatus == "success") {
                var lockUrl = $(unLockEl).parents('div.panel').find('span.lockUrl').html();
                
                var lockEl = $('<a href="' + lockUrl + '" class="lockSection">click to lock</a>');
                $(lockEl).click(function(e) {
                    e.preventDefault();
                    lockSwitch(true, this);
                });

//              $(lockEl).css( { lineHeight : "17px" });
                
                var parent = $(unLockEl).parent();
                $(parent).removeClass('btnSectionUnLock').addClass( 'btnSectionLock' );
                $(parent).empty();
                $(parent).append('Finished with this Section?');
                $(parent).append(lockEl);

                if ( lockedSections != panelCount && !$('#reviewIt').hasClass('hidden') ){
                    $('#reviewIt').addClass('hidden');
                }

            }
        }
    );
}




/**** POPUP RELATED ****/
var popupStatus = 0;   // 0 means disabled; 1 means enabled;
var clickedItem;

/* Center the popup */
function centerPopup() {
    // request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popup").height();
    var popupWidth = $("#popup").width();
    var topPos = parseInt(windowHeight) / 3 - parseInt(popupHeight) / 2;
    var leftPos = parseInt(windowWidth) / 2 - parseInt(popupWidth) / 2
    
    if ( parseInt(topPos) <= 0 ) { topPos = 20; }
    // centering
    $("#popup").css( {
        "position" : "absolute",
        "top" : parseInt(topPos),
        "left" : parseInt(leftPos)
    });
    // only need force for IE6
    $("#backgroundPopup").css( {
        "height" : windowHeight
    });
}

/* Load the popup */
function loadContentPopup(inputEl) {
    /* Don't proceed if the content item is locked */
    if ( $(inputEl).parents('.insideNewInner').find('.btnSectionUnLock').length ) {
        return false;
    }

    /* Only proceed if the popup is NOT already open */
    if ( popupStatus == 0 ) {
        popupStatus = 1;
        clickedItem = $(inputEl);

        var inputs = $(inputEl).attr('href').split("?");

        var path = inputs[0];
        var options = inputs[1].split("&");

        var cItemType = options[0].split("=");
        var section = options[1].split("=");
        var cItem = options[2].split("=");

        var cItemTypeId = cItemType[1];
        var sectionId = section[1];
        var cItemId = cItem[1];
        
        /* Load the overlay */
        $("#backgroundPopup").css( { "opacity" : "0.7" });
        $("#backgroundPopup").fadeIn("slow");

        // send the request to the popup renderer
        $.post( 
            path,
            { 
                cItemTypeId : cItemTypeId, 
                sId : sectionId, 
                cItemId : cItemId 
            },
            function(data, textStatus) {
                if (textStatus == "success") {
                    var uploader;
                    var submitAjaxUploader = false;
                    /* Lose the loader */
                    $("#backgroundPopup img").fadeOut("fast");

                    /* Append the returned data(form etc) */
                    $('#popup #data').append(data);

                    centerPopup();
  
                    $("#popup").fadeIn("slow");

                    /* Allow detection of any user input */
                    dataEntered = false;
                    $('input[type=file], input[type=text]').change(function() {
                        dataEntered = true;
                    });

                    /* Set up the ajax file/image uploads */
                    if ( $('#upload').length ) {
                        if ( $('#upload').hasClass('filetype') ) {
                            uploader = fileUploadSetup(/^(jpg|png|jpeg|gif|pdf|zip)$/i);
                        }else {
                            uploader = fileUploadSetup();
                        }
                        submitAjaxUploader = true;    
                    }

                    /* Setup Calendar day box forms */
                    if ( $('#addDayBox').length ) { 
                        dayBoxSetup(); 
                    }
                    
                    /* Setup Awards forms */
                    if ( $('#addAward').length ) {
                        awardSetup();
                    }
                    
                    $("#popup input:visible:enabled").css('line-height','1.2em');
                    $("#popup input:visible:enabled:first").focus();
                    

                    $('#saveSection').click(function(e) {
                        e.preventDefault();
                        //REPLACE THE BUTTON WITH A LOADER
                        dataEntered = false;
                        var callBack = function(a, b) {
                            sortOutSection(a, b);
                        };
                        if ( submitAjaxUploader ) { 
                            if ( $('#upload').attr('value') == null || $('#upload').attr('value') == '' || $('#upload').attr('value') == 'undefined' ) {
                                /* THIS IS THE FIX FOR THE FILE UPLOAD MULTIPLE EXTRA FIELDS NOT WORKING WHEN NO FILE IS UPLOADED */
                                ajaxSubmit($('.editablePopup form'), callBack);
                                disablePopup();
                                /*** NOT FIXED YET ***/
                            }else{
                                uploader.submit();
                            }
                        } else {    
                            ajaxSubmit($('.editablePopup form'), callBack);
                            disablePopup();
                        }                        
                    });
                }
            }
        );
    }
}

/* Generic Submit form by ajax function */
function ajaxSubmit(formEl, callBackFunc, dataType) {
    if (dataType == '' || dataType == null) {
        dataType = 'json';
    }
    if (callBackFunc == null || callBackFunc == '') {
        callBackFunc = function() { };
    }

    /* If there's a tinymce editor involved, provoke it to transfer its content back to this form */
    if ( $(formEl).find('.mceEditor').length ) {
        tinyMCE.triggerSave(true, true);
    }

    var params = {};
    $(formEl).find(":input, input[checked], input[type='password'], textarea").each(function() {
        params[this.name || this.id || this.parentNode.name || this.parentNode.id] = this.value;
    });

    $("body").addClass("curWait");

    $.post($(formEl).attr("action") + "?", params, callBackFunc, dataType);
}

/* Disable the popup */
function disablePopup() {
    if (dataEntered) {
        if (!confirm('Are you sure you wish to close the editor without saving? Any entered data will be lost.')) {
            return false;
        }
    }

    // disables popup only if it is enabled
    if (popupStatus == 1) {
        $("#backgroundPopup").fadeOut("slow");
        $("#popup").fadeOut("slow", function() {  $('#popup #data').empty(); });
        popupStatus = 0;
       
    }
}

/* Setup the close popup stuff */
function givePopupClose() {
    // Click the x event!
    $("#popupClose").click(function() {
        disablePopup();
    });
    // Click out event!
    $("#backgroundPopup").click(function() {
        disablePopup();
    });
    // Press Escape event!
    $(document).keypress(function(e) {
        if (e.keyCode == 27 && popupStatus == 1) {
            disablePopup();
        }
    });
}




/* clear any user notifications */
function clearNotices() {
    $('.notice').each(function(i) {
        $(this).fadeOut('fast');
    });
}





$(document).ready(function() {
    /* Set any radiobuttons to autosubmit their parent forms */
    if ($('.autoSubmit').length) {
        $('.autoSubmit').click(function() {
            $(this).parents('form').submit();
        });
    }

    /* give popup links popup functionality */
    if ($('a.popup').length) {
        $('a.popup').each(function() {
            $(this).click(function(e) {
                // load popup
                    loadContentPopup($(this));

                    e.preventDefault();
                });
        });

        givePopupClose();
    }

    /* hide anything that is there for accessibility/non js users */
    if ($('.jsHide').length) {
        $('.jsHide').hide();
    }

    /* give lock section links funcitonality */
    if ($('a.lockSection').length) {
        $('a.lockSection').each(function() {
            $(this).click(function(e) {
                e.preventDefault();
                lockSwitch(true, this);
            });
        });
    }
    /* give unlock section links funcitonality */
    if ($('a.unLockSection').length) {
        lockedSections = $('a.unLockSection').length; 
        $('a.unLockSection').each(function() {
            $(this).click(function(e) {
                e.preventDefault();
                lockSwitch(false, this);
            });
        });
    }

    /* show hide toggle sections */
    if ($('#helperWrap').length) {
        $('#helperWrap .toggler').click(function(e) {
            if ($('#helperWrap').css('height') == '40px') {
                $('#helperWrap').animate( {
                    height : '428px'
                }, 400);
                $('#helperWrap').animate( {
                    height : '398px'
                }, 500);
            } else {
                $('#helperWrap').animate( {
                    height : '40px'
                }, 400);
            }
            e.preventDefault();
        });
        // $('#helperWrap').animate({height: '428px'}, 400);
        // $('#helperWrap').animate({height: '398px'}, 500);
    }
    /* show hide toggle sections */
    if ($('.question').length) {
        $('.question').click(function(e) {
            $(this).parent().find('.response').toggle();
            e.preventDefault();
        });
        if ($('.openMe').length) {
            $('.openMe').parent().find('.response').toggle();
        }
    }

    /* ui mode button functionality */
    if ($('#uiOnly').length) {
        $('#uiOnly').click(function(e) {
            if ($('#head').css('height') == "101px") {
                $('#head').animate( {
                    height : '0px'
                }, 400);
                $('#innerCont').animate( {
                    margin : '0em'
                }, 400);
            } else {
                $('#head').animate( {
                    height : '101px'
                }, 400);
                $('#innerCont').animate( {
                    margin : '1em 0em 0em'
                }, 400);
            }
            e.preventDefault();
        });
    }

    /* make sure notices get cleared */
    if ($('.notice').length) {
        setTimeout("clearNotices()", 10000);
    }

    /* Start any rotators */
    if ($('.rotator').length) {
        setTimeout(function() {
            $('.rotator').cycle( {
                fx : 'scrollUp',
                delay : -2000,
                speed : 1000,
                timeout : 10000
            });
        }, 3000);
    }
    /*
     * if ( $('.draggable').length ) { $(".draggable").draggable(); }
     */
    if ($('#popup').length) {
        $("#popup").draggable( {
            handle : '.handle'
        });
    }
    
    if ( $('#reviewProcess').length ) {
        $('.btnOrderSmall a').css({'color': '#777', 'cursor': 'default', 'text-decoration':'none' });
        $('.btnOrderSmall').click(function(e){e.preventDefault();});
        
        $('#approve').click(function(e){
            e.preventDefault();
            if ( $('#approval_approver').attr('value').length < 1 ) {
                alert('You must enter your name to approve this projects content');
                return false;
            }
            if ( confirm('By agreeing to this you are indicating that you are happy with all of the content you have supplied') ) {
                $.post(
                    '/projects/reviewConfirm',
                    $('.reviewForm').serializeArray(),
                    function(data, textStatus) {
                        if (textStatus == "success" && data.status == true ) {
                            alert('Your project has been marked as approved. You can now place an order.');
                            $('.btnEditSmall').click(function(e) { e.preventDefault(); });
                            $('.btnEditSmall a').attr('href','');
                            $('.btnEditSmall a').css({'color': '#777', 'cursor': 'default', 'text-decoration':'none' });

                            $('#approval_approver').attr('disabled','disabled');

                            $('.btnOrderSmall').unbind();
                            $('.btnOrderSmall a').css({'color': '#000', 'cursor': 'pointer', 'text-decoration':'underline' });
                                
                            $('#approve').unbind();
                            $('#approve').attr('value','Content Approved');
                            $('#approve').css({'color': '#777', 'cursor': 'default', 'text-decoration':'none' });
                            $('#approve').click(function(e) { e.preventDefault(); });
                        } else {
                            alert('There was an error approving your project, Please try again and then contact Print On Demand if the problem continues.');
                        }
                    },
                    'json'
                );             
            }
        });
    }
    
});