// JavaScript Document


function checkFields() {
	missinginfo = "";
	if (document.form.name.value == "") {
	missinginfo += "\n     .  Name";
	}
	
	if (document.form.emailUserCopy.value == "") {
	missinginfo += "\n     .  Retype email";
	}
	if (document.form.password.value == "") {
	missinginfo += "\n     .  Password";
	}
	
	if (document.form.passwordCopy.value == "") {
	missinginfo += "\n     .  Retype Password";
	}
	
	if(document.form.emailUser.value == "") {
	missinginfo += "\n     .  Email";
	}
	
	if(document.form.password.value !=document.form.passwordCopy.value ) {
	missinginfo += "\n     .   Password confirmation is different  ";
	}
	
	if(document.form.emailUser.value !=document.form.emailUserCopy.value ) {
	missinginfo += "\n     .   Email confirmation is different  ";
	}
	
	if (missinginfo != "") {
	missinginfo ="" +
	"Please note.\n" + "The following info. is missing:     \n" +
	missinginfo + "\n";
	alert(missinginfo);
	return false;
	}
	var emailID=document.getElementById('emailUser');
    if(document.getElementById('name').value.length == 0){
  		alert("Write a name \"name\"."); 
		document.getElementById('name').focus();
		return (false); 
   }
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	else return true;
}//end function

function checkFieldsAd() {
	missinginfo = "";
	if (document.form.title.value == "") {
	missinginfo += "\n     .  Title";
	}
	if (document.form.content.value == "") {
	missinginfo += "\n     .  Content";
	}
	if (document.form.email.value == "") {
	missinginfo += "\n     .  Email";
	}
	if (document.find_locations.city.value == "") {
	missinginfo += "\n     .  Please select a valid city";
	}
	if ((document.find_locations.fidlevel.value == "Subject1")){
	missinginfo += "\n     .  Please select a valid Subject";
	}
	if (missinginfo != "") {
	missinginfo ="" +
	"Please note.\n" + "The following info. is missing:     \n" +
	missinginfo + "\n";
	alert(missinginfo);
	return false;
	}
	
	else return true;
}

function checkComments() {
	missinginfo = "";
	if (document.contactForm.comments.value == "") {
	missinginfo += "\n     .  Comments";
	}
	
	var emailID=document.getElementById('yourEmail');

	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID");
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false){
		emailID.value="";
		emailID.focus();
		return false;
	}
	
	if (missinginfo != "") {
	missinginfo ="" +
	"Please note.\n" + "Please write a comment:     \n" +
	missinginfo + "\n";
	alert(missinginfo);
	return false;
	}
	
	else return true;
}

function checkReturnPassword() {
	missinginfo = "";
	
	if (document.form.emailUser.value == "") {
	missinginfo += "\n     .  Email";
	}
	
	
	if (missinginfo != "") {
	missinginfo ="" +
	"Please note.\n" + "The following info. is missing:     \n" +
	missinginfo + "\n";
	alert(missinginfo);
	return false;
	}
	
	else return true;
}

function checkBoxes(formAds) {
	var c = 0;
	var i = false;

	var a=new Array();
	a=document.getElementsByName("changed[]");
	for(i=0;i<a.length;i++){
		if(a[i].checked){
			c = true;
		 }
		//else c = 0;
	}//for
	    if(c == false ){
			alert ('You didn\'t choose any of the checkboxes!');
			return false;
		}//if	
			
		else { 	
			return true;
		}
	
}
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 setForm() {
 var emailID=document.getElementById('email');
    if(document.getElementById('name').value.length == 0){
  		alert("Write a name \"name\"."); 
		document.getElementById('name').focus();
		return (false); 
   }
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}

 
  else return true;
}//end function



//

