

//Macromedia functions for Rollovers and Show/Hide Layers and open window
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Print page
function printThis(){
	if(navigator.platform.indexOf("Mac")!=-1){
	alert("Attention Mac users:\nTo print, click 'OK', go to the file menu and select 'Print'");
	}else{
	window.print();
	}
  }
  
//open URL in Opener window
function goBack(url) {
opener.location.href = url;
window.close();
}

//clear text fiels
function clearfield(obj){
	if (obj.value != "") 
		obj.value = "";
	}
	
//Close pop up window and refresh opener
function closeWinRefresh() {
	self.close();
	opener.location.reload(true);
}

//name pretty much says it
function confirmDelete() {
	var agree=confirm("Are you sure you want to delete this record?");
	if (agree)
	return true ;
		else
	return false ;
	}
			
function GP_AdvOpenWindow(theURL,winName,features,popWidth,popHeight,winAlign,ignorelink,alwaysOnTop,autoCloseTime,borderless) { //v2.0
  var leftPos=0,topPos=0,autoCloseTimeoutHandle, ontopIntervalHandle, w = 480, h = 340;  
  if (popWidth > 0) features += (features.length > 0 ? ',' : '') + 'width=' + popWidth;
  if (popHeight > 0) features += (features.length > 0 ? ',' : '') + 'height=' + popHeight;
  if (winAlign && winAlign != "" && popWidth > 0 && popHeight > 0) {
    if (document.all || document.layers || document.getElementById) {w = screen.availWidth; h = screen.availHeight;}
		if (winAlign.indexOf("center") != -1) {topPos = (h-popHeight)/2;leftPos = (w-popWidth)/2;}
		if (winAlign.indexOf("bottom") != -1) topPos = h-popHeight; if (winAlign.indexOf("right") != -1) leftPos = w-popWidth; 
		if (winAlign.indexOf("left") != -1) leftPos = 0; if (winAlign.indexOf("top") != -1) topPos = 0; 						
    features += (features.length > 0 ? ',' : '') + 'top=' + topPos+',left='+leftPos;}
  if (document.all && borderless && borderless != "" && features.indexOf("fullscreen") != -1) features+=",fullscreen=1";
  if (window["popupWindow"] == null) window["popupWindow"] = new Array();
  var wp = popupWindow.length;
  popupWindow[wp] = window.open(theURL,winName,features);
  if (popupWindow[wp].opener == null) popupWindow[wp].opener = self;  
  if (document.all || document.layers || document.getElementById) {
    if (borderless && borderless != "") {popupWindow[wp].resizeTo(popWidth,popHeight); popupWindow[wp].moveTo(leftPos, topPos);}
    if (alwaysOnTop && alwaysOnTop != "") {
    	ontopIntervalHandle = popupWindow[wp].setInterval("window.focus();", 50);
    	popupWindow[wp].document.body.onload = function() {window.setInterval("window.focus();", 50);}; }
    if (autoCloseTime && autoCloseTime > 0) {
    	popupWindow[wp].document.body.onbeforeunload = function() {
  			if (autoCloseTimeoutHandle) window.clearInterval(autoCloseTimeoutHandle);
    		window.onbeforeunload = null;	}  
   		autoCloseTimeoutHandle = window.setTimeout("popupWindow["+wp+"].close()", autoCloseTime * 1000); }
  	window.onbeforeunload = function() {for (var i=0;i<popupWindow.length;i++) popupWindow[i].close();}; }   
  document.MM_returnValue = (ignorelink && ignorelink != "") ? false : true;
}

function P7_JumpMenu(selObj,restore){ //v1.3 by Project Seven
	var theFullString = selObj.options[selObj.selectedIndex].value;
	if (restore) selObj.selectedIndex=0;
	var theLength = theFullString.length;
	var endPos = theFullString.lastIndexOf("~");
	var theUrl, theTarget, theParent;
	if (endPos > 0) {theUrl = theFullString.substring(0,endPos);}
	else {theUrl = theFullString;}
	endPos++
	if (endPos < theLength) {theTarget = theFullString.substring(endPos,theLength)}
	else {theTarget = "window:Main";}
	if (theTarget == "window:New") {window.open(theUrl);}
	else if (theTarget == "window:Advanced") {GP_AdvOpenWindow(theUrl,'regWin','fullscreen=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no',780,550,'center','ignoreLink','',0,'');return document.MM_returnValue}
	else if (theTarget == "window:Main") {eval("parent.location='"+theUrl+"'");}
	else {eval("parent.frames[\'"+theTarget+"\'].location='"+theUrl+"'");}
}

function P7_autoLayers() { //v1.2 by PVII
 var g,b,k,f,args=P7_autoLayers.arguments;
 var a = parseInt(args[0]);if(isNaN(a))a=0;
 if(!document.p7setc) {p7c=new Array();document.p7setc=true;
  for (var u=0;u<10;u++) {p7c[u] = new Array();}}
 for(k=0; k<p7c[a].length; k++) {
  if((g=MM_findObj(p7c[a][k]))!=null) {
   b=(document.layers)?g:g.style;b.visibility="hidden";}}
 for(k=1; k<args.length; k++) {
  if((g=MM_findObj(args[k])) != null) {
   b=(document.layers)?g:g.style;b.visibility="visible";f=false;
   for(j=0;j<p7c[a].length;j++) {
    if(args[k]==p7c[a][j]) {f=true;}}
  if(!f) {p7c[a][p7c[a].length++]=args[k];}}}
}


//

function setFocus(){
	for(var i=0;i< document.forms[0].elements.length;i++){
		if(document.forms[0].elements[i].type != 'hidden'){
			document.forms[0].elements[i].focus();
			break;
		}
	}
}

function showBilling() {
	if (document.regForm.AddressSameAs.selectedIndex == 1){
		MM_showHideLayers('BillingArea','','show','SubmitButt','','hide')
	} 
		//else 
		
	//{
		//MM_showHideLayers('welcomeRegText','','hide','welcomeWhatText','','show')
	}


//functions for auto tabbing

var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

if(input.value.length >= len && !containsElement(filter,keyCode)) {
	input.value = input.value.slice(0, len);
	input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
	var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
				index++;
			return found;
		}

function getIndex(input) {
	var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
			return index;
				}
			return true;
			}
			
function CalcTotal(fee) {
	var iTotal = ((document.FormCC.Quantity.selectedIndex + 1) * fee);
	var iRounded = Math.round(iTotal*100)/100;
	if (iRounded.indexOf(".") != -1)
	{
		var iPosA = iRounded.indexOf(".");
		var iPosB = iRounded.length;
		var iLen = iRounded.substring(iPosA,iPosB);
		if (iLen.length < 2) { iRounded += iRounded + "0"; }
		alert(iPosA);
	}
	document.getElementById("PedTotal").innerHTML = "$" + iTotal;
}

//these functions used primarily for the maps

function ShowIt(theLayer) {
	if(document.layers)    										
		document.layers[theLayer].visibility = "show";	 		
	else if(document.getElementById)  						   
		document.getElementById(theLayer).style.visibility = "visible";
	else 	 													
		document.all[theLayer].style.visibility = "visible";   
}	

function HideIt(theLayer) {
	if(document.layers)	 										
		document.layers[theLayer].visibility = "hide";			
	else if(document.getElementById)  							
		document.getElementById(theLayer).style.visibility = "hidden";
	else	  													
		document.all[theLayer].style.visibility = "hidden";		
}	

var timer

function keepMenu() {
	clearTimeout(timer);1
}

function HideItLater(theLayer){
	timer = setTimeout("HideIt('" + theLayer + "')",1500)
}

//end maps


function TrackCount(fieldObj,countFieldName,maxChars)
{
  var countField = eval("fieldObj.form."+countFieldName);
  var diff = maxChars - fieldObj.value.length;

  // Need to check & enforce limit here also in case user pastes data
  if (diff < 0)
  {
    fieldObj.value = fieldObj.value.substring(0,maxChars);
    diff = maxChars - fieldObj.value.length;
  }
  countField.value = diff;
}

function LimitText(fieldObj,maxChars)
{
  var result = true;
  if (fieldObj.value.length >= maxChars)
    result = false;
  
  if (window.event)
    window.event.returnValue = result;
  return result;
}

function unblur() {
	this.blur();
}

function blurLinks() {
	if (!document.getElementById) return;
	theLinks = document.getElementsByTagName("a");
	for(i=0; i<theLinks.length; i++) { 
		theLinks[i].onfocus = unblur;
	}
}


function checkBillingAddress(list) {
	var x;
	var y;
	x = list.options.selectedIndex;
	//alert(x);
	if (x == 2){
		y = document.getElementById("NotSame"); y.style.display="";
		y = document.getElementById("IsSame"); y.style.display="none";
	}else{
		y = document.getElementById("NotSame"); y.style.display="none";
		y = document.getElementById("IsSame"); y.style.display="";
	}
}

function formatAsMoney(mnt) {
    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    return (mnt == Math.floor(mnt)) ? mnt + '.00' 
              : ( (mnt*10 == Math.floor(mnt*10)) ? 
                       mnt + '0' : mnt);
}

function ToggleImage(el)
{
    if(el)
    {
       if(el.src)
       {
          var src = el.src;
          if(src.lastIndexOf("_hover") > 0)
             src = src.replace("_hover","_button");
          else if(src.lastIndexOf("_button") > 0)
             src = src.replace("_button","_hover");

          el.src = src;
       }
    }
}


var curWidth=0;
var curHeight=0;
var targWidth=0;
var targHeight=0;
var readContentFrom;
var expandPopup;
var wIncr = 0;
var hIncr = 0;
								
function expandWindow()
{
	var win = document.getElementById("HelpPopUp");
	curWidth += wIncr;
	curHeight += hIncr;
	win.style.width = curWidth+"px";
	win.style.height = curHeight+"px";
	document.getElementById("divclose").innerHTML
	if(curWidth>targWidth) win.innerHTML = document.getElementById(readContentFrom).innerHTML + "<div style='color:red;font-size:10px;text-align: center;margin-top: 10px'>"+document.getElementById("divclose").innerHTML+"</div>";
	else setTimeout("expandWindow()",10);
}

function openPopup(sourceDiv, _top, _left, _width, _height)
{	
	// hide <select> elements from IE
	if(document.all) 
	{
		var s = document.getElementsByTagName("select");
		for(i=0;i<s.length;i++) s[i].style.display="none";
	}
	
	readContentFrom = sourceDiv;				
	var win = document.getElementById("HelpPopUp");
	win.style.width = curWidth = 0;
	win.style.height = curHeight = 0;
	win.style.top = _top;
	win.style.left = _left;
	targWidth = _width;
	targHeight = _height;
	wIncr = _width/10;
	hIncr = _height/10;
	
	if(document.all) win.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=95)";
	else win.style.opacity=.95;
	
	win.style.display = "";
	win.innerHTML = "";					
	setTimeout("expandWindow()",10);
}

function openOptions(sourceDiv, _top, _left, _width, _height)
{	
	// hide <select> elements from IE
	if(document.all) 
	{
		var s = document.getElementsByTagName("select");
		for(i=0;i<s.length;i++) s[i].style.display="none";
	}
	
	readContentFrom = sourceDiv;				
	var win = document.getElementById("HelpPopUp");
	win.style.width = curWidth = 0;
	win.style.height = curHeight = 0;
	win.style.top = _top;
	win.style.left = _left;
	targWidth = _width;
	targHeight = _height;
	wIncr = _width/10;
	hIncr = _height/10;
	
	if(document.all) win.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=95)";
	else win.style.opacity=.95;
	
	win.style.display = "";
	win.innerHTML = "";					
	setTimeout("expandWindow()",10);
}
								
function closePopup() 
{
	// unhide <select> elements from IE
	if(document.all) 
	{
		var s = document.getElementsByTagName("select");
		for(i=0;i<s.length;i++) s[i].style.display = "";
	}
	document.getElementById("HelpPopUp").style.display = "none";
}
		

function ValidateContact(form) {

	var msg = "";
	
	if (!emailValid(form.txtEmail.value)) msg += "-- Email address required\n";
	if (!isEmpty(form.txtMessage.value)) msg += "-- Message required\n";
	
	if (msg != "") 
	{ 
		alert("The following had errors: \n------------------------------\n" + msg + "------------------------------\nPlease correct and continue");
		return false;
	} 
	return true;
}

function isAlphaNum(str) 
{
	regex=/^[a-zA-Z0-9]+$/;
	return(regex.exec(str));
}

  