// ===================================================================
// Default
// This is the default javascript file for mainelistings.com
// Contains js functions that are used for pages throughout the site
// Any js functions that are custom for a particular page are included 
// in the files LOCAL _js folder
//
// Author: Jason Pierce, MREIS
// Last Modified: 9/20/2010 by Jason Pierce
// ===================================================================

// Breaks out of frames so that the mainelistings site cannot be framed
function frame_away()
{
//dont frame the entire mainelistings site please
//  if (parent.frames.length > 0)
if(window != top)
  {
    top.location.href = location.href;
  }
}
// Hide the loading gif/text
function hideLoading(){
  if(document.all("span_loading")){
    document.all("span_loading").style.visibility = "hidden";
    document.all("span_loading").style.position = "absolute";
  }
}
//Controls background colors for when the user places their mouse over TABLE ROWS
function row_over_silver(el){
  el.className="tr_silver";
}
function row_over_blue(el){
  el.className="tr_blue";
}
function row_out(el){
  el.className="tr_plain";
}
function row_over_full_blue(el){
  el.className="tr_full_blue";
}

//Controls background colors for when the user places their mouse over FIELDSETS
function fieldset_over(el, lgd){
  el.style.border='1px solid #0371b0';
  document.getElementById(lgd).style.color='#0371b0';
}
function fieldset_out(el, lgd){
  el.style.border='1px solid silver';  
  document.getElementById(lgd).style.color='#000000';
}  
//function for opening links in a new window, pdf's should always be opened in a new window
function change_page(lnk){
  if(lnk.indexOf('http://')==-1 && lnk.indexOf('.pdf')==-1){
    window.location = lnk;
  }
  else{
    window.open(lnk, '', 'fullscreen=yes, scrollbars=1');
  }
}
//Controls background colors for when the user places their mouse over SPANS
function span_link_over(el){
  el.className="link_over";
}
function span_link_out(el){
  el.className="link_out";
}
//	MLXChange Access Counter
//	Used for new users who login to MaineListings for the first time, lets them know when they 
//	will be able to access MLXchange
function mlx_countdown(start){
	window.start = parseFloat(start);
	var end = 0 // change this to stop the counter at a higher value
	var refresh=1000; // Refresh rate in milli seconds
	if(window.start >= end ){
		mytime=setTimeout('set_mlx_counter()',refresh)
	}
	else {
		document.getElementById('mlx_counter').style.color='green';
		document.getElementById('mlx_counter').innerHTML = "You can now access MLXchange <a href='http://mreis.mlxchange.com' target='_blank'>click here</a>!";
	}
}
//86400
function set_mlx_counter() {
	// Calculate the number of days left
	var days=Math.floor(window.start / 86400); 
	// After deducting the days calculate the number of hours left
	var hours = Math.floor((window.start - (days * 86400 ))/3600)
	// After days and hours , how many minutes are left 
	var minutes = Math.floor((window.start - (days * 86400 ) - (hours *3600 ))/60)
	// Finally how many seconds left after removing days, hours and minutes. 
	var secs = Math.floor((window.start - (days * 86400 ) - (hours *3600 ) - (minutes*60)))
	// Milliseconds
	var millisecs = Math.floor(secs/100);
	
	var x="You will have access to MLXchange in ";
	if(hours>0){
		x += hours + " Hours ";
	}
	if(minutes>0){
		x += minutes + " Minutes and ";
	}
	x += secs + " Seconds ";
	//var x = window.start + "(" + days + " Days " + hours + " Hours " + minutes + " Minutes and " + secs + "." + millisecs + " Seconds " + ")";
	
	document.getElementById('mlx_counter').innerHTML = x;
	window.start= window.start- 1;
	
	tt=mlx_countdown(window.start);
}
//window.location wrapper
function change_page(lnk){
window.location = lnk;
}

