jQuery(document).ready(function(){
	jQuery('.row').hover(
		function(){
			jQuery(this).addClass('row_hover');
		},
		function(){
			jQuery(this).removeClass('row_hover');
		}
	);
});

function populateSearchValues(e,localArray) {
  var d = new Array();
  d = localArray;
  for(var i=0; i<e.length; i++) {
    for(var j=0; j<d.length; j++) {
      if(e[i].value == d[j]) {
        e[i].checked = true;
      }
    }
  }
}

function submitForm(form,location,method){
  form.action=location;
  if(method) {
    form.method = method;
  }
  if(form.SubmitFunction){
    eval(form.SubmitFunction.value);
  }
  form.submit();
}

function moveAthletic(sourceList,radioset,destList) {
	isThere=0;
	i=sourceList.options.length
	var selected;
	for(i = 0; i < radioset.length; i++){
		if(radioset[i].checked == true){
			selected = radioset[i].value;
		}
	}
	if(sourceList.options[sourceList.selectedIndex]  && sourceList.options[sourceList.selectedIndex].value){
		var tmp1=selected+sourceList.options[sourceList.selectedIndex].value;
		var tmp2=sourceList.options[sourceList.selectedIndex].text+"("+selected+")";

		for (j=0; j<destList.options.length; j++){
			if(tmp1==destList.options[j].value){
					isThere=1;
			}
		
		}
		if(isThere==0){
			if(sourceList.options != null){
				var i=destList.options.length;
				destList.options[i]=new Option(tmp2);
				destList.options[i].value=tmp1;			
			}
		}
	}else{
		alert("Please select a sport!");
	}
  	
}
/////////////////////////////////////////////////////////////////////////////////

function fillSelectFromArray(selectCtrl, itemArray){
	var i, j;
 	var prompt;
	
 	// empty existing items
 	for (i = selectCtrl.options.length; i >= 0; i--) {
  		selectCtrl.options[i] = null; 
 	}
 	j=0;
 	if (itemArray != null) {
		//alert("testing good array: "+itemArray.length+":"+selectCtrl.options.length);
  		// add new items
  		for (i = 0; i < itemArray.length; i++) {
   			selectCtrl.options[i] = new Option(itemArray[i][1]);
   			if (itemArray[i][1] != null) {
    				selectCtrl.options[i].value = itemArray[i][0]; 
			}
   		}
   		j++;
  	}
	
}
////////////////////////////////////////////////////////////////////////////////

function moveTo(selectOne,selectTwo){
	isThere=0;
	i=selectTwo.options.length;
	if(selectOne.options[selectOne.selectedIndex] && selectOne.options[selectOne.selectedIndex].value){
	   for(k=0; k<selectOne.options.length; k++){
		isThere=0;
		if(selectOne.options[k].selected==true){
			for(j=0; j<selectTwo.options.length; j++){
				if(selectOne.options[k].value==selectTwo.options[j].value){
					isThere=1;
				}
			}
			i=selectTwo.options.length;
			if(isThere==0){
				selectTwo.options[i]=new Option(selectOne.options[k].text);
				selectTwo.options[i].value=selectOne.options[k].value;
			}
		}
	   }
	}else{
		alert("Please select a value!");
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveAll(selectOne,selectTwo){
	isThere=0;
	for(k=0; k<selectOne.options.length; k++){
	        isThere=0;
		for(j=0; j<selectTwo.options.length; j++){
			if(selectOne.options[k].value==selectTwo.options[j].value){
				isThere=1;
			}
		}
		i=selectTwo.options.length;
		if(isThere==0){
			selectTwo.options[i]=new Option(selectOne.options[k].text);
			selectTwo.options[i].value=selectOne.options[k].value;
		}
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveFrom(selectform){
	if(selectform.selectedIndex!=-1){
		for(k=0; k<selectform.options.length; k++){	
			if(selectform.options[k].selected==true){
				selectform.options[k]=null;
				k--;
			}
		}
	}
}
////////////////////////////////////////////////////////////////////////////////
 
function moveTextAndSelect(textbox,sourceList,destList1,destList2){
 	moveTo(sourceList,destList2);
	value=textbox.value+":"+sourceList.options[sourceList.selectedIndex].value;
 
 	isThere=0;
	for(j=0; j<destList1.options.length; j++){
		if(destList1.options[j].value==value){
			isThere=1;
		}
	}
	if(isThere==0  && !textbox.value==""){
		i=destList1.options.length;
 		destList1.options[i]=new Option(textbox.value);
		destList1.options[i].value=value;
		
	}
}
////////////////////////////////////////////////////////////////////////////////

function moveSelectAndSelect(slist,sourceList,destList1,destList2){
 	moveTo(sourceList,destList2);
	value=slist.options[slist.selectedIndex].value;
 
 	isThere=0;
	for(j=0; j<destList1.options.length; j++){
		if(destList1.options[j].value==value){
			isThere=1;
		}
	}
	if(isThere==0){
		i=destList1.options.length;
 		destList1.options[i]=new Option(slist.options[slist.selectedIndex].text);
		destList1.options[i].value=value;
		
	}
}
////////////////////////////////////////////////////////////////////////////////


function test(sourceList,radioset,destList){
	var value;
	var text=sourceList.options[sourceList.selectedIndex].text+"("+radioset.value+")";
	if(radioset.value == "local"){
		value=sourceList.options[sourceList.selectedIndex].value+":true";
	}else{
		value=sourceList.options[sourceList.selectedIndex].value+":false";
	}
	var i=destList.options.length;
	destList.options[i]=new Option(text);
	destList.options[i].value=value;
}
////////////////////////////////////////////////////////////////////////////////

function moveRadiosetAndSelect(sourceList,radioset,destList){	
	isThere=0;
	i=sourceList.options.length
	for (j=0; j<destList.options.length; j++){

		reg=new RegExp(sourceList.options[sourceList.selectedIndex].text+":*");
		if(reg.test(destList.options[j].text)){
				isThere=1;
		}
		
	}
	if(isThere==0){
		var value;
			
		for(i = 0; i < radioset.length; i++){
			if(radioset[i].checked == true){
				var Selected = radioset[i].value;
			}	

	
		}
		var text=sourceList.options[sourceList.selectedIndex].text+"("+Selected+")";
		if(Selected == "local"){
			value=sourceList.options[sourceList.selectedIndex].value+":true";
		}else{
			value=sourceList.options[sourceList.selectedIndex].value+":false";
		}
		var i=destList.options.length;
		destList.options[i]=new Option(text);
		destList.options[i].value=value;
	}
	
}
////////////////////////////////////////////////////////////////////////////////

function moveSelect(sourceList,destList){
	isThere=0;
	i=destList.options.length;
	for (j=0; j<destList.options.length; j++){
		if(sourceList.options[sourceList.selectedIndex].text==destList.options[j].text){
				isThere=1;
		}
	}	
	if(isThere==0){				
	var text=sourceList.options[sourceList.selectedIndex].text;
	destList.options[i]=new Option(text);
	destList.options[i].text=text;
	}	

}
////////////////////////////////////////////////////////////////////////////////

function oldmoveSelect(sourceList,destList){

	var text=sourceList.options[sourceList.selectedIndex].text;
	var l=destList.options.length;
	destList.options[l]=new Option(text);
	destList.options[1].value=value;
	
}
////////////////////////////////////////////////////////////////////////////////

function moveSelect(sourceList1,sourceList2,sourceList3,destList){
	var text=sourceList1.options[sourceList1.selectedIndex].text+"("+sourceList2.options[sourceList2.selectedIndex].text+","+sourceList3.options[sourceList3.selectedIndex].text+")";
	var value=sourceList1.options[sourceList1.selectedIndex].value+":"+sourceList2.options[sourceList2.selectedIndex].value+":"+sourceList3.options[sourceList3.selectedIndex].value;
	isThere=0;
	i=destList.options.length;
	for (j=0; j<destList.options.length; j++){
		reg=new RegExp(sourceList1.options[sourceList1.selectedIndex].text+":*");
		
		if(reg.test(destList.options[j].text)){
				isThere=1;
		}
	}	
	if(isThere==0){				
		destList.options[i]=new Option(text);
		destList.options[i].value=value;
	}	

}
////////////////////////////////////////////////////////////////////////////////
function selectAll(sourceList1){
	for(i=0; i<sourceList1.options.length; i++){
		sourceList1.options[i].selected=true;
	}
	return true;
}
////////////////////////////////////////////////////////////////////////////////

function clearSearch() {
  var form = document.createElement("form");
  form.action = "/collegesearch/index.jsp";
  form.method = "GET";

  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "citysize");

  form.appendChild(input);
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "studentbodysize");

  form.appendChild(input);
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "locations");

  form.appendChild(input);

  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "majors");

  form.appendChild(input);
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "public_private");

  form.appendChild(input);  

  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "two_four_year");

  form.appendChild(input);   
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "religiousaffil");

  form.appendChild(input);    
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "studentbodytype");

  form.appendChild(input);  
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "ethnicmix");

  form.appendChild(input);   
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "athletics");

  form.appendChild(input);     
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "disabilities");

  form.appendChild(input);       
  
  var input = document.createElement("input");
  input.setAttribute("name", "domain");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", "specialservices");

  form.appendChild(input);         

  document.getElementsByTagName("body")[0].appendChild(form);

  form.submit();
}

////////////////////////////////////////////////////////////////////////////////

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1,c.length);
      if (c.indexOf(nameEQ) == 0) {
        var cParse = c.split("=");
        var e = cParse[1].split(":");
        
        return "aos="+e[0]+"&locations="+e[1]+"&two_four_year="+e[2]+"&public_private="+e[3]+"&regions="+e[4];
      }
    }
  }
}

////////////////////////////////////////////////////////////////////////////////

function makeArray(tmp) {
    if(tmp != null && !tmp.length) {
      tmp = [tmp];
    }
    return tmp;
}

function submitSearchForm(formName, action) {
  form = document[formName];
  var schoolList = makeArray(form.schoolList);  
  
  if(schoolList.length == 1) {
    form.productTypeID.value = 2;
    form.infozapType.value = "normalInfozap";
  }
  form.action = action;
  form.submit();
}

function submitInfozapForm(pAreaId, queryPage) {
  var featuredForm = document['featured_schools'];
  var tempList = makeArray(featuredForm.schoolList);
  
  var schoolList = new Array();
  var count = 0;
  
  for(i = 0; i < tempList.length; i++) {
    if(tempList[i].checked) {
      schoolList[count] = tempList[i];
      count++;
    }
  }
  
  var form = document.createElement("form");
  form.action = '/CVSetupAction.do';
  form.method = 'post';
  
  var input = document.createElement("input");
  input.setAttribute("name","infozapType");
  input.setAttribute("type","hidden");
  if(schoolList.length == 1) {
    input.setAttribute("value","normalInfozap");
  } else {
    input.setAttribute("value","dynamicInfozap");
  }
  
  form.appendChild(input);
  
  var input = document.createElement("input");
  input.setAttribute("name","productTypeID");
  input.setAttribute("type","hidden");
  if(schoolList.length == 1) {
    input.setAttribute("value", 2);
  } else {
    input.setAttribute("value", 3);
  }
  
  form.appendChild(input);
  
  var input = document.createElement("input");
  input.setAttribute("name","productAreaID");
  input.setAttribute("type","hidden");
  input.setAttribute("value",pAreaId);
  
  form.appendChild(input);
  
  for(i = 0; i < schoolList.length; i++) {
    var input = document.createElement("input");
    input.setAttribute("name","schoolList");
    input.setAttribute("type","hidden");
    if(schoolList.length == 1) {
      input.setAttribute("value", normalInfozapIds[schoolList[i].value]);
    } else {
      input.setAttribute("value", dynaInfozapIds[schoolList[i].value]);
    }
    form.appendChild(input);
  }//for
  
  input = document.createElement("input");
  input.setAttribute("name", "queryPage");
  input.setAttribute("type", "hidden");
  input.setAttribute("value", queryPage);
  form.appendChild(input);
  
  document.getElementsByTagName("body")[0].appendChild(form);
  
  form.submit();
}

function checkCount(formName, min, max) {
  var count = 0;
  var form = document[formName];

  var schoolList = makeArray(form.schoolList);
  for(i = 0; i < schoolList.length; i++) {
    if(schoolList[i].checked == true) {
      count++;
    }
  }

  if(count <= max && count >= min) {
    return true;
  } else {
    if(count < min) {
      alert("Please select at least " + min + " school(s).");
    }
    if(count > max) {
      alert("A maximum of " + max + " school(s) can be selected.");
    }
    return false;
  }
}

function checkCount2(formNames, min, max) {
  var count = 0;
  for(var i = 0; i < formNames.length; i++) {
    count += getCount(formNames[i]);
  }
  //alert("featured count " + count);
    var schoolListHidden = document.getElementsByName("schoolListHidden");
    if (schoolListHidden != null){
        for(var i = 0; i < schoolListHidden.length; i++) {
            var obj = document.getElementById(schoolListHidden[i].value);
            if (obj != null) continue;
            count++;
        }//for    
    }//if   
  
  //alert("featured + hidden count: " + count);
  if(count <= max && count >= min) {
    return true;
  } else {
    if(count < min) {
      alert("Please select at least " + min + " school(s).");
    }
    if(count > max) {
      alert("A maximum of " + max + " school(s) can be selected.");
    }
    return false;
  }    
}

function getCount(formName) {
  var count = 0;
  var form = document[formName];
  if(form != null && form.schoolList != null) {
    var schoolList = makeArray(form.schoolList);
    for(var i = 0; i < schoolList.length; i++) {
      if(schoolList[i].checked == true) {
        count++;
      }
    }
    //alert(form.name + ", count = " + count);   
  }//if
  return count;
}

function selectSchools(checkbox, formName) {
  var form = document[formName];
  var schoolList = makeArray(form.schoolList);
  for(i = 0; i < schoolList.length; i++) {
    if(checkbox.checked == true) {
      schoolList[i].checked = true;
     } else {
      schoolList[i].checked = false;
    }
  }
}

function submitForms(formNames, action, queryPage) {
  var masterList = new Array();
  for(var i = 0; i < formNames.length; i++) {
    var form = document[formNames[i]];
    if(form != null && form.schoolList != null) {
      var schoolList = makeArray(form.schoolList);
      for(var j = 0; j < schoolList.length; j++) {
        if(schoolList[j].checked == true) {
          masterList.push(schoolList[j]);
        }
      }
      
    }//if
  }//for
  
  var schoolListHidden = document.getElementsByName("schoolListHidden");
  if (schoolListHidden != null){
      for(var j = 0; j < schoolListHidden.length; j++) {
        if (schoolListHidden[j].value != null) {
            var o = document.getElementById(schoolListHidden[j].value);
            if (o == null){
                masterList.push(schoolListHidden[j]);
            }                
        }//if
        
      }            
  }//if schoolListHidden != null
  
  
  var form = document.createElement('form');
  form.setAttribute("method", "post");
  form.setAttribute("action", action);
  
  for(var i = 0; i < masterList.length; i++) {
    var input = document.createElement('input');
    input.setAttribute('type','hidden');
    //alert(masterList[i].name + ",   " + masterList[i].value);
    if (masterList[i].name == "schoolListHidden") {
        input.setAttribute('name', 'schoolList');
    }else {
        input.setAttribute('name',masterList[i].name);
    }    
    input.setAttribute('value',masterList[i].value);
    form.appendChild(input);
  }
  
  var input = document.createElement('input');
  input.setAttribute('type','hidden');
  input.setAttribute('name','queryPage');
  input.setAttribute('value',queryPage);
  
  form.appendChild(input);
  
  document.body.appendChild(form);
  
  form.submit();
}


