//This file contain the common js function that will be used in home,srp,ldp page
/**this function is for display a pop up window
 * pass the argument for event,div id ,height,top and left position for pop up window 
 */
 //listingId and listingType variable will be used to save favourite search or listing
 var listingId;
 var listinType;
 //captcha count is a variable which will be used to track successful trial of valuation done by user
 var captchaCount=1;

 function showForm(event, div, width, height, fixedTopPos, fixedLeftPos)
{
  var windowWidth, windowHeight, scrollTop, scrollLeft, top_pos, left_pos;
  var IE = document.all?true:false;
  if (IE)
  {  
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    scrollLeft = document.documentElement.scrollLeft;
    scrollTop = document.documentElement.scrollTop;
    top_pos = scrollTop + ((windowHeight - height) / 2);
    left_pos = scrollLeft + ((windowWidth - width) / 2);
  }
  else
  {
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
    scrollLeft = window.pageXOffset;
    scrollTop = window.pageYOffset;
    top_pos = scrollTop + ((windowHeight - height) / 2);
    left_pos = scrollLeft + ((windowWidth - width) / 2);
  }

  if (fixedTopPos != -1)
  {
    top_pos = scrollTop + fixedTopPos;
  }       

  if (fixedLeftPos != -1)
  {
    left_pos = scrollLeft + fixedLeftPos;
  }
    
  div.style.top = top_pos.toString() + "px";
  div.style.left = left_pos.toString() + "px";
  div.style.display = "block";
}

//This function is used to close a popup window
function clearAndClose(div, form, feedback) 
{
  //form.reset();
  feedback.innerHTML="";
  div.style.display = "none";
}

//Function to set link in google analytics tool and Zamanzar trackAnalytics 
function trackAnalytics(str){
    urchinTracker("/custom/" + str);
    // This check analytics on/off switch    
    if(analytics)
    {
     new Ajax.Request('/home/analytics?type='+str, 
     {
       method: 'get',
     
       onSuccess: function(transport) {
       },         
   
     onFailure: function() { 
     },
     
     onLoading: function(){
     }
    });  // ajax finish
    }
  }   

//Function to set comma between a number  
function prettyNumber(aNumber, aNumOfDigitsBetweenCommas)
{
  num = parseInt(aNumber);
  if (num == null || num == 0) return "";
    var pn = "";
  if (num < 1000)
  {
    pn = num;
  }
  else
  {
    var begin_index = num.toString().length - 3;       
    pn = "," + num.toString().substring(begin_index);
    num = parseInt (num / 1000);
    while (num > Math.pow(10, aNumOfDigitsBetweenCommas))
    {
      begin_index = num.toString().length - aNumOfDigitsBetweenCommas;
      pn = "," + num.toString().substring(begin_index) + pn;
      num = parseInt(num / Math.pow(10, aNumOfDigitsBetweenCommas));
    }
    pn = num.toString() + pn;
  }
  return pn;
}
 
//function to get price in words   
function getRsPriceInWords(price)
{
  if (price <= 99999)
  {
    return prettyNumber(price, 2);
  }
  else if (price <= 9999999)
  {
    return Math.round((price / 100000) * 100) / 100 + " Lakh";
  }
  else if (price > 10000000)
  {
    return Math.round((price / 10000000) * 100) / 100 + " Crore";
  }
}

  // Function for set the Google and Yahoo map link. 
function setMapDiv(mapdiv)
{
  if(mapdiv == '1') //Show Google map and Yahoo link.
  {    
    Element.hide('ymap');
    Element.hide('googleMapTab');
    Element.show('map'); 
    Element.show('yahooMapTab');     
  }
  else //Show Yahoo map and Google link.
  {
    Element.hide('map');
    Element.show('ymap');
    Element.hide('yahooMapTab');
    Element.show('googleMapTab');           
  }
}

function convertFromSquareFeet(sourceValue, convertToUnit)
{
  var retVal = 0.0;
  if (convertToUnit == 'sqft'){
    retVal = Math.round(sourceValue);
    document.getElementById('areaUnit').innerHTML ='Sqft';
  }  
  else if (convertToUnit == 'sqyd'){
    retVal = Math.round(sourceValue * .111111 * 100) / 100;
    document.getElementById('areaUnit').innerHTML ='Sqyd';
  }  
  else if (convertToUnit == 'sqmt'){
    retVal = Math.round(sourceValue * .0929 * 100) / 100;
    document.getElementById('areaUnit').innerHTML ='Sqmt';
  }  
  else if (convertToUnit == 'acre'){
    retVal = Math.round(sourceValue * .000022957 * 100) / 100;
    document.getElementById('areaUnit').innerHTML ='Acre';
  }  
  else if (convertToUnit == 'hect'){
    retVal = Math.round(sourceValue * .00000929 * 10000) / 10000;
    document.getElementById('areaUnit').innerHTML ='Hect';
  }  
   
 return retVal;
}
   
function convertFromPerSquareFeet(sourceValue, convertToUnit)
{  
  var retVal = 0.0;
  if (convertToUnit == 'sqft' || convertToUnit == 'Sqft')
    {retVal = Math.round(sourceValue);}
  else if (convertToUnit == 'sqyd' || convertToUnit == 'Sqyd')
    {retVal = Math.round(sourceValue * 9);}
  else if (convertToUnit == 'sqmt' || convertToUnit == 'Sqmt')
    {retVal = Math.round(sourceValue * 10.7526881);}
  else if (convertToUnit == 'acre' || convertToUnit == 'Acre')
    {retVal = Math.round(sourceValue * 43560.4006);}
  else if (convertToUnit == 'hect' || convertToUnit == 'Hect')
     {retVal = Math.round(sourceValue * 107637.799); }

   return retVal;
 }
   
   function convertFromRs(sourceValue, convertToUnit)
   { 
   	 var retVal = 0.0;
     if (convertToUnit == "Rs") {
       retVal = prettyNumber(Math.round(sourceValue) , 2);
       document.getElementById('currencyUnit').innerHTML ='INR';
     }  
     else if (convertToUnit == "$") {
       retVal = prettyNumber(Math.round(sourceValue * document.getElementById('usDoller').value * 100) / 100, 3);
       document.getElementById('currencyUnit').innerHTML  = 'US $';
     }  
     else if (convertToUnit == "\xA3") {
       retVal = prettyNumber(Math.round(sourceValue * document.getElementById('pound').value * 100) / 100 , 3);
       document.getElementById('currencyUnit').innerHTML  = 'GBP (&#163;)';
     }  
     else {
       retVal = prettyNumber(Math.round(sourceValue * document.getElementById('euro').value * 100) / 100 , 3);
       document.getElementById('currencyUnit').innerHTML  = 'EURO (&#8364;)';
     }    
     return retVal;

   }  


//Display is None or Display is Block
 function toggleDivs(show, hide)
    {
        var s = document.getElementById(show);
        var h = document.getElementById(hide);
        s.style.display = 'block';
        h.style.display = 'none';
    }

//Switching the CSS class
//Display is None or Display is Block
 function radioBtn_toggle(show, hide)
    {
        var s = document.getElementById(show);
        var h = document.getElementById(hide);
        s.className = 'divDisplayOn';
        h.className = 'divDisplayOff';
    }

// Home Page Listing Tabs
  var horactiveTitle1 = "newpro";
  var horactiveContent1 = "newProjects";
  var verActiveTitle = new Array("","","","");
  var verActiveContent = new Array("","","","");
  var firstContent = new Array("newProLink0Container","resaleProLink0Container","rentProLink0Container","trendProLink0Container");
  var firstTitle = new Array("newProLink0","resaleProLink0","rentProLink0","trendProLink0");

  //Activate vertical DIV of passed ID's. Also receives index of currently active horizontal DIV.
  function verticalToggleDiv(contentDivId, titleDivId, horTabIndex)
   {
       //First deactivate currently active tab.
       //If none is active, it means, first is active by default.
       if(verActiveTitle[horTabIndex] != "")
        document.getElementById(verActiveTitle[horTabIndex]).className = 'leftLinkDeActiveContainer';
       else
        document.getElementById(firstTitle[horTabIndex]).className = 'leftLinkDeActiveContainer';
  
      if(verActiveContent[horTabIndex] != "")
        document.getElementById(verActiveContent[horTabIndex]).style.display = 'none';
      else
        document.getElementById(firstContent[horTabIndex]).style.display = 'none';

      //Set the new tab as active.
      verActiveTitle[horTabIndex] = titleDivId;
      verActiveContent[horTabIndex] = contentDivId;

      document.getElementById(verActiveContent[horTabIndex]).style.display = 'block';
      document.getElementById(verActiveTitle[horTabIndex]).className = 'leftLinkActiveContainer';      
   }

 function horizonToggle(contentDivId1, titleDivId1)
    { 
      
      if(horactiveTitle1 != "")
        document.getElementById(horactiveTitle1).className = 'deActiveTabs';
        document.getElementById(horactiveTitle1).style.color = '#909090';
      if(horactiveContent1 != "")
        document.getElementById(horactiveContent1).style.display = 'none';

      horactiveTitle1 = titleDivId1;
      horactiveContent1 = contentDivId1;

      document.getElementById(horactiveContent1).style.display = 'block';
      document.getElementById(horactiveTitle1).className = 'activeTabs';
      document.getElementById(horactiveTitle1).style.color = '#000000';
    }


// For Home page's Buyer Section.
var activeSearchTitle = "usrTab1";
var activeSearchContent = "searchForm";

function toggleSearchDiv(contentDivId, titleDivId)
  {
    //Make currently active tab inactive.
    if(activeSearchTitle != "")
    {
      document.getElementById(activeSearchTitle).className = 'deActiveUsrTabs';
      //deActivateTabTittle(activeSearchTitle);
      document.getElementById(activeSearchTitle).style.color = '#909090';
    }
      
    if(activeSearchContent != "")
      document.getElementById(activeSearchContent).style.display = 'none';
     
      activeSearchTitle = titleDivId;
      activeSearchContent = contentDivId;    

      document.getElementById(activeSearchContent).style.display = 'block';
      document.getElementById(activeSearchTitle).className = 'activeUsrTabs';
      document.getElementById(activeSearchTitle).style.color = '#000000';
  }

// For Home page's Seller Section.
var activeSellerTitle = "sellerTab1";
var activeSellerContent = "valuePropertyForm";

function toggleSellerDiv(contentDivId, titleDivId)
  {
    //Make currently active tab inactive.
    if(activeSellerTitle != "")
    {
      document.getElementById(activeSellerTitle).className = 'deActiveTab';
      //deActivateTabTittle(activeSearchTitle);
      document.getElementById(activeSellerTitle).style.color = '#909090';
    }
      
    if(activeSellerContent != "")
      document.getElementById(activeSellerContent).style.display = 'none';
     
      activeSellerTitle = titleDivId;
      activeSellerContent = contentDivId;    

      document.getElementById(activeSellerContent).style.display = 'block';
      document.getElementById(activeSellerTitle).className = 'activeTab';
      document.getElementById(activeSellerTitle).style.color = '#000000';
  }

//change color of the text to black of deactive tab
function activateTabTittle(id1)
  {
    //alert(id1!=activeSearchTitle);
    if(id1!=activeSearchTitle && id1!=horactiveTitle1 && id1!=activeSellerTitle){
    document.getElementById(id1).style.color = '#000000';
    }
  }
//change color of the text to black of deactive tab

function deActivateTabTittle(id1)
  {
    //alert(id1!=activeSearchTitle);
    if(id1!=activeSearchTitle && id1!=horactiveTitle1 && id1!=activeSellerTitle){
        document.getElementById(id1).style.color = '#909090';
      }
  }


  function maxWidth()
    {
      //document.getElementById('whatsNew').className = 'divDisplayOff floatL';
      document.getElementById('quickPost').className = 'divDisplayOff floatL';
      document.getElementById("searchContainer").style.width = '980px';
      document.getElementById("topBarMiddle").style.width = '960px';
      document.getElementById("middleSearchTab").style.width = '976px';
      document.getElementById("postReqForm").style.width = '960px';
      document.getElementById("bottomBarContainer").style.width = '980px';
      document.getElementById("bottomBarMiddle").style.width = '960px';
    }

  function minWidth()
    {
      //document.getElementById('whatsNew').className = 'divDisplayOn floatL';
      document.getElementById('quickPost').className = 'divDisplayOn floatL';
      document.getElementById("searchContainer").style.width = '580px';
      document.getElementById("topBarMiddle").style.width = '550px';
      document.getElementById("middleSearchTab").style.width = '566px';
      document.getElementById("searchForm").style.width = '550px';
      document.getElementById("bottomBarContainer").style.width = '570px';
      document.getElementById("bottomBarMiddle").style.width = '550px';
    }

/**
   * Displays the passed element as a fade-in text.
   * Initial value of the fadingMsgColor param should be the background color (255 for white).Not using separate values for R,G,B.
   * The timeout is the time in miliseconds for which the text is to be kept visible.
   * elementId is the DIV or the SPAN which contains the text element to fade-in.
   */
  function fadetext(fadingMsgColor, elementId, timeout){
    if(fadingMsgColor > 0) { //If color is not black yet
  
      fadingMsgColor -= 2; //Increase color darkness
      document.getElementById(elementId).style.color =
                          "rgb("+fadingMsgColor+","+fadingMsgColor+","+fadingMsgColor+")";
  
    //recursive call after a little while to continue fading
    setTimeout("fadetext("+fadingMsgColor+ ",'" + elementId + "'," + timeout + ")", 20); 
  }
  
  else { //It's done. The text is visible. Call to erase it after a few seconds.
  
    setTimeout("document.getElementById('"+elementId+"').style.display='none';",timeout); 
  
  }
  
  }

/**
 * Hide Alexa widget. We'll remove this once we have good enough rank.
 */
function hideAlexa() {
  document.getElementById("alexaWidget").className = 'divDisplayOff';
}

//Gets Height of an element and defines height to other element.
function getDivHeight(divHt, divHt2){
     var IE = document.all?true:false;
     
     var parntHt= document.getElementById(divHt);
     
     
     var ffHeight, ieHeight;

     
		if (IE)
      {
        ieHeight = parntHt.offsetHeight - 10;
        document.getElementById(divHt2).style.height = ieHeight + "px";
        //alert(parntHt.offsetHeight);
      }
    else
    {
      
      ffHeight = parntHt.offsetHeight - 12;
      document.getElementById(divHt2).style.height = ffHeight + "px";
			//alert(ffHeight);
    }
      			
		}

//Switch display none or block
function toggle_visibility(id)
  {
    var e = document.getElementById(id);
    if(e.style.display == 'block')
      {
        e.style.display = 'none';
      }
    else
      {
        e.style.display = 'block';
      }
  }

// To find the X position of an element
  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

// To find the Y position of an element
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;

  }
  
  //function for remove white space from string.
  String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

  // This function gets called in featured listing section when city is switched
  // It makes an AJAX call to get the contents of that city and tab combination
  // only if the assigned DIV is empty.
  function featuredList(city,div_id,tab)
  { 
    if(document.getElementById(div_id).innerHTML.trim() == "") {
     
     //Set the loading image. onLoading event is not working properly.
     document.getElementById(div_id).innerHTML = document.getElementById('flIndicator').innerHTML;
          
     new Ajax.Updater(div_id,'/home/getFeaturedListings/'+city+'/'+tab, 
     {
      method: 'get',
      
      //onLoading is creating problem - it's getting called after onSuccess!
      //onLoading: function(){
        //document.getElementById(div_id).innerHTML = document.getElementById('flIndicator').innerHTML; 
      //},
       
      onSuccess: function(transport) {
       var response = transport.responseText;
       document.getElementById(div_id).innerHTML = response;       
      },
      
      onFailure: function() {
        document.getElementById(div_id).innerHTML = "";
      }
    }
   );
   }  
  }

// switch visiblity of passed DIV elements 
function expandCollapse(id, id1)
	{
	  var e = document.getElementById(id);
	  var m = document.getElementById(id1);
	  
	  if(e.style.display == 'none') {
	    e.style.display = 'block';
	    m.style.background = '#FBFBFB url(/images/slidingDivTagColapse.gif) repeat-y top right';
    }
    else {
 	    e.style.display = 'none';
	    m.style.background = '#FBFBFB url(/images/slidingDivTagExpand.gif) repeat-y top right';
    }
	}

//show reset password pop up    
function resetPasswordPopup(event, div,email, width, height, fixedTopPos, fixedLeftPos)
{
  var windowWidth, windowHeight, scrollTop, scrollLeft, top_pos, left_pos;
  var IE = document.all?true:false;  
  if (IE)
  {  
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
    scrollLeft = document.documentElement.scrollLeft;
    scrollTop = document.documentElement.scrollTop;
    top_pos = scrollTop + ((windowHeight - height) / 2);
    left_pos = scrollLeft + ((windowWidth - width) / 2);
    if(email)
      {                     
        document.getElementById('resetDiv').innerHTML="<table width='100%'><tr>"+                              
        "<td colspan='2' width='200'>&nbsp;</td>"+
        "<td><input class='allTextBoxes' style='width: 150px;' maxlength='100' type='hidden' name='email' id='resetPasswordEmail' value=''/>"+
        "</td><td align='right'><span id='resetPasswordIndicator' style='display:none;margin-right:10px;height:20px'>"+
        "<input type='image' name='submit' src='/images/indicator.gif'/>"+             
        "</span><input class='allButtons' style='width: 130px;' type='submit' id='resetPasswordSubmit' onclick="+'trackAnalytics("RESET_PASSWORD_CLICK");'+" value='RESET PASSWORD'/>"+
        "</td></tr><tr><td colspan='2' height='15'></td></tr></table>"
        document.getElementById('emailValue').innerHTML=email+".";   
        document.getElementById('resetPasswordEmail').value = email;                
      }       
      else
      {
        document.getElementById('emailValue').innerHTML="given mail id.";
        document.getElementById('resetDiv').innerHTML="<table width='100%'><tr>"+        
         "<td id='emailTd'>Email:</td>"+
         "<td><input class='allTextBoxes' style='width: 150px;' maxlength='100' type='text' name='email' id='resetPasswordEmail'/></td>"+        
         "<td colspan='2' width='200'>&nbsp;</td>"+             
         "</td><td align='right'><span id='resetPasswordIndicator' style='display:none;margin-right:10px;height:20px'>"+
         "<input type='image' name='submit' src='/images/indicator.gif'/>"+  
          "</span><input class='allButtons' style='width: 130px;' type='submit' id='resetPasswordSubmit' onclick="+'trackAnalytics("RESET_PASSWORD_CLICK");'+" value='RESET PASSWORD'/>"+
         "</td></tr><tr><td colspan='2' height='15'></td></tr></table>"             
         
      }       
    
  }
  else
  {
    windowWidth = window.innerWidth;
    windowHeight = window.innerHeight;
    scrollLeft = window.pageXOffset;
    scrollTop = window.pageYOffset;
    top_pos = scrollTop + ((windowHeight - height) / 2);
    left_pos = scrollLeft + ((windowWidth - width) / 2);
    if(email)
      {                     
        document.getElementById('resetDiv').innerHTML="<table width='100%'><tr>"+                              
        "<td colspan='2' width='200'>&nbsp;</td>"+
        "<td><input class='allTextBoxes' style='width: 150px;' maxlength='100' type='hidden' name='email' id='resetPasswordEmail' value=''/>"+
        "</td><td align='right'><span id='resetPasswordIndicator' style='display:none;margin-right:10px;height:20px'>"+
        "<input type='image' name='submit' src='/images/indicator.gif'/>"+             
        "</span><input class='allButtons' style='width: 130px;' type='submit' id='resetPasswordSubmit' onclick="+'trackAnalytics("RESET_PASSWORD_CLICK");'+" value='RESET PASSWORD'/>"+
        "</td></tr><tr><td colspan='2' height='15'></td></tr></table>"
        document.getElementById('emailValue').innerHTML=email+".";   
        document.getElementById('resetPasswordEmail').value = email;                
      }       
      else
      {
        document.getElementById('emailValue').innerHTML="given mail id.";
        document.getElementById('resetDiv').innerHTML="<table width='100%'><tr>"+        
         "<td id='emailTd'>Email:</td>"+
         "<td><input class='allTextBoxes' style='width: 150px;' maxlength='100' type='text' name='email' id='resetPasswordEmail'/></td>"+        
         "<td colspan='2' width='200'>&nbsp;</td>"+             
         "</td><td align='right'><span id='resetPasswordIndicator' style='display:none;margin-right:10px;height:20px'>"+
         "<input type='image' name='submit' src='/images/indicator.gif'/>"+  
          "</span><input class='allButtons' style='width: 130px;' type='submit' id='resetPasswordSubmit' onclick="+'trackAnalytics("RESET_PASSWORD_CLICK");'+" value='RESET PASSWORD'/>"+
         "</td></tr><tr><td colspan='2' height='15'></td></tr></table>"             
         
      }       
  }

  if (fixedTopPos != -1)
  {
    top_pos = scrollTop + fixedTopPos;
  }       

  if (fixedLeftPos != -1)
  {
    left_pos = scrollLeft + fixedLeftPos;
  }
    
  div.style.top = top_pos.toString() + "px";
  div.style.left = left_pos.toString() + "px";
  div.style.display = "block";
}

//Get the height of the div and converts it into the top position of the pop-up div
// Parameters removeData, listAddFvt, listRemvFvt, listStatus are set for remove save listing and save searches from SRP, LDP and MyZamanzar.
    
 
function showChildPopup(popDivID, divId, topPos, leftPos,removeData,listAddFvt,listRemvFvt,listStatus,analyticsText){	        
      var divIdObj = document.getElementById(divId);
      var IE = document.all?true:false;
      var ffHeight, ieHeight;

      if (IE)
        {
          document.getElementById(popDivID).style.display = "block";
          ieHeight =findPosY(divIdObj) ;
          document.getElementById(popDivID).style.top = topPos + ieHeight + "px" ;
          document.getElementById(popDivID).style.left = leftPos + "px" ;               
        }
      else
      {
        
        document.getElementById(popDivID).style.display = "block";
        ffHeight =findPosY(divIdObj) ;
        document.getElementById(popDivID).style.top = topPos + ffHeight + "px" ;
        document.getElementById(popDivID).style.left = leftPos + "px" ;       
      }
      
      if(listAddFvt)
      { 
         document.getElementById('listData').value=removeData;
         document.getElementById('listAddFavorite').value=listAddFvt;
         document.getElementById('listRemoveFavorite').value=listRemvFvt;
         document.getElementById('listStatus').value=listStatus;
         document.getElementById('analyticsEvent').value=analyticsText;
      }
      else if(removeData!=null)
      { 
         document.getElementById('forDeleteData').value=removeData;       
         document.getElementById('analyticsEvent').value=analyticsText;  
      }
    }
 
//show login popup in srp and ldp on click of add favourite
function showLoginPopup(popDivID, divId, topPos, leftPos,id,type)
{
  listingId=id;
  listinType=type;      
  var divIdObj = document.getElementById(divId);
  var IE = document.all?true:false;
  var ffHeight, ieHeight;

  if (IE)
  {
    document.getElementById(popDivID).style.display = "block";
    ieHeight =findPosY(divIdObj) ;
    document.getElementById(popDivID).style.top = topPos + ieHeight + "px" ;
    document.getElementById(popDivID).style.left = leftPos + "px" ;           
  }
  else
  {    
    document.getElementById(popDivID).style.display = "block";
    ffHeight =findPosY(divIdObj) ;
    document.getElementById(popDivID).style.top = topPos + ffHeight + "px" ;
    document.getElementById(popDivID).style.left = leftPos + "px" ;
  }
}    

//This function is used in talktous, reset pwd, ask zamanzar, set up tour, myzamanzar, update password & change password to disable the submit button.
function hideButtonCallBack(id_submit,id_close)
{
  document.getElementById(id_submit).disabled = true;
  document.getElementById(id_submit).className = 'allButtonsDisabled';
  document.getElementById(id_close).style.display = "block";
}

//This function is used in myzamanzar, update password & change password to enable the submit button.
function hideButtonFalse(id_submit)
{
  document.getElementById(id_submit).disabled = false;	
  document.getElementById(id_submit).className = 'allButtons';
}
// function is used to disabled the image button.
function hideImageButtonCallBack(id_submit)
{
  document.getElementById(id_submit).disabled = true;
}
//function is used to enable the image button.
function enableImageButton(id_submit)
{
  document.getElementById(id_submit).disabled = false;	
}
//This function returns relative X position of given element
//and adds or subtracts given adjustment value to it.
function getX(divId,adj_value,flag)
{
  var e = document.getElementById(divId).style.left;
  
  if (IE)
  {  
    if(flag == "add")
      {
        return document.getElementById(divId).offsetLeft + adj_value + 10;
      }
      else
      {
        return document.getElementById(divId).offsetLeft - adj_value + 10;
      }
  }
  else
  {
    if(flag == "add")
    {
      return document.getElementById(divId).offsetLeft + adj_value;
    }
    else
    {
      return document.getElementById(divId).offsetLeft - adj_value;
    }
  }
  
}

//This function will be called on on propertyValue action
 function valueProperty(valueProperty_city,valueProperty_area,valueProperty_beds,
            valueProperty_baths,valueProperty_cov_area,valueProperty_prop_type,valueProperty_name,
            valueProperty_phone,valueProperty_email,valueProperty_age,valueProperty_address,propertyValue,share_info,area_unit,lot_size,lot_unit,floorN,floorT,listing_type,analyticsText,key,flag,nationalLevel)
{
  
  if(analyticsText)
  {
    trackAnalytics(analyticsText);    
  }
  //This limit will be used to display captcha on valuation
  var captcha_limit = parseInt(document.getElementById('captcha_limit').value);  
  var captcha_show = parseInt(document.getElementById('captcha_show').value);    
  var city = document.getElementById(valueProperty_city).value;
  if(flag==1)
  {  	
  	var area = document.getElementById(valueProperty_area).value;  	
  }  
  else
  {
    var area = valueProperty_area;
    document.getElementById('valueProperty_area').value = valueProperty_area;    
  }
  var cov_area = document.getElementById(valueProperty_cov_area).value;
  var beds = document.getElementById(valueProperty_beds).value;
  var baths = document.getElementById(valueProperty_baths).value;
  var prop_type = document.getElementById(valueProperty_prop_type).value;
  var user_name = document.getElementById(valueProperty_name).value;
  var phone = document.getElementById(valueProperty_phone).value;
  var email = document.getElementById(valueProperty_email).value;
  var address = document.getElementById(valueProperty_address).value;
  var age = document.getElementById(valueProperty_age).value;
  var share_info = document.valuePropertyForm.share_info.checked;  
  var email_info = document.valuePropertyForm.email_info.checked;  
  var area_unit = document.getElementById(area_unit).value;
  var lot_unit = document.getElementById(lot_unit).value;
  var lot_size = document.getElementById(lot_size).value;
  var floor_n = document.getElementById(floorN).value;
  var listing_type = document.getElementById(listing_type).value;
  if(floor_n=="0 For Ground Floor")
  {
  	floor_n="";
  }
  var floor_t = document.getElementById(floorT).value;  
  //If captcha is disable
  if((captchaCount<captcha_limit)||(!captcha_show))
  {    
     var parameter="?city="+city+"&area="+area+"&beds="+beds+"&baths="+baths+"&prop_type="+prop_type+"&list_type="+listing_type
     +"&name="+user_name+"&phone="+phone+"&email="+email+"&cov_area="+cov_area+"&address="+address+"&age="+age+"&share_info="+share_info+"&email_info="+email_info
     +"&area_unit="+area_unit+"&lot_unit="+lot_unit+"&lot_size="+lot_size+"&floor_n="+floor_n+"&floor_t="+floor_t;
  } 
  //If captcha is enable
  else
  {  
  	var recaptcha_challenge_field = document.getElementById('recaptcha_challenge_field').value;
    var recaptcha_response_field = document.getElementById('recaptcha_response_field').value;    
     var parameter="?city="+city+"&area="+area+"&beds="+beds+"&baths="+baths+"&prop_type="+prop_type+"&list_type="+listing_type
     +"&name="+user_name+"&phone="+phone+"&email="+email+"&cov_area="+cov_area+"&address="+address+"&age="+age+"&share_info="+share_info+"&email_info="+email_info
     +"&area_unit="+area_unit+"&lot_unit="+lot_unit+"&lot_size="+lot_size+"&floor_n="+floor_n+"&floor_t="+floor_t+"&recaptcha_challenge_field="+recaptcha_challenge_field
    +"&recaptcha_response_field="+recaptcha_response_field; 
  } 
    
    new Ajax.Updater(propertyValue,'/home/automatedValuation/'+parameter,
    { 
     method: 'post',  
     onLoading : (Element.hide('propertyValue')&&Element.show('propertyValueIndicator')&&document.getElementById('propertyValueIndicator').scrollIntoView(true)),
     onSuccess:function(transport) {     
         var response = transport.responseText; 
         
         //If entered captcha code is not valid than display error message
         if(response=="error")         {
         	 response = "The Code that you entered is not the correct code from the Verification Image";
         	 showRecaptcha('dynamic_recaptcha_1',key,'red');         	         	 
         	 trackAnalytics("VALUATION_CAPTCHA_FAILURE");    
           document.getElementById('recaptcha_response').innerHTML=response;
           Element.hide('propertyValueIndicator'); 
         }         
         else
         {	        
	         Element.hide('propertyValueIndicator'); 
	         Element.show('propertyValue'); 
	         
	         if(!nationalLevel)
	         {  
	           document.getElementById('locality').innerHTML =area+", "+city; 
	         }                
	         document.getElementById(propertyValue).innerHTML = response; 
	         if(document.getElementById('propertyMain').style.display=='none' && document.getElementById('showLogin')==null){
	        	 showForm1(document.getElementById('showPaymentMessage'), 100, 200, 25, 155);
	         }else if(document.getElementById('showLogin')!=null){
	        	 
	        	 document.getElementById('loginEmail').value=document.getElementById('valueProperty_email').value;
	        	 showForm1(document.getElementById('showLoginMessage'), 100, 200, 25, 155);
	         }
	         captchaCount=parseInt(document.getElementById('captcha_count').value); 
	         //Display captcha after this predefined limit   
	         // check if setting to show captcha is true in yml file
	         if(captcha_show)       
	         {  if(captchaCount>=captcha_limit)
	           { 
	           	 //hide valuation button,diplay at other place below captcha	           	
	           	 document.getElementById('valuationButton').style.display = "none"; 
	           	 //show captcha div
	           	 document.getElementById('captcha_code').style.display = "block";  
	           	 //show captcha	           	        
	             showRecaptcha('dynamic_recaptcha_1',key,'red');
	           }
	         }
	         document.getElementById('recaptcha_response').innerHTML="";  
	           
         }  
        }    
     }
    );       
}

//change color of bed bath input field based on property type
 function changeBedBath(beds,baths,prop_type){
      if(document.getElementById(prop_type).value!="Apartment" && document.getElementById(prop_type).value!="House")
      {
	    document.getElementById(beds).disabled = true;
	    document.getElementById(baths).disabled = true;
      }  
	}  

//disable  lotSize  in case of property type is not house on valuation page 
  function disableLotSize(lotsize,lotUnit,OnOff){
    document.getElementById(lotsize).disabled = OnOff;
      document.getElementById(lotUnit).disabled = OnOff;
    
  }  
//disable floor property in case of property type is not apartment on valuation page  
  function disableFloor(floorNo,floorTotal,OnOff){
    document.getElementById(floorNo).disabled = OnOff;
      document.getElementById(floorTotal).disabled = OnOff;
    
  }   
  //diable floor fields in case of property type is not apartment on valuation page  
  function loadFloor(floorNo,floorTotal,prop_type)
  {
    if(document.getElementById(prop_type).value!="Apartment")
    {
      document.getElementById(floorNo).disabled = true;
      document.getElementById(floorTotal).disabled = true;
    }  
  } 
//disable  lotSize  in case of property type is not house on valuation page 
  function loadLotSize(lotsize,lotUnit,prop_type){
      if(document.getElementById(prop_type).value!="House")
      {
      document.getElementById(lotsize).disabled = true;
      document.getElementById(lotUnit).disabled = true;
      }  
  } 
  
  //This function is used to show captcha
  function showRecaptcha(element,key,themeName)
 {  	 
  Recaptcha.create(key, element, {
        theme: themeName,
        tabindex: 0,
        callback: Recaptcha.focus_response_field
  });}
 
//Function to open chat pop up 
function popitup(url) {
  newwindow=window.open(url,'name','height=465,width=500');
  newwindow.moveTo((window.screen.availWidth -  500) / 2, (window.screen.availHeight - 475) / 2);
    if(window.focus) {newwindow.focus()}
        return false;
      }
      
//disable  beds baths according to property type 
  function disableBedBath(beds,baths,OnOff){
    document.getElementById(beds).disabled=OnOff;
    document.getElementById(baths).disabled=OnOff;
  }   
  
function disableSetting(currencyUnit)
{
  if(currencyUnit == '$'){
    document.getElementById('dollar').innerHTML = 'US $';
    document.getElementById('rupees').innerHTML = '<a href="javascript:void(0)" id="currency" name="rs" value="Rs" ' +
    'onclick=' + 'currencyConverter("Rs");disableSetting("Rs");trackAnalytics("CURRENCY_UNIT_Rs")>INR</a>';
    document.getElementById('pounds').innerHTML = '<a href="javascript:void(0)" id="currency" name="pnd" value="&#163;" ' +
    'onclick=' + 'currencyConverter("&#163;");disableSetting("&#163;");trackAnalytics("CURRENCY_UNIT_&#163;")>GBP (&#163;)</a>';
    document.getElementById('euros').innerHTML = '<a href="javascript:void(0)" id="currency" name="ero" value="&#8364;" ' +
    'onclick=' + 'currencyConverter("&#8364;");disableSetting("&#8364;");trackAnalytics("CURRENCY_UNIT_&#8364;")>EURO (&euro;)</a>';
  }
  else if(currencyUnit == "\xA3"){
    document.getElementById('pounds').innerHTML = 'GBP (&#163;)';
    document.getElementById('dollar').innerHTML = '<a href="javascript:void(0)" id="currency" name="dol" value="$" ' +
    'onclick=' + 'currencyConverter("$");disableSetting("$");trackAnalytics("CURRENCY_UNIT_$")>US $</a>';
    document.getElementById('rupees').innerHTML = '<a href="javascript:void(0)" id="currency" name="rs" value="Rs" ' +
    'onclick=' + 'currencyConverter("Rs");disableSetting("Rs");trackAnalytics("CURRENCY_UNIT_Rs")>INR</a>';
    document.getElementById('euros').innerHTML = '<a href="javascript:void(0)" id="currency" name="ero" value="&#8364;" ' +
    'onclick=' + 'currencyConverter("&#8364;");disableSetting("&#8364;");trackAnalytics("CURRENCY_UNIT_&#8364;")>EURO (&euro;)</a>';
  }
  else if(currencyUnit == "\u20AC"){
    document.getElementById('euros').innerHTML = 'EURO (&#8364;)';
    document.getElementById('rupees').innerHTML = '<a href="javascript:void(0)" id="currency" name="rs" value="Rs" ' +
    'onclick=' + 'currencyConverter("Rs");disableSetting("Rs");trackAnalytics("CURRENCY_UNIT_Rs")>INR</a>';
    document.getElementById('pounds').innerHTML = '<a href="javascript:void(0)" id="currency" name="pnd" value="&#163;" ' +
    'onclick=' + 'currencyConverter("&#163;");disableSetting("&#163;");trackAnalytics("CURRENCY_UNIT_&#163;")>GBP (&#163;)</a>';
    document.getElementById('dollar').innerHTML = '<a href="javascript:void(0)" id="currency" name="dol" value="$" ' +
    'onclick=' + 'currencyConverter("$");disableSetting("$");trackAnalytics("CURRENCY_UNIT_$")>US $</a>';
  }
  else if(currencyUnit == 'Rs'){
    document.getElementById('rupees').innerHTML = 'INR';
    document.getElementById('dollar').innerHTML = '<a href="javascript:void(0)" id="currency" name="dol" value="$" ' +
    'onclick=' + 'currencyConverter("$");disableSetting("$");trackAnalytics("CURRENCY_UNIT_$")>US $</a>';
    document.getElementById('pounds').innerHTML = '<a href="javascript:void(0)" id="currency" name="pnd" value="&#163;" ' +
    'onclick=' + 'currencyConverter("&#163;");disableSetting("&#163;");trackAnalytics("CURRENCY_UNIT_&#163;")>GBP (&#163;)</a>';
    document.getElementById('euros').innerHTML = '<a href="javascript:void(0)" id="currency" name="ero" value="&#8364;" ' +
    'onclick=' + 'currencyConverter("&#8364;");disableSetting("&#8364;");trackAnalytics("CURRENCY_UNIT_&#8364;")>EURO (&euro;)</a>';
  }
}

function disableAreaSetting(areaUnit)
{
  if(areaUnit == 'sqyd') {
    document.getElementById('sqyards').innerHTML = 'Sqyd';
    document.getElementById('areafeet').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="feet" value="sqft" ' +
    'onclick=' + 'areaConverter("sqft");disableAreaSetting("sqft");trackAnalytics("AREA_UNIT_sqft")>Sqft</a>';
    document.getElementById('sqmtrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="meters" value="sqmt" ' +
    'onclick=areaConverter("sqmt");disableAreaSetting("sqmt");trackAnalytics("AREA_UNIT_sqmt")>Sqmt</a>';
    document.getElementById('acrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="acres" value="acre" ' +
    'onclick=areaConverter("acre");disableAreaSetting("acre");trackAnalytics("AREA_UNIT_acre")>Acre</a>';
    document.getElementById('hectrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="hectares" value="hect" ' +
    'onclick=areaConverter("hect");disableAreaSetting("hect");trackAnalytics("AREA_UNIT_hect")>Hect</a>';
  }
  else if(areaUnit == 'sqmt'){
    document.getElementById('sqmtrs').innerHTML = 'Sqmt';
    document.getElementById('sqyards').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="yards" value="sqyd" ' +
    'onclick=' + 'areaConverter("sqyd");disableAreaSetting("sqyd");trackAnalytics("AREA_UNIT_sqyd")>Sqyd</a>';
    document.getElementById('areafeet').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="feet" value="sqft" ' +
    'onclick=' + 'areaConverter("sqft");disableAreaSetting("sqft");trackAnalytics("AREA_UNIT_sqft")>Sqft</a>';
    document.getElementById('acrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="acres" value="acre" ' +
    'onclick=areaConverter("acre");disableAreaSetting("acre");trackAnalytics("AREA_UNIT_acre")>Acre</a>';
    document.getElementById('hectrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="hectares" value="hect" ' +
    'onclick=areaConverter("hect");disableAreaSetting("hect");trackAnalytics("AREA_UNIT_hect")>Hect</a>';
  }
  else if(areaUnit == 'acre') {
    document.getElementById('acrs').innerHTML = 'Acre';
    document.getElementById('areafeet').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="feet" value="sqft" ' +
    'onclick=' + 'areaConverter("sqft");disableAreaSetting("sqft");trackAnalytics("AREA_UNIT_sqft")>Sqft</a>';
    document.getElementById('sqyards').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="yards" value="sqyd" ' +
    'onclick=' + 'areaConverter("sqyd");disableAreaSetting("sqyd");trackAnalytics("AREA_UNIT_sqyd")>Sqyd</a>';
    document.getElementById('sqmtrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="meters" value="sqmt" ' +
    'onclick=areaConverter("sqmt");disableAreaSetting("sqmt");trackAnalytics("AREA_UNIT_sqmt")>Sqmt</a>';
    document.getElementById('hectrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="hectares" value="hect" ' +
    'onclick=areaConverter("hect");disableAreaSetting("hect");trackAnalytics("AREA_UNIT_hect")>Hect</a>';
  }
  else if(areaUnit == 'hect') {
    document.getElementById('hectrs').innerHTML = 'Hect';
    document.getElementById('areafeet').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="feet" value="sqft" ' +
    'onclick=' + 'areaConverter("sqft");disableAreaSetting("sqft");trackAnalytics("AREA_UNIT_sqft")>Sqft</a>';
    document.getElementById('sqyards').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="yards" value="sqyd" ' +
    'onclick=' + 'areaConverter("sqyd");disableAreaSetting("sqyd");trackAnalytics("AREA_UNIT_sqyd")>Sqyd</a>';
    document.getElementById('sqmtrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="meters" value="sqmt" ' +
    'onclick=areaConverter("sqmt");disableAreaSetting("sqmt");trackAnalytics("AREA_UNIT_sqmt")>Sqmt</a>';
    document.getElementById('acrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="acres" value="acre" ' +
    'onclick=areaConverter("acre");disableAreaSetting("acre");trackAnalytics("AREA_UNIT_acre")>Acre</a>';
  }
  else if(areaUnit == 'sqft') {
    document.getElementById('areafeet').innerHTML = 'Sqft';
    document.getElementById('sqyards').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="yards" value="sqyd" ' +
    'onclick=' + 'areaConverter("sqyd");disableAreaSetting("sqyd");trackAnalytics("AREA_UNIT_sqyd")>Sqyd</a>';
    document.getElementById('sqmtrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="meters" value="sqmt" ' +
    'onclick=areaConverter("sqmt");disableAreaSetting("sqmt");trackAnalytics("AREA_UNIT_sqmt")>Sqmt</a>';
    document.getElementById('acrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="acres" value="acre" ' +
    'onclick=areaConverter("acre");disableAreaSetting("acre");trackAnalytics("AREA_UNIT_acre")>Acre</a>';
    document.getElementById('hectrs').innerHTML = '<a href="javascript:void(0)" id="cov_area" name="hectares" value="hect" ' +
    'onclick=areaConverter("hect");disableAreaSetting("hect");trackAnalytics("AREA_UNIT_hect")>Hect</a>';
  }
  
} 

// Function to show/hide drop down div (Home page city top links)
var activeLinkTab = "";
var activeDropdownDiv = "";
function menuDiv(menuDivId, submenuDivId)
{
  //If null string is passed, this function disables currently active tab, and activates nothing.
  if(menuDivId != "") {
  //document.getElementById(menuDivId).style.display = 'block' ;
  document.getElementById(submenuDivId).style.display = 'block';
 }
  //Make currently active tab inactive.
  if(activeLinkTab != "" && activeLinkTab != activeDropdownDiv)
  {
    //document.getElementById(activeLinkTab).style.display = 'none';
    document.getElementById(activeDropdownDiv).style.display = 'none';
  }           
    activeLinkTab = menuDivId;
    activeDropdownDiv = submenuDivId;
}

// Simple little function to get Elements as an object
function getEl(id)
{
  var el = document.getElementById(id);
  return el;
}
// Function to hide Elements
function hideEl(id)
{
  getEl(id).style.display ="none";
}


//Function used to set cookie
//Receives name, value and expiry period in days and sets the cookie on server side by 
//calling an AJAX function. This is required in cases where the page is cached, so that cookie gets reflected on refresh.
function SetCookieOnServer(name,value,expire)
{
  new Ajax.Request('/home/setCookie?name='+name+'&value='+value+'&expire='+expire,
  { 
 method: 'get',
      
     onSuccess: function(transport) {
       var value=transport.responseText;       
     },
     onFailure: function() { 
     },       
     onLoading: function(){         
     }
    }
    );
 }
 
 //functionuse to get cookie (used for live chat popup).
 function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}  

// Start Set positioning of the popup.
if(document.layers)
{
var wd = window.innerWidth;
}else{
var wd = screen.width;
}

if(wd==1024)
{
var startX = 507 //set x offset of bar in pixels
var startY = 171 //set y offset of bar in pixels
}else{
var startX = 507 //set x offset of bar in pixels
var startY = 171 //set y offset of bar in pixels
}

var verticalpos="fromtop" //enter "fromtop" or "frombottom"

function iecompattest()
{
 return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

// function use to display popup and scrolling in the page. 
function staticbar(){
  if(getCookie('LIVE_CHAT_OFF') == "" && document.getElementById('live_chat').value == '1') {
  barheight=document.getElementById("liveChat").offsetHeight
  var ns = (navigator.appName.indexOf("Netscape") != -1) || window.opera;
  var d = document;
  function ml(id){
    var el=d.getElementById(id);  
    el.style.display="block";
    if(d.layers)el.style=el;
    el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
    el.x = startX;
    if (verticalpos=="fromtop")
    el.y = startY;
    else{
    el.y = ns ? pageYOffset + innerHeight : iecompattest().scrollTop + iecompattest().clientHeight;
    el.y -= startY;
    }
    return el;
  }
  window.stayTopLeft=function(){
    if (verticalpos=="fromtop"){
    var pY = ns ? pageYOffset : iecompattest().scrollTop;
    ftlObj.y += (pY + startY - ftlObj.y)/8;
    }
    else{
    var pY = ns ? pageYOffset + innerHeight - barheight: iecompattest().scrollTop + iecompattest().clientHeight - barheight;
    ftlObj.y += (pY - startY - ftlObj.y)/8;
    }
    ftlObj.sP(ftlObj.x, ftlObj.y);
    setTimeout("stayTopLeft()", 10);
  }
    setTimeout("setTime()", document.getElementById('chatpopup').value); // set time for chat popup.
  window.setTime=function(){
    ftlObj = ml('liveChat');
    stayTopLeft();  
  }
 } 
}

// End Set positioning of poup

// function use to count text characters.
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) 
{
  var countedTextBox = opt_countedTextBox ? opt_countedTextBox : "linkdesc";
  var countBody = opt_countBody ? opt_countBody : "countBody";
  var maxSize = opt_maxSize ? opt_maxSize : 1024;

  var field = document.getElementById(countedTextBox);

  if (field && field.value.length >= maxSize) {
          field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(countBody);
          if (txtField) { 
          txtField.innerHTML = field.value.length;
  }
}  

// function is used for open new window for live chat. 
function openNewWindow(url)
{
  var  page_url= window.location.href;
  var base_url = getUrlBase(page_url);
  base_url = base_url+url;
  
  popUpWindow = window.open(base_url,'liveChatPage','left=250, top=130, width=500, height=465','location=no, status=no');
  popUpWindow.moveTo((window.screen.availWidth -  500) / 2, (window.screen.availHeight - 475) / 2);
  if(window.focus) {popUpWindow.focus()}
}

//Fire an AJAX request to get dynamic details of Trend pages.
    function getDetailsOfUser() { 
    
      new Ajax.Request('/listing/userDetails',
      { 
       method: 'get',
        
       onSuccess: populateDetailsOfUser,
       
       onFailure: function() {
       }
      });
    }    
    //Callback function for dynamically populating some details of the Trend Pages.
    function populateDetailsOfUser(transport) {
     
      var response = transport.responseText;
      if(response == null || response == "") { //User might not be logged in.       
        //Set user name as guest in welcome message in header.
        $('welcomeMsgContainer').innerHTML = "Welcome Guest";
        
        return;
      }      
      //Response Structure - Name, Email, Phone
      var data = response.split(',');
      
      //Populate Talk To Us
      $('qpName').value = data[0];
      $('qpEmail').value = data[1];
      $('qpPhone').value = data[2];     
      
      //Set user name in welcome message in header.
      $('welcomeMsgContainer').innerHTML = "Welcome " + data[0] + " (<a href='/user/logout'>Logout</a>)";      
       
    }      

// function used to submit the request information into database.
// and check the validation, if validation is true then open chat popup.
function submitChatPopup()
{
  var Name = document.getElementById('cuName').value;
  var Phone = document.getElementById('cuPhone').value;
  var Email = document.getElementById('cuEmail').value;
  var tran_type = document.getElementById('tran_type').value;
  var companyName = document.getElementById('companyName').value;
  var chat_price = document.getElementById('chat_price').value
  var chat_listingType = document.getElementById('chat_listingType').value;
  
  //Returns validation status and sets error message if validation fails.
  var valid = chatWithUs($('cuName'),$('cuEmail'),$('cuPhone'),'chatUserFeedback');
  
  if(valid) {
  hideEl('liveChat');    
  new Ajax.Request('/common/chatPopUp?cuName='+Name+'&cuPhone='+Phone+'&cuEmail='+Email+'&tran_type='+tran_type+'&companyName='+companyName+'&chat_price='+chat_price+'&chat_listingType='+chat_listingType,
  {
     method: 'get',
          
     onSuccess: function(transport) {
     var response = transport.responseText;  
       trackAnalytics('LIVE_CHAT_SUBMIT'); 
                     
     },
     
     onLoading: function() {
       
     },
     onFailure: function() {
       trackAnalytics('LIVE_CHAT_FAILURE'); 
     }
  }
 );
 return true;
}

else { //This prevents the chat popup link from opening. 
  return false;
 }  
}

function setUpPriceMenu(tran_type,price_no)
{
  var list_type =  tran_type;
  var pr = document.getElementById(price_no);
  if(list_type == 'S')
  {
	 pr.options[0].text='Lakhs';
	 pr.options[1].text='Thousands';
	 pr.options[2].text='Crores';
	 
	 pr.options[0].value='Lakh';
	 pr.options[1].value='Thousand';
	 pr.options[2].value='Crores';
  }
  else if(list_type == 'R') {
	  pr.options[0].text='Thousands';
	  pr.options[1].text='Lakhs';
	  pr.options[2].text='Crores';
	 
	  pr.options[0].value='Thousand';
	  pr.options[1].value='Lakh';
	  pr.options[2].value='Crores'; 
  }
}

//this function will use to get radio button value
function getCheckedValue(radioObj) {
	  if(!radioObj)
	    return "";
	  var radioLength = radioObj.length;
	  if(radioLength == undefined)
	    if(radioObj.checked)
	      return radioObj.value;
	    else
	      return "";
	  for(var i = 0; i < radioLength; i++) {
	    if(radioObj[i].checked) {
	      return radioObj[i].value;
	    }
	  }
	  return "";
	}
