// $Revision: 1.8 $
//=========================================================================
// Module: scripts.js
//
// Purpose:
//		Javascipt functions to support photo galleries for 
//		MBR Consultants, Inc. web site.
// 
// Functions:
//		open_index_window
//		open_image_window
//		close_window
//		order_print
//		recalculate_extended_price
//		emailCheck
//
// Comments:
//
// Revision: $Revision: 1.8 $
//
// MBR Consultants, Inc.
// Copyright (C), 2003 All Rights Reserved
//
//=========================================================================

//-------------------------------------------------------------------------
// Function: open_index_window
//
// Purpose:
//		Opens a new window for a photo gallery index page.
// 
// Comments:
//		The behavior I am looking for is to be able to open multiple 
//		windows (of different images) simultaneously, but only allow 
//		one window of a particulr image to be opened at a time.  
//		This is accomplished by using a unique window_name for each 
//		image.  If a particular window_name already exists, it will 
//		be used (overwritten) when we attempt to (re)open an image.  
//		If the window_name does not exist, we will open a new window.
//
// Parameters:
//		url 		- the URL to display in the newly opened window.
//		window_name 	- A unique name for the window being opened.  
//				  It is important that this name be unique to 
//				  the image being opened.  
//				  This allows the user to open multiple windows 
//				  concurrently, but only open window for each 
//				  each image.  (In other words, you can't open 
//				  mutiple windows for the same image.)
//
// Return Values:
//		None.
//
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// Globals
// Unconditionally set the HOME and BARS global vars.
//-------------------------------------------------------------------------

var HOME;
var BARS;
var TOOL_BAR;

if ( document.URL.match("localhost") )
    {
    HOME = 'http://localhost';
    BARS = 'yes';	// ALWAYS FOR LOCAL HOST
    TOOL_BAR = 'yes';	// ALWAYS FOR LOCAL HOST
    }
else
    {
//    HOME = 'https://secure-ce5p209.hostitnow.com/~triangl';
//    HOME = 'https://secure-ce5p315.hostitnow.com/~triangl';
//    HOME = 'https://secure-ce5p311.hostitnow.com/~triangle';
//    HOME = 'http://www.mbr-consultants.com/adlereyeassociates';
    HOME = 'https://ssl.confidus.com/~mbrpcon/adlereyeassociates';
    BARS = 'no';	// Turn bars off for live URL
    TOOL_BAR = 'no';	// Turn bars off for live URL
    }


//window.onload = loadSlides;


var slides = new Array(
new Array('/images/slide-17.jpg','/pages/products/eyewear/eyeglasses-lenses/pixeloptics-atlast-multifocal-bifocal-trifocal-lenses.shtml'),
new Array('/images/slide-15.jpg','/pages/products/eyewear/eyeglasses-lenses/izon-high-resolution-lenses.shtml'),
// new Array('/images/slide-8.jpg','/pages/home/news.shtml'),
new Array('/images/slide-1.jpg','/pages/services/eye-exams.shtml'),
new Array('/images/slide-3.jpg','/pages/services/contact-lens-fittings.shtml'),
new Array('/images/slide-4.jpg','/pages/services/orthokeratology.shtml'),
new Array('/images/slide-12.jpg','/pages/services/rigid-contact-lens-polishing.shtml'),
new Array('/images/slide-10.jpg','/pages/services/glaucoma-management.shtml'),
new Array('/images/slide-16.jpg','/pages/services/dry-eye-management.shtml'),
new Array('/images/slide-9.jpg','/pages/services/lasik-consultation.shtml'),
new Array('/images/slide-2.jpg','/pages/services/optical-boutique.shtml'),
new Array('/images/slide-11.jpg','/pages/home/optometrists.shtml'),
new Array('/images/slide-13.jpg','/pages/home/optometrists/barry-adler.shtml'),
// new Array('/images/slide-14.jpg','/pages/home/optometrists/hiten-prajapati.shtml'),
new Array('/images/slide-7.jpg','/pages/services/optometric-instruments.shtml'),
new Array('/images/slide-5.jpg','/pages/products/contacts.shtml'),
new Array('/images/slide-6.jpg','/pages/products/contact-lens-solutions.shtml'));


var imageWidth = 660;
var imageHeight = 280;
//var imageTimeout = 10000;
var imageTimeout = 8000;
var currentImage = 1;
var nextImage = 1;



function loadSlides() {

  var el = document.getElementById('fading_image_container');
  while (el.firstChild) { el.removeChild(el.firstChild); }

  el.style.width = imageWidth + 'px';
  el.style.height = imageHeight + 'px';

  for(var i=0; i<slides.length; i++) {

    var a = document.createElement('a');
    var t = document.createElement('img');

    a.setAttribute('href', slides[i][1]);

    t.setAttribute('src',slides[i][0]);
    t.setAttribute('width',imageWidth);
    t.setAttribute('height',imageHeight);
    t.style.position = 'absolute';
    t.style.visibility = 'hidden';
//    t.style.visibility = 'visible';

    a.appendChild(t);
    el.appendChild(a);
//alert("Continue");

  }


  el.firstChild.firstChild.style.visibility = 'visible';

  window.setTimeout(startFading, imageTimeout);

}


function startFading() {

  var el = document.getElementById('fading_image_container').childNodes[currentImage].firstChild;

  el.style.visibility = 'visible';
  el.style.zIndex = 2;
  setOpacity(el, 0);
  fadeImage(el,0);

  nextImage = (nextImage < slides.length-1) ? nextImage + 1 : 0;
  currentImage = nextImage;

}


function fadeImage(el, currentOpacity) {

  currentOpacity += 5;	// Speed of fade

  if (currentOpacity > 100) {
    setOpacity(el, 100);
    var prevEl = el.parentNode.previousSibling ? el.parentNode.previousSibling : el.parentNode.parentNode.lastChild;
    prevEl.firstChild.style.visibility = 'hidden';
    el.style.zIndex = 1;
    window.setTimeout(startFading, imageTimeout);
  }
  else {
    setOpacity(el, currentOpacity);
    window.setTimeout(function() { fadeImage(el, currentOpacity); }, 50);
  }

}

function setOpacity(el, opacity) {

	opacity /= 100;

	el.style.opacity = opacity;
	el.style.MozOpacity = opacity;
	el.style.filter = "alpha(opacity=" + (opacity*100) + ")";

}








function home_page()
{
//alert("BEGIN Home Page");
//window.location = HOME;
//document.location = HOME;
window.location = HOME;
//document.location = HOME+'/cgi-bin/index.pl?DOMAIN=localhost&HOME_PAGE_PATH=pages/home/home.shtml'
//document.location = HOME+'/cgi-bin/index.pl?DOMAIN=localhost&HOME_PAGE_PATH=pages/home/home.shtml';
//location.replace("http://localhost");
//alert("END Home Page");
}


function login()
{
// alert("admin login Begin");
    var x = 800;
    var y = 640;
    var window_name = 'login';



    window.open(HOME+'/cgi-bin/login.pl?fsm_state=admin_login&fsm_input=Start',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}

function lost_password()
{
// alert("admin login Begin");
    var x = 800;
    var y = 540;
    var window_name = 'lost_password';



    window.open(HOME+'/cgi-bin/lost_password.pl?fsm_input=Start',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}


function display_skate_sale_items()
{
//alert("Display Skate Sale Begin");
    var x = 800;
    var y = 540;
    var window_name = 'skate_sale_items';
    var form = document.skate_sale_items_form;
    if (form)
        {
	// If the form exists, get the session from the form
	session=form.session.value;
        }
    else
        {
	// If the form does not exists, set session to null so that it defaults
	session='';
        }


    window.open(HOME+'/cgi-bin/display_skate_sale_items.pl?session='+session,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);

//alert("Display Skate Sale End");
}



function display_coach_locator()
{
//alert("Display Coach Locator Begin");
    var x = 800;
    var y = 540;
    var window_name = 'coach_locator';
    var form = document.coach_locator_form;
    if (form)
        {
	// If the form exists, get the session from the form
	rink=form.rink.value;
        }
    else
        {
	// If the form does not exists, set session to null so that it defaults
	rink='';
        }


    window.open(HOME+'/cgi-bin/coach_locator.pl?rink='+rink,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);

//alert("Display Coach Locator End");
}



function display_active_events()
{
//alert("Display Active Events");
    var x = 800;
    var y = 540;
    var window_name = 'active_events';
    var form = document.skate_sale_items_form;
    if (form)
        {
	// If the form exists, get the session from the form
	session=form.session.value;
        }
    else
        {
	// If the form does not exists, set session to null so that it defaults
	session='';
        }


    window.open(HOME+'/cgi-bin/display_active_events.pl?session='+session,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);

//alert("Display Active Events End");
}




function report_management()
{
    var x = 800;
    var y = 580;
    var window_name = 'report_management';


// alert("report management");

    window.open(HOME+'/cgi-bin/report_management.pl?fsm_state=report_management&fsm_input=Start',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}


function department_management(department)
{
    var x = 800;
    var y = 580;
    var window_name = department+'_management';

//  alert("Window name:"+window_name);

    window.open(HOME+'/cgi-bin/'+window_name+'.pl',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}

//---------------------------------------------------------------------------
// DO NOT USE "reports".  Looks like a special name to JS.
// The follwoing function is as dangerous as it is ugly.  
// Unable to get the ".=" concatenation operator to function corectly, I had 
// to create the query string in a single statement.  
// The real dangerous aspect of this function is that you have to explicitly 
// set the query string rather than being able to dynamically generate it.
// Ugly though it may be, it does work.
//---------------------------------------------------------------------------
function generate_report(form)
{
    var x = 800;
    var y = 580;
    var window_name = 'generate_reports';

    var query_params;
    skater_params = 'report_skater='+form.report_skater.value;
    kidsplex_params = 'report_kidsplex='+form.report_kidsplex.value;
    user_params = 'report_user='+form.report_user.value;

    saturday_academy_params = 'report_saturday_academy='
                              +form.report_saturday_academy.value;

    figure_skating_summer_camp_params = 'report_figure_skating_summer_camp='
                              +form.report_figure_skating_summer_camp.value;

    learn_to_skate_params = 'report_learn_to_skate='
                              +form.report_learn_to_skate.value;

    figure_skating_events_params = 'report_figure_skating_events='
                              +form.report_figure_skating_events.value;

    skate_sale_params = 'report_skate_sale='
                              +form.report_skate_sale.value;

    kidsplex_summer_camp_params = 'report_kidsplex_summer_camp='
                              +form.report_kidsplex_summer_camp.value;

    kidsplex_school_day_camp_params = 'report_kidsplex_school_day_camp='
                              +form.report_kidsplex_school_day_camp.value;

    kidsplex_after_school_params = 'report_kidsplex_after_school='
                              +form.report_kidsplex_after_school.value;

    financial_params = 'report_financial='
    			      +form.report_financial.value;

    user_attributes_params = 'report_user_attributes='
    			      +form.report_user_attributes.value;

    query_params = user_params+'&'
    		   +user_attributes_params+'&'
		   +skater_params+'&'
		   +kidsplex_params+'&'
		   +saturday_academy_params+'&'
		   +figure_skating_summer_camp_params+'&'
		   +learn_to_skate_params+'&'
		   +figure_skating_events_params+'&'
		   +skate_sale_params+'&'
		   +kidsplex_summer_camp_params+'&'
		   +kidsplex_after_school_params+'&'
		   +financial_params+'&'
		   +kidsplex_school_day_camp_params;

//alert("Generate Report");
//alert("query_params="+query_params);

   window.open(HOME+'/cgi-bin/reports.pl?'+query_params,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}


function alert_management()
{
    var x = 800;
    var y = 580;
    var window_name = 'alert_management';



    window.open(HOME+'/cgi-bin/alert.pl?fsm_state=alert_management&fsm_input=Start',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}


function popup_info(my_class)
{
// alert("Registration Begin");
    var x = 800;
    var y = 745;
    var window_name = my_class.toLowerCase();
//  alert("Window name:"+window_name);



    window.open('/cgi-bin/popup_info.pl?operation=new&class='+my_class+'&form_title='+my_class+' Registration',window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}



function register(my_class,default_session)
{
// alert("Registration Begin");
    var x = 800;
    var y = 745;
    var window_name = my_class.toLowerCase()+"_register";
//  alert("Window name:"+window_name);


    window.open(HOME+'/cgi-bin/form_fsm.pl?operation=new&class='+my_class+'&form_title='+my_class+' Registration&default_session='+default_session,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}


function management(my_class)
{
    var x = 800;
    var y = 700;
    var window_name = my_class.toLowerCase()+"_manage";
//  alert("Window name:"+window_name);

    window.open(HOME+'/cgi-bin/manage.pl?class='+my_class,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}

function sub_management(operation,my_class,key,value)
{
    var x = 800;
    var y = 700;
    var window_name = my_class.toLowerCase()+"_sub_management_"+value;
//  alert("Window name:"+window_name);
//  alert("Operation:"+operation);
//  alert("MY Class:"+my_class);
//  alert("User Num:"+user_num);
    var op_title = operation.substring(0,1).toUpperCase() + 
    		   operation.substring(1);
//    alert("Op Title: "+op_title);

  window.open(HOME+'/cgi-bin/form_fsm.pl?operation='+operation+'&class='+my_class+'&form_title='+op_title+'%20'+my_class+'%20Info&key='+key+'&value='+value,window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);
}





function popup_info_window(title,msg)
{
var x = 800;
var y = 500;
var window_name = 'dialog_box';

var w = window.open("",window_name,'alwaysraised=yes,dependent=no,toolbar='+TOOL_BAR+',location='+BARS+',directories=no,status='+BARS+',menubar='+BARS+',scrollbars=yes,resizable=yes,copyhistory=no,width='+x+',height='+y);

var d = w.document;

d.write('<h2 align="center">'+title+'</h2>');
d.write('<hr>');
d.write('<p>'+msg+'</p>');
d.write('<hr>');
d.write('<p align="center"><input type="button" value="Close Window" onclick="self.close();"></p>');
c.close();
}








function backbutton()
{
    alert("Obsolete function: backbutton");
    history.back();
}


function closewindow()
{
    alert("Obsolete function: closewindow");
    window.close();
}

function reloadwindow()
{
    window.location.reload(1);
}

function browserprint()
{
    window.print();
}



function price2int(x)
{
//var int_value = x.match(/[0-9]+/g); // returns an array delimited by decimal
//return(int_value[0]+int_value[1]);

return( Number(+x.replace(/[\$.]/g,'')) ); // replace all '$' and '.' with null
}

function int2price(x)
{
if (x)
    {
    var integer = x.toString();
    var decimal_index = integer.length-2;
    var dollars = integer.slice(0, decimal_index);
    var cents = integer.slice(decimal_index);
    var price = '$'+dollars+'.'+cents;
    }
else
    {
    var price = '$0.00';
    }
return(price);
//var decimal_index = x.length-2;
//var dollars = x.slice(0, decimal_index);
//var cents = x.slice(decimal_index);
//var int_value = '$'+dollars+'.'+cents;
//return(int_value);
}


















//function emailCheck (emailStr)
function emailCheck (form)
     {
//	 alert("emailCheck:"+form.value);
	 var emailStr = form.value;
	 if (emailStr.length == 0)
	     {
	     return true;
	     }
//	 alert("Email String: "+emailStr);
         var emailPat=/(.+)@(.+)/;
         var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
         var validChars="\[^\\s" + specialChars + "\]"
         var quotedUser="(\"[^\"]*\")";
         var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
         var atom=validChars + '+';
         var word="(" + atom + "|" + quotedUser + ")";
         var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
         var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
         var matchArray=emailStr.match(emailPat);
         if (matchArray==null)
             {
             alert("Email address seems incorrect (check @ and .'s)");
	     form.select();
             return false;
             }
         var user=matchArray[1]
         var domain=matchArray[2]
 
         if (user.match(userPat)==null)
             {
             alert("The email username doesn't seem to be valid.");
	     form.select();
             return false;
             }
 
         var IPArray=domain.match(ipDomainPat);
         if (IPArray!=null)
             {
             for (var i=1;i<=4;i++)
                  {
                  if (IPArray[i]>255)
                      {
                      alert("Email Destination IP address is invalid!");
	              form.select();
                      return false;
                      }
                  }
                 //return true;
             }
 
         var domainArray=domain.match(domainPat)
         if (domainArray==null)
             {
             alert("The email domain name doesn't seem to be valid.");
	     form.select();
             return false;
             }
 
         var atomPat=new RegExp(atom,"g");
         var domArr=domain.match(atomPat);
         var len=domArr.length;
         if (domArr[domArr.length-1].length<2 ||
             domArr[domArr.length-1].length>3)
             {
             alert("The email address must end in a three-letter domain, or two letter country.");
	     form.select();
             return false;
             }
 
         if (len<2)
             {
             var errStr="This email address is missing a hostname!";
             alert(errStr);
	     form.select();
             return false;
             }
 
         return true;
     }

function setfocus ()
    {
//    alert("Set Focus");
//    form[1].focus();
 //   form.focus();
  //  alert("Set Focus End");
    document.login_form.fsm_input.focus();
    }

function uidpwCheck (form)
    {
    // FORM: No commas, no leading or trailing white space
    var status;
    var nameStr = form.value;
//    var filtered_name= nameStr.match(/(?<!,)/);
    var comma_pos = nameStr.search(/,/);
//    alert("Name: "+nameStr);
//    alert("Last Char: "+nameStr.substr(nameStr.length-1,1));
//    alert("Filtered: "+filtered_name);

    if (nameStr.charAt(0) == ' ')
        {
	alert("No leading spaces allowed.");
	form.select();
	status = false;
	}
    else if (nameStr.substr(nameStr.length-1,1) == ' ')
        {
	alert("No trailing spaces allowed.");
	form.select();
	status = false;
	}
    else if (comma_pos > 0)
	{
	alert("Commas are not allowed in this field.");
	form.select();
	status = false;
	}
    else
	{
	status = true;
	}

     return( status );
     }

function modify_user_name (form)
    {
    var status;

    alert("WARNING: DO NOT CHANGE THIS FIELD TO REFER TO A DIFFERENT PERSON.  You should only change this field to correct the name of the person this record was originally created for.  For example, you should only change this field to correct a typo in the user's name or to reflect the user's new name if the user has changed their name or wishes to be called by a different name.  If you wish to register other family members you MUST CREATE A NEW AND UNIQUE USER REGISTRATION \(or LOGIN\)  FOR EACH FAMILY MEMBER.  \n\nHint: If registering multiple family members, create the new user registration first family member who is under 18 years old.  Then login to the system and click the 'Update User Information' to update their user record so that the record contains all of the parent/guardian and emergency contact information.  Then logoff and create New User Registrations for your other family members.  When you create a new user registration for the other family members, fill in the User ID/Password in of the first registered family member in the 'Create from Existing User' dialog box in under the New User Registration form.  This will copy all of the parent/guardian and emergency contact information from the first registered user to the registration record of the user you are registering.");

    status = nameCheck(form);
    return( status );
    }


function nameCheck (form)
    {
    // FORM: Aplha chars, no space, allow apostrophe
    var status;
    var nameStr = form.value;
    var filtered_name= nameStr.match(/[a-zA-Z -]*/);
//    alert("Name: "+nameStr);
//    alert("Last Char: "+nameStr.substr(nameStr.length-1,1));
//    alert("Filtered: "+filtered_name);

    if (nameStr.charAt(0) == ' ')
        {
	alert("No leading spaces allowed.");
	form.select();
	status = false;
	}
    else if (nameStr.substr(nameStr.length-1,1) == ' ')
        {
	alert("No trailing spaces allowed.");
	form.select();
	status = false;
	}
    else if (nameStr != filtered_name)
	{
	alert("The name is invalid (Only alphabetic chars allowed).");
	form.select();
	status = false;
	}
    else
	{
	status = true;
	}

     return( status );
     }


function standardCheck (form)
    {
    // FORM: Aplha chars, no space, allow apostrophe
    var status;
    var nameStr = form.value;
//    alert("Name: "+nameStr);
//    alert("Last Char: "+nameStr.substr(nameStr.length-1,1));
//    alert("Filtered: "+filtered_name);

    if (nameStr.charAt(0) == ' ')
        {
	alert("No leading spaces allowed.");
	form.select();
	status = false;
	}
    else if (nameStr.substr(nameStr.length-1,1) == ' ')
        {
	alert("No trailing spaces allowed.");
	form.select();
	status = false;
	}
    else
	{
	status = true;
	}

     return( status );
     }

function phoneCheck (form)
    {
    // FORM: (aaa) eee-nnnn ex. nnnn
    // 
    var status = true;
    var length = form.value.length;
//
    return(status);


    alert("len= "+length);

    if(length == 1)
    {
	if (form.value.charAt(0) == '(')
	{
	    form.value = '';
	}
	else
	{
	    form.value = '(' + form.value;
	}
    }
    else if (length == 4)
    {
	form.value = form.value + ') ';
    }
    else if (length == 5)
    {
	form.value = form.value.substr(0,form.value.length-2);
    }
    else if (length == 9)
    {
	if (form.value.charAt(9) != '-')
	{
	    form.value = form.value.substr(0,form.value.length-2);
	}
	else
	{
//	    form.value = form.value + '-';
	}
    }
    else if (length == 14)
    {
	alert("Autotab");
    }



    return( status );
    }

function onlyNumber(form,digits)
    {
    // Digits = 0 => no check on field length
    // FORM: (aaa) eee-nnnn ex. nnnn
    // 
//    alert("onlyNumber - Value:"+form.value);
//    alert("onlyNumber - Digits:"+digits);
    // NOTE: In order to get the field length we must copy the value to a local
    //       var and take the length of that local var.  Otherwise, if we take
    //       the length of the form.value we will get the number of elements
    //       in form.var.
    var number = form.value;
    var filtered_field= number.match(/[0-9]*/);
    var status;
    if (filtered_field != number)
       {
       alert("Field must consist of numeric values.");
       form.select();
       status = false;
       }
    else if (number.length == 0)
       {
       status = true;
       }
    else if ((number.length != digits) && (digits != 0))
       {
       alert("Field must contain "+digits+" digits.");
       form.select();
       status = false;
       }
    else
       {
	status = true;
       }
//
    return( status );
    }



function confirmPassword(form)
    {
    var pwform = document.User_edit_form.USER_PASSWORD;
    var confirmation = form.value;
    var password= pwform.value;
    var status;

//    alert("Confirmation:"+confirmation);
//    alert("password:"+password);
    if (confirmation != password)
       {
       alert("Passwords do not match.  Please re-type both the password and the confirmation.");
//       form.select();
	pwform.select();

       status = false;
       }
    else
       {
	status = true;
       }
//
    return( status );
    }




function textCounter(field, countfield, maxlimit) 
{
if (field.value.length > maxlimit) // if too long...trim it!
    {
    field.value = field.value.substring(0, maxlimit);
    alert("Text limit exceeded. Please limit your input to "+maxlimit+" characters");
    }
}

function disable_buttons(theform)
{
//alert("Disable Submit Begin");
//    form.submit();
//    form.disabled=true;
//    alert("Disable Submit End");
//    return(1);
var status;
//alert("FSM_INPUT: "+theform.fsm_input.value);
if (document.all || document.getElementById) 
    {
//    alert("Point 1");
    for (i = 0; i < theform.length; i++) 
        {
//	alert("Point 1.5");
	var tempobj = theform.elements[i];
	if (tempobj.type.toLowerCase() == "submit" || 
	    tempobj.type.toLowerCase() == "button" ||
	    tempobj.type.toLowerCase() == "reset")
	    {
//	    alert("Point 2");
//	    theform.fsm_input.value = tempobj.value;
	    tempobj.disabled = true;
//	    alert("SUMBIT BUTTON: "+tempobj.value);
	    }
	}
//    setTimeout('alert("Your form has been submitted.  Notice how the submit and reset buttons were disabled upon submission.")', 000);
//    status = true;
//    alert("Point 3");
    }
else 
    {
//    alert("The form has been submitted.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
//    status = false;
    }

// Unconditionally set the return status to true.  Even if the user is not 
// using IE 4+ or Netscape 6, we still need to allow them to submit the 
// form (and hope they don;t hit the submit button multiple times).
status = true;
//alert("Disable Submit End");
return( status );
}

// -------------------------------------------------------------------

/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Cyanide_7 |  */
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 stripAlphaChars(pstrSource) 
{ 
var m_strOut = new String(pstrSource); 
    m_strOut = m_strOut.replace(/[^0-9]/g, ''); 

    return m_sOut; 
}



