﻿// JScript File - Matt Powers - Boston Condo Group 6/08/2007

function grid_service(mls_id)
{
alert('hi');
    load_pic(mls_id,'service_pic',0,160,130);
    load_values(mls_id);
   
}
function change_pic(mls_id,ele,val,width,height,up_down,limit)
{   
    
    pic_num = parseInt(val);
    pic_limit = parseInt(limit);
    if(up_down == 'up')
    {
       pic_num = pic_num + 1;
    }
    else
       pic_num = pic_num - 1;
    
    if(pic_num > pic_limit)
    {
        pic_num = 1;
    }
    if(pic_num < 1)
    {
    pic_num = pic_limit;
    }
    
    load_pic(mls_id,ele,pic_num - 1,width,height);
    Load_Normal_Element(pic_num,'pic_counter');
}
function load_pic(mls_id, pic_id, count,width,height)
{
    var image = document.getElementById(pic_id);
    image.src = 'http://media.mlspin.com/photo.aspx?w=' + width + '&h=' + height + '&mls=' + mls_id + '&n=' + count;
    
}


function load_values(mls_id)
{
alert('why is this not working');
AJAX_Services.Return_Building_Info_MLS(mls_id,pop_prop_preview,ErrorHandler,TimeOutHandler);

}

function pop_prop_preview(result)
{
    var results_length = result.length;

    Pop_List_Office_Agent(result[0]);
    Pop_Town(result[0]);
    
    
    //LIST_NO,LIST_AGENT,LIST_OFFICE,LIST_PRICE,TOWN_NUM,STATUS,PHOTO_COUNT,NO_BEDROOMS,NO_FULL_BATHS,NO_HALF_BATHS
    Load_Normal_Element(result[0],'service_mls');
    Load_Currency_Element(result[3],'service_price');
    //Load_Town(result[4]);
    Load_Price_Per(result[3],result[10],'service_price_per');
    Load_Status_Element(result[5],'service_status');
    Load_Normal_Element(result[6],'service_photo');
    Load_Normal_Element(result[7],'service_beds');
    Load_Normal_Element(result[8],'service_full_baths');
    Load_Normal_Element(result[9],'service_half_baths');
    Load_Normal_Element(result[10],'service_feet');
    Load_Hyperlink_Element(result[0],'service_link');
    
    
}
function Load_Hyperlink_Element(result, id)
{
var ele = document.getElementById(id);
ele.href = "http://www.bostoncondogroup.com/mls/mls" + result + ".aspx";
}
function Load_Currency_Element(result,id)
{

 var ele = document.getElementById(id);
 ele.innerHTML = formatCurrency(result);
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    num = Math.floor(num/100).toString();
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
      num = num.substring(0,num.length-(4*i+3))+','+
      num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + '$' + num);
}

function Load_Photo_Count(result)
{
}
function Load_Price_Per(result_1,result_2,id)
{
result = result_1/result_2;
var ele = document.getElementById(id);
if(result == 'Infinity')
{
    ele.innerHTML = 'N/A';
}
else
{
 ele.innerHTML = formatCurrency(result);
}
}
function Load_Status_Element(result,id)
{
 var ele = document.getElementById(id);
 if(result == 'ACT')
 {
    ele.innerHTML = 'Active, on the market';
 }
 else if(result == 'NEW')
 {
    ele.innerHTML = 'New to the market';
 }
 else if(result == 'BOM')
 {
    ele.innerHTML = 'Back on the market';
    
 }
 else if(result == 'CAN')
 {
    ele.innerHTML = 'Cancelled, off the market';
 }
 else if(result == 'EXP')
 {
    ele.innerHTML = 'Expired, off the market';
 }
 else if(result == 'EXT')
 {
    ele.innerHTML = 'Extended, on the market';
 }
 else if(result == 'PCG')
 {
    ele.innerHTML = 'Price Change, on the market';
 }
 else if(result == 'RAC')
 {
    ele.innerHTML = 'Reactivated, on the market';
 }
 else if(result == 'RNT')
 {
    ele.innerHTML = 'Rented';
 }
 else if(result == 'SLD')
 {
    ele.innerHTML = 'Sold, off the market';
 }
 else if(result == 'UAG')
 {
    ele.innerHTML = 'Under Agreement';
 }
 else if(result == 'WDN')
 {
    ele.innerHTML = 'Temporarily Withdrawn, off the market';
 }
 else
 {
 ele.innerHTML = result;
 }
}
function Load_Normal_Element(result,id)
{
 var ele = document.getElementById(id);
 ele.innerHTML = result;

}

function Pop_List_Office_Agent(mls_id)
{
//alert(mls_id);
}
function Pop_Town(mls_id)
{
//alert(mls_id);
}


function loadbox(e)
{
var ignoreKeys=[9,16,17,19,20,32,33,34,35,36,37,38,39,40,45,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,144,145,220];
var unicode=e.keyCode? e.keyCode : e.charCode
var bool = new Boolean(true);
for(i = 0; i < ignoreKeys.length; ++i)
{
  if(ignoreKeys[i] == unicode)
  {
    bool = false;
  }
}
if(bool == true)
{
var textvalue = document.forms['Index_Form'].boxer.value;
//AJAX_Services.Return_Buildings(textvalue,poptable,ErrorHandler,TimeOutHandler);
AJAX_Services.Return_Buildings_Jagged(textvalue,poptable,ErrorHandler,TimeOutHandler);
}
}
function deletetable(id)
{
 var d = document.getElementById(id);
 if(d.firstChild != null)
 {
 d.removeChild(d.firstChild);
 }
}
function DoNav(theUrl)
{
  document.location.href = theUrl;
}
function poptable(result)
{

deletetable('mybox');

var ajax_div = document.getElementById('mybox'); 
var new_tr,new_td,another_td,link,another_link;
var new_table = document.createElement('table');
new_table.width = 270;
new_table.setAttribute('id','my_buildings_table');
new_table.className = 'hover_table';

var new_tbody = document.createElement('tbody');
var my_link;
var result_1 = result[0];
var result_2 = result[1];
var results_length = result_1.length;

for(var i = 0, len = results_length; i < len;++i)
    {
       my_link = 'http://www.bostoncondogroup.com/Condos/' + result_1[i] + ".aspx";
       new_tr = document.createElement('tr');
     
       new_tr.class_name = "buildings_row";
       new_tr.onclick = function(evt){DoNav(my_link);};
       new_td = document.createElement('td');
       new_td.className = 'hover_row'; 
       new_td.align = "left";
       link = document.createElement('a');
       link.href = my_link;
       link.appendChild(document.createTextNode(result_1[i]));
       another_link = document.createElement('a');
       another_link.href = my_link;
       another_link.appendChild(document.createTextNode(result_2[i]));
       another_td = document.createElement('td'); 
       another_td.className = 'hover_row';
       another_td.align = "left";
       new_td.appendChild(link);
       another_td.appendChild(another_link);
       new_tr.appendChild(new_td);
       new_tr.appendChild(another_td);
       new_tbody.appendChild(new_tr);
           
    }
    new_table.appendChild(new_tbody);
    ajax_div.appendChild(new_table);
}

function hide_visibility(id) {
var e = document.getElementById(id);
e.style.display = 'none';
}

function show_visibility(id)
{
var e = document.getElementById(id);
e.style.display = 'block';
}

function reset_box(id)
{
var e = document.getElementById(id);
e.value = '';
}

function populate_box(id, value)
{
var e = document.getElementById(id);
e.value = value;
}

function ErrorHandler(result)
{
   var msg=result.get_exceptionType() + "\r\n";
   msg += result.get_message() + "\r\n";
   msg += result.get_stackTrace();
   //alert(msg);
}
function TimeOutHandler(result)
{
   //alert("Timeout :" + result);
}

//This is part of the animation javsacript, written by Microsoft

function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
       top.style.height = bottom.offsetHeight + 'px';
       top.style.width = bottom.offsetWidth + 'px';
     }
}


//Modal Popup
function okScript() {
        msg = 'ok';
}
    
function cancelScript() {
        msg = 'cancel';
}

function fnClickOK(sender, e) { 
__doPostBack(sender,e); 
}


//This will hide a table cell and expand another
function collapse_cell(id,other_id)
{
    var etd = document.getElementById('BCGMaptd');
    var this_id = document.getElementById(id);
   
    var width='0';
    var e = document.getElementById(other_id);
    
    if(e.style.width == "740px")
    {
        
        etd.colSpan = 1;
        width = '550px';
        show_visibility(id);
        this_id.width = 225;
        
    }
    else
    {
    
        etd.colSpan = 3;
        hide_visibility(id);
        width = '740px';
    }
    expand_div(other_id,width,'350px');

}

//This will expand a div
function expand_div(id,width,height)
{
var e = document.getElementById(id);
e.style.width = width;
e.style.height = height;
}