// JavaScript Document
var hashMap = new Map();
hashMap.put("all","All Countries");
hashMap.put("regions","All Countries by Region");
hashMap.put("groups","Country Groups");
hashMap.put("AA","Aruba");
hashMap.put("AC","Antigua and Barbuda");
hashMap.put("AF","Afghanistan");
hashMap.put("AG","Algeria");
hashMap.put("AJ","Azerbaijan");
hashMap.put("AL","Albania");
hashMap.put("AM","Armenia");
hashMap.put("AO","Angola");
hashMap.put("AQ","American Samoa");
hashMap.put("AR","Argentina");
hashMap.put("AS","Australia");
hashMap.put("AU","Austria");
hashMap.put("AY","Antarctica");
hashMap.put("BA","Bahrain");
hashMap.put("BB","Barbados");
hashMap.put("BC","Botswana");
hashMap.put("BD","Bermuda");
hashMap.put("BE","Belgium");
hashMap.put("BF","Bahamas, The");
hashMap.put("BG","Bangladesh");
hashMap.put("BH","Belize");
hashMap.put("BK","Bosnia and Herzegovina");
hashMap.put("BL","Bolivia");
hashMap.put("BM","Burma (Myanmar)");
hashMap.put("BN","Benin");
hashMap.put("BO","Belarus");
hashMap.put("BP","Solomon Islands");
hashMap.put("BR","Brazil");
hashMap.put("BT","Bhutan");
hashMap.put("BU","Bulgaria");
hashMap.put("BX","Brunei");
hashMap.put("BY","Burundi");
hashMap.put("CA","Canada");
hashMap.put("CB","Cambodia");
hashMap.put("CD","Chad");
hashMap.put("CE","Sri Lanka");
hashMap.put("CF","Congo (Brazzaville)");
hashMap.put("CG","Congo (Kinshasa)");
hashMap.put("CH","China");
hashMap.put("CI","Chile");
hashMap.put("CJ","Cayman Islands");
hashMap.put("CM","Cameroon");
hashMap.put("CN","Comoros");
hashMap.put("CO","Colombia");
hashMap.put("CS","Costa Rica");
hashMap.put("CT","Central African Republic");
hashMap.put("CU","Cuba");
hashMap.put("CV","Cape Verde");
hashMap.put("CW","Cook Islands");
hashMap.put("CY","Cyprus");
hashMap.put("CZ","Former Czechoslovakia");
hashMap.put("DA","Denmark");
hashMap.put("DJ","Djibouti");
hashMap.put("DO","Dominica");
hashMap.put("DR","Dominican Republic");
hashMap.put("EC","Ecuador");
hashMap.put("EG","Egypt");
hashMap.put("EI","Ireland");
hashMap.put("EK","Equatorial Guinea");
hashMap.put("EN","Estonia");
hashMap.put("ER","Eritrea");
hashMap.put("ES","El Salvador");
hashMap.put("ET","Ethiopia");
hashMap.put("EZ","Czech Republic");
hashMap.put("FG","French Guiana");
hashMap.put("FI","Finland");
hashMap.put("FJ","Fiji");
hashMap.put("FK","Falkland Islands (Islas Malvinas)");
hashMap.put("FO","Faroe Islands");
hashMap.put("FP","French Polynesia");
hashMap.put("FR","France");
hashMap.put("GA","Gambia, The");
hashMap.put("GB","Gabon");
hashMap.put("GC","Germany, East");
hashMap.put("GE","Germany, West");
hashMap.put("GG","Georgia");
hashMap.put("GH","Ghana");
hashMap.put("GI","Gibraltar");
hashMap.put("GJ","Grenada");
hashMap.put("GL","Greenland");
hashMap.put("GM","Germany");
hashMap.put("GP","Guadeloupe");
hashMap.put("GQ","Guam");
hashMap.put("GR","Greece");
hashMap.put("GT","Guatemala");
hashMap.put("GV","Guinea");
hashMap.put("GY","Guyana");
hashMap.put("HA","Haiti");
hashMap.put("HK","Hong Kong");
hashMap.put("HO","Honduras");
hashMap.put("HQ","Hawaiian Trade Zone");
hashMap.put("HR","Croatia");
hashMap.put("HU","Hungary");
hashMap.put("IC","Iceland");
hashMap.put("ID","Indonesia");
hashMap.put("IN","India");
hashMap.put("IQ","U.S. Pacific Islands");
hashMap.put("IR","Iran");
hashMap.put("IS","Israel");
hashMap.put("IT","Italy");
hashMap.put("IZ","Iraq");
hashMap.put("JA","Japan");
hashMap.put("JM","Jamaica");
hashMap.put("JO","Jordan");
hashMap.put("KE","Kenya");
hashMap.put("KG","Kyrgyzstan");
hashMap.put("KN","Korea, North");
hashMap.put("KR","Kiribati");
hashMap.put("KS","Korea, South");
hashMap.put("KU","Kuwait");
hashMap.put("KZ","Kazakhstan");
hashMap.put("LA","Laos");
hashMap.put("LE","Lebanon");
hashMap.put("LG","Latvia");
hashMap.put("LH","Lithuania");
hashMap.put("LI","Liberia");
hashMap.put("LO","Slovakia");
hashMap.put("LT","Lesotho");
hashMap.put("LU","Luxembourg");
hashMap.put("LY","Libya");
hashMap.put("MA","Madagascar");
hashMap.put("MB","Martinique");
hashMap.put("MC","Macau");
hashMap.put("MD","Moldova");
hashMap.put("MG","Mongolia");
hashMap.put("MH","Montserrat");
hashMap.put("MI","Malawi");
hashMap.put("MJ","Montenegro");
hashMap.put("MK","Macedonia");
hashMap.put("ML","Mali");
hashMap.put("MO","Morocco");
hashMap.put("MP","Mauritius");
hashMap.put("MR","Mauritania");
hashMap.put("MT","Malta");
hashMap.put("MU","Oman");
hashMap.put("MV","Maldives");
hashMap.put("MX","Mexico");
hashMap.put("MY","Malaysia");
hashMap.put("MZ","Mozambique");
hashMap.put("NC","New Caledonia");
hashMap.put("NE","Niue");
hashMap.put("NG","Niger");
hashMap.put("NH","Vanuatu");
hashMap.put("NI","Nigeria");
hashMap.put("NL","Netherlands");
hashMap.put("NO","Norway");
hashMap.put("NP","Nepal");
hashMap.put("NR","Nauru");
hashMap.put("NS","Suriname");
hashMap.put("NT","Netherlands Antilles");
hashMap.put("NU","Nicaragua");
hashMap.put("NZ","New Zealand");
hashMap.put("PA","Paraguay");
hashMap.put("PE","Peru");
hashMap.put("PK","Pakistan");
hashMap.put("PL","Poland");
hashMap.put("PM","Panama");
hashMap.put("PO","Portugal");
hashMap.put("PP","Papua New Guinea");
hashMap.put("PU","Guinea-Bissau");
hashMap.put("QA","Qatar");
hashMap.put("RB","Serbia");
hashMap.put("RE","Reunion");
hashMap.put("RO","Romania");
hashMap.put("RP","Philippines");
hashMap.put("RQ","Puerto Rico");
hashMap.put("RS","Russia");
hashMap.put("RW","Rwanda");
hashMap.put("SA","Saudi Arabia");
hashMap.put("SB","Saint Pierre and Miquelon");
hashMap.put("SC","Saint Kitts and Nevis");
hashMap.put("SE","Seychelles");
hashMap.put("SF","South Africa");
hashMap.put("SG","Senegal");
hashMap.put("SH","Saint Helena");
hashMap.put("SI","Slovenia");
hashMap.put("SL","Sierra Leone");
hashMap.put("SN","Singapore");
hashMap.put("SO","Somalia");
hashMap.put("SP","Spain");
hashMap.put("ST","Saint Lucia");
hashMap.put("SU","Sudan");
hashMap.put("SW","Sweden");
hashMap.put("SY","Syria");
hashMap.put("SZ","Switzerland");
hashMap.put("TC","United Arab Emirates");
hashMap.put("TD","Trinidad and Tobago");
hashMap.put("TH","Thailand");
hashMap.put("TI","Tajikistan");
hashMap.put("TK","Turks and Caicos Islands");
hashMap.put("TN","Tonga");
hashMap.put("TO","Togo");
hashMap.put("TP","Sao Tome and Principe");
hashMap.put("TS","Tunisia");
hashMap.put("TT","Timor-Leste (East Timor)");
hashMap.put("TU","Turkey");
hashMap.put("TW","Taiwan");
hashMap.put("TX","Turkmenistan");
hashMap.put("TZ","Tanzania");
hashMap.put("UG","Uganda");
hashMap.put("UK","United Kingdom");
hashMap.put("UP","Ukraine");
hashMap.put("UR","Former U.S.S.R.");
hashMap.put("US","United States");
hashMap.put("UV","Burkina Faso");
hashMap.put("UY","Uruguay");
hashMap.put("UZ","Uzbekistan");
hashMap.put("VC","Saint Vincent/Grenadines");
hashMap.put("VE","Venezuela");
hashMap.put("VI","Virgin Islands, British");
hashMap.put("VM","Vietnam");
hashMap.put("VQ","Virgin Islands,  U.S.");
hashMap.put("WA","Namibia");
hashMap.put("WI","Western Sahara");
hashMap.put("WQ","Wake Island");
hashMap.put("WS","Samoa");
hashMap.put("WZ","Swaziland");
hashMap.put("YM","Yemen");
hashMap.put("YO","Former Yugoslavia");
hashMap.put("YR","Former Serbia and Montenegro");
hashMap.put("ZA","Zambia");
hashMap.put("ZI","Zimbabwe");
hashMap.put("IV","Cote d'Ivoire (IvoryCoast)");
hashMap.put("en1","Non OECD Europe");
hashMap.put("fs1","Former Soviet Union");
hashMap.put("oa1","Other Asia");
hashMap.put("on1","Other NON-OECDE");
hashMap.put("tn1","Total NON-OECDE");
hashMap.put("ww","World");
hashMap.put("NULL","None");
hashMap.put("OH","U.S. Territories");
hashMap.put("CG2","EU-15");
hashMap.put("CG3","IEA");
hashMap.put("CG5","OECD");
hashMap.put("CG6","Non OECD");
hashMap.put("CG7","OECD Europe");
hashMap.put("CG9","OPEC");
hashMap.put("CG1","EU-27");
hashMap.put("r1","North America");
hashMap.put("r2","Central & South America");
hashMap.put("r3","Europe");
hashMap.put("r4","Eurasia");
hashMap.put("r5","Middle East");
hashMap.put("r6","Africa");
hashMap.put("r7","Asia & Oceania");
hashMap.put("CG10","OPEC-Africa");
hashMap.put("CG11","OPEC-South America");
hashMap.put("CG12","OPEC-Asia");
hashMap.put("CG13","OECD North America");
hashMap.put("CG14","OECD Asia & Oceania");
hashMap.put("CG8","Persian Gulf");

function validateBtn(btn){
 var cnt = -1;
    for (var i=btn.length-1; i > -1; i--) {
        if (btn[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1) return btn[cnt].value;
    else return null;
}

/*rB = function(radioBl) {
    if(radioBl.checked == true) {
        radioBl.checked = false;
        return false;
    }
    else {
        radioBl.checked = true;
        return true;
    }
}
*/
function Left(str, c){
	if (c <= 0){
	    return "";
	}else if (c > String(str).length){
	    return str;
	}else{
	    return String(str).substring(0,c);
	}
}
function Right(str, c){
    if (c <= 0){
       return "";
	}else if (c > String(str).length){
       return str;
	}else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - c);
	}
}
function Mid(str, start, len)
{
// Make sure start and len are within proper bounds
    if (start < 0 || len < 0) return "";
    var iEnd, iLen = String(str).length;
    if (start + len > iLen)
          iEnd = iLen;
    else
          iEnd = start + len;
    return String(str).substring(start,iEnd);
}

function isChecked(e){
	var cvalue ="";
			
	var objform=document.forms.surveyform;
	if(e.value=="monthly"){
		objform.monthly.checked=true;
		objform.quarterly.checked=false;
		//document.surveyform.submit();
		//document.getElementById("progress").className="waiting";
	}else if(e.value=="quarterly"){
		objform.quarterly.checked=true;
		objform.monthly.checked=false;
		//document.surveyform.submit();
		//document.getElementById("progress").className="waiting";
	}else if(e.value=="annual"){
		objform.quarterly.checked=false;
		objform.monthly.checked=false;
		objform.annual.checked=true;
	}else if(e.value=="regions"){
		//objform.groups.checked=false;
		for(i=0; i<objform.fips.length; i++){
			if(objform.fips[i].value != "regions"){
				objform.fips[i].checked=false;
			}
		}
	}else if(e.value=="groups"){
		//objform.regions.checked=false;
		for(i=0; i<objform.fips.length; i++){
			if(objform.fips[i].value!="groups"){
				objform.fips[i].checked=false;
			}
		}
	}else if(e.value=="all"){
		//objform.regions.checked=false;
		for(i=0; i<objform.fips.length; i++){
			if(objform.fips[i].value!="all"){
				objform.fips[i].checked=false;
			}
		}
	}
	
	
	for(i=0; i<objform.products.length; i++){
		if(objform.products[i].checked==true){
			objform.alltypes.checked=false;
		}
	}
	
	for(i=0; i<objform.fips.length; i++){
		if(objform.fips[i].value == e.value && objform.fips[i].value != "groups" && objform.fips[i].value != "regions" && objform.fips[i].value != "all"){
			//alert(objform.fips[1].value);
			objform.fips[0].checked=false;
			if(objform.fips[9]){
				if(objform.fips[9].value=="groups"){
				objform.fips[9].checked=false;
				}
			}
			if(objform.fips[16]){
				if(objform.fips[16].value=="all"){
				objform.fips[16].checked=false;
				}
			}
			
			if(objform.fips[i].value == "groups"){
			objform.fips[9].checked=false;}
		}
	}
	
	var countrydisplay=document.getElementById('searchlink');
	
	for(i=0; i<objform.fips.length; i++){
		if(objform.fips[i].checked && objform.fips[i].value!=""){
			var theValue = objform.fips[i].value;
			var tempVal = hashMap.get(theValue);
			if(cvalue == ""){
		  	cvalue = tempVal
			}else{
			cvalue = cvalue + ", " + tempVal;
			}
		
		}
	}
	<!--
	var browserName=navigator.appName; 

	//-->
	if (browserName!="Microsoft Internet Explorer"){		
		if(countrydisplay){
			countrydisplay.innerHTML="<option value=\"\" >"+cvalue+"</option>";		
			
		}
	}
	activeB();
}


function GeterrorMessage(errortype){
	var err_messgae;
	
	switch(errortype)
	{
		case 1:
			err_message = "Please select a start and year then try again.";
			break;
		case 2: 
			err_message = "Please select a frequency then try again.";
			break;
		case 3: 
			err_message = "You did not select any country from the list.\nPlease try again."
			break;	
		case 4:
			err_message = "You did not select the specified source country\nPlease try again."
			break;
		case 5:
			err_message = "You did not select the single importer\nPlease try again.";
			break;
		case 6: 
			err_message = "You did not select a time period.\n Please try again.";
			break;
		case 7:
		err_message = "You did not select the exporter(s).\n Please try again.";
			break;
		case 8:
		err_message = "You did not select the importer group(s).\n Please try again.";
	}
	alert(err_message);
}
function showForm(e){
	var objform=document.forms.surveyform;
	var val=e.value;
	if(e=="" || val=="year"){
	document.getElementById('mid').style.visibility= 'hidden';
	document.getElementById('qid').style.visibility= 'hidden';
	objform.monthdata.style.visibility = 'hidden';
	objform.Qdata.style.visibility = 'hidden';
	objform.quarter.checked=false;
	objform.month.checked=false;
     }
	if(val=="quarter"){
		objform.Qdata.style.visibility = 'visible';
		document.getElementById('qid').style.visibility= 'visible';
		objform.monthdata.style.visibility = 'hidden';
		document.getElementById('mid').style.visibility= 'hidden';
		objform.quarter.checked=true;
		objform.month.checked=false;
		objform.year.checked=false;
	}else if(val=="month"){
		objform.monthdata.style.visibility = 'visible';
		document.getElementById('mid').style.visibility= 'visible';
		objform.Qdata.style.visibility = 'hidden';
		document.getElementById('qid').style.visibility= 'hidden';
		objform.month.checked=true;
		objform.quarter.checked=false;
		objform.year.checked=false;
	}
}

function toggleYear(id){
	//alert("year");
	var objform=document.forms.surveyform;
	var yearList1 = document.getElementById('sub3');
	var yearList2 = document.getElementById('sub4');
	var yearList3 = document.getElementById('sub5');
	
	if (id=="sub5"){		
		yearList1.style.display='none';
		yearList2.style.display='none';
		yearList3.style.display='block';
	}else {
		//yearList1.style.display='block';
		//yearList2.style.display='block';
		yearList3.style.display='none';
	}
	
	for(i=0; i<objform.products.length; i++){
		if(objform.products[i].checked==true){
			//alert(objform.products[i].checked==true);
			objform.products[i].checked=false;
		}
	}
}

function toggleYear2(){
	//alert("year");
	var objform=document.forms.surveyform;
	var yearList1 = document.getElementById('sub3');
	var yearList2 = document.getElementById('sub4');
	var yearList3 = document.getElementById('sub5');
	
		yearList1.style.display='inline-block';
		yearList2.style.display='inline-block';
		yearList3.style.display='none';
}

var request;

function displayItem(str,type){
	/*request = GetXmlHttpObject();
	if(request==null)
	{
		alert("Your browser does not support AJAX!");
		return;
	}
	
	var url="iedindex.cfm";
	request.open("GET",url,true);
	request.onreadystatechange=itemChanged(str);
	request.send(null);*/
	//alert(str.value);
	if(type == "year1"){
		document.getElementById("item").innerHTML=str.value;
	}else if(type == "year2"){
		document.getElementById("item2").innerHTML=str.value;
	}else if(type == "unit"){
		document.getElementById("unit2").innerHTML=str.value;
	}

}
function itemChanged(){
	
	if(request.readyState==4){
		document.getElementById("year1").innerHTML=request.responseText;
		
	}
	
}

/*function highlight(which, color){
	if(document.all||document.getElementById)
		which.style.backgroundColor = color;
}*/

function GetXmlHttpObject()
{
var request=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  request=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    request=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    request=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return request;
}

function activeB(){
	var objform=document.forms.surveyform;
	var yearList1 = document.getElementById('sub3');
	var yearList2 = document.getElementById('sub4');
	var yearList3 = document.getElementById('sub5');
	
	document.getElementById("updateB").className='submit_B';	
	document.getElementById("updateB").removeAttribute("disabled");
	
}

function expandC(){
  	var expandform = document.getElementById("cfips");
		
  	expandform.setAttribute('multiple', 'no');
	expandform.setAttribute('style','height:300px;font-size:12px;padding:4px 2px;border:solid 1px #aacfe4;cursor:pointer;');
	expandform.setAttribute('size', '15');
	document.getElementById("colC2").className='colC1';
	document.getElementById("colC").className='expImg';
	//document.getElementById("expC").className='collpImg';
	//document.getElementById("cc1").style.display = 'none';
	
	/*document.getElementById("cc2").style.display = 'none';
	document.getElementById("cc3").style.display = 'none';
	document.getElementById("cc4").style.display = 'block';
	document.getElementById("cc5").style.display = 'block';*/
  }
  function contract(){
  	var expandform = document.getElementById("cfips");
	//alert(expandform);
	expandform.removeAttribute("multiple");
	expandform.removeAttribute("size");
  	//expandform.setAttribute('multiple', 'no');
	expandform.setAttribute('style','font-size:12px;padding:4px 2px;border:solid 1px #aacfe4;');
	document.getElementById("colC2").className='colC2';
	document.getElementById("colC").className='collpImg';
	//document.getElementById("expC").className='expImg';
	//document.getElementById("cc1").style.display = 'block';
	/*document.getElementById("cc2").style.display = 'block';
	document.getElementById("cc3").style.display = 'block';
	document.getElementById("cc4").style.display = 'block';
	document.getElementById("cc5").style.display = 'block';*/
  }
  
function Map()
{
    // members
    this.keyArray = new Array(); // Keys
    this.valArray = new Array(); // Values
        
    // methods
    this.put = put;
    this.get = get;
	this.findIt = findIt;

}

function put( key, val )
{
    var elementIndex = this.findIt( key );
    
    if( elementIndex == (-1) )
    {
        this.keyArray.push( key );
        this.valArray.push( val );
    }
    else
    {
        this.valArray[ elementIndex ] = val;
    }
}

function get( key )
{
    var result = null;
    var elementIndex = this.findIt( key );

    if( elementIndex != (-1) )
    {   
        result = this.valArray[ elementIndex ];
    }  
    
    return result;
}

function findIt( key )
{
    var result = (-1);

    for( var i = 0; i < this.keyArray.length; i++ )
    {
        if( this.keyArray[ i ] == key )
        {
            result = i;
            break;
        }
    }
    return result;
}
