﻿var doLog = true;

// toggle for tab content boxes
function toggleTabContentByPrefix(oThisMenuLink, iTabContentId, sTabContentPrefix) {

    var oThisContentDiv = document.getElementById(sTabContentPrefix + '_' + iTabContentId);

    $('#' + sTabContentPrefix + '_' + iTabContentId).siblings('div.tabbedboxcontent').andSelf().removeClass('onstate');
    $('#' + sTabContentPrefix + '_' + iTabContentId).addClass('onstate');
    $('#' + oThisMenuLink.id).siblings('a.tabbedboxmenulink').removeClass('onstate');

    // open or close (toggle) proper tab link
    if (!dom_hasClassName(oThisMenuLink, 'onstate')) {
        dom_addClassName(oThisMenuLink, 'onstate');
        LogImpressions(iTabContentId, sTabContentPrefix);
    }
    return false;
}


function getElement(id) {
    var element = document.getElementById ? document.getElementById(id) : (document.all ? document.all(id) : null)
    return element;
}

function LogImpressions(iTabContentId, sTabContentPrefix) {
    if (iTabContentId == 1 && doLog == true) {
        var panelId = '#' + sTabContentPrefix + '_' + iTabContentId;
        var ids = new Array();
        jQuery(panelId + ' img').each(function(i) {
            var id = $(this).parents("a:first").attr('ObjectId')
            ids[ids.length] = id;
        });
        var objIds = ids.join("|");
        var soapEnvelop = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                                        <soap:Body>   \
                                            <LogMostPopularImpression xmlns=\"http://theknot.com/\"> \
                                              <siteId>" + properties.siteId + "</siteId> \
                                              <pageId>" + properties.pageId + "</pageId> \
                                              <objectTypeId>" + properties.objectTypeId + "</objectTypeId> \
                                              <userId>" + properties.userId + "</userId> \
                                              <objectId>" + objIds + "</objectId> \
                                            </LogMostPopularImpression > \
                                        </soap:Body> \
                                   </soap:Envelope>";

        jQuery.ajax({
            type: "POST",
            url: "http://" + properties.url + "/odb/StatisticsWebService.asmx",
            DataType: "xml",
            data: soapEnvelop,
            contentType: "text/xml; charset=\"utf-8\""
        });
    }
    if (iTabContentId == 2 && doLog == true) {
        var panelId = '#' + sTabContentPrefix + '_' + iTabContentId;
        var ids = new Array();
        jQuery(panelId + ' img').each(function(i) {
            var id = $(this).parents("a:first").attr('ObjectId')
            ids[ids.length] = id;
        });
        var objIds = ids.join("|");
        var soapEnvelop = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                                    <soap:Body>   \
                                        <LogMostSharedImpression xmlns=\"http://theknot.com/\"> \
                                          <siteId>" + properties.siteId + "</siteId> \
                                          <pageId>" + properties.pageId + "</pageId> \
                                          <objectTypeId>" + properties.objectTypeId + "</objectTypeId> \
                                          <userId>" + properties.userId + "</userId> \
                                          <objectId>" + objIds + "</objectId> \
                                        </LogMostSharedImpression > \
                                    </soap:Body> \
                               </soap:Envelope>";

        jQuery.ajax({
            type: "POST",
            url: "http://" + properties.url + "/odb/StatisticsWebService.asmx",
            DataType: "xml",
            data: soapEnvelop,
            contentType: "text/xml; charset=\"utf-8\""
        });
    }
}

function get_Favorite_cookie( )
{
    return get_cookie('favorites');
}


function set_Favorite_cookie( favorites )
{
    var exp_m = 1;
   
    var date = new Date();
    var exp_y =  date.getFullYear();
     
    if( 12 > date.getMonth()  )
        exp_m =  date.getMonth() + 1;
    else
        exp_y = exp_y + 1;
        
    
    set_cookie('favorites',favorites, exp_y, exp_m, date.getDay, '/odb/themes/nationalgowns', null);
}


function get_cookie ( cookie_name )
{
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
{
  var cookie_string = name + "=" + escape ( value );

  if ( exp_y )
  {
    var expires = new Date ( exp_y, exp_m, exp_d );
    cookie_string += "; expires=" + expires.toGMTString();
  }

  if ( path )
        cookie_string += "; path=" + escape ( path );

  if ( domain )
        cookie_string += "; domain=" + escape ( domain );
  
  if ( secure )
        cookie_string += "; secure";
  
  document.cookie = cookie_string;
}

function delete_cookie ( cookie_name )
{
  var cookie_date = new Date ( );  // current date & time
  cookie_date.setTime ( cookie_date.getTime() - 1 );
  document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
}