<!--
function correctPNG ()
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (document.body.filters))
    {
	for(var i=0; i<document.images.length; i++)
	{
	    var img = document.images[i]
	    var imgName = img.src.toUpperCase()
	    if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	    {
		var imgID = (img.id) ? "id='" + img.id + "' " : ""
		var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		var imgStyle = "display:inline-block;" + img.style.cssText
		if (img.align == "left") imgStyle = "float:left;" + imgStyle
		if (img.align == "right") imgStyle = "float:right;" + imgStyle
		if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
		var strNewHTML = "<span " + imgID + imgClass + imgTitle
		+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
		+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		+ "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
		img.outerHTML = strNewHTML
		i = i-1
	    }
	}
    }

}

function correctPNG2 (obj)
{
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])

    if ((version >= 5.5) && (document.body.filters))
    {
	var img = obj;
	var imgName = img.src.toUpperCase()
	if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	{
	    var imgID = (img.id) ? "id='" + img.id + "' " : ""
	    var imgClass = (img.className) ? "class='" + img.className + "' " : ""
	    var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
	    var imgStyle = "display:inline-block;" + img.style.cssText
	    if (img.align == "left") imgStyle = "float:left;" + imgStyle
	    if (img.align == "right") imgStyle = "float:right;" + imgStyle
	    if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
	    var strNewHTML = "<span " + imgID + imgClass + imgTitle
	    + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
	    + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
	    img.outerHTML = strNewHTML
	    i = i-1
	}
    }

}


function source(plik)
{
    window.open(plik,"new","height=500,width=700,left=50,top=50,menubar=no,scrollbars=1,location=no,directories=no,resizable=1,fullscreen=no");
}

function show(plik)
{
    okno = window.open(plik,"show","height=600,width=900,left=0,top=0,menubar=no,scrollbars=1,location=no,directories=no,resizable=1,fullscreen=no");
}


function format_sel(v)
{

    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var sel = "<" + v + ">" + str + "</" + v + ">";
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;


    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = "<" + v + ">" + str + "</" + v + ">";
    }

    return;
}

function inserttag(v)
{
    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var sel =  "{" + v + "}" + str;
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;

    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = "{" + v + "}" + str;
    }

    return;
}

function format_sel_square(v)
{
    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var sel = "[" + v + "]" + str + "[/" + v + "]";
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;



    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = "[" + v + "]" + str + "[/" + v + "]";
    }

    return;
}
function format_sel_square_param(p, v)
{
    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var   sel = "[" + p + "]" + v + "[/" + p + "]";
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;



    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = "[" + p + "]" + v + "[/" + p + "]";
    }

    return;
}


function format_font(v,ve) {


    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var     sel = v + str + ve ;
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;




    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = v + str + ve ;
    }

    return;


}


  

function insert_link() {

    var my_link = prompt("Podaj adres URL:","http://");

    if (document.getSelection)
    {
	var strd=document.add.content.value;
	var selText = window.getSelection();
	str = selText.toString();
	selstart=document.add.content.selectionStart
	selend=document.add.content.selectionEnd
	len=selend-selstart;
	str=strd.substr (selstart, len);
	document.add.content.focus();
	var   sel = "<a href=\"" + my_link + "\">" + str + "</a>";
	if (window.RegExp)
	{
	    str = strd.replace(str, sel);
	}

	document.add.content.value = str;




    }
    else if (document.selection && document.selection.createRange)
    {
	var range = document.selection.createRange();
	var str = range.text;
	document.add.content.focus();
	var sel = document.selection.createRange();
	sel.text = "<a href=\"" + my_link + "\">" + str + "</a>";
    }


}

function insert_smile(text) {

    var item = null;
    if (document.getElementById) {
	item = document.getElementById('content');
    } else if (document.all) {
	item = document.all['content'];
    } else if (document.layers){
	item = document.layers['content'];
    }
    if (item) {
	item.focus();
	item.value = item.value + " " + text;
	item.focus();
    }
    return;
}
function mouseover(el) {
    el.className = "raised";
}

function mouseout(el) {
    el.className = "button";
}

function mousedown(el) {
    el.className = "pressed";
}

function mouseup(el) {
    el.className = "raised";
}
function Is() {
    agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.ns = ((agent.indexOf('mozilla') != -1) &&
	(agent.indexOf('spoofer') == -1) &&
	(agent.indexOf('compatible') == -1) &&
	(agent.indexOf('opera') == -1) &&
	(agent.indexOf('webtv') == -1) &&
	(agent.indexOf('hotjava') == -1));

    this.ns4 = (this.ns && (this.major == 4));
    this.ns6 = (this.ns && (this.major >= 5));

    this.ie = ((agent.indexOf("msie") != -1) &&
	(agent.indexOf("opera") == -1));

    this.ie4 = (this.ie && (this.major == 4) &&
	(agent.indexOf("msie 4") != -1));

    this.ie5 = (this.ie && (this.major == 4) &&
	(agent.indexOf("msie 5.") != -1) &&
	(agent.indexOf("msie 5.5") == -1) &&
	(agent.indexOf("mac") == -1));

    this.iem5 = (this.ie && (this.major == 4) &&
	(agent.indexOf("msie 5.") != -1) &&
	(agent.indexOf("mac") != -1));

    this.ie55 = (this.ie && (this.major == 4) &&
	(agent.indexOf("msie 5.5") != -1));

    this.ie6 = (this.ie && (this.major == 4) &&
	(agent.indexOf("msie 6.") != -1));

    this.nsdom = (this.ns4 || this.ns6);
    this.ie5dom = (this.ie5 || this.iem5 || this.ie55);
    this.iedom = (this.ie4 || this.ie5dom || this.ie6);
    this.w3dom = (this.ns6 || this.iem5
	|| this.ie55
	|| this.ie6);
}



function detach_content ()
{
    var link;
    var title2;
    var is = new Is();
    if(is.ie4)
    {
	link=parent.document.frames["contentPane"].document.location;
	title2=parent.document.frames["contentPane"].contentWindow.document.title.replace ('\s','');
    }
    else
    {
	link=parent.document.getElementById("contentPane").src;
	title2=parent.document.getElementById("contentPane").contentWindow.document.title;

    }
    title2=title2.replace (/\s+/g,'');
    title2=title2.replace (/\./g,'');
    title2=title2.replace (/\-/g,'');

    window.open(link,title2,'width=768,height=452,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes');
    window.focus();



}

function loadwindow (id,windowtype)
{
    var detachable;
    self.status='Powered by PIFPAF.pl';
    var is = new Is();
    if (id!=0)
	docsrc = "index.php?index=content&id="+id+"&area="+windowtype+"#"+id;
    else
	docsrc = "index.php?index=content&area="+windowtype;

    if(is.ie4)
    {
	if (parent.document.frames["contentPane"].document.location == docsrc)
	{
	    parent.frames['contentPane'].location.reload(1);

	//         parent.document.frames["contentPane"].document.location.reload(1);
	}
	else
	    parent.document.frames["contentPane"].document.location = docsrc;
    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {


	if (parent.document.getElementById("contentPane").src == docsrc)
	{

	    parent.frames['contentPane'].location.reload(1);
	}
	else
	    parent.document.getElementById("contentPane").src = docsrc;



    }

    ///      alert (detachable);
    self.status='Powered by PIFPAF.pl';
}
  


function handleDetach (isDetachable)
{
    p = document.getElementById('detach');

    if (isDetachable==1)
    {
	p.style.display='';

    }
    else
	p.style.display='none';


}

function submitForm (formname, framename)
{
    var is = new Is();
    if(is.ie4)
    {

	f=parent.frames[framename].document.getElementById (formname);
	f.submit ();
    }
    else

    {
	window.parent.form[0].submit();
    }
}

function loadconfigwindow (id,configid, windowtype)
{

    var is = new Is();

    docsrc = "frameconfig.php?id="+id+"&configid="+configid+"&area="+windowtype;


    if(is.ie4)
    {
	if (document.frames["configframe"].document.location == docsrc)
	{
	    document.frames["configframe"].document.location.reload(1);
	}
	else
	    document.frames["configframe"].document.location = docsrc;
    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {


	if (window.document.getElementById("configframe").src == docsrc)
	{

	    window.document.frames["configframe"].location.reload(1);
	}
	else
	    window.document.getElementById("configframe").src = docsrc;

    }
    self.status='Powered by PIFPAF.pl';
}


function ResetWindows ()
{

    var is = new Is();
    var docsrc = "index.php?index=content";

    if(is.ie4)
    {
	parent.document.frames["contentPane"].document.location = docsrc;
    }
    else
    {
	parent.document.getElementById("contentPane").src = docsrc;

    }

    RefreshServerWindow (null);

}

function RefreshContentFrame  ()
{
    var is = new Is();
    docsrc="index.php?index=content";

    if(is.ie4)
    {
	parent.document.frames["contentPane"].document.location.reload(1);;

    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {

	if (parent.document.getElementById("contentPane").src == docsrc)
	{
	    parent.frames['contentPane'].location.reload(1);
	}
	else
	    parent.document.getElementById("contentPane").src=docsrc;

    }
    self.status='Powered by PIFPAF.pl';
}

function RefreshParentFrame ()
{

    var is = new Is();


    if(is.ie4)
    {
	self.parent.location.reload(true);


    }
    else
    //
    if(is.ie5dom || is.ie6 || is.ns6)
    {

	self.parent.location.reload(true);

    }

}
  
function RRCF  ()
{

    var is = new Is();


    if(is.ie4)
    {
	self.parent.location.href='/';


    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {

	self.parent.location.href='/';

    }

}
function ControlPanel (area)
{

    var is = new Is();
    var docsrc = "index.php?index=control&area="+area;

    if(is.ie4)
    {
	parent.document.frames["controlPane"].document.location = docsrc;
    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {
	/*
        if (parent.document.getElementById("contentPane").src == docsrc)
        {
          // parent.getElementById("contentPane").src.refresh();
        }
        else*/
	parent.document.getElementById("controlPane").src = docsrc;

    }
    self.status='Powered by PIFPAF.pl';
}


function RefreshServerWindow(id) {

    var is = new Is();
    var docsrc = "index.php?index=control&id="+id;

    // controlpanel
    if(is.ie4)
    {
	parent.document.frames["controlPane"].document.location = docsrc;
    }
    else
    {

	parent.document.getElementById("controlPane").src = docsrc;
    }

    // status
    docsrc = "index.php?index=status&id="+id;
    if(is.ie4)
    {
	parent.document.frames["statusframe"].document.location = docsrc;
    }
    else
    {
	parent.document.getElementById("statusframe").src = docsrc;
    }

    // control frame
    docsrc = "index.php?index=controls&id="+id;
    if(is.ie4)
    {
	parent.document.frames["controlframe"].document.location = docsrc;
    }
    else
    {
	parent.document.getElementById("controlframe").src = docsrc;
    }

    // game
    docsrc = "index.php?index=game&id="+id;
    if(is.ie4)
    {
	parent.document.frames["gameframe"].document.location = docsrc;
    }
    else
    {
	parent.document.getElementById("gameframe").src = docsrc;
    }



}


// Hide all select boxes

function ShowInfo(from)
{

    id=from.options[from.selectedIndex].value;
    //       id=100;
    docsrc = "framemap.php?id="+id;
    var is = new Is();
    if(is.ie4)
    {
	if (document.frames["mapinfoframe"].document.location == docsrc)
	{
	    document.frames["mapinfoframe"].document.location.reload(1);
	}
	else
	    document.frames["mapinfoframe"].document.location = docsrc;
    }
    else
    //      if(is.ie5dom || is.ie6 || is.ns6)
    {


	if (window.document.getElementById("mapinfoframe").src == docsrc)
	{

	    window.document.frames["mapinfoframe"].location.reload(1);
	}
	else
	    window.document.getElementById("mapinfoframe").src = docsrc;

    }
}

function DeleteConfirmation (message, doc)
{
    var result = confirm((message));
    if(result)
    {
	window.location.href = (doc);
    }
    else
    {

}
}
function showhide(elem)
{
    p = document.getElementById(elem);
    if (p.style.display == '') p.style.display='none';
    else p.style.display = '';
}

function CheckButton (obj)
{
    obj=document.getElementById ('buttonok');
    klient=document.payonline.klient.value;
    adres=document.payonline.adres.value;
    kod=document.payonline.kod.value;
    miasto=document.payonline.miasto.value;
    email=document.payonline.email.value;
    country=document.payonline.country.value;
    type=document.payonline.type.value;
    if ((type==2 && (klient=="" || adres=="" || kod=="" || miasto=="" || email=="" || country=="" || klient.length>40 || adres.length>60 || country.length>2 || miasto.length>30 || email.length>50 || kod.length>10 || document.payonline.amount.value=='')) || document.payonline.amount.value==0 || document.payonline.amount.value<0)
    {
	obj.style.background='red';
	;
	return;

    }
    obj.style.background='green';

}

function MakePayment (serverid, userid)
{
    obj=document.getElementById ('buttonok');
    if (document.payonline.amount.value=='' || document.payonline.amount.value==0 || document.payonline.amount.value<0)
    {
	alert ('Wpisz poprawną kwotę');
	return;
    }
    amount=document.payonline.amount.value;
    type=document.payonline.type.value;

    // sprawdzic dane do karty
    if (type==2)
    {
	klient=document.payonline.klient.value;
	adres=document.payonline.adres.value;
	kod=document.payonline.kod.value;
	miasto=document.payonline.miasto.value;
	email=document.payonline.email.value;
	country=document.payonline.country.value;

	if (klient=="")
	{
	    alert ('Wpisz imię i nazwisko właściciela karty.');
	    return;
	}
	if (adres=="")
	{
	    alert ('Wpisz adres właściciela karty.');
	    return;
	}
	if (kod=="")
	{
	    alert ('Wpisz kod pocztowy właściciela karty.');
	    return;
	}
	if (miasto=="")
	{
	    alert ('Wpisz miasto zamieszkania właściciela karty.');
	    return;
	}
	if (email=="")
	{
	    alert ('Wpisz email właściciela karty.');
	    return;
	}
	if (country=="")
	{
	    alert ('Wpisz kod kraju np. PL, DE itd.');
	    return;
	}
	if (klient.length>40)
	{
	    alert ('Imię i nazwisko może mieć maksymalnie 40 znaków.');
	    return;
	}
	if (adres.length>60)
	{
	    alert ('Adres może mieć maksymalnie 60 znaków.');
	    return;
	}
	if (kod.length>10)
	{
	    alert ('Kod może mieć maksymalnie 10 znaków.');
	    return;
	}
	if (email.length>50)
	{
	    alert ('E-Mail może mieć maksymalnie 50 znaków.');
	    return;
	}
	if (country.length>2)
	{
	    alert ('Wpisz poprawny kod kraju, np. PL, DE itd.');
	    return;
	}


    }


    klient=document.payonline.klient.value;
    adres=document.payonline.adres.value;
    kod=document.payonline.kod.value;
    miasto=document.payonline.miasto.value;
    email=document.payonline.email.value;
    country=document.payonline.country.value;
    type=document.payonline.type.value;
    if (type==1)  url="https://secure.pifpaf.pl/payonline.php?serverid="+serverid+"&amount="+amount+"&userid="+userid+"&type="+type;
    if (type==2)  url="https://secure.pifpaf.pl/payonline.php?serverid="+serverid+"&amount="+amount+"&userid="+userid+"&klient="+klient+"&adres="+adres+"&kod="+kod+"&miasto="+miasto+"&country="+country+"&email="+email+"&type="+type;

    window.open(url,'PaymentsWindow','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
    window.focus();
    alert ('Transakcja w toku... Przełącz się na okienko serwisu Przelewy24.pl (jeżeli masz zablokowane wyskakujące okienka, odblokuj je dla naszej strony), dokonaj transakcji i kliknij OK. Uwaga! Nie zamykaj okienka zanim zostaniesz o to poproszony! ');
    document.payonline.type.value=1;
    document.payonline.amount.value="";
    document.payonline.predef.value="";

    window.incomeHistory.location.href='index.php?index=content&area=incomehistory&id='+serverid;
}

function AdditionalInfo ()
{
    type=document.payonline.type.value;
    divik=document.getElementById ('additional_info_div');
    if (type==2) divik.style.display=''; else divik.style.display='none';

}
function ClickLink (link)
{
    url=link;
    win2=window.open(url,'blank_','scrollbars=yes,status=yes,resizable=yes,menubar=yes, toolbar=yes,location=yes, links=yes');
    win2.focus();

};

window.onload = function()
{
    var is = new Is();
    var docsrc = "index.php?index=content";

    if(!is.ie4 && !is.ie6 && !is.iem5 && !is.ie5 && !is.ie55) return;
    var activeXObjTypes = new Array( "applet", "embed", "object" );
    for ( var i = 0; i < activeXObjTypes.length; i++ )
    {
	var xObj = document.getElementsByTagName( activeXObjTypes[i] );
	for( var j = 0; j < xObj.length; j++ )
	{
	    if (xObj[j].outerHTML == null) continue;
	    xObj[j].outerHTML = xObj[j].outerHTML;
	}
    }

}
function fmtF(w,d){

    // fmtF: formats in a style similar to Fortran's Fw.d, where w is the
    // width of the field and d is the number of figures after the decimal
    // point.
    // The result is aligned to the right of the field.  The default
    // padding character is a space " ". This can be modified using the
    // setSpacer(string) method of ToFmt.
    // If the result will not fit in the field , the field will be returned
    // containing w asterisks.
    var width=w;
    var dpls=d;
    var lt1=false;
    var len=this.x.toString().length;
    var junk;
    var res="";
    // First check for valid format request
    if ( width < (dpls+2)){
	window.alert("Illegal format specified : w = " + d +
	    " w = " + d +
	    "\nUsage: [ToFmt].fmtF(w,d)" +
	    "\nWidth (w) of field must be greater or equal to the number " +
	    "\nof digits to the right of the decimal point (d) + 2");
	junk = filljunk(width);
	return junk;
    }
    // Work with absolute value
    var absx=Math.abs(this.x);
    // Nasty fix to deal with numbers < 1 and problems with leading zeros!
    if ((absx < 1) && (absx > 0)){
	lt1 = true;
	absx+=10;
    }
    // Get postion of decimal point
    var pt_pos = absx.toString().indexOf(".");
    if ( pt_pos == -1){
	res+= absx;
	res+= ".";
	for (var i = 0; i < dpls; i++){
	    res += 0;
	}
    }
    else{
	res = Math.round(absx * Math.pow(10,dpls));
	res=res.toString();
	if (res.length ==
	    Math.round(Math.floor(absx * Math.pow(10,dpls))).toString().length){
	    res = res.substring(0,pt_pos) + "." +
	    res.substring(pt_pos,res.length);
	}
	else{
	    pt_pos++;
	    res = res.substring(0,pt_pos) + "." +
	    res.substring(pt_pos,res.length);
	}
	// Remove leading 1 from  numbers < 1 (Nasty fix!)
	if (lt1) {
	    res=res.substring(1,res.length);
	}
    }
    // Final formatting statements
    // Reinsert - sign for negative numbers
    if (this.x < 0)res = "-"+res;
    // Check whether the result fits in the width of the field specified
    if (res.length > width){
	res=filljunk(width);
    }
    // If necessary, pad from the left with the spacer string
    else if (res.length < width){
	var res_bl="";
	for (var i = 0; i < (width - res.length); i++){
	    res_bl += this.spacer ;
	}
	res = res_bl + res;
    }
    return res;
}

function fmtE(w,d){

    // fmtE: formats in a style similar to Fortran's Ew.d, where w is the
    // width of the field and d is the number of figures after the decimal
    // point.
    // The result is aligned to the right of the field.  The default
    // padding character is a space " ". This can be modified using the
    // setSpacer(string) method of ToFmt.
    // If the result will not fit in the field , the field will be returned
    // containing w asterisks.
    //
    var width=w;
    var dpls=d;
    var e="E+";
    var len=this.x.toString().length;
    var pow10;
    var xp10;
    var junk;
    var res="";
    // First check for valid format request
    if ( width < (dpls+5)){
	window.alert("Illegal format specified : w = " + d +
	    " w = " + d +
	    "\nUsage: [ToFmt].fmtE(w,d)" +
	    "\nWidth (w) of field must be greater or equal to the number " +
	    "\nof digits to the right of the decimal point (d) + 6");
	junk = filljunk(w);
	return junk;
    }
    // Work with absolute value
    var absx=Math.abs(this.x);
    // Get postion of decimal point
    var pt_pos = absx.toString().indexOf(".");
    // For x=0
    if (absx == 0){
	res +="0.";
	for (var i=0; i< dpls; i++){
	    res += "0";
	}
	res  += "E+00";
    }
    // For abs(x) >= 1
    else if (absx >= 1.0){
	pow10=1;
	xp10 = absx;
	while (xp10 >= 1.){
	    pow10++;
	    xp10 /= 10;
	}
	res = Math.round(xp10 * Math.pow(10,dpls));
	res=res.toString();
	if (res.length ==
	    Math.round(Math.floor(xp10 * Math.pow(10,dpls))).toString().length){
	    pow10--;
	}
	res = "0." + res.substring(0,dpls) + e + (new ToFmt(pow10)).fmt00();
    }
    // For abs(x) < 1
    else if (absx < 1.0){
	pow10=1;
	xp10 = absx;
	while (xp10 < 1.){
	    pow10--;
	    xp10 *= 10;
	}
	res = Math.round(xp10/10 * Math.pow(10,dpls));
	res=res.toString();
	if (res.length !=
	    Math.round(Math.floor(xp10/10 * Math.pow(10,dpls))).toString().length){
	    pow10++;
	}
	if (pow10 < 0) e = "E-";
	res = "0." + res.substring(0,dpls) + e + (new ToFmt(Math.abs(pow10))).fmt00();
    }
 
    if (this.x < 0)res = "-"+res;
    if (res.length > width){
	res=filljunk(width);
    }
    else if (res.length < width){
	var res_bl="";
	for (var i = 0; i < (width - res.length); i++){
	    res_bl += this.spacer ;
	}
	res = res_bl + res;
    }
    return res;
 
}

function fmtI(w){

    // fmtI: formats in a style similar to Fortran's Iw, where w is the
    // width of the field.
    // Floating point values are truncated (rounded down) for integer
    // representation.
    // The result is aligned to the right of the field.  The default
    // padding character is a space " ". This can be modified using the
    // setSpacer(string) method of ToFmt.
    // If the result will not fit in the field , the field will be returned
    // containing w asterisks.
    var width=w;
    var lt0=false;
    var len=this.x.toString().length;
    var junk;
    var res="";
    // Work with absolute value
    var absx = Math.abs(this.x);

    // Test for < 0
    if (parseInt(this.x) < 0){
	lt0 = true;
    }
    res = Math.round(Math.floor((absx))).toString();
    if (lt0){
	res = "-"+res;
    }
    if (res.length > width){
	res=filljunk(width);
    }
    else if (res.length < width){
	var res_bl="";
	for (var i = 0; i < (width - res.length); i++){
	    res_bl += this.spacer ;
	}
	res = res_bl + res;
    }
    return res;
}

function filljunk(lenf){
    // Fills field of length lenf with asterisks
    var str="";
    for (var i=0; i < lenf; i++){
	str +="*";
    }
    return str;
}
function ToFmt(x){
    this.x=x;
    this.fmt00 = fmt00;
    this.fmtF = fmtF;
    this.fmtE=fmtE;
    this.fmtI=fmtI;
    this.spacer=" ";
    this.setSpacer=setSpacer;
}

function fmt00(){
    // fmt00: Tags leading zero onto numbers 0 - 9.
    // Particularly useful for displaying results from Date methods.
    //
    if (parseInt(this.x) < 0) var neg = true;
    if (Math.abs(parseInt(this.x)) < 10){
	this.x = "0"+ Math.abs(this.x);
    }
    if (neg) this.x = "-"+this.x;
    return this.x;
}
function setSpacer(spc){
    var spc;
    this.spacer=spc;
    return this.spacer;
}

//-->
