﻿/*----------------------------------------------------------------------------------
    CSS JQUERY MENU
----------------------------------------------------------------------------------*/

var arrowimages={
    down:['downarrowclass', 'arrow-down.gif', 25], 
    right:['rightarrowclass', 'arrow-right.gif']
};

var jquerycssmenu={
    fadesettings: {overduration: 200, outduration: 200}, //duration of fade in/ out animation, in milliseconds
    buildmenu:function(menuid, arrowsvar){
	    $(document).ready(function($){
		    var $mainmenu=$("#"+menuid+">ul");
		    var $headers=$mainmenu.find("ul").parent();
		    $headers.each(function(i){
			    var $curobj=$(this);
			    var $subul=$(this).find('ul:eq(0)');
			    this._dimensions={
			        w:this.offsetWidth, 
			        h:this.offsetHeight, 
			        subulw:$subul.outerWidth(), 
			        subulh:$subul.outerHeight()
                };
                
			    this.istopheader=$curobj.parents("ul").length==1? true : false;
			    $subul.css({top:this.istopheader? this._dimensions.h+"px" : 0});
			    $curobj.children("a:eq(0)").append('&nbsp;&raquo;');
			    $curobj.hover(
				    function(e){
					    var $targetul=$(this).children("ul:eq(0)");
					    this._offsets={
					        left:$(this).offset().left, 
					        top:$(this).offset().top
                        };
                        
					    var menuleft=this.istopheader? 0 : this._dimensions.w;
					    menuleft=(this._offsets.left+menuleft+this._dimensions.subulw>$(window).width())? (this.istopheader? -this._dimensions.subulw+this._dimensions.w : -this._dimensions.w) : menuleft;
					    $targetul.css({left:menuleft+"px", width:(this.offsetWidth>$targetul.outerWidth()) ? this.offsetWidth : $targetul.outerWidth()}).slideDown(jquerycssmenu.fadesettings.overduration);
				    },
				    function(e){
					    $(this).children("ul:eq(0)").slideUp(jquerycssmenu.fadesettings.outduration);
				    }
			    ) //end hover
		    }) //end $headers.each()
		    $mainmenu.find("ul").css({display:'none', visibility:'visible'});
	    }) //end document.ready
    }
};

//build menu with ID="myjquerymenu" on page:
jquerycssmenu.buildmenu("myjquerymenu", arrowimages);

/*----------------------------------------------------------------------------------
    /CSS JQUERY MENU
----------------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------------
    /JS Functions
----------------------------------------------------------------------------------*/
function showDialog(ClientID){
    $(document).ready(function($){
	    //Create the over-lay div
	    $('#'+ClientID).parent().append($('<div id="pnlOverlay" class="ui-widget-overlay" style="width: '+$(document).outerWidth()+'px; height: '+$(document).outerHeight()+'px; z-index: 1001;"></div>'))

	    //Get the left position for making element stay at the center of the screen			
	    var _left = 50;

	    if($('body').outerWidth() > $('#'+ClientID).outerWidth()){
		    _left = Math.floor(($(document).outerWidth() - $('#'+ClientID).outerWidth())/2)
	    }
    	
	    $('#'+ClientID).css({position: 'absolute', top: '50px', left: _left+'px', zIndex: 1002});
	    $('#'+ClientID).fadeIn('slow');
    	
	    $('#'+ClientID).draggable();
    });
}

function hideDialog(ClientID){
	$(document).ready(function($){
		//Clear the over-lay div
		if($('#pnlOverlay')){
			$('#pnlOverlay').remove();
		}
		
		//Hide the main panel
		$('#'+ClientID).fadeOut('fast');
	});
}

function showAlert(alertMessage, redirectURL, clientElement){
    //Config and create alert
    $(document).ready(function($){
		var uniqueID = 'diagAlert_' + generateGuid().toString();
		$('body').append($("<div id='" + uniqueID + "' title='Alert' style='display: none; text-align: left;' />"));
		$('#'+uniqueID).html(alertMessage);
	    $('#'+uniqueID).dialog({
		    autoOpen: false,
		    width: 400,
		    close: function(e){
			    if(redirectURL != ''){
					if(redirectURL == 'close'){
						window.close();
					}
					else{
						window.location = redirectURL;
					}
			    }
			    else{
					$('#'+uniqueID).remove();
					if(clientElement != ''){
						$('#' + clientElement).focus();
					}
			    }
		    },
		    modal: true,
		    buttons: {
			    "Close": function() { 
				    $(this).dialog("close"); 
			    }
		    }
	    });
	    
	    $('#'+uniqueID).dialog('open');
    });
}

function generateGuid(){
	var result, i, j;
	result = '';
	
	for(j=0; j<32; j++) {
		if( j == 8 || j == 12|| j == 16|| j == 20) 
		result = result + '_';
		i = Math.floor(Math.random()*16).toString(16).toUpperCase();
		result = result + i;
	}
	
	return result;
}

function loadClickMethodForTagA(){
	$(document).ready(function($){
		$.each($('a'), function(){
			if(typeof(this.click) == 'undefined'){
				this.click = function(){
					var result = true;
					if(this.onclick){
						result = this.onclick();
					}
					if(typeof(result) == 'undefined' || result) {
						eval(this.getAttribute('href'));
					}
				}
			}
		});
	});
}

function setEffect(){
    //hover for JQuery button
    $(document).ready(function($){
        $('.hover-effect').hover(
              function(){$(this).addClass('ui-state-hover');}
            , function(){$(this).removeClass('ui-state-hover');}
        );
        
        //Config click event for tag A (FF case)
        loadClickMethodForTagA();
        
        $('input[type=text]').click(function(){
            this.select();
        });
    })
}
setEffect();
/*----------------------------------------------------------------------------------
    /JS Functions
----------------------------------------------------------------------------------*/
