var zipdebug = false;

function addSubject()
{
	document.getElementById("subjects_invis").innerHTML += '<input checked type="checkbox" name="crs[]" value="'+document.getElementById("ssubject").value+'" >'+document.getElementById("ssubject").value+'<br>';
	document.getElementById("ssubject").value = "";
}

function updateSchool()
{
	document.getElementById("tschool").value = '<br>School: '+document.getElementById("sschool").value;	
}

function moveOver()  
{
var boxLength = document.payfrm.choiceBox.length;
var selectedItem = document.payfrm.available.selectedIndex;
var selectedText = document.payfrm.available.options[selectedItem].text;
var selectedValue = document.payfrm.available.options[selectedItem].value;
var i;
var isNew = true;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
thisitem = document.payfrm.choiceBox.options[i].text;
if (thisitem == selectedText) {
isNew = false;
break;
      }
   }
} 
if (isNew) {
newoption = new Option(selectedText, selectedValue, false, false);
document.getElementById("subjects_invis").innerHTML += '<input checked type="checkbox" name="crs[]" value="'+selectedText+'" >'+selectedText+'<br>';
document.payfrm.choiceBox.options[boxLength] = newoption;
}
document.payfrm.available.selectedIndex=-1;
}
function removeMe() {
var boxLength = document.payfrm.choiceBox.length;
arrSelected = new Array();
var count = 0;
for (i = 0; i < boxLength; i++) {
if (document.payfrm.choiceBox.options[i].selected) {
arrSelected[count] = document.payfrm.choiceBox.options[i].value;
}
count++;
}
var x;
for (i = 0; i < boxLength; i++) {
for (x = 0; x < arrSelected.length; x++) {
if (document.payfrm.choiceBox.options[i].value == arrSelected[x]) {
document.payfrm.choiceBox.options[i] = null;
   }
}
boxLength = document.payfrm.choiceBox.length;
   }
}
function saveMe() {
var strValues = "";
var boxLength = document.payfrm.choiceBox.length;
var count = 0;
if (boxLength != 0) {
for (i = 0; i < boxLength; i++) {
if (count == 0) {
strValues = document.payfrm.choiceBox.options[i].value;
}
else {
strValues = strValues + "," + document.payfrm.choiceBox.options[i].value;
}
count++;
   }
}
if (strValues.length == 0) {
alert("You have not made any selections");
}
else {
alert("Here are the values you've selected:\r\n" + strValues);
   }
}


//***************************start*****************************
	function getElementsByClassName(strClass, strTag, objContElm) {
	/*
	usage:
	cont = container, element with id name ex:
	cont = document.getElementById('container')

	objClassArry = getElementsByClassName('one')	//array with all class 'one' objs
	getElementsByClassName('one', 'a', cont)		//class 'one' objs inside of <a>
	getElementsByClassName('one two', 'a', cont)	//'one' AND 'two' in <a>
	getElementsByClassName('one|two', 'span', cont)	//'one' OR 'two' in <a>

	for (i = 0; i < objClassArry.length; i++) 
	   // Do your thing here.
	   //ex: objClassArry[i].id
	}
	*/

		strTag = strTag || "*";
		objContElm = objContElm || document;
		var objColl = objContElm.getElementsByTagName(strTag);
		if (!objColl.length &&  strTag == "*" &&  objContElm.all) objColl = objContElm.all;
		var arr = new Array();
		var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
		var arrClass = strClass.split(delim);
		for (var i = 0, j = objColl.length; i < j; i++) {
			var arrObjClass = objColl[i].className.split(' ');
			if (delim == ' ' && arrClass.length > arrObjClass.length) continue;
			var c = 0;
			comparisonLoop:
			for (var k = 0, l = arrObjClass.length; k < l; k++) {
				for (var m = 0, n = arrClass.length; m < n; m++) {
					if (arrClass[m] == arrObjClass[k]) c++;
					if (( delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length)) {
						arr.push(objColl[i]);
						break comparisonLoop;
					}
				}
			}
		}
		return arr;
	}

	// To cover IE 5.0's lack of the push method
	Array.prototype.push = function(value) {
		this[this.length] = value;
	}
	//*******************END*****************************


	function getIndexByValue(selectlist, valfind) {
		//This functions returns the index number for a submitted option box value
		i=0;
		while (selectlist.options[i] != null) {
			if (selectlist.options[i].value == valfind) {
				return i
			}
			i++
		}
		return 0;
	 
	 }
	
 
	function showOneClass(cName,idName, dispType) {
		//hides all elements of class cName except for one with id idName

		//cont = container, element with id name ex:
		//cont = document.getElementById('container')
		//getElementsByClassName('one', 'a', cont)		//class 'one' objs inside of <a> inside cont
		objClassArry = getElementsByClassName(cName,'span');	//array with all class 'one' objs

		for (i = 0; i < objClassArry.length; i++) {
			if (objClassArry[i].id != idName) {
				objClassArry[i].style.display = 'none';
			} else {
				objClassArry[i].style.display = dispType;
			}
		}
	}
 
 
	function showhidedropdown(state_max, docform) {
	//to get an option value:   document.form_name.select_id.options[option ID starts with 1].value
	//to get current option ID:   document.form_name.select_id.selectedIndex
	//to get current option value:  document.form_name.select_id.options[document.form_name.select_id.selectedIndex].value
	//pain in the ass, huh?
		
		
		new_id=document.getElementById(docform.thisstate.options[docform.thisstate.selectedIndex].value)
		//new_id=eval(thisstate.value)

		for(i=0;i < state_max+1; i++){
			allunv = document.getElementById("thisunv"+i)
			allunv.selectedIndex = 0
			cur_id = document.getElementById("university"+i)
			
			//cur_id=eval("university"+i)
			
			if (cur_id==new_id){
				cur_id.style.display = "inline"
			}	else{
				cur_id.style.display = "none"
			} 
		} 
		docform.school.value = ""
	}


	function selectschool(curunv, docform) {

		docform.school.value = curunv.options[curunv.selectedIndex].value

		
		scale = parseInt(curunv.options[curunv.selectedIndex].getAttribute('value2'))
		pricegrid(scale, docform)
		showstep3 = document.getElementById("step3")
		showstep3.style.display = "block";
		
		changerow = docform.level.selectedIndex
		changecol = docform.hours.selectedIndex

		if (changerow && changecol) {
			temp = "g"+changerow+changecol
			cell = document.getElementById(temp)
			docform.rate.value = cell.innerHTML.replace("$","")
		}	
		
	}
	
	
	function setschool(schoollist, unvfrm) { //a simple version of select school
		unvfrm.school.value = schoollist.options[schoollist.selectedIndex].value
	}
	
	function matchZip(docform){
		zip = document.getElementById('zipForm').value;
		var buysnd=document.payfrm
		//alert(ziparray[6][2]);
		//alert(arrlength);
		var uindex = "";
		for(i=0; i<arrlength; i++){
			if(ziparray[i][0] > zip){
				if(ziparray[i][0] - zip < zip - ziparray[i-1][0]){
					uindex = i;	
					break;
				}else{
					uindex = i-1;
					break;
				}
			}
		}
		if(zipdebug==true){
			alert(ziparray[uindex][2]);
		}
		if(uindex==""){
			uindex = arrlength-1;	
		}
		buysnd.school.value = ziparray[uindex][4];
		pricegrid(ziparray[uindex][1],docform);
	}
	
	
	function pricegrid(scale, docform) {
		
		for(row=1;row <= 5; row++){
			for(col=1;col <= 6; col++){
				cell = document.getElementById("g"+row+col);
				level = row-1+scale;
				if (row == 5) {
					//level=10-1; //for megamind
					level=16-1+scale; //for megamind
				}
				cell.innerHTML = "$"+priceary[level][col];
				//cell.innerHTML = "$"+level+"]["+col;
			}
		}
	
	}


	function changecolor(docform) {

		changerow = docform.level.selectedIndex

		changecol = docform.hours.selectedIndex

		for(row=1;row <= 5; row++){
			for(col=1;col <= 6; col++){
				cell = document.getElementById("g"+row+col)

				if (row == changerow) {
					cell.style.backgroundColor = "#FF8588"
				}	else if (col == changecol) {
					cell.style.backgroundColor = "#B9C3FF"
				}	else {
					cell.style.backgroundColor = "#D6D6D6"
				}
				cell.style.color = "#000000"
			}
		}
		
		if (changerow && changecol) {
			cell = document.getElementById("g"+changerow+changecol)
			cell.style.backgroundColor = "purple"
			cell.style.color = "white"
			docform.rate.value = cell.innerHTML.replace("$","")
			
			if (docform.travel[1].checked==true) {
				travelfee = docform.travel[1].value;
			} else if (docform.travel[2].checked==true) {
				travelfee = docform.travel[2].value;
			} else {
				travelfee = 0;
			};
			//Must have the *1 or it considers them strings and breaks
			sspfee = 19.95;
			if (docform.returning.value=="YES") {
				sspfee = 0;
			}
			temptotal = ((cell.innerHTML.replace("$","")*1 + travelfee*1) * docform.hours.options[changecol].value) + sspfee;
			temptotal = temptotal.toFixed(2);
			docform.totalbox.value = temptotal;
		}
		else {
			docform.rate.value = "";
			docform.totalbox.value = "";
		}
	}
	
	
	function clickflipbar(the_id_name) {
		//version 2, changes img and div at same time
		//this will hide/show an element with name the_id_name
		//and it will switch the picture on an element with the_id_namei
		
		the_id = document.getElementById(the_id_name)
		the_img = document.getElementById(the_id_name + "i")
		
		if (the_img.src.indexOf('open') > 0) {
			if (the_id) the_id.style.display = "none"
			the_img.src = 'images/tutors-college-close.gif';
		}
		else {
			if (the_id) the_id.style.display = "block"
			the_img.src = 'images/tutors-college-open.gif';
		}
	}//*/


	function showhidesomething(the_id_name) {
		//alert(typeof(the_idg));
		if (typeof(the_idg) == "object" && the_old_nameg != the_id_name ) {
			the_idg.style.display = "none";
		}
		the_idg = document.getElementById(the_id_name);
		if (the_idg) {
			if (the_idg.style.display=="block") {
				the_idg.style.display = "none";
			} else {
				the_idg.style.display = "block";
			}
		}
		the_old_nameg = the_id_name;
	}


	function hoverflip1bar(the_img) {
		if (the_img.src.indexOf('close') > 0) { /*the_img.src = 'images/tutors-college-subjects.gif'; */ }
	}
	function hoverflip2bar(the_img) {
		if (the_img.src.indexOf('subjects') > 0) { the_img.src = 'images/tutors-college-close.gif';  }
	}
