sfHover = function() {
            var sfEls = document.getElementById("nav_left").getElementsByTagName("LI");
            for (var i=0; i<sfEls.length; i++) {
                    sfEls[i].onmouseover=function() {
                            this.className+=" sfhover";
                    }
                    sfEls[i].onmouseout=function() {
                            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                    }
            }
    }

    if (window.attachEvent) window.attachEvent("onload", sfHover);

    function swapImage(imgName,newImg) {
        if (document[imgName]) document[imgName].src = newImg;
    }       

function toggle(obj)
{
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		jQuery(el).slideUp(500);
	}
	else {
		jQuery(el).slideDown(500);
	}
}

function insideAccess()
{
	var n = $('name').value;
	var e = $('email').value;
	var p = $('phone').value;
	var c = $('comments').value;

	var pars = 'email=' + e + '&' +
				'name=' + n + '&' +
				'phone=' + p + '&'+
				'comments=' + c;

    	if (e.match(/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i))
    	{
    		new Ajax.Request('/new-york-city-property-developments/ajax/inside-access/index.php',
    		  {
    		    method:'post',
    		    parameters: pars,
    		    onSuccess: function(transport){
    		      var response = transport.responseText;
    		      if (!response)
    		      {
    		      	alert('A problem occurred.');
    		      	return false;
    		      }
    		      $('mail_list_content').innerHTML = response;
    		    },
    		    onFailure: function(){ alert('Something went wrong...') }
    		  });
    	}
    	else
    	{
    		alert('Please provide a valid email address.');
    		return false;
    	}
}


function save_building(building_id, click_link, event)
{	
	if (event.preventDefault) { event.preventDefault() };
	$('saveBuilding').style.left = (jQuery(click_link).offset().left - 1) + 'px';
	$('saveBuilding').style.top = (jQuery(click_link).offset().top + jQuery(click_link).height()) + 'px';
	$('saveBuilding').innerHTML = '<img src="/images/loading.gif"/>';
	$('saveBuilding').style.display = '';

	jQuery.ajax({
		type:'POST',	
		url:'/building-detail/ajax/save-building/',
		data:'b_id='+building_id,
		success: function(response) {
			$('saveBuilding').innerHTML = response;
			$('saveBuilding').style.display = '';
		},
		error: function(response) {
			alert('unable to save building');
		}	
	});
}

function get_email_updates(building_id)
{
	new Ajax.Request('/new-york-city-property-developments/ajax/email-updates/?building_id=' + building_id,
    		  {
    		    method:'GET',
    		    onSuccess: function(transport){
    		      var response = transport.responseText;
    		      if (!response)
    		      {
    		      	alert('There was a problem.');
    		      	return false;
    		      }
    		      alert(response);
    		    },
    		    onFailure: function(){ alert('Something went wrong...') }
    		  });
}

sfHover = function() {
            var sfEls = document.getElementById("nav_left").getElementsByTagName("LI");
            for (var i=0; i<sfEls.length; i++) {
                    sfEls[i].onmouseover=function() {
                            this.className+=" sfhover";
                    }
                    sfEls[i].onmouseout=function() {
                            this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                    }
            }
    }

    if (window.attachEvent) window.attachEvent("onload", sfHover);

    function swapImage(imgName,newImg) {
        if (document[imgName]) document[imgName].src = newImg;
    }
            
        
function closeFrame(iframe)
{
	document.location = $(iframe).src;
}
