
function NavigateToMarket(Rgn) {
    if (Rgn == null || Rgn.length == 0) {
        Rgn = GetSelectedRegion();
    }
    if (Rgn.length > 0 && document.getElementById("SelMarket").value != null && document.getElementById("SelMarket").value != "NoMarkets") {
        window.location.href = Rgn.toLowerCase() + "/markets/" + document.getElementById("SelMarket").value + ".aspx";
       }

}

function FetchContact() {
    window.location.href = 'default.aspx?contact=' + document.getElementById('TxtBrokerSearch').value;
}
function FetchContactFromRegion(Rgn) {
    window.location.href = 'contact/default.aspx?contact=' + document.getElementById('TxtBrokerSearch').value;
} 

function NavigateToContact(Rgn) {
    if (Rgn == null || Rgn.length == 0)
    {
       Rgn =  GetSelectedRegion();
    }

    var SelContact = "";
    SelContact = document.getElementById("TxtBrokerSearch").value;

    if (Rgn.length > 0 && SelContact.length > 0)
    {
        window.location.href = Rgn.toLowerCase() + "/contact/default.aspx?contact=" + SelContact.toLowerCase();
    }

  
}

function GetSelectedRegion(){
    if (document.getElementById("USMarket").checked)
    {
    return "us";
    }
if (document.getElementById("EUMarket").checked)
    {
    return "eu";
    }
if (document.getElementById("ASIAPacificMarket").checked)
    {
    return "asiapacific";
    }
}

function SetContactUsMarkets(Rgn) {

    //Remove Previous Options
    removeAllOptions(document.getElementById("SelMarket"));

    //Get Selected Region
    if (Rgn == null || Rgn.length == 0) {
        Rgn = GetSelectedRegion();
    }

//    for (var i=0; i < document.forms[0].RdoGrpRegion..length; i++)
//       {
//           if (document.forms[0].RdoGrpRegion[i].checked)
//            {
//                SelRegion = document.forms[0].RdoGrpRegion[i].value;
//           }
//       }
//    
    //Set US Markets
    if (Rgn == 'us') {
        if (document.getElementById("DivMarketLabel") != null)
        { document.getElementById("DivMarketLabel").style.display = "inline"; }
        if (document.getElementById("DivMarket") != null)
        { document.getElementById("DivMarket").style.display = "inline"; }
        addOption(document.getElementById("SelMarket"), "AgricultureAndSofts", "Agriculture and Softs");
        addOption(document.getElementById("SelMarket"), "Aviation", "Aviation");
        addOption(document.getElementById("SelMarket"), "Coal", "Coal");
        addOption(document.getElementById("SelMarket"), "Electricity", "Electricity");
        addOption(document.getElementById("SelMarket"), "ElectronicMarkets", "Electronic Markets");
        addOption(document.getElementById("SelMarket"), "EnvironmentalMarkets", "Environmental Markets");
        addOption(document.getElementById("SelMarket"), "Logistics", "Logistics");
        addOption(document.getElementById("SelMarket"), "NaturalGas", "Natural Gas");
        addOption(document.getElementById("SelMarket"), "NuclearFuels", "Nuclear Fuels");
        addOption(document.getElementById("SelMarket"), "Oils", "Oils");
        
    }

	//Set EU Markets
    if (Rgn == 'eu') {
        if (document.getElementById("DivMarketLabel") != null)
        { document.getElementById("DivMarketLabel").style.display = "inline"; }
        if (document.getElementById("DivMarket") != null)
        { document.getElementById("DivMarket").style.display = "inline"; }
	    addOption(document.getElementById("SelMarket"), "Coal", "Coal");
	    addOption(document.getElementById("SelMarket"), "Electricity", "Electricity");
	    addOption(document.getElementById("SelMarket"), "EnvironmentalMarkets", "Environmental Markets");
	    addOption(document.getElementById("SelMarket"), "NaturalGas", "NaturalGas");
        addOption(document.getElementById("SelMarket"), "Oils", "Oils");
        
}

    //Set ASIA Markets
    if (Rgn == 'asiapacific') {
        if (document.getElementById("DivMarketLabel") != null)
        { document.getElementById("DivMarketLabel").style.display = "none"; }
        if (document.getElementById("DivMarket") != null)
        { document.getElementById("DivMarket").style.display = "none"; }
        
        //addOption(document.getElementById("SelMarket"), "NoMarkets", "No Markets");
	}

}


//This function removes all options from a selectbox
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}

//This function adds an option to a selectbox
function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

