/**
 *
 * @param {function pointer} function_
 */
function addLoadEvent(function_){
    $("#preLoadDiv").show();
/** since in jquery 1.3.2 it wasnt worked **/
/*
     var old= window.onload;
    
    
     document.getElementById("preLoadDiv").style.display = "block";
    
    
     if (typeof window.onload != 'function') {
    
    
     window.onload = function_;
    
    
     } else {
    
    
     window.onload = function() {
    
    
     if (old) {
    
    
     old();
    
    
     }
    
    
     function_();
    
    
     }
    
    
     }
    
    
     */
}


function addAjaxEvent(function_){
    var old = $("#mainPicture").onload;
    $("#preLoadDiv").style.display = "block";
    if (typeof $("mainPicture").onload != 'function') {
        $("#mainPicture").onload = function_;
    }
    else {
        $("#mainPicture").onload = function(){
            if (old) {
                old();
            }
            function_();
        }
    }
}

var isShowPersonalMenu = false;
var isShowSystemMenu = false;
var isShowContentMenu = false;
var isShowUserContentMenu = false;

$(document).ready(function(){
    $("#preLoadDiv").hide();
    
    $("select[name='templates']").change(function(){
        self.location.href = "index.php?template=set&id=" + $(this).val() ;
    });
    
    $(document).find('td').each(function() {
        if ($(this).attr('class') != null && $(this).attr('style') != null) {
            if ($(this).attr('class') == 'mainHeader' && $(this).attr('style').indexOf('box_head_1.gif') == -1) {
                $(this).attr('style', '');
            }
        }
		
        if ( $(this).attr('style') != null ) {
            if ( $(this).attr('style').indexOf('box_head_1.gif') != -1 ) {
                $(this).attr('style', ( $(this).attr('style') ) + 'border-bottom: 1px solid #d1d1d1;' );
            }
        }
		
        if ( $(this).attr('class') != null ) {
            if ( $(this).attr('class') == 'inputsTdS' ) {
                $(this).parent('tr').parent('tbody').parent('table').addClass('inputs_tables_version_1');
                $(this).addClass('inputs_cells_overflow');
				
            }
        }
		
        if ( $(this).attr('id') != null ) {
            if ( $(this).attr('id') == 'inputsTdS' ) {
                $(this).parent('tr').parent('tbody').parent('table').addClass('inputs_tables_version_1');
                $(this).addClass('inputs_cells_overflow');
            }
        }
    });
    
    $("div[uclickkey='content']").click(function(){
        showContentMenu();
    });
    
    $("div[uclickkey='user_content']").click(function(){
        showUserContentsMenu();
    });
    
    $("div[uclickkey='system']").click(function(){
        showSystemMenu();
    });
    
    $("div[uclickkey='person_menu']").click(function(){
        showPersonalMenu();
    });
    
    $(document).find('div').each(function(){
        if ($(this).attr('ulkey') != null) {
            if ($(this).attr('ulkey') == 'person_menu' || $(this).attr('ulkey') == 'system' ||
                $(this).attr('ulkey') == 'content' ||
                $(this).attr('ulkey') == 'user_content') {
                $(this).hide();
            }
        }
    });
	
    $("select[name='cat_MOD_PHP']").change(function(){
        self.location.href = document.location + "&s_cat_mode=" + $("select[name='cat_MOD_PHP']").val();
    });
    
});



function showUserContentsMenu(){
    if (!isShowUserContentMenu) {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'user_content') {
                    $(this).show(1000);
                }
            }
        });
        $("a[id='user_content_down_arrow']").html('<img src="images/arrow/up_arrow.gif" border="0"/>&nbsp;');
        isShowUserContentMenu = true;
    }
    else {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'user_content') {
                    $(this).hide(1000);
                }
            }
        });
        $("a[id='user_content_down_arrow']").html('<img src="images/arrow/down_arrow.gif" border="0"/>&nbsp;');
        isShowUserContentMenu = false;
    }
    
}


function showContentMenu(){
    if (!isShowContentMenu) {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'content') {
                    $(this).show(1000);
                }
            }
        });
        
        $("a[id='content_down_arrow']").html('<img src="images/arrow/up_arrow.gif" border="0"/>&nbsp;');
        
        isShowContentMenu = true;
    }
    else {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'content') {
                    $(this).hide(1000);
                }
            }
        });
        $("a[id='content_down_arrow']").html('<img src="images/arrow/down_arrow.gif" border="0"/>&nbsp;');
        isShowContentMenu = false;
    }
    
}

function showSystemMenu(){
    if (!isShowSystemMenu) {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'system') {
                    $(this).show(1000);
                }
            }
        });
        
        $("a[id='system_down_arrow']").html('<img src="images/arrow/up_arrow.gif" border="0"/>&nbsp;');
        
        isShowSystemMenu = true;
    }
    else {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'system') {
                    $(this).hide(1000);
                }
            }
        });
        $("a[id='system_down_arrow']").html('<img src="images/arrow/down_arrow.gif" border="0"/>&nbsp;');
        isShowSystemMenu = false;
    }
    
}

function showPersonalMenu(){
    if (!isShowPersonalMenu) {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'person_menu') {
                    $(this).show(1000);
                }
            }
        });
        $("a[id='down_arrow']").html('<img src="images/arrow/up_arrow.gif" border="0"/>&nbsp;');
        isShowPersonalMenu = true;
    }
    else {
        $(document).find('div').each(function(){
            if ($(this).attr('ulkey') != null) {
                if ($(this).attr('ulkey') == 'person_menu') {
                    $(this).hide(1000);
                }
            }
        });
        $("a[id='down_arrow']").html('<img src="images/arrow/down_arrow.gif" border="0"/>&nbsp;');
        isShowPersonalMenu = false;
    }
    
}

/**
 * Set the DOM element display property in headmenu
 * @param idname
 * @return
 */
function setDisplayIn(idname)
{
    document.getElementById(idname).style.display = "block";
}
	 
/**
 * Set the DOM element display property in headmenu
 * @param idname
 * @return
 */
function setDisplayOut(idname)
{
	   
    document.getElementById(idname).style.display = "none";
}