String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
function checkMajorsform(limit)
{	

	var check_flag = true;
	var a = 'Please choose at least one MBA program';
	var b = 'Please choose at least one GMAT Score range';
	var c = 'Please choose Country or State location';
	var d = 'No results found. Please change your search criteria and search again.';
	
	//alert ('you are in ' + document.majorsForm2.concs.name + '\n the length is ' + document.majorsForm2.concs.length );


 var cnt = 0;

    for (var i = 0; i < document.majorsForm2.concs.length; i++)
    {
        if (document.majorsForm2.concs[i].selected) cnt++;
    }

 if ( document.majorsForm2.concs.selectedIndex < 0 && check_flag)	
 	{	
 		alert(a);
 		document.majorsForm2.concs.focus();
 		check_flag = false;
 	}
 if ( cnt > limit && check_flag)	
 	{	
 		alert('Please limit your selection to '+ limit +' concentrations or less.\nYou currently have chosen ' + cnt + ' concentrations.');
 		check_flag = false;
 	} 
 	
 if (!check_flag)
    {
        document.majorsForm2.concs.focus();
    } 	
 if ( document.majorsForm2.scores.selectedIndex < 0 && check_flag)	
    {
       alert(b); 
       document.majorsForm2.scores.focus();
       check_flag = false;
    }
 if ( document.majorsForm2.location.selectedIndex < 0 && check_flag)	
    {
       alert(c); 
       document.majorsForm2.location.focus();
       check_flag = false;
    } 
    if (document.getElementById('location')[0].value == "ZeroLO" && check_flag)
    {
       alert(d); 
       document.majorsForm2.concs.focus();
       check_flag = false;
    }    
 if (check_flag)
	{		
	document.majorsForm2.action = "AcdSearchResults.asp";
	document.majorsForm2.submit();				
	}	
}

function checkform2()
{	
	var check_flag = true;
	var a = 'Please enter a keyword or phrase';
 
if ( document.FTSsearch.anyQuery.value.trim() == "" && check_flag)	
 	{	
 		alert(a);
 		document.FTSsearch.anyQuery.focus();
 		check_flag = false;
 	}
 
if (check_flag)
	{		
	document.FTSsearch.action = "/fts/code/smplrslt.asp";
	document.FTSsearch.submit();				
	}	

}

function checkform3()
{	
	var check_flag = true;
	var a = 'Please enter all or part of an institution' + "'" + 's name';
 
if ( document.InstSearchResults.instName.value.trim() == "" && check_flag)	
 	{	
 		alert(a);
 		document.InstSearchResults.instName.focus();
 		check_flag = false;
 	}
 
if (check_flag)
	{		
	document.InstSearchResults.action = "InstSearchResults.asp";
	document.InstSearchResults.submit();				
	}	

}
function keypressHandler1(DnEvents,sponsor)
{	K = navigator.appName=="Netscape" ? DnEvents.which : DnEvents.keyCode
	if (K==13) checkform1(sponsor)
}

var is_restore=false;
//--restore the seletions
function restoreState(sponsor){
	if  (document.getElementById('locsel').value != ''){
        is_restore=true;
		EventScores(sponsor); 
	}
}

function EventConcs(sponsor){ 
    return EventScores(sponsor);  
}
function EventScores(sponsor){ 
 
  // ajax functionality added below 
  var mba_Ajax=new PcomAjax();
    
  var concs = GetSelectedOptionsList('concs'); //selected Major List
  var scores = GetSelectedOptionsList('scores'); //selected Score List
  
  if ((concs.trim()!='') && (scores.trim()!='')){
     mba_Ajax.load('AjaxLocation.asp?sponsor='+sponsor+'&reqtype=getlocations&scores=' + scores.substring(0,(scores.length-1)) + '&major=' + concs.substring(0,(concs.length-1)),LoadLocations);
  }else{ClearList('location','Select Major and Scores');}
}


function LoadLocations(xmldoc){
	locationList = document.getElementById('location');
	ClearList('location');
	
	dNodes = xmldoc.getElementsByTagName('Location');
	for(var j=0; j<dNodes.length; j++) {
		var dId = dNodes[j].attributes[0].value;
		var dVal = dNodes[j].childNodes[0].nodeValue;
		locationList.options[j] = new Option(dVal, dId);
	}
	if (is_restore) {
	    SelectList('location',document.getElementById('locsel').value);
	    is_restore=false;
	}
}
