function openPage(url,width,height) 
{
  window.name = 'main';
  side = window.open(url, 'side', 'scrollbars,menubar,width=' + width + ',height=' + height);
  if (!side.opener)
  { 
    side.opener = self;
  }
  side.focus();
}

function confirmPage(url,message)
{
  if (confirm(message)) {
    window.location.href = url;
  }
}

function isEmpty(value)
{
  var answer = true;
  
  if (!value.length)
  {
    answer = true;
  }
  
  for (var i=0; i < value.length; i++)
  {
    if(value.charAt(i) !=' ')
    {
	  answer = false;
    }
  }
  // Checking to make sure that at least something has been entered, cftrim will take care of the rest when i put it into the table
  
  return answer;
}

function checkEmail(value)
{
  validmail = false;
  
  for (var i=0; i < value.length; i++)
  {
	if(value.charAt(i) == '@')
    {
	  validmail = true;
    }
  } 

  return validmail;
}

function isInt(value)
{
  // This is a quick srcipt iv written to test for ints
  
  var alphaCheck = ' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"£$%^&*()_+?,.'
  // The String of things i dont want the user to output, => must be int
    
  var answer = true;
  
  for (var i=0; i < alphaCheck.length; i++)
  {
	if (value.indexOf(alphaCheck.charAt(i)) >= 0)
    {
	  answer = false;
    }
	// Looping through the whole of alphaCheck length to check for indexsof
  }
  
  return answer;
}

function leapYear(intYear) 
{
  // Way of Checking to See if Year is a Leap Year
  if (intYear % 100 == 0) 
  {
    if (intYear % 400 == 0) 
	{ 
	  return true; 
	}
  }
  else 
  {
    if ((intYear % 4) == 0) 
	{ 
	  return true; 
	}
  }
  
  return false;

}

function checkDate(formname)
{
  var answer = true;
  var testdate = formname.value;

  if (!testdate.length)
  {
	answer = false;
	// If it was no Length
  }
  else if (testdate.length !=10)
  {
    answer = false;
	// Check length of the entered date
  } 
  else if ((testdate.charAt(2) != "/") || (testdate.charAt(5) != "/"))
  {  
	answer = false;
	// Check / is in the right places
  }
  else if ((!isInt(testdate.substring(0,2))) || (!isInt(testdate.substring(3,5))) || (!isInt(testdate.substring(6,10))))
  {
    answer = false;
	// Check that the numbers are actually integers
  }
  else
  {
    // Now we know it is the right length and format we can chack the inputted numbers
  
    var dateday = testdate.substring(0,2);
    var datemonth = testdate.substring(3,5);
    var dateyear = testdate.substring(6,10);
  
    if (datemonth < 1 || datemonth > 12)
	{
	  alert('Invalid Month');
	  answer = false;
	  // Wrong Month
	}
	else if ((datemonth == 1 || datemonth == 3 || datemonth == 5 || datemonth == 7 || datemonth == 8 || datemonth == 10 || datemonth == 12) && (dateday > 31 || dateday < 1))
    {
	  alert('Invalid Days for the Month');
	  answer = false;
	  // Check 31 Days in these month
	}
	else if ((datemonth == 4 || datemonth == 6 || datemonth == 9 || datemonth == 11) && (dateday > 30 || dateday < 1))
    {
	  alert('Invalid Days for the Month');
	  answer = false;
	  // Check 30 Days in these month
	}
	else if (datemonth == 2)
	{
	  // Febuary is always the difficult month
	  if (dateday < 1)
	  {
	    alert('Invalid Days for the Month');
	    answer = false;
	  }
	  else if (leapYear(dateyear))
	  {
	    // Handel Leap Year Days, 29days in Feb if and 28days in Feb if not
		if (dateday > 29)
		{
	      alert('Invalid Days for the Month, ' + dateyear + ' is a LeapYear');
	      answer = false;
		}
	  }
	  else
	  {
	    if (dateday > 28)
		{
	      alert('Invalid Days for the Month, ' + dateyear + ' is Not a LeapYear');
	      answer = false;
		}
	  }
	}
  }

  return answer;
}