// JavaScript Document
function validateInput(input,msg){
	var returnString = "";
	if(input){
		if(input.value.length <= 0 || input.value == null){
			input.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		}else{
			input.style.border = '';	
		}
	}
	
	return returnString;
}


function validateCheck(checkbox,msg){
	var returnString = "";
	if(checkbox){
		if(checkbox.checked==false){
			//checkbox.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		}
	}
	
	return returnString;
	
}


function validateCheckGroup(check,msg){
	var returnString = "";
	if(check){
		//loop through radio/checkbox group and if an element is checked then return true
		for(i=0;i<check.length;i++){
			if(check[i].checked){
				return returnString;
			}		
		}
	}
	returnString = "-" + msg  + "\n";
	return returnString;
	
}



//Use this function when you want to require a field...but it should only be required if a different element is checked
/*function validateCheckDependent(check,dependent,errorElement,msg,checked){
	//alert(checked);
	if(check && dependent){
		if(checked==true){
			if(check.checked && dependent.value.length <= 0){	
				dependent.style.border = '#C00 solid 3px';
				dependent.focus();
				errorElement.innerHTML = msg;
				errorElement.style.display = 'block';
				return false;
			}
		}
		else if(checked == false){
			if(check.checked == false && dependent.value.length <= 0){	
				dependent.style.border = '#C00 solid 3px';
				dependent.focus();
				errorElement.innerHTML = msg;
				errorElement.style.display = 'block';
				return false;
			}
		}
	}
	
	return true;
		
		
}*/

function validateDate(date,msg){
	
	var returnString = "";
	if(date){
		
		/* 
		
		Valid Date Formats
		---------------------------
		NOTE: formats are acceptable with a slash(/) or dash(-)
		> mm/dd/yyyy
		> mm/dd/yy
		> mm/d/yyyy
		> mm/d/yy
		> m/dd/yyyy
		> m/dd/yy
		> m/d/yyyy
		> m/d/yy
		
		*/
		
		if(date.value.match(/^((0?[1-9])|(1[0-2]))[-\/](([0-2]?[0-9])|(3[0-1]))[-\/](([0-9]{2})|([0-9]{4}))$/)){  
			date.style.border = '';
		}
		else{
			date.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		
		}
	}
	
	return returnString;
	
	
}


function validatePhone(phone,msg){
	
	var returnString = "";
	if(phone){
		
		/*
		
		Valid Phone Number Formats
		---------------------------------
		NOTE: numbers other 5 are acceptable, I just used 5 for an example number
		> 555-555-5555
		> 5555555555
		> 555 - 555 - 5555
		> 555 - 555- 5555
		> 555 - 555 -5555
		> 555 -555 - 5555
		> 555 -555 -5555
		> 555 -555- 5555
		> 555- 555 - 5555
		> 555- 555- 5555
		> 555- 555 -5555
		
		*/
		
		if(phone.value.match(/^[0-9]{10}$|[0-9]{3}\s?-\s?[0-9]{3}\s?-\s?[0-9]{4}$/)){
			phone.style.border = '';
		}
		else{
			phone.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		}		
	}
	
	return returnString;
}


function validateZip(postal,msg){
	var returnString = "";
	if(postal){
		
		/*
		
		Valid Zip Code Formats
		-------------------------------
		NOTE: Numbers other than 5 are acceptable I just used 5 for an example
		> 55555
		> 55555-5555
		> 55555 -5555
		> 55555- 5555
		> 55555 - 5555
		> 55555 5555
		
		*/
		
		if(postal.value.match(/^[0-9]{5}$|[0-9]{5}(\s)?-(\s)?[0-9]{4}$/)){
			postal.style.border = '';
		}
		else{
			postal.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		}
	}
	return returnString;
}


function validateSocial(social,msg){
	var returnString = "";
	if(social){
		
		/*
		
		Valid Social Security Number Formats
		--------------------------------------
		NOTE: Numbers other than 5 are acceptable, I justed used 5 for an example number
		> 555-55-5555
		> 555555555
		> 55555-5555
		> 555-555555
		> 555 - 55 - 5555
		> 555 - 55- 5555
		> 555 - 55 -5555
		> 555 -55 - 5555
		> 555 -55 -5555
		> 555 -55- 5555
		> 555- 55 - 5555
		> 555- 55- 5555
		> 555- 55 -5555
		
		*/
		
		if(social.value.match(/^[0-9]{9}$|[0-9]{3}\s?-\s?[0-9]{2}\s?-\s?[0-9]{4}$/)){
			social.style.border = '';
		}
		else{
			social.style.border = '#C00 solid 3px';
			returnString = "-" + msg  + "\n";
		}		
	}
	return returnString;
}