var ShowLinks=true;
var PageIsLoaded=false;
var SportsLimit=20;
var MajorsLimit=20;

var description=new Array;
    description['enroll_size___4']="Student Population - The more the better";
    description['enroll_size___3']="Student Population - Lots, but not a small city";
    description['enroll_size___2']="Student Population - Keep it cozy";
    description['enroll_size___1']="Student Population - Small and intimate";
	description['tuition_cost___1']="Tuition - Up to $5000";
	description['tuition_cost___2']="Tuition - Up to $10000";
	description['tuition_cost___3']="Tuition - Up to $15000";
	description['tuition_cost___4']="Tuition - Up to $20000";
	description['tuition_cost___5']="Tuition - Up to $25000";
	description['tuition_cost___6']="Tuition - $25000 or more";
	description['college_type_allmen_or_allwomen___MO']="College Type - Men’s (single sex)";
	description['college_type_allmen_or_allwomen___WO']="College Type - Women’s (single sex)";
	description['affiliations___AA']="Affiliation - Historically Black Colleges and Universities (HBCU)";
	description['affiliations___HACU']="Affiliation - Hispanic Association of Colleges and Universities (HACU)";
	description['affiliations___CCCU']="Affiliation - Christian Colleges and Universities";
	description['accelerated_degree_programs___AD']="Accelerated degree program";
	description['accelerated_degree_programs___AP']="AP credit";
	description['accelerated_degree_programs___CL']="CLEP credit";
	description['disablility_programs___AP']="Academic programs";
	
	description['academic_programs___HP']="Academic program - Honors program";
	description['academic_programs___DM']="Academic program - Double majors";
	description['academic_programs___SM']="Academic program - Student-designed majors";
	description['academic_programs___IS']="Academic program - Independent study";
	description['academic_programs___ES']="Academic program - ESL programs";
	description['academic_programs___SA']="Academic program - Study abroad";
	description['academic_programs___OL']="Academic program - Online learning";
	
	description['special_services___TG']="Special Service - Tutoring";
	description['special_services___OS']="Special Service - Off-campus study";
	description['career_services___IT']="Special Service - Internships";
	description['career_services___WS']="Special Service - Work-study";
	
	description['male_female_ratio___PW']="M/F Ratio - Primarily women (More than 80%)";
	description['male_female_ratio___PM']="M/F Ratio - Primarily men (More than 80%)";
	description['male_female_ratio___CE']="M/F Ratio - I'm all about balance";
	
	description['cultural_diversity___1']="Cultural Diversity - More than 15%";
	description['cultural_diversity___2']="Cultural Diversity - More than 25%";
	description['cultural_diversity___3']="Cultural Diversity - More than 40%";
	
	description['in_out_state___II']="Student Location - Mostly in-state";
	description['in_out_state___OS']="Student Location - Mostly out-of-state";
	description['in_out_state___GM']="Student Location - A good mix";
	
	description['clubs___NP']="Club - School Newspaper";
	description['clubs___DT']="Club - Drama/Theater Club";
	description['clubs___RS']="Club - College Radio station";
	description['clubs___BN']="Club - Band";
	description['clubs___CG']="Club - Choral group";
	description['clubs___TV']="Club - College Television Station";
	
	description['dorm___FR']="Dorms - Yes, at least for freshmen";
	description['dorm___UG']="Dorms - Yes, for all undergrads";
	
	description['selectivity___MST']="Selectivity - Most difficult";
    description['selectivity___VERY']="Selectivity - Very difficult";
    description['selectivity___MOD']="Selectivity - Moderately difficult";
    description['selectivity___MIN']="Selectivity - Minimally difficult";
    description['selectivity___NONC']="Selectivity - Open enrollment";
    
    description['gpa___3']="Average High School GPA = 3.0 or better";
    description['gpa___2']="Average High School GPA = 2.5 or better";
    description['gpa___1']="Average High School GPA = 2.0 or better";
	
	description['setting___Urban']="Campus Setting - Urban";
    description['setting___Suburban']="Campus Setting - Suburban";
    description['setting___Small_town']="Campus Setting - Small Town";
	description['setting___Rural']="Campus Setting - Rural";

	description['college_type_public_or_private___Public']="College Type - Public";
	description['college_type_public_or_private___Private']="College Type - Private";
	     
	description['college_type_2_or_4yr___2yr']="College Type - 2 year";
	description['college_type_2_or_4yr___4yr']="College Type - 4 year";
	     
	description['college_type_allmen_or_allwomen___MO']="College Type - All Men";
	description['college_type_allmen_or_allwomen___WO']="College Type - All Women";
	
	description['degrees___Bachelors']="Degrees Offered - Bachelors";
	description['degrees___Associates']="Degrees Offered - Associates";
	description['degrees___Certificate']="Degrees Offered - Certificate";
	
	description['advanceddegrees___Masters']="Advanced Degrees Offered - Masters";
	description['advanceddegrees___Doctorate']="Advanced Degrees Offered - Doctorate";
	
	

//MAJORS START
function select_all(select_1) 
{
  if(!select_1) return;
  if(!select_1.options) return;
  for (var i = 0; i < select_1.options.length; i++) 
  {
	select_1.options[i].selected = true;
  }
}
function select_none(select_1) 
{
  //alert(select_1);
  if(!select_1) return;
  if(!select_1.options) return;
  for (var i = 0; i < select_1.options.length; i++) 
  {
    select_1.options[i].selected = false;
  }
}
function select_blank(select_1) {
  for (var i = 0; i < select_1.options.length; i++) {
    if(select_1.options[i].value=0)
    {
    select_1.options[i].value = "";
    }
  }
}
function move(fbox,tbox,mode) 
{
	//alert('fbox.name='+fbox.name);
	//alert(fbox.form.name);
	if(fbox.name=="states")blurstate();
	
	if (mode=='all'){select_all(fbox)}
		
	var arrFbox = new Array();
	var arrTbox = new Array();
	var arrLookup = new Array();
	var i;

	numberofselected = tbox.options.length - 1

	for (i = 0; i < tbox.options.length; i++) 
	{
		arrLookup[tbox.options[i].text] = tbox.options[i].value;
		arrTbox[i] = tbox.options[i].text;
	}
	var fLength = 0;
	var tLength = arrTbox.length;
	var selectedOrnot = 0;
	for(i = 0; i < fbox.options.length; i++) 
	{
		arrLookup[fbox.options[i].text] = fbox.options[i].value;
		if (fbox.options[i].selected && fbox.options[i].value != 0) 
		{
			arrTbox[tLength] = fbox.options[i].text;
			tLength++;
			selectedOrnot++;
		}
		else {
			arrFbox[fLength] = fbox.options[i].text;
			fLength++;
	   }
	}

	if (selectedOrnot == 0) 
	{
		return;
		//alert("Please select at least one option to add or remove.")
	}
	
	arrFbox.sort();
	arrTbox.sort();
	
	fbox.length = 0;
	tbox.length = 0;
	var c;
	for(c = 0; c < arrFbox.length; c++) 
	{
		var no = new Option();
		no.value = arrLookup[arrFbox[c]];
		no.text = arrFbox[c];
		fbox[c] = no;
	}
	for(c = 0; c < arrTbox.length; c++) 
	{
		var no = new Option();
		no.value = arrLookup[arrTbox[c]];
		no.text = arrTbox[c];
		tbox[c] = no;
   }
   //alert(fbox.name);
   //alert(fbox.form.name);
   if(fbox.name=="sports")cleanUpWomens();
   if(fbox.name=="nacountry")ClearLocationSearch();
   //if(fbox.name=="regionlist" || fbox.name=="regions")rebindRegions();
   //select_all(tbox);
}
function addToList(listField, newText, newValue) 
{
   //alert(newText);
   //alert(newValue);
   if ( ( newValue == "" ) || ( newText == "" ) ) 
   {
      //You cannot add blank values.
      return;
   } 
   else if(itemExists(listField, newText, newValue))
   {
		//do not add items to submajors list that have already been chosen.
		return;
   }
   else 
   {  
      var len = listField.length++; // Increase the size of list and return the size
      listField.options[len].value = newValue;
      listField.options[len].text = newText;
   } 
}
function itemExists(listField, newText, newValue)
{	
	for (k=0; k<document.profile.majors.length; k++)
	{	if(document.profile.majors[k].value==newValue) 
		{	
			return true;
		}
	}
}
function ClearList(listField) 
{	
	if(listField.length==0)return;
	listField.options[0] = null;
	ClearList(listField); 	
}
function populateSubmajors(cip)
{	
	ClearList(document.profile.submajorselect);
	var arrayname=eval("_" + cip);
	var arraynameCodes=eval("_" + cip + "Codes")
	for (i=0; i<arrayname.length; i++)
	{
		addToList(document.profile.submajorselect, arrayname[i], arraynameCodes[i])
	}
}

//MAJORS END

//SPORTS START
function cleanUpWomens()
{	
	for (k=0; k<document.profile.mensSports.length; k++)
	{	//alert(document.profile.mensSports[k].text);
		//alert(getIndex(womens_sportsCodes,document.profile.mensSports[k].value));
		if(getIndex(womens_sportsCodes,document.profile.mensSports[k].value) >= 0) 
		{	
			document.profile.mensSports[k].selected=true;
		}
	}
	move(document.profile.mensSports,document.profile.womensSports)
}
//SPORTS END

//REGIONS START
function moveRegions()
{
	for (i=0; i< document.profile.regionlist.length; i++)
	{
		if(document.profile.regionlist[i].selected)
		{
			var no = new Option();
			var prefix="";
			if(regionList[i]!="West" && regionList[i]!="Southwest"&& regionList[i]!="Midwest"&& regionList[i]!="South" && regionList[i]!="New England" && regionList[i]!="Mid-Atlantic")prefix="  -";
			no.text = prefix+regionList[i];
			document.profile.regions[document.profile.regions.length] = no;
		}
	}
}
function selectRegion(item)
{
	var i=item.selectedIndex;
	while ( i >= 0 ) 
	{ 
		if(item[i].value.length!=2)
		{
			item[i].selected=true;
			return;
		}
		i--; 
	} 
}
function selectStates(item)
{
	var i=item.selectedIndex;
	//alert(i);
	//alert(item[i].value);
	//if(item[i].selected)
	//{
		//item[i].selected=false;
	//}
	var selectChildren=false;
	for (i=0; i< document.profile.regionlist.length; i++)
	{
		if(item[i].value.length!=2 && item[i].selected)
		{
			selectChildren=true;
		}
		if(item[i].value.length!=2 && !item[i].selected)
		{
			selectChildren=false;
		}
		if(!item[i].selected)
		{
			item[i].selected=selectChildren;
		}
		//alert(selectChildren);
	}
}
function rebindRegions()
{
	for (i=0; i< document.profile.regionlist.length; i++)
	{
		document.profile.regionlist[i]=null;
	}
	document.profile.regionlist.length=0;
	for (j=0; j< regionList.length; j++)
	{
		var no = new Option();
		no.value = regionListCodes[j];
		var prefix="";
		if(regionList[j]!="West" && regionList[j]!="Southwest"&& regionList[j]!="Midwest"&& regionList[j]!="South" && regionList[j]!="New England" && regionList[j]!="Mid-Atlantic")prefix="-";
		no.text = prefix+regionList[j];
		document.profile.regionlist[j] = no;
	}
		
}
//REGIONS END

function getIndex(iarray,value)
{
	for (j=0; j<iarray.length; j++)
	{
		if(iarray[j]==value) return j;
	}
	//return "";
}
function exists(iarray,value)
{
	for (j=0; j<iarray.length; j++)
	{
		if(iarray[j]==value) return true;
	}
	return false;
}
function getFileName(url)
{
	path=url.toLowerCase();
	var pathArray = new Array();
	pathArray = path.split('.asp');
	filename=pathArray[0];
	return filename+'.asp';
}
function doSortPopup(url)
{
	if(getFileName(url)=='srchrslt.asp')
	{
		return true;
	}
	return false;
}
function SortOrder(url,sponsor)
{
	var defaultSort="&searchtype=multicrit&sortcolumn=iname&sortorder=";
	var customSort="&searchtype=multicrit&sortcolumn=CLIENT_CHECK,INAME&sortorder=";
	//if(sponsor!="1" && sponsor!="") return defaultSort;
	if(doSortPopup(url))
	{
		var sort=confirm('Would you like to see schools with extended features such as virtual tours, pictures, and live chats appear at the top of your results list?');
		if(sort) 
		{
			return customSort;
		}
		else
		{
			return defaultSort;
		}
	}
	else
	{
		return "";
	}
}
//timeout is in milliseconds
//(n minutes * 60 seconds per minute * 1000 milliseconds per second) 
//var timeout=<%=Session.Timeout%>;

function ShowTimeoutWarning (sponsor)
{
	var t = new Date();
    t.setMinutes(t.getMinutes()+5)
    alert("The system will automatically log out your session on " +t.toLocaleString()+".  To remain logged in, please click “OK” to continue.");
    //if(c)
    //{
		//document.form[0].submit();
    //}
    //else
    //{
    
   // }
    
}
var criteria = "";
function setInnerHTML(id,html)
{    
	 //alert('settingInnerHtml on'+id);
	 if(!document.getElementById) return; // Not Supported
     if(document.getElementById)
     {
          document.getElementById(id).innerHTML = html;
     }
}
function getInnerHTML(id)
{    if(!document.getElementById) return; // Not Supported
     if(document.getElementById)
     {
          return document.getElementById(id).innerHTML;
     }
}
var collectionArray = new Array();
function BuildCriteriaArray()
{
	//Get the existing criteria first
	//savedCriteria=getInnerHTML('savedCriteria');
	//alert(savedCriteria);
	var savedCriteriaArray=savedCriteria.split("||");
	var section="";
	
	//Loop through the data and assign new structures for each item
	for (i=0; i < savedCriteriaArray.length; i++)
	{
		var itemArray=savedCriteriaArray[i].split("::");
		this[itemArray[0]]=new structure();
		this[itemArray[0]].name=itemArray[0];
		this[itemArray[0]].value=itemArray[1];
		var sectionIndex=itemArray[0].indexOf("section_");
		if(sectionIndex > -1 )
		{
			section=itemArray[0];
		}
	    this[itemArray[0]].section=section;
		collectionArray[collectionArray.length]=this[itemArray[0]];
		 
	}
}
//////////////////////////////////////////////////////////// 
function getMajorDescriptionObsolete(code)
{
	var arrayname=code.substring(0,code.indexOf("."));
	var indexs=getIndex(eval("_"+arrayname+"Codes"),code)
	var description=eval("_"+arrayname)[indexs];
	return description;
}
function getMajorDescription(code)
{
	return allMajors[escape(code)];
}
var sportsArray = new Array();
function BuildSportsArray()
{
	for (i=0; i< mens_sports.length; i++)
	{
		sportsArray[mens_sportsCodes[i]]=mens_sports[i];
	}
	for (i=0; i< womens_sports.length; i++)
	{
		sportsArray[womens_sportsCodes[i]]=womens_sports[i];
	}
}
function getSportsDescription(code)
{
	if(sportsArray.length==0)BuildSportsArray();
	return sportsArray[code];
}
function getCountryDescription(code)
{
	
	var indexs=getIndex(countryArrayCodes,code)
	var description=countryArray[indexs];
	//alert(code);
	//alert(description);
	return description;
}
function getRegionsDescription(code)
{
	var indexs=getIndex(regionListCodes,code)
	var description=regionList[indexs];
	return description;
}
function getFaithsDescription(code)
{
	var indexs=getIndex(faithsArrayCodes,code)
	var description=faithsArray[indexs];
	return description;
}
function getDescription(item,code)
{
	if(code=="") alert("missing code");
	//alert(item);
	//alert(code);
	//alert(item+'='+code);
	var returnval="";
	var codeArray = new Array();
	codeArray=code.split(",");
	//alert(codeArray.length);
	for (n=0; n < codeArray.length; n++)
	{	
		//alert('codeArray.length='+ n );
		var thiscode=codeArray[n];
		thiscode=thiscode.trim();
		//alert(thiscode);
		if (item=="majors")
		{
			returnval=returnval + getMajorDescription(thiscode) + ", ";
		}
		else if (item=="sports")
		{
			returnval=returnval + getSportsDescription(thiscode) + ", ";  
		}
		else if (item=="country")
		{
			returnval=returnval + getCountryDescription(thiscode) + ", ";
		}
		else if (item=="nacountry")
		{
			returnval=returnval + getCountryDescription(thiscode) + ", ";
		}
		else if (item=="faiths")
		{
			returnval=returnval + getFaithsDescription(thiscode) + ", ";
		}
		else if (item=="satmath")
		{
			returnval=returnval + "SAT Math - "+ thiscode + ", ";
		}
		else if (item=="satcritreading")
		{
			returnval=returnval + "SAT Reading - "+ thiscode + ", ";
		}
		else if (item=="act_score")
		{
			returnval=returnval + "ACT Score - "+ thiscode + ", ";
		}
		else if (
		   item=="enroll_size" ||
		   item=="tuition_cost" ||
		   item=="college_type_allmen_or_allwomen" ||
		   item=="affiliations" ||
		   item=="accelerated_degree_programs" ||
		   item=="disablility_programs" ||
		   item=="academic_programs" ||
		   item=="special_services" ||
		   item=="career_services" ||
		   item=="male_female_ratio" ||
		   item=="cultural_diversity" ||
		   item=="in_out_state" ||
		   item=="clubs" ||
		   item=="dorm" ||
		   item=="selectivity" ||
		   item=="gpa"  ||
		   item=="setting"  ||
		   item=="college_type_public_or_private"  ||
		   item=="college_type_2_or_4yr"  ||
		   item=="college_type_allmen_or_allwomen" ||
		   item=="degrees"  ||
		   item=="advanceddegrees"
		  )
		{
			returnval=returnval + getOtherDescription(item+'___'+thiscode) + ", ";
		}
	}
	if(returnval!="")
	{
		//remove last comma
		if(returnval.substring(returnval.length-2,returnval.length)==", ")
		{
			returnval=returnval.substring(0,returnval.length-2);
		}
	} 
	
	if(returnval=="")returnval=code; 
	return returnval;
	
}
function getOtherDescription(code)
{
	//alert('getOtherDescription_Code='+ code);
	return description[escape(code)];
}
function BindCriteria(id,section,sponsor)
{
	//this function uses a global variable called ShowLinks
	//just set this value before calling BindCriteria
	//alert('binding '+id);
	//alert('section='+section);
	closediv(id);
	if(collectionArray.length==0)BuildCriteriaArray();
	//var collectiondump="";
	//for (j=0; j < collectionArray.length; j++)
	//{
		//collectiondump=collectiondump+ collectionArray[j].name+"="+collectionArray[j].value +'\n';
	//}
	//alert (collectiondump);
	//Loop through the collection array and build the criteria string
	var returnstring="";
	
	for (k=0; k < collectionArray.length; k++)
	{	
		if(section=="")
		{
			if(collectionArray[k].value!="" && collectionArray[k].name!="" && collectionArray[k].name!="section_SearchPath" && collectionArray[k].name!="pages"  && collectionArray[k].name!="majorsselect")
			{			
				if(ShowLinks)
				{
					returnstring=returnstring + "<a href=\"JavaScript:jump('"+collectionArray[k].section+ "','" + collectionArray[k].name + "','" + sponsor + "')\">" + getDescription(collectionArray[k].name,collectionArray[k].value) + "</a> > ";
				}
				else
				{
					returnstring=returnstring + collectionArray[k].value + " <b>></b> ";
				}
							
			}
		}
		else
		{
			if(collectionArray[k].value!="" && collectionArray[k].name!="" && collectionArray[k].name!="section_SearchPath" && collectionArray[k].name!="pages"  && collectionArray[k].name!="majorsselect" && collectionArray[k].section==section)
			{			
				//alert('ShowLinks='+ShowLinks);
				if(ShowLinks)
				{
					returnstring=returnstring + "<a href=\"JavaScript:jump('"+collectionArray[k].section+ "','" + collectionArray[k].name + "','" + sponsor + "')\">" + getDescription(collectionArray[k].name,collectionArray[k].value) + "</a> > ";
				}
				else
				{
					returnstring=returnstring + getDescription(collectionArray[k].name,collectionArray[k].value) + " <b>></b> ";
				}
			}
		}
	}
	//criteria="<textarea rows='5' cols='70' style='font-size:11px;'>"+returnstring+"</textarea><br>Massaged<br>"+returnstring2;
	criteria=returnstring;
	setInnerHTML(id,criteria);
	opendiv(id);
}
function ShowSections()
{	
	var currentSection="";
	var returnstring="";
	for (k=0; k < collectionArray.length; k++)
	{	
		if((currentSection!=collectionArray[k].section) && collectionArray[k].section!="section_SearchPath")
		{
			currentSection=collectionArray[k].section;
			returnstring=returnstring + currentSection.replace('section_','') + " <b>></b> ";
		}
	}
	//setInnerHTML('sectionPath',returnstring);
}

///////////////////////////////////////////////////////////////////////////////////////////////
var thisSection="";
function SetSection(section)
{	
	//alert('sectionset');
	thisSection=section;
	//setInnerHTML('currentsection',section);
}
function updateCriteria(item,id,sponsor)
{
	return;
	//Look though the colllection array to see if the current data matches any existing items
	//we want to overwrite existing data
	//alert(item.form.name);
	//alert(item.type);
	SelectBoxes();
	var val=getValues(item);
	//alert('val1='+val);
	var itemExists=false;
	for (j=0; j < collectionArray.length; j++)
	{
		if(collectionArray[j].name==item.name)
		{	itemExists=true;
			//alert('itemexists');
			//alert(collectionArray[j].name+"=="+item.name);
			collectionArray[j].value=val;
		}
	}
	//alert('val2='+val);
	if(!itemExists) //create a new structure and add it to the collectionArray
	{
		//alert(item.name);
		this[item.name]=new structure();
		this[item.name].name=item.name;
		this[item.name].value=val;
		this[item.name].section="";
		collectionArray[collectionArray.length]=this[item.name];
	}
	//Now bind the collection array and build the criteria bar
	if(thisSection=="")
	{
		BindCriteria(id,'',sponsor);
	}
	else
	{
		BindCriteria(id,thisSection,sponsor);
	}
	UnselectBoxes();
	//BindCriteria(id,'',sponsor);
} 
function structure() 
{
  this.name=null
  this.value=null
  this.section=null
}
function getValues(item)
{
	//alert(item.value);
	//alert(item.name);
	//alert(item.form.name);
	///////////////select_all(item);
	var element=eval("document." +item.form.name+ "." + item.name);
	if(!element.length)
	{
		if(element.selected||element.checked) 
		{	
			return element.value;
		}
		else
		{
			return element.value;
		}
	}
	else //loop through length and get values
	{
		var returnval="";
		for (i=0; i < element.length; i++)
		{	//alert(element[i].selected);
		    //alert(element[i].checked);
			if(element[i].selected||element[i].checked) 
			{	
				returnval=returnval + element[i].value.trim()+ ', ';
			}
		}
		//remove last comma
		if(returnval.substring(returnval.length-1,returnval.length)==", ")
		{
			returnval=returnval.substring(0,returnval.length-1);
		}
		//alert(returnval);
		//////////////select_none(item);
		return returnval;
	}
}
function jump(section,question,sponsor)
{
	var pageNameArray=new Array("Criteria","Basics","Academics","StudentBody","CampusLife","GettingIn","Results")
	var pageUrlArray=new Array("chooseCriteria.asp","srchCrit2.asp","srchCrit3.asp","srchCrit4.asp","srchCrit5.asp","srchCrit6.asp","srchRslt.asp")
	var Section=section.substring(section.indexOf('_')+1);
	var index=getIndex(pageNameArray,Section);
	var baseurl=pageUrlArray[index];
	//alert(baseurl);
	if(section=="")
	{
		var url="#"+question;
	}
	else
	{
		var url=baseurl+"?sponsor="+sponsor+ "&a=b#"+question;
	}
	submitThis(url);  //Use this if they want it to submit
	//document.location.href=url;
}
function expandCollapse() 
{
	for (var i=0; i<expandCollapse.arguments.length; i++) 
	{
		var element = document.getElementById (expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

function clearDefault(el) 
{
	if (el.defaultValue==el.value) el.value = ""
}
function opendiv() 
{
	//alert('opening'+opendiv.arguments[0]);
	for (var i=0; i< opendiv.arguments.length; i++) 
	{	
		var element = document.getElementById(opendiv.arguments[i]);
		if(!element) return; 
		element.style.display ="block";
	}
}
function closediv() 
{
	for (var i=0; i< closediv.arguments.length; i++) 
	{	
		var element = document.getElementById(closediv.arguments[i]);
		if(!element) return;
		element.style.display ="none";
	}
}
function ClearNonUs()
{
	
}
function swapSearches(item) 
{	
	//alert(item.value);
	//alert(item.name);
	//alert(item.form.name);
	
	var nacountry=eval("document." +item.form.name+ "." + "nacountry");
	select_all(nacountry);
	
	var USSelected=false;
	for (var i=0; i< nacountry.length; i++) 
	{	
		if(nacountry[i].value=="USA") USSelected=true;
	}
	select_none(nacountry);
	if(!USSelected && nacountry.value!="USA")
	{
		var doUS=confirm('This option is only for US searches.  Would you like to do a US search?');
		if (doUS)
		{
			addUS(item);
			ClearNonUs();
		}
		else
		{
			document.profile.location_search_option[0].checked=false;
			document.profile.location_search_option[1].checked=false;
			document.profile.location_search_option[2].checked=false;
			document.profile.location_search_option[3].checked=false;
			return;
		}
	}

	if(item.value=='State')
	{
		opendiv('state');
		closediv('region');
		closediv('metro');
		closediv('distance');
	}
	if(item.value=='Region')
	{
	
		opendiv('region');
		closediv('state');
		closediv('metro');
		closediv('distance');
	}
	if(item.value=='Metro Area')
	{
		closediv('region');
		closediv('state');
		opendiv('metro');
		closediv('distance');
	}
	if(item.value=='Distance from Home')
	{
		closediv('region');
		closediv('state');
		closediv('metro');
		opendiv('distance');
	}
}
function addUS(item)
{
	var nacountry=eval("document." +item.form.name+ "." + "nacountry");
	var nacountrylist=eval("document." +item.form.name+ "." + "nacountrylist");
	selectSingleItem(nacountrylist,"USA");
	move(nacountrylist,nacountry);
	select_all(nacountry);
	
}
function ClearLocationSearch()
{
	//alert('clearing location search');
	var nacountry=document.profile.nacountry;
	select_all(nacountry);
	var USSelected=false;
	for (var i=0; i< nacountry.length; i++) 
	{	
		if(nacountry[i].value=="USA") USSelected=true;
	}
	select_none(nacountry);
	if(!USSelected)
	{		
			if(document.profile.location_search_option.type=='hidden')
			{
				document.profile.location_search_option.value='';
			}
			else
			{
				document.profile.location_search_option[0].checked=false;
				document.profile.location_search_option[1].checked=false;
				document.profile.location_search_option[2].checked=false;
			}
			
			closediv('region');
			closediv('metro');
			closediv('distance');
			return;
	}
}
function selectSingleItem(select,value) 
{
  for (var i = 0; i < select.options.length; i++) {
    if(select.options[i].value==value)
    {
		select.options[i].selected = true;
		return;
    }
  }
}
function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

function SwapNoPref(item)
{	
	//if(item.checked==false) return;
	//alert(item.value);
	//alert(item.name);
	//alert(item.form.name);
	var noPrefChecked=false;
	var othersChecked=false;
	var element=eval("document." +item.form.name+ "." + item.name);
	
	if(item.checked&&item.value=="")
	{
		noPrefChecked=true;
	}
	if(item.checked&&item.value!="")
	{
		othersChecked=true;
	}
	
	if(noPrefChecked)
	{
		for (j=0; j < element.length; j++)
		{
			if(element[j].value!="")
			{
				element[j].checked=false;	
			}
		}
	}
	if(othersChecked)
	{
		for (j=0; j < element.length; j++)
		{
			if(element[j].value=="")
			{
				element[j].checked=false;	
			}
		}
	}
	var totalchecked=0;
	for (j=0; j < element.length; j++)
	{
		if(element[j].checked)
		{
			totalchecked++;	
		}
	}
	if(totalchecked<1)
	{
		for (j=0; j < element.length; j++)
		{
			if(element[j].value=="")
			{
				element[j].checked=true;	
			}
		}
	}
}
function field(item)
{
	return eval("document." +item.form.name+ "." + item.name);
}
function SelectBoxes()
{
	//alert('selecting boxes');
	select_none(document.profile.countrylist);
	select_none(document.profile.metrolist);
	select_all(document.profile.nacountry);
	select_all(document.profile.country);
	select_all(document.profile.metroareas);
	select_all(document.profile.regions);
	select_all(document.profile.states);
	select_none(document.profile.majorsselect);
	select_none(document.profile.submajorselect);
	select_all(document.profile.majors);
	select_none(document.profile.mensSports);
	select_none(document.profile.womensSports);
	select_all(document.profile.sports);
}
function UnselectBoxes()
{
	select_none(document.profile.countrylist);
	select_none(document.profile.metrolist);
	select_none(document.profile.nacountry);
	select_none(document.profile.country);
	select_none(document.profile.metroareas);
	select_none(document.profile.regions);
	select_none(document.profile.states);
	select_none(document.profile.statelist);
	select_none(document.profile.majorsselect);
	//select_none(document.profile.submajorselect);
	select_none(document.profile.majors);
	//select_none(document.profile.mensSports);
	//select_none(document.profile.womensSports);
	select_none(document.profile.sports);
}
function QuickSearch(url,sponsor)
{
	//opendiv('basics_expand');
	//opendiv('acad_expand');
	//opendiv('sb_expand');
	//opendiv('campus_expand');
	//opendiv('getin_expand');
	
	var urltest;
	
	urltest=url;
	if (url == "Y") 
	{
		url = "";
	}
	SelectBoxes();
	
	if(url!="")
	{
		submitThis(url,sponsor);
	}
	else
	{		
		var str1;
		var pos;
		str1 = document.location.href;
		pos = str1.indexOf("MyProfile.asp");
		if (pos >= 0) 
		{
			if (urltest == "Y") 
			{
				document.profile.action=document.location.href;
			}
			else
			{
				document.profile.action="srchRslt.asp?sponsor=1&searchtype=multicrit&sortcolumn=iname&sortorder="
			}
		}
		else
		{
			document.profile.action=document.location.href;
		}
		document.profile.submit();
	}
	
}
function submitThis(url,sponsor)
{	//alert(PageIsLoaded);
	//alert(url);
	//alert(sponsor);
	if(PageIsLoaded==false)
	{
		alert('Please let the page load'); 
		return;
	}
	if(url=="")url=document.location.href;
	//alert(url);
	SelectBoxes();
	if(document.profile.majors)
	{
		if(document.profile.majors.length==0)
		{
			document.profile.majorsearchtype[0].checked=false;
			document.profile.majorsearchtype[1].checked=false;
		}
		else
		{
			if(document.profile.majorsearchtype[0].checked==false && document.profile.majorsearchtype[1].checked==false)
			{
				document.profile.majorsearchtype[0].checked=true;
			}
		}
	}
	//var sortorder=SortOrder(url,sponsor);
	var sortorder="&searchtype=multicrit&multicrit=y&sortcolumn=CLIENT_CHECK,ISORT&sortorder="
	document.profile.action=url+sortorder;
	document.profile.submit();
}
function moveSports(fbox,tbox,mode)
{
	if(tbox.name=="sports")
	{
		if(sportsExceeded())
		{
			alert('Please limit your choice to 20 sports or less');
			return;
		}
		else
		{
			move(document.profile.mensSports,document.profile.sports,mode);
			move(document.profile.womensSports,document.profile.sports,mode);
		}
	}
	else
	{
		move(document.profile.sports,document.profile.mensSports,mode);
		move(document.profile.sports,document.profile.womensSports,mode);
	}
	
}
function moveMajors(fbox,tbox,mode)
{
	if(tbox.name=="majors")
	{
		if(majorsExceeded(mode))
		{
			alert('Please limit your choice to 20 majors or less');
			return;
		}
	}
	move(fbox,tbox,mode);
}
function majorsExceeded(mode)
{
	var tcnt = 0;
	select_all(document.profile.majors);
	for (var i = 0; i < document.profile.majors.length; i++)
	{
	    if (document.profile.majors[i].selected) tcnt++;
	}
	select_none(document.profile.majors);
	//alert(tcnt);
	
	var fcnt = 0;
	for (var i = 0; i < document.profile.submajorselect.length; i++)
	{
	    if (document.profile.submajorselect[i].selected) fcnt++;
	}
	if (mode=='all'){fcnt=document.profile.submajorselect.length}
	if(tcnt+fcnt>MajorsLimit)
	{
		return true;
	}
	else
	{
		return false;
	}
	
}
function sportsExceeded()
{
	var tcnt = 0;
	select_all(document.profile.sports);
	for (var i = 0; i < document.profile.sports.length; i++)
	{
	    if (document.profile.sports[i].selected) tcnt++;
	}
	select_none(document.profile.sports);
	//alert(tcnt);
	
	var fcnt = 0;
	for (var i = 0; i < document.profile.mensSports.length; i++)
	{
	    if (document.profile.mensSports[i].selected) fcnt++;
	}
	for (var i = 0; i < document.profile.womensSports.length; i++)
	{
	    if (document.profile.womensSports[i].selected) fcnt++;
	}
	//alert(fcnt);
	if(tcnt+fcnt>SportsLimit)
	{
		return true;
	}
	else
	{
		return false;
	}
	
}
function limitTotal(fbox,tbox,limit)
{
	var tcnt = 0;
	select_all(tbox);
	for (var i = 0; i < tbox.length; i++)
	{
	    if (tbox[i].selected) tcnt++;
	}
	//alert(tcnt);
	select_none(tbox);
	var fcnt = 0;
	for (var i = 0; i < fbox.length; i++)
	{
	    if (fbox[i].selected) fcnt++;
	}
	//alert(fcnt);
}
function SearchKeypressHandler(DnEvents,url,sponsor)
{	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) submitThis(url+'?sponsor='+sponsor);
}
function lockstate()
{	//alert('locking'+CUSTOM_SEARCH_STATE);
	if (CUSTOM_SEARCH_STATE=='')return;
	for (var i = 0; i < document.profile.statelist.length; i++) 
	{
		if(document.profile.statelist.options[i].value==CUSTOM_SEARCH_STATE)
		{
			document.profile.statelist.options[i].selected = true;
		}
	}
	move(document.profile.statelist,document.profile.states);
}
function blurstate()
{	//alert('bluring'+CUSTOM_SEARCH_STATE);
	if (CUSTOM_SEARCH_STATE=='')return;
	for (var i = 0; i < document.profile.states.length; i++) 
	{	
		if(document.profile.states.options[i].selected)
		{
			if(document.profile.states.options[i].value==CUSTOM_SEARCH_STATE)
			{
				document.profile.states.options[i].selected = false;
			}
		}
	}
}