function checkField( theField, fldLabel, type )
{
	var fOK = true;
	var errorString;
	
	if ( fOK && ( theField.value == '' ) )
	{
		fOK = false;
		errorString = fldLabel + ' må fylles ut';
		alert( errorString );
	}
	if ( !fOK )
		theField.focus();
	return fOK;
}
function checkField2( theField, fldLabel, type, msg2 )
{
	var fOK = true;
	var errorString;
	
	if ( fOK && ( theField.value == '' ) )
	{
		fOK = false;
		errorString = fldLabel + ' ' + msg2;
		alert( errorString );
	}
	if ( !fOK )
		theField.focus();
	return fOK;
}
function isEmail(theField,str) {
 	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_@.";
  	var checkStr = str; // theField.value;
	var fOK = true;
	if (!theField.value == "") {
		if (theField.value.indexOf("@") > 0 && checkStr.length - theField.value.indexOf("@") > 5 && theField.value.indexOf(".") != -1) {
			for (i = 0;  i < checkStr.length;  i++) {
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkOK.length;  j++)
					if (ch == checkOK.charAt(j))
						break;
		    	if (j == checkOK.length) {
					fOK = false;
					break;
				}
	 		}
		}
		else {
			fOK = false;
		}
	} 
	else {
		fOK = false;
	}
	if (!fOK) {
		alert("Feil format på e-postadressen");
		theField.focus();
		theField.select();
	}
	return (fOK);
}


function getFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
         if (i == -1)   return "";
         else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
            alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
         break;
   }
   
   return "";
}

