/* 
 *	Copyright (c) 2002 Fieba Ltd 
 *	Fieba Javscript Popup Opener
 *	Author : Gavin Dell
 *	Version : 1.1
 */
	function checkString(Input) {
		//check for null input
		if (null == Input)
		{
			return 0;
		}
		//check for zero length string.
		if ("string" == typeof(Input) && "" == Input)
		{
			return 1;
		}
		// otherwise this is a string.
		return 2;
	}

	function checkNumber(Input) {

		// check for null input
		if (null == Input)
		{
			return 0;
		}

		if (isNaN(parseFloat(Input)))
		{
			return 1;
		}

		return 2; // number
	}


	function FiebaGeneralPopUp(popupURL, AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, ServiceCode)
    { 
	    
	var isFirst = true;

	if (FiebaGeneralPopUp.arguments.length != 0) {
	
		popupURL += '?';

		// Try to parse a number out of AmountToConvert.
		if (checkNumber(AmountToConvert) > 1) {
			popupURL += 'inputAmount=' + parseFloat(AmountToConvert);
			isFirst = false;
		}
		// Parse currency code and if not empty string then add to URL
		if (checkString(SourceCurrencyCode) == 2) {
				popupURL += (isFirst?'':'&') + 'fromCurrency=' + SourceCurrencyCode;
				isFirst = false;
		}
		// Parse destination code and if not empty add to URL;
		if (checkString(DestinationCurrencyCode) == 2) {
				popupURL += (isFirst?'':'&') + 'toCurrency=' + DestinationCurrencyCode;
				isFirst = false;
		}
		if (checkString(ServiceCode) > 1) {
			popupURL += (isFirst?'':'&') + 'serviceCode=' + ServiceCode;
		}
	}

	PopupWindow = window.open ( popupURL,'PopupWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=220,width=350')
	PopupWindow.focus();
   	return PopupWindow;
    }


	function FiebaPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCRETAIL');
	}

	function FiebaB2BPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCB2B');
	}

	function FiebaRetailPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCPRETAIL');
	}

	function FiebaNonRetailPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCPNONRETAIL');
	}
	
	function FiebaCustomPopUp(cnvId, AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode)
    { 
	    
	var popupURL = 'http://www.fieba.net/converter';
	var isFirst = true;

	if (FiebaCustomPopUp.arguments.length != 0) {
		
		popupURL += '?serviceCode=CPCC';

		isFirst = false;

		if (checkNumber(cnvId) > 1) {
			popupURL += (isFirst?'':'&') + 'cnvId=' + new Number(cnvId).toString();
		} else 
		{ 
			FiebaPopUp( AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode );
		}
		// Try to parse a number out of AmountToConvert.
		if (checkNumber(AmountToConvert) > 1) {
			popupURL += (isFirst?'':'&') + 'inputAmount=' + parseFloat(AmountToConvert);
		}
		// Parse currency code and if not empty string then add to URL
		if (checkString(SourceCurrencyCode) == 2) {
				popupURL += (isFirst?'':'&') + 'fromCurrency=' + SourceCurrencyCode;
		}
		// Parse destination code and if not empty add to URL;
		if (checkString(DestinationCurrencyCode) == 2) {
			popupURL += (isFirst?'':'&') + 'toCurrency=' + DestinationCurrencyCode;
		}
	}

	CustomPopupWindow = window.open ( popupURL,'PopupWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=220,width=350')
	CustomPopupWindow.focus();
   	return CustomPopupWindow;
    }


