window.onload=function() {
	var forms = document.getElementsByTagName('form');
	for (i=0;i<forms.length;i++) {//Loop through all forms in the page
		if (forms[i].className == "auto_validate") {
			var inputs = forms[i].getElementsByTagName('input');
			for (j=0;j<inputs.length;j++) {//Loop through input-fields in a form
				if (inputs[j].className == "req_text") {//required field
					var req_img = document.createElement('img');//Create image to mark the required field
					req_img.src="required.gif";
					req_img.className="form";
					req_img.alt="Required_field";
					inputs[j].parentNode.insertBefore(req_img, inputs[j]);//Insert it before the field
					inputs[j].onblur=function() {//
						if (trim(this.value) == "") {
							this.previousSibling.src="invalid.gif";
							this.style.border="1px solid #f00";
						}
						else {
							this.previousSibling.src="valid.gif";
							this.style.border="1px solid #aaa";
						}
					}
				}
				else if (inputs[j].className == "req_email") {
					var req_img = document.createElement('');
					req_img.src="required.gif";
					req_img.className="form";
					req_img.alt="Required_field";
					inputs[j].parentNode.insertBefore(req_img, inputs[j]);
					inputs[j].onblur=function() {
						if (trim(document.form.email.value) == "" || !check_email(document.form.email.value)) {
							this.style.border= "1px solid #d00000";
							this.style.background="#ff6a6a";
						}
						else {
							this.style.border= "1px solid #5991dd";
							this.style.background="#b2ccef";
						}
						if (trim(document.form.email.value) == trim(document.form.email_powt.value)) {
                                                    document.form.email_powt.style.border="1px solid #5991dd";
                                                    document.form.email_powt.style.background="#b2ccef";
                                                }
                                                else
                                                {
                                                    document.form.email_powt.style.border="1px solid #d00000";
                                                    document.form.email_powt.style.background="#ff6a6a";
                                                }
					}
				}
			}
		}
	}
	if (document.images) {
		pic1= new Image(20,20);
		pic1.src="valid.gif";

		pic2= new Image(20,20);
		pic2.src="invalid.gif";
	}
}


function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 

}

}

function trim(str) {
	return str.replace(/^\s+|\s+$/g, '');
}


