// ********************************** // ** C O O K I E M O N S T E R ** // ** By Dan Searle March 2001 ** // ********************************** // Create expiry time/date for all cookies. // Currently set to : one month from today today = new Date() ; month = today.getMonth() + 1 ; year = today.getYear() ; date = today.getDate() if ( year < 1000 ) { year += 1900 } // Correct Netscape year bug if ( month > 11 ) { month = 0 ; year++ } // If Dec, make it Jan of next year. var expirydate = new Date(year,month,date) // Create Cookie Function function setCookie (name,value,expires,path,domain,secure) { document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); } // Return value of cookie 'name' function getCookie(name) { var cookie = " " + document.cookie var search = " " + name + "=" var setStr = null var offset = 0 var end = 0 if (cookie.length > 0) { offset = cookie.indexOf(search) if (offset != -1) { offset += search.length end = cookie.indexOf(";", offset) if (end == -1) { end = cookie.length } setStr = unescape(cookie.substring(offset, end)) } } return setStr } // Delete Cookie (sets cookie's expiry date to 1970) function expireCookie (name,path,domain) { if (getCookie(name)) { document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT"; } } function deleteCookies(thisform){ for ( c = 0 ; c < thisform.elements.length ; c++ ) { field = thisform.elements[c]; if ( field.type == "checkbox" ) { expireCookie(field.name+'-'+c,"/"); //alert (field.name+'-'+c+" expiring cookie"); }else{ expireCookie(field.name,"/"); } // alert (field.name+" expiring cookie"); } } // Saves any text, select lists (not multiple) values in cookies // Field's name is used for cookie name function saveFields(thisform){ for ( c = 0 ; c < thisform.elements.length ; c++ ) { field = thisform.elements[c]; if ( field.type == "text" ) { setCookie(field.name,field.value,expirydate,"/") } else if ( field.type == "select-one" || field.type == "select-multiple") { for ( lc = 0 ; lc < field.length; lc++ ) { if ( field[lc].selected ) { setCookie(field.name,field[lc].value,expirydate,"/") } } } else if (field.type == "checkbox"){ if ( field.checked ) { setCookie(field.name+'-'+c,field.value,expirydate,"/") } } } } // Looks for a cookie of each field's name and if there is one, fills the field with the cookies value function fillFields(thisform){ for ( c = 0 ; c < thisform.elements.length ; c++ ) { field = thisform.elements[c] //alert(field.name+" is of type "+field.type+", numb of elements in the form "+thisform.elements.length); if (field.type == "checkbox") { cookval = getCookie(field.name+'-'+c); } else { cookval = getCookie(field.name); } if (cookval != null) { if ( field.type == "text" ) { field.value = cookval } else if (field.type == "select-one" || field.type == "select-multiple") { //alert(thisform.name+" name : feild length"+field.length); for (lc = 0 ; lc < field.length ; lc++) { if (field[lc].value == cookval) { field.selectedIndex = lc; if (field.name == 'make') { //alert(field.name+" "+makeForm.make.options[makeForm.make.selectedIndex].value+" "+field.length); populateModel(thisform,thisform.make.options[thisform.make.selectedIndex].value); } if (field.name == 'make2'){ populateModel2(makeForm2,makeForm2.make2.options[makeForm2.make2.selectedIndex].value); //alert('I am back2'); } if (field.name == 'make3'){ populateModel3(makeForm3,makeForm3.make3.options[makeForm3.make3.selectedIndex].value); //alert('I am back3'); } } // alert("dealing with element number (of select):"+lc); } } else if (field.type == "checkbox"){ if ( field.value == cookval ) { field.checked = true; } } } //alert('have finished dealing with control '+c+' ('+field.name+') of '+thisform.elements.length+' name: '+thisform.name); } }