

// START Image and background insertion scripts


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
String.prototype.qtrim = function() {
	return this.replace(/“/,"");
}

function insertFlare() {
	//find all blockquotes and insert letter background
	quotes = document.getElementsByTagName('blockquote');
	for (i = 0; i < quotes.length; i++) {
		letter = quotes[i].innerHTML.trim().qtrim().substring(0,1).toLowerCase();
		quotes[i].style.background = "url(http://www.ambhealthsys.com/images/block_"+letter+".gif) no-repeat";
	}
	
	//inspect all elements in content div, and if last valid element is not a list, image, form, or blockquote, and ends with a period, insert tag image
	if(document.getElementById('notag') == null){//check for 'notag' id first -- cancels function
		//
		var lastelement = null;
        elements = document.getElementById('content').childNodes;
		myString = new String("m")
	  
		for(i=elements.length-1; i>=0; i--){ 
			if(elements[i].tagName == "OL" || elements[i].tagName == "UL" || elements[i].tagName == "BLOCKQUOTE" || elements[i].tagName == "FORM" || elements[i].tagName == "DIV" || elements[i].tagName == "A"){
				break;
			}else if((elements[i].nodeType == 1 && elements[i].tagName != "IMG") || (elements[i].nodeType == 3 && elements[i].nodeValue.lastIndexOf('.') != -1)){
				lastelement = elements[i];
				break;
			}
		}
		if(lastelement != null){
			if(lastelement.nodeType == 1){
				lastelement.innerHTML += ' <img src="http://www.ambhealthsys.com/images/copy_closer.gif" />';
			}else if(lastelement.nodeType == 3){
				var newimg = document.createElement('img');
				newimg.setAttribute("src","http://www.ambhealthsys.com/images/copy_closer.gif");
				document.getElementById('content').appendChild(newimg);
			}
		}
	}
}

// END Image and background insertion scripts

// START Top Nav Rollover Scripts
function rollover(myId,mySwitch) {
	myDiv = document.getElementById(myId).childNodes;
    mySpan = myDiv[0];
    
	if(mySwitch == "On"){
        mySpan.style.backgroundPosition = "top right";
    }else if(mySwitch == "Off"){
        mySpan.style.backgroundPosition = "top center";  
    }
}
// END Top Nav Rollover Scripts

// START Drop Down Menus

ns4 = (document.layers)? true:false;
ie4 = (document.all)? true:false;
myTimeOut = 400;
var myLast = null;

function show(id) {
	if (myLast != null && myLast != id){
		hide2(myLast);
	}
	myLast = id;
	
    if (id == "dropdown_about_us"){									clearTimeout(timeoutID1)}
	else if (id == "dropdown_a_new_approach"){						clearTimeout(timeoutID2)}
	else if (id == "dropdown_our_communities"){						clearTimeout(timeoutID3)}
	else if (id == "dropdown_for_families___potential_residents"){	clearTimeout(timeoutID4)}
	else if (id == "dropdown_for_healthcare_professionals"){		clearTimeout(timeoutID5)}
	else if (id == "dropdown_news"){								clearTimeout(timeoutID6)}
	else if (id == "dropdown_careers"){								clearTimeout(timeoutID7)}
	else if (id == "dropdown_contact_us"){							clearTimeout(timeoutID8)}

	if (ns4) document.layers[id].visibility = "show"
	else if (ie4) document.all[id].style.visibility = "visible"
	else if(!document.all && document.getElementById) document.getElementById(id).style.visibility = "visible"
}

var timeoutID1 = 0
var timeoutID2 = 0
var timeoutID3 = 0
var timeoutID4 = 0
var timeoutID5 = 0
var timeoutID6 = 0
var timeoutID7 = 0
var timeoutID8 = 0

function hide(id) {
	if (id == "dropdown_about_us"){									timeoutID1 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_a_new_approach"){						timeoutID2 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_our_communities"){						timeoutID3 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_for_families___potential_residents"){	timeoutID4 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_for_healthcare_professionals"){		timeoutID5 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_news"){								timeoutID6 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_careers"){								timeoutID7 = setTimeout("hide2('"+id+"')",myTimeOut)}
	else if (id == "dropdown_contact_us"){							timeoutID8 = setTimeout("hide2('"+id+"')",myTimeOut)}
}

function hide2(id) {
	if (ns4) document.layers[id].visibility = "hide"
	else if (ie4) document.all[id].style.visibility = "hidden"
	else if(!document.all && document.getElementById) document.getElementById(id).style.visibility = "hidden"
}

// END Drop Down Menus

// START Telescoping Functions

function showItem(id) {
	document.getElementById("item"+id).className = "itemList_expanded";
	document.getElementById("plus"+id).className = "hideBtn";
	document.getElementById("minus"+id).className = "showBtn";
}
function hideItem(id) {
	document.getElementById("item"+id).className = "itemList_collapsed";
	document.getElementById("plus"+id).className = "showBtn";
	document.getElementById("minus"+id).className = "hideBtn";
}

// END Telescoping Functions


/*
Some additional JavaScript
*/

function printArticle() {
	if (window.print) {
		setTimeout('window.print();', 333);
	}
	else if (agt.indexOf("mac") != -1) {
		alert("Press 'Cmd+p' on your keyboard to print article.");
	}
	else {
		alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}

function open_print(gohere) {
    window.open(gohere, "print", config="height=400,width=600,scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,top=0,left=0")
}

function open_email(gohere) {
    window.open(gohere, "email", config="height=475,width=500,scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,top=0,left=0")
}

function open_faq(gohere) {
    window.open(gohere, "faq", config="height=475,width=500,scrollbars=yes,toolbar=no,menubar=yes,resizable=yes,top=0,left=0")
}

function confirmSubmit() {
    var agree=confirm("Do you really want to mark this prospect as in the database?");

    if (agree) return true ;
    else return false ;
}

function toggle_display(display_area) {
    if (document.getElementById(display_area)) { 
        var display_element = document.getElementById(display_area);
        display_element.style.display = display_element.style.display == "none" ? "block":"none"; 
    }
}

function show_block(block)
{
	//alert(block);
	document.getElementById(block).style.display = "block";
}

function open_me(gohere)
{
	window.open(gohere, "popup", config="width=475,height=450,scrollbars=yes,toolbar=no,menubar=yes,resizable=no,top=0,left=0");
}

function printMe(gohere)
{
	window.open(gohere, "print", config="width=600,height=450,scrollbars=yes,toolbar=no,menubar=yes,resizable=no,top=0,left=0");
}
function emailMe(gohere)
{
	window.open(gohere, "print", config="width=600,height=450,scrollbars=yes,toolbar=no,menubar=yes,resizable=no,top=0,left=0");
}