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_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

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_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 in_array(needle, haystack)
{
	var i;
	
	for (i in haystack)
		if (haystack[i] == needle)
			return true;
	
	// else we're here...
	return false;
}

function is_alphanumeric(txt_obj)
{
	var name = new String(txt_obj.value);
	var tmp;
	
	tmp = name.search(/^\w*$/);
	
	if (tmp == -1 || name.length < 1)
		return false;
	else
		return true;
}

function repop_addr_summary(dbox)
{
	var aid = dbox.options[dbox.selectedIndex].value;
	var i;
	var new_node;
	var old_node;
	var removed_node;

	for (i in addr_data)
	{
		if (addr_data[i].acct_id == aid)
		{
			// this is the old and busted way to do it...
			new_node	= document.createTextNode(addr_data[i].address1);
			old_node	= document.getElementById('addr1').firstChild;
			removed_node	= document.getElementById('addr1').replaceChild(new_node, old_node);

			new_node	= document.createTextNode(addr_data[i].address2);
			old_node	= document.getElementById('addr2').firstChild;
			removed_node	= document.getElementById('addr2').replaceChild(new_node, old_node);

			new_node	= document.createTextNode(addr_data[i].city);
			old_node	= document.getElementById('city').firstChild;
			removed_node	= document.getElementById('city').replaceChild(new_node, old_node);
			
			new_node	= document.createTextNode(addr_data[i].state);
			old_node	= document.getElementById('state').firstChild;
			removed_node	= document.getElementById('state').replaceChild(new_node, old_node);
			
			new_node	= document.createTextNode(addr_data[i].zipcode);
			old_node	= document.getElementById('zipcode').firstChild;
			removed_node	= document.getElementById('zipcode').replaceChild(new_node, old_node);
			
			new_node	= document.createTextNode(addr_data[i].fon);
			old_node	= document.getElementById('fon').firstChild;
			removed_node	= document.getElementById('fon').replaceChild(new_node, old_node);
			
			new_node	= document.createTextNode(addr_data[i].tz);
			old_node	= document.getElementById('tz').firstChild;
			removed_node	= document.getElementById('tz').replaceChild(new_node, old_node);
		}
	}
}

function load_addr_data(aid)
{
	for (var i = 0; i < addr_data.length; i++)
	{
		with (document.personal_form)
		{
			if (addr_data[i].acct_id == aid)
			{
				addr1_dev.value		= addr_data[i].address1;
				addr2_dev.value		= addr_data[i].address2;
				fon_dev.value		= addr_data[i].fon;
				city_dev.value		= addr_data[i].city;
				zipcode_dev.value	= addr_data[i].zipcode;
			
				for (var j = 0; j < tz_dev.options.length; j++)
				{
					if (tz_dev.options[j].value == addr_data[i].tz)
						tz_dev.selectedIndex = j;
					else
						continue;
				}
			
				for (var k = 0; k < state_dev.options.length; k++)
				{
					if (state_dev.options[k].value == addr_data[i].state)
						state_dev.selectedIndex = k;
					else
						continue;
				}
			}
		}
	}
}


function open_scroll_only_window(url, name, height, width)
{
	var new_winder = window.open(url, name, 'height=' + height + ',width=' + width + ',resizeable=no,scrollbars=yes,toolbar=no', false);
	
	return new_winder;
}

function open_empty_window(url, name, height, width)
{
	var new_winder = window.open(url, name, 'height=' + height + ' ,width=' + width + ',resizeable=no,scrollbars=no,toolbar=no', false);
	
	return new_winder;
}

function select_all(sbox)
{
  var i;
  
  for (i = 0; i < sbox.options.length; i++)
      sbox.options[i].selected = true;
    
  return;  
}


// some box movement funcs pulled from dah web...
function moveUpList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == 0 ) {
               alert("The first entry in the list cannot be moved up.");
            } else {
               // Get the text/value of the one directly above the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected-1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected-1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected-1].text = moveText2;
               listField[selected-1].value = moveValue2;
               listField.selectedIndex = selected-1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

function moveDownList(listField) {
   if ( listField.length == -1) {  // If the list is empty
      alert("There are no values which can be moved!");
   } else {
      var selected = listField.selectedIndex;
      if (selected == -1) {
         alert("You must select an entry to be moved!");
      } else {  // Something is selected 
         if ( listField.length == 0 ) {  // If there's only one in the list
            alert("There is only one entry!\nThe one entry will remain in place.");
         } else {  // There's more than one in the list, rearrange the list order
            if ( selected == listField.length-1 ) {
               alert("The last entry in the list cannot be moved down.");
            } else {
               // Get the text/value of the one directly below the hightlighted entry as
               // well as the highlighted entry; then flip them
               var moveText1 = listField[selected+1].text;
               var moveText2 = listField[selected].text;
               var moveValue1 = listField[selected+1].value;
               var moveValue2 = listField[selected].value;
               listField[selected].text = moveText1;
               listField[selected].value = moveValue1;
               listField[selected+1].text = moveText2;
               listField[selected+1].value = moveValue2;
               listField.selectedIndex = selected+1; // Select the one that was selected before
            }  // Ends the check for selecting one which can be moved
         }  // Ends the check for there only being one in the list to begin with
      }  // Ends the check for there being something selected
   }  // Ends the check for there being none in the list
}

// and here's what crossto's need...
function makeStringFromSelect(selectCtrl) {
	var i;
	var j = 0;
	var outlist = "";

	for (i = 0; i < selectCtrl.options.length; i++) {
		if (j > 0) {
			outlist = outlist + "::";
		}
		outlist = outlist + selectCtrl.options[i].value;
		j++;
	}
	return outlist;
}

function addItems(fromCtrl, toCtrl) {
	var i;
	var j;
	var itemexists;
	var nextitem;

	// step through all items in fromCtrl
	for (i = 0; i < fromCtrl.options.length; i++) {
		if (fromCtrl.options[i].selected) {
			// search toCtrl to see if duplicate
			j = 0;
			itemexists = false;
			while ((j < toCtrl.options.length) && (!(itemexists))) {
				if (toCtrl.options[j].value == fromCtrl.options[i].value) {
					itemexists = true;
//					alert(fromCtrl.options[i].value + " found!");
				}
				j++;
			}
			if (!(itemexists)) {
				// add the item
				nextitem = toCtrl.options.length;
				toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
				toCtrl.options[nextitem].value = fromCtrl.options[i].value;
			}
		}
	}
}

function removeItems(fromCtrl) {
	var i = 0;
	var j;
	var k = 0;

	while (i < (fromCtrl.options.length - k)) {
		if (fromCtrl.options[i].selected) {
			// remove the item
			for (j = i; j < (fromCtrl.options.length - 1); j++) {
				fromCtrl.options[j].text = fromCtrl.options[j+1].text;
				fromCtrl.options[j].value = fromCtrl.options[j+1].value;
				fromCtrl.options[j].selected = fromCtrl.options[j+1].selected;
			}
			k++;
		} else {
			i++;
		}
	}
	for (i = 0; i < k; i++) {
		fromCtrl.options[fromCtrl.options.length - 1] = null;
	}
}


/* the following is how these crossto's should be implemented...
<INPUT TYPE="HIDDEN" NAME="Avail">
<INPUT TYPE="HIDDEN" NAME="Sel">
<SELECT MULTIPLE NAME="AvailItems" SIZE="5">
	<OPTION VALUE="1">Item 1</OPTION>
	<OPTION VALUE="2">Item 2</OPTION>
</SELECT>
</TD>
<TD ALIGN="CENTER">
 <INPUT TYPE="BUTTON" NAME="AddBtn" VALUE="    >>    " OnClick="addItems(this.form.AvailItems, this.form.SelItems); removeItems(this.form.AvailItems);"> <BR>
<BR>
 <INPUT TYPE="BUTTON" NAME="RemoveBtn" VALUE="    <<    " OnClick="addItems(this.form.SelItems, this.form.AvailItems); removeItems(this.form.SelItems);"> <BR>
</TD>
<TD VALIGN="TOP">
Selected Items:<BR>
<SELECT MULTIPLE NAME="SelItems" SIZE="5">
	<OPTION VALUE="3">Item 3</OPTION>
	<OPTION VALUE="4">Item 4</OPTION>
</SELECT>
<INPUT TYPE="BUTTON" VALUE="Submit" OnClick="this.form.Avail.value = makeStringFromSelect(this.form.AvailItems); this.form.Sel.value = makeStringFromSelect(this.form.SelItems); this.form.submit();">


  
  
*/


/**********************************************************
Sleight
(c) 2001, Aaron Boodman
http://www.youngpup.net
*********************************************************
THIS IS USED SO THAT IE ON THE PC SIDE CAN UTILIZE TRANSPARENT PNG GRAPHICS.*/

if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent)
{
	document.writeln('<style type="text/css">img { visibility:hidden; } </style>');
	window.attachEvent("onload", fnLoadPngs);
}

function fnLoadPngs()
{
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--)
	{
		if (itsAllGood && img.src.match(/\.png$/i) != null)
		{
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}
