/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function showRequestedCurrencyPrice(defaultCurrency,count)
{   
    var currency = document.getElementById("currency");
    var requestedCurrency = currency.options[currency.selectedIndex].value;
    var currentCurrency = document.getElementById("currentCurrency").value;
    var prices = new Array();
    var setOnlyCurrency = false;
    var defaultTaxText = new Array();

    if(defaultCurrency == 'INR')
    {
        for(var i=1;i<=count;i++)
        {
            defaultTaxText[i-1] = document.getElementById("defaultTaxText"+""+i);
            defaultTaxText[i-1].style.display = "none";
        }
    }
    for(i=1;i<=count;i++)
    {
      prices[i-1] = document.getElementById("price"+""+i);
    }
    var defaultPrices = new Array();
    for(i=1;i<=count;i++)
    {
        defaultPrices[i-1] = document.getElementById("defaultPrice"+""+i).value;
    }
    
    var symbol="";
    if(requestedCurrency == "USD")
    {
        symbol = "US$";
    }
    else
    {
        symbol = "Rs.";
    }
    if(requestedCurrency == defaultCurrency)
    {
        for(i=1;i<=count;i++)
        {
            if(defaultCurrency == 'INR')
            {
                if(i == 1)
                {
                    prices[i-1].innerHTML = symbol+" "+defaultPrices[i-1]+"<br/><span style='color:red;font-size:12px;margin-left:15px;'> per class<br/><span style='font-size:10px;color:#666666;margin-left:10px;'>(Taxes Extra)</span>";
                }
                else
                {
                    prices[i-1].innerHTML = symbol+" "+defaultPrices[i-1]+"<br/><span style='font-size:10px;color:#666666;margin-left:10px;'>(Taxes Extra)</span>";
                }
            }
            else
                prices[i-1].innerHTML = symbol+" "+defaultPrices[i-1];
        }
        document.getElementById("currentCurrency").value = requestedCurrency;
        setOnlyCurrency = true;
    }
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        alert("Your browser does not support XMLHTTP!");
    }
    //alert(currentCurrency +" "+requestedCurrency);
    var params = "from="+currentCurrency+"&to="+requestedCurrency+"&amts="+defaultPrices+"&setOnlyCurrency="+setOnlyCurrency;
    document.getElementById("currentCurrency").value = requestedCurrency;
    
    xmlhttp.onreadystatechange=function()
    {
        if(xmlhttp.readyState==4)
        {
            if(xmlhttp.status==200)
            {
                for(i=1;i<=count;i++)
                {
                   //alert(xmlhttp.responseXML.getElementsByTagName("rate"+""+i)[0].childNodes[0].nodeValue);
                   if(!setOnlyCurrency)
                   {
                    if(requestedCurrency == 'INR')
                        prices[i-1].innerHTML = symbol+" "+xmlhttp.responseXML.getElementsByTagName("rate"+""+i)[0].childNodes[0].nodeValue+"<br/><span style='font-size:10px;color:#666666;margin-left:10px;'>(Taxes Extra)</span>";
                    else if(defaultCurrency == 'INR' && i == 1)
                        prices[i-1].innerHTML = symbol+" "+xmlhttp.responseXML.getElementsByTagName("rate"+""+i)[0].childNodes[0].nodeValue+"<br/><span style='color:red;font-size:12px; margin-left:15px;'> per class </span>";
                    else if(defaultCurrency == 'INR')
                        prices[i-1].innerHTML = symbol+" "+xmlhttp.responseXML.getElementsByTagName("rate"+""+i)[0].childNodes[0].nodeValue+"";
                    else
                        prices[i-1].innerHTML = symbol+" "+xmlhttp.responseXML.getElementsByTagName("rate"+""+i)[0].childNodes[0].nodeValue;
                    document.getElementById("currentCurrency").value = requestedCurrency;
                   }
                }
            }
        }
    }
    xmlhttp.open("POST","/main/payment/ajax/currencyConversion.jsp",true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlhttp.setRequestHeader("Content-length", params.length);
    xmlhttp.setRequestHeader("Connection", "close");
    xmlhttp.send(params);
}

function setDefaultValuesInDropDowns(currency)
{
     var tmp = document.getElementById("currency");
     
     for(var i=0;i<tmp.options.length;i++)
     {
         if(tmp.options[i].value+"" == ""+currency)
         {
             tmp.selectedIndex = i;
             break;
         }
     }
     document.getElementById("currentCurrency").value = currency;
}

function addDropDownOption(link)
{
    link.href = link.href+"?i="+document.getElementById("currency").selectedIndex;
}