function BrowserInfo() {
    var agent = window.navigator.userAgent;
    if (agent.indexOf("MSIE") != -1) {
        var start = agent.indexOf("MSIE");
        this.name = "MSIE";
        this.version = parseFloat(agent.substring(start + 5, agent.indexOf(";", start)));
    } else if (agent.indexOf("Firefox") != -1) {
        var start = agent.indexOf("Firefox");
        this.name = "Firefox";
        this.version = agent.substring(start + 8, agent.length);
        var firstDec = this.version.indexOf(".") + 1;
        while (this.version.indexOf(".", firstDec) != -1)
            this.version = this.version.substring(0, firstDec) + this.version.substring(firstDec).replace(".", "");
        this.version = parseFloat(this.version);
    } else {
        this.name = "Unknown";
        this.version = 0;
    }
}

var info = new BrowserInfo();
var isIE6 = (info.name == "MSIE" && info.version < 7);


function writePngImage(url, width, height, alt) {
    if (!isIE6)
        document.write("<img alt=\"" + alt + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
    else
    	document.write("<img alt=\"" + alt + "\" src=\"images/spacer.png\" style=\"width: " + width + "px; height: " + height +
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}

function writePngClass(url, width, height, alt, className) {
    if (!isIE6)
        document.write("<img alt=\"" + alt + "\" class=\"" + className + "\" src=\"" + url + "\" style=\"width: " + width + "px; height: " + height + "px;\">");
    else
    	document.write("<img alt=\"" + alt + "\" class=\"" + className + "\"  src=\"images/spacer.png\" style=\"width: " + width + "px; height: " + height +
			"px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + url + "', sizingMethod=scale);\">");
}


String.prototype.trim = function() {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


reset_form_value = function(str1, str2, oInput) {
    if (str1 == oInput.value.trim())
        oInput.value = str2;
}
reset_form_password = function(str1, str2, oInput) {
    //if(str1 == oInput.value.trim())
    //oInput.value = str2;

    if (str1 == "" && "" == oInput.value.trim()) {
    	if (oInput.className != "w150 bg_password_field")
    		oInput.className = "w150 bg_password_field";
    } else if (str1 != "") {
        if (oInput.className != "w150")
        	oInput.className = "w150";
    }
}

function launchWindow(url, width, height, title) {
    if (url != "")
        window.open(url, "preview_image", "width=" + (width + 50) + ", height=" + (height + 50) + ", location=0, menubar=1, resizable=0, scrollbars, status=0, titlebar=1, toolbar=0");
    //	return false;
}

function RefreshStateChooser(ddlStateId, ddlCountryId)
{
	document.getElementById(ddlStateId).disabled = document.getElementById(ddlCountryId).value != "US";
}







// *****************************************************************************************
//
//  Vote control
//
(function($)
{
	var $$;
	var outerPnl;
	var innerPnl;
	var maxRating = 5;
	var oldRating = 0;
	var onRatingSelectedFunc;

	//
	// .ctor
	//
	$$ = $.fn.voter = function(_onRatingSelectedFunc)
	{
		onRatingSelectedFunc = _onRatingSelectedFunc;
		outerPnl = this;
		innerPnl = $(outerPnl.children()[0]);

		innerPnl.mousemove($$.onMouseMove);
		outerPnl.mousemove($$.onMouseMove);
		innerPnl.mouseout($$.onMouseOut);
		outerPnl.mouseout($$.onMouseOut);
		outerPnl.click($$.onMouseClick);

		return this;
	};

	//
	//
	//
	$$.onMouseMove = function(e)
	{
		var p = $$.pageToClientPoint(e.pageX, e.pageY);
		var rating = $$.getRatingByClientPoint(p.x, p.y);

		$$.showRating(rating);
	};

	//
	//
	//
	$$.onMouseOut = function(e)
	{
		var p = $$.pageToClientPoint(e.pageX, e.pageY);
		if (p.x <= 0 || p.y <= 0 || p.x >= outerPnl.width() - 1 || p.y >= outerPnl.height() - 2)
			$$.showRating(oldRating);
	};


	//
	//
	//
	$$.pageToClientPoint = function(pageX, pageY)
	{
		var x = pageX - outerPnl.offset().left;
		var y = pageY - outerPnl.offset().top;

		return { x: x, y: y };
	};


	//
	//
	//
	$$.getRatingByClientPoint = function(clientX, clientY)
	{
		if (clientX <= 0 || clientY <= 0 || clientX >= outerPnl.width() || clientY >= outerPnl.height())
			return oldRating;

		var rating = Math.ceil(maxRating * (clientX / outerPnl.width()));
		rating = Math.max(1, rating);
		rating = Math.min(maxRating, rating);

		return rating;
	}


	//
	//
	//
	$$.onMouseClick = function(e)
	{
		var p = $$.pageToClientPoint(e.pageX, e.pageY);
		var rating = $$.getRatingByClientPoint(p.x, p.y);
		$$.saveRating(rating);
	};





	//
	//
	//
	$$.showRating = function(rating)
	{
		innerPnl.width(rating * outerPnl.width() / maxRating);
	};

	//
	//
	//
	$$.saveRating = function(rating)
	{
		onRatingSelectedFunc(rating);
	};


	$$.resetRating = function()
	{
		innerPnl.removeClass();
		innerPnl.addClass("starsActive");
		$$.showRating(oldRating);
	}


})(jQuery);


