//custom js link states
function changeBtn(type, object) {
	if (type=="ro") object.style.backgroundPosition="0px -"+object.offsetHeight+"px";
	else if (type=="on") object.style.backgroundPosition="0px -"+object.offsetHeight*2+"px";
	else object.style.backgroundPosition="0px 0px";
}

// the function to clear prepopulated text on input field
<!--
function clear_text(object) {
object.value = "";
object.focus();}
//-->


// recipe details print pop-up
function popSmall(url) {
	newwindow=window.open(url,'name','width=450','height=600','scrollbars=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}





$(document).ready(function() {
    //Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    //Mars.Tooltip(".help-ttip");
});

/* 	Mars.Tooltip object - builds a tooltip with its lower left corner positioned over the trigger
- requires only the class name of the tool tip trigger
- "message" of the tooltip should be placed within a title tag on the tool tip trigger
*/
var Mars = {};

Mars.Tooltip = function(trg_class) {
    var self = this;
    var trgs = $(trg_class);

    self.build = function() {
        trgs.each(function(i) {
            var msg = $(this).attr('title');
            var trg_ID = this.id + "_tt";

            var html = '<div id="' + trg_ID + '" class="tt-container">';
            html += '<img src="i/ttip_top.png" class="tt-top" />';
            html += '<div class="tt-body">';
            html += '<img src="i/ttip_close_btn.gif" class="tt-close-btn" />';
            html += '<h3 class="sifr-roman">' + msg + '</h3>';
            html += '</div>';
            html += '<img src="i/ttip_btm.png" class="tt-btm" />';
            html += '</div>';

            self.populate(this, html);
        });
    }

    self.populate = function(trg, tt) {
        $(tt)
            .insertAfter(trg)
            .css('left', -1000000); // positioned off screen rather than hidden, so supersleight png fix can work in IE 6

        self.display(trg);
    }

    self.position = function(trg) {
        var tPos = $(trg).position().top;
        var lPos = $(trg).position().left;
        var tt = $(trg).next();

        // currently this will position the tooltip's lower left corner just over the trigger
        tt.css({
            'top': parseInt(tPos) - (parseInt(tt.height()) - (parseInt($(trg).height()) + parseInt($(trg).css('margin-top')))),
            'left': parseInt(lPos)
        });
    }

    self.display = function(trg) {
        $(trg).click(function() {

            self.position(trg); // must run on click, otherwise position() will not get right values in webkit browsers
            
            $('.tt-container').hide();
            var tt = '#' + $(this).attr('id') + '_tt';
            $(tt)
            .show()
            .find('.tt-close-btn').click(function() {
            $('.tt-container').hide();
            });
        });
    }

    return self.build();
}

function doTandC() {
    windso('TermsandConditions.aspx', 680, 480);
}
function windso(argline, height, width) {
    var sStr = ",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no";
    if (window.screen) {
        var aw = screen.availWidth - 30;
        var ah = screen.availHeight - 50;
        sStr = "width=" + width + ",height=" + height + sStr;
        sStr += ",left=" + ((aw - width) / 2);
        var nTop = (ah - height) / 2;
        if (nTop < 0)
            nTop = 0;
        sStr += ",top=" + nTop;
    }
    window.open(argline, "printWin", sStr);
}
