home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1996, 1997 Netscape Communications Corporation, All rights reserved.
-
- var prefs = parent.prefs;
- var configs = parent.configs;
- var gp = parent;
- var focusfield;
-
- // -- auto controls
- var type_string = 1;
- var type_number = 2;
- var type_bool = 3; // Associates true w/ checked
- var type_bool2 = 9; // Associates false w/ checked
- var type_bool3 = 10; // Associates "true" w/ checked
- var type_radio1 = 4; // Associates true/false
- var type_radio2 = 5; // Associates "true"/"false"
- var type_radio3 = 6; // Associates string with the buttons
- var type_string2 = 7;
- var type_select1 = 8;
-
- function mapper(control_name, lock_name, pref_name, type)
- {
- this.control_name = control_name;
- this.pref_name = pref_name;
- this.type = type;
- this.lock_name = lock_name;
- }
-
- // Takes the mapping of controls to XPprefs specified in mappers
- // and fills in the controls with the corresponding pref values.
- function initValue()
- {
- var dp = document.prefsform;
-
- for (i = 0; i < mappers.length; i++)
- {
- var map = mappers[i];
- var pref = gp.get_pref(map.pref_name, prefs);
- var selector = (map.type == type_bool) ? "checked" : "value";
-
- if ((pref!=null) && (pref.default_value!=null))
- {
- if ((map.type == type_radio1) || (map.type == type_select1))
- {
- var setter = (map.type == type_radio1) ? "checked" : "selected";
- for (j=0; j < dp[map.control_name].length; j++)
- {
- if (parseInt(dp[map.control_name][j].value)==pref.default_value)
- dp[map.control_name][j][setter]=true;
- }
- }
- if (map.type == type_radio2) {
- for (j=0; j < dp[map.control_name].length; j++)
- {
- if ( ((dp[map.control_name][j].value=="true") && (pref.default_value==true)) ||
- ((dp[map.control_name][j].value=="false") && (pref.default_value==false)) )
- dp[map.control_name][j].checked=true;
- }
- }
- if (map.type == type_radio3) {
- dbgMsg("Pref: " + pref.default_value);
- for (j=0; j < dp[map.control_name].length; j++)
- {
- dbgMsg("Control: " + dp[map.control_name][j].value);
- if(dp[map.control_name][j].value == pref.default_value)
- dp[map.control_name][j].checked = true;
- }
- }
-
- if (map.type == type_bool2)
- {
- if (pref.default_value==false) dp[map.control_name].checked=true;
- if (pref.default_value==true) dp[map.control_name].checked=false;
- }
- else {
- dp[ map.control_name ][selector] = pref.default_value;
- }
-
- if (map.type == type_bool3)
- {
- if (pref.default_value=="false") dp[map.control_name].checked=false;
- if (pref.default_value=="true") dp[map.control_name].checked=true;
- }
- else {
- dp[ map.control_name ][selector] = pref.default_value;
- }
-
- if (map.lock_name!="") dp[map.lock_name].checked = pref.locked;
- }
- }
- }
-
- // Takes the mapping of controls to XPprefs specified in mappers
- // and updates the pref values with the values in the correspoding controls
- function doCommit()
- {
- var dp = document.prefsform;
-
- for (i = 0; i < mappers.length; i++)
- {
- var map = mappers[i];
-
- var isLocked = (map.lock_name=="") ? false : dp[map.lock_name].checked;
- if ( (map.type == type_radio1) || (map.type == type_select1) )
- {
- var setter = (map.type == type_radio1) ? "checked" : "selected";
- for (j=0; j<dp[map.control_name].length; j++)
- {
- if (dp[map.control_name][j][setter]==true)
- gp.set_pref(map.pref_name,
- parseInt(dp[map.control_name][j].value),
- isLocked);
- }
- }
- else if (map.type == type_radio2)
- {
- gp.set_pref(map.pref_name, false, isLocked);
- for (j=0; j<dp[map.control_name].length; j++)
- {
- if (dp[map.control_name][j].checked==true)
- if (dp[map.control_name][j].value=="true")
- gp.set_pref(map.pref_name, true, isLocked);
- else if (dp[map.control_name][j].value=="false")
- gp.set_pref(map.pref_name, false, isLocked);
- }
- }
- else if (map.type == type_radio3)
- {
- for (j=0; j<dp[map.control_name].length; j++)
- {
- if (dp[map.control_name][j].checked==true)
- gp.set_pref(map.pref_name, dp[map.control_name][j].value, isLocked);
- }
- }
- else if (map.type == type_bool2)
- {
- if (dp[map.control_name].checked==true)
- gp.set_pref(map.pref_name, false, isLocked);
- else
- gp.set_pref(map.pref_name, true, isLocked);
- }
- else if (map.type == type_bool3)
- {
- if (dp[map.control_name].checked==true)
- gp.set_pref(map.pref_name, "true", isLocked);
- else
- gp.set_pref(map.pref_name, "false", isLocked);
- }
- else if (map.type == type_number)
- {
- if (dp[map.control_name].value!="")
- gp.set_pref(map.pref_name,
- parseInt( dp[ map.control_name ].value ),
- isLocked);
- }
- else
- {
- var selector = (map.type == type_bool) ? "checked" : "value";
- gp.set_pref(map.pref_name,
- dp[ map.control_name ][selector],
- isLocked);
- }
- }
- }
-
- function isANumber (checkstring)
- {
- for (var i=0; i<checkstring.length; i++)
- {
- if (isNaN(parseInt(checkstring.substring(i,i+1))))
- return false
- }
- return(true);
- }
-
- function verifyIsANumber(field)
- {
- focusfield = field;
- if (! isANumber(field.value))
- {
- setTimeout("alert('This field must contain a number');focusfield.focus();",300);
- }
- }
-
- // should check to make sure it starts with # and contains only
- // 0-9 and A-F
- function verifyIsAColor(field)
- {
- return(true);
- // alert("Colors must be in the format \"#nnnnnn\" where n is a hexidecimal digit");
- }
-