String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function checkForm(formId){
	var form = document.getElementById(formId);
	var message = "WORK_IN_PROGRESS";
	if(form==null) return false;
	switch(formId){
		case "searchForm":
			if(form.string.value.trim().length<2
				&& form.elements['skillid[]'][0].value==""
				&& form.elements['skillid[]'][1].value==""
				&& form.elements['skillid[]'][2].value==""
				&& form.elements['skillid[]'][3].value==""){
				alert(i18n("EMPTY_REQUEST"));
				return false;
			}
			message = "SEARCH_IN_PROGRESS"
		break;
		case "companyForm":
			if(form.name.value.trim().length<3){
				alert(i18n("NAME_TOO_SHORT"));
				return false;
			}
			if(form.address.value.trim().length<3){
				alert(i18n("ADDRESS_TOO_SHORT"));
				return false;
			}
			var lReg = new RegExp("[0-9 -]{5,}", "i");
			if(lReg.exec(form.zip.value.trim())==null){
				alert(i18n("INVALID_ZIP"));
				return false;
			}
			if(form.city.value.trim().length<3){
				alert(i18n("CITY_TOO_SHORT"));
				return false;
			}
			if(form.country.value.trim().length<3){
				alert(i18n("COUNTRY_TOO_SHORT"));
				return false;
			}
			if(form.callingcode.value.trim().length<1){
				alert(i18n("CALLING_CODE_NOT_FOUND"));
				return false;
			}
			var lReg = new RegExp("[0-9 ]{10,}", "i");
			if(lReg.exec(form.phone.value.trim())==null){
				alert(i18n("INVALID_PHONE"));
				return false;
			}
			var lReg = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{3,}(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", "i");
			if(lReg.exec(form.email.value.trim())==null){
				alert(i18n("INVALID_EMAIL"));
				return false;
			}
			if(form.descriptionfr.value.trim().length<20){
				alert(i18n("DESCRIPTION_TOO_SHORT"));
				return false;
			}
		break;
		case "contactForm":
			if(form["title[0]"].value.trim().length>0||
				form["lastname[0]"].value.trim().length>0||
				form["firstname[0]"].value.trim().length>0||
				form["function[0]"].value.trim().length>0||
				form["phone[0]"].value.trim().length>0){
			
				if(form["title[0]"].value.trim().length<1){
					alert(i18n("TITLE_0_NOT_FOUND"));
					return false;
				}
				if(form["lastname[0]"].value.trim().length<2){
					alert(i18n("LASTNAME_0_NOT_FOUND"));
					return false;
				}
				if(form["firstname[0]"].value.trim().length<2){
					alert(i18n("FIRSTNAME_0_NOT_FOUND"));
					return false;
				}
				if(form["function[0]"].value.trim().length<2){
					alert(i18n("FUNCTION_0_NOT_FOUND"));
					return false;
				}
				var lReg = new RegExp("[0-9 ]{10,}", "i");
				if(lReg.exec(form["phone[0]"].value.trim())==null){
					alert(i18n("PHONE_0_INVALID"));
					return false;
				}
			}
			if(form["title[1]"].value.trim().length>0||
				form["lastname[1]"].value.trim().length>0||
				form["firstname[1]"].value.trim().length>0||
				form["function[1]"].value.trim().length>0||
				form["phone[1]"].value.trim().length>0){
			
				if(form["title[1]"].value.trim().length<1){
					alert(i18n("TITLE_1_NOT_FOUND"));
					return false;
				}
				if(form["lastname[1]"].value.trim().length<2){
					alert(i18n("LASTNAME_1_NOT_FOUND"));
					return false;
				}
				if(form["firstname[1]"].value.trim().length<2){
					alert(i18n("FIRSTNAME_1_NOT_FOUND"));
					return false;
				}
				if(form["function[1]"].value.trim().length<2){
					alert(i18n("FUNCTION_1_NOT_FOUND"));
					return false;
				}
				var lReg = new RegExp("[0-9 ]{10,}", "i");
				if(lReg.exec(form["phone[1]"].value.trim())==null){
					alert(i18n("PHONE_1_INVALID"));
					return false;
				}
			}
		break;
		case "connectForm":
			if(!form.guest.checked && form.value.value.trim().length<5){
				alert(i18n("INVALID_CODE"));
				return false;
			}
		break;
		case "membershipForm":
			if(form.company.value.trim().length<3){
				alert(i18n("COMPANY_TOO_SHORT"));
				return false;
			}
			if(form.firstname.value.trim().length<3){
				alert(i18n("FIRSTNAME_TOO_SHORT"));
				return false;
			}
			if(form.lastname.value.trim().length<3){
				alert(i18n("LASTNAME_TOO_SHORT"));
				return false;
			}
			if(form.title.value.trim().length<2){
				alert(i18n("FUNCTION_TOO_SHORT"));
				return false;
			}
			if(form.address.value.trim().length<3){
				alert(i18n("ADDRESS_TOO_SHORT"));
				return false;
			}
			var lReg = new RegExp("[0-9 -]{5,}", "i");
			if(lReg.exec(form.zip.value.trim())==null){
				alert(i18n("INVALID_ZIP"));
				return false;
			}
			if(form.city.value.trim().length<3){
				alert(i18n("CITY_TOO_SHORT"));
				return false;
			}
			if(form.country.value.trim().length<3){
				alert(i18n("COUNTRY_TOO_SHORT"));
				return false;
			}
			if(form.callingcode.value.trim().length<1){
				alert(i18n("CALLING_CODE_NOT_FOUND"));
				return false;
			}
			var lReg = new RegExp("[0-9 ]{10,}", "i");
			if(lReg.exec(form.phone.value.trim())==null){
				alert(i18n("INVALID_PHONE"));
				return false;
			}
			var lReg = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{3,}(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", "i");
			if(lReg.exec(form.email.value.trim())==null){
				alert(i18n("INVALID_EMAIL"));
				return false;
			}
			if(!form.site.checked &&
			!form.shop.checked &&
			!form.manufacturer.checked &&
			!form.purchasing.checked &&
			!form.distributor.checked &&
			!form.other.checked){
				alert(i18n("SKILLS_NOT_FOUND"));
				return false;
			}
			if(form.other.checked && form.othervalue.value.trim().length<3){
				alert(i18n("INVALID_PRECISION"));
				return false;
			}
		break;
		case "connectForm":
			if(form.value.value.trim().length<5){
				alert(i18n("INVALID_CODE"));
				return false;
			}
		break;
		case "sendForm":
			if(form.login.value.trim().length<4){
				alert(i18n("LOGIN_TOO_SHORT"));
				return false;
			}
		break;
		case "signinForm":
			if(form.login.value.trim().length<4){
				alert(i18n("LOGIN_TOO_SHORT"));
				return false;
			}
			if(form.password.value.trim().length<4){
				alert(i18n("PASSWORD_TOO_SHORT"));
				return false;
			}
		break;
		case "signupForm":
			if(form.login.value.trim().length<4){
				alert(i18n("LOGIN_TOO_SHORT"));
				return false;
			}
			if(form.password.value.trim().length<4){
				alert(i18n("PASSWORD_TOO_SHORT"));
				return false;
			}
			var lReg = new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]{3,}(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", "i");
			if(lReg.exec(form.email.value.trim())==null){
				alert(i18n("INVALID_EMAIL"));
				return false;
			}
		break;
	}
	setTimeout('loading("'+message+'","'+formId+'")', 50);
	return true;
}
function confirmDelete(){
	return confirm(i18n("CONFIRM_DELETE"));
}
function loading(message, formId){
	var form = document.getElementById(formId);
	if(form!=null){
		for(var i=0; i<form.elements.length; i++){
				form.elements[i].disabled="disabled";
		}
	}
	var cdiv = document.getElementById("page-content-div");
	var ldiv = document.createElement("div");
	if(cdiv!=null && ldiv!=null){
		ldiv.id="loading-div";
		ldiv.innerHTML='<p>'+i18n(message)+'</p><img src="/ima/loading.gif"/>';
		ldiv.style.top=-cdiv.offsetHeight-cdiv.offsetTop+30+'px';
		//ldiv.style.height=cdiv.offsetHeight+'px';
		cdiv.parentNode.appendChild(ldiv);
	}
}
