﻿/*
	Brown Paper Bag - Web Studio - Web Design - Web Creation - Web Hosting - Internet - Intranet
	Version 1.0
	Created: 10-Jan-2008
	Modified: 
	By: Geordie McCabe (info@brownpaperbag.com.au
*/

// Include the right script
//=================================================================================
var WindowStyle = 'modal';

switch(WindowStyle){
    case 'lightview':{
        document.write("<script type='text/javascript' src='/_share/scripts/lightview.js'></script>");
    } break;
    case 'modal':{
        document.write("<script type='text/javascript' src='/_share/scripts/control.modal.2.2.3.js'></script>");
    }
}        

// Setup the modal links
//=================================================================================

//Event.observe(document, 'dom:loaded', setupModals);

Event.observe(window, 'load', setupModals);


//Sets up the modals for each 
function setupModals() {
    var ModalArray = new Array();
    //alert('setting up modals');
    
    // create for each new model definition as "className, Width, Height, Options"
    ModalArray[0] = 'modal-test~300~300~menubar:false';
    ModalArray[1] = 'modal-Prod~450~600~menubar:false';
      ModalArray[2] = 'modal-ProdTemp~700~400~menubar:false';
          ModalArray[3] = 'modal-Grad~500~500~menubar:false';
          ModalArray[4] = 'modal-SearOrder~600~550~menubar:false';
          ModalArray[5] = 'modal-Incent~860~754~menubar:false';
          ModalArray[6] = 'modal-ProdItem~600~450~menubar:false';
          ModalArray[7] = 'modal-Invoice~600~840~menubar:false';
          ModalArray[8] = 'modal-Down~450~600~menubar:false';
          ModalArray[9] = 'modal-Bank~750~600~menubar:false';
          ModalArray[10] = 'modal-Products~660~830~menubar:false';
          ModalArray[11] = 'modal-Credit~400~300~menubar:false';
          ModalArray[12] = 'modal-AddStageImg~885~600~menubar:false';
          ModalArray[13] = 'modal-Over~700~890~menubar:false';
          ModalArray[14] = 'modal-Skip~400~230~menubar:false';
          
          
    // cycle thru thr modals and setup the links.
    for (var i=0; i<ModalArray.length; i++){
        var newModal = ModalArray[i].split('~');
        var modalClass = newModal[0];
        var modalWidth = newModal[1];
        var modalHeight = newModal[2];
        var modalOptions = newModal[3];
        
        // append , to modal options
        if (modalOptions != ''){
            modalOptions = ', ' + modalOptions;
        }
        
        //setup the right sort of modal
        switch(WindowStyle){
            case 'lightview':{
                $$('a.' + modalClass).each(function(link){
                    //alert('lightview: ' + link.href);
                    
                    link.className = 'lightview';
                    link.rel = 'iframe';
                    link.title = ':: :: width: ' + modalWidth + ', height: ' + modalHeight + modalOptions;
                });
            } break;
            case 'modal':{
                $$('a.' + modalClass).each(function(link){
                    //alert('modal: ' + link.href);
                    new Control.Modal(link, {
                        iframe: true,
                        opacity: 0.6,
                        overlayCloseOnClick: false,
                        width: modalWidth,
                        height: modalHeight,
                        fade: true,
                        fadeDuration: 0.5 
                    });
                });
            } break;
        }          
    }
}


//Event.observe(window, 'load', showMessageBox);

 //This is a specific modal on every page for showing server-side feedback
//function showMessageBox() {
// if($("messagebox_text").innerHTML == "") return;
// var my_modal = new Control.Modal($("messagebox_link"));
// my_modal.open($("messagebox"),{
//            iframe: true,
//            opacity: 0.6,
//            overlayCloseOnClick: false,
//            width: 340,
//            height: 150
//        });
//}

//function hideMessageBox() {
// $("messagebox_text").innerHTML = "";
// parent.Control.Modal.close();
//}

// Close the modal dialog and reload the parent window
//=================================================================================
var modalReturnValue = null;

function closeModal(returnValue, refresh, javascript) {
    // setup the return value
    if(parent){ 
     parent.modalReturnValue = returnValue;
    
      if(returnValue || refresh || javascript) {
        var ModalPostBackButton = parent.document.getElementById("ctl00_ModalPostBackButton");
        ModalPostBackButton.value = returnValue;
        ModalPostBackButton.click();
        }
    // setup the right sort of modal
    switch(WindowStyle){
        case 'lightview':{
            parent.Lightview.hide(); 
        } break;
        case 'modal':{
            parent.Control.Modal.close();
        } break;
        }   
   }
}         

