function get_content(url, divId) 
{
    var div = document.getElementById(divId);
    div.innerHTML = '<img style="padding-left:275px;padding-top:175px;" src="images/loading.gif" alt="Loading...">';  
    new Ajax.Updater(div,url,{
                                  method: 'GET', 
                                  onException: function(req,exception) { 
                                    alert(exception);
                                  }
                             }
                                       
    );
}

function select_tab(id)
{
            for( x = 1; x < 17; x++ )
        {
            var outer_tab  = document.getElementById( 'ms_mt' + x );
            var inner_tab  = document.getElementById( 'ms_mt2' + x );

            if( ! outer_tab ) continue;

            if( x != id )
            {
                    outer_tab.setAttribute( 'class', 'microsite_menu_tab' );
                        outer_tab.setAttribute( 'className', 'microsite_menu_tab' );
                inner_tab.setAttribute( 'class', '' );
                inner_tab.setAttribute( 'className', '' );
            }
            else
            {
                outer_tab.setAttribute( 'class', 'microsite_menu_tab_on' );
                        outer_tab.setAttribute( 'className', 'microsite_menu_tab_on' );
                inner_tab.setAttribute( 'class', 'microsite_menu_tab_on1' );
                inner_tab.setAttribute( 'className', 'microsite_menu_tab_on1' );
            }
        }

}
function update_availability_tab(listing_id)
{
    var url = "/new_developments/ajax/get_images.php?listingId=" + listing_id;
    var divId = "gallery_html";
    get_content(url, divId);
    
    url = "/new_developments/ajax/get_financial_info.php?listingId=" + listing_id;
    divId = "financial_html";
    get_content(url, divId);

    url = "/new_developments/ajax/get_description.php?listingId=" + listing_id;
    divId = "description_html";
    get_content(url, divId);    
    
}
function validate_user_pass(user,pass)
{
    var url = '/new_developments/nd_login_check.php?u=' + user+ "&p="+pass;
     var myAjax = new Ajax.Request(url, {
                                           method: 'get',
                                           asynchronous: false,
                                           parameters: ""
                                         }
                     );
    return myAjax.transport.responseText;
}

function validate_form(return_url, building_id)
{
    // Form JS validation
    var login_username = document.nd_login.login_username.value;
    if (login_username == null || login_username == "") {
        alert("Please enter username name");
        document.nd_login.login_username.focus();
        return false;
    }

    var login_password = document.nd_login.login_password.value;
    if (login_password == null || login_password == "") {
        alert("Please enter password");
        document.nd_login.login_password.focus();
        return false;
    }
 
    var ret = validate_user_pass(login_username,login_password);
    if (ret == 0) {
       alert("Invalid username or password");
    }
    else {
       var url= return_url + building_id;
       divId="microsite_content";
       get_content(url, divId);
    }
    return false;
}

function save_building(building_id)
{
    var url= "/new_developments/save_building.php?building_id=" + building_id;
    var divId = "microsite_content";
    get_content(url, divId);
}
function get_email_updates(building_id)
{
    var url= "/new_developments/email_updates.php?building_id=" + building_id;
    var divId = "microsite_content";
    get_content(url, divId);
}


function add_nd_css()
{
  /* add nd_css resale style sheet if it was not already included */
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("href") == '/new_developments/css/nd_resale.css') {
       return;
    }
  }
  
  var headID = document.getElementsByTagName("head")[0];         
  var cssNode = document.createElement('link');
  cssNode.type = 'text/css';
  cssNode.rel = 'stylesheet';
  cssNode.href = '/new_developments/css/nd_resale.css';
  cssNode.media = 'screen';
  headID.appendChild(cssNode);
}

function delete_nd_css()
{
  /* delete nd_css resale style sheet if it was included */
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("href") == '/new_developments/css/nd_resale.css') {
       a.removeAttribute("href");
       return;
    }
  }

}
