﻿// JScript File
function expand(divlvl0Id, divlvl1Id, divlvl2Id, anchlvl0Id, anchlvl1Id, anchlvl2Id, anchlvl3Id)
{
        if(document.getElementById("nav-container"))
        {
            document.getElementById("nav-container").style.display="block";
        }
  
        changeImageSelected(divlvl0Id);
        var classname1;
        if(document.getElementById(divlvl0Id))
        {
            document.getElementById(divlvl0Id).style.display="block";
        }
        
        if(document.getElementById(divlvl1Id))
        {
            document.getElementById(divlvl1Id).style.display="block";
        }
        
        if(document.getElementById(divlvl2Id))
        {
            document.getElementById(divlvl2Id).style.display="block";
        }
        
        if(anchlvl3Id)
        {
            if(document.getElementById(anchlvl0Id))
            {
                document.getElementById(anchlvl0Id).className="navLevel0 sel2";
            }   
            if(document.getElementById(anchlvl1Id))
            {
                if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 41)
                {
                    document.getElementById(anchlvl1Id).className="navLevel13 lev1d";
                }
                else if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 24)
                {
                    document.getElementById(anchlvl1Id).className="navLevel12 lev1d";
                }
                else
                {
                    document.getElementById(anchlvl1Id).className="navLevel1 lev1d";
                }
            } 
            if(document.getElementById(anchlvl2Id))
            {
                if(trim(document.getElementById(anchlvl2Id).innerHTML).length > 22)
                {
                    document.getElementById(anchlvl2Id).className="navLevel22 lev2d";
                }
                else
                {
                    document.getElementById(anchlvl2Id).className="navLevel2 lev2d";
                }
            } 
            if(document.getElementById(anchlvl3Id))
            {
                if(trim(document.getElementById(anchlvl3Id).innerHTML).length > 18)
                {
                    document.getElementById(anchlvl3Id).className="navLevel32 lev3s";
                }
                else
                {
                    document.getElementById(anchlvl3Id).className="navLevel3 lev3s";
                }
            } 
        }
        else if(anchlvl2Id)
        {
            if(document.getElementById(anchlvl0Id))
            {
               document.getElementById(anchlvl0Id).className="navLevel0 sel2";
            }   
            if(document.getElementById(anchlvl1Id))
            {
                if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 41)
                {
                    document.getElementById(anchlvl1Id).className="navLevel13 lev1d";
                }
                else if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 24)
                {
                    document.getElementById(anchlvl1Id).className="navLevel12 lev1d";
                }
                else
                {
                    document.getElementById(anchlvl1Id).className="navLevel1 lev1d";
                }
            } 
            if(document.getElementById(anchlvl2Id))
            {
                if(trim(document.getElementById(anchlvl2Id).innerHTML).length > 22)
                {
                    document.getElementById(anchlvl2Id).className="navLevel22 lev2s";
                }
                else
                {
                    document.getElementById(anchlvl2Id).className="navLevel2 lev2s";
                }
            } 
        }
        else if(anchlvl1Id)
        {
            if(document.getElementById(anchlvl0Id))
            {
                document.getElementById(anchlvl0Id).className="navLevel0 sel2";
            }   
            if(document.getElementById(anchlvl1Id))
            {
                if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 41)
                {
                    document.getElementById(anchlvl1Id).className="navLevel13 lev1s";
                }
                else if(trim(document.getElementById(anchlvl1Id).innerHTML).length > 22)
                {
                    document.getElementById(anchlvl1Id).className="navLevel12 lev1s";
                }
                else
                {
                    document.getElementById(anchlvl1Id).className="navLevel1 lev1s";
                }
            } 
        }
        else if(anchlvl0Id)
        {
            if(document.getElementById(anchlvl0Id))
            {
               document.getElementById(anchlvl0Id).className="navLevel0 sel";
            }   
        }
    }
    
    
    function getQueryVariable(variable)
    {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++)
        {
            var pair = vars[i].split("=");
            if (pair[0].toLowerCase() == variable.toLowerCase())
            {
                if(variable.toLowerCase()=="page")
                {
                    runScriptAssetManagement(trim(pair[1]));
                }
                if(variable.toLowerCase()=="calc")
                {
                    runScriptInvestmentCalculator(trim(pair[1]));
                }
                if(variable=="FeedbackType")
                {
                    runScriptEnquiry(trim(pair[1]));
                }
            }
            
        }
    }
    
    function runScriptAssetManagement(page)
    {
        if(page=="1")
        {
            expand('lvl0Sales', '', '', 'anchSales', 'anchWhyAssetInvestmentManagement');
        }
        else if(page=="2")
        {
            expand('lvl0Lettings', '', '', 'anchLettings', 'anchAssetandInvestmentManagement');
        }
        else
        {
            expand('lvl0UKDevelopments', '', '', 'anchUKDevelopments', 'anchAssetManagement');
        }
    }
    
    function runScriptInvestmentCalculator(page)
    {
        if(page=="1")
        {
            expand('lvl0UKDevelopments', '', '', 'anchUKDevelopments', 'anchInvestmentCalculatorUK');
        }
        else
        {
            expand('lvl0International', '', '', 'anchInternational', 'anchInvestmentCalculator');
        }
    }
    
    function runScriptEnquiry(page)
    {
        if(page=="Feedback")
        {
            expand('lvl0AboutHamptons', 'lvl2ContactUs', '', 'anchAboutHamptons', 'anchContactUs', 'anchFeedBackForm')
        }
        if(page=="enquiry")
        {
            expand('lvl0AboutHamptons', 'lvl2ContactUs', '', 'anchAboutHamptons', 'anchContactUs', 'anchGeneralEnquiry')
        }
    }
    // Removes leading whitespaces
    function LTrim( value ) 
    {
    	var re = /\s*((\S+\s*)*)/;
	    return value.replace(re, "$1");
    }

    // Removes ending whitespaces
    function RTrim( value ) 
    {
	    var re = /((\s*\S+)*)\s*/;
	    return value.replace(re, "$1");
    }

    // Removes leading and ending whitespaces
    function trim( value ) 
    {   value = removeMiddleSpace(value)
	    return LTrim(RTrim(value));
    }
    
    function removeMiddleSpace(value)
    {
        while(value.indexOf("  ") != -1)
        {
            value = value.replace("  "," ");
        }
        
        if(value.length == 0)
        {
            return "";
        }
        else
        {
            return value;
        }
    }


function changeImageSelected(lstrMainTab)
{

var MainMenuId
switch(lstrMainTab)
{
        
     case "lvl0Sales":
            MainMenuId = "tabSales";
            break;
      case "lvl0Lettings":
            MainMenuId = "tabLettings";
            break;
       case "lvl0UKDevelopments":
            MainMenuId = "tabUkDevelopments";
            break;
       case "lvl0International":
            MainMenuId = "tabInternationalDelevopments";
            break;
       case "lvl0Mortgages":
            MainMenuId = "tabMortgages";
            break;
       case "lvl0AboutHamptons":
            MainMenuId = "tabAboutHamptons";
            break; 
       case "lvl0MyHamptons":
            MainMenuId = "tabMyHamptons";
            break;
        case "tabMyHamptons":
            MainMenuId = "tabMyHamptons";
            break; 
      case "tabAdvancedSearch":
            MainMenuId = "tabSearchProperties"
            break;
      case "tabHome":
            MainMenuId = "tabHome"
            break; 
      case "tabUKDevelopments":
            MainMenuId = "tabUkDevelopments"
            break;
      case "lvl0International":
            MainMenuId = "tabInternationalDelevopments"
            break;
      case "lvl0Services":
            MainMenuId = "tabServices"
            break;
     case "tabHamptonsworld":
            MainMenuId = "tabHamptonsworld"
            break;  
      default:
            MainMenuId = "tabHome" ; 
      
       
}

if(MainMenuId != "")
ResetAllTabs();
    
     if(document.getElementById(MainMenuId)) 
  document.getElementById(MainMenuId).id = MainMenuId + "Active";
   else if(document.getElementById("tabHome")) 
  document.getElementById("tabHome").id = "tabHomeActive";
   
   if(MainMenuId == "tabHamptonsworld")
       if(document.getElementById("tabHome"))
        document.getElementById("tabHome").id = "tabHomeActive";
    

}

function ResetAllTabs()
{


    if(document.getElementById("tabSalesActive")) 
        document.getElementById("tabSalesActive").id = "tabSales";
            
    if(document.getElementById("tabLettingsActive")) 
        document.getElementById("tabLettingsActive").id = "tabLettings";
                
    if(document.getElementById("tabUkDevelopmentsActive")) 
        document.getElementById("tabUkDevelopmentsActive").id = "tabUkDevelopments";
                
    if(document.getElementById("tabInternationalDelevopmentsActive")) 
        document.getElementById("tabInternationalDelevopmentsActive").id = "tabInternationalDelevopments";
                
    if(document.getElementById("tabMortgagesActive")) 
        document.getElementById("tabMortgagesActive").id = "tabMortgages";
                
    if(document.getElementById("tabAboutHamptonsActive")) 
        document.getElementById("tabAboutHamptonsActive").id = "tabAboutHamptons";
                
    if(document.getElementById("tabMyHamptonsActive")) 
        document.getElementById("tabMyHamptonsActive").id = "tabMyHamptons";
                
    if(document.getElementById("tabSearchPropertiesActive")) 
        document.getElementById("tabSearchPropertiesActive").id = "tabSearchProperties";
                
    if(document.getElementById("tabHomeActive")) 
        document.getElementById("tabHomeActive").id = "tabHome";
                
    if(document.getElementById("tabUkDevelopmentsActive")) 
        document.getElementById("tabUkDevelopmentsActive").id = "tabUkDevelopments";
                
    if(document.getElementById("tabServicesActive")) 
        document.getElementById("tabServicesActive").id = "tabServices";
                
    if(document.getElementById("tabHamptonsworldActive")) {
    
        document.getElementById("tabHamptonsworldActive").id = "tabHamptonsworld";
        }
            
}

function getQueryVariable_global(variable)
    {
        var query = window.location.search.substring(1);
        
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++)
        {
            var pair = vars[i].split("=");
            if (pair[0] == variable)
            {
                runScript(pair[1]);
            }
        }
    }

    function runScript(lstID)
    {
        if(lstID=="2")
        { 
            expandLevel('lvl0International', 'lvl1India', 'lvl2IndiaSales','','anchInternational', 'anchIndia','anchIndiaSales','anchIndiaDevDetails','');
        }
        else if(lstID=="3")
        {
            expand('lvl0Location', 'lvl2Dubai', '', 'anchLocation', 'anchDubai', 'anchDubaiDevelopments');
        }
        else if(lstID=="4")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','');
        }
        else if(lstID=="5")
        {
            expand('lvl0Location', 'lvl2Mauritius', '', 'anchLocation', 'anchMauritius', 'anchMauritiusDevelopment');
        }
        else if(lstID=="6")
        {         
            expandLevel('lvl0International', 'lvl1Morocco', 'lvl2MoroccoSales','','anchInternational', 'anchMorocco','anchMoroccoSales','anchMoroccoDevDetails','');
        }
        else if(lstID=="7")
        {
            expand('lvl0Location', 'lvl2Oman', '', 'anchLocation', 'anchOman', 'anchOmanDevelopment');
        }
        else if(lstID=="8")
        {         
            expandLevel('lvl0International', 'lvl1Pakistan', 'lvl2PakistanSales','','anchInternational', 'anchPakistan','anchPakistanSales','anchPakistanDevDetails','');
        }
        else if(lstID=="9")
        {         
            expandLevel('lvl0International', 'lvl1Seychelles', 'lvl2SeychellesSales','','anchInternational', 'anchSeychelles','anchSeychellesSales','anchSeychellesDevDetails','');
        }
        else if(lstID=="11")
        {         
            expandLevel('lvl0International', 'lvl1US', 'lvl2USSales','','anchInternational', 'anchUS','anchUSSales','anchUSDevDetails','');
        }
        else if(lstID=="15")
        {
            expand('lvl0Location', 'lvl2Canada', '', 'anchLocation', 'anchCanada', 'anchCanadaDevelopment');
        }
        else if(lstID=="16")
        {         
            expandLevel('lvl0International', 'lvl1Portugal', 'lvl2PortugalSales','','anchInternational', 'anchPortugal','anchPortugalSales','anchPortugalDevDetails','');
        }
        else if(lstID=="17")
        {
            expand('lvl0Location', 'lvl2Barbados', '', 'anchLocation', 'anchBarbados', 'anchBarbadosDevelopment');
        }
    }
    
    
    
    function getStateQueryVariable_global(variable)
    {
        var query = window.location.search.substring(1);
        
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++)
        {
            var pair = vars[i].split("=");
            if (pair[0] == variable)
            {
                runStateScript(pair[1]);
            }
        }
    }

    function runStateScript(lstID)
    {
        if(lstID=="1")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesLiguria');
        }
        else if(lstID=="2")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesSicily');
        }
        else if(lstID=="3")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesTuscany');
        }
        else if(lstID=="4")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesUmbria');
        }
        else if(lstID=="5")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesCalabria');
        }
        else if(lstID=="6")
        {
            expand('lvl0Location', 'lvl2Italy', 'lvl3ItalyProperties', 'anchLocation', 'anchItaly', 'anchItalyDevelopments', 'anchItalyPropertiesPuglia');
        }
         else if(lstID=="7")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesLazio');
        }
        else if(lstID=="8")
        {         
            expandLevel('lvl0International', 'lvl1Italy', 'lvl2ItalySales','lvl4ItalyProperties','anchInternational', 'anchItaly','anchItalySales','anchItalyDevDetails','anchItalyPropertiesCampania');
        }
        
    }
    
    function removeLeadingSlash()
    {       
        var breadCrumb = document.getElementById("ctl00_mainBreadCrumb");
        if(breadCrumb)
        {             
            var inputArr = breadCrumb.getElementsByTagName("span");
            for (var i = 0; i < inputArr.length; i++) 
            {                                            
                if(inputArr[i].innerHTML == '' || inputArr[i].innerHTML == '<a href="/NewWeb2UI/notrequired"></a>' || inputArr[i].innerHTML == '<A href="/NewWeb2UI/notrequired"></A>') 
                {                    
                    if(inputArr[i+1])
                    {                        
                        inputArr[i+1].innerHTML = "";
                        break;
                    }
                }
            }
         }
    }
    function Propertylongdescription(elementid)
    {
      if(document.getElementById(elementid))
      {
        var longdescText= document.getElementById(elementid).innerHTML;
        document.getElementById(elementid).innerHTML = longdescText.replace(/(http\:\/\/[\w\.\-\?\!\&\=]+)/g,'<a target="_blank" style="color:#E2760A;font-weight:bold;" href="$1">$1</a>');
      }
    }