function logout()
{
OpenWindow("logout.asp?lev=opt", "logout", 370, 250);
}

function nextgrp(item)
{
	if (document.forms.prop.recid)
	{
		document.forms.prop.recid.value = "";
	}
	if (document.forms.prop.recsys)
	{
		document.forms.prop.recsys.value = "";
	}
	i = eval('document.forms.prop.' + item );
	i.value++;
	document.forms.prop.submit();
}

function prevgrp(item)
{
	if (document.forms.prop.recid)
	{
		document.forms.prop.recid.value = "";
	}
	if (document.forms.prop.recsys)
	{
		document.forms.prop.recsys.value = "";
	}
	i = eval('document.forms.prop.' + item );
	i.value--;
	document.forms.prop.submit();
}

PopupWin = null;
function OpenWindow( url, name, width, height ) 
{
	var scbars, stat
	if (( name == "feedback" )||( name == "Pict" )||( name == "Install" )||( name=="strplot"))
		scbars = 1
	else
		scbars = 0

	if ( name == "Install" )
                stat = 0
        else
                stat = 1
    
    if ( name == "key" ){
                stat = 0
                scbars = 0
    }            

	var params = "width=" + width + ",height=" + height + ",resizable=0,scrollbars="+ scbars +",status="+ stat;
	if ( PopupWin != null )
	{
		if ( PopupWin.closed )
		{
			PopupWin = null;
			PopupWin = window.open( url, name, params );
    		}
		else
		{
			if ( PopupWin.name != name )
			{
				PopupWin.close();
				PopupWin = null;
				PopupWin = window.open( url, name, params );
			}
			else
			{
				PopupWin.focus();
			}
		}
	}
	else
	{
		PopupWin = window.open( url, name, params );
	}
}


function setnum(dat)
{
    if(dat == "1.#INF"||dat == "1.#IND")
    {
        return "&mdash;"
    }
	else if ((dat >= 100000000)||(dat <= -100000000)||((dat <= 0.01)&&(dat > 0))||((dat >= -0.01)&&(dat < 0)))
	{
//                var newval = dat.toExponential([3]);
//                return newval;
        
        var x, y, z, A, B, C, exponent, Bstring, Blength, negative;
                  
        if(dat < 0){
            negative = true;
            dat = Math.abs(dat);
        }

        x = Math.LOG10E * Math.log(dat);
        exponent = Math.floor(x);
        y = x - exponent;
        z = Math.pow(10, y);
        A = 1000*z;
        B = Math.round(A);
        Bstring = B.toString();
        Blength = Bstring.length;


        //Last number is not zero
        if(Bstring.lastIndexOf("0")!=Blength-1)
            C = B/1000;

        //Last number is zero
        else if((Bstring.charAt(Blength-2)=="0")&&(Bstring.charAt(Blength-3)=="0"))
            C = B/1000+".000";
        else if(Bstring.charAt(Blength-2)=="0")
            C = B/1000+"00";
        else
            C = B/1000+"0";

        if(exponent>0)
            exponent="+"+exponent;
        else if(exponent<0)
            exponent=exponent;
  
        if(negative==true)
            C = "-"+C;

        if(isNaN(C))
            return "N/A";
        else
            return C+"e"+exponent;

	}
	else
	{
		return dat;
	}
}

function setnum2(dat, dec, sfig )
{
    if(dat == "1.#INF"||dat == "1.#IND")
    {
        return "&mdash;"
    }
	else
	{
	    var fixed, precise;
	    
	    fixed = dat.toFixed(dec);
	    precise = dat.toPrecision(precise);
	    
	    if(fixed.length < precise.length)
	        return fixed;
	    
	    return precise;
	}
}

function Edate(){
	switch (document.getElementById("EMonth").selectedIndex){
		case 1:
			if (parseInt(document.getElementById("EYear").value)%4==0){
				if (parseInt(document.getElementById("EDay").value)>29)
					document.getElementById("EDay").selectedIndex=28;
			}
			else {
				if (parseInt(document.getElementById("EDay").value)>28)
					document.getElementById("EDay").selectedIndex=27;
			}
			break;
		case 3:
		case 5:
		case 8:
		case 10:
			if (parseInt(document.getElementById("EDay").value)>30)
				document.getElementById("EDay").selectedIndex=29;
			break;
	}
}

function Ldate(){
	switch (document.getElementById("LMonth").selectedIndex){
		case 1:
			if (parseInt(document.getElementById("LYear").value)%4==0){
				if (parseInt(document.getElementById("LDay").value)>29)
					document.getElementById("LDay").selectedIndex=28;
			}
			else {
				if (parseInt(document.getElementById("LDay").value)>28)
					document.getElementById("LDay").selectedIndex=27;
			}
			break;
		case 3:
		case 5:
		case 8:
		case 10:
			if (parseInt(document.getElementById("LDay").value)>30)
				document.getElementById("LDay").selectedIndex=29;
			break;
	}
}

function DateCheck(){
	var LYear, EYear, LMonth, EMonth, LDay, EDay;
	LYear=document.getElementById("LYear").selectedIndex;
	EYear=document.getElementById("EYear").selectedIndex;
	LMonth=document.getElementById("LMonth").selectedIndex;
	EMonth=document.getElementById("EMonth").selectedIndex;
	LDay=document.getElementById("LDay").selectedIndex;
	EDay=document.getElementById("EDay").selectedIndex;
  
	if(LYear<EYear)
		alert("Latest Date cannot be before Earliest Date.");
	else if(LYear==EYear){
		if(LMonth<EMonth)
			alert("Latest Date cannot be before Earliest Date.");
		else if(LMonth==EMonth){
			if(LDay<EDay)
				alert("Latest Date cannot be before Earliest Date.");
			else
				document.forms[0].submit();
		}
		else
			document.forms[0].submit();
	}
	else
		document.forms[0].submit();
}


function linkwidth()
{
var nav1, nav2;
    nav1=document.getElementById("nav");
    nav2=document.getElementById("nav2");
    if(screen.width==800){
        nav1.style.visibility="hidden";
        nav2.style.visibility="visible";
    }
    else{
    document.write(nav1);
        nav1.style.visibility="visible";
        nav2.style.visibility="hidden";
        //nav1.style.style.left = "-1000px";
    }
}

//resizes model, keeps data at side constant size
function resizeModel(winWidth, modWidth){
//alert(document.documentElement.clientWidth);
    model=document.getElementById("VesselView");
    win=document.getElementById("body");
    
    if(document.documentElement.clientWidth<=(parseInt(winWidth)-20)){      //min window width -20(scrollbar)
        win.style.width = (parseInt(winWidth)-50);                         //min window width -20(scrollbar)-30(body margins in CSS)
        model.style.width = 4*parseInt((parseInt(winWidth)+parseInt(modWidth)-1024)/4);   //min window width -(1024-max model width)
        model.style.height = 4*parseInt((parseInt(winWidth)+parseInt(modWidth)-1024)/4);
    }
    else{
        win.style.width = parseInt(document.documentElement.clientWidth)-30;          //min window width -20-30
        model.style.width = 4*parseInt(String(parseInt(document.documentElement.clientWidth)+parseInt(modWidth)+20-1024)/4); //min window width -(1024 - max model width - 20)
        model.style.height = 4*parseInt(String(parseInt(document.documentElement.clientWidth)+parseInt(modWidth)+20-1024)/4);
    }
    
}

//resizes graph, keeps data at side constant size
function resizeGraph(winWidth, gapSize){
    graph=document.getElementById("graphsize");
    win=document.getElementById("body");
    
    if(document.documentElement.clientWidth<=(parseInt(winWidth)-20)){  //min window width -20(scrollbar)
        win.style.width = (parseInt(winWidth)-50);                     //min window width -20(scrollbar)-30(body margins in CSS)
        graph.style.width = (parseInt(winWidth)-parseInt(gapSize)-20);  //min window width -gap size - scrollbar
    }
    else{
        win.style.width = parseInt(document.documentElement.clientWidth)-30;          //min window width -20-30
        graph.style.width = String(parseInt(document.documentElement.clientWidth)-parseInt(gapSize));
    }
    
}

//keeps model constant(if present), resizes data at side(if necessary)
function resizeWindow(winWidth){
//alert(document.documentElement.clientWidth);
    win=document.getElementById("body");
    
    if(document.documentElement.clientWidth<=(parseInt(winWidth)-20))   //min window width -20(scrollbar)
        win.style.width = (parseInt(winWidth)-50);                     //min window width -20(scrollbar)-30(body margins in CSS)
    else
        win.style.width = parseInt(document.documentElement.clientWidth)-30;  //min window width -20-30
    
}

