 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//	Copyright (C) 2008 Cro-Cec, Inc. dba Digital Solutions.
//	A complete description of the Digital Solutions (c) copyright notice can be found online at: 
//	http://www.digitalsolutionslc.com/copyright_notice.php 
//		
//	Digital Solutions is a premier marketing and web development company in Las Cruces, New Mexico. 
//	We offer professional web design including flash and database web sites, graphic design, marketing materials, 
//	and video production. 
//
//	If you enjoyed this website and are looking for custom web development, give us a call at (575) 523-7661.
//		
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*********************************************************************
Version 4.0 --> modified Jun 6, 2007
*********************************************************************/
// This is the function you would use to require certain fields to be filled in when submitting a form.
// PLEASE NOTE: If you wish to have another field required, copy/paste the if statement for one of the
// other fields (e.g. first_name) and change the information to match the appropriate field.
function validate_login_restricted(form) 
{
	var e = form.elements, m = '';
	
	if(!e['username'].value) 
	{
		m += '- Username is required.\n\n';
	} 

	if(!e['password'].value) 
	{
		m += '- Password is required.\n\n';
	} 
	
	if(m) 
	{
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	
	return true;
}

function validate(form) 
{
	var e = form.elements, m = '';
	
	if(!e['first_name'].value) 
	{
		m += '- First name is required.\n\n';
	}
	
	if(!e['last_name'].value) 
	{
		m += '- Last name is required.\n\n';
	}
	
	if(!e['email'].value) 
	{
		m += '- Email is required.\n\n';
	} 
	
	if(e['email'].value) 
	{
		var str = e['email'].value;
		var reg = new RegExp("([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})");
	
		if(!reg.test(str))
		{
			m += '- E-Mail address is not valid.\n\n';
		}
	}
	
	if(!e['comments'].value) 
	{
		m += '- Comments are required.\n\n';
	}
	
	if(!e['s_image'].value) 
	{
		m += '- Security Code is required.\n\n';
	}
	
	if(e['s_image'].value) 
	{
		var str2 = e['s_image'].value;
		var reg2 = new RegExp("([a-z]{4})");
		
		if(!reg2.test(str2)) 
		{
			m += '- Security Code must have 4 characters.\n\n';
		}
	}
	
	if(m) 
	{
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}

	return true;
}

function validateAgent(form) 
{
	var e = form.elements, m = '';
	
	if(!e['phone_1_type'].value && ((e['phone_1_prefix'].value || e['phone_1_prefix'].value != 0) && (e['phone_1_suffix'].value || e['phone_1_suffix'].value != 0))) 
	{
		m += '- You must specify the Phone Type if you enter Phone 1.\n';
	}
	
	if(!e['phone_2_type'].value && ((e['phone_2_prefix'].value || e['phone_2_prefix'].value != 0) && (e['phone_2_suffix'].value || e['phone_2_suffix'].value != 0))) 
	{
		m += '- You must specify the Phone Type if you enter Phone 2.\n';
	}
	
	if(m) 
	{
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}
	
	return true;
}

function validateSiteConfig(form) 
{
	var e = form.elements, m = '';
	
	if(!e['site_name'].value) 
	{
		m += '- Site name is required.\n\n';
	}
	
	if(!e['site_url'].value) 
	{
		m += '- Site URL is required.\n\n';
	}
	
	if(m) 
	{
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}

	return true;
}

function validatePage(form) 
{
	var e = form.elements, m = '', myOption = -1, myOption2 = -1;
	
	if (document.getElementById('page_type_num').value && document.getElementById('page_type_num').value != 1)
	{
		var account_types_checked = 0;
		
		// now do the check to see if at least 1 account_type box is checked
		for (i_accounts_types = 0; i_accounts_types < document.getElementById('num_results_accounts_types').value; i_accounts_types++)		 
		{
			if(e['account_type_'+i_accounts_types].checked) 
			{
				account_types_checked++;
			}
		}
		if(account_types_checked == 0)
		{
			m += '- You must assign access of this page to at least 1 account type.\n\n';
		}
	}
	
	if(!e['page_name'].value) 
	{
		m += '- Page name is required.\n\n';
	}
	
	for (i=form.external_link.length-1; i > -1; i--)
	{
		if (form.external_link[i].checked)
		{
			myOption = i; i = -1;
		}
	}
	if (myOption == -1)
	{
		m += '- You must answer whether or not the page will be an external link.\n\n';
	}
	if (myOption == 0)
	{
		if(!e['special_page_link'].value) 
		{
			m += '- External link is required.\n\n';
		}
	}
	if (myOption == 1)
	{
		if(!e['page_title'].value) 
		{
			m += '- Page title is required.\n\n';
		}
	}
		
	if(m) 
	{
		alert('The following error(s) occurred:\n\n' + m);
		return false;
	}

	return true;
}
