var lc_FormName = 'frmLogin';

function CheckLogin(lc_Action)
{
	
	var ll_Valid = true;
	var ln_Valid = 0;
	
	var lc_ErrorClass = 'field_error';
	var lc_ErrorCboClass = 'field_error_dd';
	var lc_NormClass = 'inputTypes';
	var lc_NormCboClass = 'inputTypes_dd';
	
	
	
	// Username Check
	var lc_Username = document.getElementById("txtUsername").value;
	if (lc_Username.length == 0)
	{
		document.getElementById("txtUsername").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtUsername").className = lc_NormClass;
	}	
		
	// Password Check
	var lc_Password = document.getElementById("txtPassword").value;
	if (lc_Password.length == 0)
	{
		document.getElementById("txtPassword").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtPassword").className = lc_NormClass;
	}	
	
	
	
	
	// Can form be submitted?
	if (ln_Valid > 0)
	{
		ll_Valid = false;
		alert('Please complete all fields marked with a *');
	}
	else
	{
		document.getElementById('hdnAction').value = lc_Action;
		document.getElementById('frmCandidateLogin').submit();
	}

}

var lc_FormName = "frmCandidate";
function CheckRegister(lc_Action,ln_Mode)
{
	
	var ll_Valid = true;
	var ln_Valid = 0;
	var ln_ImgValid = 0;
	
	var lc_ErrorClass = 'field_error';
	var lc_ErrorCboClass = 'field_error_dd';
	var lc_NormClass = 'inputTypes';
	var lc_NormCboClass = 'inputTypes_dd';
	
	
	//Title Check
	lc_value=document.getElementById('cboTitle').getAttribute('value');
	if (lc_value == 0)
	{
		document.getElementById("cboTitle").className = lc_ErrorCboClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("cboTitle").className = lc_NormCboClass;
	}
	
	// Forename Check
	var lc_Forename = document.getElementById("txtForename").value;
	if (lc_Forename.length == 0)
	{
		document.getElementById("txtForename").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtForename").className = lc_NormClass;
	}
	
	// Surname Check
	var lc_Surname = document.getElementById("txtSurname").value;
	if (lc_Surname.length == 0)
	{
		document.getElementById("txtSurname").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtSurname").className = lc_NormClass;
	}

	// Sector Check
	lc_value=document.getElementById('cboSector').getAttribute('value');
	if (lc_value == 0)
	{
		document.getElementById("cboSector").className = lc_ErrorCboClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("cboSector").className = lc_NormCboClass;
	}

	// Postcode Check
	var lc_Postcode = document.getElementById("txtPostcode").value;
	if (lc_Postcode.length == 0)
	{
		document.getElementById("txtPostcode").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtPostcode").className = lc_NormClass;
	}
	
	// Telephone Check
	var lc_Telephone = document.getElementById("txtTelephone").value;
	if (lc_Telephone.length == 0)
	{
		document.getElementById("txtTelephone").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtTelephone").className = lc_NormClass;
	}

// Email Check
	var lc_Email = document.getElementById("txtEmail").value;
	if (lc_Email.length == 0)
	{
		document.getElementById("txtEmail").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtEmail").className = lc_NormClass;
	}	
		
	// Password Check
	var lc_Password = document.getElementById("txtRegPassword").value;
	if (lc_Password.length == 0)
	{
		document.getElementById("txtRegPassword").className = lc_ErrorClass;
		ln_Valid = ln_Valid + 1;
	}
	else
	{
		document.getElementById("txtRegPassword").className = lc_NormClass;
	}	
	
	//Check Doc Upload
	lc_ImgString = document.getElementById("CvUpload").value;
	if (ln_Mode == 1)
	{
		if (lc_ImgString.length == 0)
		{
			document.getElementById("CvUpload").className = lc_ErrorClass;
			ln_ImgValid = ln_ImgValid + 1;
		}
		else
		//if (lc_ImgString.length != 0)
		{
			lc_ImgString = lc_ImgString.toLowerCase();
			
			ln_LastSlash = lc_ImgString.lastIndexOf('\\');
			
			var lc_Filename = lc_ImgString.substring(ln_LastSlash+1);
			//alert('lc filename = ' + lc_Filename);
			
			ln_LastDot = lc_Filename.lastIndexOf('.');
			lc_FileType = lc_Filename.substring(ln_LastDot);
			
			//alert('file type = ' + lc_FileType);
			
			if (lc_FileType != '.doc' && lc_FileType != '.pdf')
			{
				document.getElementById("CVUpload").className = lc_ErrorClass;
				ln_ImgValid = ln_ImgValid + 1;
				alert('File must be of .pdf or .doc format *');
			}
			
			//ln_SpacePos = lc_Filename.indexOf(' ');
			//alert('space pos = ' + ln_SpacePos);
			
			//if (ln_ImgValid == 0)
			//{
			//	if (ln_SpacePos != -1)
			//	{
			//		//alert('has spaces in filename');
			//		document.getElementById("CVUpload").className = lc_ErrorClass;
			//		ln_ImgValid = ln_ImgValid + 1;
			//	}
			//}
		}	
	}
	else
	{
			if (lc_ImgString.length != 0)
			{
			lc_ImgString = lc_ImgString.toLowerCase();
			
			ln_LastSlash = lc_ImgString.lastIndexOf('\\');
			
			var lc_Filename = lc_ImgString.substring(ln_LastSlash+1);
			//alert('lc filename = ' + lc_Filename);
			
			ln_LastDot = lc_Filename.lastIndexOf('.');
			lc_FileType = lc_Filename.substring(ln_LastDot);
			
			//alert('file type = ' + lc_FileType);
			
			if (lc_FileType != '.doc' && lc_FileType != '.pdf')
			{
				document.getElementById("CVUpload").className = lc_ErrorClass;
				ln_ImgValid = ln_ImgValid + 1;
				alert('File must be of .pdf or .doc format *');

			}
			
			//ln_SpacePos = lc_Filename.indexOf(' ');
			//alert('space pos = ' + ln_SpacePos);
			
			//if (ln_ImgValid == 0)
			//{
			//	if (ln_SpacePos != -1)
			//	{
			//		//alert('has spaces in filename');
			//		document.getElementById("CVUpload").className = lc_ErrorClass;
			//		ln_ImgValid = ln_ImgValid + 1;
			//	}
			//}
		}	
	}
	
	ln_Valid = ln_Valid + ln_ImgValid;
	
	
	// Can form be submitted?
	if (ln_Valid > 0)
	{
		ll_Valid = false;
		alert('Please complete all fields marked with a *');
	}
	else
	{
		document.getElementById('hdnAction').value = lc_Action;
		document.getElementById(lc_FormName).submit();
	}

}