﻿// <!--

function isValidEmail(val, emailValidationRegExp) {
	return (val.match(emailValidationRegExp) != null);
}

// CAN NOT USE THIS FUNCTION - IT IS A jQuery Function
//function $(id) {
    //return document.getElementById(id);
//}

function $$(id) {
	return document.getElementById(id);
}

function trim(value) {
    return rtrim(ltrim(value));
}

function ltrim(value) {
    var v_length = value.length;
    if (v_length < 1) {
        return "";
    }
    var w_space = String.fromCharCode(32);
    var strTemp = "";

    var iTemp = 0;

    while (iTemp < v_length) {
        if (value.charAt(iTemp) != w_space) {
            strTemp = value.substring(iTemp, v_length);
            break;
        }
        iTemp = iTemp + 1;
    } //End While

    return strTemp;

}

function rtrim(value) {
    var w_space = String.fromCharCode(32);
    if (v_length < 1) {
        return "";
    }

    var strTemp = value;
    var v_length = value.length;
    var iTemp = v_length;

    while (iTemp > 0) {
        if (value.charAt(iTemp) != w_space) {
            strTemp = value.substring(0, iTemp);
            break;
        } else if (iTemp == 1) {
            strTemp = "";
            break;
        } else {
            iTemp = iTemp - 1;
        }
    } //End While

    return strTemp;
}

function isEmail(elm, emailValidationRegExp) {
	return (elm.value.match(emailValidationRegExp) != null);	
} 

function isFilled(elm) {
	if (elm.value == "" || elm.value == null)
		return false;
	return true;
}

function clickControlOnEnter(event, id) {
	if (isEnter(event)) {
		document.getElementById(id).click();
		return false;
	}
}

function isEnter(event) {
	if (event.keyCode == 13) {
		return true;
	}
	return false;
}

function manageSiteSkin() {
    var d = new Date();
    var day = d.getDate();
    var backgroundWidth = 2000;
    var backgroundOffCenter = 0;
    var offset = (document.body.clientWidth - backgroundWidth - backgroundOffCenter) / 2;
    var isIe6 = ($.browser.msie && $.browser.version.substr(0, 1) < 7);
    
    if (d.getMonth() === 9 && d.getFullYear() === 2010) {
        if (day == 4) {
            $(document.body).css('background', '#60649f url(http://media.salemwebnetwork.com/thefish2/ads/Meaningful_Skin_TheFish.jpg) no-repeat ' + offset + 'px 0');
            $(document.body).css('background-attachment', 'fixed');
            $(document.body).append("<img alt='' src='http://view.atdmt.com/481/view/261869534/direct/01/' />");
            if (!isIe6) {
                $(".logo a img").attr("src", "http://media.salemwebnetwork.com/TheFish2/sys/gr/the-fish-transparent.png");
            }
        }
    }

    if (d.getMonth() === 10 && d.getFullYear() === 2011) {
        if (day > 17 && day < 28) {
            $(".logo a img").attr("src", "http://media.salemwebnetwork.com/TheFish2/ads/thefish_thankslogo.jpg");
        }
//        if (day == 28) {
//            if (!isIe6) {
//                $(".logo a img").attr("src", "http://media.salemwebnetwork.com/TheFish2/ads/thefish-friday.png");
//            }
//        }
    }
}

function WireTooltips() {
    $(".htmlTooltip").each(function () {
        var tooltip = $(this);
        var offsetY = -10; // default for vertical positioning
        var offsetX = 66;  // default for horizontal positioning

        // get the tooltip override attr's, if they exist
        if (tooltip.find(".TooltipAttributes").length > 0) {
            var dataStr = tooltip.find(".TooltipAttributes").val();
            var attributes = JSON.parse(dataStr);

            // override defaults
            offsetY = attributes.offsetY;
            offsetX = attributes.offsetX;
        }

        tooltip.tooltip({ offset: [offsetY, offsetX] });
    })
};




$(document).ready(function () {
    manageSiteSkin();
    WireTooltips();
});

// -->
