function validate(){
	var err = 0;

	err |= CheckItem("txtName", "You need to enter a Valid Name");
	err |= CheckItem("txtSujet" , "You need to enter a Valid Subject");
	err |= CheckItem("cboType", "You need to select a type of request");
	err |= CheckItem("txtCommentaire", "You need to enter an Inquiry");
	err |= CheckMail("txtMail", "You need to enter a Valid E-Mail");
	
	if (err){
		return false;
	}
	else{
		return true;
	}
}

function validateRegister(){
	var err = 0;

	err |= CheckPassword("txtPassword", "txtConfirmPassword", 
							"You need to enter a Valid Password",
							"Password doesn't match",
							"Minimum lenght for password is 6 character"
						);
	
	err |= CheckItem("txtNick", "You need to enter a Nick Name");
	err |= CheckItem("txtCode", "You need to enter a Validation Code");
	err |= CheckMail("txtMail", "You need to enter a Valid E-Mail");
	
	if (err){
		return false;
	}
	else{
		return true;
	}
}


function validateLostPassword(){
	var err = 0;
	err |= CheckMail("txtMail", "You need to enter a Valid E-Mail");
	if (err){
		return false;
	}
	else{
		return true;
	}	
}

function validateEditProfile(){
	var err = 0;

	if (document.getElementById("txtNewPassword").value != ""){
		err |= CheckPassword("txtNewPassword", "txtConfirmNewPassword", 
								"You need to enter a Valid Password",
								"Password doesn't match",
								"Minimum lenght for password is 6 character"
							);
	}
	
	err |= CheckItem("txtNick", "You need to enter a Nick Name");
	err |= CheckMail("txtMail", "You need to enter a Valid E-Mail");
	
	if (err){
		return false;
	}
	else{
		return true;
	}
}

function validateversion(){
	var err = 0;

	err |= CheckItem("txtName", "You need to enter a Valid Name");
	err |= CheckMail("txtMail", "You need to enter a Valid E-Mail");
	
	if (err){
		return false;
	}
	else{
		return true;
	}
}


function resetform()
{
	ClearAll("txtMail");
	ClearAll("txtName");
	ClearAll("txtSujet");
	ClearAll("cboType");
	ClearAll("txtPassword");
	ClearAll("txtConfirmPassword");
	ClearAll("txtCode");
	ClearAll("txtNick");
	ClearAll("txtCommentaire");		
	ClearAll("txtSite");		
	ClearAll("txtCountry");		
	ClearAll("txtFirstName");		
	ClearAll("txtLastName");		
	ClearAll("txtMsn");	
	return true;
}

function CheckItem(itemname ,error){
	var item;
	item = document.getElementById(itemname).value;
	if (item == ""){
		SetError("err" + itemname, error);
		return 1;
	}
	else{
		ClearError("err" + itemname);
		return 0;
	}
}

function CheckPassword(itemname , itemnameconfirmation ,error1, error2, error3){
	var item1, item2;
	item1 = document.getElementById(itemname).value;
	item2 = document.getElementById(itemnameconfirmation).value;
	ClearError("err" + itemname);
	ClearError("err" + itemnameconfirmation);	
	if (item1 != ""){
		if (item1 == item2){
			if (item1.length > 5){
				return 0;
			}
			else{	
				SetError("err" + itemname, error3);
				return 1;
			}
		}
		else{
			SetError("err" + itemnameconfirmation, error2);
			return 1;
		}
	}
	else{
		SetError("err" + itemname, error1);
		return 1;
	}
}

function CheckMail(itemname, error){
	var item;
	var e =/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;	
	item = document.getElementById(itemname).value;

	if (item == "" || !e.test(item)){
		SetError("err" + itemname, error);
		return 1;
	}
	else{
		ClearError("err" + itemname);
		return 0;
	}
}

function SetError(item, error){
	document.getElementById(item).innerHTML=error;
	document.getElementById(item).style.display ="inline";
}

function ClearError(item){
	if (document.getElementById(item)){
		document.getElementById(item).innerHTML="";
		document.getElementById(item).style.display ="none";
	}
}

function ClearItem(item){
	if (document.getElementById(item)){
		document.getElementById(item).value = "";
	}
}

function ClearAll(item){
	ClearItem(item);
	ClearError("err" + item);
}

