/* 
 *	Copyright (c) 2002 Fieba Ltd 
 *	Fieba Javscript Popup Opener
 *	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, SmallVersion)
    { 
	    
	var isFirst = true;
	var PopupWindow = null;

	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;
		}
	}
	if ( SmallVersion == true ) 
		PopupWindow = window.open ( popupURL,'PopupWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=228,width=146')
	else 
		PopupWindow = window.open ( popupURL,'PopupWindow','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,height=273,width=468')
	// If it isn't null then focus it.
	if (PopupWindow != null) PopupWindow.focus();
   	return PopupWindow;
    }


	function FiebaPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		//FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCRETAIL');
		return FiebaCompactPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode);
	}

	function FiebaB2BPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		return FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCB2B');
	}

	function FiebaRetailPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		return FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCPRETAIL');
	}

	function FiebaNonRetailPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		return FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'PCCPNONRETAIL');
	}
	
	function FiebaCompactPopUp(AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode) 
	{
		return FiebaGeneralPopUp('http://www.fieba.net/converter',AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, 'IFPCCRETAIL', true);
	}

	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')
	if (CustomPopupWindow != null) CustomPopupWindow.focus();
   	return CustomPopupWindow;
    }

	 /*
	  * AmountToConvert - the numeric amount to convert
	  * SourceCurrencyCode - the source currency code to convert from
	  * DestinationCurrencyCode - the destination currency code to convert to
	  * PerformConversion - either true or false - convert automatically?
	  */
	 function FiebaControlIFrame( AmountToConvert, SourceCurrencyCode, DestinationCurrencyCode, PerformConversion ) {
		// Try to parse a number out of AmountToConvert.
		var inputAmount = 1.0;
		var sourceCurrencyCode = "";
		var destinationCurrencyCode = "";
		
		if (checkNumber(AmountToConvert) > 1) {
			inputAmount = parseFloat(AmountToConvert);
		}
		// Parse currency code and if not empty string then add to URL
		if (checkString(SourceCurrencyCode) == 2) {
			sourceCurrencyCode = SourceCurrencyCode;
		}
		// Parse destination code and if not empty add to URL;
		if (checkString(DestinationCurrencyCode) == 2) {
			destinationCurrencyCode = DestinationCurrencyCode;
		}
		
		// try and locate the IFrame Converter.
		iFrame = document.getElementById('FiebaIFrameConverter');
		if ( iFrame != null ) {
			if ( sourceCurrencyCode == "" || destinationCurrencyCode == "" ) {
				iFrame.src = "http://www.fieba.net/converter" + "?serviceCode=IFRETAIL" +
				"&inputAmount=" + inputAmount +  
				( ( sourceCurrencyCode == "" )?"":"&fromCurrency=" + sourceCurrencyCode )	+ 
				( ( destinationCurrencyCode == "" )?"":"&toCurrency=" +
				destinationCurrencyCode ); 
			}
			else { // okay to actually do the conversion.
				iFrame.src = "http://www.fieba.net/converter" + "?serviceCode=IFRETAIL&action=calculate" +
				"&inputAmount=" + inputAmount + "&fromCurrency=" + 
				sourceCurrencyCode + "&toCurrency=" + destinationCurrencyCode;
			}
		}
	 }
