//Note: 'AgentLoginId' value will be blank only if the affiliate is 'Hotel Voucher Shop',else it will be a affiliate company name.
		//e.g.- AgentLoginId = "interflora" .
		var AgentLoginId = "HotelStayUKFlex";
		var DeepLinkURL = "http://www.hotelvouchershop.com/" + AgentLoginId + "/SitePages/BuyerRecipientDetails.aspx";
		
		var currencyConversionRate = 0;
		var totalAmountInSiteCurrency = 0;
		var VoucherAmount = 0;
		var TotalAmount = 0;
		var Quantity = 0 ;
		var baseCurrencyType = "" ;

			function ValidateFields()
			{
				var ControlsParent = 'UC_MultiVouchers_';
				var txtQuantity = document.getElementById("IV_TB_Quantity");
				if (txtQuantity.value == '' || txtQuantity.value == '0')
				{
					alert('Please enter Voucher quantity.');
					txtQuantity.focus();
					return false;
				}
				else 
				{
					if (IsNumeric(txtQuantity.value))
					{
						return true;
					}
					else
					{
						alert('Please enter valid Voucher quantity.');
						txtQuantity.focus();
						return false;
					}
				}
			}
			
			function IsNumeric(sText)
			{
			var ValidChars = "0123456789";
			var IsNumber=true;
			var Char;

			for (i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
				Char = sText.charAt(i); 
				if (ValidChars.indexOf(Char) == -1) 
					{
						IsNumber = false;
					}
			}
			return IsNumber;
			   
			}

			function ChangeCurrencySign(sCurrency)
			{
				var lblCurrencySign = document.getElementById("lbl_CurrencySign");

				/* In Firefox the style is not getting applied for dynamically changing text so here we have assigned style to the label's text.*/
				if(sCurrency == 'GBP')
				{
					lblCurrencySign.innerHTML = '<b><font color="#0d3b78">&pound;</font></b>';
				}
				else if(sCurrency == 'EUR')
				{
					lblCurrencySign.innerHTML = '<b><font color="#0d3b78">&#128;</font></b>';
				}
				else if(sCurrency == 'USD')
				{
					lblCurrencySign.innerHTML = '<b><font color="#0d3b78">&#36;</font></b>';
				}
			}
			
			function AddToBasket()
			{
			try
			{
				   
			if(ValidateFields())
			{
			  var blnValidVoucherAmt=true;
			  //Get the table order div.
			  var Div_Table_OrderData = document.getElementById("Div_Table_OrderData");
			  
			  //Get the error Lable control.
			 var ErrorMessageDiv = document.getElementById("ErrorMessageDiv");
			 if(ErrorMessageDiv!=null)
			 {
			 ErrorMessageDiv.style.display="none";
			 }
			  
			  if(blnValidVoucherAmt)
			  {
			       //Get the table control.
                    var oTable=document.getElementById("OrderTable");
                    //set the display style.
                    Div_Table_OrderData.style.display="block";
                    
                    //Get the currency drop down.
                    var ddlCurrency=document.getElementById("DDL_Currency");
                    //Get the Amount drop down.
                    var ddlAmount=document.getElementById("DDL_Amount");
                    //Get the total quantity text box.
                    var txtQuantity=document.getElementById("IV_TB_Quantity");

                    if(oTable!=null)
                    {
                     var length=oTable.rows.length;                  
                     var oRow=oTable.insertRow(length);
                     var ocell=oRow.insertCell(0);
                     ocell.innerHTML = txtQuantity.value;
                     ocell.className = "TitleColumn";
                     var oCell1=oRow.insertCell(1);
                     oCell1.innerHTML = ddlAmount.value;
                     oCell1.className = "TitleColumn";
                     var oCell2=oRow.insertCell(2);
                     oCell2.innerHTML = ddlCurrency.value + " " + (parseInt(txtQuantity.value) * parseInt(ddlAmount.value));
                     oCell2.className = "TitleColumn";
                     
                     //Display total amount.
                     //GetTotalAmount();
                     
                    }
                  
			  }
			}
			   }
			   catch(e)
			   {
			   alert(e.message);
			   return false;
			   }
			}

		    function ResetValues()
		    {
		      try
				{
				 var obj= document.getElementById("DDL_Currency");
				 if(obj!=null)
				 {
				  obj.value="GBP";
				 }
				  document.getElementById("DDL_Amount").value = "10";
				  document.getElementById("IV_TB_PromotionalCode").value = "";
				  document.getElementById("IV_TB_Quantity").value ="";
				  document.getElementById("Div_Table_OrderData").style.display="none";
				  
				  //Change the currency sign.
				  ChangeCurrencySign(document.getElementById("DDL_Currency").value);
				  
				  //Get the table object.
				   var oTable=document.getElementById("OrderTable");
				   //Get the number of rows.
				   var rowCount=oTable.rows.length;
				   var loopInteger;
				   if(oTable!=null)
				   {
					//Delete the tows from the order table.
					for(loopInteger=oTable.rows.length-1;loopInteger>0;loopInteger--)
					{
					    oTable.deleteRow(loopInteger);
					}
				   }
				}
				catch(e)
				{
				alert(e.message)
				return false;
				}
		    }
		    
		    function IV_Button_SubmitData_onClick()
		    {
				try
				{
                    //Get the table object.
				   var oTable=document.getElementById("OrderTable");
				   //Get the number of rows.
				   var rowCount=oTable.rows.length;
				   //Get the error Lable control.
				   var ErrorMessageDiv = document.getElementById("ErrorMessageDiv");
				   
				   if(rowCount<=1)
				   {
				      ErrorMessageDiv.style.display="block";
					  return false;
				   }
				   else
				   {
				      //Make queryString.
				      var buyVoucherQueryString = MakeQueryString();
				      //Assign to hidden field.
				      var hiddenField = document.getElementById("hidRedirectUrl");
				      hiddenField.value= DeepLinkURL + "?" + buyVoucherQueryString;
					  return true;
				   }					
				}
				catch(e)
				{
					alert(e.message)
					return false;
				}
		    }
		    
		    function MakeQueryString()
		    {
				try
				{
				  //Get the table object.
				   var oTable=document.getElementById("OrderTable");
				   //Get the number of rows.
				   var rowCount=oTable.rows.length;
				   var buyVoucherQueryString="";
				   var counter;
				   
				   if(oTable!=null)
				   {
					for(counter=1;counter<rowCount;counter++)
					{
					    //Get the table row.
						var tableRow=oTable.rows[counter];
						//Read the text from the cell.
						var currencyType=tableRow.cells[2].innerHTML;
						//Read the currency.
						currencyType=currencyType.substring(0,currencyType.indexOf(" "));
						//Read the quantity.
						var quantity=tableRow.cells[0].innerHTML;
						//Read the amount
						var amountValue=tableRow.cells[1].innerHTML;
						
					    if(buyVoucherQueryString=="")
					    {
					      buyVoucherQueryString = "data=" + quantity + "-" + amountValue + "-" + currencyType;
					    }
					    else
					    {
					      buyVoucherQueryString = buyVoucherQueryString + "," + quantity + "-" + amountValue + "-" + currencyType;
					    }
					  }  
					    //Get the radion button control.
					    var radioButton = document.getElementById("rdo_PostalVoucher");
					    var promoCodeControl = document.getElementById("IV_TB_PromotionalCode");
					    
					    if(radioButton.checked==true)
					    {
					     buyVoucherQueryString = buyVoucherQueryString + "&type=pv";
					    }
					    else
					    {
					     buyVoucherQueryString = buyVoucherQueryString + "&type=ev";
					    }
					    
					    buyVoucherQueryString = buyVoucherQueryString + "&pc=" + promoCodeControl.value;
					
				   }
				}
				catch(e)
				{
				alert(e.message)
				buyVoucherQueryString="";
				}
				
				return buyVoucherQueryString;
		    }

            function GetConversionRate(FromCurrency,ToCurrency)
            { 
            try
            { 
                var WebService = document.getElementById("WebService");   
                WebService.useService("http://localhost/CurrencyConversionWebService/CurrencyConversion.asmx?WSDL",  "CurrencyConversion");
                WebService.CurrencyConversion.callService(GetResult,"GetCurrencyConversionRate", FromCurrency,ToCurrency);       
             }
             catch(e)
             {
               alert(e.message);
               return false;
             }
               
		     
            }
            function GetResult(oResult)
            {
                if (oResult.error)
				{
					var sErrorMessage = oResult.errorDetail.code
									+ "\n" + oResult.errorDetail.string;
					alert("An error occurred:\n"
						+ sErrorMessage
						+ "See message pane for SOAP fault.");
						currencyConversionRate = 0;
				}
				else
				{
					
		            var TotalAmountInSiteCurrency=0;
					currencyConversionRate = oResult.value;
					//Calculate the total amount with the conversion rate.
					CalculateTotalAmount();
					//display the total amount.
					ShowAmount();
				}
				
            }
		    
		    
		    function GetTotalAmount()
		    {	    
		       try
		       {
		         //Get the table object.
				   var oTable=document.getElementById("OrderTable");
				   baseCurrencyType="";
				   var counter;
				   totalAmountInSiteCurrency = 0;
				   TotalAmount = 0;
				   
				   if(oTable!=null)
				   {
				     //Get the number of rows.
				    var rowCount=oTable.rows.length;
				    if(rowCount>1)
				    {
				      //Read the currency.
				      baseCurrencyType = oTable.rows[1].cells[2].innerHTML;
					  baseCurrencyType = baseCurrencyType.substring(0,baseCurrencyType.indexOf(" "));
				    }
				    
				    for(counter=1;counter<rowCount;counter++)
				    {
				      //Get the table row.
						var tableRow=oTable.rows[counter];
						//Get the currency Type.
						var currencyType=tableRow.cells[2].innerHTML;
						currencyType = currencyType.substring(0,currencyType.indexOf(" "));
						Quantity=tableRow.cells[0].innerHTML;
						
						if(baseCurrencyType != currencyType)
						{
						   VoucherAmount=tableRow.cells[1].innerHTML;
						  //totalAmountInSiteCurrency = ConvertCurrency(currencyType,baseCurrencyType,tableRow.cells[1].innerHTML);
						  //Call the webservice to get the conversion rate.
						  GetConversionRate(currencyType,baseCurrencyType);
						}
						else
						{
						  totalAmountInSiteCurrency = parseFloat(tableRow.cells[1].innerHTML);
						}

						if(baseCurrencyType == currencyType)
						{
						TotalAmount = parseFloat(TotalAmount + (totalAmountInSiteCurrency * parseInt(tableRow.cells[0].innerHTML)));
						}
				    } 
				    if(baseCurrencyType == currencyType)
				    {
				    TotalAmount = Math.round(TotalAmount, 2);
				    //Display the total amount.
				    ShowAmount();
				   }
				   
				   }
		       }
		       catch(e)
		       {
		       alert(e.message);
		       }
		    }

		    function CalculateTotalAmount()
		    {
		       try
		       {
		        
		        totalAmountInSiteCurrency = 0;
		        
		        if(currencyConversionRate > 0)
		        {
		          totalAmountInSiteCurrency = parseFloat(VoucherAmount) *  parseFloat(currencyConversionRate);	
		        }

		        TotalAmount = parseFloat(parseFloat(TotalAmount) + (totalAmountInSiteCurrency * parseInt(Quantity)));
		        
		       }
		       catch(e)
		       {
		        alert(e.message);
		        return false;
		       }
		        
		        return false;
		    }
		    
		    function ShowAmount()
		    {

		       //TotalAmount = Math.round(TotalAmount, 2);

				//Set TotalCurrency to the GrandTotalCurrency lable.
			 	var lbl_GrandTotalCurrency = document.getElementById("lbl_GrandTotalCurrency");
				lbl_GrandTotalCurrency.innerText = baseCurrencyType;

				//Set TotalAmountAfterDiscount to the GrandTotalValue lable.
				var lbl_GrandTotalValue = document.getElementById("lbl_GrandTotalValue");
				lbl_GrandTotalValue.innerText = TotalAmount.toString();
		    }
