﻿var $j = jQuery.noConflict();

// pop up window
function dbqPopUp(url, width, height) {
    props = window.open(url, 'poppage', 'toolbars=0, scrollbars=0, location=0, statusbars=0, menubars=0, resizable=0, width=' + width + ', height=' + height + ', left = 100, top = 100');
}

// Forms
function formInput_focus(e) {
    $j(e).css("border-color", "#ffd867");
}

function formInput_blur(e) {
    $j(e).css("border-color", "#9baeb5");
}

function blogSearchOnClick(elem) {
    if (elem.value == "Search this blog...") {
        elem.value = "";
    }
}

function blogSearchBlur(elem) {
    if (elem.value == "") {
        elem.value = "Search this blog...";
    }
}

//<![CDATA[
var cot_loc0=(window.location.protocol == "https:")? "https://secure.comodo.net/trustlogo/javascript/cot.js" :
"http://www.trustlogo.com/trustlogo/javascript/cot.js";
document.writeln('<scr' + 'ipt language="JavaScript" src="'+cot_loc0+'" type="text\/javascript">' + '<\/scr' + 'ipt>');
//]]>

$j(document).ready(function() {
    
    $j("#TopBarPane .menuBarContent .feedback").mouseover(function() {
        $j("#TopBarPane .menuBarContent #menuBarDropDown").fadeIn("slow");
    }).mouseout(function() {
    $j("#TopBarPane .menuBarContent #menuBarDropDown").hide();
});

$j("#TopBarPane .menuBarContent #menuBarDropDown").mouseover(function() {
    $j("#TopBarPane .menuBarContent #menuBarDropDown").show();
}).mouseout(function() {
    $j("#TopBarPane .menuBarContent #menuBarDropDown").hide();
});

$(".businessListingPurchase table tr:last td").css("border-bottom-width", "0");

// Homepage picture view
var currentImg = 0;
var isOnLoad = true;
var totalImages = $("div.hpPicView a.hpPicViewLink").size();
var lastInterval = setInterval(function() { rotateImage(nextImg()); }, 10000);
$(".hpPicView .links .link").removeClass("linkActive");
$(".hpPicView .links .link:eq(0)").addClass("linkActive");

$("div.hpPicView a.hpPicViewLink:eq(0)").click(function() {
    clickImage(0);
    currentImg = 0;
    clearInterval(lastInterval);
    lastInterval = setInterval(function() { rotateImage(nextImg()); }, 10000);
});

$("div.hpPicView a.hpPicViewLink:eq(1)").click(function() {
    clickImage(1);
    currentImg = 1;
    clearInterval(lastInterval);
    lastInterval = setInterval(function() { rotateImage(nextImg()); }, 10000);

});

$("div.hpPicView a.hpPicViewLink:eq(2)").click(function() {
    clickImage(2);
    currentImg = 2;
    clearInterval(lastInterval);
    lastInterval = setInterval(function() { rotateImage(nextImg()); }, 10000);

});


function nextImg() {
    if (isOnLoad == true) {
        isOnLoad = false;
        currentImg = currentImg + 1;
        return currentImg;
    } else {

        if ((currentImg + 1) == (totalImages)) {
            currentImg = 0;
            return 0;
        } else {
            currentImg = currentImg + 1;
            return currentImg;
        }
    }
}

function rotateImage(nextImg) {
    if (nextImg == 0) {
        $("div.hpPicView img:eq(" + (totalImages - 1) + ")").hide();
    } else {
        $("div.hpPicView img:eq(" + (nextImg - 1) + ")").hide();
    }
    $("img#hpPicView_" + (nextImg + 1)).fadeIn(1100);
    $(".hpPicView .links .link").removeClass("linkActive");
    $(".hpPicView .links .link:eq(" + nextImg + ")").addClass("linkActive");
}

function clickImage(whichImg) {

    $(".hpPicView .links .link").removeClass("linkActive");
    $(".hpPicView .links .link:eq(" + whichImg + ")").addClass("linkActive");
    $("div.hpPicView img").hide();
    $("img#hpPicView_" + (whichImg + 1)).fadeIn(1100);
}


});

var IE = document.all ? true : false

if (!IE) document.captureEvents(Event.MOUSEMOVE)

var tempX = 0
var tempY = 0

var stNames = new Array("Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming");

var stAbbs = new Array("AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY");

function getStateName(abbr) {
    for (var i = 0; i < stAbbs.length; i++) {
        if (stAbbs[i] == abbr) {
            var stateIndex = i;

        }
    }

    return stNames[stateIndex];

}

//State Map
function highlightState(state) {

    document.getElementById("stateMap").src = "/Portals/0/images/" + state + ".png";
    document.getElementById(state).onmousemove = getMouseXY;

    var stateAbbr = state.charAt(10).toUpperCase() + state.charAt(11).toUpperCase();

    document.getElementById('stateMapStateBox').innerHTML = getStateName(stateAbbr);
}

function noHighlight() {
    document.getElementById("stateMap").src = "/Portals/0/images/state_map.png";
    document.getElementById('stateMapStateBox').style.display = "none";
}

function getMouseXY(e) {
    
    if (IE) { // x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft
        tempY = event.clientY + document.body.scrollTop
    } else {  // x-y pos.s if browser is NS
        tempX = e.pageX
        tempY = e.pageY
    }

    // possible negative values in NS4
    if (tempX < 0) { tempX = 0 }
    if (tempY < 0) { tempY = 0 }

    var stateBox = document.getElementById('stateMapStateBox');
    stateBox.style.display = "block";  

    stateBox.style.marginTop = tempY - 15 + "px";
    stateBox.style.marginLeft = tempX + 10 + "px";

    return true;
}
