
var whitespace = " \t\n\r";

//checks if both username and password is entered before submiting form
function ForceEntry(objField, FieldName){
  var strField = objField.value;
//alert(strField);  
  if(isWhitespace(strField)){
    alert("You need to enter information for (" + FieldName + ") as this is a required field.");
    eval(objField).focus();
    return false;
  }
  return true;
}

//Check whether string s is empty.
function isEmpty(s){   
  return ((s == null) || (s.length == 0));
}

// Returns true if string s is empty or 
// whitespace characters only.
function isWhitespace (s){
  var i;

  // Is s empty?
  if (isEmpty(s))
    return true;
  // Search through string's characters one by one
  // until we find a non-whitespace character.
  // When we do, return false; if we don't, return true.
  for (i = 0; i < s.length; i++){   
    // Check that current character isn't whitespace.
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) 
      return false;
    }
    // All characters are whitespace.
    return true;
}

 function isValidEmail(s){  
    // is s whitespace?
    if(s == '')  
       return false;
    
    // there must be >= 1 character before $AT, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for $AT
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) 
      return false;
    else 
      i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else 
      return true;
  }

function ForceEmail(field, FieldName){
  if(!isValidEmail(field.value)){
    alert("You need to enter valid Email Address for (" + FieldName + ").");
    field.focus();
    return false;
  }
  return true;  
}
//===========================
function processLoginForm() {
	var username = document.loginForm.username.value;
	var password = document.loginForm.password.value;
alert(username);
	makePOSTRequest('http://develop.worldhosting.org/ebm4/NL/cmagazine/cp_login.php','username='+username+'&password='+password,document.getElementById('myDetails'),null,null);
	loginX();
}
/*
//===========================
function processAanmelden() {
	var usernameNew = document.createAccountForm.usernameNew.value;
	var passwordNew = document.createAccountForm.passwordNew.value;
	var password2 = document.createAccountForm.password2.value;
alert(usernameNew);
	makePOSTRequest('http://develop.worldhosting.org/ebm4/NL/cmagazine/cp_login.php','mode=aanmelden&usernameNew='+usernameNew+'&passwordNew='+passwordNew+'&password2='+password2,document.getElementById('myDetails'),null,null);
	loginX();
}
//============================
function processforgotForm() {;
	var email = document.forgotForm.email.value;
alert(email);
	makePOSTRequest('http://develop.worldhosting.org/ebm4/NL/cmagazine/cp_login.php','mode=forgotPassword&email='+email,document.getElementById('myDetails'),null,null);
	loginX();
}
*/
function switchForm(type,message) {
//alert(type+'   '+type.substr(3)+'   '+message);
	document.getElementById('inloggen').style.display='none';
	document.getElementById('forgotForm').style.display='none';
	document.getElementById('aanmelden').style.display='none';
	document.getElementById('LC_forgotForm').style.color = 'white';
	document.getElementById('LC_aanmelden').style.color = 'white';
	document.getElementById('LC_inloggen').style.color = 'white';
	document.getElementById(type).style.color = 'silver';
	document.getElementById(type.substr(3)).style.display='block';
	if (message != '') {
		document.getElementById('loginMessage').style.display='block';
		document.getElementById('loginMessage').innerHTML= message;
	}
} 

/*
function afmelden() {
	makePOSTRequest('http://develop.worldhosting.org/ebm4/NL/cmagazine/cp_login.php','mode=logout',document.getElementById('myDetails'),null,null);
	openCloseDivs('news');
	document.getElementById('login').style.display = 'block';
	document.getElementById('afmelden').style.display = 'none';
	document.getElementById('loggedIn').style.display = 'none';
}
*/

