[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/ -> general.js (source)

   1  //

   2  // +----------------------------------------------------------------------+

   3  // |zen-cart Open Source E-commerce                                       |

   4  // +----------------------------------------------------------------------+

   5  // | Copyright (c) 2003 The zen-cart developers                           |

   6  // |                                                                      |   

   7  // | http://www.zen-cart.com/index.php                                    |   

   8  // |                                                                      |   

   9  // | Portions Copyright (c) 2003 osCommerce                               |

  10  // +----------------------------------------------------------------------+

  11  // | This source file is subject to version 2.0 of the GPL license,       |

  12  // | that is bundled with this package in the file LICENSE, and is        |

  13  // | available through the world-wide-web at the following url:           |

  14  // | http://www.zen-cart.com/license/2_0.txt.                             |

  15  // | If you did not receive a copy of the zen-cart license and are unable |

  16  // | to obtain it through the world-wide-web, please send a note to       |

  17  // | license@zen-cart.com so we can mail you a copy immediately.          |

  18  // +----------------------------------------------------------------------+

  19  // $Id: general.js 1105 2005-04-04 22:05:35Z birdbrain $

  20  //

  21  
  22  function SetFocus(TargetFormName) {
  23    var target = 0;
  24    if (TargetFormName != "") {
  25      for (i=0; i<document.forms.length; i++) {
  26        if (document.forms[i].name == TargetFormName) {
  27          target = i;
  28          break;
  29        }
  30      }
  31    }
  32  
  33    var TargetForm = document.forms[target];
  34      
  35    for (i=0; i<TargetForm.length; i++) {
  36      if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
  37        TargetForm.elements[i].focus();
  38  
  39        if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
  40          TargetForm.elements[i].select();
  41        }
  42  
  43        break;
  44      }
  45    }
  46  }
  47  
  48  function RemoveFormatString(TargetElement, FormatString) {
  49    if (TargetElement.value == FormatString) {
  50      TargetElement.value = "";
  51    }
  52  
  53    TargetElement.select();
  54  }
  55  
  56  function CheckDateRange(from, to) {
  57    if (Date.parse(from.value) <= Date.parse(to.value)) {
  58      return true;
  59    } else {
  60      return false;
  61    }
  62  }
  63  
  64  function IsValidDate(DateToCheck, FormatString) {
  65    var strDateToCheck;
  66    var strDateToCheckArray;
  67    var strFormatArray;
  68    var strFormatString;
  69    var strDay;
  70    var strMonth;
  71    var strYear;
  72    var intday;
  73    var intMonth;
  74    var intYear;
  75    var intDateSeparatorIdx = -1;
  76    var intFormatSeparatorIdx = -1;
  77    var strSeparatorArray = new Array("-"," ","/",".");
  78    var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  79    var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
  80  
  81    strDateToCheck = DateToCheck.toLowerCase();
  82    strFormatString = FormatString.toLowerCase();
  83    
  84    if (strDateToCheck.length != strFormatString.length) {
  85      return false;
  86    }
  87  
  88    for (i=0; i<strSeparatorArray.length; i++) {
  89      if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
  90        intFormatSeparatorIdx = i;
  91        break;
  92      }
  93    }
  94  
  95    for (i=0; i<strSeparatorArray.length; i++) {
  96      if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
  97        intDateSeparatorIdx = i;
  98        break;
  99      }
 100    }
 101  
 102    if (intDateSeparatorIdx != intFormatSeparatorIdx) {
 103      return false;
 104    }
 105  
 106    if (intDateSeparatorIdx != -1) {
 107      strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
 108      if (strFormatArray.length != 3) {
 109        return false;
 110      }
 111  
 112      strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
 113      if (strDateToCheckArray.length != 3) {
 114        return false;
 115      }
 116  
 117      for (i=0; i<strFormatArray.length; i++) {
 118        if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
 119          strMonth = strDateToCheckArray[i];
 120        }
 121  
 122        if (strFormatArray[i] == 'dd') {
 123          strDay = strDateToCheckArray[i];
 124        }
 125  
 126        if (strFormatArray[i] == 'yyyy') {
 127          strYear = strDateToCheckArray[i];
 128        }
 129      }
 130    } else {
 131      if (FormatString.length > 7) {
 132        if (strFormatString.indexOf('mmm') == -1) {
 133          strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
 134        } else {
 135          strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
 136        }
 137  
 138        strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
 139        strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
 140      } else {
 141        return false;
 142      }
 143    }
 144  
 145    if (strYear.length != 4) {
 146      return false;
 147    }
 148  
 149    intday = parseInt(strDay, 10);
 150    if (isNaN(intday)) {
 151      return false;
 152    }
 153    if (intday < 1) {
 154      return false;
 155    }
 156  
 157    intMonth = parseInt(strMonth, 10);
 158    if (isNaN(intMonth)) {
 159      for (i=0; i<strMonthArray.length; i++) {
 160        if (strMonth == strMonthArray[i]) {
 161          intMonth = i+1;
 162          break;
 163        }
 164      }
 165      if (isNaN(intMonth)) {
 166        return false;
 167      }
 168    }
 169    if (intMonth > 12 || intMonth < 1) {
 170      return false;
 171    }
 172  
 173    intYear = parseInt(strYear, 10);
 174    if (isNaN(intYear)) {
 175      return false;
 176    }
 177    if (IsLeapYear(intYear) == true) {
 178      intDaysArray[1] = 29;
 179    }
 180  
 181    if (intday > intDaysArray[intMonth - 1]) {
 182      return false;
 183    }
 184    
 185    return true;
 186  }
 187  
 188  function IsLeapYear(intYear) {
 189    if (intYear % 100 == 0) {
 190      if (intYear % 400 == 0) {
 191        return true;
 192      }
 193    } else {
 194      if ((intYear % 4) == 0) {
 195        return true;
 196      }
 197    }
 198  
 199    return false;
 200  }


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics