// JavaScript Document


function addInputXTimes(xTimes) {
	for (intC=0;intC<xTimes;intC++){
		arrNameInput.push(arrNameInput.length);
		arrNameInputValue.push("");
		arrAgeInput.push(arrAgeInput.length);
		arrAgeInputValue.push("");
		arrGenderInput.push(arrGenderInput.length);
		arrGenderInputValue.push("");
		arrExperienceInput.push(arrExperienceInput.length);
		arrExperienceInputValue.push("");
		arrSchoolInput.push(arrSchoolInput.length);
		arrSchoolInputValue.push("");
		arrUniformInput.push(arrUniformInput.length);
		arrUniformInputValue.push("");
		arrProgramInput.push(arrProgramInput.length);
		arrProgramInputValue.push("");
		/*arrLocationInput.push(arrLocationInput.length);
		arrLocationInputValue.push("");*/
		arrRequestInput.push(arrRequestInput.length);
		arrRequestInputValue.push("");
		arrBirthdateInput.push(arrBirthdateInput.length);
		arrBirthdateInputValue.push("");
		arrEthnicityInput.push(arrEthnicityInput.length);
		arrEthnicityInputValue.push("");
	}
	display();
	
}

function createGenderInput(name, id,value) {
	strSelect = "";
	strSelect += "<tr><td></td><td>Gender:</td><td><select name=\'"+name+id +"\' id=\'"+name+id +"\' class=\'eventform\' onChange=\'javascript:arr" + name + "InputValue[" + id + "]=this.value\' >";
	strSelect += "<option value=\'\' selected>Select one...</option>";
	if(value != "male"){
		strSelect += "<option value=\'male\'>Male</option>";
	}else{
		strSelect += "<option value=\'male\' selected>Male</option>";
	}
	if(value != "female"){
		strSelect += "<option value=\'female\'>Female</option>";
	}else{
		strSelect += "<option value=\'female\' selected>female</option>";
	}
	strSelect += "</select></td></tr>";
	
	return strSelect;
}


function createEthnicityInput(name, id,value) {
	strSelect = "";
	strSelect += "<tr><td></td><td>Ethnicity:</td><td><select name=\'"+name+id +"\' id=\'"+name+id +"\' class=\'eventform\' onChange=\'javascript:arr" + name + "InputValue[" + id + "]=this.value\' >";
	strSelect += "<option value=\'\' selected>Select one...</option>";
	if(value != "white"){
		strSelect += "<option value=\'white\'> White</option>";
	}else{
		strSelect += "<option value=\'white\' selected> White</option>";
	}
	if(value != "black"){
		strSelect += "<option value=\'black\'> Black</option>";
	}else{
		strSelect += "<option value=\'black\' selected> Black</option>";
	}
	if(value != "Asian"){
		strSelect += "<option value=\'asian\'> Asian</option>";
	}else{
		strSelect += "<option value=\'asian\' selected> Asian</option>";
	}
	if(value != "hispanic"){
		strSelect += "<option value=\'hispanic\'> Hispanic</option>";
	}else{
		strSelect += "<option value=\'hispanic\' selected> Hispanic</option>";
	}
	if(value != "other"){
		strSelect += "<option value=\'other\'> Other</option>";
	}else{
		strSelect += "<option value=\'other\' selected> Other</option>";
	}
	strSelect += "</select></td></tr>";
	
	return strSelect;
}

function createUniformInput(name, id,value) {
	
	strSelect = "";
	strSelect += "<tr><td></td><td>Uniform:</td><td><select name=\'"+name+id +"\' id=\'"+name+id +"\' class=\'eventform\' onChange=\'javascript:arr" + name + "InputValue[" + id + "]=this.value\' >";
	strSelect += "<option value=\'\'>Select one...</option>";
	if(value == "Youth Small"){
	strSelect += "<option value=\'Youth Small\' selected>Youth Small (6-8)</option>";
	}else{
	strSelect += "<option value=\'Youth Small\'>Youth Small (6-8)</option>";
	}
	if(value == "Youth Medium"){
	strSelect += "<option value=\'Youth Medium\' selected>Youth Medium (10-13)</option>";
	}else{
	strSelect += "<option value=\'Youth Medium\'>Youth Medium (10-13)</option>";
	}
	if(value == "Youth Large"){
	strSelect += "<option value=\'Youth Large\' selected>Youth Large (14-16)</option>";
	}else{
	strSelect += "<option value=\'Youth Large\'>Youth Large (14-16)</option>";
	}
	if(value == "Adult Small"){
	strSelect += "<option value=\'Adult Small\' selected>Adult Small</option>";
	}else{
	strSelect += "<option value=\'Adult Small\'>Adult Small</option>";
	}
	if(value == "Adult Medium"){
	strSelect += "<option value=\'Adult Medium\' selected>Adult Medium</option>";
	}else{
	strSelect += "<option value=\'Adult Medium\'>Adult Medium</option>";
	}
	if(value == "Adult Large"){
	strSelect += "<option value=\'Adult Large\' selected>Adult Large</option>";
	}else{
	strSelect += "<option value=\'Adult Large\'>Adult Large</option>";
	}
	strSelect += "</select></td></tr>";
	
	return strSelect;
}

function deleteInput() {
	if(isFirstRun){
		firstRun();
	}
	if (arrNameInput.length > 0) {  
		arrNameInput.pop(); 
		arrNameInputValue.pop(); 
		arrAgeInput.pop(); 
	 	arrAgeInputValue.pop(); 
	 	arrGenderInput.pop(); 
	 	arrGenderInputValue.pop(); 
	 	arrExperienceInput.pop(); 
	 	arrExperienceInputValue.pop(); 
	 	arrSchoolInput.pop(); 
	    arrSchoolInputValue.pop(); 
	 	arrUniformInput.pop(); 
		arrUniformInputValue.pop(); 
	 	arrProgramInput.pop(); 
	 	arrProgramInputValue.pop();
		/*arrLocationInput.pop(); 
	 	arrLocationInputValue.pop(); */
	 	arrRequestInput.pop(); 
	 	arrRequestInputValue.pop(); 
	 	arrBirthdateInput.pop(); 
	 	arrBirthdateInputValue.pop(); 
		arrEthnicityInput.pop(); 
	 	arrEthnicityInputValue.pop(); 
	}
	display();
	getTotal();
}

function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,"");
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+","+
	num.substring(num.length-(4*i+3));
	return (((sign)?"":"-") + "$" + num + "." + cents);
}

function createExperienceInput(name, id,value) {
	strSelect = "";
	strSelect += "<tr><td></td><td>Experience:</td><td><select name=\'"+name+id +"\' id=\'"+name+id +"\' class=\'eventform\' onChange=\'javascript:arr" + name + "InputValue[" + id + "]=this.value\' >";
	strSelect += "<option value=\'\' selected>Select one...</option>";
	if(value != "no experience"){
		strSelect += "<option value=\'no experience\'>No Experience</option>";
	}else{
		strSelect += "<option value=\'no experience\' selected>No Experience</option>";
	}
	if(value != "1-2"){
		strSelect += "<option value=\'1-2\'>1-2 Years</option>";
	}else{
		strSelect += "<option value=\'1-2\' selected>1-2 Years</option>";
	}
	if(value != "3-4"){
		strSelect += "<option value=\'3-4\'>3-4 Years</option>";
	}else{
		strSelect += "<option value=\'3-4\' selected>3-4 Years</option>";
	}
	if(value != "5"){
		strSelect += "<option value=\'5\'>5+ Years</option>";
	}else{
		strSelect += "<option value=\'5\' selected>5+ Years</option>";
	}
	strSelect += "</select></td></tr>";
	
	return strSelect;
}

//check for integer, pass it form name
function CheckNumber(obj,index)
{	
	var form=obj;
	var vld_Float =/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
	for(var x=0;x<form.length; x++){
		var fieldName=form.elements[x].name;
		/* define elements to be tested here*/
    var indexfield=fieldName.indexOf(index);
		if (indexfield>=0){
			if(eval(vld_Float).test(form.elements[x].value)==false){
				
				form.elements[x].focus;
				alert("Please Enter a Valid Number.");
				
				return false;
			}
		}
	}	
	return true;
}

function SpecifyAmount(obj){
	obj.donation[10].checked=true;
	getTotal();
}

function applyOD(){
	form=document.register;
	//get primary person attending price
	if (document.getElementById("primaryprogram").value > ""){
		prog_price=parseFloat(eval("form.value_"+document.getElementById("primaryprogram").value+".value"));
	}else{
		prog_price=0;
	}
	
	//additional attendees
	for(x=0;x<form.length; x++){
		fieldName=form.elements[x].name;
		program=fieldName.indexOf("Program");
		if (program >= ""){
			if (document.getElementById(fieldName).value > "" ){
				prog_price=prog_price+parseFloat(eval("form.value_"+document.getElementById(fieldName).value+".value"));
			}
		}
	}
	
	//apply open doors discount
	var p = (matrix[obj.openDoorsSalary.value])/100;
	prog_price = prog_price * p
	
	//donations
	for(x=0;x<form.donation.length;x++){
		if (form.donation[x].checked==true){
			var donate=form.donation[x].value;
			if (donate=="spec"){
				donate=0;
				if (CheckNumber(this.form,'spec_donate')){
					donate=form.spec_donate.value;
				}else{
					donate=0;
				}
			}
		}
	}
	prog_price=prog_price + parseFloat(donate);
	
	total=prog_price;
	document.getElementById("eCount").value = arrNameInput.length;
	document.getElementById("total").value = formatCurrency(total);
}

var xmlhttp=false; 
/*@cc_on @*/ 
/*@if (@_jscript_version >= 5) 
// JScript gives us Conditional compilation, we can cope with old IE versions. 
// and security blocked creation of the objects. 
  try { 
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); 
  } catch (e) { 
   try { 
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
   } catch (E) { 
    xmlhttp = false; 
   } 
  } 
@end @*/ 
if (window.XMLHttpRequest) {
	xmlhttp = new XMLHttpRequest(); 
}else{
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
function loadFragmentInToElement(fragment_url, element_id) { 
	var element = document.getElementById(element_id); 
    //document.getElementById('loadInfo').innerHTML = 'Loading ...'; 
    element.innerHTML = 'Loading...';
    xmlhttp.open("GET", fragment_url); 
    xmlhttp.onreadystatechange = function() { 
      if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { 
      element.innerHTML = xmlhttp.responseText; 
      
      //document.getElementById('loadInfo').innerHTML = '....'; 
      } 
    } 
    xmlhttp.send(null); 
}
function loadOpenDoorsApplication(){
	loadFragmentInToElement('/classes/membership/odForm.php', 'appDiv');
}