// Madgex Limited
// Copyright (c) 2004 Madgex Limited. All Rights Reserved.
// Validation - Core Components Project
// 12 August 2004
// Version 1.0.0

/*
Mofication
----------
Date:		20th April 2005
Author:		Paul Bilton & Oliver Southgate (Written by PB, added by OS)
Purpose:	With the existing date validation, it only checks for numeric 
			structure and does not account for number of days within the 
			month & Feb leap year day’s count.
Example:	<input type="text" id="txt1" value="" onblur="CheckDateFormatNew(this)">
*/

/*
Mofication
----------
Date:		6th May 2005
Author:		Oliver Southgate
Purpose:	Allows the use of multiple forms, create a variable (frmNumber) which holds a 
			number by default, this can then be set on a perpage level if you need a different form
Example:	frmNumber = 1;
*/
var frmNumber = 0;

/*
function CheckDateFormat( sFieldName )
{
	//alert ( sFieldName );

	if ( document.getElementById(sFieldName).value != '' )
	{
		eval( 'var elt = document.forms[frmNumber].' + sFieldName )
		CheckDateFormatElt( document.getElementById(sFieldName).value )
	}
}
*/

function CheckDateFormat(sFieldName)
{
	var sMsg = ''

	sMsg = IsValidDate(sFieldName);
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		document.getElementById(sFieldName).focus()
		document.getElementById(sFieldName).select()
		event.returnValue = false;
		return false;		
	}
}


function noEnter() {
	//return !(window.event && window.event.keyCode == 13)
	if(window.event && window.event.keyCode == 13)
	{
		var bs = document.getElementsByName('btnSearch')
		if(bs!=null)
		{
			bs[0].focus()	
		}
		return false;
	}  
	else
		return true;
  }


// Returns and empty string for a valid date, else an error string.
function IsValidDate(sFieldName)
{
	var sText = ''
	var sMsg = ''
	var sRes = ''
	
	if ( document.getElementById(sFieldName).value != '' )
	{
		sText = document.getElementById(sFieldName).value
	}
	
	if ( document.getElementById(sFieldName).value.length < 5 )
	{
		sText = ''
	}
	
	if ( sText != '' )
	{
		var d = sText.split('/')

		if ( d.length == 2 )
		{
			var dt = new Date()
			d[2] = dt.getFullYear()
		}
		
		if ( d.length != 3 )
		{
			sMsg = 'Invalid date format - ' + sText + '. The date format should be : dd/mm/yyyy.'
		}
		else
		{
			
			if ( isNaN(parseInt(d[1],10)) || d[1] > 12 || d[1] < 1 )
			{
				//sMsg = 'Invalid month - ' + d[1]			
				sMsg = 'This date is invalid (Month), please correct it - ' + d[0] + '/' + d[1] + '/' + d[2];
			}
			else if ( isNaN(parseInt(d[2],10)) )
			{
				//sMsg = 'Invalid day of year - ' + d[2]
				sMsg = 'This date is invalid (Day), please correct it - ' + d[0] + '/' + d[1] + '/' + d[2];
			}
			
			else if ( d[2] > -1 && d[2] < 100 )
			{
				d[2] = parseInt(d[2],10) + 2000
			}
			
			if ( d[2] < 1900 || d[2] > 3000 )
			{
				//sMsg = 'Invalid year - ' + d[2]
				sMsg = 'This date is invalid (Year), please correct it - ' + d[0] + '/' + d[1] + '/' + d[2];
			}
			
			if(sMsg == "")
			{ // check days
				var maxDays = daysInMonth(d[1], d[2]);
		
				if ( isNaN(parseInt(d[0],10)) || d[0] > maxDays || d[0] < 1 )
				{
					sMsg = 'This date is invalid (Day), please correct it - ' + d[0] + '/' + d[1] + '/' + d[2];
					//sMsg = 'Invalid day of month - ' + d[0] + '/' + d[1];
				}
		
			}
			
			var day, month
			
			day = parseInt(d[0],10)
			if (day<10)
				day = '0' + day
			
			month = parseInt(d[1],10)
			if ( month<10 )
				month = '0' + month
			
			sRes = day + '/' + month  + '/' + parseInt(d[2],10) 
		}
	}
	if(sMsg == "") document.getElementById(sFieldName).value = sRes
	return sMsg;
}
// Gets the number of days in a given month (allowing for leap years)
// iMonth is 1 based 1 = Jan, 2 = feb ...
function daysInMonth(iMonth, iYear)
{
	return 32 - new Date(iYear, iMonth - 1, 32).getDate();
}


function CheckInteger( sFieldName )
{
	var sText = ''
	var sMsg = ''
	var sRes = ''
	
	if ( document.getElementById(sFieldName).value != '' )
	{
		sText = document.getElementById(sFieldName).value
	}
	
	if ( sText != '' )
	{	sRes = parseInt( sText,10);
	
		if ( isNaN(sRes) )
			sMsg = 'Invalid number'
	}
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		document.getElementById(sFieldName).focus()
		document.getElementById(sFieldName).select()
	}
	else
	{
		document.getElementById(sFieldName).value = sRes
	}
}

function CheckMoney( sFieldName )
{
	//eval( 'var elt = document.forms[frmNumber].' + sFieldName )
	var sText = ''
	var sMsg = ''
	var sRes = sText
	
	if ( document.getElementById(sFieldName).value != '' )
	{
		sText = document.getElementById(sFieldName).value
	}
	if ( sText != '' )
	{
		if (sText.substr(0,1) == '.')
			sText = '0' + sText
	
		var d = sText.split('.')

		if ( d.length == 1 )
		{
			d[1] = '00'
		}
	
		if (d.length != 2)
		{
			sMsg = 'Invalid amount'
		}
		else
		{
			if ( isNaN(parseInt(d[0],10)) )
			{
				sMsg = 'Invalid amount'
			}
			else if ( isNaN(parseInt(d[1],10)) || d[1]<0)
			{
				sMsg = 'Invalid fractional amount'
			}
			else
			{
				sRes = d[0] + '.' + d[1]
			}

		}
	}
		
	/*if ( sMsg != '' )
	{
		alert( sMsg )
		elt.focus()
		elt.select()
	}
	else
	{
		elt.value = sRes
	}*/
	if ( sMsg != '' )
	{
		alert( sMsg )
		document.getElementById(sFieldName).focus()
		document.getElementById(sFieldName).select()
	}
	else
	{
		document.getElementById(sFieldName).value = sRes
	}
}

function CheckEmailFormat( sFieldName )
{
	eval( 'var elt = document.forms[frmNumber].' + sFieldName )
	var sText = elt.value;

	var sMsg = ''
	var sRes = ''
	
	if ( sText != '' )
	{	
		sRes = sText;

		var d = sText.split('@')

		if ( d.length != 2 )
		{
			sMsg = 'We do not recognise non-business addresses. If you would like further information on EGi please call the sales team on 0845 3015544.'

		}
		else
		{
			var dom = d[1].split('.') ;
			
			if ( dom.length < 2 )
			{
				sMsg = 'We do not recognise non-business addresses. If you would like further information on EGi please call the sales team on 0845 3015544.'

			}
		}
	}
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		elt.focus()
		elt.select()
	}
	else
	{
		elt.value = sRes
	}
}

function CheckURLFormat( sFieldName ) {
	var regEx = /^(file|http|https):\/\/\S+\.\S+$/i
	
	eval( 'var elt = document.forms[frmNumber].' + sFieldName )
	var sText = elt.value;
	
	if ( sText != '' && !regEx.test( sText ) )
	{	
		alert( 'Invalid URL' )
		elt.focus()
		elt.select()
	}
 }

function CheckTimeFormat( sFieldName )
{
	eval( 'var elt = document.forms[frmNumber].' + sFieldName )
	var sText = elt.value;

	var sMsg = ''
	var sRes = ''
	
	if ( sText != '' )
	{
		var d = sText.split(':')
		
		if ( d.length != 2 )
		{
			sMsg = 'Invalid time format, colon needed - ' + sText
		}
		else
		{
			if ( isNaN(parseInt(d[0],10)) || d[0] > 24 || d[0] < 0 )
			{
				sMsg = 'Invalid hour - ' + d[0]
			}
			else if ( isNaN(parseInt(d[1],10)) || d[1] > 59 || d[1] < 0 )
			{
				sMsg = 'Invalid minute - ' + d[1]			
			}
			
			var mn, hr
			
			mn = parseInt(d[0],10)
			if (mn<10)
				mn = '0' + mn
			
			hr = parseInt(d[1],10)
			if ( hr<10 )
				hr = '0' + hr
			
			sRes = mn + ':' + hr
		}
	}
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		elt.focus()
		elt.select()
	}
	else
	{
		elt.value = sRes
	}
}

String.prototype.IsWhiteSpace = function()
{
	return this == ' ' || this == '\t';
}

//BW - 23/03/2009 - Sprint M10 - Item 834 - Change Validation and presentation of Forgotten Password
String.prototype.TrimLeft = function()
{
	var i=0;
	
	while (this.charAt(i).IsWhiteSpace()) i++;
		
	return this.substr(i)
}

//BW - 23/03/2009 - Sprint M10 - Item 834 - Change Validation and presentation of Forgotten Password
String.prototype.TrimRight = function()
{
	var i=this.length;
	
	while (this.charAt(i-1).IsWhiteSpace()) i--;
		
	return this.substr(0,i)
}

String.prototype.Trim = function()
{
	return this.TrimLeft().TrimRight();
}

function CheckValidEmail( sText )
{
		
	// Assumes sText is not empty
	var d = sText.split('@')

	if ( d.length != 2 )
	{
		return false;
	}
	else
	{
		var dom = d[1].split('.') ;
		
		if ( dom.length < 2 )
			return false;
	}
	
	return true;
}

function validEmail(item)
{
	if(item.indexOf('@') > 0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
String.prototype.GetDate = function()
	{
		var sText = this;
		var sMsg = ''
		var sRes = ''
		
		if ( sText != '' )
		{
			var d = sText.split('/')

			if ( d.length == 2 )
			{
				var d = new Date()
				d[2] = d.getFullYear()
			}
			
			if ( d.length != 3 )
			{
				sMsg = 'Invalid date format - ' + sText
			}
			else
			{
				if ( isNaN(parseInt(d[0],10)) || d[0] > 31 || d[0] < 1 )
				{
					//sMsg = 'Invalid day of month - ' + d[0]
					sMsg = 'This date is invalid (Month), please correct it  - ' + d[0] + '/' + d[1] + '/' + d[2];
				}
				else if ( isNaN(parseInt(d[1],10)) || d[1] > 12 || d[1] < 1 )
				{
					//sMsg = 'Invalid month - ' + d[1]
					sMsg = 'This date is invalid (Month), please correct it  - ' + d[0] + '/' + d[1] + '/' + d[2];			
				}
				else if ( isNaN(parseInt(d[2],10)) )
				{
					//sMsg = 'Invalid day of year - ' + d[2]
					sMsg = 'This date is invalid (Year), please correct it  - ' + d[0] + '/' + d[1] + '/' + d[2];		
				}
				else if ( d[2] > -1 && d[2] < 100 )
				{
					d[2] = parseInt(d[2],10) + 2000
				}
				
				if ( d[2] < 1900 || d[2] > 3000 )
				{
					//sMsg = 'Invalid year - ' + d[2]
					sMsg = 'This date is invalid (Year), please correct it  - ' + d[0] + '/' + d[1] + '/' + d[2];
				}
				
				var day, month
				
				day = parseInt(d[0],10)
				if (day<10)
					day = '0' + day
				
				month = parseInt(d[1],10)
				if ( month<10 )
					month = '0' + month
				
				//sRes = day + '/' + month  + '/' + parseInt(d[2],10)
				sRes =  month + '/' +  day + '/' + parseInt(d[2],10)  
			}
		}
		
		if ( sMsg != '' )
		{
			return null;
		}
		else
		{
			var dRes = new Date( Date.parse( sRes ) );
			return dRes;
		}
	}
 //////////////////////////////////////////////////////////////////////
 
 var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date in this format (dd/mm/yyyy.")
		return false
	}
return true
}

function CheckDateFormatNew( txtField ){
  
  var dt=txtField
  if ( dt.value != '' ) {
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
  }

}

function CheckString(txtField)
{
	var st=txtField;

	if (st == null || st.value == '') 
	{
	    //YS: Sprint M13 : Item 794/ISSUE 13.5 : 12/Jun/2009 : Change the text of the pop-up window 
	    //var txtName = txtField.name.replace('HowDidYouHearAboutUs', 'How you heard about EGi');
		var txtName = txtField.name.replace('HowDidYouHearAboutUs','How did you hear about EGi');
		if (txtName == 'Username')
			txtName = txtField.name.replace('Username','Email');
		alert('Please enter a value in the ' + txtName + ' field.');
		return false;
	}
	else
	{
		return true;
	}
 }
 
 function CheckCheckBox(txtField)
 {
	var st=txtField;
	var val=st.value;
	
	if( st==null || st.value == '' || st.checked == false) 
	{
		alert('Please check the ' + txtField.name + ' field before submitting the form.');
		
		return false;
	}
	else
	{
		return true;
	}
	
 }
 
 function CheckEmailFormatNew( sFieldName )
{
	eval( 'var elt = document.forms[1].' + sFieldName )
	var sText = elt.value;

	var sMsg = ''
	var sRes = ''
	
	if ( sText != '' )
	{	
		sRes = sText;

		var d = sText.split('@')

		if ( d.length != 2 )
		{
			sMsg = 'We do not recognise non-business addresses. If you would like further information on EGi please call the sales team on 0845 3015544.'

		}
		else
		{
			var dom = d[1].split('.') ;
			
			if (badEmail(sRes) || dom.length < 2)
			{
				sMsg = 'We do not recognise non-business addresses. If you would like further information on EGi please call the sales team on 0845 3015544.';
			}
		}
	}
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		elt.focus()
		elt.select()
	}
	else
	{
		elt.value = sRes
	}
}

 function CheckEmailFormatEPO( sFieldName )
{
	eval( 'var elt = document.forms[1].' + sFieldName )
	var sText = elt.value;

	var sMsg = ''
	var sRes = ''
	
	if ( sText != '' )
	{	
		sRes = sText;

		var d = sText.split('@')

		if ( d.length != 2 )
		{
			sMsg = 'We do not recognise non-business addresses. If you would like further information on EuroProperty please call the Customer Services team on +44 (0) 7911 1864.'

		}
		else
		{
			var dom = d[1].split('.') ;
			
			if ( dom.length < 2 )
			{
				sMsg = 'We do not recognise non-business addresses. If you would like further information on EuroProperty please call the Customer Services team on +44 (0) 7911 1864.'

			}
			else 
			{			
				if (badEmail(sRes))
				{
					sMsg = 'We do not recognise non-business addresses. If you would like further information on EuroProperty please call the Customer Services team on +44 (0) 7911 1864.';
				}
			}
		}
	}
	
	if ( sMsg != '' )
	{
		alert( sMsg )
		elt.focus()
		elt.select()
	}
	else
	{
		elt.value = sRes
	}
}

function badEmail(email)
{
	/*
	** YS: The "@" is going to be introduced to the email address so we are sure we are restricting the right email addresses,
	** also, a restriction to some domain names was introduced - 10/July/2008 - Issue 633
	**   
	if ( 
		email.match('bpp.co.uk')!=null ||
		email.match('cmpi.biz')!=null ||
		email.match('bpplaw.co.uk')!=null ||
		email.match('city.ac.uk')!=null ||
		email.match('coem.ac.uk')!=null ||
		email.match('lawcol.co.uk')!=null ||
		email.match('lawcol.com')!=null ||
		email.match('ccoc.ie')!=null ||
		email.match('dit.ie')!=null ||
		email.match('gcal.ac.uk')!=null ||
		email.match('harper-adams.ac.uk')!=null ||
		email.match('kingston.ac.uk')!=null ||
		email.match('lit.ie')!=null ||
		email.match('ljmu.ac.uk')!=null ||
		email.match('lsbu.ac.uk')!=null ||
		email.match('ntu.ac.uk')!=null ||
		email.match('brookes.ac.uk')!=null ||
		email.match('rac.ac.uk')!=null ||
		email.match('shu.ac.uk')!=null ||
		email.match('sheffield.ac.uk')!=null ||
		email.match('ucl.ac.uk')!=null ||
		email.match('aberdeen.ac.uk')!=null ||
		email.match('abdn.ac.uk')!=null ||
		email.match('uce.ac.uk')!=null ||
		email.match('glam.ac.uk')!=null ||
		email.match('unn.ac.uk')!=null ||
		email.match('port.ac.uk')!=null ||
		email.match('reading.ac.uk')!=null ||
		email.match('uwe.ac.uk')!=null ||
		email.match('ulster.ac.uk')!=null ||
		email.match('westminster.ac.uk')!=null ||
		email.match('tesco.net')!=null ||
		email.match('virgin.net')!=null ||
		email.match('yahoo.com')!=null ||
		email.match('hotmail.com')!=null ||
		email.match('googlemail.com')!=null ||
		email.match('sky.com')!=null ||
		email.match('talk21.com')!=null ||
		email.match('yahoo.co.uk')!=null ||
		email.match('ntlworld.com')!=null ||
		email.match('gmail.com')!=null ||
		email.match('aol.com')!=null ||
		email.match('costar.co.uk')!=null 
		*/
		if ( 
		email.match('@bpp.co.uk')!=null ||
		email.match('@bpplaw.co.uk')!=null ||
		email.match('@city.ac.uk')!=null ||
		email.match('@coem.ac.uk')!=null ||
		email.match('@lawcol.co.uk')!=null ||
		email.match('@lawcol.com')!=null ||
		email.match('@ccoc.ie')!=null ||
		email.match('@dit.ie')!=null ||
		email.match('@gcal.ac.uk')!=null ||
		email.match('@harper-adams.ac.uk')!=null ||
		email.match('@kingston.ac.uk')!=null ||
		email.match('@lit.ie')!=null ||
		email.match('@ljmu.ac.uk')!=null ||
		email.match('@lsbu.ac.uk')!=null ||
		email.match('@ntu.ac.uk')!=null ||
		email.match('@brookes.ac.uk')!=null ||
		email.match('@rac.ac.uk')!=null ||
		email.match('@shu.ac.uk')!=null ||
		email.match('@sheffield.ac.uk')!=null ||
		email.match('@ucl.ac.uk')!=null ||
		email.match('@aberdeen.ac.uk')!=null ||
		email.match('@abdn.ac.uk')!=null ||
		email.match('@uce.ac.uk')!=null ||
		email.match('@glam.ac.uk')!=null ||
		email.match('@unn.ac.uk')!=null ||
		email.match('@port.ac.uk')!=null ||
		email.match('@reading.ac.uk')!=null ||
		email.match('@uwe.ac.uk')!=null ||
		email.match('@ulster.ac.uk')!=null ||
		email.match('@westminster.ac.uk')!=null ||
		email.match('@tesco.net')!=null ||
		email.match('@virgin.net')!=null ||
		email.match('@yahoo.com')!=null ||
		email.match('@hotmail.com')!=null ||
		email.match('@googlemail.com')!=null ||
		email.match('@sky.com')!=null ||
		email.match('@talk21.com')!=null ||
		email.match('@yahoo.co.uk')!=null ||
		email.match('@ntlworld.com')!=null ||
		email.match('@gmail.com')!=null ||
		email.match('@aol.com')!=null ||
		//YS: search for domain name using a different function (/i) makes the serch case insensitive.
		email.search(/@costar\./i)>0 ||
		email.search(/@cmpi\./i)>0
	)
	{
		return true;
	} else {
		return false;
	}
}

function JobFunctionChange()
{
	var box = document.forms[1].JobFunction;
	var opt = box.options[box.selectedIndex].value;
	
	document.forms[1].JobFunctionOther.value = "";
	hideFreeTrial( 'JFOtherDiv' );
	
	if ( opt == "Other" )
	{ 
		document.forms[1].JobFunctionOther.value = "";
		showFreeTrial( 'JFOtherDiv' );
	}
	
	if ( opt == "Student" )
	{
		alert('Please contact your library administrator for a username and password.\nYour university may already have a subscription to EGi.');	
		showHideFreeTrial('BoxFreeTrial2'); 
		showHideFreeTrial('boxLogin');
		showHideFreeTrial('bottomSection')
		document.forms[1].reset();
	}
}

function ResetRadios() {
	rads = document.getElementsByName('DateRange');
	var radLength = rads.length;
	for ( i=0; i < radLength; i++ ) {
		rads[i].checked = false;
	}
}

function CheckTrial1()
{
	debugger;
	if (!CheckString(document.forms[1].FirstName))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].LastName))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Telephone))
	{
		return false;
	}
	else
	{
		showHideFreeTrial('BoxFreeTrial1');
		showHideFreeTrial('BoxFreeTrial2'); 
		return false;
	}
}

function CheckTrial1New()
{
	if (!CheckString(document.forms[1].FirstName))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].LastName))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Telephone))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Username))
	{
		return false;
	}
	else
	{
		showHideFreeTrial('BoxFreeTrial1');
		showHideFreeTrial('BoxFreeTrial2'); 
		return false;
	}
}

function CheckTrial2()
{
	if (!CheckString(document.forms[1].JobTitle))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Company))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Sector))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Postcode))
	{
		return false;
	}
	else
	{
		showHideFreeTrial('BoxFreeTrial2');
		showHideFreeTrial('BoxFreeTrial3'); 
		return false;
	}
}

function CheckTrial2New(isEpo)
{
	if (!CheckString(document.forms[1].JobFunction))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Company))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Sector))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Address1))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Town))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Postcode))
	{
		return false;
	}
	else if (!isEpo && !CheckString(document.forms[1].County)) //AP : 10/12/2008 : Sprint M6 : Item 755 : County is a required field now.
	{
		return false;
	}	
	else
	{
		showHideFreeTrial('BoxFreeTrial2');
		showHideFreeTrial('BoxFreeTrial3'); 
		return false;
	}
}

function CheckTrial3()
{
	if (!CheckString(document.forms[1].Username))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].HowDidYouHearAboutUs))
	{
		return false;
	} 
	else if (!CheckCheckBox(document.forms[1].Terms))
	{
		return false;
	}
	else
	{
		return true;
	}
}

function CheckTrial3New()
{
	if (!CheckString(document.forms[1].HowDidYouHearAboutUs))
	{
		return false;
	} 
	else if (!CheckCheckBox(document.forms[1].Terms))
	{
		return false;
	}
	else
	{
		return true;
	}
}

// Checks the supplied object for a date that is in the future
// and displays an error Message if it is.
function CheckFutureDate(obj){
	if(IsValidDate(obj.id) == "" && IsFutureDate(obj))
	{
		try
		{
			document.getElementById("futureDateError").style.display = "block";
		}catch(err)
		{
			alert("You cannot enter a future date.");
		}
		obj.focus()
		obj.select()
	}
	else
	{
		try
		{
			document.getElementById("futureDateError").style.display = "none";
		}catch(err) { }
	}

}

// for checking if a date is in the future.
// returns true for a future valid date else false.
function IsFutureDate(obj){

	//break string into day/month/year portions
	var dateParts =obj.value.split("/");

	if(dateParts.length>2)
	{
	try{
		document.getElementById("futureDateError").style.display = "none";
		return false;
		}catch(err)
		{}
	}
	

	
	var dateFuture = true;
	var now=new Date();
	var newDate= new Date(dateParts[1]+ "/" + dateParts[0] + "/" + dateParts[2]);  //Pass date in mm/dd/yyyy format

	if(isNaN(newDate))
	{
		try
		{
			document.getElementById("futureDateError").style.display = "none";
		}catch(err) { }
		return false;
	}
	if(newDate <= now)
	{
		dateFuture = false;
	}
	return dateFuture;
}

function CheckPostCode(sFieldName)
{
	var pCode = objWrapper(sFieldName);
	if(pCode.obj.value != '' && (!IsValidPostCode(pCode.obj.value)))
	{
		alert("You must enter at least two digits of a valid postcode.");
		pCode.obj.focus();
		pCode.obj.select();
	}
}

function IsValidPostCode(pc)
{
	var regexstring = "^[A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]?";
	var myregexp = new RegExp(regexstring); 
	return pc.toUpperCase().match(myregexp);
}

//BW - 23/03/2009 - Sprint M10 - Item 834 - Change Validation and presentation of Forgotten Password
function CompareUsernames() {
    var username = document.getElementById("username").value.Trim();
    var username_confirm = document.getElementById("username_confirm").value.Trim();

    if (username == '') {
        alert("Please enter an email address");
        document.getElementById("username").value = '';
        document.getElementById("username_confirm").value = '';
        return false;
    }
    else if (username != username_confirm) {
        alert("The email addresses entered do not match. Please try again");
        document.getElementById("username").value = '';
        document.getElementById("username_confirm").value = '';
        return false;
    }
    return true;
}

//YS: Sprint M13 : Item 889 : 04/Jun/2009 : Make the free trial Form just one Form instead of three.
//    This function checks that all the compulsory fields of what previously were three forms are filled out by the user.
function CheckComprisedFormFreeTrial()
{
	if (!CheckString(document.forms[1].FirstName))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].LastName))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Telephone))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Username))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].JobFunction))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Sector))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].Company))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Address1))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Town))
	{
		return false;
	} 
	else if (!CheckString(document.forms[1].Postcode))
	{
		return false;
	}
	else if (!CheckString(document.forms[1].County))
	{
		return false;
	}
	else if(!CheckString(document.forms[1].HowDidYouHearAboutUs))
	{
		return false;
	} 
	else if (!CheckCheckBox(document.forms[1].Terms))
	{
		return false;
	}
	else
	{
		return true;
	}
}