﻿/*
SAVEOLOGY LIBRARIES
THIS DOCUMENT HAS BEEN CREATED TO BE THE ONE SINGLE WHITELABEL-ABLE CORE JAVASCRIPT FILE.  HAVING ONE FILE WILL REDUCE REQUESTS, AND HELP ORGANIZE WHERE CODE IS COMING FROM.
THIS FILE IS ORGANIZED IN THE FOLLOWING MANNER
1. LIBRARIES - These are the utilities and ui tools used for the site.
2. SAVEO - These are saveology specific modules, Search Widget, Dialog box
3. OLD CODE - This is all the old saveology modules
4. INIT - All code starting up when page is done loading and DOM is ready
*/


// 1. LIBRARIES
/////////////////////////////////////////////////////////////////////////////////
(function($) {
    $.fn.checked = function() {
        return $(this).is(':checked');
    };
    
    $.debug = function(text, type) {
		if (window.console && window.console.log) {
			if (type == 'info' && window.console.info) {
				window.console.info(text);
			}
			else if (type == 'warn' && window.console.warn) {
				window.console.warn(text);
			}
			else {
				window.console.log(text);
			}
		}
	};
	
	$.fn.enterKey = function(fn, ig) {
		if (!fn) return this.keyup();
		this.keydown(function(e) {
			if (e.keyCode == 13) {
				if (e.preventDefault) e.preventDefault();
				fn();
			}
		});
	};
	
	$.slideMessage = function(msg, type, time) {
	    time = time || 6;
        var ctn = $(".ui-message-global");
	    if (!ctn.length) {
	        $("body").prepend('<div class="ui-message-global" style="display: none; position: fixed; top: 0; left: 0; right: 0; padding: 15px; background: #fff; border: 1px solid #ccc; font-size: 14px; z-index: 9000"></div>');
	        var ctn = $(".ui-message-global").first();
	    }
	    if (type == "error") ctn.css({'background': '#fcc', 'color': '#900', 'border-color': '#900'});
	    else if (type == "success") ctn.css({'background': '#cfc', 'color': '#090', 'border-color': '#090'});
	    else ctn.css({'background': '#eee', 'color': '#444', 'border-color': '#bbb'});
	    if (!msg) {
	        ctn.slideUp(200, function() {ctn.height("auto"); });
	        return;
	    }
	    ctn.text(msg);
	    ctn.slideDown(200, function() {ctn.height("auto"); });
	    clearTimeout($.slideMessageTimer);
	    $.slideMessageTimer = setTimeout(function() {
	        ctn.slideUp(200);
	    }, time * 1000)
	};
	$.slideMessageTimer;
    
    $.dialog = function(opts) {
        var defaults = {
            text: null,
            useDialog: null
        };
        // INSTANCE
        var c = $.extend(defaults, opts);
    
        c.show = function() {
            c.bg.show().animate({opacity: .5 }, {queue: false});
            c.window.show().animate({opacity: 1 }, {queue: false});
        };
        
        c.hide = function() {
            c.bg.animate({opacity: 0 }, {queue: false, duration: 200, complete: function() {c.bg.hide();} });
            c.window.animate({opacity: 0 }, {queue: false, duration: 200, complete: function() {c.window.hide();} });
        };
        
        c.generate = function() {
            var layout = '<div class="dialog-wrapper"><div class="dialog-window"></div><div class="dialog-bg"></div></div>';
            
            var bod = $("body");
            bod.prepend(layout);
            c.container = $("div.dialog-wrapper").first();
            c.bg = c.container.children().last();
            c.window = c.container.children().first();

            bod.css("position", "relative");
            c.bg.hide().css("opacity", 0);
            c.window.hide().css("opacity", 0);
            
        };
        
        // INIT
        c.init = function() {
            if (c.useDialog) {
                c.stuff;
            } else {
                c.generate();
            }
        };
        c.init();
        
        
        return c;   
    
    };
})(jQuery);


// 2. SAVEO
/////////////////////////////////////////////////////////////////////////////////


// SAVEO NAMESPACE
var saveo;

(function($) {

    saveo = function() {
        var a = {};

      
        // EXTENDS DIALOG
        a.searchDialog = function() {
            var b = {};
            
            b.init = function() {
                b.dialog = $.dialog();
                b.dialog.container.addClass("searchDialog");
              
                // TESTING
                b.dialog.show();
            };
            return b;
        } ();
        
        
        // SEARCH WIDGET
        a.searchWidgets = [];
        a.searchWidget = (function() {
            var b = {};
            b.widgets = [];
            b.init = function(selector) {
                b.instances = $(selector);
           
                b.instances.each(function() {
                    $.debug("SAVEOLOGY - SEARCH WIDGET - INITED " + selector);
                    $.debug(this);
                    var ctn = $(this);

                    var c = {
                        ctn: ctn,
                        fields: {
                            address: ctn.find(".search-address, input[name='address']").first(),
                            apt: ctn.find(".search-apt, input[name='apt']").first(),
                            zip: ctn.find(".search-zip, input[name='zip']").first()
                        },
                        submitBtn: ctn.find(".form-submit, .submit, input[type='submit']").first()
                    };
                    $.debug(c);
                    
                    c.submit = function() {
                        $.debug("SAVEOLOGY - SEARCH WIDGET - SUBMITTED");
                        var valid = true, errorMessage, errField;
                        var data = {};
                        var f = c.fields;
                        
                        // HIDE MESSAGE
                        $.slideMessage();

                        var v;
                        // VALIDATE ADDRESS
                        if (valid) {
                            v = f.address.val();
                            if (typeof (v) == "undefined" || !v.length || v == f.address.attr("title")) {
                                valid = false;
                                errorMessage = "Please enter an address";
                                errField = f.address;
                            }
                        }
                        // VALIDATE ZIP
                        if (valid) {
                            v = f.zip.val();
                            if (typeof (v) == "undefined" || !v.length || v == f.zip.attr("title")) {
                                valid = false;
                                errorMessage = "Please enter a valid zip code";
                                errField = f.zip;
                            }
                        }

                        if (!valid) {
                            $.debug("SAVEOLOGY - SEARCH WIDGET - FORM ERROR");
                            //$.dialog({text: errorMessage});
                            $.slideMessage(errorMessage, "error", 10);
                            errField.parent().addClass("field-error");
                            errField.focus();
                            
                            return false;
                        }
                        // SUCCESS
                        else {
                            $.slideMessage();
                            // BUILD DATA
                            data = {
                                address: c.fields.address.val(),
                                apt: c.fields.apt.val(),
                                zip: c.fields.zip.val()
                            };
                            
                            saveo.compareOffers(data);
                        }
                    };

                    // INIT

                    // EVENTS
                    var f = c.fields;
                    for (x in f) {
                        f[x].enterKey(c.submit);
                    }

                    c.submitBtn.attr("href", "javascript: void(0)");
                    // CLICK EVENTS
                    c.submitBtn.click(function(e) {
                        e.preventDefault();
                        c.submit();
                        return false;
                    });

                    
                    b.widgets.push(c);

                }); // b.instances
                
      
            }; // b.init   
            return b;     
            
        })(); // SEARCH WIDGET

        return a;
    } ();




    // SUBMIT COMPARE OFFERS FORM FROM DATA
    saveo.compareOffers = function(data) {
        // VALIDATE
        if (data.apt == "Apartment" || data.apt == "Apartamento") data.apt = "";

        var ru = "/CompareOffers/default.aspx";
        var url;

        url = ru + '?a=' + data.address.replace(/\s/g, "+") + ',';
        if (data.apt) url += data['apt'];
        url += ',,,' + data.zip;
        //if (newcust) url += '&IsNewCustomer=' + newcust;
        //if (mvDate) url += '&MoveDate=' + mvDate;
        url += '&c=39&p=995037&nt=Category&nv=null&sc=null';
        //if (selectedCategory) url += "&nv=" + selectedCategory + '&sc=' + selectedCategory;


        // BUILD URL
        /*
    
    url += "?a=" + data['address'].replace(/\s/g, "+") + ",";
        if (data['apt']) url += data['apt'];
        url += ",,," + data['zip'];
        //url += ",,," + "516,,EMERSON,,ST,,,,,,,,,,,False";
        url += "&ua=" + data['address'].replace(/\s/g, "+") + ",,,," + data['zip'];
        url += "&c=39&p=995037&nt=Category&sch=0&nv=2087&sc=2087&s=null";
        */


        // http://localhost:90/CompareOffers/default.aspx?a=516+EMERSON+ST,,PHILADELPHIA,PA,19111,1935,,516,,EMERSON,,ST,,,,,,,,,,,False&ua=516+EMERSON+ST,,PHILADELPHIA,PA,19111&c=16383&p=2096053983&sch=0&nt=Category&nv=2087&sc=2087&s=b89072e1-4fa9-4faf-94ef-f2b2d17191d5&thm=1800cabletv


        // REDIRECT TO URL WITH QUERYSTRING
        window.location = url;
    };



})(jQuery);


// 3. OLD CODE
/////////////////////////////////////////////////////////////////////////////////


// FROM validate.js
// PLEASE REWRITE THIS
function isValidEmail(sEmailAddress) {
    var regexPattern = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i;

    if (sEmailAddress.match(regexPattern))
        return true;
    else
        return false;
}

function CustomEmailValidator(sender, args) {
    if (isValidEmail(args.Value))
        args.IsValid = true;
    else
        args.IsValid = false;
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}


// FROM phone.js
// PLEASE REWRITE THIS
//Container to group similar methods and prevent naming collisions...
var Phone = {};
    
//Dynamically loads an external javascript file and sets callback upon load...
Phone.LoadScript = function(source, callback) {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = source;
    
    if (callback != null)
    {
        script.onreadystatechange = callback;
        script.onload = callback;
    }

    var head = document.getElementsByTagName("HEAD");
    if (head[0] != null) head[0].appendChild(script);
}

//Container to group similar methods and prevent naming collisions...
Phone.SetSource = {};

//Sends a source phone number to the server, checking for required Prototype.Ajax along the way...
Phone.SetSource.Invoke = function(url, phone) {
if (typeof (Ajax) == 'undefined') 
    {
        Phone.LoadScript("/_resources/javascript/phone.js", 
            function() { Phone.SetSource.SendToServer(url, phone); });
    } else {
        Phone.SetSource.SendToServer(url, phone);
    }
}

//Handles an asynchronous response from Phone.SetSource.SendToServer...
Phone.SetSource.ServerResponse = function(xmlHttpRequest, responseHeader) {
    var xmlMessage = xmlHttpRequest.responseXML;
    
    //Do nothing with response...
}
    
//Sends an updated source phone number to the server using Prototype.Ajax...
Phone.SetSource.SendToServer = function (url, phone) {
    if (typeof(Ajax) != 'undefined') {
        var params = "phone=" + phone;
        
        //Invoke Prototype.Ajax...
        var ajaxRequest = new Ajax.Request(url, {
                method:       "get", 
                parameters:   params, 
                asynchronous: true,
                onComplete:   Phone.SetSource.ServerResponse
            });
    }
}



// FROM common.js
// PLEASE REWRITE THIS
//////////////////////

/*
function $(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++)
            elements.push($(arguments[i]));
        return elements;
    }
    if (typeof element == 'string')
        element = document.getElementById(element);
    return Element.extend(element);
}
*/
/*
function $(element) {
    return document.getElementById(element);
}
*/
// TAKES PLACE OF OLD $
var df = function(element) {
    return document.getElementById(element);
};

function createObjectCallback(obj, fn) {
    return function() { fn.apply(obj, arguments); };
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/;";
  //  if (document.domain != "localhost")
     //   cookie += " domain= .imperialfire.com;";
   // document.cookie = cookie;

}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

/* Client-side access to querystring name=value pairs
Version 1.3
28 May 2008
	
License (Simplified BSD):
http://adamv.com/dev/javascript/qslicense.txt
*/
function Querystring(qs) { // optionally pass a querystring to parse
    this.params = {};

    if (qs == null) qs = location.search.substring(1, location.search.length);
    if (qs.length == 0) return;

    // Turn <plus> back to <space>
    // See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
    qs = qs.replace(/\+/g, ' ');
    var args = qs.split('&'); // parse out name/value pairs separated via &

    // split out each name=value pair
    for (var i = 0; i < args.length; i++) {
        var pair = args[i].split('=');
        var name = decodeURIComponent(pair[0]);

        var value = (pair.length == 2)
			? decodeURIComponent(pair[1])
			: name;

        this.params[name] = value;
    }
}
Querystring.prototype.get = function(key, default_) {
    if(key == null)
        return location.search.substring(1, location.search.length);
    else{
        var value = this.params[key];
        return (value != null) ? value : default_;
    }
}
Querystring.prototype.contains = function(key) {
    var value = this.params[key];
    return (value != null);
}


//*******************************//
function alertSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    window.alert('Width = ' + myWidth);
    window.alert('Height = ' + myHeight);
}
function getWindowHeight() {
    return jQuery(window).height();
}
function getWindowWidth() {
    return jQuery(window).width();
}
/*
document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b' + cl + '\\b');
    var elem = this.getElementsByTagName('*');
    for (var i = 0; i < elem.length; i++) {
        var classes = elem[i].className;
        if (myclass.test(classes)) retnode.push(elem[i]);
    }
    return retnode;
};
*/

function IsNullOrEmpty(checkValue)
{
    if ((window[checkValue] == undefined) ||(typeof checkValue == 'undefined') || (window[checkValue] == null) ||(typeof checkValue == 'null'))
    {
        return true;
    }
    else
    {
        return false;
    }
}

//findcss uses CSS selectors in js
// use findCSS ('selectorHere')
/*
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 5=9(a,b){1S{5.P=b?b:X;7 r=q();7 c=a.1o(",");8(c.m==1){r=5.1g(a)}p{v(7 i=0;i<c.m;i++){r=5.17(r,5.1g(5.1t(c[i])))}}6 r}1Z(e){6"1U 1R 1Q 1O 1L 2e 2c 29"}};9 N(a,b){b=b?b:X;8(!N.V[a]){N.V[a]=5(a,b)}6 N.V[a]}9 24(a){5.1c=o;7 r=5(a);5.1c=k;6 r}N.V={};5.1g=9(a){5.L=q();7 b=5.1C(a);7 c=k;7 i=0;7 x=5.1c?q(k,0):5.1B(b);8(x[1]===o||x[1]>0){7 r=q();7 d=x[0].1v();1A(d){r.u(d);d=x[0].1v()}8(x[1]===o){6 r}p{i=x[1]%2==0?x[1]:x[1]-1;8(i%2==0){c=5.I(b[i])}}}p{c=5.I(b[0]);7 e=5.1p(c,5.P);8(e!==k){7 r=e;i=1}p{7 r=5.S(c,5.P.15(c[1]))}}v(;i<b.m;i++){8(i%2==0){r=5.S(c,r)}p{c=5.I(b[i+1]);r=5.1m(b[i],c[1],r)}}6 r};5.1C=9(a){7 b=q();7 d="";7 e=k;7 f=0;7 l=a.m;1A(f<l){7 c=a.C(f);8(e==k&&(c=="+"||c==">"||c=="~")){b.u(d);b.u(c);d=""}p{8(e==k&&c==" "){7 g=a.C(f+1);7 h=a.C(f-1);8(g!=" "&&h!=" "&&h!=">"&&g!=">"&&g!="+"&&h!="+"&&h!="~"&&g!="~"){b.u(d);b.u("16");d=""}}p{8(c=="]"){e=k;d+=c}p{8(c=="["){e=o;d+=c;8(a.C(f+1)=="@"){f++}}p{d+=c}}}}f++}b.u(d);6 b};5.I=9(a){7 b="";7 d=q("1b");7 e=0;7 c=a.C(0);8(c=="#"||c==":"||c=="."||c=="["){a="*"+a}v(7 f=0;f<a.m;f++){c=a.C(f);8(e==0&&(c=="#"||c==":"||c=="."||c=="[")){d.u(b);d.u(c);b=""}p{8(c=="("){b+=c;e++}p{8(c==")"){b+=c;e--}p{b+=c}}}}d.u(b);6 d};5.S=9(a,b){7 r=q();8(a.m==2){6 b}v(7 j=0;j<b.m;j++){7 c=o;v(7 i=2;i<a.m;i+=2){8(!5.11[a[i]](b[j],a[i+1])){c=k;W}}8(c){r[r.m]=b[j]}}6 r};5.1m=9(a,b,c){7 r=q();v(7 i=0;i<c.m;i++){r=5.17(r,5.1G[a](c[i],b))}6 r};5.1B=9(a){8(X.1F){7 b="";7 c;7 d="//";10:v(7 i=0;i<a.m;i++){8(i%2==0){c=5.I(a[i]);v(7 j=0;j<c.m;j+=2){8(5.y[c[j]]){7 s=5.y[c[j]](c[j+1]);8(!s){i--;W 10}d+=s}p{i--;W 10}}b+=d}p{8(5.y[a[i]]){d=5.y[a[i]]}p{W 10}}}8(i>0){6 q(X.1F(b,5.P,1e,26.25,1e),i==a.m-1?o:i)}p{6 q(k,0)}}6 q(k,0)};5.1p=9(a,b){8(a.m==2){6 b.15(a[1])}p{8(a.m==4&&a[2]=="#"){7 c=b.23(a[3]);8(c.M==a[1].J()||a[1]=="*"){6 q(c)}}}6 k};5.17=9(a,b){7 c=b.m;7 r=a;v(7 i=0;i<c;i++){8(!5.1E(r,b[i])){a.u(b[i])}}6 a};5.1E=9(b,c){7 d=b.m;v(7 i=0;i<d;i++){8(b[i]==c){6 o}}6 k};5.1D=9(a){7 r=q();v(7 i=0;i<a.w.F.m;i++){8(a.w.F[i]!=a){r.u(a.w.F[i])}}6 r};5.1a=9(a){7 c=5.E(a.w);v(7 i=0;i<c.m;i++){8(c[i]==a){6 i}}6 k};5.E=9(a){8(!a.19){a.19=5.K(a.F,"22",1)}6 a.19};5.K=9(b,c,d){7 r=q();v(7 i=0;i<b.m;i++){8(b[i][c]==d||d=="*"){r.u(b[i])}}6 r};5.U=9(a,b,c){8(!5.L[a]){5.L[a]=a.1o(b)}v(7 i=0;i<5.L[a].m;i++){8(5.L[a][i]==c){6 o}}6 k};5.1t=9(a){6 a.1x(/^\\s+|\\s+$/g,"")};5.D={"1w-A":9(a){7 c=5.E(a.w);6 c[0]==a},"1u-A":9(a){7 c=5.E(a.w);6 c[c.m-1]==a},"1y-A":9(a){7 c=5.E(a.w);6 c.m==1},"1z":9(a){6 a.F.m==0},"21-A":9(a,b){8(b=="1s"||b=="1r"){6 5.D[b](a)}7 c=5.E(a.w);6 c[b-1]==a},"1s":9(a){6 5.1a(a)%2!=0},"1r":9(a){6 5.1a(a)%2==0},"T":9(a,b){7 c=5.I(b);7 d=5.S(c,q(a));8(d.m==1){6 k}6 o},"20":9(a){6 a.w?k:o},"1d":9(a,b){8(a.1q){7 c=a.1q}p{7 d=a.1Y.1x(/<[\\1W-1V-Z\\/]+>/g,"")}b=b.B(1,-1);6 d.O(b)==-1?k:o},"1T":9(a){8(1i.1l.1k){7 b=1i.1l.1k.14(1);8(a.13==b){6 o}}6 k},"Q":9(a){8(a.Q){6 o}6 k},"R":9(a){8(a.R){6 o}6 k}};5.1G={"16":9(a,b){6 a.15(b)},">":9(a,b){6 5.K(a.F,"M",b.J())},"+":9(a,b){7 r=q();8(a.1j){r.u(a.1j)}8(a.1n){r.u(a.1n)}6 5.K(r,"M",b.J())},"~":9(a,b){6 5.K(5.1D(a),"M",b.J())}};5.y={"1b":9(a){6 a},"#":9(a){6"[@13=\'"+a+"\']"},".":9(a){6"[1d(1P(\' \', @1X, \' \'), \' "+a+" \')]"},"[":9(a){7 b=5.11["["](1e,a,o);8(b===o){6"[@"+a+"]"}p{8(5.y.12[b[1]]){6 5.y.12[b[1]](b[0],b[2])}}6 k},"12":{"=":9(a,b){6"[@"+a+"=\\""+b+"\\"]"},"*=":9(a,b){6"[1d(@"+a+",\'"+b+"\')]"},"^=":9(a,b){6"[1N-1K(@"+a+",\'"+b+"\')]"},"$=":9(a,b){6"[1M-1K(@"+a+",\'"+b+"\')]"}},":":9(a){8(5.y.18[a]){6 5.y.18[a]}6 k},"18":{"1w-A":"[T(1h-G::*)]","1u-A":"[T(Y-G::*)]","1y-A":"[T(1h-G::* 1I Y-G::*)]","1z":"[1H(*) = 0 2d (1H(1J()) = 0 1I 2b(1J(), \' \\t\\r\\n\', \'\') = \'\')]","Q":"[@Q]","R":"[@R]"},"16":"//",">":"/","+":"./Y-G::*[1]","~":"./Y-G::*"};5.11={"1b":9(a,b){8(a.M!=b.J()&&b!="*"){6 k}6 o},".":9(a,b){6 5.U(a.2a," ",b)},"#":9(a,b){8(a.13!=b){6 k}6 o},":":9(a,b){8(5.D[b]){6 5.D[b](a)}p{7 c=b.28(/[a-z\\-]+/)[0];7 d=b.B(c.m+1,-1);8(5.D[c]){6 5.D[c](a,d)}p{6 k}}},"[":9(a,b,c){7 d=b.O("=");8(d==-1){7 e=b.B(0,-1);8(c){6 o}6 a.27(e)}p{7 f=b.B(0,-2);7 g=f.14(d+2);7 h=f.B(d-1,d+1);8(5.1f[h]){d=d-1}p{h="="}7 i=f.B(0,d);8(c){6 q(i,h,g)}6 5.1f[h](a,i,g)}}};5.1f={"=":9(a,b,c){6 a.H(b)==c},"*=":9(a,b,c){7 d=a.H(b);8(d&&d.O(c)!=-1){6 o}6 k},"~=":9(a,b,c){7 d=a.H(b);8(d&&5.U(d," ",c)){6 o}6 k},"|=":9(a,b,c){7 d=a.H(b);8(d&&5.U(d,"-",c)){6 o}6 k},"^=":9(a,b,c){7 d=a.H(b);8(d&&d.O(c)==0){6 o}6 k},"$=":9(a,b,c){7 d=a.H(b);8(d){8(d.14(d.m-c.m)==c){6 o}}6 k}};',62,139,'|||||findCSS|return|var|if|function|||||||||||false||length||true|else|Array||||push|for|parentNode||xpath||child|slice|charAt|pseudos|fakeChildren|childNodes|sibling|getAttribute|buildIStack|toUpperCase|filterByValue|temp|nodeName|findCSSc|indexOf|node|checked|disabled|filterSelector|not|splitAndCheck|cached|break|document|following||stk|selectors|att_xpath|id|substring|getElementsByTagName|space|merge|pseudo_xpath|children|findElement|tag|noX|contains|null|att_types|findSingle|preceding|window|nextSibling|hash|location|filterCombinator|previousSibling|split|filterQuick|innerText|odd|even|trim|last|iterateNext|first|replace|only|empty|while|filterXpath|buildStack|findAllSiblings|inA|evaluate|combinators|count|or|text|with|in|ends|start|error|concat|an|was|try|target|There|zA|sa|class|innerHTML|catch|root|nth|nodeType|getElementById|findCSSx|UNORDERED_NODE_ITERATOR_TYPE|XPathResult|hasAttribute|match|syntax|className|translate|CSS|and|you'.split('|'),0,{}))
*/

function getProvider(productKey){
    var keyInfo;
    var provider = "";
    if (productKey != null && productKey != "")
    {
        keyInfo = productKey.split("=");
        if (keyInfo.length > 0){provider = keyInfo[2];}
        provider = provider.replace("&id", "");
        return provider;
    }
}
function getPhoneNumber(){
    var phoneNum = "Customer Service";
    var phoneDiv = jQuery('#divPhoneNum');
    if (phoneDiv.length)
    {
        if(phoneDiv.html() != null && phoneDiv.html() != ""){ phoneNum = phoneDiv.html(); }
    }
    return phoneNum;
  }
  function getPromo() {
    var promoNum = "Promo";
    var promoDiv = jQuery('#divpromo');
    if (promoDiv.length) {
      if (promoDiv.html() != null && promoDiv.html() != "") { promoNum = promoDiv.html(); }
    }
    return promoNum;
  }

function notSellingProvider(provider){
    if (provider == "ATT" || provider == "Verizon" || provider == "Vonage" || provider == "Qwest" || provider == "Dish")
    {
        return true;
    } else{
        return false;
    }
    KillSplash();
}
  // ****************************************************************
    // * Resusable overlay for popup windows
    // ****************************************************************

function ReplaceEmbedWithSpan(isReplaceBack)
{
 var arSelect = document.getElementsByTagName("embed");
 
 for(var i=0;i<arSelect.length;i++)
 {
 if(!isReplaceBack)
 {
       arSelect[i].style.marginLeft = "-5000px";
  }
     else
   {    arSelect[i].style.marginLeft = "";}
 }
}




function toggle(obj) {
       var el;
       if (typeof obj == 'string')
           el = document.getElementById(obj);
       else
           el = obj;
    if (el.style.display != 'none') {
        el.style.display = 'none';
    }
    else {
        el.style.display = 'block';
    }
}

    

function toggleVisibility(obj, initialValue) {
    var el;
    if (typeof obj == 'string')
        el = document.getElementById(obj);
    else
        el = obj;
    if ((el.style.visibility == '') && !(initialValue === undefined)) {
        el.style.visibility = initialValue;
    }
    if (el.style.visibility != 'hidden') {
        el.style.visibility = 'hidden';
    }
    else {
        el.style.visibility = 'visible';
    }
}

//**********  Start Dictionary Section **********//
/*  var providerRedirect = new Dictionary();
providerRedirect.Add("comcast", "http://www.onlinecomcast.com");
providerRedirect.Add("charter", "http://www.buycharter.com");
providerRedirect.Add("cox", "http://www.buycox.com");
providerRedirect.Add("brighthouse", "http://www.buybrighthouse.com");
providerRedirect.Add("insight", "http://www.buyinsightnow.com");
providerRedirect.Add("optimum", "http://www.buyoptimum.com");
providerRedirect.Add("time_warner", "http://www.buytimewarnercable.com");

var keys = providerRedirect.Keys;

function Lookup(key) {
    key = key.toString().toLowerCase();
    var newUrl = 'http://www.saveology.com';
    for (var i = 0; i < this.Keys.length; i++) {
        if (this[key] != null)
            newUrl = (this[key]);
        break;
    }
    return newUrl;
}

function Delete() {
    for (c = 0; c < Delete.arguments.length; c++) {
        this[Delete.arguments[c]] = null;
    }
    // Adjust the keys (not terribly efficient)
    var keys = new Array()
    for (var i = 0; i < this.Keys.length; i++) {
        if (this[this.Keys[i]] != null)
            keys[keys.length] = this.Keys[i];
    }
    this.Keys = keys;
}

function Add() {
    for (c = 0; c < Add.arguments.length; c += 2) {
        // Add the property
        this[Add.arguments[c]] = Add.arguments[c + 1];
        // And add it to the keys array
        this.Keys[this.Keys.length] = Add.arguments[c];
    }
}

function Dictionary() {
    this.Add = Add;
    this.Lookup = Lookup;
    this.Delete = Delete;
    this.Keys = new Array();
}
*/
//**********  End Dictionary Section **********//
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

    

// END common.js


// SUPPRESS ERRORS FORM OLD CODE
if (!s) var s = {};
if (!s.t) s.t = function() {};


// 4. INIT
/////////////////////////////////////////////////////////////////////////////////

// IMPLEMENTATION ON STARTUP

jQuery(function($) {

    if (saveo.searchWidget && saveo.searchWidget.init)
        saveo.searchWidget.init(".section-searchForm");

});
