function getformvalues(fobj,valfunc) 
{
	var str = ""; 
	aok = true; 
	var val;
	
	for(var i = 0; i < fobj.elements.lenght; i++) {
		if(valfunc) {
			if (aok == true) {
				val = valfunc (fobj.elements[i].value,fobj.elements[i].name);
				if (val == false) {
					aok = false;
					}
				}
			}
			str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
		}
		return str;
	}

function colorsInit(colorOk,id_array)
{
	for (x = 0; x < id_array.lenght; x++)
   {
	   document.getElementById(id_array[x]).style.backgroundColor=colorOk;
	   document.getElementById(id_array[x]).style.backgroundImage='none';
   }
}

function errorDisplay(objID,message,colorError,colorOk,obj)
{
	document.getElementById(objID).style.backgroundColor=colorError;
	document.getElementById(objID).focus();
	obj.innerHTML = message;
}

function makerequest(serverPage,objID,divID)
{
var obj = document.getElementById(objID);
var obj2 = document.getElementById(divID);
xmlhttp.open("GET",serverPage);
xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{	
			var colorError = "#780047";
			var colorOk = "#FFFFFF";
			if (objID=="question_message_box")
			{
				var id_array = new Array("question_name","question_email","question_contents","captcha");
				colorsInit(colorOk,id_array);
	
				if (xmlhttp.responseText == 'captcha_bad')
				{
					errorDisplay('captcha','Enter the characters found in the image above.',colorError,colorOk,obj);
					document.getElementById('captch_quest').style.borderColor='red';
				}
				else if (xmlhttp.responseText == 'question_name_empty')
				{
					errorDisplay('question_name','Please type your name.',colorError,colorOk,obj);
					document.getElementById('captch_quest').style.borderColor='green';
				}
				else if (xmlhttp.responseText == 'question_email_empty')
				{
					errorDisplay('question_email','Please type in your email.',colorError,colorOk,obj);
					document.getElementById('captch_quest').style.borderColor='green';
				}	
				else if (xmlhttp.responseText == 'question_email_invalid')
				{
					errorDisplay('question_email','Please type correct email.',colorError,colorOk,obj);
					document.getElementById('captch_quest').style.borderColor='green';
				}
				else if (xmlhttp.responseText == 'question_contents_empty')
				{
					errorDisplay('question_contents','Please type in your question.',colorError,colorOk,obj);
					document.getElementById('captch_quest').style.borderColor='green';
				}
				else if (xmlhttp.responseText == 'OK')
				{
				colorsInit(colorOk,id_array);
				document.getElementById('captch_quest').style.borderColor='green';
				obj.innerHTML = '<img src="i/spinner_white.gif" />&nbsp;Processing...';
				//alert(document.getElementById('textF').value);
				obj2.innerHTML = 'Thank you for your question.<br/><a href="javascript:window.location.reload( false );">Add another question...</a>';
				}
				else
				{
					obj.innerHTML = xmlhttp.responseText;
				}
			}
			else if (objID=="suggest_message_box")
			{
				var id_array = new Array("suggest_contents","captcha2");
				colorsInit(colorOk,id_array);
				
				if (xmlhttp.responseText == 'captcha2_bad')
				{
					errorDisplay('captcha2','Enter the letters and numbers found in the image above.',colorError,colorOk,obj);
					document.getElementById('captch').style.borderColor='red';
					
				}
				else if (xmlhttp.responseText == 'suggest_contents_empty')
				{
					errorDisplay('suggest_contents','Please type in your suggestion.',colorError,colorOk,obj);
					document.getElementById('captch').style.borderColor='green';
				}
				
				else if (xmlhttp.responseText == 'OK')
				{
				colorsInit(colorOk,id_array);
				document.getElementById('captch').style.borderColor='green';
				obj.innerHTML = '<img src="i/spinner_white.gif" />&nbsp;Processing...';
				//alert(document.getElementById('textF').value);
				obj2.innerHTML = 'Thank you for your suggestion.<br/><a href="javascript:window.location.reload( false );">Suggest another article...</a>';
				}
				else
				{
					obj.innerHTML = xmlhttp.responseText;
				}
			}
		}
		else if (xmlhttp.readyState == 1)
		{
			obj.innerHTML = '<img src="i/spinner_white.gif" />&nbsp;Processing...';
		}
		
		
	}
xmlhttp.send(null);
}

function validate_question_form(question_name,question_email,question_contents,captcha)
{
	serverPage = "validator.php?action=validate_question&question_name=" + question_name + "&question_email=" + question_email + "&question_contents=" + question_contents + "&captcha=" + captcha;
	objID = "question_message_box";
	divID = "question_form_id";
	makerequest(serverPage,objID,divID);
}

function validate_suggest_form(suggest_contents,captcha2)
{
	serverPage = "esender.php?action=email_send&suggest_contents=" + suggest_contents + "&captcha2=" + captcha2;
	objID = "suggest_message_box";
	divID = "suggest_form_id";
	makerequest(serverPage,objID,divID);
}