﻿// JScript File
var _frame='FrameWrapper';
var _timerG;
var test;
var _showHover;
var EF = {
    /* Short hand to return object in global */
    $_script: function () {
        return this.Global.ScriptHandler
    },
    $_util: function () {
        return this.Global.Utilities
    },
    /* -- Global */
    Global: {
        Utilities: {
            CookieManager: {
                /* Create cookie */
                Bake: function (name, value, days) {
                     var now = new Date();
			days = days || 1
                    now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * days)
                   // alert (";expires=" + now.toGMTString());

                    
                    document.cookie = name + "=" + value + "; Max-Age=" + (60 * 60 * 24 * days) + "; path=/;" +";expires=" + now.toGMTString() ;
                },
                /* Create session cookie */
                Session: function (name, value) {
                    document.cookie = name + "=" + value + "; path=/";
                },
                Consume: function (name, key) {
                    var arr = this._Check(name);
                    var condition = undefined;
                    if (arr) {
                        arr = unescape(arr).split("&");
                        for (var i = 0; i < arr.length; i++) {
                            var t = arr[i].split("|");
                            for (var g = 0; g < t.length; g++) {
                                t[g] = t[g].split("=");
                            }
                            for (var counter = 0; counter < t.length; counter++) {
                                if (unescape(t[counter][0]) == key) {
                                    condition = t[counter][1];
                                    break;
                                }
                            }
                        }
                        return condition;
                    } else {
                        return condition;
                    }
                },
                /* Checks for key or key/value pair in cookie - hacked together for leadform*/
                Check: function (name, key, value) {
              
                    var arr = this._Check(name);
                      
               
                    var condition = false;
                    if (arr) {
                        arr = unescape(arr).split("&");
                        for (var i = 0; i < arr.length; i++) {
                            var t = arr[i].split("|");
                            for (var g = 0; g < t.length; g++) {
                                t[g] = t[g].split("=");                                
                            }
                            for (var counter = 0; counter < t.length; counter++) {
                                if (arguments.length == 2) {
                                    if (unescape(t[counter][0]) == key) {
                                        condition = true;
                                        break;
                                    }
                                } else {
                                    if (unescape(t[counter][0]) == key & unescape(t[counter][1]) == value) {
                                        condition = true;
                                        break;
                                    }
                                }
                            }
                        }
                        return condition;
                    } else {
                        return condition;
                    }
                },
                /* Helper - returns value of specified cookie */
                _Check: function (name) {
                    var s = document.cookie.split(';');
                    
                    for (var i = 0, l = s.length; i < l; i++) {
                        var c = s[i].toString(), f, r;
                        f = c.substring(0, c.indexOf("="))                        
                        r = c.substring(c.indexOf("=") + 1, c.length)
                        
                        while (f.charAt(0) == " ") 
                        {
                        f = f.substring(1, f.length)
                        }
                        
                        if (f == name) 
                        {
                        return r;
                        }
                    }
                }
            },
            GetDimensions: function (Width_Height_or_Both) {
                Width_Height_or_Both = Width_Height_or_Both.toLowerCase()
                switch (Width_Height_or_Both) {
                    case "width":
                        return { "width": width() }
                        break;
                    case "height":
                        return { "height": height() }
                        break;
                    case "both":
                        return { "width": width(), "height": height() }
                        break;
                    // If nothing, just return both...  
                    default:
                        return { "width": width(), "height": height() }
                        break;
                        window.location
                }
                function height() {
                    return Math.max(
            Math.max(document.body.scrollHeight, document.documentElement.scrollHeight),
            Math.max(document.body.offsetHeight, document.documentElement.offsetHeight),
            Math.max(document.body.clientHeight, document.documentElement.clientHeight)
          );
                }
                function width() {
                    return Math.max(
            Math.max(document.body.scrollWidth, document.documentElement.scrollWidth),
            Math.max(document.body.offsetWidth, document.documentElement.offsetWidth),
            Math.max(document.body.clientWidth, document.documentElement.clientWidth)
          );
                }
            }
        }
    },
    /* -- HoverLead */
    HoverLead: {
       
            Private: function () {
                var playing = new Boolean();
                return function setter(condition) {
                    if (arguments.length == 0) return playing;
                    playing = condition;
                    if (playing == "true") {
			
                        EF.HoverLead.killTimer(test);
                        return playing;
                    } else if (playing == "false") {
                        EF.HoverLead.setTimer();
                        return playing;
                    }
                }
            },
            showModal: function () {
                /* Load ColorBox for pop-in -- Will eventually replace nryo and ThickBox */
              //alert("modals");

		//$('<iframe id="myFrame" name="myFrame">').appendTo('body');
		//$('body').append('<iframe id="myFrame" name="myFrame">')
               // document.getElementById(EF.HoverLead.Private._iframe).src=EF.HoverLead.Private._liveball;  
		$('body').append('<div id="' + EF.HoverLead.Private._wrapper  + '"></div>')
		$('#' + EF.HoverLead.Private._wrapper).append('<iframe id="HoverFrame" class="HoverFrame" scrolling="no" frameborder="0" allowTransparency="true" style="border:none;width:389px;height:585px;" src="' + EF.HoverLead.Private._liveball + '"></iframe>') 
                 	  
               TB_MPPshow(EF.HoverLead.Private._wrapper,EF.HoverLead.Private._width,EF.HoverLead.Private._height,EF.HoverLead.Private._isscroll);
              
            },
            closeModal: function () {
                /* Create EFLD cookie */
                EF.Global.Utilities.CookieManager.Session("EFLD", escape("Viewed=True"));

                /* Increment counter */
		if ((!EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count")) || isNaN(EF.Global.Utilities.CookieManager.Consume("EFFEDCK", "Count"))) 
                    EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=0", "180");

                var _count = parseInt(EF.Global.Utilities.CookieManager.Consume("EFFEDCK", "Count")) + 1;
                EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=" + _count, "180");
		
                TB_MPPHide('FrameWrapper');
                
            },
            setTimer: function () {
                //EF.HoverLead.Private._timer = setTimeout('EF.HoverLead.showModal()', EF.HoverLead.Private._timeout);
		test = setTimeout('if(!EF.HoverLead.checkForLoginInit()){EF.HoverLead.showModal();}', EF.HoverLead.Private._timeout);
		
		
            },
            resetTimer: function () {
		        if(_showHover)
		             EF.HoverLead.Init('/splash/HoverLead.aspx');
            },
            killTimer: function (timer) {
                try {
                    clearTimeout(test);
                } catch (err) { }
            },
            checkForLoginInit: function() {
		
                if(document.getElementById('CloseWindowCtl') != null && document.getElementById('CloseWindowCtl').href=="javascript:TB_remove();EF.HoverLead.resetTimer();")
		{
		    return true; 
		}
                else
                    return false;
            },
            Init: function (url, timeout, width, height, iframe,isScroll,wrapper) {
                /* Create counter cookie, if nec. */
		
                if (!EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count")) {
                    EF.Global.Utilities.CookieManager.Bake("EFFEDCK", "Count=0", "180");
                }
                if (EF.Global.Utilities.CookieManager.Check("EFLD", "Viewed", "True") || EF.Global.Utilities.CookieManager.Check("EFFEDCK", "Count", "3")) return /*silently*/;
                EF.HoverLead.Private._liveball = url;
                EF.HoverLead.Private._timeout = timeout || 45000;
                EF.HoverLead.Private._width = width || 389;
                EF.HoverLead.Private._height = height || 585;
                EF.HoverLead.Private._iscroll = isScroll || 0;
                EF.HoverLead.Private._wrapper = wrapper || 'FrameWrapper'
                EF.HoverLead.Private._iframe = iframe || 'ctl00_ContentPlaceHolder1_HoverFrame'
		_showHover = true;
                _frame='FrameWrapper';
		
                this.setTimer();		
                
            },
            FlashInit: function () {
                return EF.HoverLead.Private._temp = new this.Private()
            }
        
    }
}
//EF.HoverLead.Private._showHover = false;
