/*
  $Id: general.js,v 1.3 2003/02/10 22:30:55 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

<!--
function mmLoadMenus() {
  if (window.mm_menu_0528062640_0) return;
                            window.mm_menu_0528062640_0_1 = new Menu("Assistive&nbsp;Technology",97,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_1.addMenuItem("Accessories","location='/catalog/index.php?cPath=31_166'");
     mm_menu_0528062640_0_1.fontWeight="bold";
     mm_menu_0528062640_0_1.hideOnMouseOut=true;
     mm_menu_0528062640_0_1.bgColor='#000000';
     mm_menu_0528062640_0_1.menuBorder=1;
     mm_menu_0528062640_0_1.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_1.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_2 = new Menu("Augmentative&nbsp;Communicators",97,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_2.addMenuItem("Accessories","location='/catalog/index.php?cPath=132_159'");
     mm_menu_0528062640_0_2.fontWeight="bold";
     mm_menu_0528062640_0_2.hideOnMouseOut=true;
     mm_menu_0528062640_0_2.bgColor='#000000';
     mm_menu_0528062640_0_2.menuBorder=1;
     mm_menu_0528062640_0_2.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_2.menuBorderBgColor='#000000';
      window.mm_menu_0528062640_0_3_1 = new Menu("Books",129,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
      mm_menu_0528062640_0_3_1.addMenuItem("Reference&nbsp;Books","location='/catalog/index.php?cPath=131_145_146'");
       mm_menu_0528062640_0_3_1.fontWeight="bold";
       mm_menu_0528062640_0_3_1.hideOnMouseOut=true;
       mm_menu_0528062640_0_3_1.bgColor='#000000';
       mm_menu_0528062640_0_3_1.menuBorder=1;
       mm_menu_0528062640_0_3_1.menuLiteBgColor='#000000';
       mm_menu_0528062640_0_3_1.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_3 = new Menu("Autism/PDD",110,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_3.addMenuItem(mm_menu_0528062640_0_3_1,"location='/catalog/index.php?cPath=131_145'");
    mm_menu_0528062640_0_3.addMenuItem("DVDs/Videos","location='/catalog/index.php?cPath=131_147'");
     mm_menu_0528062640_0_3.fontWeight="bold";
     mm_menu_0528062640_0_3.hideOnMouseOut=true;
     mm_menu_0528062640_0_3.childMenuIcon="arrows.gif";
     mm_menu_0528062640_0_3.bgColor='#000000';
     mm_menu_0528062640_0_3.menuBorder=1;
     mm_menu_0528062640_0_3.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_3.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_4 = new Menu("Boardmaker",239,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_4.addMenuItem("Speaking&nbsp;Dynamically&nbsp;Pro&nbsp;Add-On","location='/catalog/index.php?cPath=116_137'");
     mm_menu_0528062640_0_4.fontWeight="bold";
     mm_menu_0528062640_0_4.hideOnMouseOut=true;
     mm_menu_0528062640_0_4.bgColor='#000000';
     mm_menu_0528062640_0_4.menuBorder=1;
     mm_menu_0528062640_0_4.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_4.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_5 = new Menu("Books",129,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_5.addMenuItem("Reference&nbsp;Books","location='/catalog/index.php?cPath=134_143'");
     mm_menu_0528062640_0_5.fontWeight="bold";
     mm_menu_0528062640_0_5.hideOnMouseOut=true;
     mm_menu_0528062640_0_5.bgColor='#000000';
     mm_menu_0528062640_0_5.menuBorder=1;
     mm_menu_0528062640_0_5.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_5.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_6 = new Menu("Functional&nbsp;Living/Adaptive&nbsp;Behaviour",150,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_6.addMenuItem("Books&nbsp;and&nbsp;Materials","location='/catalog/index.php?cPath=154_156'");
    mm_menu_0528062640_0_6.addMenuItem("Software","location='/catalog/index.php?cPath=154_155'");
     mm_menu_0528062640_0_6.fontWeight="bold";
     mm_menu_0528062640_0_6.hideOnMouseOut=true;
     mm_menu_0528062640_0_6.bgColor='#000000';
     mm_menu_0528062640_0_6.menuBorder=1;
     mm_menu_0528062640_0_6.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_6.menuBorderBgColor='#000000';
      window.mm_menu_0528062640_0_7_1 = new Menu("Keyboards",140,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
      mm_menu_0528062640_0_7_1.addMenuItem("Writer&nbsp;Accessories","location='/catalog/index.php?cPath=29_160_129'");
       mm_menu_0528062640_0_7_1.fontWeight="bold";
       mm_menu_0528062640_0_7_1.hideOnMouseOut=true;
       mm_menu_0528062640_0_7_1.bgColor='#000000';
       mm_menu_0528062640_0_7_1.menuBorder=1;
       mm_menu_0528062640_0_7_1.menuLiteBgColor='#000000';
       mm_menu_0528062640_0_7_1.menuBorderBgColor='#000000';
      window.mm_menu_0528062640_0_7_2 = new Menu("Mounting&nbsp;Systems",97,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
      mm_menu_0528062640_0_7_2.addMenuItem("Accessories","location='/catalog/index.php?cPath=29_149_125'");
       mm_menu_0528062640_0_7_2.fontWeight="bold";
       mm_menu_0528062640_0_7_2.hideOnMouseOut=true;
       mm_menu_0528062640_0_7_2.bgColor='#000000';
       mm_menu_0528062640_0_7_2.menuBorder=1;
       mm_menu_0528062640_0_7_2.menuLiteBgColor='#000000';
       mm_menu_0528062640_0_7_2.menuBorderBgColor='#000000';
      window.mm_menu_0528062640_0_7_3 = new Menu("Switches/Controls",155,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
      mm_menu_0528062640_0_7_3.addMenuItem("Accessories","location='/catalog/index.php?cPath=29_39_127'");
      mm_menu_0528062640_0_7_3.addMenuItem("Connectors/Adaptors","location='/catalog/index.php?cPath=29_39_126'");
       mm_menu_0528062640_0_7_3.fontWeight="bold";
       mm_menu_0528062640_0_7_3.hideOnMouseOut=true;
       mm_menu_0528062640_0_7_3.bgColor='#000000';
       mm_menu_0528062640_0_7_3.menuBorder=1;
       mm_menu_0528062640_0_7_3.menuLiteBgColor='#000000';
       mm_menu_0528062640_0_7_3.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_7 = new Menu("Hardware",135,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_7.addMenuItem(mm_menu_0528062640_0_7_1,"location='/catalog/index.php?cPath=29_160'");
    mm_menu_0528062640_0_7.addMenuItem(mm_menu_0528062640_0_7_2,"location='/catalog/index.php?cPath=29_149'");
    mm_menu_0528062640_0_7.addMenuItem("Mouse&nbsp;Emulators","location='/catalog/index.php?cPath=29_167'");
    mm_menu_0528062640_0_7.addMenuItem(mm_menu_0528062640_0_7_3,"location='/catalog/index.php?cPath=29_39'");
     mm_menu_0528062640_0_7.fontWeight="bold";
     mm_menu_0528062640_0_7.hideOnMouseOut=true;
     mm_menu_0528062640_0_7.childMenuIcon="arrows.gif";
     mm_menu_0528062640_0_7.bgColor='#000000';
     mm_menu_0528062640_0_7.menuBorder=1;
     mm_menu_0528062640_0_7.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_7.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_8 = new Menu("Language/Speech",164,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_8.addMenuItem("Professional&nbsp;Resources","location='/catalog/index.php?cPath=152_158'");
     mm_menu_0528062640_0_8.fontWeight="bold";
     mm_menu_0528062640_0_8.hideOnMouseOut=true;
     mm_menu_0528062640_0_8.bgColor='#000000';
     mm_menu_0528062640_0_8.menuBorder=1;
     mm_menu_0528062640_0_8.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_8.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_9 = new Menu("Miscellaneous&nbsp;Products",176,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_9.addMenuItem("CDs,&nbsp;DVDs,&nbsp;and&nbsp;Videos","location='/catalog/index.php?cPath=142_144'");
     mm_menu_0528062640_0_9.fontWeight="bold";
     mm_menu_0528062640_0_9.hideOnMouseOut=true;
     mm_menu_0528062640_0_9.bgColor='#000000';
     mm_menu_0528062640_0_9.menuBorder=1;
     mm_menu_0528062640_0_9.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_9.menuBorderBgColor='#000000';
    window.mm_menu_0528062640_0_10 = new Menu("Software",123,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
    mm_menu_0528062640_0_10.addMenuItem("Pictures/Images","location='/catalog/index.php?cPath=30_141'");
    mm_menu_0528062640_0_10.addMenuItem("Switch/Scanning","location='/catalog/index.php?cPath=30_133'");
     mm_menu_0528062640_0_10.fontWeight="bold";
     mm_menu_0528062640_0_10.hideOnMouseOut=true;
     mm_menu_0528062640_0_10.bgColor='#000000';
     mm_menu_0528062640_0_10.menuBorder=1;
     mm_menu_0528062640_0_10.menuLiteBgColor='#000000';
     mm_menu_0528062640_0_10.menuBorderBgColor='#000000';
  window.mm_menu_0528062640_0 = new Menu("root",250,18,"Arial, Helvetica, sans-serif",12,"#0000FF","#0000FF","#FFFFFF","#FCE22F","left","middle",3,0,500,-5,7,true,true,true,3,true,true);
  mm_menu_0528062640_0.addMenuItem("Assessment&nbsp;Material","location='/catalog/index.php?cPath=168'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_1,"location='/catalog/index.php?cPath=31'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_2,"location='/catalog/index.php?cPath=132'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_3,"location='/catalog/index.php?cPath=131'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_4,"location='/catalog/index.php?cPath=116'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_5,"location='/catalog/index.php?cPath=134'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_6,"location='/catalog/index.php?cPath=154'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_7,"location='/catalog/index.php?cPath=29'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_8,"location='/catalog/index.php?cPath=152'");
  mm_menu_0528062640_0.addMenuItem("Literacy:&nbsp;Reading/Writing","location='/catalog/index.php?cPath=130'");
  mm_menu_0528062640_0.addMenuItem("Manipulatives","location='/catalog/index.php?cPath=115'");
  mm_menu_0528062640_0.addMenuItem("Mathematics","location='/catalog/index.php?cPath=151'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_9,"location='/catalog/index.php?cPath=142'");
  mm_menu_0528062640_0.addMenuItem("New&nbsp;Products","location='/catalog/index.php?cPath=140'");
  mm_menu_0528062640_0.addMenuItem("Other&nbsp;Disabilities","location='/catalog/index.php?cPath=157'");
  mm_menu_0528062640_0.addMenuItem("Preschool&nbsp;Level","location='/catalog/index.php?cPath=163'");
  mm_menu_0528062640_0.addMenuItem("Portability","location='/catalog/index.php?cPath=165'");
  mm_menu_0528062640_0.addMenuItem("Science/Nature","location='/catalog/index.php?cPath=162'");
  mm_menu_0528062640_0.addMenuItem("Social&nbsp;Skills/Behaviour","location='/catalog/index.php?cPath=153'");
  mm_menu_0528062640_0.addMenuItem(mm_menu_0528062640_0_10,"location='/catalog/index.php?cPath=30'");
  mm_menu_0528062640_0.addMenuItem("Toys/Games","location='/catalog/index.php?cPath=148'");
   mm_menu_0528062640_0.fontWeight="bold";
   mm_menu_0528062640_0.hideOnMouseOut=true;
   mm_menu_0528062640_0.childMenuIcon="arrows.gif";
   mm_menu_0528062640_0.bgColor='#000000';
   mm_menu_0528062640_0.menuBorder=1;
   mm_menu_0528062640_0.menuLiteBgColor='#000000';
   mm_menu_0528062640_0.menuBorderBgColor='#000000';

mm_menu_0528062640_0.writeMenus();
} // mmLoadMenus()



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];}
}
