﻿var xmlHttp;

function start_wizard() {
    start = document.getElementById('registration_wizard');
    start.style.visibility = 'visible';
    wizard1 = document.getElementById('cheerleader_wizard');
    wizard1.style.visibility = 'visible';
}

function quit_wizard() {
    quit = document.getElementById('registration_wizard');
    quit.style.visibility = 'hidden';
    quitch = document.getElementById('cheerleader_wizard');
    quitch.style.visibility = 'hidden';
    quitpa = document.getElementById('parent_wizard');
    quitpa.style.visibility = 'hidden';
    quitem = document.getElementById('emergency_wizard');
    quitem.style.visibility = 'hidden';
    quitre = document.getElementById('release');
    quitre.style.visibility = 'hidden';
    quitph = document.getElementById('photo_release');
    quitph.style.visibility = 'hidden';
}

function nextpage(nextid,curid) {
	validatecheer(curid);
	if (valstatus == 'Validated'){
		obid = document.getElementById(nextid);
		obid.style.visibility = 'visible';
		noid = document.getElementById('registration_wizard');
		noid1 = noid.getElementsByTagName('div');
		for (i=0; i<=noid1.length-1; i++){
			if (noid1[i].id != nextid && noid1[i].className == 'wiz'){
				noid1[i].style.visibility = 'hidden';
			}
		}
	}
}

function previouspage(id) {
    obid = document.getElementById(id);
    obid.style.visibility = 'visible';
    noid = document.getElementById('registration_wizard');
    noid1 = noid.getElementsByTagName('div');
    for (i=0; i<=noid1.length-1; i++) {
        if (noid1[i].id != id && noid1[i].className == 'wiz') {
            noid1[i].style.visibility = 'hidden';
        }
    }
}

function validatecheer(id) {
	id = document.getElementById(id);
	inputs = id.getElementsByTagName('input');
	selects = id.getElementsByTagName('SELECT');
	status = '';
	for (i=0;i<inputs.length-1;i++) {
		inputid = inputs[i].id;
		if (inputid == 'ch_first') {
			if (inputs[i].value == ''){
			    inputs[i].style.background = '#eed2cf';
				status = 'Error';
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		}
		if (inputid == 'ch_last') {
			if (inputs[i].value == ''){
			    inputs[i].style.background = '#eed2cf';
				status = 'Error';
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		}
		if (inputid == 'ch_areacode' || inputid == 'ch_prefix'){
			if (inputs[i].value.length != 3){
				inputs[i].style.background = '#eed2cf';
				status = 'Error';
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		}
		if (inputid == 'ch_number'){
			if (inputs[i].value.length != 4){
				inputs[i].style.background = '#eed2cf';
				status = 'Error';	
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		}
		if (inputid == 'ch_street1') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'ch_city') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'ch_zip') {
		    if (inputs[i].value.length != 5) {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'ch_email') {
			if (inputs[i].value == '' || validateEmail(inputs[i].value) != true) {
				inputs[i].style.background = '#eed2cf';
				status = 'Error';
			}
			else {
				inputs[i].style.background = '#eceae6';				
			}
		
		}
		if (inputid == 'ch_school') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'ch_boundaryy' && inputs[i].checked == true) {
			boundary = 'Y';
		}
		if (inputid == 'ch_boundaryn' && inputs[i].checked == true) {
			boundary = 'N';
		}
		if (inputid == 'ch_fally' && inputs[i].checked == true) {
			fall = 'Y';
		}
		if (inputid == 'ch_falln' && inputs[i].checked == true) {
			fall = 'N';
		}
		if (inputid == 'emerg_contact') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'emerg_areacode' || inputid == 'emerg_prefix') {
		    if (inputs[i].value.length < 3) {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'emerg_number') {
			if (inputs[i].value.length < 4) {
				inputs[i].style.background = '#eed2cf';
				status = 'Error';				
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		}
		if (inputid == 'phys_name') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'phys_areacode' || inputid == 'phys_prefix') {
		    if (inputs[i].value.length < 3) {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if  (inputid == 'phys_number') {
			if (inputs[i].value.length <4) {
				inputs[i].style.background = '#eed2cf';
				status = 'Error';
			}
			else {
				inputs[i].style.background = '#eceae6';
			}
		
		}
		if (inputid == 'release_name' || inputid == 'photo_release_name') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
		if (inputid == 'release_date' || inputid == 'photo_release_date') {
		    if (inputs[i].value == '') {
		        inputs[i].style.background = '#eed2cf';
		        status = 'Error';
		    }
		    else {
		        inputs[i].style.background = '#eceae6';
		    }
		}
    }
	/*if (id = 'cheerleader_wizard' && boundary != 'Y' && boundary != 'N'){
		boundaryy = document.getElementById('boundaryy')
		boundaryn = document.getElementById('boundaryn')
		boundaryy.style.color = 'red';
		boundaryn.style.color = 'red';
		status = 'Error';
	}
	else {
		boundaryy = document.getElementById('boundaryy')
		boundaryn = document.getElementById('boundaryn')
		boundaryy.style.color = '#000000';
		boundaryn.style.color = '#000000';
	}
	if (id = 'chearleader_wizard' && fall != 'Y' && fall != 'N'){
		fally = document.getElementById('fally')
		falln = document.getElementById('falln')
		fally.style.color = 'red';
		falln.style.color = 'red';
		status = 'Error';
	}
	else {
		fally = document.getElementById('fally')
		falln = document.getElementById('falln')
		fally.style.color = '#000000';
		falln.style.color = '#000000';
	}
	*/
    for (i=0;i<=selects.length-1;i++) {
        selectid = selects[i].id;
        if (selectid == 'ch_bdaymo' || selectid == 'ch_bdayday' || selectid == 'ch_bdayyr' || selectid == 'ch_grade') {
            if (selects[i].value == '') {
                selects[i].style.background = '#eed2cf';
                status = 'Error';
            }
            else {
                selects[i].style.background = '#eceae6';
            }
        }
    }

	if (status == 'Error') {
		valstatus = 'Error';
		}
	else {
		valstatus = 'Validated';
		}
}

function clearvalidation(type){
	switch (type){
		case 'boundary':
			boundaryy = document.getElementById('boundaryy');
			boundaryn = document.getElementById('boundaryn');
			boundaryy.style.color = '#000000';
			boundaryn.style.color = '#000000';
			status17 = '';
		break;
		case 'fall':
			fally = document.getElementById('fally');
			falln = document.getElementById('falln');
			fally.style.color = '#000000';
			falln.style.color = '#000000';
			status17 = '';
		break;
	}
}

function validateEmail(elementValue){  
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;  
	return emailPattern.test(elementValue);  
} 

function digitsOnly(obj){
	obj.value=obj.value.replace(/[^\d]/g,'');
}

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}	
}

function submitRegistration() {
	var ch_first = document.getElementById('ch_first').value;
	var ch_last = document.getElementById('ch_last').value;
	var ch_nick = document.getElementById('ch_nick').value;
	var ch_homephone = document.getElementById('ch_areacode').value + document.getElementById('ch_prefix').value + document.getElementById('ch_number').value;
	var ch_street1 = document.getElementById('ch_street1').value;
	var ch_street2 = document.getElementById('ch_street2').value;
	var ch_city = document.getElementById('ch_city').value;
	var ch_state = document.getElementById('ch_state').value;
	var ch_zip = document.getElementById('ch_zip').value;
	var ch_primary = document.getElementById('ch_primary').value;
	var ch_email = document.getElementById('ch_email').value;
	var ch_birthday = document.getElementById('ch_bdayyr').value + '-' + document.getElementById('ch_bdaymo').value + '-' + document.getElementById('ch_bdayday').value;
	var ch_school = document.getElementById('ch_school').value;
	var ch_grade = document.getElementById('ch_grade').value;
	if (document.getElementById('ch_boundaryy').checked == true) {var ch_boundary = 'Y'} else {var ch_boundary = 'N'};
	var ch_sports = document.getElementById('ch_sports').value;
	var mom_first = document.getElementById('mom_first').value;
	var mom_last = document.getElementById('mom_last').value;
	var mom_homephone = document.getElementById('mom_homeareacode').value + document.getElementById('mom_homeprefix').value + document.getElementById('mom_homenumber').value;
	var mom_cellphone = document.getElementById('mom_cellareacode').value + document.getElementById('mom_cellprefix').value + document.getElementById('mom_cellnumber').value;
	var mom_email = document.getElementById('mom_email').value;
	var dad_first = document.getElementById('dad_first').value;
	var dad_last = document.getElementById('dad_last').value;
	var dad_homephone = document.getElementById('dad_homeareacode').value + document.getElementById('dad_homeprefix').value + document.getElementById('dad_homenumber').value;
	var dad_cellphone = document.getElementById('dad_cellareacode').value + document.getElementById('dad_cellprefix').value + document.getElementById('dad_cellnumber').value;
	var dad_email = document.getElementById('dad_email').value;
	var other_first = document.getElementById('other_first').value;
	var other_last = document.getElementById('other_last').value;
	var other_homephone = document.getElementById('other_homeareacode').value + document.getElementById('other_homeprefix').value + document.getElementById('other_homenumber').value;
	var other_cellphone = document.getElementById('other_cellareacode').value + document.getElementById('other_cellprefix').value + document.getElementById('other_cellnumber').value;
	var other_email = document.getElementById('other_email').value;
	var emerg_contact = document.getElementById('emerg_contact').value;
	var emerg_phone = document.getElementById('emerg_areacode').value + document.getElementById('emerg_prefix').value + document.getElementById('emerg_number').value;
	var phys_name = document.getElementById('phys_name').value;
	var phys_phone = document.getElementById('phys_areacode').value + document.getElementById('phys_prefix').value + document.getElementById('phys_number').value;
	var insurance = document.getElementById('insurance').value;
	var allergies = document.getElementById('allergies').value;
	if (document.getElementById('tetanusy').checked == true) {var tetanus = 'Y'} else {var tetanus = 'N'};	
	var other_med = document.getElementById('other_med').value;
	if (document.getElementById('pyramidsy').checked == true) {var pyramids = 'Y'} else {var pyramids = 'N'};
	if (document.getElementById('carpooly').checked == true) {var carpool = 'Y'} else {var carpool = 'N'};
	var release_name = document.getElementById('release_name').value;
	var release_date = document.getElementById('release_date').value;
	var photo_release_name = document.getElementById('photo_release_name').value;
	var photo_release_date = document.getElementById('photo_release_date').value;
	if (document.getElementById('vol_parent').checked == true) {var vol_parent = 'Y';} else {var vol_parent = 'N';}
	if (document.getElementById('vol_fundraising').checked == true) {var vol_fundraising = 'Y';} else {var vol_fundraising = 'N';}
	if (document.getElementById('vol_party').checked == true) {var vol_party = 'Y';} else {var vol_party = 'N';}
	if (document.getElementById('vol_board').checked == true) {var vol_board = 'Y';} else {var vol_board = 'N';}
	if (document.getElementById('vol_coach').checked == true) {var vol_coach = 'Y';} else {var vol_coach = 'N';}
	if (document.getElementById('vol_sponsor').checked == true) {var vol_sponsor = 'Y';} else {var vol_sponsor = 'N';}
	var querystring = 'ch_first=' + ch_first + '&ch_last=' + ch_last + '&ch_nick=' + ch_nick + '&ch_homephone=' + ch_homephone + '&ch_street1=' + ch_street1 + '&ch_street2=' + ch_street2 + '&ch_city=' + ch_city + '&ch_state=' + ch_state + '&ch_zip=' + ch_zip + 
		'&ch_primary=' + ch_primary + '&ch_email=' + ch_email + '&ch_birthday=' + ch_birthday + '&ch_school=' + ch_school + '&ch_grade=' + ch_grade +
		'&ch_boundary=' + ch_boundary + '&ch_sports=' + ch_sports + '&mom_first=' + mom_first + '&mom_last=' + mom_last + '&mom_homephone=' + mom_homephone +
		'&mom_cellphone=' + mom_cellphone + '&mom_email=' + mom_email + '&dad_first=' + dad_first + '&dad_last=' + dad_last + '&dad_homephone=' + dad_homephone +
		'&dad_cellphone=' + dad_cellphone + '&dad_email=' + dad_email + '&other_first=' + other_first + '&other_last=' + other_last + '&other_homephone=' + other_homephone +
		'&other_cellphone=' + other_cellphone + '&other_email=' + other_email + '&emerg_contact=' + emerg_contact + '&emerg_phone=' + emerg_phone +
		'&phys_name=' + phys_name + '&phys_phone=' + phys_phone + '&insurance=' + insurance + '&allergies=' + allergies + '&tetanus=' + tetanus + '&other_med=' + other_med +
		'&pyramids=' + pyramids + '&carpool=' + carpool + '&release_name=' + release_name + '&release_date=' + release_date + '&photo_release_name=' + photo_release_name +
		'&photo_release_date=' + photo_release_date + '&vol_parent=' + vol_parent + '&vol_fundraising=' + vol_fundraising + '&vol_party=' + vol_party +
		'&vol_board=' + vol_board + '&vol_coach=' + vol_coach + '&vol_sponsor=' + vol_sponsor;
	var url = 'processreg.asp?timestamp=' + new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.open('POST',url,false);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", encodeURI(querystring).length);
	xmlHttp.send(encodeURI(querystring));
	if (xmlHttp.responseText == 'Success') {
	    register();
	}
	else {
	    alert('Your registration was unsuccessful. Please resubmit your information.');
	}
}

function register() {
    obid = document.getElementById('submit');
    obid.style.visibility = 'visible';
    noid = document.getElementById('registration_wizard');
    noid1 = noid.getElementsByTagName('div');
    for (i = 0; i <= noid1.length - 1; i++) {
        if (noid1[i].id != 'submit' && noid1[i].className == 'wiz') {
            noid1[i].style.visibility = 'hidden';
        }
    }
}
