﻿function DetailView(companyId, companyTitle){
    createTip('aMoreInfo_'+companyId, 'dvMoreInfo_'+companyId, 2);
    
    $('aMoreInfo_'+companyId).observe('click', function() {
      //alert(companyId+'+'+companyTitle);
      if (Prototype.Browser.IE){
        $('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){
    var pageTracker = _gat._getTracker("<asp:literal id='ltlAnalytics' runat='server' />");
    pageTracker._trackPageview('/clicks/localCompanies/'+companyId+'-'+companyTitle);
    return false;

}

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
//        }
//    );
//}