﻿// JScript File

//public methods

var listname;

function getCost(country)
{
    var from, to;
    
    if (country.id == "receiveList")
    {
        from = document.getElementById('remit').value;
        to = country.value;
    }else{
        from = country.value;
        to = document.getElementById('receive').value;
    }
    
    window.location = '/RemittanceCosts/?from='+from+'&to='+to;
}

function onCountryChange(countryDropdown, requestType)
{
    //set select list name
    if(requestType == 'remit')
        listname = 'receiveList';
    else
        listname = 'remitList';
        
    if (countryDropdown.value == -1)
    {
        document.getElementById(listname).disabled = true;
        return;
    }
    
    //enable select list
    document.getElementById(listname).disabled = false;
    
    //populate list for the selected country
    getCountries("/getCountries.ashx?countryid="+countryDropdown.value+"&type="+requestType, iHandler);
}

function getCountries(url, responseHandler)
{
     if (window.XMLHttpRequest)   
      {   
          // browser has native support for XMLHttpRequest object   
          req = new XMLHttpRequest();   
      }   
      else if (window.ActiveXObject)   
      {   
         // try XMLHTTP ActiveX (Internet Explorer) version   
         req = new ActiveXObject("Microsoft.XMLHTTP");   
      }   
         
      if(req)   
      {
          req.onreadystatechange = responseHandler;   
          req.open('GET', url, true);   
          req.setRequestHeader("content-type","application/x-www-form-urlencoded");   
          req.send('');   
      }   
      else  
      {   
          alert('Your browser does not seem to support XMLHttpRequest.');   
      }   
}

function iHandler()
{
    if (req.readyState == 4 || req.readyState == 'complete')   
    { 
        var optionArr = [];
        optionArr = req.responseText.split(',');
        
        //clear options
        selectList.clear(document.getElementById(listname));
        
        //add options
        for(var i = 0; i < optionArr.length-1; i++){
            if((optionArr[i] != null) || (optionArr[i] != " ")){
                var option = optionArr[i].split('-');
                selectList.add(document.getElementById(listname), option[0], option[1]);
            }
        }
    }  
}

/******************************************************************************************
Methods to add, remove and clear items of select element
*******************************************************************************************/
//new object to add options to the select list
var selectList = new Object;
selectList.add = function(selectObj, sValue, sName)
{
    var option = document.createElement("option");
    option.appendChild(document.createTextNode(sName));
    
    if(arguments.length == 3)
        option.setAttribute("value", sValue);
    
    selectObj.appendChild(option);    
}

//remove option from select list
selectList.remove = function(selectObj, index)
{
    selectObj.remove(index);
}

//clear all options
selectList.clear = function(selectObj)
{
    for(var i = selectObj.options.length-1; i > 0; i--)
        selectList.remove(selectObj,i);
}
/**********************************************************************

***********************************************************************/

/*function pageLoad(){
    var tabContainer = $find('ctl00_contentBody_remittanceAmount');
    var tabs = tabContainer.get_tabs();

    for(var i = 0; i<tabs.length; i++){
        var tab = tabs[i];
        $addHandler(
            tab.get_headerTab(),
            'mouseover',
            Function.createDelegate(tab, function(){
                tabContainer.set_activeTab(this);
            }
        ));
    }
}*/

function setmouseover(container){
    var tabContainer = $find(container);
    var tabs = tabContainer.get_tabs();

    for(var i = 0; i<tabs.length; i++){
        var tab = tabs[i];
        $addHandler(
            tab.get_headerTab(),
            'mouseover',
            Function.createDelegate(tab, function(){
                tabContainer.set_activeTab(this);
            }
        ));
    }
}

function expand(e){
    Effect.toggle('rmt','slide');
}


  var arrImages;
  var total;
  var dvGraphPanel;
  var rInterval;
  var iCurrent;
  function RotateImages()
  {
  	
  	for(var index=0; index < total; index++)
  	{
  	    for(var i=0; i<dvGraphPanel.childNodes.length; i++)
  	    {
  	        if(dvGraphPanel.childNodes[i].id.indexOf('dvGraph' + index) != -1)
  	        {
  	            if(index==iCurrent)
  	            {
  	                dvGraphPanel.childNodes[i].style.display = 'block';
  	            }
  	            else
  	            {
  	                dvGraphPanel.childNodes[i].style.display = 'none';
  	            }
  	        }       
  	    }
  	}
  	//window.setTimeout("RotateImages("+(Start+1)+")", rInterval * 10000);
  }
  
  function InitRotator(totalGraphs, dvId, rotationInterval)
  {
    dvGraphPanel = $(dvId);
    total = totalGraphs;
    iCurrent = 0;
    rInterval = rotationInterval;
    RotateImages(0);
  }
  
  function ForwardBack(bForward)
  {
  
  if (bForward == 0)
   {
      //back
      if ( iCurrent != 0)
      {
       iCurrent--;             
       RotateImages();
      }
    }
   else
   //forward
   {
   if ( iCurrent != total -1)
      {
       iCurrent++;             
       RotateImages();
      }   
   } 
    
  }
  
  //addLoadEvent(RotateImages(0));
