
function expand(ele) {
	
	if(ele.style.display == "none"){
		ele.style.display = "";
		
	}
}

function collapse(ele) {
	
	if(ele.style.display == ""){
		ele.style.display = "none";
		
	}
}

function validate(){
	
	var invalid = new Array();
	
	if(document.getElementById('name').value.length == 0){
		invalid.push('name');
	}
	if(!radioHasSelection('gender')){
		invalid.push('genderInfo');
	}
	if(document.getElementById('dob').value.length == 0){
		invalid.push('dob');
	}
	if(document.getElementById('ssn').value.length == 0){
		invalid.push('ssn');
	}
	if(document.getElementById('phone').value.length == 0){
		invalid.push('phone');
	}
		
	var residence = document.getElementsByName('residence');

	if(radioHasSelection('residence')){
	
		if(!(residence[2].checked)){
			
			if(document.getElementById('address1').value.length == 0){
				invalid.push('address1');
			}
			if(document.getElementById('city').value.length == 0){
				invalid.push('city');
			}
			if(document.getElementById('zip').value.length == 0){
				invalid.push('zip');
			}
		}
	}
	else {
		invalid.push('residenceInfo');
	}
	
	if(!selectHasSelection(document.getElementById('branch'))){
		invalid.push('branchInfo');
	}
	if(!selectHasSelection(document.getElementById('discharge'))){
		invalid.push('dischargeInfo');
	}
	if(!selectHasSelection(document.getElementById('startMonth')) || !selectHasSelection(document.getElementById('startYear')) || !selectHasSelection(document.getElementById('endMonth')) || !selectHasSelection(document.getElementById('endYear'))){
		invalid.push('datesOfService');
	}
	
	if(!radioHasSelection('card')){
		invalid.push('cardInfo');
	}
	if(!radioHasSelection('days')){
		invalid.push('daysInfo');
	}
	if(!radioHasSelection('overnight')){
		invalid.push('overnightInfo');
	}
	if(!radioHasSelection('transportation')){
		invalid.push('transportationInfo');
	}
	if(!radioHasSelection('disabled')){
		invalid.push('disabledInfo');
	}
	if(!radioHasSelection('cta')){
		invalid.push('ctaInfo');
	}
	

	if(invalid.length > 0){
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);		
		
		var errors = document.getElementById('errors');
		
		for(var a=0;a<invalid.length;a++){
			
			if (invalid[a] == undefined){
			}
			else{
				if (invalid[a]){
					var element = document.getElementById(invalid[a]);
					if (element){
						element.style.border = "1px solid red";
						element.style.background = "#FFCCCC";
					}
				}
			}
		}
		
		location.href = sPage+"#top";
		document.getElementById('errors').style.display = "";
	}
	else {
		
		document.getElementById('errors').style.display = "none";
		return true;
	}
	

}

function selectHasSelection(ele){

	return ele.value == '' ? false : true;
}

function radioHasSelection(ele){

	var has = false;
	var radios = document.getElementsByName(ele);
	
	for(var i=0;i<radios.length;i++){
		if(radios[i].checked){
			has = true;
			break;
		}
	}
	return has;
}

function resetField(ele){
	
	if(ele.value.length > 0){
		ele.style.border = '1px solid #cacaca';
		ele.style.background = '#fff';
	}

}

function resetSelect(name){
	
	var ele = document.getElementById(name);

	if(ele.Value != ''){
		ele.style.border = '';
		ele.style.background = '#eee';
	}
}

function resetSelectGroup(eleName, group){
	
	var container = document.getElementById(eleName);
	
	var field;
	var satisfied = true;
	
	for(var i=0;i<group.length;i++){
		
		field = eval("document.forms[0]." + group[i] + ".value");
		
		if(field == ''){
			satisfied = false;
		}
	}
	
	if(satisfied){
		container.style.border = '';
		container.style.background = '#eee';
	}
}


function resetRadioGroup(name){
	var ele = document.getElementById(name);
	ele.style.border = '';
	ele.style.background = '#eee';
}



function mapQuest(){
	
    var city = "Carpentersville";
    var state = "IL";
    var address = "150 S. Kennedy Drive Rte 25";
    var zip = "60110";
    var country = "USA";
    
    var url = "http://www.mapquest.com/maps?city="+city+"&state="+state+"&address="+address+"&zipcode="+zip+"&country="+country+"&geocode=ADDRESS";
    
    window.open(''+url,'Map',
'left=20,top=20,width=700,height=600,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0');

}