﻿(function($) {
$(document).ready(function() {
    $('#byTag').show();
    //perform form transformation
    $('#search, #more-than-categories, #loginDetails').jqTransform({ imgPath: 'images/' });
    //replace search by tag background on focus
    $('#search .search-offers .jqTransformInputWrapper input').focus(function() { jQuery(this).parent().parent().css('background-position', '0 -1400px'); }).blur(function() { jQuery(this).parent().parent().css('background-position', '0 -1450px'); });

    //open categories drop down selection in a new window
    $("#more-than-categories .jqTransformSelectWrapper li a").click(function() {
        var location = $("#cmbInsurance option").eq($(this).attr('index')).val();
        location = location.match("(http://[^/]*)(.*)");
        //dcsMultiTrack("DCS.dcssip", location[1], "DCS.dcsuri", location[2], "DCS.dcsref", window.location, "WT.ti", "Offsite:" + location[0], "WT.dl", "24", "WT.tx_s", "0.00", "WT.tx_e", "p", "WT.nv", "");
        if (location[0] != 0) { window.open(location[0], 'external'); }
    });

    //Select external links, open them in a new window/tab
    $("#frmForm a[href^='http://']").not("a[href^='http://" + window.location.hostname + "']").not("a[href^='http://www." + window.location.hostname + "']").click(function() {
        //dcsMultiTrack("DCS.dcssip", this.protocol + "//" + this.hostname, "DCS.dcsuri", this.pathname, "DCS.dcsref", window.location, "WT.ti", "Offsite:" + this.href, "WT.dl", "24", "WT.tx_s", "0.00", "WT.tx_e", "p", "WT.nv", "");
		if(jQuery.support.objectAll == false){
			//Browser sniffing: IE will return false
			var referLink = $(document.createElement('a')).hide();
			referLink.attr('href', $(this).attr('href'));
			$('.offer-redeem-details').append(referLink).trigger('click');
		} else {
			window.open(this.href, 'external');
			return false;
		}
    });
    $("a[rel='external']").click(function() {
		//dcsMultiTrack("DCS.dcssip", this.protocol + "//" + this.hostname, "DCS.dcsuri", this.pathname, "DCS.dcsref", window.location, "WT.ti", "Offsite:" + this.href, "WT.dl", "24", "WT.tx_s", "0.00", "WT.tx_e", "p", "WT.nv", "");
		window.open(this.href, 'external');
		return false;
    });
});
})(jQuery.noConflict());