// common_scripts.js

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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_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_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 MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 myModal(myWindow,winWidth,winHeight) {
  window.showModalDialog(myWindow, null, "dialogWidth:" + winWidth + " px;dialogHeight:" + winHeight + "px;center:1;scroll:1;help:0;status:0");
}

function myModal2(myWindow,winWidth,winHeight,winScroll) {
  window.showModalDialog(myWindow, null, "dialogWidth:" + winWidth + " px;dialogHeight:" + winHeight + "px;center:1;scroll:" + winScroll + ";help:0;status:0");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/*  shiftHighlight Javascript for selection list "type ahead"
	Please keep the following lines visible, in recognition of my work...
	************************	
	Author: Max Holman <max@blueroo.net>
	Date  : Sun, 21 Jan 2001
	************************
	This functions lets users type in letters to select an option in your SELECT form fields.
	Usually the browser only takes notice of single keystrokes and switches to the first Option that
	begins with that letter.
	This scripts buffers the users input and compares it against the OPTIONs in the SELECT field, 
	choosing the closest match as you type
	Usage:	<SELECT onKeyPress = "return shiftHighlight(event.keyCode, this);">	

	Platform: Only tested on IE5 (Win) - will not work on Netscape
*/
	var timerid     = null;
	var matchString = "";
	var mseconds    = 2000;	// Length of time before search string is reset
	function shiftHighlight(keyCode,targ)
	{
		keyVal      = String.fromCharCode(keyCode); // Convert ASCII Code to a string
		matchString = matchString + keyVal; // Add to previously typed characters
		elementCnt  = targ.length - 1;	// Calculate length of array -1

		for (i = elementCnt; i > 0; i--)
		{
			selectText = targ.options[i].text.toLowerCase(); // convert text in SELECT to lower case
			if (selectText.substr(0,matchString.length) == 	matchString.toLowerCase())
			{
				targ.options[i].selected = true; // Make the relevant OPTION selected
			}
		}
		clearTimeout(timerid); // Clear the timeout
		timerid = setTimeout('matchString = ""',mseconds); // Set a new timeout to reset the key press string
		return false; // to prevent IE from doing its own highlight switching
	}

<!--
// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}

function OriginalSearch(searchTerms) {

	//document.SearchBoxForm.UserEnteredSearchTerms.value = searchTerms;
	//Search();
	alert("using javascript for search sort original has been depracated");
}

function validateZipCode(zip) {
	var result = null;
	if(zip == null || zip.length == 0) {
		result = "Please enter a zip code";
	}
	if(zip.length < 5) {
		result = "Zip code must contain at least 5 numbers. Please enter a valid zip code.";
	}
	if(isNaN(parseInt(zip))) {
		result = "Please enter a 5 digit zip code with only numbers.";
	}
	return result;
}

function submitECard(submitView) {
	document.ecardForm.action = submitView;
	document.ecardForm.submit();
}

<!--
	/**
	 * Name: didFormChange v2
	 * Description:
	 *		checks for changes to the form
	 */
	function didFormChange(fields)
	{
		//var fields = formObject.elements;
		var changes = false;
		for (var k = 0; k < fields.length; k++ )
		{ 
			if (changes)
			{
				break;
			}
			switch (fields[k].type)
			{
			
				case "checkbox":
				case "radio":
					if (fields[k].defaultChecked != fields[k].checked)
					{
						changes = true;
						break;
					}
				case "select-one":
				case "select-multiple":

					var defVal = new Array();
					var newVal = new Array();
					for (var i=0; i < fields[k].length; i++)
					{
						if(fields[k].options[i].defaultSelected)
						{
							defVal.push(fields[k].options[i].value);
						}
						if (fields[k].options[i].selected)
						{
							newVal.push(fields[k].options[i].value)
						}
					}
					
					defVal.sort();
					newVal.sort();

					for (var t=0; t < newVal.length; t++)
					{
						for(var u=0; u< defVal; u++)
						{
							if (newVal[t] != defVal[u])
							{
								changes = true;
								break;
							}
						}
					}
					break;
				default:
					if (fields[k].defaultValue != fields[k].value)
					{
						changes = true;
						break;
					}
			}
		}
		
		return changes;
	}

function doClock(){ // By Paul Davis - www.kaosweaver.com
  var t=new Date(),a=doClock.arguments,str="",i,a1,lang="1";
  var month=new Array('January','Jan', 'February','Feb', 'March','Mar', 'April','Apr', 'May','May', 'June','Jun', 'July','Jul', 'August','Aug', 'September','Sep', 'October','Oct', 'November','Nov', 'December','Dec');
  var tday= new Array('Sunday','Sun','Monday','Mon', 'Tuesday','Tue', 'Wednesday','Wed','Thursday','Thr','Friday','Fri','Saturday','Sat');
  for(i=0;i<a.length;i++) {a1=a[i].charAt(1);switch (a[i].charAt(0)) {
  case "M":if  ((Number(a1)==3) && ((t.getMonth()+1)<10)) str+="0";
  str+=(Number(a1)>1)?t.getMonth()+1:month[t.getMonth()*2+Number(a1)];break;
  case "D": if ((Number(a1)==1) && (t.getDate()<10)) str+="0";str+=t.getDate();break;
  case "Y": str+=(a1=='0')?t.getFullYear():t.getFullYear().toString().substring(2);break;
  case "W":str+=tday[t.getDay()*2+Number(a1)];break; default: str+=unescape(a[i]);}}return str;
}

// This function is dependent on the s_code_remote.js file in order to obtain
// the account and list of file extensions
function openMe(parent, url, name, features) { //v2.0
  re=/,/
  extList = s_linkDownloadFileTypes.split(re)
  for(i=0;i<extList.length;i++) {
    re.compile(extList[i]+"$")
    if (re.test(url)) {
      s_linkType="d"
      s_linkName=url
      s_lnk=s_co(parent)
      s_gs(s_account)
    }
  }
  window.open(url,name,features)
}

function popupParentGoToURL(url){
	window.opener.location.href = url;
}