/***********************************************
** Title........: validate me
** Version......: 0.1
** Description..: client validation for plugin recommend me
** Author.......: Alexios Fakos <a.fakos@web.de>
** Notes........: all files are protected by copyright of author
** Last changed.: 26/06/2001
** Last change..: initial release 
***********************************************/


/***************************************************
** set some styles of the form element - input text
**************************************************/
var invalidColor			=		"#fcc";
var myborderColor			=		"#c00";

/* dotted, dashed, solid, double, groove, ridge, inset and outset */
var myborderStyle		=		"dashed";
var myborderWidth		=		"1px";

/***************************************
** set the error messages
*************************************/
var msgRecipienteMail		= 	"this is not a valid emailadress (mail@domain.com)";
var msgRecipientName		= 	"please enter your name.";
var msgMyName				=	"this entry is not valid.";
var msgMyeMail				=	"please enter your name!";


/**************************************
** Nothing to change below here
*************************************/

function is_eMail(strEmail) {

	var regexp= /^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+)(\.[a-z]{2,3}))$/;
	
	if (regexp.exec (strEmail)) 
		return true; 
	else
		return false;
}

function is_Empty(strValue) {

	if (strValue=='' || strValue==null)
		return true;
	else 
		return false;
}

function revertDefaultColor(objElem) {

		if (objElem.type=="text") {
			if (objElem.style.backgroundColor == invalidColor) {
				objElem.style.backgroundColor =	'';
				objElem.style.borderColor	=	'';
				objElem.style.borderStyle	=	'';
				objElem.style.borderWidth	=	'';
			} //invalidColor
		}//type==text
}


function doFalse(strMSG, myElement) {
			
			myElement.style.backgroundColor	= invalidColor;
			myElement.style.borderColor			= myborderColor;
			myElement.style.borderStyle			= myborderStyle;
			myElement.style.borderWidth			= myborderWidth;			
			alert (strMSG);
			myElement.focus();
}

String.prototype.trim = function () {

		return this.replace (/^\s+|\s+$/g,"");
}
	

function checkForm() {
	
	var strMSG="";
	myArray= new Array (msgRecipientName, msgRecipienteMail, msgMyName, msgMyeMail);

	thisForm= document.contact;
	

//	for (i=0; i<thisForm.elements.length; i++) 
// using only two elements instead
	for (i=0; i<2; i++) 
	{	
		myElement = thisForm.elements[i];		
		if (myElement.type=="text") 
		{
			eName	=	myElement.name;
			strValue	=	myElement.value.trim();

			if (eName.indexOf("email") != -1) 
			{
				if (!is_eMail(strValue)) 
				{ 
					doFalse(myArray[i], myElement);
					return false;
				}
			} 
			else 
			{
				if (is_Empty(strValue)) 
				{
					doFalse(myArray[i], myElement);
					return false;
				}
			}			
		} // if type=text
	} // for

	return true;
}
