var MySiteDomain = "lifepin.lifeguard30.com";
var exit = false;
var exceptions = new Array();
exceptions.push('profile_manage.php');
exceptions.push('account_home.php');
exceptions.push('profile_sections.php');
exceptions.push('profile_history.php'); 
exceptions.push('printout.php'); 
exceptions.push('medications.php'); 
exceptions.push('allergies.php');
exceptions.push('immunizations.php');
exceptions.push('preview.php'); 
exceptions.push('medical_conditions.php');
exceptions.push('lifepin_review.php'); 


var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
/*	HTMLElement.prototype.click = function() {
	var evt = this.ownerDocument.createEvent('MouseEvents');
	evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
	this.dispatchEvent(evt);
	}*/ 
function HandleEvents(target,eventName,handlerName) {
  if ( target.addEventListener ) {
    target.addEventListener(eventName, function(e){target[handlerName](e);}, false);
  } else if ( target.attachEvent ) {
    target.attachEvent("on" + eventName, function(e){target[handlerName](e);});
  } else {
    var originalHandler = target["on" + eventName];
    if ( originalHandler ) {
      target["on" + eventName] = function(e){originalHandler(e);target[handlerName](e);};
    } else {
      target["on" + eventName] = target[handlerName];
    }
  }
}
function is_exception()
{
	var page_arr = document.location.href.split('/');
	var filename = page_arr[page_arr.length-1];
	if(filename.indexOf("?")>=0)
	{
		var tmp_arr = filename.split('?');
		filename = tmp_arr[0];
	}

	for(var myfile in exceptions)
	{
		if(exceptions[myfile] == filename)
		{
			return true;
		}
	}
	
	return false;
}
function warn()
{
	/*if(exit && !hasSaved && !is_exception())
	{
		var answer = confirm("You have not saved your most recent changes, if you would like to do so please select 'cancel' and press the save button.");
		if(!answer){ alert("Cancel Load"); return false; }	
	}
	*/
}
function InternalLink(url)
{
	if(!is_exception() && exit)
	{
	if(hasSaved)
	{
		document.location.href=url; 
	}	
	else
	{
		var answer = confirm("You have not saved your most recent changes! To do so, click 'OK' to save or Cancel to proceed without saving.");
		if(answer){  	
			document.getElementById('autosave').value = '1';
			document.forms[0].submit();
		}
		else
		{
			document.location.href=url; 
		}
	}
	}
	else
		document.location.href=url; 
}

function LinkConvert()
{
	if(is_exception()){ return false; }
	var inputs = document.getElementsByTagName('input');

	for(var y=0; y<inputs.length; y++)
	{
		inputs[y].clickhandler= function(){ exit=true; }; 
		HandleEvents(inputs[y],"change","clickhandler");
	}
	var anchors = document.getElementsByTagName('a');
	for(var y=0; y<anchors.length; y++)
	{
		if(anchors[y].href.indexOf("javascript:") == -1)
		{	
			var href = anchors[y].href;	
			anchors[y].href = "javascript:InternalLink('"+href+"');";	
			/*anchors[y].clickhandler= function(){ 
					var answer = confirm("You have not saved your most recent changes, if you would like to do so please select 'cancel' and press the save button.");
					if(!answer){  return false; }	
					else{ document.location.href=anchors[y].href; }
				}; 
			HandleEvents(anchors[y],"click","clickhandler");
			*/	
		}
	}
}
LinkConvert();

