// Date picker functions

function do_cal( control_name, rownum, function_name )
{
   if( function_name == 'mainlist' && document.inputform['f' + rownum + '_select'] )
      document.inputform['f' + rownum + '_select'].checked = true;
   if( function_name == 'feature' && document.inputform['i_' + rownum] )
      document.inputform['i_' + rownum].checked = true;
//   if( document.inputform[ rownum + '_select'] )
//      document.inputform[ rownum + '_select' ].checked = true;
   var cal = document.getElementById('cal_' + control_name );
   if( cal.style.display == '' )
   {
      cal.style.display = 'none';
      return;
   }
   document.getElementById('frame_' + control_name ).src='/html/other/popup/datepicker/datepicker.html?' + control_name + ',' + document.inputform[control_name].value + ',inputform';
   document.getElementById('frame_' + control_name ).style.display = '';
}

function pick( control_name, rownum, function_name )
{
   var s = '';
   // if not IE, or it's a Mac browser, use the alternate date picker
   if( !document.all || browser_mac == 'true' )
      return;

   s += '<A onMouseOver="window.status=\'Pick Date\'; return(true);" onMouseOut="window.status=\'\';return(true);" ';
   s += 'HREF="javascript:do_cal(\'' + control_name + '\',\'' + rownum + '\',\'' + function_name + '\');';
   s += '">';
   s += '<img src="/images/datepicker.gif" border="0" style="cursor:hand;" alt="Select date"></A>';
   s += '<div id="cal_' + control_name + '" style="position:absolute;display:none;">';
   s += '<iframe name="frame_' + control_name + '" id="frame_' + control_name + '" frameborder="1" scrolling="no" width="183" height="201" src=""></iframe>';
   s += '</div>&nbsp;';

   document.write( s );
}


// this function applies to the Netscape date picker
function showhide( groupID )
{
   if( !document.all[groupID] )
      return;
   if( document.all[groupID].length > 1 )
      for( var x = 0; x < document.all[groupID].length; x++ )
         document.all[groupID][x].style.display = (document.all[groupID][x].style.display == 'none' ? '' : 'none' );
   else
      document.all[groupID].style.display = (document.all[groupID].style.display == 'none' ? '' : 'none' );
   document.all[groupID + '_pm'].innerHTML = (document.all[groupID + '_pm'].innerHTML == '+' ? '-' : '+' );
}
// Closes the features 
// this function applies to the Netscape date picker
function pageloader()
{ 
	for (x=1;x<10;x++)
  		showhide('tr_0' + x);
  for (x=10;x<30;x++)
			showhide('tr_' + x);
	
	}
  
// this function applies to the Netscape date picker
function popUpCenteredWindow() {
	var iMyWidth;
	var iMyHeight;
	//gets top and left positions based on user's resolution so hint window is centered.
	iMyWidth = (window.screen.width/2) - (30 + 10); //half the screen width minus half the new window width (plus 5 pixel borders[ADD 25 FOR SCROLL).
	iMyHeight = (window.screen.height/2) - (125 + 25); //half the screen height minus half the new window height (plus title bar).
	var win2 = window.open("/html/search/fullsearchtemplate/use/NS_calendar.html","cal","height=250,width=200,resizable=no,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",scrollbars=no,menubar=no,directories=no,location=no,toolbar=no,status=no");
	win2.focus();
}


// verification functions

function key_check()
{
   if( document.all ) // IE
   {
     if( event && event.keyCode )
     {
        if( event.keyCode == 8 )  // 8 == backspace
        {
           event.keyCode = 0;
           return true;
        }
     }
     return false;
   }
}

function verifyint( string )
{
   string = '' + string; // `#-- make sure it's a string --#`
   var num = parseInt( string );

   if( isNaN( num ) )
      return '';


   // `#-- parseInt does octal and hex conversions, which is not desired.
   //  #-- must solve this problem by manually stripping bad characters. --#`
   num = string.replace(/[^-\d]/gi,"");

   return num;
}

function verifyfloat( string )
{
   string = '' + string; // `#-- make sure it's a string --#`
   var num = parseFloat( string );

   if( isNaN( num ) )
      return '';


   // `#-- parseFloat does octal and hex conversions, which is not desired.
   //  #-- must solve this problem by manually stripping bad characters. --#`
   num = string.replace(/[^\d.-]/gi,"");

   return num;
}

function verifydate( string )
{
   string = '' + string; // `#-- make sure it's a string --#`

   num = string.replace(/[^\d.-\/]/gi,"");

   return num;
}

function showlist( field_id, fieldcount, card_fmt_list, table_name, maxlength )
{
   var prefill_value = document.inputform[field_id].value;

   if( find_parent )
   {
      var parent_field = find_parent( field_id );
      if(parent_field)
      {
         // find parent's checkbox
         var inputs = document.getElementsByTagName('input');
         var parent_checked;
         for(var i=0; i < inputs.length; ++i)
         {
            if(inputs[i].type == 'checkbox' && inputs[i].value == parent_field)
            {
               parent_checked = inputs[i].checked;
               break;
            }
         }

         var pf = document.getElementById( parent_field );
         var val_list = '';
         if( parent_checked && pf && pf.options )
         {
            for(var i=0; i < pf.options.length; ++i)
            {
               if(pf.options[i].selected)
                  val_list += (val_list ? ',' : '') + pf.options[i].value;
            }
         }
      }
   }

   var f = document.lookupform;
   f.table_name.value = table_name;
   f.field_id.value = field_id;
   f.form_field.value = field_id;
   f.check_field.value = 'f' + fieldcount + '_select';
   f.maxlength.value = maxlength;
   f.card_fmt_list.value = card_fmt_list;
   f.prefill_value.value = prefill_value;
   if(parent_field)
   {
      f.parent_val_list.value = val_list;
      f.parent_field.value = parent_field;
   }

   var w = window.open("about:blank","Field","height=250,width=450,resizable=yes,scrollbars=no,menubar=no,directories=no,location=no,toolbar=no,status=no");

   f.target = 'Field';
   f.submit();

   if( w.focus )
      w.focus();
}

function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}

function pre_submit()
{
   var f = document.inputform;
   // for quick search on list number only
   if ( f.list && trimString(f.list.value) != '' )
   { 
      f.cmd.value = list_num_cmd;
   }
   else
   {  //alert(other_search_cmd);
      f.cmd.value = other_search_cmd;
   }
   return true;
}
