// form validation function //
function loginCheck(form) {
  var user			=	form.user.value;//alert(name);
  var pass		=	form.pass.value;
  
  if(user == "") {
    //inlineMsg('user','You must enter username.',2);
	alert("You must enter username");
	document.getElementById("user").focus();
    return false;
  }
  if(pass == "") {
    //inlineMsg('pass','You must enter password.',2);
	alert("You must enter password");document.getElementById("pass").focus();
    return false;
  }
  return true;
}

function check_form(form) {
	var HomeTeam = form.HomeTeam.value;
  var HomeScore = form.HomeScore.value;
	  var AwayTeam = form.AwayTeam.value;
	  var AwayScore = form.AwayScore.value;
	  var Period = form.Period.value;
	  if(HomeTeam == "") {
		//inlineMsg('Name','You must enter  name.',2);
		alert("You must enter the home team.");document.getElementById("HomeTeam").focus();
		return false;
	  }
	  if(HomeScore == "") {
		//inlineMsg('Name','You must enter  name.',2);
		alert("You must enter the home score.");document.getElementById("HomeScore").focus();
		return false;
	  }
	  if(AwayTeam == "") {
		//inlineMsg('Name','You must enter  name.',2);
		alert("You must enter the away team.");document.getElementById("AwayTeam").focus();
		return false;
	  }
	  if(AwayScore == "") {
		//inlineMsg('Name','You must enter  name.',2);
		alert("You must enter the away score.");document.getElementById("AwayScore").focus();
		return false;
	  }
	  if(Period == "") {
		//inlineMsg('Name','You must enter  name.',2);
		alert("Please select a period.");document.getElementById("Period").focus();
		return false;
	  }
  
}


function validate(form) {
  var Name = form.Name.value;
  var Organization = form.Organization.value;
  var Email = form.Email.value;
  var Password = form.Password.value;
  var RePassword = form.RePassword.value;
  
  var NameRegex = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
  var EmailRegex = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  
  //var messageRegex = new RegExp(/<\/?\w+((\s+\w+(\s*=\s*(?:".*?"|'.*?'|[^'">\s]+))?)+\s*|\s*)\/?>/gim);
  
  if(Name == "") {
    //inlineMsg('Name','You must enter  name.',2);
	alert("You must enter a name.");document.getElementById("Name").focus();
    return false;
  }
  if(!Name.match(NameRegex)) {
    //inlineMsg('Name','You have entered an invalid  name.',2);
	alert("You have entered an invalid name.");document.getElementById("Name").focus();
    return false;
  }
  if(Organization == "") {
    //inlineMsg('Organization','You must enter  name.',2);
	alert("You must enter an organization.");document.getElementById("Organization").focus();
    return false;
  }
  if(Email == "") {
    //inlineMsg('Email','You must enter  email.',2);
	alert("You must enter an e-mail address.");document.getElementById("Email").focus();
    return false;
  }
  
  if(!Email.match(EmailRegex)) {
    //inlineMsg('Email','You have entered an invalid  email.',2);
	alert("You have entered an invalid e-mail address.");document.getElementById("Email").focus();
    return false;
  }
  
  if(Password==""){
		//inlineMsg('Password','You must enter password.',2);
		alert("You must enter a password.");document.getElementById("Password").focus();
		return false;
  }
  if(Password.length<4){
		//inlineMsg('Password','Password should be more than 6 characters.',2);
		alert("Password should be more than 4 characters.");document.getElementById("Password").focus();
		return false;
  }
  if(Password!=RePassword){
		//inlineMsg('RePassword','Password should be same.',2);
		alert("Your passwords did not match!");document.getElementById("RePassword").focus();
		return false;
  }
  return true;
}






function validate_change_password(form){
	
		var OldPassword	=	form.OldPassword.value;
		var NewPassword = form.NewPassword.value;
		var RePassword = form.RePassword.value;
		
		if(OldPassword == "") {
		//inlineMsg('OldPassword','You must enter old password.',2);
		alert("You must enter your old password.");document.getElementById("OldPassword").focus();
		return false;
	  }
	  
	  if(NewPassword == "") {
		//inlineMsg('NewPassword','You must enter new password.',2);
		alert("You must enter a new password.");document.getElementById("NewPassword").focus();
		return false;
	  }
	   if(RePassword == "") {
		//inlineMsg('RePassword','You must re-enter password.',2);
		alert("You must re-enter your new password.");document.getElementById("RePassword").focus();
		return false;
	  }
	  
	   if(NewPassword.length<4){
		//inlineMsg('NewPassword','Password should be more than 6 characters.',2);
		alert("Your password should be more than 4 characters.");document.getElementById("NewPassword").focus();
		return false;
	  }
	  if(NewPassword!=RePassword){
			//inlineMsg('RePassword','Password should be same.',2);
			alert("Your passwords did not match!");document.getElementById("RePassword").focus();
			return false;
	  }
	  
	  
	  return true;
	
	}








	//Date Format: mm/dd/yy (02/15/09)
	//if (!isValidDate(PosDate)){ 
//		inlineMsg('PosDate','You have entered an invalid date.',2);
//		return false;
//  }
//	
//
//
//
////Date Validation Code
//
//function isValidDate(ctrl){
//	
//	var dateStr = ctrl;
//	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;
//	var matchArray = dateStr.match(datePat); // is the format ok?
//	if (matchArray == null){
//		//alert("Invalid date format. Please enter the date in the MM/DD/YY format (example: 1/15/08) or select a date by clicking the calendar icon.")
//		//ctrl.focus();
//		return false;
//	}
//	month = matchArray[1]; // parse date into variables
//	day = matchArray[3];
//	year = matchArray[4];
//	if (month < 1 || month > 12){ 
//	// check month range
//		//alert("Month must be between 1 and 12.");
//		return false;
//	}
//	if (day < 1 || day > 31){
//		//alert("Day must be between 1 and 31.");
//		return false;
//	}
//	if ((month==4 || month==6 || month==9 || month==11) && day==31){
//		//alert("Month "+month+" doesn't have 31 days!")
//		return false
//	}
//	if (month == 2){ 
//	// check for february 29th
//		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
//		if (day>29 || (day==29 && !isleap)) {
//		//alert("February " + year + " doesn't have " + day + " days!");
//		return false;
//		}
//	}
//	return true; // date is valid
//}
//End Date Validation Code



























////			RED ALERT FOR BIGNNERS			//////////////


// START OF MESSAGE SCRIPT //

var MSGTIMER = 20;
var MSGSPEED = 5;
var MSGOFFSET = 3;
var MSGHIDE = 3;

// build out the divs, set attributes and call the fade function //
function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var targetwidth = targetdiv.offsetWidth;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
  msg.style.top = topposition + 'px';
  msg.style.left = leftposition + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;  
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

// hide the form alert //
function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

// face the message box //
function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}

// calculate the position of the element in relation to the left of the browser //
function leftPosition(target) {
  var left = 0;
  if(target.offsetParent) {
    while(1) {
      left += target.offsetLeft;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.x) {
    left += target.x;
  }
  return left;
}

// calculate the position of the element in relation to the top of the browser window //
function topPosition(target) {
  var top = 0;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}

// preload the arrow //
if(document.images) {
  arrow = new Image(7,80); 
  arrow.src = "images/msg_arrow.gif"; 
}
