
function unescapeHTML(html) {
    var htmlNode = document.createElement("DIV");
    htmlNode.innerHTML = html;
    if(htmlNode.innerText)
        return htmlNode.innerText; // IE
    return htmlNode.textContent; // FF
}

function jax(Ddata, Uurl, Ssuccess)
{
    $.ajax({
        url: Uurl,
        cache: false,
        type: "POST",
        data: Ddata,
        dataType:"xml",
        beforeSend: function(XMLHttpRequest) {if (this.data == null) {this.data = "none" } },
        success: function(msg) {Ssuccess(msg)},
        //complete: function(XMLHttpRequest, textStatus){ 
        //    if (XMLHttpRequest.status==200) { Ssuccess(XMLHttpRequest.responseText); }
        //    else { alert('The server had to refresh and logged everyone out. Please copy any unsaved data and log back in. Status:' + XMLHttpRequest.status); }
        //},
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
             $.post("/logerror.asmx/SaveError", {errorData: XMLHttpRequest.responseText, LocInfo: XMLHttpRequest.getAllResponseHeaders(), ErrorThrown: errorThrown, TextStatus: textStatus },  
                function(msg) {eval( $('string',msg).text() ); }
            );
        }
            
    });
}

function Ping()
{ 
    jax(null, "/login/login.asmx/Ping", function(msg) {eval( $('string',msg).text() );});
}


//to currency
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
        num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}

$().ready(function() {
    
    tips();
    $("input[@type=radio]").css({border:"none"});
    
}); 


function tips() {
if ($.Tooltip != null){
    $('.tip').Tooltip({
		    track: true,
		    delay: 0,
		    showURL: false,
		    showBody: " - "
        }); 
    }
}

function bellows(topdog, headers)
        {
            $(topdog + " " + headers).unbind('click').css({'font-weight': 'normal'});
            $(topdog + " " + headers)
                .attr('showing', 'false')
                .click(function() {
                if ($(this).attr('showing') == 'false')
                { 
                    $(this).parent().siblings().children(headers).attr('showing', 'false')
                    $(this).attr('showing', 'true');
                    $(this).css({'font-weight': 'bold'})
                    $(this).next().slideDown('fast').css({'padding-left':'10px'}); 
                    $(this).parent().siblings().children(headers).css({'font-weight': 'normal'}).next().slideUp('fast'); 
                 }
                 else
                 { 
                    $(this).css({'font-weight': 'normal'}).next().slideUp('fast');
                     $(topdog + " " + headers).unbind('click');
                     bellows(topdog, headers); 
                }
            });
            $(topdog + " " + headers).next().hide(); 
        }
       
       
//scrolling
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function scrollPos()
{
	if ((f_scrollTop() + (f_clientHeight()/2) - 400 ) > 50)
	{
		return (f_scrollTop() + (f_clientHeight()/2) - 400 ) ;
	}
	else
	{
	return 50;
	}
}
 
function doScroll() {

		$("#Loading").css("top", f_scrollTop());
		 
		//alert(f_scrollTop());
}

window.onscroll = doScroll;
