var user = "";

function processForm(collect) {
	
	alert(collect.username.value);
	var id1 = collect.username.value;
	id2 = collect.password.value;
	id3 = collect.location.value;
	
	if(!id1=="") {
 		alert(id1 + id2 + id3);	
		collect.submit();
	}
	else {
		alert('Add username please!');
		return;
	}
}

function checkPassNum(form) {

	pass1 = document.myform.password.value;
	if (pass1.length < 4) {
		alert("Password  must not be less than 4 characters !");
	}
	else{return;}
}


function checkPass(form) {

	pass1 = document.myform.password.value;
	pass2 = document.myform.cpassword.value;
	if (pass1 != pass2 || pass1.length < 4) {
		alert("Password do not match, please re-input and comfirm password!\n password must not be less than 6 characters");
		document.myform.password.focus();
	}
	else{return;}
}


function checkEmail(form) {

	pass1 = document.myform.email.value;
	pass2 = document.myform.cemail.value;
	if (pass1 != pass2) {
		alert("Your email do not match !");
		document.myform.email.focus();
	}
	else{return;}
}


function checkPass2(form) {

	pass1 = document.myform.newpassword.value;
	pass2 = document.myform.cpassword.value;
	if (pass1 != pass2 || pass1.length < 6) {
		alert("Password do not match, please re-input and comfirm new password!\n password must not be less than 6 characters");
		document.myform.newpassword.focus();
	}
	else{return;}
}


function submitEntry(form) {

	pass1 = document.myform.username.value;
	pass2 = document.myform.password.value;
	pass3 = document.myform.email.value;
	pass4 = document.myform.location.value;
	pass5 = document.myform.nationality.value;
	pass6 = document.myform.year.value;
	if (pass1 != "" && pass2 != "" && pass3 != "" && pass6 != "") {
		if (pass4 != "" && pass5 != "") {

			if (document.myform.policy.checked) {
				form.submit();
			}
			else {
				alert("If you have read our terms of service and agreed, please, check the field.");
			}
		}
		else{
			alert("Please, make sure location and nationlity fields are filled");
		}
	}
	else{
		alert("Please, make sure all the fields are well filled");
	}
}


function submitEntry2(form) {

	pass1 = document.myform.gender1.value;
	pass2 = document.myform.gender2.value;
	pass3 = document.myform.reason.value;
	if (pass1 != "" && pass2 != "" && pass3 != "") {
		form.submit();
	}
	else{
		alert("Please, make sure all the fields are well filled");
	}
}

function sendMessage(form) {
	
	rec = document.compose.recipient.value;
	sub = document.compose.subject.value;
	meg = document.compose.message.value;
	
	if (sub == "" || meg == "") {
		alert("Message field or Subject field is empty, pls fill.");
	}
	else if ( rec == "") {
		alert("You have not selected To(recipient) field");
	}
	else {
		meg = removeHype(meg);
		document.compose.message.value = meg;
		form.submit();
	}
}


function sendMail(form) {
	
	m1 = document.shareprofile.mail1.value;
	m2 = document.shareprofile.mail2.value;
	m3 = document.shareprofile.mail3.value;
	m4 = document.shareprofile.mail4.value;
	m5 = document.shareprofile.mail5.value;
	
	if (m1 == "" && m2 == "" && m3 == "" && m4 == "" && m5 == "") {
		alert("Please, add email addresses of your friends ");
	}
	
	else {
		form.submit();
	}
}

function sendInvitation(form) {
	
	m1 = document.invite.mail1.value;
	m2 = document.invite.mail2.value;
	m3 = document.invite.mail3.value;
	m4 = document.invite.mail4.value;
	m5 = document.invite.mail5.value;
	m6 = document.invite.mail6.value;
	m7 = document.invite.mail7.value;
	m8 = document.invite.mail8.value;
	m9 = document.invite.mail9.value;
	m10 = document.invite.mail10.value;
	meg = document.invite.message.value;
	
	if (m1 == "" && m2 == "" && m3 == "" && m4 == "" && m5 == "" && m6 == "" && m7 == "" && m8 == "" && m9 == "" && m10 == "") {
		alert("Please, add email addresses of your friends ");
	}
	
	else {
		meg = removeHype(meg);
		document.invite.message.value = meg;
		form.submit();
	}
}

function replyMail(form) {
	rec = document.readmail.sender.value;
	sub = document.readmail.subject.value;
	meg = document.readmail.message.value;
	
	if (sub == "" || meg == "") {
		alert("Message field or Subject field is empty, pls abort.");
	}
	else if ( rec == "") {
		alert("Recipient is not set, pls abort");
	}
	else {
		meg = removeHype(meg);
		document.readmail.message.value = meg;
		form.submit();
	}
}


function sendFlirt(form) {
	
	rec = document.flirt.recipient.value;
	meg = document.flirt.message.value;
	
	if (rec == "" || meg == "None") {
		alert("Message field or Subject Recipient is empty, pls fill.");
	}
	else {
		form.submit();
	}
}



function replyFlirt(form) {
	rec = document.readflirt.recipient.value;
	meg = document.readflirt.message.value;
	
	if (rec == "" || meg == "None") {
		alert("Reply message field or Recipient field is empty, pls abort.");
	}
	else {
		form.submit();
	}
}


function addComment(form) {
	
	meg = document.article.comment.value;
	
	if (meg == "") {
		alert("Comment box is empty, pls add comment.");
	}
	else {
		meg = removeHype(meg);
		document.article.comment.value = meg;
		form.submit();
	}
}


function updateArticle(form) {
	rec = document.updatearticle.title.value;
	cat = document.updatearticle.category.value;
	meg = document.updatearticle.message.value;	

	if (rec == "" || meg == "" || cat == "") {
		alert("Title field, category or Message field is empty, pls fill.");
	}
	else {
		meg = removeHype(meg);
		document.updatearticle.message.value = meg;
		form.submit();
	}
}


function articleCompose(form) {
	rec = document.articlecompose.title.value;
	meg = document.articlecompose.message.value;	

	if (rec == "" || meg == "") {
		alert("Title field, or Message field is empty, pls fill.");
	}
	else {
		meg = removeHype(meg);
		document.articlecompose.message.value = meg;
		form.submit();
	}
}



function addTopic(form) {
	
	meg = document.myforum.topic.value;
	
	if (meg == "") {
		alert("Topic box is empty, pls add comment.");
	}
	else {
		meg = removeHype(meg);
		document.myforum.topic.value = meg;
		form.submit();
	}
}



function simpleMatch(form) {
	rec = document.matchform.gender1.value;
	sub = document.matchform.gender2.value;
	meg = document.matchform.firstage.value;
	
	if (sub == "" || meg == "") {
		alert("Fields are not completely filled.");
	}
	else if ( rec == "") {
		alert("Plese select all the fields");
	}
	else {
		form.submit();
	}
}

function lgaMatch(form) {
	rec = document.matchform.gender1.value;
	sub = document.matchform.gender2.value;
	meg = document.matchform.firstage.value;
	lg = document.matchform.lga.value;
	
	if (sub == "" || meg == "") {
		alert("Fields are not completely filled.");
	}
	else if ( rec == "" || lg=="none") {
		alert("Plese select all the fields");
	}
	else {
		form.submit();
	}
}

function stateMatch(form) {
	rec = document.matchform.gender1.value;
	sub = document.matchform.gender2.value;
	meg = document.matchform.firstage.value;
	lg = document.matchform.state.value;
	
	if (sub == "" || meg == "") {
		alert("Fields are not completely filled.");
	}
	else if ( rec == "" || lg=="none") {
		alert("Plese select all the fields");
	}
	else {
		form.submit();
	}
}


function countryMatch(form) {
	rec = document.matchform.gender1.value;
	sub = document.matchform.gender2.value;
	meg = document.matchform.firstage.value;
	lg = document.matchform.country.value;
	
	if (sub == "" || meg == "") {
		alert("Fields are not completely filled.");
	}
	else if ( rec == "" || lg=="none") {
		alert("Plese select all the fields");
	}
	else {
		form.submit();
	}
}

function searchname(form) {
	meg = document.matchform.s_name.value;	

	if ( meg == "") {
		alert("Please, fill the form.");
	}
	else {
		meg = removeHype(meg);
		meg = document.matchform.s_name.value;
		form.submit();
	}
}


function sendContact(form) {

	meg = document.contact.message.value;	

	if (meg == "") {
		alert("Message field is empty, pls fill.");
	}
	else {
		form.submit();
	}
}

function sendDeposit(form) {

	meg1 = document.deposit.branch.value;
	meg2 = document.deposit.amount.value;
	meg3 = document.deposit.date.value;	

	if (meg1 == "" || meg2 == "" || meg3 == "") {
		alert("Please, make sure branch,amount and date fields are correctly filled.");
	}
	else {
		form.submit();
	}
}

function createRoom(form) {
	rec = document.chat.chatname.value;
	meg = document.chat.description.value;	

	if (rec == "" || meg == "") {
		alert("Please, fill the name and description fields.");
	}
	else {
		rec = removeHype(rec);
		rec = document.chat.chatname.value;
		meg = removeHype(meg);
		meg = document.chat.description.value;
		form.submit();
	}
}


function removeHype(type_sent) {
	var tex;
	rExp = /'/g;
	type_sent = type_sent.replace(rExp,"");
	tex = removeTag(type_sent);
	return tex;
}

function removeTag(type_sent) {
	var x;
	rExp = /</g;
	type_sent = type_sent.replace(rExp,"");
	x = removeTag2(type_sent);
	return x;
}

function removeTag2(type_sent) {
	rExp = />/g;
	type_sent = type_sent.replace(rExp,"");
	return type_sent;
}

// Email Validator

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateEmail(form){
	
	var emailID=document.invite.mail1
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter the Email ID")
	
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
}


function ValidateEmail2(form){
	
	var emailID=document.shareprofile.mail1
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter the Email ID")
	
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }
