//2005 - Developed by Javier Reartes - Santex Standard

function LimitAttach(file) {
	var a = file;
	allowSubmit = false;
	if (!a) 
	{
		return;
	}
	while (a.indexOf("\\") != -1)
	{
		a = a.slice(a.indexOf("\\") + 1);
	}
	ext = a.slice(a.indexOf(".")).toLowerCase();
	for (var i = 0; i < extArray.length; i++) 
	{
		//alert(extArray[i]);
		if (extArray[i].toLowerCase() == ext) 
		{ 
			allowSubmit = true; break; 
		}
	}
	if (allowSubmit)
	{
		return null;
	}
	else
	{
	return("\r\n- Please select only this file type:  " 
	+ (extArray.join("  ")) + "\nSelect "
	+ "other file");
	}
}
function verify (f)
{
	var msg;
	var empty = "";
    var errors = "";
	for(var i = 0; i < f.length; i++) 
	{
		var e = f.elements[i];
		if(e.allow)
		{
			extArray = e.allow;
			extArray = extArray.split(",");
		}
		if(e.required && e.type=="select-one"){
			if(e.value==""){
				empty+="- You must complete the " + e.id + " field.\n";
			}
		}
		if (((e.type == "text") || (e.type == "textarea") || (e.type == "file")) && (e.required || e.allow))
		{
			if ((e.value == null) || (e.value == "") && e.required)
			{
				empty += "- You must complete the " + e.id + " field.\n";
            	continue;
			}
			if(e.required == 'c')
			{
				var valid = /[A-Za-z]/;
				var text = e.value
				var result = text.match(valid);
				if (result == null) 
				{
				errors += "- The " + e.id + " field must be a character";
				errors += ".\n";
				} 
			}
			if(e.required == 'n')
			{
				var valid = /[0-9.]/;
				var text = e.value
				var result = text.match(valid);
				if (result == null) 
				{
				errors += "- The " + e.id + " field must be a number";
				errors += ".\n";
				} 
			}
			if(e.required == 'm')
			{
				var valid = /^[_a-zA-Z0-9-](\.{0,1}[_a-zA-Z0-9-])*@([a-zA-Z0-9-]{1,}\.){0,}[a-zA-Z0-9-]{2,}(\.[a-zA-Z]{2,4}){1,2}$/;
				var text = e.value
				var result = text.match(valid);
				if (result == null) 
				{
				errors += "- The " + e.id + " field must be a valid e-mail address";
				errors += ".\n";
				} 
			}
			if(e.required == 'p')
			{
				var text = e.value;
				var invalid = /[A-Za-z]/;
				var result = text.match(invalid);
				if (result != null) 
				{
				errors += "- The " + e.id + " field must be a valid phone number";
				errors += ".\n";
				}else{
					var valid = /[0-9\(\)\-]/;
					var result = text.match(valid);
					if (result == null) 
					{
					errors += "- The " + e.id + " field must be a valid phone number";
					errors += ".\n";
					} 
				}
			}
			
			if(e.allow)
			{
				if (LimitAttach(e.value) != null) 
				{
				errors += LimitAttach(e.value);
				errors += ".\n";
				} 
			}
		}
	}
	
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//Custom validation for contact form only
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
if(f.name == 'frmContact'){
	if(f.c_describe_you.value==""){
		empty += "- You must complete the What describe you best field.\n";
	}else if(f.c_describe_you.value=="Other" && f.c_describe_you_other.value==""){
		empty += "- You must complete the What describes you best field.\n";
	}
	if(f.c_how_hear.value==""){
		empty += "- You must complete the How did you hear about us field.\n";
	}else if(f.c_how_hear.value=="Other" && f.c_how_hear_other.value==""){
		empty += "- You must complete the How did you hear about us field.\n";
	}	
	switch (f.c_it.value) {
		case '100% In-house development':
			break;
		case 'Partially outsourced':
			if(f.c_npi.value==""){empty += "- You must complete the Number of people in-house field.\n";}
			if(f.c_npo.value==""){empty += "- You must complete the Number of people outsource field.\n";}
			if(f.c_cot.value==""){empty += "- You must complete the Where are currently outsourcing to field.\n";}						
			break;
		case 'Completely outsourced':
			if(f.c_npo.value==""){empty += "- You must complete the Number of people outsource field.\n";}
			if(f.c_cot.value==""){empty += "- You must complete the Where are currently outsourcing to field.\n";}					
			break;
		default:
			empty += "- You must complete the Software Development needs field.\n";
			break;
	}
}
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=	
	
	if (errors || empty)
	{
		msg = empty + "\r\n" + errors;
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}