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){
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      return false
   }
   if (str.indexOf(" ")!=-1){
      return false
   }
   return true
}


function validatelogin() {
			  // get form variables
			  var myusername 	= document.login.myusername.value;
			  var mypassword	= document.login.mypassword.value;
			  var incorrect = new Array;
			  //var error = "";
			  var no=0;
			  
			  if(myusername=="") {
			   //	error += "Please fill in your user name.<br />";
				incorrect[no]= "myusername";
				no++;
			  } 
			  
			  if(mypassword=="") {
			   	//error += "Please fill in your password.<br />";
				incorrect[no]= "mypassword";
				no++;
			  }
			  
			  document.getElementById("myusername").style.color="#ffffff";
			document.getElementById("mypassword").style.color="#ffffff";
			
			if (incorrect.length>0) {
				for(i=0;i<incorrect.length;i++) {
			  		document.getElementById(incorrect[i]).style.color="#ff9900";
			 	}
				//document.getElementById("errors").innerHTML = "There was an error with your form submission. Please fill in the neccessary fields.<br />" + error + "<br />" ;
				return false;
			} else {
				return true;
			}
}


function validatefeedback() {
			  // get form variables
			  var name 	= document.feedback.name.value;
			  var contact	= document.feedback.contact.value;
			  var email	= document.feedback.email.value;
			  var type_support	= document.feedback.type_support;
			  var type_others	= document.feedback.type_others;
			  var comments	= document.feedback.comments.value;
			  var incorrect = new Array;
			  var error = "";
			  var no=0;
			  
			  if(name=="") {
			   error += "Please fill in your name.<br />";
				incorrect[no]= "name";
				no++;
			  } 
			  
			  if(contact=="") {
			   	error += "Please fill in your contact number.<br />";
				incorrect[no]= "contact";
				no++;
			  } else if (isNaN(contact)) {
				error += "Please fill in a valid contact number.<br />";
				incorrect[no]= "contact";
				no++;
			  }
			  
			  
			  if(email=="") {
			   error += "Please fill in your email address.<br />";
				incorrect[no]= "email";
				no++;
			  } else if (!echeck(email)) {
				error += "Please fill in a valid email address.<br />";
				incorrect[no]= "email";
				no++;
			  }
			  
			  
			  if(!type_support.checked && !type_others.checked) {
			   	error += "Please choose your feedback type.<br />";
				incorrect[no]= "type_feedback";
				no++;
			  }
			  
			  
			  if(comments=="") {
			   	error += "Please fill in your comments.<br />";
				incorrect[no]= "comments";
				no++;
			  }
			  
			  document.getElementById("name").style.color="#000000";
			  document.getElementById("type_feedback").style.color="#000000";
			document.getElementById("contact").style.color="#000000";
			document.getElementById("email").style.color="#000000";
			document.getElementById("comments").style.color="#000000";

			
			if (incorrect.length>0) {
				for(i=0;i<incorrect.length;i++) {
			  		document.getElementById(incorrect[i]).style.color="#ff0000";
			 	}
				document.getElementById("errors").innerHTML = "There was an error with your form submission. Please fill in the neccessary fields.<br />" + error + "<br />" ;
				return false;
			} else {
				return true;
			}
}

