function selectCountry(Country)
{
    
    var strQueryString;
    strQueryString = "?Action=GetCurrencies";
    method = "post";
	var ICtryCde;
	var ChargeGroup;
	
	//Get Ictrycde
	ICtryCde = Country.substring(3, 6);
	
	//ChargeGroupCode
	document.forms[0].hdnICtryCde.value = ICtryCde;
	
	ChargeGroup = (Country.substring(6, 9));
	document.forms[0].hdnChargeCode.value = ChargeGroup;

	if (document.forms[0].optPayment[0].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[0].value;  
	else if (document.forms[0].optPayment[1].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[1].value;  
	else if (document.forms[0].optPayment[2].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[2].value;  
	else
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[3].value;  

	//Submit the form	
	document.forms[0].action = 'PriceIt.asp' + strQueryString;
	document.forms[0].submit();

}

function selectCurrency(Currency)
{
    
    var strQueryString;
    strQueryString = "?Action=GetCurrCode";
    method = "post";
	
	if (document.forms[0].optPayment[0].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[0].value;  
	else if (document.forms[0].optPayment[1].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[1].value;
	else if (document.forms[0].optPayment[1].checked == true)
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[2].value;    
	else
		document.forms[0].hdnPayment.value = document.forms[0].optPayment[3].value;  

	
	//Submit the form	
	document.forms[0].hdnCurrCode.value = Currency;
	document.forms[0].action = 'PriceIt.asp' + strQueryString;
	document.forms[0].submit();

}

function selectService(Service)
{
    
    var strQueryString;
    strQueryString = "?Action=GetCurrencies";
    method = "post";
      
	document.forms[0].hdnServiceCde.value = Service;
	
	//Submit the form	
	document.forms[0].action = 'PriceIt.asp' + strQueryString;
	document.forms[0].submit();

}

function EnableSendAmount()
{
	document.getElementById("AmountCaption").innerHTML = '<font size="2" color="black" face="Arial, Helvetica, sans-serif"><strong> Send Amount: </strong>';
}

function EnablePayoutAmount()
{
	document.getElementById("AmountCaption").innerHTML = '<font size="2" color="black" face="Arial, Helvetica, sans-serif"><strong> Payout Amount: </strong>';
}

function displayToolTip()
{
	var radios = document.getElementsByName('optPayment');
	for (var i = 0; i < radios.length; i++) {
		if (radios[i].checked && (radios[i].value != 'CH')) {
			alert("Credit/Debit cards services are only avaliable via the phone and not agent locations.");
			break;
		}
	}
	//if (document.getElementById('SelService').disabled == false)
	//{
		var obj = document.getElementById('SelCountry')
		selectCountry(obj.options[obj.selectedIndex].value);
	//} 
}


function SubmitPage()
{
	var strCountry;
	var strCurrency;
	var strQueryString;
	
    strQueryString = "?Action=SubmitPage";
    method = "post";
    
	//Check to ensure a payment type was selected
	if (document.forms[0].optPayment[0].checked == false && document.forms[0].optPayment[1].checked == false && document.forms[0].optPayment[2].checked == false && document.forms[0].optPayment[3].checked == false)
	{
		alert("A payment type must be selected");
		document.forms[0].optPayment[0].focus();
		return;
	}

	//Check to ensure a price type was entered
	if (document.forms[0].optPriceType[0].checked == false  && document.forms[0].optPriceType[1].checked == false)
	{
		alert("A Price Type must be selected");
		document.forms[0].optPriceType[0].focus(); 
		return;
	}

	// Validate that a country is selected
	strCountry=document.forms[0].SelCountry.value;
	if(strCountry == "all")
	{
		alert("A Country must be selected.");
		document.forms[0].SelCountry.focus();
		return;
	}

	// Validate that a country is selected
	strCurrency=document.forms[0].SelCurrency.value;
	if(strCurrency == "0")
	{
		alert("A Payout Currency must be selected.");
		document.forms[0].SelCurrency.focus();
		return;
	}
	
	if(document.forms[0].optPriceType[0].checked == true)
	{
		if (document.forms[0].txtAmt.value == "" || document.forms[0].txtAmt.value <= 0)
		{
			alert("Please enter a send amount");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	if(document.forms[0].optPriceType[0].checked == true)
	{
		//Ensure that the field is not blank
		if (document.forms[0].txtAmt.value.length > 7)
		{
			alert("Send amount must be in the format of 0000.00");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	if(document.forms[0].optPriceType[0].checked == true)
	{
		// Call a function to validate the amount field.
		if (isAmount(document.forms[0].txtAmt.value) == false) {
			alert("Invalid amount entered.");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	//Minimum amount greater than 15
	if(document.forms[0].optPriceType[0].checked == true)
	{
		if (document.forms[0].txtAmt.value < 15)
		{
			alert("Please enter a send amount 15 or more.");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	//Payout Checks
	if(document.forms[0].optPriceType[1].checked == true)
	{
		if (document.forms[0].txtAmt.value == "" || document.forms[0].txtAmt.value <= 0)
		{
			alert("Please enter a payout currency amount");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	if (document.forms[0].optPriceType[1].checked == true)
	{	
		//Ensure that the field is not blank
		if (document.forms[0].txtAmt.value.length > 7)
		{
			alert("Payout amount must be in the format 0000.00");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	if (document.forms[0].optPriceType[1].checked == true)
	{	
		if (isAmount(document.forms[0].txtAmt.value) == false) {
			alert("Invalid amount entered.");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
		
	// Minimum amount greater than 15
	if (document.forms[0].optPriceType[1].checked == true)
	{	
		if (document.forms[0].txtAmt.value < 15)
		{
			alert("Please enter a payout amount 15 or more.");
			document.forms[0].txtAmt.focus();
			return;
		}
	}
	
	//'*** Get the Price option value
	if (document.forms[0].optPriceType[0].checked == true)
		document.forms[0].hdnPriceType.value = document.forms[0].optPriceType[0].value;  
	else 
		document.forms[0].hdnPriceType.value = document.forms[0].optPriceType[1].value;  


	// Pass baack a hidden field value from the currency combo 
	document.forms[0].hdnCurrcodeFromCombo.value = document.forms[0].SelCurrency.value;
	
	// Pass baack a hidden field value from the Service combo 
	document.forms[0].hdnServiceCde.value = document.forms[0].SelService.value;
	
	//Set the action of the page + querystring
	document.forms[0].action = 'PriceIt.asp' + strQueryString;
	
	//Submit the form	
	document.forms[0].submit();
}

function isAmount(text)
{
	var numaric = text;
	var bDecimal = false;
	for (var j = 0; j < numaric.length; j++) {
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		if ((hh == 46) || ((hh > 47) && (hh < 59))) {
			if (hh == 46) {
				if (bDecimal == true) {
					return false;
				}
				bDecimal = true;
			}
		}
		else {
			return false;
		}
	}
	return true;
}
