function Focus(SetTo)
	{
		document.forms[0].elements[SetTo].focus();
		ClearFields();
	}

function ClearFields()
	{
		//change to a button and loop "for each"
		//document.forms[0].elements['curr'].value='';
		//document.forms[0].elements['oper'].value='';
	}
	
function addOptions(chosen)
{
	var choosebox = document.forms[0].ListBox1;
	if (!choosebox.options[0].text == null)
	{
		var selbox = document.forms[0].ListBox2;
		var fnd = 0;
		for (n=0;n<selbox.length;n++)
		{
			if (selbox.options[n].text == chosen)
			{
				fnd = 1;
			}
		}
		if (!fnd)
		{
			selbox.options[selbox.options.length] = new Option(chosen, selbox.options.length);
		}
	}
}

			
function delOptions(chosen) {
	var selbox = document.forms[0].ListBox2;
	if (selbox.options[0].value != " ") {
		nomatch = new Array();
		for (n=0;n<selbox.length;n++){
			if(selbox.options[n].text != chosen){
			nomatch[nomatch.length] = new Array(selbox.options[n].value, selbox.options[n].text);
			}
		}
		selbox.options.length = 0;
		if (!nomatch.length == 0) {
			for (n=0;n<nomatch.length;n++){
				selbox.options[n] = new Option(nomatch[n][1], nomatch[n] [0]);
			}
		}
	}
}

function setImage(imageid, url) {
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(imageid).src = url;
		} else { 
			eval(layerRef + '["' + imageid + '"].src="' + url + '"'); 
		} 
	} else { 
		return; 
	} 
}

// Toggles the layer display on 
function showLayer(layerName) { 
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(layerName).style.display=""; 
		} else { 
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display=""'); 
		} 
	} else { 
		return; 
	} 
} 

// Toggles the layer display off 
function hideLayer(layerName) { 
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(layerName).style.display="none"; 
		} else { 
			eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.display="none"'); 
		} 
	} else { 
		return; 
	}
}

// Repaints the RadListBox
function repaintListBox(listBoxID) {

    if (listBoxID == "RadNATY1InList") {
        var listbox = $find("ctl01_RadNATY1InList");
        listbox.repaint();
    }
    if (listBoxID == "NATY1InList") {
        var listbox = $find("ctl01_NATY1InList");
        listbox.repaint();
    }
    if (listBoxID == "RadNATY2InList") {
        var listbox = $find("ctl01_RadNATY2InList");
        listbox.repaint();
    }
    if (listBoxID == "NATY2InList") {
        var listbox = $find("ctl01_NATY2InList");
        listbox.repaint();
    }
    if (listBoxID == "RadBACNTRYInList") {
        var listbox = $find("ctl01_RadBACNTRYInList");
        listbox.repaint();
    }
    if (listBoxID == "BACNTRYInList") {
        var listbox = $find("ctl01_BACNTRYInList");
        listbox.repaint();
    }
    if (listBoxID == "DisplayFieldsIn") {
        var listbox = $find("ctl01_DisplayFieldsIn");
        listbox.repaint();
    }
    if (listBoxID == "DisplayFieldsOut") {
        var listbox = $find("ctl01_DisplayFieldsOut");
        listbox.repaint();
    }
    if (listBoxID == "RadOOMCODInList") {
        var listbox = $find("ctl01_RadOOMCODInList");
        listbox.repaint();
    }
    if (listBoxID == "OOMCODInList") {
        var listbox = $find("ctl01_OOMCODInList");
        listbox.repaint();
    }
    if (listBoxID == "RadStatusInList") {
        var listbox = $find("ctl01_RadStatusInList");
        listbox.repaint();
    }
    if (listBoxID == "StatusInList") {
        var listbox = $find("ctl01_StatusInList");
        listbox.repaint();
    }
    if (listBoxID == "RadShipTypeInList") {
        var listbox = $find("ctl01_RadShipTypeInList");
        listbox.repaint();
    }
    if (listBoxID == "ShipTypeInList") {
        var listbox = $find("ctl01_ShipTypeInList");
        listbox.repaint();
    }
    if (listBoxID == "RadIceClassInList") {
        var listbox = $find("ctl01_RadIceClassInList");
        listbox.repaint();
    }
    if (listBoxID == "IceClassInList") {
        var listbox = $find("ctl01_IceClassInList");
        listbox.repaint();
    }
    if (listBoxID == "RadEngineDesignInList") {
        var listbox = $find("ctl01_RadEngineDesignInList");
        listbox.repaint();
    }
    if (listBoxID == "EngineDesignInList") {
        var listbox = $find("ctl01_EngineDesignInList");
        listbox.repaint();
    }
    if (listBoxID == "RadCOBInList") {
        var listbox = $find("ctl01_RadCOBInList");
        listbox.repaint();
    }
    if (listBoxID == "COBInList") {
        var listbox = $find("ctl01_COBInList");
        listbox.repaint();
    }
    if (listBoxID == "STATCODE") {
        var listbox = $find("ctl01_STATCODE");
        listbox.repaint();
    }
    if (listBoxID == "STAT5CODE") {
        var listbox = $find("ctl01_STAT5CODE");
        listbox.repaint();
    }                    
}  

function changeClass(layername, newclass) {
	if(check) { 
		if (what =="none") { 
			return; 
		} else if (what == "dom1") { 
			document.getElementById(layername).className = newclass;
		} else { 
			eval(layerRef + '["' + layername + '"].className="' + newclass + '"'); 
		} 
	} else { 
		return; 
	} 
}

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, div, value, expires, path, domain, secure)
{
	var cookiestring = getCookie(name);
	
	if (cookiestring == null)
	{
		cookiestring = "hidehidehidehidehide";
	}
	
	switch (div)
	{
	case "1":
		cookiestring = value + cookiestring.substring(4);
		break
	case "2":
		cookiestring = cookiestring.substring(0,4) + value + cookiestring.substring(8);
		break
	case "3":
		cookiestring = cookiestring.substring(0,8) + value + cookiestring.substring(12);
		break
	case "4":
		cookiestring = cookiestring.substring(0,12) + value + cookiestring.substring(16);
		break
	case "5":
		cookiestring = cookiestring.substring(0,16) + value;
		break		
	}
		
	var exdate=new Date()
    exdate.setTime (exdate.getTime() + expires*24*60*60*1000)
	//exdate.setDate(exdate.getDate()+expires)
    document.cookie= name + "=" + escape(cookiestring) +
        ((expires) ? "; expires=" + exdate.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
/**
 * Gets value from querystring.
 */
function Querystring()
{
// get the query string, ignore the ? at the front.
	var querystring=location.search.substring(1,location.search.length);

// parse out name/value pairs separated via &
	var args = querystring.split('&');

// split out each name = value pair
	for (var i=0;i<args.length;i++)
	{
		var pair = args[i].split('=');

		// Fix broken unescaping
		temp = unescape(pair[0]).split('+');
		name = temp.join(' ');

		temp = unescape(pair[1]).split('+');
		value = temp.join(' ');

		this[name]=value;
	}

	this.get=Querystring_get;
}


function Querystring_get(strKey,strDefault)
{
	var value=this[strKey];
	if (value==null)
	{
        value=this[strKey.toUpperCase()] 
	    if (value==null)	    
	    {
	        value=this[strKey.toLowerCase()] 
	        if (value==null)
	        {
		        value=strDefault;
		    }    
		}    
	}

	return value;
}

function showPopup(popup) {
  document.all[popup].style.visibility = "visible";
}

function hidePopup(popup) {
  document.all[popup].style.visibility = "hidden";
}

function popuphelp (mylink, windowname)
{
	if (!window.focus)
	{
		return true;
	}
	
	var href;
	
	if (typeof(mylink) == 'string')
	{
		href=mylink;
	}
	else
	{
		href=mylink.href;
	}
	
	NewWindow = window.open(href, windowname, 'width=800,height=600,scrollbars=yes');
	NewWindow.focus();

	return false;
}

function runReport(report, orientation)
	{
		var number = '';
		var field = '';
		var sort = '';
		var windowFeatures = 'left=100,top=0,resizable=yes,scrollbars=yes,toolbar=no,menubar=no,location=no,status=yes';
		
		if (orientation == 'portrait')
		{
			windowFeatures += ',height=1200,width=900';
		}
		else //orientation == 'landscape'
		{
			windowFeatures += ',height=900,width=1200';
		}
		var qs = new Querystring();
		var listtype = qs.get('ListType');
		var specialindicator = qs.get('SpecialIndicator');
        var control = qs.get('control');		
		
		if (report == 'analysis')
		{
			if (control == 'list')
			{
				number = document.getElementById('ctl01_txtNumber').value;
				field = document.getElementById('ctl01_ddlField').options[document.getElementById('ctl01_ddlField').selectedIndex].value;
				
				var radioButtons = document.getElementsByName("ctl01$rblSort");	
			}
			else
			{
				number = document.getElementById('txtNumber').value;
				field = document.getElementById('ddlField').options[document.getElementById('ddlField').selectedIndex].value;
				
				var radioButtons = document.getElementsByName("rblSort");
			}
				
			for (var x = 0; x < radioButtons.length; x ++)
			{
				if (radioButtons[x].checked)
				{
					sort = radioButtons[x].value;
					//alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
				}
			}
		}
		else if (report == 'analysis2500')
		{
		    report = 'analysis';
			if (control == 'list')
			{
				number = document.getElementById('ctl01_txtNumber2500').value;
				field = document.getElementById('ctl01_ddlField2500').options[document.getElementById('ctl01_ddlField2500').selectedIndex].value;
				
				var radioButtons = document.getElementsByName("ctl01$Radiobuttonlist2500");	
			}
			else
			{
				number = document.getElementById('txtNumber2500').value;
				field = document.getElementById('ddlField2500').options[document.getElementById('ddlField2500').selectedIndex].value;
				
				var radioButtons = document.getElementsByName("Radiobuttonlist2500");
			}
				
			for (var x = 0; x < radioButtons.length; x ++)
			{
				if (radioButtons[x].checked)
				{
					sort = radioButtons[x].value;
					//alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
				}
			}
		}	
		else if (report == 'flist' || report == 'flist2')
		{
			if (control == 'list')
			{
				var radioButtons = document.getElementsByName("ctl01$rblFList");
			}
			else
			{
			    if (report == 'flist')
			    {
			    	var radioButtons = document.getElementsByName("rblFList");
			    }
			    else // report == 'flist2
			    {
			        var radioButtons = document.getElementsByName("rblFList2");
			        var OWCODE = qs.get('OWCODE');
			    }
			}

			for (var x = 0; x < radioButtons.length; x ++)
			{
				if (radioButtons[x].checked)
				{
					field = radioButtons[x].value;
//					alert("You checked " + radioButtons[x].id + " which has the value " + radioButtons[x].value);
				}
			}
		}				
		
//			var related="authenticated_handler.aspx?control=report_viewer2005&SearchString="+encodeURIComponent(qs.get('SearchString',''))+
		var related="report_viewer.aspx?SearchString="+encodeURIComponent(qs.get('SearchString',''))+

//					"&FieldList="+qs.get('FieldList','')+
				"&SpecialIndicator="+specialindicator+
				"&Number="+number+
				"&Field="+field+
				"&Sort="+sort+
//					"&ListType="+listtype+
//					"&bp=1"+
				"&report=1"+
				"&type="+report+
				"&orientation="+orientation+
				"&OWCODE="+OWCODE;

		newwin=window.open(related,'report',windowFeatures);
		
		if (control == 'list')
		{
			hidePopup('popRepVAnalysis');
			hidePopup('popRepShips');
			hidePopup('popRepVAnalysis2500');
			hidePopup('popRepShips2500');
			hidePopup('popRepOwners');
			hidePopup('popRepFList');
			hidePopup('popRepOwners2500');
			hidePopup('popRepFList2500');	
		}
		else if (control == 'shipovw')
		{
			hidePopup('popRepVAnalysisOvw');
			hidePopup('popRepShipsOvw');
			hidePopup('popRepVAnalysisOvw2500');
			hidePopup('popRepShipsOvw2500');
		}
		else if (control == 'ownerovw')
		{
			hidePopup('popRepOwnersOvw');
			hidePopup('popRepFListOvw');
			hidePopup('popRepFList2Ovw');	
		}
		
	}	
