/**
 * @copyright 2009 Impiger Technologies Pvt. Ltd
 * @package EasyCallNow Webscript library
 * @license copyrighted & restricted
 * @version 1.0.1
 */
Ecn = {
    version: '1.0.1'
};

// for old browsers
window["undefined"] = window["undefined"];


/**
 * @class Ecn
 * @classDescription singleton
 */
Ecn.apply = function(object, config, defaults){
    if (defaults) {
        Ecn.apply(object, defaults);

    }
    if (object && config && typeof config == 'object') {
        for (var params in config) {
            object[params] = config[params];

        }
    }
    return object;

};

(function(){
    var autoId = 0;

    var userAgent = navigator.userAgent.toLowerCase();

    var isDTDStrict = document.compatMode == "CSS1Compat", isBrowserOpera = userAgent.indexOf("opera") > -1, isBrowserChrome = userAgent.indexOf("chrome") > -1, isBrowserSafari = !isBrowserChrome && (/webkit|khtml/).test(userAgent), isBrowserSafari3 = isBrowserSafari && userAgent.indexOf('webkit/5') != -1, isBrowserIE = !isBrowserOpera && userAgent.indexOf("msie") > -1, isBrowserIE7 = !isBrowserOpera && userAgent.indexOf("msie 7") > -1, isBrowserIE8 = !isBrowserOpera && userAgent.indexOf("msie 8") > -1, isBrowserGecko = !isBrowserSafari && !isBrowserChrome && userAgent.indexOf("gecko") > -1, isBrowserGecko3 = isBrowserGecko && userAgent.indexOf("rv:1.9") > -1, isStyleBorderBox = isBrowserIE && !isDTDStrict, isOSWindows = (userAgent.indexOf("windows") != -1 || userAgent.indexOf("win32") != -1), isOSMac = (userAgent.indexOf("macintosh") != -1 || userAgent.indexOf("mac os x") != -1), isOSLinux = (userAgent.indexOf("linux") != -1), isSecure = window.location.href.toLowerCase().indexOf("https") === 0;


    // remove css image flicker
    if (isBrowserIE && !isBrowserIE7) {
        try {
            document.execCommand("BackgroundImageCache", false, true);

        }
        catch (e) {
        }
    }

    Ecn.apply(Ecn, {
        isDTDStrict: isDTDStrict,
        isBrowserOpera: isBrowserOpera,
        isBrowserChrome: isBrowserChrome,
        isBrowserSafari: isBrowserSafari,
        isBrowserSafari3: isBrowserSafari3,
        isBrowserIE: isBrowserIE,
        isBrowserIE7: isBrowserIE7,
        isBrowserIE8: isBrowserIE8,
        isBrowserGecko: isBrowserGecko,
        isBrowserGecko3: isBrowserGecko3,
        isStyleBorderBox: isStyleBorderBox,
        isOSWindows: isOSWindows,
        isOSMac: isOSMac,
        isOSLinux: isOSLinux,
        isSecure: isSecure,
        onReady: function addLoadEvent(func){
            var oldonload = window.onload;

            if (typeof window.onload != 'function') {
                window.onload = func;

            }
            else {
                window.onload = function(){
                    if (oldonload) {
                        oldonload();

                    }
                    func();

                }
            }
        },
        includeCss: function(url)
        {
            // Create the script tag
            var scriptObj = document.createElement("link");

            // Add script object attributes
            scriptObj.setAttribute("rel", "stylesheet");

            scriptObj.setAttribute("title", "EasyCallNow Widget Style");

            //scriptObj.setAttribute("media", "screen, print");

            scriptObj.setAttribute("type", "text/css");

            //scriptObj.setAttribute("charset", "utf-8");

            scriptObj.setAttribute("href", url);
				var headEl = document.getElementsByTagName("head").item(0);
            headEl.appendChild(scriptObj);

        }
    });


    Ecn.config = {
        hostDomain: 'www.easycallnow.com',
        hostProtocol: 'http',
        clientDomain: document.domain,
        clientProtocol: function(){
            if (window.location.href.toLowerCase().indexOf("https") === 0) {
                return 'https';

            }
            else {
                return 'http';

            }
        },
        serviceDomain: 'www.easycallnow.com',
        serviceProtocol: 'http'
    }

    Ecn.urls = {
        logo: Ecn.config.hostProtocol + '://' + Ecn.config.hostDomain + '/images/widget/powered.jpg',
        link: Ecn.config.hostProtocol + '://' + Ecn.config.hostDomain + '/'
    }

})();


Ecn.renderWidgetUrl = function()
{
	var buttonEl = document.getElementById('ecn_widget_button');
	if ( typeof buttonEl != 'undefined' && buttonEl!= null)
	{
		//buttonEl.innerHTML = buttonText || '';
		elCls = buttonEl.getAttribute('class');
		if ( typeof elCls == 'undefined' || elCls == null )
		{
			//buttonEl.setAttribute('class','ecn_widget_button');
			//buttonEl.setAttribute('class','ecn_widget_button_blocked');
			buttonEl.className = 'ecn_widget_button_blocked';
		}
		buttonEl.setAttribute('title',"Sorry, this service has been disabled for the moment!");
	}
	else
	{
		var bodyEl = document.getElementsByTagName('body')[0];
		var buttonEl = document.createElement('div');
		//buttonEl.innerHTML = buttonText || '';
		buttonEl.setAttribute('id','ecn_widget_button');
		//buttonEl.setAttribute('class','ecn_widget_button_blocked');
		buttonEl.className = 'ecn_widget_button_blocked';
		buttonEl.setAttribute('title',"Sorry, this service has been disabled for the moment!");
		bodyEl.appendChild(buttonEl);
	}
	buttonEl.onclick = function()
	{
		alert("Sorry, this service has been disabled for the moment!");
	};
}

Ecn.init = function()
{
	Ecn.includeCss(Ecn.config.hostProtocol+"://"+Ecn.config.hostDomain+"/css/widget-url.css");
	Ecn.renderWidgetUrl();
}
Ecn.onReady(Ecn.init);
//var ecn_widget_url = new Ecn.renderWidgetUrl();
