[ Index ] |
|
Code source de osCommerce 2.2ms2-060817 |
1 /* 2 $Id: general.js,v 1.3 2003/02/10 22:30:55 hpdl Exp $ 3 4 osCommerce, Open Source E-Commerce Solutions 5 http://www.oscommerce.com 6 7 Copyright (c) 2003 osCommerce 8 9 Released under the GNU General Public License 10 */ 11 12 function SetFocus(TargetFormName) { 13 var target = 0; 14 if (TargetFormName != "") { 15 for (i=0; i<document.forms.length; i++) { 16 if (document.forms[i].name == TargetFormName) { 17 target = i; 18 break; 19 } 20 } 21 } 22 23 var TargetForm = document.forms[target]; 24 25 for (i=0; i<TargetForm.length; i++) { 26 if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) { 27 TargetForm.elements[i].focus(); 28 29 if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) { 30 TargetForm.elements[i].select(); 31 } 32 33 break; 34 } 35 } 36 } 37 38 function RemoveFormatString(TargetElement, FormatString) { 39 if (TargetElement.value == FormatString) { 40 TargetElement.value = ""; 41 } 42 43 TargetElement.select(); 44 } 45 46 function CheckDateRange(from, to) { 47 if (Date.parse(from.value) <= Date.parse(to.value)) { 48 return true; 49 } else { 50 return false; 51 } 52 } 53 54 function IsValidDate(DateToCheck, FormatString) { 55 var strDateToCheck; 56 var strDateToCheckArray; 57 var strFormatArray; 58 var strFormatString; 59 var strDay; 60 var strMonth; 61 var strYear; 62 var intday; 63 var intMonth; 64 var intYear; 65 var intDateSeparatorIdx = -1; 66 var intFormatSeparatorIdx = -1; 67 var strSeparatorArray = new Array("-"," ","/","."); 68 var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"); 69 var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 70 71 strDateToCheck = DateToCheck.toLowerCase(); 72 strFormatString = FormatString.toLowerCase(); 73 74 if (strDateToCheck.length != strFormatString.length) { 75 return false; 76 } 77 78 for (i=0; i<strSeparatorArray.length; i++) { 79 if (strFormatString.indexOf(strSeparatorArray[i]) != -1) { 80 intFormatSeparatorIdx = i; 81 break; 82 } 83 } 84 85 for (i=0; i<strSeparatorArray.length; i++) { 86 if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) { 87 intDateSeparatorIdx = i; 88 break; 89 } 90 } 91 92 if (intDateSeparatorIdx != intFormatSeparatorIdx) { 93 return false; 94 } 95 96 if (intDateSeparatorIdx != -1) { 97 strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]); 98 if (strFormatArray.length != 3) { 99 return false; 100 } 101 102 strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]); 103 if (strDateToCheckArray.length != 3) { 104 return false; 105 } 106 107 for (i=0; i<strFormatArray.length; i++) { 108 if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') { 109 strMonth = strDateToCheckArray[i]; 110 } 111 112 if (strFormatArray[i] == 'dd') { 113 strDay = strDateToCheckArray[i]; 114 } 115 116 if (strFormatArray[i] == 'yyyy') { 117 strYear = strDateToCheckArray[i]; 118 } 119 } 120 } else { 121 if (FormatString.length > 7) { 122 if (strFormatString.indexOf('mmm') == -1) { 123 strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2); 124 } else { 125 strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3); 126 } 127 128 strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2); 129 strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2); 130 } else { 131 return false; 132 } 133 } 134 135 if (strYear.length != 4) { 136 return false; 137 } 138 139 intday = parseInt(strDay, 10); 140 if (isNaN(intday)) { 141 return false; 142 } 143 if (intday < 1) { 144 return false; 145 } 146 147 intMonth = parseInt(strMonth, 10); 148 if (isNaN(intMonth)) { 149 for (i=0; i<strMonthArray.length; i++) { 150 if (strMonth == strMonthArray[i]) { 151 intMonth = i+1; 152 break; 153 } 154 } 155 if (isNaN(intMonth)) { 156 return false; 157 } 158 } 159 if (intMonth > 12 || intMonth < 1) { 160 return false; 161 } 162 163 intYear = parseInt(strYear, 10); 164 if (isNaN(intYear)) { 165 return false; 166 } 167 if (IsLeapYear(intYear) == true) { 168 intDaysArray[1] = 29; 169 } 170 171 if (intday > intDaysArray[intMonth - 1]) { 172 return false; 173 } 174 175 return true; 176 } 177 178 function IsLeapYear(intYear) { 179 if (intYear % 100 == 0) { 180 if (intYear % 400 == 0) { 181 return true; 182 } 183 } else { 184 if ((intYear % 4) == 0) { 185 return true; 186 } 187 } 188 189 return false; 190 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 19:48:25 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |