﻿// JScript File
var jQueryObj = {
    setEffect:function(){
        //hover for JQuery button
        $j(document).ready(function($){
            $j('.hover-effect').hover(
	              function(){$j(this).addClass('ui-state-hover');}
	            , function(){$j(this).removeClass('ui-state-hover');}
            );
//            
//            //Enable jQuery validator callout
//            $j.updnValidatorCallout.attachAll();
//            
//            //Enable jQuery water mark
//            $j.updnWatermark.attachAll({cssClass: "SpiderTextBox_watermarked"});
            
            //Config click event for tag A (FF case)
            jQueryObj.loadClickMethodForTagA();
        })
    },
    showAlert:function(alertMessage, redirectURL, clientElement){
        //Config and create alert
        $j(document).ready(function($){
			var uniqueID = 'diagAlert_' + jQueryObj.generateGuid().toString();
			$j('body').append($j("<div id='" + uniqueID + "' title='Alert' style='display: none; text-align: left;' />"));
			$j('#'+uniqueID).html(alertMessage);
		    $j('#'+uniqueID).dialog({
			    autoOpen: false,
			    width: 400,
			    close: function(e){
				    if(redirectURL != ''){
						if(redirectURL == 'close'){
							window.close();
						}
						else{
							window.location = redirectURL;
						}
				    }
				    else{
						$j('#'+uniqueID).remove();
						if(clientElement != ''){
							$j('#' + clientElement).focus();
						}
				    }
			    },
			    modal: true,
			    buttons: {
				    "Close": function() { 
					    $j(this).dialog("close"); 
				    }
			    }
		    });
		    
		    $j('#'+uniqueID).dialog('open');
        })
    },     
    ShowJQueryPopup:function(ClientID){
		$j(document).ready(function($){
			//Create the over-lay div
			$j('#'+ClientID).parent().append($j('<div id="pnlOverlay" class="ui-widget-overlay" style="width: '+$j(document).outerWidth()+'px; height: '+$j(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($j('body').outerWidth() > $j('#'+ClientID).outerWidth()){
				_left = Math.floor(($j(document).outerWidth() - $j('#'+ClientID).outerWidth())/2)
			}
			
			$j('#'+ClientID).css({position: 'absolute', top: '50px', left: _left+'px', zIndex: 1002});
			$j('#'+ClientID).fadeIn('slow');
			
			$j('#'+ClientID).draggable();
		});
    }, 
    HideJQueryPopup:function(ClientID){
		$j(document).ready(function($){
			//Clear the over-lay div
			if($j('#pnlOverlay')){
				$j('#pnlOverlay').remove();
			}
			
			//Hide the main panel
			$j('#'+ClientID).fadeOut('fast');
		});
    },
    generateGuid:function(){
		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;
    },
    loadClickMethodForTagA:function(){
		$j(document).ready(function($){
			$j.each($j('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'));
						}
					}
				}
			});
		});
    }
}

//reload jquery effect
jQueryObj.setEffect();
