/**
 * SITECHIPS Application Framework based on Zend Framework
 * (c) 2008 qbus | websolutions
 *
 * @category   	Sitechips
 * @package		JS
 * @copyright	Copyright (c) 2008 qbus | websolutions
 * @version		$Id: qbTools.js 835 2009-03-04 18:52:56Z mla $
 */
/**
 * Single Entry Point Javascript Script Loading ( Lazy Loader )
 *
 * Defining all used Functions, Plugins
 * Attention : If a new Function is needed create a Plugin.
 * And Extend the Plugin List, Loading will happen if the Function itself, is called.
 *
 * @ToDo : Refactoring JQuery itself to utilise the Lazy Loader itself
 *
 * @author Sebastian Fuentes
 */
$(document).ready(function(){

    // Global var decalarations
    
    var lastCall = '';
    var php_vars = [''];
	
    // Predefining JQuery Plugins
    jQuery.ajaxSetup({
        cache: true,
        error: function(XMLHttpRequest, textStatus, errorThrown){
					
            if (textStatus == 'error' && lastCall == 'mca') {
				
                mc = php_vars['aRequestPath'].split(".");

                $.getScript('_files/js/modules/' + mc[0] + '.' + mc[1] + '.js', function(){
                    if (php_vars['aRequestPath'] != 'undefined') {
						lastCall = 'mca';
					}
                });
            }
        }
    });
    
    $.getScript("_files/js/lazy_load.js", function(){
    
        $.lazy('_files/js/plugins/jquery.asmselect.js', 'asmSelect');
        $.lazy('_files/js/plugins/jquery.chainedSelects.js', 'chainedSelects');
        $.lazy('_files/js/plugins/jquery.dimensions.js', 'dimensions');
        $.lazy('_files/js/plugins/jquery.prompt.js', 'prompt');
        $.lazy('_files/js/plugins/jquery.jdmenu.js', 'jdMenu');
        
    });
    
    
    // Load Controller Module specific javascript
    
    $('.php').each(function(){
		php_vars[$(this).attr('class').substring(4)] = $(this).text();
	});
    if (typeof php_vars['aRequestPath'] != 'undefined') {
		$.getScript('_files/js/modules/' + php_vars['aRequestPath'] + '.js', function(){
			lastCall = 'mca';
		});
	}
 
    
    // Load Globals
    $.getScript("_files/js/plugins/qbevents.del.js"); // Deletion Prompt
     $.getScript("_files/js/plugins/thickbox.js"); // Thickbox
    // not yet Plugins
    $.getScript('_files/js/plugins/qbevents.menu.js');
    $.getScript('_files/js/plugins/qbevents.toogleselect.js');
    
    
    // Generic Shorts
    // ToDo : Move into a seperated File
    $('.paginationControl').change(function(){
        window.location = this.options[this.selectedIndex].value;
    });
    
    $('.history .back').click(function(){
        history.back();
    });
});


/**
 * @status deprecated use class="form submit" as trigger
 * @param {Object} fp_nForm
 * @param {Object} fp_sLocation
 */
function submitForm(fp_nForm, fp_sLocation){
    document.forms[fp_nForm].action = fp_sLocation;
    document.forms[fp_nForm].submit();
}

/**
 * @status deprecated define a local JS if needed
 * @param {Object} fp_nForm
 */
function invertElements(fp_nForm){
    for (var i = 0; i < document.forms[fp_nForm].elements.length; i++) {
        var check = document.forms[fp_nForm].elements[i];
        if (check != null && !check.disabled) 
            check.checked = !check.checked;
    }
}

/**
 * @status deprecated define a local JS if needed
 * @param {Object} fp_nForm
 * @param {Object} fp_nStart
 * @param {Object} fp_nEnd
 * @param {Object} fp_nIntervall
 */
function invertElementsEx(fp_nForm, fp_nStart, fp_nEnd, fp_nIntervall){
    for (var i = fp_nStart; i < fp_nEnd; i += fp_nIntervall) {
        var check = document.forms[fp_nForm].elements[i];
        if (check != null && !check.disabled) 
            check.checked = !check.checked;
    }
}

/**
 * @status deprecated
 * @param {Object} fp_nForm
 * @param {Object} fp_sLocation
 */
function submitFormAdd(fp_nForm, fp_sLocation){
    document.forms[fp_nForm].action += fp_sLocation;
    document.forms[fp_nForm].submit();
}

/**
 * @status deprecated
 * @param {Object} fp_sForm
 * @param {Object} fp_nWidth
 * @param {Object} fp_nHeight
 * @param {Object} fp_sAction
 */
function submitFormToNewWindow(fp_sForm, fp_nWidth, fp_nHeight, fp_sAction){
    var newWindow = openWindow(fp_nWidth, fp_nHeight, "#");
    newWindow.name = "copyMoveWindow";
    document.forms[fp_sForm].action = fp_sAction;
    document.forms[fp_sForm].target = "copyMoveWindow";
    document.forms[fp_sForm].submit();
}

/**
 * @status deprecated
 * @param {Object} fp_nWidth
 * @param {Object} fp_nHeight
 * @param {Object} fp_sLocation
 */
function openWindow(fp_nWidth, fp_nHeight, fp_sLocation){
    l = (screen.width / 2) - (fp_nWidth / 2);
    t = (screen.height / 2) - (fp_nHeight / 2);
    var Window = window.open(fp_sLocation, "", " toolbar=0,location=0,status=0,menubar=0,resizable=1,scrollbars=yes,height=" + fp_nHeight + ",width=" + fp_nWidth + ", left=" + l + ",top=" + t);
    return Window;
    
}

