/**This js file contain the function that will be called on showSuccess.php page*/ 
//array for storing marker object
var mapflag =1;
var mapMarkers = [];
var yahooMapMarkers = [];
//array for storing window content for display for each marker
var mapMarkerHtmls = [];  
var yahooMapMarkerHtmls = [];
var activedivid="";

//Function to change color of a div when we click on show map link of that div 
function changeColorOfDiv(divid)
{
  if(activedivid != divid)
  {      
    activedivid.className= "marker_close";
  }        
  divid.className="marker_on";     
  activedivid=divid; 
}   

//Function to open a map popup when we click on the "Show On Map" icon on the listings.
function markerOnGoogleMap(markerNum,divid)
{ 
	changeColorOfDiv(divid);
  document.getElementById('search_title').scrollIntoView(true); //Set window focus on top part of the map.
  if(mapflag)
  {
  mapMarkers[markerNum].openInfoWindowHtml(mapMarkerHtmls[markerNum]);
  }
  else
  {
  yahooMapMarkers[markerNum].openSmartWindow(yahooMapMarkerHtmls[markerNum]);
  }
} 

//used to convert the covered area into different area unit(sqft,sqyd,sqmt,acre)
function areaConverter(area)
{
  var i;
  var cov_area;

  for(i=0; i<=9; i++)
  {
    var lplot_sqft = document.getElementById('lplot_sqft' + i);
    var lot_size;
    if (lplot_sqft != null) lot_size = lplot_sqft.innerHTML;
    var plot_size = document.getElementById('lplot_size' + i)
    
    var lca_sqft = document.getElementById('lca_sqft' + i);
    var cov_area;
    if (lca_sqft != null) cov_area = lca_sqft.innerHTML;
    lca = document.getElementById('lca' + i);
    if (lca != null)
    {
      if (area == 'sqft'){
        lca.innerHTML = prettyNumber(Math.round(parseFloat(cov_area) * 100) / 100, 3) + " sqft";
        document.getElementById('areaUnit').innerHTML ='Sqft';
      }
      else if (area == 'sqyd'){
        lca.innerHTML = prettyNumber(Math.round(parseFloat(cov_area) * .111111 * 100) / 100, 3) + " sqyd";
        document.getElementById('areaUnit').innerHTML ='Sqyd';
      }  
      else if (area == 'sqmt'){
        lca.innerHTML = prettyNumber(Math.round(parseFloat(cov_area) * .0929 * 100) / 100, 3) + " sqmt";
        document.getElementById('areaUnit').innerHTML ='Sqmt';
      }  
      else if (area == 'acre'){
        lca.innerHTML = Math.round(parseFloat(cov_area) * .000022957 * 100) / 100 + " acre";
        document.getElementById('areaUnit').innerHTML ='Acre';
      }  
      else if (area == 'hect'){
        lca.innerHTML = Math.round(parseFloat(cov_area) * .00000929 * 10000) / 10000 + " hect";
        document.getElementById('areaUnit').innerHTML ='Hect';
      }  
    }
    else if(plot_size != null)
    {
      if (area == 'sqft'){
        plot_size.innerHTML = prettyNumber(Math.round(parseFloat(lot_size) * 100) / 100, 3) + " sqft";
        document.getElementById('areaUnit').innerHTML ='Sqft';
      }  
      else if (area == 'sqyd'){
        plot_size.innerHTML = prettyNumber(Math.round(parseFloat(lot_size) * .111111 * 100) / 100, 3) + " sqyd";
        document.getElementById('areaUnit').innerHTML ='Sqyd';
      }  
      else if (area == 'sqmt'){
        plot_size.innerHTML = prettyNumber(Math.round(parseFloat(lot_size) * .0929 * 100) / 100, 3) + " sqmt";
        document.getElementById('areaUnit').innerHTML ='Sqmt';
      }  
      else if (area == 'acre'){
        plot_size.innerHTML = Math.round(parseFloat(lot_size) * .000022957 * 100) / 100 + " acre";
        document.getElementById('areaUnit').innerHTML ='Acre';
      }  
      else if (area == 'hect'){
        plot_size.innerHTML = Math.round(parseFloat(lot_size) * .00000929 * 10000) / 10000 + " hect";
        document.getElementById('areaUnit').innerHTML ='Hect';
      }  
    }
  }
}

//used to convert the price into different currency unit(Rs,$ etc)
function currencyConverter(currency)
{
	var j;
  var curr_value;

  for(j=0;j<=9;j++)
  {//alert(document.getElementById('lp_rs' + j).innerHTML);
    curr_value = document.getElementById('lp_rs' + j).innerHTML;
    lp = document.getElementById('lp' + j);
    if (currency == 'Rs'){
      lp.innerHTML = "Rs " + getRsPriceInWords(Math.round(parseFloat(curr_value)));
      document.getElementById('currencyUnit').innerHTML ='INR';
    }  
    else if (currency == '$'){
      lp.innerHTML = "$ " + prettyNumber(Math.round(curr_value * document.getElementById('usDoller').value ), 3);
      document.getElementById('currencyUnit').innerHTML  = 'US $';
    }  
    else if (currency == "\xA3"){
      lp.innerHTML = "&#163; " + prettyNumber(Math.round(curr_value * document.getElementById('pound').value ), 3);
      document.getElementById('currencyUnit').innerHTML  = 'GBP (&#163;)';
    }  
    else if (currency == "\u20AC"){
      lp.innerHTML = "&#8364; " + prettyNumber(Math.round(curr_value * document.getElementById('euro').value ), 3);
      document.getElementById('currencyUnit').innerHTML  = 'EURO (&#8364;)';
    }    
  }
}