//Removes "Click to activate and use this control" issue that exists when using Flash objects (and any other objects?)
function removeDoubleClick()
{
	theObjects = document.getElementsByTagName("object");
	
	for (var i = 0; i < theObjects.length; i++) 
	{
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}
}

//Redirect user to the selected page
function showSelectedPage()
{
	document.location.href=document.form.pageSelection.options[document.form.pageSelection.selectedIndex].value;	
}

//validates the input on the ask a question form
function validateInput(form)
{
	if ( trim(form.name.value).length < 1 ) 
  {
    alert( "Please enter your name so that we can get back to you with an answer to your question." );
    return false;
  }
  if ( trim(form.contact.value).length < 1 ) 
  {
    alert( "Please enter your email address or phone number so that we can get back to you with an answer to your question." );
    return false;
  }
  if ( trim(form.message.value).length < 1 ) 
  {
    alert( "Please enter your question or message." );
    return false;
  }

  return true;
}


//Opens an html page in a printer friendly version and pops up the print window at the same time
function openForPrinting()
{ 
	var display_setting="toolbar=yes, location=no, directories=no, menubar=yes,"; 
    	display_setting+="scrollbars=yes, width=800, height=600, left=50, top=5"; 
  
	var print_content=document.getElementById("print-content").innerHTML; 
  	var new_page_title=document.title;
  
  	var popup_window=window.open("","",display_setting); 
   	popup_window.document.open(); 
   	popup_window.document.write('<html><head>');
   	popup_window.document.title=new_page_title;
   	popup_window.document.write('<link href="/styles-main.css" type="text/css" rel="stylesheet" />');
	popup_window.document.write('<link href="/styles-pages.css" type="text/css" rel="stylesheet" />');
   	//popup_window.document.write('<link href="http://www.hoyes.com/blog_styles.css" type="text/css" rel="stylesheet" />');
	popup_window.document.write('</head><body onload="self.print()">');          
   	popup_window.document.write('<p class="print-window-comment">Make a Plan: Call <i>Hoyes Michalos &amp; Associates Inc.</i> at <b>310-PLAN</b> today and arrange for a free initial consultation.</p>');
   	popup_window.document.write(print_content);
   	popup_window.document.write('</body></html>'); 
   	popup_window.document.close(); 		//closes the document for writing
   	popup_window.focus(); 
}

function popupDirections(windowName)
{
	var display_setting="toolbar=yes, location=yes, directories=yes, menubar=yes,"; 
    	display_setting+="resizable=yes, scrollbars=yes, width=900, height=700, left=100, top=0"; 
	
	window.open("", windowName, display_setting);
}

//removes leading and trailing spaces in the string passed in.
function trim( string_to_trim )
{ 
  while (string_to_trim.charAt(0) == " ")
  { 
    // remove leading spaces 
    string_to_trim = string_to_trim.substring(1); 
  } 
  
  while (string_to_trim.charAt(string_to_trim.length - 1) == " ")
  { 
    // remove trailing spaces 
    string_to_trim = string_to_trim.substring(0,string_to_trim.length - 1); 
  } 
  
  return string_to_trim; 
} 

//show div passed in
function showControl(controlId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(controlId).style.visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[controlId].style.visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[controlId].visibility = "visible";
		document.getElementById(controlId).style.display = "block"; 
	}
}

//hide div passed in
function hideControl(controlId)
{
	if (document.getElementById)
	{
		// this is the way the standards work
		document.getElementById(controlId).style.visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
	else if (document.all)
	{
		// this is the way old msie versions work
		document.all[controlId].style.visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
	else if (document.layers)
	{
		// this is the way nn4 works
		document.layers[controlId].visibility = "hidden";
		document.getElementById(controlId).style.display = "none"; 
	}
}

// delaying the print pop-up window to give time Google maps to load first
var timer;

function loopTillPrintAnchorShows() {
	//alert("test before if and before print");
	if (document.getElementById("end")) {
		//alert("test after if, before print");
		window.print();
		clearInterval(timer);
	}    
}

function delayPrint()
{
	timer = setInterval('loopTillPrintAnchorShows()', 2000);
}


//brings up the "email page to a friend" window
function emailToFriend( )
{
	var url=document.URL; 
	var popupwindowurl = "http://www.hoyes.com/email-to-friend.php?url="+url; 
	window.open(popupwindowurl,'','scrollbars=no,resizable=no,width=440,height=340');
}



function validate_email_friend (form)
{	
	if ( form.sender_name.value.length < 1 ) 
	{
		alert( "Please enter your name." );
		form.sender_name.focus();
		return false;
	}

	if ( form.receiver_name.value.length < 1 ) 
	{
		alert( "Please enter the receiver's name." );
		form.receiver_name.focus();
		return false;
	}

	if ( form.receiver_email.value.length < 1 ) 
	{
		alert( "Please enter the receiver's email address." );
		form.receiver_email.focus();
		return false;
	}

	return true;
}

//Add to Favourites window
function bookmarkPage( ) 
{
	var url=document.URL;
	var title=document.title;
	
	if (window.sidebar) // firefox
	{ 
		window.sidebar.addPanel(title, url,"");
    }
	else if (document.all)  // IE
	{
		window.external.AddFavorite(url, title);
    }
	else
	{
    	return true;
	}
	
	/*
	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) 
	{
		var url=document.URL;
		var title=document.title;

		window.external.AddFavorite(url,title);
	}
	else 
	{
		var msg = "Please press CTRL+D to add a bookmark to this site";

		if(navigator.appName == "Netscape")
		{
			alert(msg);
		}
	}
	*/
}

function validateSearch(form)
{
	if ( trim(form.q.value).length < 1 ) 
	  {
		alert( "Please enter your search keyword/phrase." );
		return false;
	  }
	
	return true;
}

// ADDTHIS BUTTON to index page
function addit_index()
{
	
addthis_pub             = 'hoyes'; 
addthis_logo            = 'http://www.hoyes.com/images/addit.gif';
addthis_logo_background = 'EFEFFF';
addthis_logo_color      = '666699';
addthis_brand           = 'Hoyes.com';
addthis_options         = 'favorites, email, myspace, facebook, google, live,delicious, digg,technorati,myweb,ask,twitter,more';

document.write("<a href='http://www.addthis.com/bookmark.php' onmouseover=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onmouseout='addthis_close()' onclick='return addthis_sendto()'><img src='http://www.hoyes.com/images/addit.gif'  height='16' border='0' alt='' /></a>");

}

// ADDTHIS BUTTON to other page
function addit_button()
{
	
addthis_pub             = 'hoyes'; 
//addthis_logo            = 'http://www.hoyes.com/images/addthis_button.gif';
addthis_logo            = 'http://www.hoyes.com/images/addit.gif';
addthis_logo_background = 'EFEFFF';
addthis_logo_color      = '666699';
addthis_brand           = 'Hoyes.com';
addthis_options         = 'myspace, facebook, google, live,delicious, digg,technorati,myweb,ask,twitter,more';
document.write("<div class='addthisbutton'>");
//document.write("<a href='http://www.addthis.com/bookmark.php' onmouseover=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onmouseout='addthis_close()' onclick='return addthis_sendto()'><img src='http://www.hoyes.com/images/addthis_button.gif'  height='16' border='0' alt='' /></a>");
document.write("<a href='http://www.addthis.com/bookmark.php' onmouseover=\"return addthis_open(this, '', '[URL]', '[TITLE]')\" onmouseout='addthis_close()' onclick='return addthis_sendto()'><img src='http://www.hoyes.com/images/addit.gif'  height='16' border='0' alt='' /></a>");
document.write("</div>");
}