﻿/// <reference name="MicrosoftAjax.js"/>


Type.registerNamespace("Site.Ajax");

Site.Ajax.Utilities = function() {
    Site.Ajax.Utilities.initializeBase(this);

}

Site.Ajax.Utilities.prototype = {
     
    GetSiteUrl: function(subDomen) {
   
        var domenUrl = new String(window.location.href);
        var regExp=new RegExp(/:\/\/(.[^/]+)/);
        domenUrl=domenUrl.match(regExp)[1];
        if(subDomen!=null && subDomen.length>0)
            domenUrl='http://'+domenUrl+'/'+subDomen+'/';
        else
            domenUrl='http://'+domenUrl+'/';
        
        return domenUrl;
    },
    
    GetBrowserType:function(){
    
        var agt = navigator.userAgent.toLowerCase();
        if (agt.indexOf("opera") != -1) return 'Opera';
        if (agt.indexOf("staroffice") != -1) return 'Star Office';
        if (agt.indexOf("webtv") != -1) return 'WebTV';
        if (agt.indexOf("beonex") != -1) return 'Beonex';
        if (agt.indexOf("chimera") != -1) return 'Chimera';
        if (agt.indexOf("netpositive") != -1) return 'NetPositive';
        if (agt.indexOf("phoenix") != -1) return 'Phoenix';
        if (agt.indexOf("firefox") != -1) return 'Firefox';
        if (agt.indexOf("safari") != -1) return 'Safari';
        if (agt.indexOf("skipstone") != -1) return 'SkipStone';
        if (agt.indexOf("msie") != -1) return 'Internet Explorer';
        if (agt.indexOf("netscape") != -1) return 'Netscape';
        if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
        if (agt.indexOf('\/') != -1) {
            if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
                return navigator.userAgent.substr(0, agt.indexOf('\/'));
            }
            else return 'Netscape';
        } else if (agt.indexOf(' ') != -1)
            return navigator.userAgent.substr(0, agt.indexOf(' '));
        else return navigator.userAgent;
    
    },
    LoadScript:function(filePath,fileType){//debugger;

     if (fileType=="js"){ //if filename is a external JavaScript file
      var fileref=document.createElement('script');
      fileref.setAttribute("type","text/javascript");
      fileref.setAttribute("src", filePath);
     }
     else if (fileType=="css"){ //if filename is an external CSS file
      var fileref=document.createElement("link");
      fileref.setAttribute("rel", "stylesheet");
      fileref.setAttribute("type", "text/css");
      fileref.setAttribute("href", filePath);
     }
     if (typeof fileref!="undefined")
      document.getElementsByTagName("head")[0].appendChild(fileref);

    },
    
    dispose: function() {        
        //Add custom dispose actions here
    Site.Ajax.Utilities.callBaseMethod(this, 'dispose');
    }
}


////////////////////BlockUI///////////////////////////////
Type.registerNamespace("Site.Ajax.Alerts");

Site.Ajax.Alerts = function() {
    Site.Ajax.Alerts.initializeBase(this);
    this._message = String();
    this._messageColor='Black';
    this._messageFontFamaly='Arial';
    this._messageFontSize='12px';
    
    this._title = String();
    this._titleColor='Black';
    this._titleFontFamaly='Arial';
    this._titleFontSize='14px';
    
    this._hasBorder=false;
    this._borderColor='Red';
    
    this._toolTipBackgroundColor='White';
    this._currentToolTipElementID=new String('@#$');
    
    this._toolTipFontColor='Black';
    this._currentToolTipElementID=new String('@#$');
    
    this._toolTipFontColor='White';
    this._toolTipFontFamily='Arial';
}

Site.Ajax.Alerts.prototype = {
 
    _message: String,
    _messageColor:String,
    _messageFontFamily:String,
    _messageFontSize:String,
    
    _title: String,
    _titleColor:String,
    _titleFontFamily:String,
    _titleFontSize:String,
    
    _hasBorder:Boolean,
    _borderColor:String,
    
    _toolTipBackgroundColor:String,
    _currentToolTipElementID:String,
    
    _toolTipFontColor:String,
    _toolTipFontFamily:String,
    
   
    get_Message: function() {
        return this._message;
    },
    set_Message: function(value) {
        this._message = value;
    },
    get_messageColor: function() {
        return this._messageColor;
    },
    set_messageColor: function(value) {
        this._messageColor = value;
    },
    get_messageFontFamily: function() {
        return this._messageFontFamaly;
    },
    set_messageFontFamily: function(value) {
        this._messageFontFamaly = value;
    },
    get_messageFontSize: function() {
        return this._messageFontSize;
    },
    set_messageFontSize: function(value) {
        this._messageFontSize = value;
    },
    
    
    get_Title: function() {
        return this._title;
    },
    set_Title: function(value) {
       this._title = value;
    },
    get_titleColor: function() {
        return this._titleColor;
    },
    set_titleColor: function(value) {
       this._titleColor = value;
    },
    get_titleFontFamily: function() {
        return this._titleFontFamaly;
    },
    set_titleFontFamily: function(value) {
       this._titleFontFamaly = value;
    },
    get_titleFontSize: function() {
        return this._titleFontSize;
    },
    set_titleFontSize: function(value) {
       this._titleFontSize = value;
    },
    
    
     get_toolTipBackgroundColor: function() {
        return this._toolTipBackgroundColor;
    },
    set_toolTipBackgroundColor: function(value) {
       this._toolTipBackgroundColor = value;
    },
    
    
     get_toolTipFontColor: function() {
        return this._toolTipFontColor;
    },
    set_toolTipFontColor: function(value) {
       this._toolTipFontColor = value;
    },
    
    get_toolTipFontFamily: function() {
        return this._toolTipFontFamily;
    },
    set_toolTipFontFamily: function(value) {
       this._toolTipFontFamily = value;
    },
 
    
//    get_hasBorder: function() {
//        return this._hasBorder;
//    },
//    set_hasBorder: function(value) {
//       this._hasBorder = value;
//    },
//    get_borderColor: function() {
//        return this._borderColor;
//    },
//    set_borderColor: function(value) {
//       this._borderColor = value;
//    },
    
     _createBlockUI: function(){
        var messageDivParent = document.createElement('div');
        $(messageDivParent).css('display','none');
        $(messageDivParent).css('background-color','#656565');
        var messageDiv = document.createElement('div');
        messageDiv.innerHTML=this.get_Message();

        $(messageDiv).html('<div style="padding-top:10px;padding-bottom:10px;">'
                          +'<div align="right" onclick="javascript:{setTimeout($.unblockUI, 1000);}">'
                          +'<img alt="" id="imgCloseMessage"  style="cursor: pointer;position:relative;z-index:99999;padding-right:10px;" />'
                          +'</div><div align="center" style="font-weight: bold;position:relative;top:-18px;" id="divBlockUITitle"></div>'
                          +'<div id="divBlockUIContent" style="padding-left: 0px;"></div></div>');
        
        
        $(messageDiv).css('background','White');
        $(messageDivParent).append(messageDiv);
        $("body").append(messageDivParent);
         
        $('#divBlockUITitle').css('color',this.get_titleColor());       
        $('#divBlockUITitle').css('font-size',this.get_titleFontSize());       
        $('#divBlockUITitle').css('font-family',this.get_titleFontFamily());       
        $('#divBlockUITitle').html(this.get_Title());
        
        $('#divBlockUIContent').css('color',this.get_messageColor());       
        $('#divBlockUIContent').css('font-size',this.get_messageFontSize());       
        $('#divBlockUIContent').css('font-family',this.get_messageFontFamily()); 
        $('#divBlockUIContent').html(this.get_Message());  
        
        $('#imgCloseMessage').attr('src',utils.GetSiteUrl('')+'AJAX/images/images.jpg');   
        var currObj=this;
        $(document).ready(function(){
             $.blockUI({
                css: {
                    border: 'none',
                    backgroundColor: '#656565',
                    opacity: .9
                    //,color: '#411f70'
                },
                message: $(messageDivParent)
            });
            if(currObj._hasBorder)
                $(messageDiv).corner('round').parent().css('background',currObj._borderColor).css('padding','2px').corner('round'); 
            else
                $(messageDiv).corner('round 15px');
          });
    },
    ShowMessage: function() {
      //debugger;
        if(typeof BLOCKUI === 'undefined'){
           var currObj=this;
           $.getScript(utils.GetSiteUrl('')+'AJAX/JS/jquery.blockUI.js', function() {
              if(typeof CORNER === 'undefined'){
                  $.getScript(utils.GetSiteUrl('')+'AJAX/JS/jquery.corner.js', function() {
                        currObj._createBlockUI();
                    });
              }
            });
        }
        else{
            this._createBlockUI();
        }
    },
    _createToolTip:function(element,message,trigger){
        var currObj=this;
        switch(trigger){
        case 'click':
        $(element).bt(message,
                        {showTip: function(box){
                        $(box).fadeIn(500,function(){}); currObj._currentToolTipElementID=element.attr('id'); 
//                        var $content = $('.bt-content', box); /* hide the content until after the animation */
//                        var $canvas = $('canvas', box); /* hide the canvas for a moment */
//                        
//                        $(box).show(); 
//                        $canvas.css( {top: -8}).show();
//                        $content.css( {top: -8}).show();                  
                        
                        
                        },
                        hideTip: function(box, callback){
                        $(box).animate({opacity: 0}, 500, callback);
//                        var $content = $('.bt-content', box); /* hide the content until after the animation */
//                        var $canvas = $('canvas', box); /* hide the canvas for a moment */
//                        $(box).hide(); /* show the wrapper, however elements inside (canvas, content) are now hidden */
//                        $canvas.css( {top: 0}).hide();
//                        $content.css( {top: 0}).hide();   
                         
                         },
                         //shrinkToFit: true,
                         trigger: 'click',
                         fill: this._toolTipBackgroundColor,
                         cornerRadius: 10,
                         strokeWidth: 0,
                         shadow: true,
                         shadowOffsetX: 3,
                         shadowOffsetY: 3,
                         shadowBlur: 8,
                         shadowColor: 'rgba(0,0,0,.9)',
                         shadowOverlap: false,
                         noShadowOpts: {strokeStyle: '#999', strokeWidth: 1},
                         positions: ['bottom','top'],
                         width: 300,
                         
                         cssStyles: {
                            
                            fontSize: '12px',
                            fontFamily: this._toolTipFontFamily,
                            color:this._toolTipFontColor
                          }
                         });
        break;
        default:
        $(element).bt(message,
                        {showTip: function(box){
                        $(box).fadeIn(500,function(){}); currObj._currentToolTipElementID=element.attr('id'); 
//                        var $content = $('.bt-content', box); /* hide the content until after the animation */
//                        var $canvas = $('canvas', box); /* hide the canvas for a moment */
//                        
//                        $(box).show(); 
//                        $canvas.css( {top: -8}).show();
//                        $content.css( {top: -8}).show();                  
                        
                        
                        },
                        hideTip: function(box, callback){
                        $(box).animate({opacity: 0}, 500, callback);
//                        var $content = $('.bt-content', box); /* hide the content until after the animation */
//                        var $canvas = $('canvas', box); /* hide the canvas for a moment */
//                        $(box).hide(); /* show the wrapper, however elements inside (canvas, content) are now hidden */
//                        $canvas.css( {top: 0}).hide();
//                        $content.css( {top: 0}).hide();   
                         
                         },
                         //shrinkToFit: true,
                         
                         trigger: ['focus', 'blur'],
                         fill: this._toolTipBackgroundColor,
                         cornerRadius: 10,
                         strokeWidth: 0,
                         shadow: true,
                         shadowOffsetX: 3,
                         shadowOffsetY: 3,
                         shadowBlur: 8,
                         shadowColor: 'rgba(0,0,0,.9)',
                         shadowOverlap: false,
                         noShadowOpts: {strokeStyle: '#999', strokeWidth: 1},
                         positions: ['right','bottom','top'],
                         width: 117,
                         
                         cssStyles: {
                            //width:'auto'
                            fontSize: '12px',
                            fontFamily: this._toolTipFontFamily,
                            color:this._toolTipFontColor
                          }
                         });
        break;
        }
        
        window.onresize=function(){$(document).ready(function(){try{ $('#'+currObj._currentToolTipElementID).blur();}catch(ex){}//$('#'+currObj._currentToolTipElementID).focus();
        //$('#'+currObj._currentToolTipElementID).btOn();$('#'+currObj._currentToolTipElementID).btOff();
        });}
    },
    ShowOnFocusToolTip:function(element,message){
        if(typeof BT === 'undefined'){
           var currObj=this;
           $.getScript(utils.GetSiteUrl('')+'AJAX/JS/jquery.bt.js', function() {
              if(typeof EXCANVAS === 'undefined'){
                  $.getScript(utils.GetSiteUrl('')+'AJAX/JS/excanvas.js', function() {
                        currObj._createToolTip(element,message,'');
                    });
              }
            });
        }
        else{
            this._createToolTip(element,message,'');
        }
    },
   ShowOnClickToolTip:function(element,message){
        if(typeof BT === 'undefined'){
           var currObj=this;
           $.getScript(utils.GetSiteUrl('')+'AJAX/JS/jquery.bt.js', function() {
              if(typeof EXCANVAS === 'undefined'){
                  $.getScript(utils.GetSiteUrl('')+'AJAX/JS/excanvas.js', function() {
                        currObj._createToolTip(element,message,'click');
                    });
              }
            });
        }
        else{
            this._createToolTip(element,message,'click');
        }
    },
    dispose: function() {        
        //Add custom dispose actions here
    Site.Ajax.Alerts.callBaseMethod(this, 'dispose');
    }
}
////////////////////BlockUI///////////////////////////////



Site.Ajax.Utilities.registerClass('Site.Ajax.Utilities',null, Sys.IDisposable);
Site.Ajax.Alerts.registerClass('Site.Ajax.Alerts', null, Sys.IDisposable);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

var utils = new Site.Ajax.Utilities();