//=== Handler for Javascript runtime errors.==============
function noErrorMessages () { return true; }

function handleMissingObjects() {
	alert("Current view mode is strictly for printing.");
	return true;
}

function handleError (err, url, line) {
  var strErrMsg = "Oops, an error occured on this page.";
  
      alert(strErrMsg + 
             '\nDescription: ' + err + 
             '\nURL: ' + url + 
             '\nLine Num: ' + line);
      return true; // error is handled
}
  //=== Put in one of these calls in the <head> tag.
    //Supress all error messages...
    //window.onerror = noErrorMessages;
    //window.onerror = customLocalfunctionCall;
    //Handle Errors
    //window.onerror = handleError;

//========================================================================================

function stripAnchor(strInput)	
 {	

		var strOutput = "";
		var rexpCrLf = /\r\n/g;
		var rexpHTML = /\<[^\>]+\>/g;
		var rexpAnchor = /\<a[\s]+[^\>]+\>([^<]+)\<\/a\>/g;
		
		//First off remove carriage returns and line feeds
		strOutput = strInput.replace(rexpCrLf, "");
		// Strip begining and ending anchor tags but leave text
		strOutput = strOutput.replace(rexpAnchor, "$1");
		
		//strOutput = strOutput.replace(rexpTest, "$2");
		// Replace all HTML tag matches with the empty string
		//strOutput = strInput.replace(rexpHTML, "");
		
			//alert(strOutput);
			return strOutput;
}
//============================================

var xOp7=false,xOp5or6=false,xIE4Up=false,xNN4=false,xUA=navigator.userAgent.toLowerCase();
if(window.opera){
  xOp7=(xUA.indexOf('opera 7')!=-1 || xUA.indexOf('opera/7')!=-1);
  if (!xOp7) xOp5or6=(xUA.indexOf('opera 5')!=-1 || xUA.indexOf('opera/5')!=-1 || xUA.indexOf('opera 6')!=-1 || xUA.indexOf('opera/6')!=-1);
}
else if(document.layers) {xNN4=true;}
else {xIE4Up=document.all && xUA.indexOf('msie')!=-1 && parseInt(navigator.appVersion)>=4;}

function xGetElementById(e) {
  if(typeof(e)!='string') return e;
  if(document.getElementById) e=document.getElementById(e);
  else if(document.all) e=document.all[e];
  else if(document.layers) e=xLayer(e);
  else e=null;
  return e;
}

function xDef() {
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function xShow(e) {
  if(!(e=xGetElementById(e))) {return;}
  if(e.style && xDef(e.style.visibility)) {
  		e.style.visibility='visible'; 
		e.style.display='block';
  }	
  else if(xDef(e.visibility)) {
  	e.visibility='show'; 
	e.display=''
  }	
}
function xHide(e) {
  if(!(e=xGetElementById(e))) {return;}
  if(e.style && xDef(e.style.visibility)) {
  		e.style.visibility='hidden'; 
		e.style.display='none';
  }
  else if(xDef(e.visibility)) {
  		e.visibility='hide'; 
		e.display='none';
  }
}

function xShowHide(e){
	if(!(e=xGetElementById(e))) {return;}
	if(e.style && xDef(e.style.visibility)) {	//IE
		if(e.style.visibility=='visible'){xHide(e)}
		else{xShow(e)}
	}
	else if(xDef(e.visibility)) {
		if(e.visibility=='show'){xHide(e)}
		else{xShow(e)}
	}
}

function xHideAll(arrObjDiv){
	if (arrObjDiv.length > 0){
			for(i=0;i < arrObjDiv.length; i++){
				xHide(arrObjDiv[i])
			}
	}
}
function xShowAll(arrObjDiv){
	if (arrObjDiv.length > 0){
			for(i=0;i < arrObjDiv.length; i++){
				xShow(arrObjDiv[i])
			}
	}
}
//=============================================
function cancelProcess(strRedirectPage)
{
	if(confirm("Are you sure you want to cancel this process?"))
	{
		window.location.href=strRedirectPage;
	}
}
//==============================================
/*
Used for form submission either via DOM or forms collection
Fred Scales
*/
function LockButtons(whichform) {
	var ua = new String(navigator.userAgent);
	var InputNode;
	var InputNodeName;
	if (ua.match(/IE/g)) {

		if(whichform == document.all)
		{
			var inputElements = document.all.tags("input");
			
			for (i=0; i<inputElements.length; i++) {
			//var InputText = inputElements[i].tagName;
				InputNode = inputElements.item(i);
				InputNodeName = InputNode.getAttribute('name');
				if(InputNodeName.toUpperCase() != 'BTNRESET'){	//Exempt for reset buttons
					if ((InputNode.getAttribute('type') == 'submit') || (InputNode.getAttribute('type') == 'button')) {
								InputNode.disabled = true;
					}
				}
			}
		}
		else{
		
			for (i=0; i<whichform.elements.length; i++) {
				InputNodeName = whichform.elements[i].name;
				if(InputNodeName.toUpperCase() != 'BTNRESET'){	//Exempt for reset buttons
					if ((whichform.elements[i].type == 'submit') || (whichform.elements[i].type == 'button')) {
						whichform.elements[i].disabled = true;
					}
				}
			}
		}
	}
	//whichform.submit();
}	

//============================================================================
function unLockButtons(whichform) {
	ua = new String(navigator.userAgent);
	if (ua.match(/IE/g)) {

		if(whichform == document.all)
		{
			var inputElements = document.all.tags("input");
			
			for (i=0; i<inputElements.length; i++) {
			var InputNode = inputElements.item(i);
			
				if ((InputNode.getAttribute('type') == 'submit') || (InputNode.getAttribute('type') == 'button')) {
							InputNode.disabled = false;
				}
			}
		}
		else{
			for (i=0; i<whichform.elements.length; i++) {
				if ((whichform.elements[i].type == 'submit') || (whichform.elements[i].type == 'button')) {
					whichform.elements[i].disabled = false;
				}
			}
		}
	}

}	
//============================================================================
function trim(strText)
	{
		//this will get rid of leading spaces
		while (strText.substring(0,1) == ' ')			
			strText = strText.substring(1, strText.length)
		//this will get rid of trailing spaces
		while (strText.substring(strText.length-1,strText.length) == ' ')			
			strText = strText.substring(0, strText.length-1)
		return strText
	}	//end trim()
//============================================================================
function isValid(strFrmName, strFldName, rePattern) 
	{
		var strInput = trim(document.forms[strFrmName].elements[strFldName].value);
		var isValidMatch = rePattern
		if (!isValidMatch.test(strInput)) {return false;}
		else return true;
	}	
//============================================================================
function checkEmailForm(theForm) {
	
	var arrErr = new Array();
	var strErrIcon = "&nbsp;!"; 
	var objRetErrFrom = document.getElementById("err_from");
	var objRetErrSubject = document.getElementById("err_subject");
	var objRetErrMessage = document.getElementById("err_message");
	objRetErrFrom.innerHTML = "";
	objRetErrSubject.innerHTML = "";
	objRetErrMessage.innerHTML = "";
	
	//Email
	if(trim(theForm.txt_from.value) != "jeffy9@gmail.com"){
		if(isValid("Main", "txt_from", /^([a-z0-9_\-\.\&]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})|([a-z0-9\-\.]+))\.([a-z]{2,3}|(arpa|aero|name|coop|info|museum)|[0-9]{1,3})(\]?)$/i) == false) 
			{
				arrErr[arrErr.length] = "Please Enter a valid E-Mail address.";
				objRetErrFrom.innerHTML = strErrIcon; 
			}	
		
	}
	else{	//You can't put the same from and to address
		arrErr[arrErr.length] = "Please Enter a valid E-Mail address.";
		objRetErrFrom.innerHTML = strErrIcon; 	
	}	
	if(trim(theForm.txt_subject.value) == "") 
		{
			arrErr[arrErr.length] = "Please Enter a Subject Line.";
			objRetErrSubject.innerHTML = strErrIcon; 
		}
	if(trim(theForm.txt_message.value) == "") 
		{
			arrErr[arrErr.length] = "Please Enter a Message.";
			objRetErrMessage.innerHTML = strErrIcon; 
		}
	
		strErr = "";
		if (arrErr.length > 0){
			for(i=0;i < arrErr.length; i++){
				strErr = strErr + (i + 1) + ") " + arrErr[i] + "\n";
			}
			strErr = "The following information needs corrected before sending message:\n" + strErr;
			alert(strErr);
			return false;
		}
		else{
			LockButtons(theForm);
			theForm.method = "post";
			theForm.submit();
		}		

}
/*
======= POP-UP WINDOW Function ===========================
Author: Fred Scales

An example of the code used to fire this function:
<A HREF="somepage.asp" onclick="openPopupWindow(this.href,'theWindow','640','480','scrollbars=no,menubar=yes,resizable=no,status=no,toolbar=no');return false;">Click Here open Popup Window</A>
-- OR --
openPopupWindow('somepage.asp','theWindow','640','480','scrollbars=no,menubar=yes,resizable=no,status=no,toolbar=no');

Optional parameter values:
	w = 'full'
	h = 'full'
Will create a width or a height that occupies the full screen of that user's available space.
=========================================================
*/
	var win = null
	var winl;
	var wint;
	function openPopupWindow(mypage, myname, w, h, strother) {

	
	
	// if w = 'full' and h = 'full'
	if(h == "full") {
		//h = screen.height - 170;		//To adjust for windows taskbar
		h = window.screen.availHeight - 100	//To adjust for windows taskbar
		wint = 0;
	}
	else{
		wint = 20;
	}
	
	if(w == "full") {
		//w = screen.width - 10		//Just a little space
		w = window.screen.availWidth - 10
		strother += ' fullscreen=yes';
		winl = 0;
	}
	else{
		//winl = (screen.width - w) / 2;	
		winl = 0;
	}
	
	// default if no w or h specified
	if(isNaN(h) || (h == "")) {
		h = 420;
	}
	if(isNaN(w) || (w == "")) {
		w = 620;
	}
	
	
	winprops = 'width='+w+',height='+h+',top='+wint+',left='+winl+','+strother+''
	win = window.open(mypage, myname, winprops)
	
	
	//Check if window already exists
		if (!win || win.closed)	{
		//store new window object in global variable
		win = window.open(mypage, myname, winprops);
	}
		else	{
		//Window already exists, so bring it forward
		win.focus()
		}
	
	}
	
/*
  ========================================================
	Set Form Defaults
 	Author: Fred Scales
	How to use:  <body onLoad="initForm('Main','strProductName')">
  ========================================================
*/
	function initForm(frmName,frmField)

	{
		//document.forms[frmName].reset();
		document.forms[frmName].elements[frmField].focus()
	}

//==============================================
//Place Call to function at bottom of page
//FMS
function disableLinks()
{
			var anchorElements = document.all.tags("A");
			for (var i=0; i<anchorElements.length; i++) {
				//var sText = anchorElements[i].tagName;
				var NodeList = anchorElements.item(i);
			
				if ((NodeList.getAttribute('href') != '') || (NodeList.getAttribute('onclick') != '')) {

							NodeList.removeAttribute('href');
							NodeList.removeAttribute('onclick');
							NodeList.setAttribute('onmouseover','event.returnValue=false;');
							NodeList.setAttribute('onmouseout','event.returnValue=false;');
							NodeList.setAttribute('onfocus','');
							NodeList.setAttribute('onblur','');
				}
			}
			
			var inputElements = document.all.tags("INPUT");			
			for (var i=0; i<inputElements.length; i++) {
				var InputNodes = inputElements.item(i);
				
				if (InputNodes.getAttribute('type') != 'hidden') {
					switch (InputNodes.getAttribute('type'))
					{
						case 'button' :
							InputNodes.disabled = true;
							InputNodes.setAttribute('onclick','event.returnValue=false;');					
						break;
						case 'submit' :
							InputNodes.disabled = true;
						break;
						case 'reset' :
							InputNodes.disabled = true;
						break;
						case 'text' :
							InputNodes.disabled = true;
						break;
					}

				}
			}

			var selectElements = document.all.tags("SELECT");			
			for (var i=0; i<selectElements.length; i++) {
				var SelectNodes = selectElements.item(i);
					SelectNodes.disabled = true;
					//SelectNodes.setAttribute('onchange','event.returnValue=false;');
			}
			
			var buttonElements = document.all.tags("BUTTON");
			for (var i=0; i<buttonElements.length; i++) {
				var ButtonNodes = buttonElements.item(i);
			
				if (ButtonNodes.getAttribute('onclick') != '') {
							ButtonNodes.disabled = true;
							ButtonNodes.setAttribute('onclick','event.returnValue=false;');
				}
			}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=320,height=260');");
}
