function clarion_callback(){
    var PhoneDiv = document.createElement('div');
    PhoneDiv.innerHTML = 'Call Us Now at 1-866-702-0768';
    PhoneDiv.style.color = 'white';
    PhoneDiv.style.textAlign = 'center';
    PhoneDiv.style.font = 'bold 16pt verdana';
    PhoneDiv.style.marginBottom = '5px';
    PhoneDiv.setAttribute('id','icm_tracker_phone');
    document.body.insertBefore(PhoneDiv,document.body.childNodes[0]);
    document.body.style.marginTop='30px';
    var ot = document.getElementById('infoline-top');
    if (ot)
	ot.style.display='none';
    return;
}

function macdonellphotography_callback(){
    var ot = document.getElementById('id_contact_phone');
    if (ot)
	ot.innerHTML='416.800.1596';
    return;
}


var _IcmTracker = null;
var _iat = new Object({
    uid:undefined,

    GetTracker:function(_uid)
    {
        this.uid = '_icm_' + _uid;
        return this;
    },

    Init:function()
    {
    if( !this.uid )
        return false;
    var s = document.cookie;

    var ref = document.referrer

    var tpl_g = /^http\:\/\/www\.google.[a-zA-Z]{2,3}\/.*$/i
    var tpl_y = /^http\:\/\/[a-zA-Z.]{0,8}search\.yahoo.com\/.*$/i
    var tpl_m = /^http\:\/\/www\.bing.com\/.*$/i

    if(tpl_g.test(ref) || tpl_m.test(ref) || tpl_y.test(ref)) {
        document.cookie = "_icm_seo_on=on;path=/";
        document.cookie = "_icm_ad_on=on;path=/";
        //alert('seo_cookie');
        return true;
    }

    if( document.location.search.indexOf('a=y')==-1 &&
        document.location.search.indexOf('a=m')==-1 &&
        document.location.search.indexOf('a=g')==-1 &&
        s.indexOf('_icm_ad_on=on')==-1 )
        return false;
    document.cookie = "_icm_ad_on=on;path=/";
    return true;
    },

    ShowPhone:function( flds)
    {
    if (this.uid=='_icm_clarionmedical'){
	window.onload=clarion_callback;
	return true;
    }
    if (this.uid=='_icm_macdonellphotography'){
	window.onload=macdonellphotography_callback;
	return true;
    }
    
    var PhoneDiv = document.createElement('div');
    PhoneDiv.innerHTML = flds[0];
    PhoneDiv.setAttribute('id','icm_tracker_phone');
    document.body.insertBefore(PhoneDiv,document.body.childNodes[0]);
    PhoneDiv.style.font=flds[1];
    PhoneDiv.style.padding=flds[2];
    PhoneDiv.style.height=flds[3];
    PhoneDiv.style.textAlign=flds[4];
    PhoneDiv.style.border=flds[5];
    PhoneDiv.style.background=flds[6];
    PhoneDiv.style.color=flds[7];
    if (flds[8]) PhoneDiv.style.zIndex=flds[8];
    return true;
    }

});

function isICMTrackerAds(){
    var s = document.cookie;
    if( document.location.search.indexOf('a=y')==-1 &&
        document.location.search.indexOf('a=m')==-1 &&
        document.location.search.indexOf('a=g')==-1 &&
        s.indexOf('_icm_ad_on=on')==-1 
    )
	return false;
    return true;
}

function isICMTrackerSeo()
{
    var ref = document.referrer
    var s = document.cookie

    var tpl_g = /^http\:\/\/www\.google.[a-zA-Z]{2,3}\/.*$/i
    var tpl_y = /^http\:\/\/[a-zA-Z.]{0,8}search\.yahoo.com\/.*$/i
    var tpl_m = /^http\:\/\/www\.bing.com\/.*$/i

    if (tpl_g.test(ref) == false &&
        tpl_y.test(ref) == false &&
        tpl_m.test(ref) == false &&
        s.indexOf('_icm_seo_on=on') == -1
    ) {
        return false
    }
    return true;
}

function processICMTracker( clientID)
{
    if( window._iat )
    {
        _IcmTracker = _iat.GetTracker( clientID );
        if (_IcmTracker.Init())
        {
            var flds = _icm_data_str.split( ':' );
           _IcmTracker.ShowPhone( flds );
        }
    }
}

function handleICMTracker (clientID)
{
    if (window._iat)
    {
       _IcmTracker = _iat.GetTracker( clientID );
       _IcmTracker.Init();
    }
}
