// When menu toogle is on the menu frame will auto-disappear as you enter the content frame
var movingMenu = 0;

// Shrink the menu frame by 1 - stop when we hit 18px
function moveMenu(type) {
	var cur;
	with (top.document.getElementById('horizontalFrameset')) {
		cur = cols.substr(0, cols.indexOf(',')) - 15;
		if (cur <= 18 || type) {
			clearInterval(movingMenu); 
			movingMenu = 0;
			cur = 18;
		}
		cols = cur + ',*' + ((cols.split(',').length == 3) ? ',0' : '');
	}
}

function contentMouseOver() {
	if (!top.document.menuLock)
		with (top.document.getElementById('horizontalFrameset')) {
			// We aren't currently moving and should be hidden and our menu frame is exposed - start the shrink interval
			if (movingMenu == 0 && top.frames.length && cols.substr(0, cols.indexOf(',')) > 18) {
				movingMenu = setInterval("moveMenu();", 20);
				setTimeout("moveMenu(true);", 300);
			}
		}
}

if (top.frames.length) document.onmouseover = contentMouseOver;

// Chainable Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();

function safeAddOnload(f) {
	document.body.onload = safeOnload;
	gSafeOnload[gSafeOnload.length] = f;
}

function safeOnload() {
	for (var i=0; i < gSafeOnload.length; i++)
		gSafeOnload[i]();
}

// Start validation stuff
var validateArray = new Array();
		
// Restore the current tab - Loop over the <DIV> tags AND find the one that's called xxxViewX AND make it visible
function restoreTab(thisTab) {
	var divs = document.getElementsByTagName('DIV');
	for (var i=0; i < divs.length; i++) 
		if (divs[i].id.indexOf('View' + thisTab) > 0) {
			if (typeof(activateTab) != 'undefined') activateTab(eval('gid("tab_' + divs[i].id + '")')); 
			else eval('gid("' + divs[i].id + '").Show()');
		}
}
			
// Overflow toggle
function ov(o) {
	o.style.overflow = (o.style.overflow.length) ? '' : 'hidden';
	return true;
}

// Overflow row toggle
function ovr(o) {
	var divs = o.parentNode.parentNode.childNodes;
	for (var i=0; i < divs.length; i++)
		// Non-IE browsers have to skip the text nodes and expand the div height
		if (browser != 'IE') {
			try {
				divs[i].childNodes[1].style.overflow = (divs[i].childNodes[1].style.overflow.length) ? '' : 'hidden';
				divs[i].childNodes[1].style.height = (divs[i].childNodes[1].style.overflow.length) ? '12px' : '';
			}
			catch (x) { }
		} else if (divs[i].firstChild.style) 
			divs[i].firstChild.style.overflow = (divs[i].firstChild.style.overflow.length) ? '' : 'hidden';
	return true;
}

// Record the current tab - Loop over the <DIV> tags and find the one that's called xxxViewX and is visible
function getCurrentTab() {
	var divs = document.getElementsByTagName('DIV');
	for (var i=0; i < divs.length; i++) {
		if (divs[i].id.indexOf('View') > 0 && divs[i].style.display == 'block') 
			 return divs[i].id.substr(divs[i].id.length - 1, 1);
	}
	return 0;
}

// Don't submit blank values for RFA and CFA 
function disableBlankStackSend(formName) {
	if (typeof formName.RFA != "undefined") if (!formName.RFA.value.length) formName.RFA.disabled = true;
	if (typeof formName.CFA != "undefined") if (!formName.CFA.value.length) formName.CFA.disabled = true;
}

// Validate all the validated fields (as some required fields never receive focus to fire onblur validation)
function validateForm(formName) {
	var isValid = true;
	focusInvalid = false;
	formName.currentTab.value = getCurrentTab();
	disableBlankStackSend(formName);
	
	// Don't post any of the ADOXXX_X fields nor the Button fields
	for (var ados=0; ados < formName.length; ados++) {
		if (formName[ados].name && (formName[ados].name.indexOf('ado') == 0 || formName[ados].name.indexOf('Button') > -1)) {
			try {formName[ados].SQL = '';} catch (any) {}
			try {formName[ados].disabled = true;} catch (any) {}
		}
	}

	// Execute each of the Validations
	for (var izo=0; izo < validateArray.length; izo++) {
		try {
			if (!eval(validateArray[izo])) return false;
		}
		catch (any) {
			window.status = 'Could not validate ' + validateArray[izo] + ', during form submission. Skipped.';
		}
	}

	// Escape " (&quot;) and ' (&acute) for input fields, except if attribute "escaped" exists
	var inputs = document.getElementsByTagName('INPUT');
	for (var i=0; i < inputs.length; i=i+1)	{
		while (inputs[i].value.indexOf('"') > -1 && !inputs[i].getAttribute('escaped')) {
			inputs[i].value = inputs[i].value.substring(0, inputs[i].value.indexOf('"')) + '&quot;' 
				+ inputs[i].value.substring(inputs[i].value.indexOf('"') + 1, inputs[i].value.length); 
		}
		
		while (inputs[i].value.indexOf("'") > -1 && !inputs[i].getAttribute('escaped')) {
			inputs[i].value = inputs[i].value.substring(0, inputs[i].value.indexOf("'")) + '&acute;' 
				+ inputs[i].value.substring(inputs[i].value.indexOf("'") + 1, inputs[i].value.length); 
		}
	}
	
	// Escape < (&lt;) for textarea fields, except if attribute "escaped" exists
	var textareas = document.getElementsByTagName('TEXTAREA');
	for (var i=0; i < textareas.length; i=i+1) {
		while (textareas[i].value.indexOf('<') > -1 && !textareas[i].getAttribute('escaped')) {
			textareas[i].value = textareas[i].value.substring(0, textareas[i].value.indexOf('<')) + '&lt;' 
				+ textareas[i].value.substring(textareas[i].value.indexOf('<') + 1, textareas[i].value.length); 
		}
	}
	
	return true;
}

// Add the currentTab to the href of all href clicks, not mailto: and not blank href
function addTabtoHREF(e) {
	// x-browser compatibility
	if (window.event) e = window.event;
	var src = (e.srcElement) ? e.srcElement : e.target;
	
	if (src.tagName == 'A' 
		&& typeof(src.href) != 'undefined' 
		&& src.href.length > 0
		&& src.href.indexOf('mailto:') == -1
		&& src.href.indexOf('SQL') == -1
		&& src.href.indexOf('javascript:') == -1
		&& src.href.indexOf('?') != -1)
			src.href += '&currentTab=' + getCurrentTab();
}

// Set the (hidden) field to the 0th element based on the 1st element
function setComboValue(value, comboBoxArray, field) {
	for (var a=0; a < comboBoxArray.length; a++)
		if (comboBoxArray[a][1] == value) field.value = comboBoxArray[a][0];
}

function emailPage() {
	var myRange = document.body.createTextRange();
	myRange.execCommand('Copy');
	location.href = 'mailto:?subject=' + escape(document.title) + '&body=' + escape('Press Paste (Ctrl V)');
	// Previous attempt at opening an Outlook Form that "pasted" the results into it HTMLBody. Couldn't make it access the clipboard!
	// location.href = 'file:\/\/C:\/radar.oft';
}

function changeCSS(myClass, element, value) {
	var CSSRules;
	if (document.all) CSSRules = 'rules';
	else if (document.getElementById) CSSRules = 'cssRules';
	
	for (var s=0; s < document.styleSheets.length; s++)
		for (var i=0; i < document.styleSheets[s][CSSRules].length; i++) {
			if (document.styleSheets[s][CSSRules][i].selectorText == myClass) {
				document.styleSheets[s][CSSRules][i].style[element] = value;
			}
		}	
}

// Useful for large lists. Changes to tahoma which is thiner than verdana
function toggleFontSize(o) {
	var curFont = (o.getAttribute('curFont') == 'tahoma') ? 'verdana' : 'tahoma';
	changeCSS('.' + o.getAttribute('fontClass') + 'cell', 'fontFamily', curFont);
	changeCSS('.' + o.getAttribute('fontClass') + 'cellc', 'fontFamily', curFont);
	changeCSS('.' + o.getAttribute('fontClass') + 'cellr', 'fontFamily', curFont);
	o.setAttribute('curFont', curFont);
}

function checkIt(string) {
	var detect = navigator.userAgent.toLowerCase();
	var place = detect.indexOf(string) + 1;
	return place;
}

var browser;

if (checkIt('konqueror')) browser = "Konqueror";
else if (checkIt('safari')) browser = "Safari";
else if (checkIt('omniweb')) browser = "OmniWeb";
else if (checkIt('opera')) browser = "Opera";
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab";
else if (checkIt('msie')) browser = "IE";
else if (!checkIt('compatible')) browser = "Netscape Navigator";
else browser = "An unknown browser";


// Capture all clicks and if its a known href then add &currentTab=X
document.onclick = addTabtoHREF;

// Cached country list
var country = new Array();
country[0] = new Array(3, '-');
country[1] = new Array(333, '-- UNUSED --');
country[2] = new Array(188, 'AFGHANISTAN');
country[3] = new Array(190, 'ALBANIA');
country[4] = new Array(226, 'ALGERIA');
country[5] = new Array(413, 'AMERICAN SAMOA');
country[6] = new Array(475, 'ANDORRA');
country[7] = new Array(189, 'ANGOLA');
country[8] = new Array(423, 'ANTIGUA & BARBUDA');
country[9] = new Array(193, 'ARGENTINA');
country[10] = new Array(444, 'ARMENIA');
country[11] = new Array(194, 'AUSTRALIA');
country[12] = new Array(195, 'AUSTRIA');
country[13] = new Array(445, 'AZERBAIJAN');
country[14] = new Array(476, 'AZORES');
country[15] = new Array(201, 'BAHAMAS');
country[16] = new Array(200, 'BAHRAIN');
country[17] = new Array(198, 'BANGLADESH');
country[18] = new Array(206, 'BARBADOS');
country[19] = new Array(449, 'BELARUS');
country[20] = new Array(197, 'BELGIUM');
country[21] = new Array(202, 'BELIZE');
country[22] = new Array(466, 'BENIN');
country[23] = new Array(203, 'BERMUDA');
country[24] = new Array(208, 'BHUTAN');
country[25] = new Array(204, 'BOLIVIA');
country[26] = new Array(442, 'BOSNIA & HERZEGOVINA');
country[27] = new Array(209, 'BOTSWANA');
country[28] = new Array(205, 'BRAZIL');
country[29] = new Array(207, 'BRUNEI DARUSSALAM');
country[30] = new Array(199, 'BULGARIA');
country[31] = new Array(467, 'BURKINA FASO');
country[32] = new Array(196, 'BURUNDI');
country[33] = new Array(259, 'CAMBODIA');
country[34] = new Array(436, 'CAMEROON');
country[35] = new Array(210, 'CANADA');
country[36] = new Array(216, 'CAPE VERDE ISLANDS');
country[37] = new Array(219, 'CAYMAN ISLANDS');
country[38] = new Array(437, 'CENTRAL AFRICAN REPUBLIC');
country[39] = new Array(434, 'CHAD');
country[40] = new Array(212, 'CHILE');
country[41] = new Array(213, 'CHINA');
country[42] = new Array(403, 'CHRISTMAS ISLAND');
country[43] = new Array(214, 'COLOMBIA');
country[44] = new Array(215, 'COMOROS');
country[45] = new Array(435, 'CONGO');
country[46] = new Array(406, 'COOK ISLANDS');
country[47] = new Array(217, 'COSTA RICA');
country[48] = new Array(465, 'COTE D\'IVOIRE (IVORY COAST)');
country[49] = new Array(336, 'CROATIA');
country[50] = new Array(450, 'CROATIA (HERTZ)');
country[51] = new Array(218, 'CUBA');
country[52] = new Array(220, 'CYPRUS');
country[53] = new Array(221, 'CZECH REPUBLIC');
country[54] = new Array(224, 'DENMARK');
country[55] = new Array(223, 'DJIBOUTI');
country[56] = new Array(420, 'DOMINICA');
country[57] = new Array(225, 'DOMINICAN REPUBLIC');
country[58] = new Array(312, 'EAST TIMOR');
country[59] = new Array(227, 'ECUADOR');
country[60] = new Array(228, 'EGYPT');
country[61] = new Array(303, 'EL SALVADOR');
country[62] = new Array(432, 'EQUATORIAL GUINEA');
country[63] = new Array(451, 'ESTONIA');
country[64] = new Array(230, 'ETHIOPIA');
country[65] = new Array(330, 'EUROPE');
country[66] = new Array(233, 'FALKLAND ISLANDS');
country[67] = new Array(478, 'FAROE ISLAND');
country[68] = new Array(337, 'FAROE ISLANDS');
country[69] = new Array(232, 'FIJI');
country[70] = new Array(231, 'FINLAND');
country[71] = new Array(234, 'FRANCE');
country[72] = new Array(462, 'FRENCH GUIANA');
country[73] = new Array(417, 'FRENCH POLYNESIA');
country[74] = new Array(433, 'GABON');
country[75] = new Array(238, 'GAMBIA');
country[76] = new Array(443, 'GEORGIA');
country[77] = new Array(222, 'GERMANY');
country[78] = new Array(236, 'GHANA');
country[79] = new Array(237, 'GIBRALTAR');
country[80] = new Array(240, 'GREECE');
country[81] = new Array(474, 'GREENLAND');
country[82] = new Array(422, 'GRENADA');
country[83] = new Array(430, 'GUADELOUPE');
country[84] = new Array(409, 'GUAM');
country[85] = new Array(241, 'GUATEMALA');
country[86] = new Array(471, 'GUINEA');
country[87] = new Array(239, 'GUINEA-BISSAU');
country[88] = new Array(242, 'GUYANA');
country[89] = new Array(245, 'HAITI');
country[90] = new Array(244, 'HONDURAS');
country[91] = new Array(243, 'HONG KONG');
country[92] = new Array(246, 'HUNGARY');
country[93] = new Array(252, 'ICELAND');
country[94] = new Array(248, 'INDIA');
country[95] = new Array(247, 'INDONESIA');
country[96] = new Array(250, 'IRAN');
country[97] = new Array(251, 'IRAQ');
country[98] = new Array(249, 'IRELAND');
country[99] = new Array(253, 'ISRAEL');
country[100] = new Array(254, 'ITALY');
country[101] = new Array(255, 'JAMAICA');
country[102] = new Array(257, 'JAPAN');
country[103] = new Array(256, 'JORDAN');
country[104] = new Array(452, 'KAZAKHSTAN');
country[105] = new Array(258, 'KENYA');
country[106] = new Array(340, 'KIRIBATI');
country[107] = new Array(260, 'KUWAIT');
country[108] = new Array(447, 'KYRGYZSTAN');
country[109] = new Array(463, 'LAOS');
country[110] = new Array(448, 'LATVIA');
country[111] = new Array(261, 'LEBANON');
country[112] = new Array(265, 'LESOTHO');
country[113] = new Array(262, 'LIBERIA');
country[114] = new Array(263, 'LIBYAN ARAB JAMAHIRIYA');
country[115] = new Array(473, 'LIECHTENSTEIN');
country[116] = new Array(446, 'LITHUANIA');
country[117] = new Array(266, 'LUXEMBOURG');
country[118] = new Array(441, 'MACAU');
country[119] = new Array(440, 'MADAGASCAR');
country[120] = new Array(479, 'MADEIRA');
country[121] = new Array(276, 'MALAWI');
country[122] = new Array(277, 'MALAYSIA');
country[123] = new Array(268, 'MALDIVES');
country[124] = new Array(472, 'MALI');
country[125] = new Array(270, 'MALTA');
country[126] = new Array(412, 'MARSHALL ISLANDS');
country[127] = new Array(428, 'MARTINIQUE');
country[128] = new Array(274, 'MAURITANIA');
country[129] = new Array(275, 'MAURITIUS');
country[130] = new Array(439, 'MAYOTTE');
country[131] = new Array(269, 'MEXICO');
country[132] = new Array(404, 'MICRONESIA, FEDERATED STATES OF');
country[133] = new Array(458, 'MOLDOVA');
country[134] = new Array(477, 'MONACO');
country[135] = new Array(272, 'MONGOLIA');
country[136] = new Array(421, 'MONTSERRAT');
country[137] = new Array(267, 'MOROCCO');
country[138] = new Array(273, 'MOZAMBIQUE');
country[139] = new Array(271, 'MYANMAR (BURMA)');
country[140] = new Array(464, 'NAMIBIA');
country[141] = new Array(405, 'NAURU');
country[142] = new Array(282, 'NEPAL');
country[143] = new Array(280, 'NETHERLANDS');
country[144] = new Array(191, 'NETHERLANDS ANTILLES');
country[145] = new Array(402, 'NEW CALEDONIA');
country[146] = new Array(283, 'NEW ZEALAND');
country[147] = new Array(279, 'NICARAGUA');
country[148] = new Array(469, 'NIGER');
country[149] = new Array(278, 'NIGERIA');
country[150] = new Array(410, 'NIUE');
country[151] = new Array(291, 'NORTH KOREA');
country[152] = new Array(418, 'NORTHERN MARIANA ISLANDS');
country[153] = new Array(281, 'NORWAY');
country[154] = new Array(284, 'OMAN');
country[155] = new Array(285, 'PAKISTAN');
country[156] = new Array(286, 'PANAMA');
country[157] = new Array(289, 'PAPUA NEW GUINEA');
country[158] = new Array(293, 'PARAGUAY');
country[159] = new Array(287, 'PERU');
country[160] = new Array(288, 'PHILIPPINES');
country[161] = new Array(414, 'PITCAIRN');
country[162] = new Array(290, 'POLAND');
country[163] = new Array(292, 'PORTUGAL');
country[164] = new Array(331, 'PUERTO RICO');
country[165] = new Array(429, 'PUERTO RICO (I)');
country[166] = new Array(294, 'QATAR');
country[167] = new Array(438, 'REUNION');
country[168] = new Array(295, 'ROMANIA');
country[169] = new Array(332, 'RUSSIA');
country[170] = new Array(296, 'RWANDA');
country[171] = new Array(300, 'SAINT HELENA');
country[172] = new Array(426, 'SAINT KITTS & NEVIS');
country[173] = new Array(431, 'SAINT LUCIA');
country[174] = new Array(461, 'SAINT PIERRE & MIQUELON');
country[175] = new Array(427, 'SAINT VINCENT AND THE GRENADINES');
country[176] = new Array(325, 'SAMOA');
country[177] = new Array(480, 'SAN MARINO');
country[178] = new Array(305, 'SAO TOME AND PRINCIPE');
country[179] = new Array(297, 'SAUDI ARABIA');
country[180] = new Array(468, 'SENEGAL');
country[181] = new Array(459, 'SERBIA/MONTENEGRO');
country[182] = new Array(309, 'SEYCHELLES');
country[183] = new Array(302, 'SIERRA LEONE');
country[184] = new Array(299, 'SINGAPORE');
country[185] = new Array(453, 'SLOVAKIA');
country[186] = new Array(338, 'SLOVENIA');
country[187] = new Array(301, 'SOLOMON ISLANDS');
country[188] = new Array(304, 'SOMALIA');
country[189] = new Array(327, 'SOUTH AFRICA');
country[190] = new Array(339, 'SOUTH KOREA');
country[191] = new Array(229, 'SPAIN');
country[192] = new Array(264, 'SRI LANKA');
country[193] = new Array(298, 'SUDAN');
country[194] = new Array(306, 'SURINAME');
country[195] = new Array(308, 'SWAZILAND');
country[196] = new Array(307, 'SWEDEN');
country[197] = new Array(211, 'SWITZERLAND');
country[198] = new Array(310, 'SYRIAN ARAB REPUBLIC');
country[199] = new Array(411, 'TAHITI');
country[200] = new Array(317, 'TAIWAN');
country[201] = new Array(457, 'TAJIKISTAN');
country[202] = new Array(318, 'TANZANIA, UNITED REPUBLIC OF');
country[203] = new Array(311, 'THAILAND');
country[204] = new Array(470, 'TOGO');
country[205] = new Array(408, 'TOKELAU');
country[206] = new Array(313, 'TONGA');
country[207] = new Array(314, 'TRINIDAD AND TOBAGO');
country[208] = new Array(315, 'TUNISIA');
country[209] = new Array(316, 'TURKEY');
country[210] = new Array(456, 'TURKMENISTAN');
country[211] = new Array(407, 'TUVALU');
country[212] = new Array(319, 'UGANDA');
country[213] = new Array(460, 'UKRAINE');
country[214] = new Array(192, 'UNITED ARAB EMIRATES');
country[215] = new Array(235, 'UNITED KINGDOM');
country[216] = new Array(321, 'UNITED STATES');
country[217] = new Array(416, 'UNITED STATES MINOR OUTLYING ISLANDS');
country[218] = new Array(320, 'URUGUAY');
country[219] = new Array(455, 'UZBEKISTAN');
country[220] = new Array(324, 'VANUATU');
country[221] = new Array(322, 'VENEZUELA');
country[222] = new Array(323, 'VIETNAM');
country[223] = new Array(425, 'VIRGIN ISLANDS (U.K.)');
country[224] = new Array(424, 'VIRGIN ISLANDS (U.S.)');
country[225] = new Array(415, 'WAKE ISLAND');
country[226] = new Array(419, 'WALLIS & FUTUNA');
country[227] = new Array(326, 'YEMEN');
country[228] = new Array(328, 'ZAMBIA');
country[229] = new Array(329, 'ZIMBABWE');


