  function objectEval(text)
  {
    // eval() breaks when we use it to get an object using the { a:42, b:'x' }
    // syntax because it thinks that { and } surround a block and not an object
    // So we wrap it in an array and extract the first element to get around
    // this.
    // This code is only needed for interpreting the parameter input fields,
    // so you can ignore this for normal use.
    // The regex = [start of line][whitespace]{[stuff]}[whitespace][end of line]
    text = text.replace(/\n/g, ' ');
    text = text.replace(/\r/g, ' ');
    if (text.match(/^\s*\{.*\}\s*$/))
    {
      text = '[' + text + '][0]';
    }
    return eval(text);
  }
  
function $(field){
	return document.getElementById(field);
}
  
function isProper(s){
   if (!string) return false;
   var iChars = "*|,\":<>[]{}`\';()@&$%#^~!_+=/?.";
   for (var i = 0; i < string.length; i++) 
   {
      if (iChars.indexOf(string.charAt(i)) != -1){
		    return false;
	  }
   }
   return true;
} 


function isString(s){
  	var i;
  	var state = false;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) state= true;
    }
	return state;
}
  
function isInt(s){
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }

    return true;
}

function isDate(s){
	var i;
	if(s.length > 10 || s.length < 8) return false;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }

    return true;
}

function isFilled(s){
	if(s.length>0)
		return true;
	else return false;
}

function isEmail(s){
 	p=s.indexOf('@');
	if (p<1 || p==(s.length-1)) return false;
	return true;
}

function isChecked(s){
	if ( s.checked == false ) { 
	 	return false;
	}else
		return true;
}

function checkField(action,s,field){
	var check=true;
	var msg = "The field '";
	var msg2 = "' should be";
	var error = "";
	switch(action){
		case "INT": 
			if(!isInt(s)){
				check=false;
				error = msg+""+field+""+msg2+" numeric.\n"; 
			}
			break;
		case "STRING": 
			if(!isString(s)){
				check=false;
				error = msg+""+field+""+msg2+" alpha.\n"; 
			}
			break;
		case "DATE":
			if(!isDate(s)){
				check=false;
				error = msg+""+field+""+msg2+" date.\n"; 
			}
			break;
		case "FILLED":
			if(!isFilled(s)){
				check=false;
				error = msg+""+field+""+msg2+" filled in.\n"; 
			}
			break;
		case "EMAIL":
			if(!isEmail(s)){
				check=false;
				error = msg+""+field+""+msg2+" a valid email address.\n"; 
			}
			break;	
		case "CHECK":
			if(!isChecked(s)){
				check=false;
				error = "The checkbox regarding '"+field+""+msg2+" flagged.\n"; 
			}
			break;	
		default: break;
	}
	return error;
	
	
}
