var isIE4 = false;
var isNav4 = false;
var isNav6 = false;

function _el(id) {return document.getElementById(id);}
function _x() {
	if(typeof ActiveXObject!="undefined"){
		try{return new ActiveXObject("Microsoft.XMLHTTP")}
		catch(a){}
	}
	if(typeof XMLHttpRequest!="undefined"){return new XMLHttpRequest()}
	return null	
}
function kb(a){this.xmlhttp=a}
kb.prototype.generate=function(a){
	var c=this.xmlhttp;
	if (!c) return;
	var str = "";
	c.open("POST",a,false);
	c.onreadystatechange=function(){
		if(c.readyState==4){
			str = c.responseText;
			c.onreadystatechange=_nullFunction;
		}
	};
	c.send(null);
	return str;
};
function _nullFunction(){}
function strToInt(str) {
	str = str.replace(/\%|\$|\,/g,'')
  	var num = 0
  	if (!isNaN(parseInt(str)))
    	num = parseInt(str);
	return num;
}

function strToDbl(str,decimals)
{ str = str.replace(/\%|\$|\,/g,'')
  var num = 0
  if (!isNaN(parseFloat(str)))
    num = parseFloat(str);

  if (!decimals) {
  	return num;
  }else{
	  if (   isNaN( parseInt(decimals) )   ) decimals = 2;
	  num = Math.floor( num * Math.pow(10,decimals) + 0.50000000001 );
	  cents = num % Math.pow(10,decimals);
  	  num = Math.floor( num / Math.pow(10,decimals) ).toString();
	  for (var i = decimals - 1; i > 0; i--)
		if (cents < Math.pow(10,i) )
		  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 (num + (decimals > 0 ? '.' + cents: ''));
  }
}
function formatCurrency(num, decimals)
{
  if (   isNaN( parseInt(decimals) )   ) decimals = 2;

  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num)) num = "0";

  sign = (   num == ( num = Math.abs(num) )   );
  num = Math.floor( num * Math.pow(10,decimals) + 0.50000000001 );
  cents = num % Math.pow(10,decimals);
  num = Math.floor( num / Math.pow(10,decimals) ).toString();

  for (var i = decimals - 1; i > 0; i--)
    if (cents < Math.pow(10,i) )
      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 + (decimals > 0 ? '.' + cents: '') + ( sign ? '' : ')' )  );
}
function formatDate(inputElement)
{
    var dateTxt = inputElement.value;
    if (dateTxt.charCodeAt(dateTxt.length-1) == "160")
      dateTxt = dateTxt.substr(0,dateTxt.length-1);

    var testDate=new Date(Date.parse(dateTxt));
    if (!testDate.getYear())
       inputElement.value = '';
    else if (inputElement.value.substr(inputElement.value.length-3,1) == '/' ||
            inputElement.value.substr(inputElement.value.length-3,1) == '\\' ||
            inputElement.value.substr(inputElement.value.length-3,1) == '-')
    {  inputElement.value = (testDate.getMonth()+1) + "/" + testDate.getDate() + "/"
                    + (Math.floor(new Date().getFullYear() / 1000) * 1000 + testDate.getFullYear() - 1900)
    }else {
      inputElement.value = (testDate.getMonth()+1) + "/" + testDate.getDate() + "/" + testDate.getFullYear();
    }

}
function formatPercent(num, decimals)
{
  if (   isNaN( parseInt(decimals) )   ) decimals = 2;

  num = num.toString().replace(/\$|\,/g,'');

  if(isNaN(num)) num = "0";

  num = num * 100;

  sign = (   num == ( num = Math.abs(num) )   );
  num = Math.floor( num * Math.pow(10,decimals) + 0.50000000001 );
  cents = num % Math.pow(10,decimals);
  num = Math.floor( num / Math.pow(10,decimals) ).toString();

  for (var i = decimals - 1; i > 0; i--)
    if (cents < Math.pow(10,i) )
      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 + (decimals > 0 ? '.' + cents: '') + ( sign ? '' : ')' ) + '%' );
}
function setSelect(x,id) {
	if (x==null||x=='undefined') return;
	for (var i=0; i<x.options.length; i++) {
		if (x.options[i].value==(isNaN(id)?id:parseInt(id))) x.options[i].selected=true;
	}	
}
function setRadio(x,id) {
	if (x==null||x=='undefined') return;
	if (x.length > 0) {
		for (var i = 0;i<x.length;i++) {
			if (x[i].value==id) {
				x[i].checked=true;
				break;
			}
		}
	}else{
		if (x.value==id) x.checked=true;
	}
}
function winHeight(n) {
	if (window.screen.availHeight) return window.screen.availHeight - 100;
	else return n;
}
function winWidth(n) {
	if (window.screen.availWidth) return window.screen.availWidth - 100;
	else return n;
}
function doError(msg) {
	if (typeof msg == "undefined") return true;
	if (msg.length>6&&msg.substring(0,6).toUpperCase()=='ERROR:') alert(msg);
	else return true;
	return false;
}
function setBrowser()
{
    if (navigator.appVersion.charAt(0) == "4")
    {
        if (navigator.appName.indexOf("Explorer") >= 0)
        {
            isIE4 = true;
        }
        else
        {
            isNav4 = true;
        }
    }
    else if (navigator.appVersion.charAt(0) > "4")
    {
        isNav6 = true;
    }
}

function getIdProperty( id, property )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "##" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (isNav4)
    {
        return document[id][property];
    }
    else
    {
        return document.all[id].style[property];
    }
}

function setIdProperty( id, property, value )
{
    if (isNav6)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }
    }
    else if (isNav4)
    {
        document[id][property] = value;
    }
    else if (isIE4)
    {
         document.all[id].style[property] = value;
    }
}

function doSelectHref(s) {
	var val = s.options[s.selectedIndex].value;
	if (val!=''&&val!='-') window.location.href=val;
}
function selectAll(s,chk) {
	var f = s.getElementsByTagName('INPUT');
	for (var i=0;i<f.length;i++){
 		var e=f[i];
 		if ((e.name != 'allbox') && (e.type=='checkbox')){
 			e.checked=chk;
 		}
 	}	
}

