//Make sure nobody frames us//
if(top.location.href != document.location.href) {
 top.location.replace(document.location.href);
}

//Determine Where we are for dynamic linking//
var httpExp = /^http/i;
if(httpExp.test(location.href)) {
 var rootExp = /^(https?:\/\/[^\/]+\/)\??(.*[^\/]+(\.html)?.*$3?.*$3?.*)$/i;
 var domExp = /^https?:\/\/w{0,3}\.?([^\/]+)\/?$/;
} else {
 var rootExp = /^(.+\/pointmedical\.com\/)\??(.*[^\/]+(\.html)?.*$3?.*$3?.*)$/i;
 var domExp = /^.+\/(pointmedical\.com)\/?$/;
}
var root = (location.href).replace(rootExp,"$1");
var endURL = (location.href).replace(rootExp,"$2");
var myDomain = root.replace(domExp,"$1");
//NOTE: 'domain' is a reserved word, thus 'myDomain'//

var mailNameAdmin		= 'Eric Harris';
var mailAliasAdmin		= 'webmaster';
var mailNameIntl		= 'Michael I. Basta';
var mailAliasIntl		= 'doreen';
var mailNameDom			= 'Frank DeBartola';
var mailAliasDom		= 'fdebartola';
var mailNameCs			= 'Biljana Kajmakoski';
var mailAliasCs			= 'bkajmakoski';
//var mailNameDefault		= 'Kristie Hanlon';
//var mailAliasDefault	= 'khanlon';
var mailNameDefault		= mailNameCs;
var mailAliasDefault	= mailAliasCs;
var emailExp		= /^[\w.-]{2,}\@[\w.-]{2,}\.([a-z]{2,3}|aero|arpa|coop|info|museum|name)$/
var emptyExp		= /^\s*$/;		// for client-side validation of form fields
var onload_list		= new Array();
var onscroll_list	= new Array();
var onresize_list	= new Array();


//Which browser are we using?//
var Netscape = false; var IE = false;
if(navigator.appName == 'Netscape') {
 Netscape = true;
} else {
 IE = true;
	document.write('<META HTTP-EQUIV="imagetoolbar" CONTENT="no">');
	document.write('<meta name="MSSmartTagsPreventParsing" content="TRUE">');
}

document.oncontextmenu=function(){return false}



//document.write('<LINK REL="SHORTCUT ICON" HREF="../'+root+'favicon.ico">');
//document.write('<LINK REL="P3Pv1" HREF="../'+root+'w3c/p3p.xml">');
//document.write('<META NAME="ROBOTS" CONTENT="NOARCHIVE">');

window.defaultStatus = "Point Medical";
function display(message) {
	if(Netscape) {
	 netStatus();
	 if(document.child_window) { document.child_window.focus() }
	}
 window.status = "Point Medical     " + message;
}

if(Netscape) {
 netStatusRun = false;
 function netStatus() {
	 if(netStatusRun) { return }
		for(i=0; i<document.links.length; i++) {
		 document.links[i].onmouseout = function(){ window.status = '' }
		}
		netStatusRun = true;
	}
}

function nav(x) {
 document.location = root + x;
}

var emailExp = /^[\w\-\.]+\@[\w\-\.]+\.[\w\-\.]+$/;
function mail(name,email,subject,cc) {
 var page = document.location;
	if(email && !emailExp.test(email)) { email += '@'+myDomain }
	if(cc && !emailExp.test(cc)) { cc += '@'+myDomain }
 nav('cgi-bin/mail/emailer.cgi?compose=1&to_name='+ name +'&to_email='+ email +'&subject='+ subject +'&cc='+ cc);
}


//////////////////////////////////////////////////////////////////////////
// Write-in email links dynamically so email-harvesting spiders can't	//
// get them from the source code. Call with in-line script tag:			//
// document.write( write_email_link('name','alias' [,'emailDomain']) );	//
//////////////////////////////////////////////////////////////////////////
function write_email_link(name, alias, emailDomain, subject, cc, style) {
	name		= (name == undefined || name == '')?				mailNameAdmin	: name;
	alias		= (alias == undefined || alias == '')?				mailAliasAdmin	: alias;
	emailDomain = (emailDomain == undefined || emailDomain == '')?	myDomain		: emailDomain;
	subject		= (subject == undefined)?							''				: subject;
	cc			= (cc == undefined)?								''				: cc;
	style		= (style == undefined)?								'reg'			: style;
	var atOffsiteDomain = '';
	if(emailDomain != myDomain) {
		atOffsiteDomain = '@'+ emailDomain;
	}
	return	'<a href="javascript:mail(\''+ name +'\',\''+ alias + atOffsiteDomain +'\',\''+
			subject +'\',\''+ cc +'\');" title="'+ alias +'@'+ emailDomain +
			'" class="'+ style +'">' +
			alias +'@'+ emailDomain +'</a>';
}


function mailPage() {
 var deadloop = /mail_page\.cgi$/i; //Don't mail the mail_page page!//
 if(!deadloop.test(document.location) && httpExp.test(document.location)) {
		document.invis_mail_page.submit();
	}
}
//////////////////////////////////////////
// invisible form for function mailPage //
with(document) {
 write('<form name="invis_mail_page" method="POST" action="../'+root+'cgi-bin/mail/mail_page.cgi">');
	write('<input type="hidden" name="page" value="' + document.location + '">');
	write('<input type="hidden" name="page_name" value="' + document.title + '">');
	write('<input type="hidden" name="evaluate" value="1">');
	write('</form>');
}

var child_window;
function small_window(path,x,y) {
	var centerV = screen.height / 3;
 var centerH = screen.width / 3;
	path = root + path.replace(/™/,"(TM)");
	if(x > 0 && y > 0) {
	 centerV = (screen.height / 2) - (y / 2);
		centerH = (screen.width / 2) - (x / 2);
	 top.child_window = window.open(path,"small_window",config='height='+y+',width='+x+',left='+centerH+',top='+centerV+'');
	} else {
  top.child_window = window.open(path,"small_window",config='height=100,width=300,left='+centerH+',top='+centerV+'');
	}
}


//////////////////////////////////
// Document event handlers::	//
//////////////////////////////////
onload = function() {
	for(var loadIndex=0; loadIndex<=onload_list.length; loadIndex++) {
		eval(onload_list[loadIndex]);
	}
	afterLoad();	//Special onLoad functions to execute after all the rest//
}

onscroll = function() {
	for(var scrollIndex=0; scrollIndex<=onscroll_list.length; scrollIndex++) {
		eval(onscroll_list[scrollIndex]);
	}
}

onresize = function() {
	for(var resizeIndex=0; resizeIndex<=onresize_list.length; resizeIndex++) {
		eval(onresize_list[resizeIndex]);
	}
}

/*if(IE) {
	onfocus = function(){
		//this allows IE to focus on a form fields in the popup window
		//unlike using "onblur=focus()" in the popup
		if(typeof(top.childWindow.document) == 'object') {
			top.childWindow.focus();
		}
	}
}*/
	//////////////////////////////////////////////////////////////////////////////////////////
	// DOCUMENT EVENT HANDLER NOTES::														//
	//////////////////////////////////////////////////////////////////////////////////////////
	// The on*_list arrays are global lists of functions to be called by their respective	//
	// window event handlers. Functions were previously added to handlers by scripts on		//
	//		each page like so:																//
	//		onload2 = onload;																//
	//		onload = function() { onload2(); cutomFunction1(); cutomFunction2(); }			//
	// This would eventaully cause a "stack overflow" because of the recursion involved		//
	// when this code appeared in multiple scripts imported into a single HTML page. Now	//
	// calls like onload_list.push('commands;'); are used by each page to control the flow.	//
	// Note: Any function with a for loop will keep the remaining calls in its on*_list		//
	// array from executing IF a globally-scoped i variable is used, as is the norm. In		//
	// such a case use: on*_list.unshift('func'); to add functions to the end of the list.	//
	//////////////////////////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////////////////////
// Execute these commands at the end of all other onLoad functions (onload_list). //
////////////////////////////////////////////////////////////////////////////////////
function afterLoad() {
	
	//Make all document links display their title attributes in the status bar//
	for(var i=0; i<document.links.length; i++) {
		if(document.links[i].title) {
			var otherOvers = document.links[i].onmouseover;
			if(otherOvers == undefined) { otherOvers = 'void(1);' }
			if(otherOvers.toString().indexOf('function') < 0) { otherOvers = function(){otherOvers} }
			document.links[i].mouseover2 = otherOvers;
			document.links[i].onmouseover = function(){
				setNetscapeEvent(1);
				this.mouseover2();
				display(this.title);
				return true;
			};
			
			if(Netscape) {//needs a mousout event to clear the status bar
				var otherOuts = document.links[i].onmouseout;
				if(otherOuts == undefined) { otherOuts = 'void(1);' }
				if(otherOuts.toString().indexOf('function') < 0) {
					eval('otherOuts = function(){'+otherOuts+'}');
				}
				//otherOuts = otherOuts.toString().replace(/^[^{]+\{([^}])\}.*$/,"$1");
				document.links[i].mouseout2 = otherOuts;
				document.links[i].onmouseout = function() {
					setNetscapeEvent(1);
					this.mouseout2();
					window.status = window.defaultStatus;
					//'alert('+otherOuts+');
					return true;
				};
			}
		}
		
		var otherFocus = document.links[i].onfocus;
		if(otherFocus == undefined) { otherFocus = 'void(1);' }
		if(otherFocus.toString().indexOf('function') < 0) { otherFocus = function(){otherFocus} }
		document.links[i].focus2 = otherFocus;
		document.links[i].onfocus = function(){
			this.focus2();
			this.blur();
		};
		
	}
	//END fixing links//
	
	//Take the focus off of form buttons & checkboxes
	for(var i=0; i<document.forms.length; i++) {
		var myForm = document.forms[i];
		for(var j=0; j<myForm.elements.length; j++) {
			var myObj = myForm.elements[j];
			if(myObj.type == 'submit' || myObj.type == 'reset' || myObj.type == 'button' ||
			   myObj.type == 'radio' || myObj.type == 'checkbox') {
				var otherFocus = myObj.onfocus;
				if(otherFocus == undefined) { otherFocus = 'void();' }
				if(otherFocus.toString().indexOf('function') < 0) {
					otherFocus = function(){otherFocus}
				}
				myObj.focus2 = otherFocus;
				myObj.onfocus = function(){
					this.focus2();
					this.blur();
				};
			}
		}
	}
	//END de-focusing buttons//
}

//////////////////////////////////////////////////////////////////////////////////
// The regexps in the object checkFieldTest are to exclude certain characters.	//
// The function is called in the onKeyUp or a similar handler from form fields.	//
//////////////////////////////////////////////////////////////////////////////////
var checkFieldTest = {
	numDigits2	: {replacer: /\D|^(\d{2}).+/g, checker: /\D|^\d{2}.+/},
	numbers		: {replacer: /\D()/g, checker: /\D/},
	noquotes	: {replacer: /["']()/g, checker: /['"]/},
	username	: {replacer: /\W|^[^A-z]+()/g, checker: /\W|^[^A-z]+/},
	email		: {replacer: /[^\w@\-.]()/g, checker: /[^\w@\-.]/} /*|([@\-.])[@\-.]+|^[_@\-.]+/g,
	cc			: /[^\w@\-.,;\s]|([@\-.,;\s])[@\-.,;]+|^[_@\-.,;\s]+/g*/
}
function checkField(field, checkset) {
	checkset = (checkset == undefined)? field.name : checkset;
	var checkExp = eval("checkFieldTest."+checkset+".replacer");
	var newValue = field.value.replace(checkExp, "$1");
	//field.value = field.value.replace(checkExp, "");
	/*if(checkset == 'cc') {	// let the cursor jump to the end of multiple spaces //
		newValue = newValue.replace(/(\s)\s+/, "$1");
	}*/
	
	checkExp = eval("checkFieldTest."+checkset+".checker");
	//Do all this nonesense to make sure the cursor ends up in the same position it started
	if(field.setSelectionRange) { //Netscape
		var caretPosition = field.selectionStart;
		if(checkExp.test(field.value)) { caretPosition-- }
		field.value = newValue;
		field.setSelectionRange(caretPosition, caretPosition);
	} else if(field.createTextRange) { //IE
		//Get cursor position via empty selection range
		var sel = document.selection.createRange();
		//Move selection start to 0 position
		sel.moveStart ('character', -field.value.length);
		//The caret position is selection length
		var caretPosition = sel.text.length
		if(checkExp.test(field.value)) { caretPosition-- }
		field.value = newValue;
		sel.collapse();
		sel.move('character', caretPosition);
		sel.select();
	}
	
}


//////////////////////////////////////////////////////////////////////////////////////////
// Toggle a form field between blank space and some default guide text, like "(email)".	//
// Fields that call this should do so with both onFocus AND onBlur handlers, and have	//
// starting/default values that match the value of guideText, the second argument.		//
//////////////////////////////////////////////////////////////////////////////////////////
function emptyField(field, guideText) {
	if(field.value == guideText) {
		field.value = '';
	} else if(emptyExp.test(field.value)) {
		field.value = guideText;
	}
}

