var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;
function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>149) pos += dir;
if (pos>149) len -= dir;
if (pos>149 && len==0) pos=0;
elem.style.left = pos-75+'px';
elem.style.width = len+60+'px';
}
}

function remove_loading() {
	this.clearInterval(t_id);
	var targelem = document.getElementById('loader_container');
	targelem.style.display='none';
	targelem.style.visibility='hidden';
}


function doresize() {
    MWJ_changeSize('header',getWindowWidth(),90);
    var oW = getWindowWidth() - 200 - 3;
    var oH = getWindowHeight() - 90 - 2;
    MWJ_changePos('stationlist', oW, 90 , 1);
//    MWJ_changeSize('info',150);
//    MWJ_changeSize('stationlist',200);
}

//function setCookie(name, value) {
//    var dc = document.cookie;
//    dc = name + "=" + escape(value) + ";expires=0";
//}

function custRound(x,places) {
	return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}

function YYtoLL1(UTMEasting,UTMNorthing)
{
    var PI = 3.14159265;
    var FOURTHPI = PI / 4;
    var deg2rad = PI / 180;
    var rad2deg = 180.0 / PI;

    //default LL coord. syst. WGS-84
	var a = 6378137;                //EquatorialRadius
	var eccSquared = 0.00669438;    //Eccentricity Squared
	var k0 = 0.9996;                // Scale

	var e1 = (1 - Math.sqrt(1 - eccSquared))/(1 + Math.sqrt(1 - eccSquared));

	var x = UTMEasting - 500000.0; //remove 500,000 meter offset for longitude
	var y = UTMNorthing;

	LongOrigin = 24; //(ZoneNumber - 1)*6 - 180 + 3;  //+3 puts origin in middle of zone

	var eccPrimeSquared = (eccSquared)/(1 - eccSquared);

	var M = y / k0;
	var mu = M/(a*(1-eccSquared/4-3*eccSquared*eccSquared/64-5*eccSquared*eccSquared*eccSquared/256));

	var phi1Rad = mu	+ (3*e1/2-27*e1*e1*e1/32)*Math.sin(2*mu)
				+ (21*e1*e1/16-55*e1*e1*e1*e1/32)*Math.sin(4*mu)
				+(151*e1*e1*e1/96)*Math.sin(6*mu);
	var phi1 = phi1Rad*rad2deg;

	var N1 = a/Math.sqrt(1-eccSquared*Math.sin(phi1Rad)*Math.sin(phi1Rad));
	var T1 = Math.tan(phi1Rad)*Math.tan(phi1Rad);
	var C1 = eccPrimeSquared*Math.cos(phi1Rad)*Math.cos(phi1Rad);
	var R1 = a*(1-eccSquared)/Math.pow(1-eccSquared*Math.sin(phi1Rad)*Math.sin(phi1Rad), 1.5);
	var D = x/(N1*k0);

	var Lat = phi1Rad - (N1*Math.tan(phi1Rad)/R1)*(D*D/2-(5+3*T1+10*C1-4*C1*C1-9*eccPrimeSquared)*D*D*D*D/24
					);//+(61+90*T1+298*C1+45*T1*T1-252*eccPrimeSquared-3*C1*C1)*D*D*D*D*D*D/720);
	Lat = Lat * rad2deg;

	var Long = (D-(1+2*T1+C1)*D*D*D/6+(5-2*C1+28*T1-3*C1*C1+8*eccPrimeSquared+24*T1*T1)
					*D*D*D*D*D/120)/Math.cos(phi1Rad);
	Long = LongOrigin + Long * rad2deg;
    return [Lat, Long];
}

function YYtoLL(scale, dXr, dX0, dYr, dY0, latt, longt)
{
    var div = MM_findObj( 'mainmap' );
    var scX, scY, scXY;
    var L1, L2, Lo1, Lo2;
    if( div ) {
        if( div.captureEvents ) {
            div.captureEvents( Event.MOUSEMOVE );
        }
        div.onselectstart = function () { return false; }
        div.onmousemove = function (e) {
            var xM = MWJ_getMouseCoords(e);
            var xP = MWJ_getPosition(this);
            window.sO = [xM[0]-xP[0],xM[1]-xP[1]];
            MWJ_monitorMouse( function () {
                scX = (((window.MWJ_getMouse[0] -  scale)   * dXr) + dX0);
                scY = (dY0 - ((window.MWJ_getMouse[1] - 92)   * dYr));
                //scXY = YYtoLL1(scX,scY);
                L1 = parseInt(scY);
                L2 = (scY - L1) * 60;
                L2 = custRound(L2,3);
                L3 = parseInt((String(L2).substr(3,2) * 0.6));
                L2 = parseInt(L2);
                Lo1 = parseInt(scX);
                Lo2 = (scX - Lo1) * 60;
                Lo2 = custRound(Lo2,3);
                Lo3 = parseInt((String(Lo2).substr(3,2) * 0.6));
                Lo2 = parseInt(Lo2);
                document.getElementById('info').innerHTML='<br><font color=\"#4281bd\">' + latt + ':</font> ' + L1 + '&deg; '+ L2 + '\' ' + L3 + '\'\' <br><font color=\"#4281bd\">' + longt + ':</font> ' + Lo1 + '&deg; '+ Lo2 + '\' ' + Lo3 + '\'\'';

             });
        }
    }
}

function stopit()
{
   document.onmousemove = null;
   document.onmouseup = null;
   if( document.releaseEvents ) {
     document.releaseEvents( Event.MOUSEMOVE );
     document.releaseEvents( Event.MOUSEUP );
   }
}

function nospam(first,last,text,id)
{
  var a;
  a  = '<a href="mail' + 'to:';
  a += first;
  a += '@'+last;
  a += '">';
  a += text;
  a += '</a>';
  document.getElementById('mailContainer'+id).innerHTML=a;
}



function pause(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
}

function openExternal(ref)
{
window.open(ref);
}


