﻿function DetailView(companyId, companyTitle) {
    createTip('aMoreInfo_' + companyId, 'dvMoreInfo_' + companyId, 2);

    $('aMoreInfo_' + companyId).observe('click', function () {
        //alert(companyId+'+'+companyTitle);
        if (Prototype.Browser.IE && !navigator.userAgent.match(/MSIE 9/)) {
            $('aMoreInfo_' + companyId).prototip.hide();
        }
        alterStyle();
        //      if(_gat){
        //          var pageTracker = _gat._getTracker("<asp:literal id='ltlAnalytics' runat='server' />");
        //          pageTracker._trackPageview('/clicks/localCompanies/'+companyId+'-'+companyTitle);
        //      }
    });

    if (Prototype.Browser.IE) {
        $('aMoreInfo_' + companyId).observe('prototip:shown', function () {
            //alert('test');
            alterStyle();
        });
    }
    return false;
}

function createTip(target, tip, style) {

    switch (style) {
        case 1:
            new Tip($(target), $(tip), {
                title: '',
                border: 1,
                borderColor: '#a3b6c4',
                radius: 1,
                width: 350,
                closeButton: true,
                showOn: 'click',
                hideOn: { element: 'closeButton', event: 'click' },
                stem: 'bottomMiddle',
                hook: { target: 'topMiddle', tip: 'bottomMiddle' },
                //fixed: true,
                viewport: true,
                offset: { x: 0, y: 0 }
            });
            break;
        case 2:
            new Tip($(target), $(tip), {
                title: '',
                border: 1,
                borderColor: '#a3b6c4',
                radius: 1,
                width: 350,
                closeButton: true,
                showOn: 'click',
                hideOn: { element: 'closeButton', event: 'click' },
                fixed: true,
                stem: 'topLeft',
                hook: { tip: 'topLeft', mouse: true },
                offset: { x: 0, y: 8 }

            });
            break;
        default:
            new Tip($(target), $(tip), {
                title: '',
                border: 1,
                borderColor: '#a3b6c4',
                radius: 1,
                width: 350,
                closeButton: true,
                showOn: 'click',
                hideOn: { element: 'closeButton', event: 'click' },
                stem: 'bottomMiddle',
                //stem: 'topLeft',
                hook: { tip: 'topLeft', mouse: false },
                //fixed: true,
                viewport: true,
                offset: { x: 0, y: 0 }
            });
    } //switch
}

function alterStyle() {
    /*Work around to shift popups' stem div position up so that triangle stem would not be separated by the shadow div
    left -1px is for IE to display offset correctly
    */
    var divsImg = $$('div.prototip_StemImage');
    //alert(divsImg.size());

    divsImg.each(function (e) {
        var url = e.getStyle('background');
        if (url.indexOf('bottomleft') > -1) {
            e.parentNode.setStyle(
                { position: "relative", top: "-18px", left: "-1px" }
            );
        }
        else {
            e.parentNode.setStyle(
                { position: "absolute", top: "0px", left: "-1px" }
            );
        }
    });
}

function trackDetailLink(companyId, companyTitle) {


}

function toggleContent(id) {
    Effect.toggle(id, 'appear');
    //    $(id).show();
    //    $(id).hide();
    return false;
}

function _claimListing(url, compId, type, catId, compName, phone, address, city, state, country) {
    var _url = $H(
            {
                compId: compId,
                t: type,
                catId: catId,
                compName: compName,
                phone: phone,
                add: address,
                city: city,
                state: state,
                country: country
            }
        ).toQueryString();
    window.open(url + "?" + _url);
}

function _claimListing2(url, compId, type, catId, compName, phone, address, city, state, zip, country) {
    alert('test');
    var form = document.createElement("form");
    form.setAttribute("method", "post");
    form.setAttribute("action", url);
    form.setAttribute("target", "_blank");
    var params = $H({
        compId: compId,
        t: type,
        catId: catId,
        compName: compName,
        phone: phone,
        add: address,
        city: city,
        state: state,
        zip: zip,
        country: country
    });
    params.each(function (param) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("name", param.key);
        hiddenField.setAttribute("value", param.value);
        form.appendChild(hiddenField);
        document.body.appendChild(form);    // Not entirely sure if this is necessary                   
    });
    form.submit();
}

//function _claimListing(compId, url)
//{
//    window.open(url+"?compid="+compId.toString());
//}

//function ClaimAcxiomCompanyAjax(compId, url, catId){
//     new Ajax.Request(
//        url,
//        {   
//            parameters: $H(
//                    {
//                     compId: compId,
//                     categoryId: catId,
//                     compName:,
//                     Address:,
//                     City:,
//                     State:,
//                     Zip:,
//                     CountryCode:,
//                    }
//                ).toQueryString();
//                //'id=' +
//                //encodeURIComponent(element.id)
//                //'initialValue='+$('targetElement').innerHTML
//            onSuccess: setCategoryAttributes
//        }
//    );
//}

function evalFlash() {
    for (var i = 3; i <= 9; i++) {
        eval('MM_VB_FlashCanPlay' + i + ' = 0;');
    }

    if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && navigator.appVersion.indexOf("Win") != -1) {
        var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

        if (!plugin) {
            document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
            document.write('on error resume next \n');
            document.write('MM_VB_FlashCanPlay3 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3")))\n');
            document.write('MM_VB_FlashCanPlay4 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4")))\n');
            document.write('MM_VB_FlashCanPlay5 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5")))\n');
            document.write('MM_VB_FlashCanPlay6 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6")))\n');
            document.write('MM_VB_FlashCanPlay7 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7")))\n');
            document.write('MM_VB_FlashCanPlay8 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8")))\n');
            document.write('MM_VB_FlashCanPlay9 = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9")))\n');
            document.write('</SCR' + 'IPT\> \n');
        }
    }
}

function AVP_ActivateFlash(htmlCode) {
    document.writeln(htmlCode);
}

function AVP_ActivateFlashByVersion(flashCode, alternateCode, requiredVersion) {
    if (!alternateCode || alternateCode.length == 0) {
        document.writeln(flashCode);
    }

    else {
        var MM_contentVersion = requiredVersion;
        var MM_PluginVersion = 0;
        var MM_FlashCanPlay = 0;

        var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

        if (plugin) {
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");

            for (var i = 0; i < words.length; ++i) {
                if (isNaN(parseInt(words[i]))) {
                    continue;
                }

                MM_PluginVersion = words[i];
            }

            MM_FlashCanPlay = (MM_PluginVersion >= MM_contentVersion);
        }

        else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && navigator.appVersion.indexOf("Win") != -1) {
            if (MM_VB_FlashCanPlay3 && requiredVersion <= 3) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay4 && requiredVersion <= 4) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay5 && requiredVersion <= 5) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay6 && requiredVersion <= 6) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay7 && requiredVersion <= 7) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay8 && requiredVersion <= 8) { MM_FlashCanPlay = 1; }
            else if (MM_VB_FlashCanPlay9 && requiredVersion <= 9) { MM_FlashCanPlay = 1; }
            else { MM_FlashCanPlay = 0; }
        }

        if (MM_FlashCanPlay) {
            document.writeln(flashCode);
        }

        else {
            document.writeln(alternateCode);
        }
    }
}


