var allok=false;
function validate(val, err){
	serverPage = "lib/validate.php?vstring=" + val;
	var obj = document.getElementById(err);
	processAjax(serverPage, obj, "get", "");
}

function getVal(theform){
	var str="";	
	for(var i=0;i < theform.elements.length;i++){		
		str += theform.elements[i].name + "=" + theform.elements[i].value + "&";
	}
	return str;
}
function submitform (theform, serverPage, objID){
		validateVal();
		if(allok==true){
			var str = getVal(theform);
			var obj = document.getElementById(objID);
			processAjax (serverPage, obj, "post", str);
		}		
}

function validateVal(){
	allok=true;
	var fname = document.getElementById("ptxtfname").value;
	var lname = document.getElementById("ptxtlname").value;
	if(trim(fname) == ""){
		err("perrFname");
		allok=false;
	}else
		ok("perrFname");
	if(trim(lname) == ""){
		err("perrLname");
		allok=false;
	}else
		ok("perrLname");
}

function err(errMsg){
	document.getElementById(errMsg).innerHTML = "<img style='border:0;' src='images/error.png' />";
}
function ok(okMsg){
	document.getElementById(okMsg).innerHTML = "<img style='border:0;' src='images/ok.png' />";
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
	  retValue = retValue.substring(0, retValue.length-1);
	  ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function getCont(){
	var tid=document.getElementById('cbotest').value;
	serverPage="html-include/package.php?create=" + tid;
	var obj= document.getElementById('cont2');
	processAjax(serverPage, obj, "get","");
}

function getCont2(){
	var dum = document.getElementById('ampaw').value;	
	serverPage="html-include/package.php?create2="+ dum;
	var obj = document.getElementById('cont3');
	processAjax(serverPage, obj, "get","");	
}

function addSelected(){
	
}
function hideCont(val){
	serverPage = "html-include/create.php?val="+val;
	var obj=document.getElementById('cont');
	processAjax(serverPage, obj, "get","");
}

function selectPlant(val){
	serverPage = "html-include/choose.php?plid="+val;
	var obj = document.getElementById('selectcont');
	processAjax(serverPage, obj, "get","");
}

function checkMail(val){
	/*if(val.length > 0){
		if (val.indexOf(' ') >= 0)
			alert("email addresses cannot have spaces in them");
		else if (val.indexOf('@') == -1)
			alert("a valid email address must have an @ in it");
    }*/
	alert('aw');
}