function validate(form)
{ 
	var returncheck = 0;
	
	// First Name
	if(form.firstname.value == "")
	{
		document.getElementById('fieldgroup_firstname').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_firstname').style.padding = "5px";
		document.getElementById('fieldgroup_firstname').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_firstname').style.display = "inline";
		returncheck++;
	}
	
	// Last Name
	if(form.lastname.value == "")
	{
		document.getElementById('fieldgroup_lastname').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_lastname').style.padding = "5px";
		document.getElementById('fieldgroup_lastname').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_lastname').style.display = "inline";
		returncheck++;
	}
	
	// Title
	if(form.title.value == "")
	{
		document.getElementById('fieldgroup_title').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_title').style.padding = "5px";
		document.getElementById('fieldgroup_title').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_title').style.display = "inline";
		returncheck++;
	}
	
	// Job Function
	if(form.custom1.options[form.custom1.selectedIndex].value == "")
	{
		document.getElementById('fieldgroup_jobfunction').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_jobfunction').style.padding = "5px";
		document.getElementById('fieldgroup_jobfunction').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_jobfunction').style.display = "inline";
		returncheck++;
	}
	
	// Company
	if(form.company.value == "")
	{
		document.getElementById('fieldgroup_company').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_company').style.padding = "5px";
		document.getElementById('fieldgroup_company').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_company').style.display = "inline";
		returncheck++;
	}
	
	// Email Address	
    if(form.email.value == "")
	{
		document.getElementById('fieldgroup_email').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_email').style.padding = "5px";
		document.getElementById('fieldgroup_email').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_email_missing').style.display = "inline";
		returncheck++;
    }
	else if(!isValidEmail(form.email.value))
	{
		document.getElementById('fieldgroup_email').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_email').style.padding = "5px";
		document.getElementById('fieldgroup_email').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_email_invalid').style.display = "inline";
		returncheck++;
	}

	// State
	if(form.state.options[form.state.selectedIndex].value == "")
	{
		document.getElementById('fieldgroup_state').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_state').style.padding = "5px";
		document.getElementById('fieldgroup_state').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_state').style.display = "inline";
		returncheck++;
	}

	// Country
	if(form.country.options[form.country.selectedIndex].value == "")
	{
		document.getElementById('fieldgroup_country').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_country').style.padding = "5px";
		document.getElementById('fieldgroup_country').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_country').style.display = "inline";
		returncheck++;
	}
	
	
	// Password
    if(form.password.value == "")
	{
		document.getElementById('fieldgroup_password').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_password').style.padding = "5px";
		document.getElementById('fieldgroup_password').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_password').style.display = "inline";
		returncheck++;
    }
	
	// Password2
    if(form.password2.value == "")
	{
		document.getElementById('fieldgroup_password2').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_password2').style.padding = "5px";
		document.getElementById('fieldgroup_password2').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_password2').style.display = "inline";
		returncheck++;
    }
	
	// Do passwords match??
	// Password
    if(form.password.value != "" && form.password.value != form.password2.value)
	{
		document.getElementById('fieldgroup_password2').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_password2').style.padding = "5px";
		document.getElementById('fieldgroup_password2').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_password2_match').style.display = "inline";
		returncheck++;
    }
	
	
	// Identifter
   	if(form.custom2[0].checked == false && form.custom2[1].checked == false && form.custom2[2].checked == false)
	{
		document.getElementById('fieldgroup_identifier').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_identifier').style.padding = "5px";
		document.getElementById('fieldgroup_identifier').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_identifier').style.display = "inline";
		returncheck++;
	}
	
	if(form.custom2[2].checked == true && form.custom3.value == "")
	{
		document.getElementById('fieldgroup_identifier').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_identifier').style.padding = "5px";
		document.getElementById('fieldgroup_identifier').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_identifier2').style.display = "inline";
		returncheck++;
	}
	
	// alert(returncheck);
	
	if(returncheck == 0) {
		return true;
	} else {
		return false;
	}	
}

function validate2(form)
{ 
	var returncheck = 0;
	
	
	// First Name
	if(form.firstname.value == "")
	{
		document.getElementById('fieldgroup_firstname').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_firstname').style.padding = "5px";
		document.getElementById('fieldgroup_firstname').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_firstname').style.display = "inline";
		returncheck++;
	}
	
	// Last Name
	if(form.lastname.value == "")
	{
		document.getElementById('fieldgroup_lastname').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_lastname').style.padding = "5px";
		document.getElementById('fieldgroup_lastname').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_lastname').style.display = "inline";
		returncheck++;
	}
	
	// Email Address	
    if(form.email.value == "")
	{
		document.getElementById('fieldgroup_email').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_email').style.padding = "5px";
		document.getElementById('fieldgroup_email').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_email_missing').style.display = "inline";
		returncheck++;
    }
	else if(!isValidEmail(form.email.value))
	{
		document.getElementById('fieldgroup_email').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_email').style.padding = "5px";
		document.getElementById('fieldgroup_email').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_email_invalid').style.display = "inline";
		returncheck++;
	}

	// Comments
	if(form.comments.value == "")
	{
		document.getElementById('fieldgroup_comments').style.border = "1px solid #df0032";
		document.getElementById('fieldgroup_comments').style.padding = "5px";
		document.getElementById('fieldgroup_comments').style.backgroundColor = "#fde9eb";
		document.getElementById('warning_comments').style.display = "inline";
		returncheck++;
	}
	
	if(returncheck == 0) {
		return true;
	} else {
		return false;
	}	
}


function isValidEmail(email)
{
	invalidchars = " /:;"

	for(i=0; i < invalidchars.length; i++)
	{ //checks for invalid chars
			
		badchars = invalidchars.charAt(i);
		
		if(email.indexOf(badchars,0) != -1)
		{
			return false;
		}
	}
	
	atPos = email.indexOf("@",1)  //holds position of "@"
			
	if(atPos == -1) 
	{	//checks to see if "@" present
		return false;
	}
							
	if(email.indexOf("@",atPos+1) != -1) 
	{ //checks for second "@"
		return false;
	}
							
	periodPos = email.indexOf(".",atPos) //holds position of "."
			
	if(periodPos == -1)
	{ //checks for presence of "."
		return false;
	}
	
	if(periodPos+3 > email.length)
	{//makes sure at least two chars after the period
		return false;
	}
	
	return true;
}



function resetWarning(id) {
	var fieldgroup = "fieldgroup_" + id;
	
	document.getElementById(fieldgroup).style.border='0px';
	document.getElementById(fieldgroup).style.padding='0px';
	document.getElementById(fieldgroup).style.backgroundColor='#ffffff';
	
	if(id == "password2") {
		var warning = "warning_" + id;
		var warning2 = "warning_" + id + "_match";
		
		document.getElementById(warning).style.display='none';
		document.getElementById(warning2).style.display='none';
	}
	else if (id == "email") {  
		var warning = "warning_" + id + "_missing";
		var warning2 = "warning_" + id + "_invalid";
		
		document.getElementById(warning).style.display='none';
		document.getElementById(warning2).style.display='none';
	}
	else if (id == "identifier") {  
		var warning = "warning_" + id;
		var warning2 = "warning_" + id + "2";
		
		document.getElementById(warning).style.display='none';
		document.getElementById(warning2).style.display='none';
	}
	else {
		var warning = "warning_" + id; 
		document.getElementById(warning).style.display='none';
	}
}
