// onLoad code by Simon Willison http://simonwillison.net/2004/May/26/addLoadEvent/

function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
}
}
}
//addLoadEvent(highlight); highlight fullcourt
addLoadEvent(showNav);
addLoadEvent(clickTool);
addLoadEvent(clickChannel);
addLoadEvent(clickDial);
addLoadEvent(showNavcorp);




function openurl(url_add){
newwindow = window.open(url_add,'atmconline', 'width=997,height=620,menubar=yes,status=yes, location=yes,toolbar=yes,scrollbars=yes,resizable=yes');
  if(newwindow) newwindow.focus();
  return false; }

	function showNavcorp() {
	if (!document.getElementById("crightnav")) return false;
	var currenturl = window.location.href;
	

	
	var currentsplit = currenturl.split("?");
	var currenta = currentsplit[0];
	var current = currenta.slice(26,100);	
	
		var crightnav = document.getElementById("crightnav");
	var canchors = crightnav.getElementsByTagName("a");

	var cimgs = crightnav.getElementsByTagName("img");	
	if (!crightnav.getElementsByTagName("ul")) return false;
	var culindex = crightnav.getElementsByTagName("ul");	
	
		
	for (var i=0; i<culindex.length; i++){
	culindex[i].style.display = "none";}
	
	
	for (var i=0; i<canchors.length; i++) {

	if (canchors[i].getAttribute("href",2) == current){

if(canchors[i]  == canchors[0]) {
			cimgs[0].setAttribute("src", onimgs[0]);
			culindex[0].style.display = "block";
		
			}
	
			if(canchors[i] == canchors[1]) {
			cimgs[1].setAttribute("src", onimgs[1]);
			culindex[1].style.display = "block";
			}
	
			if(canchors[i] == canchors[2]) {
			cimgs[2].setAttribute("src", onimgs[2]);
			culindex[2].style.display = "block";
			}
	
			if(canchors[i] == canchors[3]) {
			cimgs[3].setAttribute("src", onimgs[3]);
			culindex[3].style.display = "block";	
			}	
				if(canchors[i] == canchors[4]) {
			cimgs[4].setAttribute("src", onimgs[4]);
			culindex[4].style.display = "block";	
			}		

			if(canchors[i] == canchors[5]) {
			cimgs[1].setAttribute("src", onimgs[1]);
			culindex[1].style.display = "block";
			}
	
			if(canchors[i] == canchors[9]) {
			cimgs[1].setAttribute("src", onimgs[1]);
			culindex[1].style.display = "block";
			}
	
			if(canchors[i] == canchors[10]) {
			cimgs[2].setAttribute("src", onimgs[2]);
			culindex[2].style.display = "block";
			
	
			}
	
			if(canchors[i] == canchors[11]) {
			cimgs[3].setAttribute("src", onimgs[3]);
			culindex[3].style.display = "block";
			}
		
			if(canchors[i] == canchors[12]) {
			cimgs[4].setAttribute("src", onimgs[4]);
			culindex[4].style.display = "block";
			}}}}



function getNextElement(node) {
if(node.nodeType == 1) {
return node;
}
if (node.nextSibling) {
return getNextElement(node.nextSibling);
}
return null;
}


	
function showNav() {
if (!document.getElementById("rightnav")) return false;
	var currenturl = window.location.href;
	
if (currenturl.indexOf("#",0)>0){
		
		var currenta = currenturl;

		}
	else if (currenturl.indexOf("?",0)>0){
	var currentsplit = currenturl.split(("?"));
		var currenta = currentsplit[0];}
	
	else {currenta = currenturl}

	var slashLoc = currenta.lastIndexOf("/");
	var current = currenta.substring(slashLoc+1);
	var rightnav = document.getElementById("rightnav");
	var anchors = rightnav.getElementsByTagName("a");	
	var ulindex = rightnav.getElementsByTagName("ul");	
	
	
			for (var i=0; i<ulindex.length; i++){
			ulindex[i].style.display = "none";}
			
					for (var i=0; i<anchors.length; i++) {
					curr_a = anchors[i];
					
					slashLoc = curr_a.getAttribute("href",2).lastIndexOf("/");
					curr_a_short = curr_a.getAttribute("href",2).substring(slashLoc+1);

					if (curr_a_short == current){
						
									if (curr_a.className.match("main")) {
									curr_a.style.color = "#87f36b";
									var next = getNextElement(curr_a.nextSibling);
									next.style.display = "block";
									
								}
									
					
									if (curr_a.className.match("minorlink")) {
									curr_a.style.color = "white";
									
									
									var nextw = curr_a.parentNode.parentNode;
									nextw.style.display = "block";
									
									var nextz = nextw.parentNode;
									nextz.firstChild.style.color = "#87f36b";
									
									
									/*var nextg = nextw.firstChild.firstChild;
									
						
									alert(nextg.className);
										alert(nextg.firstChild.className);
										alert(nextg.childNodes[0].className);
											alert(nextg.childNodes[0].lastChild.className);
												
									
									 
									if (nextg.className.match("minorsub")) {
								
										 nextg.style.border = "3px solid pink";
												 	 nextg.style.display = "block";
									}
									
									nextg.childNodes[1].style.display = "block";
									alert(nextz.className);
										alert(nextz.firstChild.nodeName);
											alert(nextz.firstChild.textValue);*/
									
								}
					}
			}
	}
	
function whichElement(e)
{
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // defeat Safari bug
   targ = targ.parentNode
var tname
tname=targ.tagName
alert("You clicked on a " + tname + " element.")
}
	
function clickTool() {
if (!document.getElementById("toolsbox")) return false;
	var clk = document.getElementById("quicktools");
	document.getElementById("toolsbox").style.opacity = "0"
		
	clk.onclick = function() {
	shiftOpacity('toolsbox', 1000);
var back = document.getElementsByTagName("body");

	}
	}
	
	
	
function clickChannel() {
if (!document.getElementById("plat")) return false;
	var clk = document.getElementById("viewchan");
	document.getElementById("plat").style.opacity = "0"	
	clk.onclick = function() {
	shiftOpacity("plat", 1000);

	}
	}

function clickDial() {
if (!document.getElementById("dialup")) return false;
	var clk = document.getElementById("dial");
	document.getElementById("dialup").style.opacity = "0"
	document.getElementById("dialup").style.zindex= "1"
	clk.onclick = function() {
	shiftOpacity("dialup", 1000);

	}
	}

function clickBroad() {
if (!document.getElementById("broadband")) return false;
	var clk = document.getElementById("broad");
	document.getElementById("broadband").style.opacity = "0"
		document.getElementById("broadband").style.zindex= "1"
		
	clk.onclick = function() {
	shiftOpacity("broadband", 1000);

	}
	}	



	
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it invisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 95, millisec); 
		document.getElementById(id).style.display = "block";
		
    } else { 
        opacity(id, 95, 0, millisec); 
		document.getElementById(id).style.display = "none";
    } 
} 

function closeOpacity(id, millisec) { 
        opacity(id, 95, 0, millisec); 
		document.getElementById(id).style.display = "none";
} 


function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 300); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function toolMove() {
	var tools = document.getElementById("toolsbox");
	var wdth =  parseInt(tools.style.width);
	var hght =  parseInt(tools.style.height);
	tools.style.display = "block";	
	/*txt = document.createTextNode("writeme");
	tt = document.createTextNode(hght);
	tools.appendChild(tt);*/
		
	if (hght < 400){
	hght++;
	}
	if (wdth < 300){
	wdth++;
	}

	tools.style.width = wdth + "px";
	tools.style.height = hght + "px";
	movement = setTimeout("toolMove()", 0);
	}
	
function show(id) {
var box = document.getElementById(id);
box.style.display = "block";
}


function showLayer (layerName)
{if (document.getElementById) // Netscape 6 and IE 5+
{ var targetElement = document.getElementById(layerName);
  targetElement.style.visibility ='visible';
  }
  }
  
function hideLayer (layerName)
{if (document.getElementById)
	{ var targetElement = document.getElementById(layerName);
	  targetElement.style.visibility = 'hidden';
	  }
	  }
	  
	  
	  
function searchDirectory() {

	var p = "1"
	var bObj = document.getElementById("dirSearchForm").b;
	var b = "";
	var sObj = document.getElementById("dirSearchForm").s;
	var s = "";
	var go = document.getElementById("go").value;
	
	for (i = 0; i < bObj.length; i++) {
		if (bObj[i].checked) {
			b = bObj[i].value;
		}
	}
	
	for (i = 0; i < sObj.length; i++) {
		if (sObj[i].checked) {
			s = sObj[i].value;
		}
	}

	var URL = "http://www.informationpages.com/sys/pageserver.dll?b=" + b + "&p=" + p +"&s=" + s + "&f=&gp=&go=" + go;
	window.open(URL, "directorySearch", "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=1024,height=768");
}







function validateFormOnSubmit(myForm) {
var reason = "";

  reason += validateFname(myForm.firstname);
   reason += validateLname(myForm.lastname);
    reason += validatePhone(myForm.phone);
       reason += validateEmail(myForm.email);

   
   if (reason != "")  
  var divo = document.getElementById("ermess");
  divo.innerHTML = "<b>" + "Your entry contains errors:" + "</b>" + "<br/>"  + reason ;
    divo.style.display = "block";
    
 
  return false;
}

function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 



function validateEmpty(fld) {
    var error = "";
 
    if (fld.value.length == 0) {
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
         fld.style.border = '1px solid #84acd2';
    }
    return error;  
}


function validateFname(fld) {
    var error = "";
    var illegalChars =  /[\(\)\<\>\,\;\:\\\"\[\]]/;  
 
    if (fld.value == " ") {
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Please enter your first name.\n";
    }  else if (illegalChars.test(fld.value)) {
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Your first name contains illegal characters.\n";
     }  else {
        fld.style.background = 'White';
         fld.style.border = '1px solid #84acd2';
    }
    return error;
}

function validateLname(fld) {
    var error = "";
    var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\]]/; 
 
    if (fld.value == " ") {
               fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Please enter your last name.\n";
    } else if (illegalChars.test(fld.value)) {
              fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Your last name contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
         fld.style.border = '1px solid #84acd2';
    }
    return error;
}

function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == " ") {
        error = "Please enter a phone number.\n";
           fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
          fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
    } else {
        fld.style.background = 'White';
        fld.style.border = '1px solid #84acd2'; 
    }
    return error;
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Please enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = '#ffffcc';
         fld.style.border = '1px solid #84acd2';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
         fld.style.border = '1px solid #84acd2';
    }
    return error;
}


function clearUs(id){
document.getElementById(id).submit();
 clearFm(id);
}


function clearFm(id) {
document.getElementById(id).userid.value = "";
document.getElementById(id).passwd.value = "";
}



function clearGogfm(id) {
document.getElementById(id).q.value = "";
}

function clearAtmcfm(id) {
document.getElementById(id).q.value = "";
}

function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13){
   myfield.form.submit();
   return false;
   }
else
   return true;
}


 function submitenterse(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13){
   myfield.form.submit();
  searchDirectory();
   
    
   return false;
   }
else
   return true;
} 


function doRedirect() {

	window.location.replace("https://bill.atmc.net");
}



function getHTTPObject() {
var xhr = false;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {

try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xhr = false;
}
}
}
return xhr;
}

//function getID(id) {   this was for the fullcourt ajax calendar

//var request = getHTTPObject();
//if (request) {
//request.onreadystatechange = function() {
//displayResponse(request);
//};

//request.open("Post", "/FullCourt", true);
//request.setRequestHeader("Content-Type", 
          //             "application/x-www-form-urlencoded");
  //request.send(id);
	//}
//}

function displayResponse(request) {
if (!document.getElementById("response")) return false;
if (request.readyState ==4){

	if (request.status == 200 || request.status == 304) {
document.getElementById('response').innerHTML = request.responseText;
			}
		
	}
}




function navAnchorLinkColor(obj){
var children = new Array(2);
var children = obj.parentNode.parentNode.childNodes;
len = children.length;
	for (i=0; i<len; i++) {
		if (children[i].nodeName == 'LI'){
		children[i].firstChild.style.color='#8bc4fb';
		obj.style.color = 'white';
	
			}
				
	}
}


/*onerror=handleErr;
var txt="";function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n";
txt+="Error: " + msg + "\n";
txt+="URL: " + url + "\n";
txt+="Line: " + l + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return true;
}*/


//function highlight() {
//date = new Date();
//month = date.getMonth()+1;

//id = "id=" + month;
//getID(id);
//if (!document.getElementsByTagName) return false;
//if (!document.getElementById) return false;
//if (!document.getElementById("monthcona")) return false;

//var group = document.getElementById("monthcona");
//var links = group.getElementsByTagName("a");

//if (month == "11") {
//links[0].style.backgroundColor = "#ffffcc";
//links[0].style.color = "#063a69";
//}

//if (month == "12") {
//links[1].style.backgroundColor = "#ffffcc";
//links[1].style.color = "#063a69";
//}

//if (month == "1") {
//links[2].style.backgroundColor = "#ffffcc";
//links[2].style.color = "#063a69";
//}
//if (month == "2") {
//links[3].style.backgroundColor = "#ffffcc";
//links[3].style.color = "#063a69";
//}
//if (month == "3") {
//links[4].style.backgroundColor = "#ffffcc";
//links[4].style.color = "#063a69";
//}

//for (var i=0; i<links.length; i++) {

//links[i].onclick = function(){
	//for (var i=0; i<links.length; i++) {
	//links[i].style.backgroundColor = "#063a69";
	//links[i].style.color = "white";}

//this.style.backgroundColor = "#ffffcc";
//this.style.color = "#063a69";

//var string = this.href.lastIndexOf("/");
//var id = this.href.substring(string+1);

//getID(id);

//return false;
 //}
//}
//}


