// user input validation
function ValidateRegistration(form)
{
    var error = false;

    for(var i=0; i<form.elements.length; i++)
    {

        if(form.elements[i].title=="please fill out")
        {
          form.elements[i].style.border="1px solid #2486D5";

          //select field
          if(form.elements[i].selectedIndex==0)
          {
              form.elements[i].style.border="1px solid red";
              error = true;
          }
          //text fields
          if(form.elements[i].value == "")
          {
             form.elements[i].style.border="1px solid red";
             error = true;
          }

          ////email validation
//          if(form.elements[i].name=="email")
//          {
//             if(!ValidateEmail(form.elements[i].value))
//             {
//                form.elements[i].style.border="1px solid red";
//
//                error = true;
//
//             }
//
//          }
        }
    }

    if(form.password_confirm)
    {
      if(form.password.value != form.password_confirm.value)
      {

          form.password.style.border="1px solid red";
          form.password_confirm.style.border="1px solid red";
          error = true;

      }

    }

    if(error)
    {

       alert("Please fill out the red marked fields and try again!");
	   return false;
    }

    return true;

}

function ValidateEmail(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 ValidateLogin(form)
{

  if(form.username.value!="" && form.password.value!="")
  {
    return true;
  }
  //alert("Bitte geben Sie Ihre Zugangsdaten ein!");
  return false;

}