jQuery.fn.pngfix = function(setting) {
    var sizeMethod = setting;
    return this.each(function(sizeMethod){
        this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='" + setting + "')";
        this.src = "/Common/Images/x.gif";
    });
};
jQuery.fn.textboxblur = function() {
  return this.each(function(){
    jQuery(this).attr('title', jQuery(this).val()).focus(
        function(){
            if(jQuery(this).val() == jQuery(this).attr('title')){
            jQuery(this).val('');
        }}).blur(
        function(){
            if($(this).val() == ''){
            $(this).val($(this).attr('title'));
        }});
  });
};
$(function(){
    // IE6 Specific code - Suckerfish class on hover and PNG alpha transparency
    if (($.browser.msie) && ($.browser.version=='6.0')) {
        $("img[@src*=.png], img.png, input[@src*=.png]").pngfix('scale');
    }
    if ($.browser.msie) {
        $('#masthead ul.navigation li').hover(function(){$(this).addClass('sfhover');},function(){$(this).removeClass();});
    }
    $('#base li:eq(0), #masthead .navigation li:eq(0)').css('border','0');
	$("a[rel='external']").attr("target","_blank");
	$("#panelmeasure").click(function(){location.href='/Opportunity/You.htm'});
	$("#opNewBusiness").click(function(){location.href='/Opportunity/NewBusiness.htm'});
	$("#opMediumBusiness").click(function(){location.href='/Opportunity/ExistingBusiness.htm'});
	$("#opTelco").click(function(){location.href='/Opportunity/Enterprise.htm'});
	$("#opOrganisationAssociation").click(function(){location.href='/Opportunity/Enterprise.htm'});
	$('#CustomerSignUp input').click(function(){$('#custom').val("");})
	$(".arrow").append('&nbsp;<img src="/Images/arrow-red-grey.png" alt="" class="png" />');
	$(".larrow").wrapInner("<span></span>").prepend('<img src="/Images/arrow-red.png" alt="" class="png" />&nbsp;');
	$("#linklist a").hover(function(){$("img", this).attr("src", $("img", this).attr("src").split('_off').join('_on'));$("strong", this).css("backgroundImage", $("strong", this).css("backgroundImage").split('_off').join('_on'));}, function(){$("img", this).attr("src", $("img", this).attr("src").split('_on').join('_off'));$("strong", this).css("backgroundImage", $("strong", this).css("backgroundImage").split('_on').join('_off'));});
	//$("input:text").textboxblur();
	$(".rollover, input.submit").hover(function(){$(this).attr("src", $(this).attr("src").split('_off').join('_on'))}, function(){$(this).attr("src", $(this).attr("src").split('_on').join('_off'))});
	$('#answers dd').hide();
	$("#answers dt").click(function(){$('#answers dd').hide();$(this).next().show("slow");});
	$('table.edit tr:odd td').css({backgroundColor: "#fafafa"});
	$('#back').click(function(){history.back();});
});
function checkSubmit(e){
    $('#CustomerSignUp input').each(function(){$(this).attr({checked: false})});
    var characterCode
    if(e && e.which){
        e = e;
        characterCode = e.which;
    } else {
        e = event;
        characterCode = e.keyCode;
    }
    if(characterCode == 13){calcIncome();return false;}
}
function calcIncome(){
    var cust = ($('#custom').val() != "") ? $('#custom').val() : $('#CustomerSignUp input:checked').val();
    if(!Number(cust)){alert("Not a valid number");return false;}
    
    $('#IncomeGraph').show();
    
    var upperlimit = cust*111*12;
    var lowerlimit = cust*111;
    var upperclean = (parseInt((upperlimit+'').slice(0,2))+1)*Math.pow(10,parseInt((upperlimit+'').length-2));
    var cumulative = (12*(lowerlimit+upperlimit))/2; // arithmetic progression, total sum equals (n*(a1 + an))/2
    
    var axislist = '';
    for (var i=10; i>0; i--) {
        axislist += ('<li>$'+(upperclean/10)*i+'</li>');
    }
    axislist += ('<li>0</li>');
    
    $("#axisDollar").empty().append(axislist);
    $("#graphBase em").empty().append("$"+cumulative).animate({ color: "#000000" }, 500).animate({ color: "#ffffff" }, 500);
    
    $("#axisMonth span").animate({height: "0%", backgroundColor: "#e2e2e2"}, 500).each(
        function(i){
        $(this).animate({height: (((i+1)*lowerlimit)/upperclean)*200}, 1000).attr({title: "$"+(i+1)*lowerlimit});
        }
    )
    var ran=Math.floor(Math.random()*4);
    switch(ran) {
        case 0:
        $("#axisMonth span:odd").animate({ backgroundColor: "#336699" }, 500); //blue
        $("#axisMonth span:even").animate({ backgroundColor: "#6699cc" }, 500);
        break;
        case 1:
        $("#axisMonth span:odd").animate({ backgroundColor: "#cc3333" }, 500); //red
        $("#axisMonth span:even").animate({ backgroundColor: "#ff6666" }, 500);
        break;
        case 2:
        $("#axisMonth span:odd").animate({ backgroundColor: "#339966" }, 500);//green
        $("#axisMonth span:even").animate({ backgroundColor: "#669966" }, 500);
        break;
        case 3:
        $("#axisMonth span:odd").animate({ backgroundColor: "#ffcc66" }, 500);//pink
        $("#axisMonth span:even").animate({ backgroundColor: "#ff9900" }, 500);
        break;
    }
    
}
Math.rand = function(l,u) {
    return Math.floor((Math.random() * (u-l+1))+l);
}
