﻿function ConfigurePrintPreviewStylesheet(sheetId, bIsStaticForm) {
	/*var cssPreview = document.getElementById("ctl00_" + sheetId);
	//alert(cssPreview.href);
	if (cssPreview != null) {
		cssPreview.disabled = (window.location.search.indexOf("PrintPreview") == -1);
		if (!cssPreview.disabled) window.setTimeout("print();", 250);
		cssPreview = null;
	}*/
	
	if (window.location.search.indexOf("PrintPreview") > -1 && !IsChromeBrowser()) {
		var name = (bIsStaticForm ? sheetId : "ctl00_" + sheetId)
		var ss = document.styleSheets[name];
		if (ss != null) {  // IE
			if (ss.media == "print") { ss.media = ""; }
		}
		else {  // Non-IE
			var item = null;
			for (var i=0; i < document.styleSheets.length; i++) {
				item = document.styleSheets.item(i);
				if (item.title == sheetId && item.media.mediaText == "print") {
					item.media.mediaText = "";
					ss = item;
					break;
				}
			}
			item = null;
		}
		if (ss != null) { window.setTimeout("print();", 250); }
	}
}

function IsChromeBrowser() {
	return (navigator.userAgent.toLowerCase().indexOf('chrome') > -1);
}

function IsProdSite() {
	return ("www.sentara.com" == window.location.hostname);
}

function OpenMap(address, mapUrl) {
	if (mapUrl == null) { mapUrl = "http://portal.sentara.com/mapping/DisplayMap.aspx"; }
	if (mapUrl.indexOf("?") > 0) {
		window.open(mapUrl + address, 'Map', 'width=750, height=550, status=yes, toolbar=no, top=20, left=20, resizable=yes, scrollbars=yes')
	}
	else {
		window.open(mapUrl + '?addressText='+address, 'Map', 'width=750, height=550, status=yes, toolbar=no, top=20, left=20, resizable=yes, scrollbars=yes')
	}
}

function SetPageContentTitle(title) {
	var div = document.getElementById('MpBCHTitle');
	if(div.childNodes.length > 0) {
		div.childNodes[0].innerHTML = title;
	}
}

function attachInputPrompt() {
	  $('input[type=text][title],input[type=password][title],textarea[title],select[title]').each(function(i){
	    if ( $(this).css('display') != 'none' && $(this).css('visibility') != 'hidden' ) {
		    $(this).addClass('input-prompt-' + i);
		    var promptSpan = $('<span class="input-prompt"/>');
		    $(promptSpan).attr('id', 'input-prompt-' + i);
		    $(promptSpan).append($(this).attr('title'));
		    $(promptSpan).click(function(){
		      $(this).hide();
		      $('.' + $(this).attr('id')).focus();
		    });
		    if($(this).val() != ''){
		      $(promptSpan).hide();
		    }
		    $(this).before(promptSpan);
		    $(this).focus(function(){
		      $('#input-prompt-' + i).hide();
		    });
		    $(this).blur(function(){
		      if($(this).val() == ''){
		        $('#input-prompt-' + i).show();
		      }
		    });
		}
	  });
}


if (typeof _spBodyOnLoadFunctionNames == 'undefined') {
	$(document).ready(attachInputPrompt);
}
else {
	_spBodyOnLoadFunctionNames.push('attachInputPrompt');
}
