



var insecureHost = "http://www.studentuniverse.com";
var secureHost = "https://www.studentuniverse.com";
var imageHost = "http://images.studentuniverse.com";
var sessionTimeoutPeriod = 15 * 60000;
var sessionWarningPeriod = 1 * 60000;
var abandonOrderPeriod = 15 * 60000-180000;
var itinID = 0;
var oidNumber = "00D3000000013nM";
var lookupDelay = 100;
var verifyOnlyUpdateTime = 20000;
var verificationPendingTextStayTime = 8000;
var autocheckVerifiedStatus;
if ( window.location.href.indexOf("http://www.studentuniverse.com/study.html") == 0 ) {
    window.location.replace("http://www.studentuniverse.com");
}

var xMousePos = 200;
var yMousePos = 300;

function insertLink() {
	var modifySearchBoxDiv = get("modifySearch");
	if ( get("outputArea") ) {
		var newDiv = document.createElement('div');
		newDiv.id = "searchFeedbackLink";
		newDiv.innerHTML = '<A HREF="#"ONCLICK="showSearchFeedbackPopup();return false">Like our new look?</A>';
		modifySearchBoxDiv.parentNode.insertBefore(newDiv,modifySearchBoxDiv);
	}
}
function submitSearchResultsFeedback(feedbackForm) {
	if (feedbackForm.comments.value == '') {
		alert('Please enter your comments.');
		feedbackForm.comments.focus();
	}
	else {
	    if ( feedbackForm.name.value == '' ) {
	    	feedbackForm.name.value = "Anonymous";
		}
		if ( feedbackForm.email.value.indexOf('@') < 0 ) {
	    	feedbackForm.email.value = "anon@anon.com";
		}
		var techInfoStr = "";
		for( key in navigator ) {
			techInfoStr += key + ": " + eval("navigator." + key) + "\n";
		}
		techInfoStr += "Date: " + Date() + "\n";
		feedbackForm.techinfo.value = techInfoStr;
		feedbackForm.connection.value = "Like our new look?";
		feedbackForm.submit();
		setTimeout("closePopup()",400);
	}
}
function showSearchFeedbackPopup() {
	get("popupTitle").innerHTML = "Like our new look?";
	openPopup(get("searchFeedbackPopupSrc").innerHTML);
	return false;
}

function openNewWindow(anchorObj,width,height) {
	window.open(anchorObj.href,'popup','width=' + width + ',height=' + height + 
',toolbar=yes,location=yes,directories=yes,status=yes,titlebars=yes,menubar=yes,resizable=yes,copyhistory=yes,scrollbars=yes');
	return false;
}

function preventDefault(event) {
	if ( isIE() && window.location.href.indexOf("/common/admin/content/") < 0 ) {
		event.cancelBubble=true;  // prevent the default submit command
		event.returnValue=false;  // prevent the default submit command
	}
	else {
		event.preventDefault();  // prevent the default submit command
	}
}

function defined(obj) {
	if ( typeof( obj ) == "undefined" ) return false;
	if ( obj == null ) return false;
	else return true;
}

function centerDivOnScreen(div) {
	topPosition=(getBrowserHeight() / 2 ) - div.offsetHeight+getScrollTop();
	leftPosition=375;
	div.style.left=leftPosition+"px";
	div.style.top=topPosition+"px";
}

function getBrowserWidth() {
	if (document.all) return document.documentElement.clientWidth;
    else if (document.getElementById) return window.innerWidth;
}

function getBrowserHeight() {
	if (document.all) return document.documentElement.clientHeight;
    else if (document.getElementById) return window.innerHeight;
}

function getScrollLeft() {
	if (document.all) return document.documentElement.scrollLeft;
    else if (document.getElementById) return window.pageXOffset;
}

function getScrollTop() {
	if (document.all) return document.documentElement.scrollTop;
    else if (document.getElementById) return window.pageYOffset;
}

function changeClass(element, newClass) {
	element.className=newClass;
	layoutPage(); // must account for page shifting
}

function applyClass(element,className) {
	if ( element && element.className && !matchesClass(element,className) ) {
		element.className += " "+className;
	}
	else {
		element.className=className;
	}
	return element;
}

function replaceClass(element,className,newClassName) {
	if ( matchesClass(element,className) ) {
		element.className=element.className.replace(className,newClassName);
	}
}

function removeClass(element,className) {
	if ( matchesClass(element,className) ) {
		element.className += " "+className;
		element.className=element.className.replace(className+" ","");
		element.className=element.className.replace(" "+className,"");
		element.className=element.className.replace(className,"");
	}
}

function matchesClass(element,className) {
	if ( element.className == className ) return true;
	else if ( element.className.indexOf(className+" ") >= 0 ) return true;
	else if ( element.className.indexOf(" "+className) >= 0 ) return true;
	else if ( element.className.indexOf(className+"-") >= 0 ) return true;
	else return false;
}

function switchToRoundTrip() {
	//if ( window.location.href.indexOf("dcn=") >= 0 ) onFlySearch(2); // if showing hot deal refresh page (and get rid of hot deal messages)
	if ( false ) onFlySearch(2); // if showing hot deal refresh page (and get rid of hot deal messages)
	else {
		if ( defined( get("modifySearch") ) ) {
			get("modifySearch").className="roundTrip";
			get("modifySearch").style.height="177px";
		}
		get("searchBox").className="roundTrip";
		SearchForm.setTripType(2);
		try {
			if(get('nav-rt')){get('nav-rt').className="selected"};
			if(get('nav-ow')){get('nav-ow').className=""};
			if(get('nav-oj')){get('nav-oj').className=""};
		} catch(e) {}
	}
	if (get("outboundFlexibility") != null){
		get("outboundFlexibility").style.display = "block";
	}
	if (get("inboundFlexibility") != null){
		get("inboundFlexibility").style.display = "block";		
	}
	$("#outboundAirport").focus();
}

function switchToOneWay() {
	//if ( window.location.href.indexOf("dcn=") >= 0 ) onFlySearch(1); // if showing hot deal refresh page (and get rid of hot deal messages)
	if ( false ) onFlySearch(1); // if showing hot deal refresh page (and get rid of hot deal messages)
	else {
		if ( defined( get("modifySearch") ) ) {
			get("modifySearch").className="oneWay";
			get("modifySearch").style.height="145px";
		}
		get("searchBox").className="oneWay";
		SearchForm.setTripType(1);
		try {
			if(get('nav-ow')){get('nav-ow').className="selected"};
			if(get('nav-rt')){get('nav-rt').className=""};
			if(get('nav-oj')){get('nav-oj').className=""};
		} catch(e) {}
	}
	if (get("outboundFlexibility") != null){
		get("outboundFlexibility").style.display = "block";
	}
	if (get("inboundFlexibility") != null){
		get("inboundFlexibility").style.display = "none";
	}
	$("#outboundAirport").focus();
}

function switchToOpenJaw() {
	//if ( window.location.href.indexOf("dcn=") >= 0 ) onFlySearch(3); // if showing hot deal refresh page (and get rid of hot deal messages)
	if ( false ) onFlySearch(3); // if showing hot deal refresh page (and get rid of hot deal messages)
	else {
		if ( defined( get("modifySearch") ) ) {
			get("modifySearch").className="openJaw";
			get("modifySearch").style.height="287px";
		}
		get("searchBox").className="openJaw";
		SearchForm.setTripType(3);
		SearchForm.setOutboundAirport(SearchForm.getOutboundAirport());
		try {
			get('nav-oj').className="selected";
			get('nav-rt').className="";
			get('nav-ow').className="";
		} catch(e) {}
	}
	if (get("outboundFlexibility") != null){
		get("outboundFlexibility").style.display = "none";
	}
	if (get("inboundFlexibility") != null){
		get("inboundFlexibility").style.display = "none";
	}
	
	$("#outboundAirport").focus();
}

function selectThisAP(field,apCode,apDesc) {
	SearchForm.setByFieldId(field,apCode,true,apDesc);
	hideAirportResults();
	$.facebox.close();
}

// ***************************** AJAX ***************************** //

function getAjaxURL(functionName,formObj) {
	var path="/nospring/ajax/"+functionName;
	if ( formObj ) path += "?"+getParams(formObj);
	return path;
}

function submitAjax(functionName,returnFunction,method,formObj,waitMsg) {
	var url="/nospring/ajax/"+functionName;
	if ( formObj ) url += "?"+getParams(formObj);
	xmlBasicRequest(url,returnFunction,method,waitMsg);
}

function submitAjaxFromQuery(functionName,returnFunction,method,query,waitMsg) {
	var url="/nospring/ajax/"+functionName+"?"+query;
	xmlBasicRequest(url,returnFunction,method,waitMsg);
}


//handle multiple AJAX call at the same time -- default disallowed
var allow2ndAjaxCall = false;
var ajaxCalling = false;

function xmlBasicRequest(url,func,method,waitMsg) {

	var http;
	
	if (ajaxCalling && !allow2ndAjaxCall && url.indexOf("setSearch") == -1){	
		return;
	}

	url = getURI(url); // make this a relative url to keep the scheme consistent with the page
	
	if ( waitMsg != null ) showWaitMsg(waitMsg);
	
	if (window.XMLHttpRequest) {
		http = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try { 
			http = new ActiveXObject("Msxml2.XMLHTTP");
		}
    	catch(e) {
			http = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	if (!http) return false;

	now=new Date();
	if ( url.indexOf('?') < 0 ) {
		url += "?timestamp="+now.getTime();	// IE caches XMLHttpRequests, so put unique string on url to prevent
	}
	else  {
		url += "&timestamp="+now.getTime();	// IE caches XMLHttpRequests, so put unique string on url to prevent
	}
	
	ajaxCalling = true;
	if ( method != null && method.toUpperCase() == "GET" ) {
		url=getFullPathCurrentScheme(url);
		http.open("GET", url, true);
		http.send(null);
	}
	else {
		postURL=url.substring(0,url.indexOf("?"));
		params=url.substring(url.indexOf("?")+1);
		postURL=getFullPathCurrentScheme(postURL);
		http.open('POST', postURL, true); 
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    	http.setRequestHeader("Content-length", params.length); 
    	http.setRequestHeader("Connection", "close"); 
    	http.send(params); 
	}
	
	if (func) {
		http.onreadystatechange=function() {
			if (http.readyState != 4) return;
			if (waitMsg) hideWaitMsg();
			func( returnXMLOrText(http) );
			ajaxCalling = false;
			allow2ndAjaxCall = false;
		};
	}
	else {
		http.onreadystatechange=function() { 
			if (waitMsg) hideWaitMsg();
			return returnXMLOrText(http);
			ajaxCalling = false;
			allow2ndAjaxCall = false;
		};
	}
	
}

function returnXMLOrText(responseObj) {
	if (responseObj.responseText.indexOf('<?xml') == 0) return responseObj.responseXML;
	else return responseObj.responseText;
}

function loadSessionData(thisData) {
	if ( !thisData ) {
		url="/nospring/loadData?action=sessionData&token="+new Date().getTime();
		xmlBasicRequest(url,loadSessionData);
	}
	else {
		sessionData=new Array();
		sessionBits=thisData.split('\n');
		for ( var i=0 ; i < sessionBits.length ; i++ ) {
			name=sessionBits[i].split('=')[0];
			value=sessionBits[i].split('=')[1];
			sessionData[name]=value;
		}
	}
}

sessionData=null;

function getSessionData(attrName) {
	if (sessionData == null ) {
		loadSessionData();
		setTimeout('getSessionData(attrName)',1000);
	}
	else {
		return sessionData[attrName];
	}
}

function loadPage(url) {
	xmlBasicRequest(url,showPage);
}

function showPage(pageSource) {
	document.body.innerHTML=pageSource;
	layoutPage();
	window.location.hash="/test/";
}

var showWaitStartTime;
var hideWaitMsgTimeout;
var minShowWaitTime=500;

function showWaitMsg(msg) {
	clearTimeout(hideWaitMsgTimeout);
	showWaitStartTime=new Date();
	var pleaseWaitPrompt=createElement("div","pleaseWaitPrompt");
	if ( !msg ) msg="Please wait.";
	pleaseWaitPrompt.innerHTML="<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+msg+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	pleaseWaitPrompt.style.visibility="visible";
	centerDivOnScreen(pleaseWaitPrompt);
}

function createElement(type,id,className,parentObj) {
	var element=get(id);
	if ( !element ) {
		if ( !parentObj ) parentObj=document.body;
		var element=document.createElement(type);
		element.id=id;
		document.body.appendChild(element);
	}
	element.className=className;
	return element;
}

function showMovingAltTag(parentObj,msg,posX,minX,maxX) {
	var altTag=createElement("div","movingAltTag");
	altTag.style.top=getTopPos(parentObj)+30+"px";
	if ( posX < minX ) posX=minX;
	else if ( posX > maxX ) posX=maxX;
	altTag.style.left=posX+"px";
	altTag.style.display="block";
	altTag.innerHTML=msg;	
}

var showingAirportCodeDesc;
var movingAltTagParent;

function showAPAltTag(element,description) {
	movingAltTagParent = element;
	description = description.replace("'","\\\'");
	showingAirportCodeDesc = setTimeout("showMovingAltTag(movingAltTagParent,'" + description + "'," + getLeftPos(element) + ",0,10000)",750);
}

function showOrbitzMouseover(element) {
	movingAltTagParent = element;
	showingAirportCodeDesc = setTimeout("showMovingAltTag(movingAltTagParent,'The lowest student fares sell out<br/> quickly, so we\\\'ve partnered with<br/> Orbitz to make sure you get the<br/> best deal (even if it\\\'s not from us)'," + getLeftPos(element) + ",0,790)",750);
}

function hideAirportResults() {
	
	try { 
		
		if (get("airportLookupResults") != null){
	
			get("airportLookupResults").style.display="none"; 
		}
		
	} catch(e) { }
}

function hideWaitMsg(timeoutPeriod) {
	if ( !defined(timeoutPeriod) ) timeoutPeriod=0;
	if ( timeoutPeriod < minShowWaitTime ) {
		var now=new Date();
		var minTimeLeftToShow=minShowWaitTime - (now.getTime() - showWaitStartTime.getTime());
		timeoutPeriod=Math.max(timeoutPeriod,minTimeLeftToShow);
	}
	hideWaitMsgTimeout=setTimeout("get(\"pleaseWaitPrompt\").style.visibility=\"hidden\"",timeoutPeriod);
}

// ***************************** misc  ***************************** //

function closePopup() {
	if (get("popupContainer")) get("popupContainer").parentNode.removeChild(get("popupContainer"));
	else {
		try {
			if ( window.opener && window.opener.location.href.indexOf("studentuniverse.com") >= 0 )  {
				window.close()
			}
		}
		catch(e) {};
	}
}


function openPopup(thisTxt,xMousePos,yMousePos) {

	closePopup();
	var border=2;
	var padding=15;
	var windowMargin=10;
	var minWidth=350;
	var minHeight=300;
	var maxWidth=640;
	var maxHeight=480;
	
	var width=600;
	var height=350;
	if ( blurbWidth > 0 && blurbHeight > 0 ) {
		width=blurbWidth;
		height=blurbHeight;
	}

	adjWidth=width+windowMargin+border * 2;
	adjHeight=height+windowMargin+border * 2;
	
	posx=xMousePos;
	posy=yMousePos;
	
	
	
	if ( (posx+adjWidth) > (document.documentElement.scrollLeft+document.documentElement.clientWidth) ) {
		posx=document.documentElement.scrollLeft+document.documentElement.clientWidth - adjWidth;
	}

	if ( (posy+adjHeight) > (document.documentElement.scrollTop+document.documentElement.clientHeight) ) {
		posy=document.documentElement.scrollTop+document.documentElement.clientHeight - adjHeight;
	}
	
	if(posy < 0){//Fix the popup window is way too high in the small window. Bug 3765
		posy = 0;
	}
	// hack to fix issue in Safari on home page, where popup appears off the page
	if ( document.body.id == "home" && isSafari() ) {
		posx=xMousePos - 590;
		posy=yMousePos - 250;
	}
	// hack to fix issue in Safari
	else if ( document.body.id == "searchResultsPage" && isSafari() ) {
		posx=xMousePos - 590;
		posy=yMousePos - 250;
		if(posx<0){
			posx = 250;
		}
		if(posy<0){
			posy = 250;
		}
	}	
	
	
	// hack to fix issue in homePage airportCodeLink pop page	
	if (xMousePos<350 && yMousePos<300 && isSafari()){
 		posx= 150;
 		posy= 150;
 	}
	

	popup=document.createElement('div');
	popup.id="popup";
	popup.className="popup";
	popup.style.width=width - (padding*2)+"px";
	popup.style.height=height - (padding*2)+"px";
	popup.style.padding=padding+"px";
	popup.innerHTML=thisTxt;
	//popup.onmousedown=function() { this.offsetParent.onmousedown=null };
	//popup.onmouseup=function() { this.offsetParent.onmousedown=function() { dragStart(arguments[0],get("popupContainer") ) } };
	
	popupContainer=document.createElement('div');
	popupContainer.id="popupContainer";
	popupContainer.style.width=width+"px";
	popupContainer.style.height=height+"px";
	popupContainer.style.left=posx+"px";
	popupContainer.style.top=posy+"px";
	popupContainer.style.borderWidth= border+"px";
	popupContainer.style.zIndex= "20000";
	
	if ( isIE() ) {
		iframe=document.createElement('iframe');
		iframe.style.width=width+"px";
		iframe.style.height=height+"px";
		iframe.style.zIndex= "19999";
		iframe.src="/common/tools/blank.html"; // this url doesn't matter, just need to give it a src to avoid security warning on https
		popupContainer.appendChild(iframe);
	}

	//popupContainer.onmousedown=function() { 
	//	dragStart(arguments[0],get("popupContainer") );
	//};
	
	popupContainer.appendChild(popup);
	//document.body.appendChild(iframe);
	document.body.appendChild(popupContainer);
	officeHoursLoad(); 
	$("a.popupLink, img.popupLink, a.airportCodeLink, a#popupLink",popup).bind("click",registerPopupLinks);
    $("a.newWindowLink").click(function (e) {
		window.open(this.href);
		return false;
	});
	$("BUTTON#sendEmailButton").click(function () { sendSabreEmail(); });
	return popup;
}

// ***************************** validation ***************************** //

function validateName(name){
	var regexLetter =(/\d/g);//checks for numbers
	var result = regexLetter.test(name);
	return !result;
}
function monitorFormItems() {
	var formFields=getElementsByClassName(document, '*', 'validReq');
	for ( var i=0 ; i < formFields.length ; i++ ) {
		thisField=get(formFields[i].id);
		thisField.onchange=function() { validate(this); layoutPage(); };
	}
}

function validateForm(formObj) {
	var formFields=getElementsByClassName(formObj, '*', 'validReq');
	for ( var i=0 ; i < formFields.length ; i++ ) validate(formFields[i]);
	var errorFields=getElementsByClassName(formObj, 'div', 'errorTop');
	if ( errorFields.length == 0 ) formObj.submit();
	else {
		layoutPage(); // we're changing the page dimensions, so this keeps the footer and runarounds intact
		alert('There were errors.  Please correct as indicated above.');
	}
}

function validate(obj) {
	if (obj.id == 'firstname') validateString(obj,'Enter first name');
	else if (obj.id == 'middle') validateString(obj,'Enter middle name');
	else if (obj.id == 'lastname') validateString(obj,'Enter last name');
	else if (obj.id == 'email') validateEmail(obj);
	else if (obj.id == 'schoolEmail') validateEmail(obj);
	else if (obj.id == 'password') validatePassword(obj);
	else if (obj.id == 'cellPhone') validateCellPhone(obj);
}

function validateString(obj,msg) {
	obj.value=trim(obj.value);
	if (obj.value.length == 0) showErrorMsg(obj,msg);
	else removeErrorMsg(obj);
}

function validatePassword(obj) {
	obj.value=trim(obj.value);
	if (obj.value.length == 0) showErrorMsg(obj,'Enter a password, must be at least 6 characters');
	else if (obj.value.length < 6) showErrorMsg(obj,'Password must be at least 6 characters');
	else removeErrorMsg(obj);
}

function validateEmail(obj) {
	obj.value=trim(obj.value);
	if (obj.value.length == 0) showErrorMsg(obj,'Enter an email address');
	else if (!validEmail(obj.value)) showErrorMsg(obj,'Enter a valid email address');
	else removeErrorMsg(obj);
}

function validateSchoolEmail(obj) {
	obj.value=trim(obj.value);
	if (obj.value.length == 0) showErrorMsg(obj,'Enter an email address');
	else if (!validEmail(obj.value)) showErrorMsg(obj,'Enter a valid email address');
	else removeErrorMsg(obj);
}

function validateCellPhone(obj) {
	obj.value=trim(obj.value);
	if ( obj.value.length > 0 && !validPhoneNumber(obj.value) ) showErrorMsg(obj,'Enter a valid phone number');
	else removeErrorMsg(obj);
}

function validEmail(str) {
   return ( (str.indexOf("@") > 0) && str.indexOf(".") >= 1 );
}

function validPhoneNumber(PhoneNumber) {	
	var PNum=new String(PhoneNumber);	// 555-555-5555	or (555)555-5555 or (555) 555-5555 or 555.555.5555
	var regex=/^[1]*[0-9]{3,3}[ ]*[0-9]{3,3}[ ]*[0-9]{4,4}$|^[0-9]{3,3}\-[0-9]{3,3}\-[0-9]{4,4}$|^\([0-9]{3,3}\) [0-9]{3,3}\-[0-9]{4,4}$|^\([0-9]{3,3}\)[0-9]{3,3}\-[0-9]{4,4}$|^[0-9]{3,3}\.[0-9]{3,3}\.[0-9]{4,4}$/;
	return regex.test(PNum);
}

function showErrorMsg(obj,msg) {
	errorField=getErrorField(obj);
	errorField.innerHTML=msg;
	errorField.style.display='block';
}

function getErrorField(obj) {
	var errorField=get(obj.id+'-error');
	if ( !errorField ) {
		fieldRow=getParentForm(obj);
		errorField=document.createElement('div');
		errorField.className='errorTop';
		errorField.id=obj.id+'-error';
		alert(getParentFieldRow(obj));
		parentFieldRow=getParentFieldRow(obj);
		fieldRow.insertBefore(errorField,parentFieldRow);
	}
	return errorField;
}

function getParentForm(obj) {
	while ( obj.parentNode && obj.parentNode.id != 'vertForm' ) obj=obj.parentNode;
	if (obj.parentNode) return obj.parentNode;
	else if ( get('signUpForm') ) return get('signUpForm');
	else if ( get('billingShippingForm') ) return get('billingShippingForm');
}

function getParentFieldRow(obj) {
	while ( obj.parentNode && obj.parentNode.className != 'formField' ) {
		obj=obj.parentNode;
		alert(obj);
	}
	return obj.parentNode;
}

function removeErrorMsg(obj) {
	errorField=getErrorField(obj);
	errorField.parentNode.removeChild(errorField); 
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s=s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s=s.substring(0,s.length-1);
  }
  return s;
}

function flagError(element) {
	try {
		element.style.color="#cc0000";
		element.style.fontWeight="bold";
	}
	catch(e) { alert(e) }
	return element;
}

function unflagError(element) {
	try {
		element.style.color="";
		element.style.backgroundColor="";
		element.style.fontWeight="";
	}
	catch(e) { alert(e) }
	return element;
}

function showElement(element,suppressLayout) {
	if ( !element.style) element=get(element); // if not an object, get the object by id
	element.style.display="block";
	if ( !suppressLayout ) layoutPage(); // must account for page shifting
}

function hideElement(element,suppressLayout) {

	if ( !element.style) element=get(element); // if not an object, get the object by id
	element.style.display="none";
	if ( !suppressLayout ) layoutPage(); // must account for page shifting
}

var blurbWidth=0;
var blurbHeight=0;

function displayBlurb(url,width,height) {
	if ( width && height ) {
		blurbWidth=width;
		blurbHeight=height;
	}
	else {
		blurbWidth=0;
		blurbHeight=0;
	}
	xmlBasicRequest(url,openPopup);
}

// ***************************** ABSOLUTE POSITIONING STUFF ***************************** //

function getTopPos(div) {
	pos=div.offsetTop; //init
	while ( div.offsetParent ) {
		div=div.offsetParent;
		pos += div.offsetTop;
	}
	return pos;
}

function getBottomPos(div) {
	return div.offsetHeight+getTopPos(div);
}

function getLeftPos(div) {
	pos=div.offsetLeft; //init
	while ( div.offsetParent ) {
		div=div.offsetParent;
		pos += div.offsetLeft;
	}
	return pos;
}

function getRightPos(div) {
	return div.offsetWidth+getLeftPos(div);
}

function positionUnder(div,upperDiv) {
	if ( div && upperDiv ) {
		div.style.top=getBottomPos(upperDiv)+"px";
	}
	else alert('POSITIONING FAILED');
}

function drawRunarounds() {
	var divs=document.getElementsByTagName('div');
	for( var i=0 ; i < divs.length; i++ ) { 
		thisDiv=divs[i];
		if(/\brunaround\b/.test(thisDiv.className)) { 
			drawRunaround(thisDiv);
		}
	}
	setTimeout('showRunarounds()',0);
	//showRunarounds();
}

function drawRunaround(thisDiv) {
	 if ( thisDiv.getElementsByTagName('h2')[0] ) {
		createClassedDiv(thisDiv,'run-tl-hdr');
	 } else {
		createClassedDiv(thisDiv,'run-tl');
	 }
	 createClassedDiv(thisDiv,'run-tr');
	 createClassedDiv(thisDiv,'run-bl');
	 createClassedDiv(thisDiv,'run-br');
}

function createClassedDiv(thisObj,className) {
	existingDivs=getElementsByClassName(thisObj,'div',className);
	if ( existingDivs.length > 0 ) {
		newDiv=existingDivs[0];
	}
	else newDiv=document.createElement('div');
	newDiv.className=className;
	newDiv.innerHTML="&nbsp;";

	thisObj.appendChild(newDiv);
}

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements=(strTagName == "*" && document.all)? document.all : 
    oElm.getElementsByTagName(strTagName);
    var arrReturnElements=new Array();
    strClassName=strClassName.replace(/\-/g, "\\-");
    var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement=arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

function getElementByClassName(oElm, strTagName, strClassName){
   return getElementsByClassName(oElm, strTagName, strClassName)[0];
}

function showRunarounds() {
	var divs=document.getElementsByTagName('div');
	for( var i=0 ; i < divs.length; i++ ) { 
		thisDiv=divs[i];
		if(/\brunaround\b/.test(thisDiv.className)) { 
			thisDiv.style.visibility="visible";
			//if ( isIE() ) setCorners(thisDiv);
		}
	}
}

function isIE() {
	if ( navigator.userAgent.toLowerCase().indexOf("msie") >= 0 ) return true;
	else return false;
}

function isOldIE() {
	if ( navigator.userAgent.toLowerCase().indexOf("msie") >= 0 && navigator.userAgent.toLowerCase().indexOf("msie 6") > 0 ) return true;
	else return false;
}

function isSafari() {
	if ( navigator.userAgent.toLowerCase().indexOf("safari") >= 0 ) return true;
	else return false;
}

function isChrome() {
	if ( navigator.userAgent.toLowerCase().indexOf("chrome") >= 0 ) return true;
	else return false;
}
/*function getSliderClassName() {
	if ( isIE() ) return "slider";
	else return "sliderBG";
}*/

function setCorners(thisDiv) {
	if ( (thisDiv.offsetWidth % 2) == 1 ) {
		getElementByClassName(thisDiv,'div','run-tr').style.right="-3px";
		getElementByClassName(thisDiv,'div','run-br').style.right="-3px";
	}
	if ( (thisDiv.offsetHeight % 2) == 1 ) {
		getElementByClassName(thisDiv,'div','run-bl').style.bottom="-3px";
		getElementByClassName(thisDiv,'div','run-br').style.bottom="-3px";
	}
}

function growDivs(objToTraverse) {
	lowestBottom=getBottomPos(objToTraverse);
	var divs=objToTraverse.getElementsByTagName('div');
	for( var i=0 ; i < divs.length; i++ ) { 
		thisDiv=divs[i];
		lowestBottom=Math.max(lowestBottom,growDivs(thisDiv));
	}
	totalHeight=lowestBottom - getTopPos(objToTraverse);
	if ( objToTraverse.style ) {
		objToTraverse.style.height=totalHeight+"px";
	}
	return lowestBottom;
}

function childOf(thisObj,parentObj) {
	while ( thisObj.id != parentObj.id && thisObj.parentNode ) {
		thisObj=thisObj.parentNode;
	}
	return(thisObj.id==parentObj.id);
}

function layoutPage() {
	drawRunarounds();
}

// ***************************** general functions ***************************** //

function get(elementID) {
	return document.getElementById(elementID);
}

// ***************************** POPUPS.JS ***************************** //

// Popup window functions
// Author: Dale Wiggins
// standard popup window, with no window options
function popupWindow(path,width,height,argumentsStr) {
    popupWindowFull(path,'popmeup',width,height,0,0,argumentsStr);
}

// Popup window functions
// Author: Dale Wiggins
// standard popup window, with no window options
function popupNamedWindow(path,name,width,height,argumentsStr) {
    popupWindowFull(path,name,width,height,0,0,argumentsStr);
}

// full-featured popup window
function popupWindowFull(path,name,width,height,xOffset,yOffset,argumentsStr) {
if (window.thisPopWin && !window.thisPopWin.closed) // checks if window is already open.  if it is, closes it, so it can re-open at correct size
  thisPopWin.close(); 
argumentsStr += ''; // if arguments are undefined, converting to a string makes testing easier.
var options=new Array('toolbar','location','directories','status','titlebars','menubar','resizable','copyhistory','scrollbars');
if (argumentsStr == 'undefined')
  optionsString='toolbar=no,location=no,directories=no,status=no,titlebars=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,';
else
  {
  optionsString=''
  for ( var i=0 ; i < options.length ; i++ )
    {
    if (argumentsStr.indexOf(options[i]) != -1)
	  optionsString += options[i]+'=yes,'
    else
      optionsString += options[i]+'=no,'
    }
  }
  
centeredLeftPos=(screen.width / 2 - width / 2) / 2;  // these 2 lines center the popup on the user's screen
centeredTopPos=(screen.height / 2 - height / 2) / 2;

var xMousePos = 200;
var yMousePos = 200;

leftPos=xMousePos - width+3+xOffset; // get the cursor on the close button by default
topPos=yMousePos - 10+yOffset;

optionsString += 'width='+width+',height='+height+',left='+centeredLeftPos+',top='+centeredTopPos+',screenX='+leftPos+',screenY='+topPos;

thisPopWin=window.open(path,name,optionsString);
}

function infopop( source, sourceId ) {
	var sURL="/common/tools/hotDealsFareRules.jsp?source="+source+"&sourceId="+sourceId;
	popupWindow(sURL,425,430,'scrollbars');
}

function trackAndRedirectPageTitle(redirectURL,pageTitle,newWindow) {
	if (newWindow == 1) {
		window.open(redirectURL,'externalSite');
	}
	else {
		window.location=redirectURL;
	}
}

function skipToPage(thisURL) {
  windowToChange=parent.window;
  if (!parent.hiddenFrame) { // this isn't a child frame (shouldn't happen)
    windowToChange=window;
  }
  var version=parseInt(navigator.appVersion,10)
  // replace is supported
  if (version>=4 || window.location.replace)
    windowToChange.location.replace(thisURL);
  else
    windowToChange.location.href=thisURL;
}

function redirectFrom(referer_code) {
	pageURL='/?referer='+referer_code;
	setTimeout("skipToPage(pageURL)",6000);
}

// ***************************** AIRSEARCH.JS ***************************** //

function getSearchForm() {
	return get("farefinder");
}

function onFlySearch(tripType) {
	if ( getSearchForm() && window.location.href.indexOf("dcn=") < 0 ) {
		if ( tripType == 2 ) switchToRoundTrip();
		if ( tripType == 1 ) switchToOneWay();
		if ( tripType == 3 ) switchToOpenJaw();
	}
	else goToURL("/?tripType="+tripType);
}

/*function aironClick(eventType) {
	var returnFunction = function(returnMsg) { 
		openPopup(returnMsg,eventType.xMousePos,eventType.yMousePos);
		return false;
	}
	xmlBasicRequest(eventType.target.href,returnFunction,null,null);
}*/

/*function showTaxesAndFees(eventType) {
	var returnFunction = function(returnMsg) { 
		openPopup(returnMsg,eventType.xMousePos,eventType.yMousePos);
		return false;
	}
	if ( cartTax ) url="/popups/taxesAndFeesCart.jsp?airItemID="+uuid;
	else url="/popups/taxesAndFees.jsp?itinUUID="+uuid;
	xmlBasicRequest(url,returnFunction,null,null);
}*/

function showTaxesAndFees(uuid,cartTax) {
	if ( cartTax ) url="/popups/taxesAndFeesCart.jsp?airItemID="+uuid;
	else url="/popups/taxesAndFees.jsp?itinUUID="+uuid;
	openPopup(url,400,400);
}

/*function showTaxesAndFees(eventType) {
	var returnFunction = function(returnMsg) { 
		openPopup(returnMsg,eventType.xMousePos,eventType.yMousePos);
		return false;
	}
	if ( cartTax ) url="/popups/taxesAndFeesCart.jsp?airItemID="+uuid;
	else url="/popups/taxesAndFees.jsp?itinUUID="+uuid;
	xmlBasicRequest(url,returnFunction,null,null);
}*/

function outboundChoice_onchange( input_data ) {
	getSearchForm().outboundAirport.value=input_data;
	inboundJawChoice_onchange(input_data);
}

function inboundChoice_onchange( input_data ) {
	getSearchForm().inboundAirport.value=input_data;
}

function outboundJawChoice_onchange( input_data ) {
	getSearchForm().outboundJawAirport.value=input_data;
}

function inboundJawChoice_onchange( input_data ) {
	getSearchForm().inboundJawAirport.value=input_data;
}

function prePopCodes(advSearchFlag) { // replaces blank airport code boxes with default description (i.e. "City name or code")
	if (getSearchForm().outboundAirport.value == '') {
        getSearchForm().outboundAirport.value=defaultCodeText;
    }
    
    if (getSearchForm().inboundAirport.value == '') {
        getSearchForm().inboundAirport.value=defaultCodeText;
    }
	
	if (advSearchFlag) {
        if (getSearchForm().outboundJawAirport.value == '') {
            getSearchForm().outboundJawAirport.value=defaultCodeText;
        }
        
        if (getSearchForm().outboundAirport.value != defaultCodeText) {
		    getSearchForm().inboundJawAirport.value=getSearchForm().outboundAirport.value;
		}
		else if (getSearchForm().inboundJawAirport.value == '') {
            getSearchForm().inboundJawAirport.value=defaultCodeText;
        }
	}
}

function searchOrLogin(){
	if (window.event) { // if supported
		theKey=window.event.keyCode;
		if(theKey==13 && enterButtonEnabled){
		    window.event.cancelBubble=true;  // for disabling BEEP when hitting enter button to submit
    	    window.event.returnValue=false;  // for disabling BEEP when hitting enter button to submit
			if (getSearchForm()) {
				getSearchForm().submit();
			}
			else if (document.login) {
				document.login.submit();
			}
		}
	}
}

function enableEnterButton() {
    enterButtonEnabled=true;
}

function disableEnterButton() {
    enterButtonEnabled=false;
}

// ***************************** PROFILE.JSP ***************************** //

function initFields() {
	months=new Array("----","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	monthValues=new Array("-1","0","1","2","3","4","5","6","7","8","9","10","11");
	monthSelectBox=get("dobMonth");
	//updateSelectBox(get("dobMonth"),months,monthValues,"-1");
	//updateSelectBox(get("gradMonth"),months,monthValues,"-1");
}

function getDaysInMonth(month,year) {
	if ( !year ) year=2004; // set to a leap year to allow 29 days in February ( if we don't know year )
	now=new Date();
	now.setMonth(parseInt(month)+1);
	now.setDate(1);
	now.setYear(year);
	now.setTime( now.getTime() - 1000*60*60*24 );
	//return now.getDate();
	return 31;
}

function loadDays(monthsObj) {
	numDaysInMonth=getDaysInMonth( getSelectBoxValue(monthsObj) );
	currentDayText=getSelectBoxText(get("dobDay"));
	currentDayValue=getSelectBoxValue(get("dobDay"));
	
	if ( currentDayValue > numDaysInMonth ) {
		currentDayText="----";
		currentDayValue="-1";
	}
	
	labels=new Array();
	values=new Array();
	labels.push(currentDayText);
	values.push(currentDayValue);
	for ( i=1 ; i <= numDaysInMonth ; i++ ) {
		labels.push(i);
		values.push(i);
	}
	updateSelectBox(get("dobDay"),labels,values,"-1");
}

function getSelectBoxText(selectObj) {
	return selectObj.options[selectObj.selectedIndex].text;
}

function getSelectBoxValue(selectObj) {
	return selectObj.options[selectObj.selectedIndex].value;
}

function getCheckedValue(radioObj) {
	if(!radioObj) return "";
	var radioLength=radioObj.length;
	if (radioLength == undefined )
		if( radioObj.checked )
			return radioObj.value;
		else			
			return "";
	for(var i=0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}


function loadCountries() {
	url="/nospring/loadData?action=countries";
	selectBoxPrompt("universityCountryID"," -- Please wait while country location data is loading -- ");
	selectBoxPrompt("universityLocationID"," -- Please choose a country above -- ");
	selectBoxPrompt("universityID"," -- Please choose a country above -- ");
	xmlBasicRequest(url,showCountries,"GET");
}

function loadStates(eventType) {
	//edit hu_wg for eventType.target==undefined
	var cntrySelectObj= eventType.target==undefined ?eventType :eventType.target;
	url = "";
	if ( cntrySelectObj.id == "universityCountryID" ) {
		url="/nospring/loadData?action=states&value="+getSelectObjValue(cntrySelectObj);
		
		selectBoxPrompt("universityLocationID"," -- Please wait while state location data is loading -- ");
		selectBoxPrompt("universityID"," -- Please select your school's state -- ");
		xmlBasicRequest(url,showUnivStates,"GET");
	}
	else if ( cntrySelectObj.id == "billcountry" ) {
		url="/nospring/loadData?action=statesByCountryName&value="+getSelectObjValue(cntrySelectObj);
		selectBoxPrompt("billstate"," -- Please wait while state location data is loading -- ");
		xmlBasicRequest(url,showStates,"GET");
	}
	else if ( cntrySelectObj.className == "shipCountryField" ) {
		url="/nospring/loadData?action=statesByCountryName&value="+cntrySelectObj.value;
		xmlBasicRequest(url,showShipStates,"GET");
	}
}

function loadStates_AC(obj) { 

	
	url = "";
	if ( obj == "universityCountryID" ) {
		url="/nospring/loadData?action=states&value="+get("universityCountryID").options[get("universityCountryID").selectedIndex].value;
		selectBoxPrompt("universityLocationID"," -- Please wait while state location data is loading -- ");
		selectBoxPrompt("universityIDSelect"," -- Please select your school's state -- ");
		xmlBasicRequest(url,showUnivStates_AC,"GET");
	}
	else if ( obj == "billcountry" ) {
		url="/nospring/loadData?action=statesByCountryName&value="+getSelectObjValue(cntrySelectObj);
		selectBoxPrompt("billstate"," -- Please wait while state location data is loading -- ");
		xmlBasicRequest(url,showStates,"GET");
	}
	else if ( obj == "shipCountryField" ) {
		url="/nospring/loadData?action=statesByCountryName&value="+cntrySelectObj.value;
		xmlBasicRequest(url,showShipStates,"GET");
	}
}
function showUnivStates_AC(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("universityLocationID");
	if ( names.length < 2 ) {
		allow2ndAjaxCall = true;
		updateSelectBox(childSelObj,names,values);
		loadUnivs_AC(childSelObj);
	}
	else {
		names.splice(0,0," --- Please select your school's state --- ");
		values.splice(0,0,"-1");
	}
	updateSelectBox(childSelObj,names,values);
	loadUnivs_AC(childSelObj);
}
function loadUnivs_AC(eventType) { 

	var stateSelectObj;
	if ( eventType.target ) { // if called directly from state choice change
		stateSelectObj=eventType.target;
	}
	else {
		stateSelectObj=eventType; // if called after country choice change ( and no states exist )
	}
	var stateID=getSelectObjValue(stateSelectObj);
	// if they selected the default (no state) choice, reset university field, and do not proceed
	if ( stateID < 0 ) selectBoxPrompt("universityIDSelect"," -- Please select your school's state -- ");
	else {
		url="/nospring/loadData?action=universities&value="+stateID;
		selectBoxPrompt("universityIDSelect"," -- Please wait while university location data is loading -- ");
		xmlBasicRequest(url,showUnivs_AC,"GET");
	}
}

function showUnivs_AC(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("universityIDSelect");
	names.splice(0,0," --- Please select your school --- ");
	values.splice(0,0,"-1");
	updateSelectBox(childSelObj,names,values);
}
function loadUnivs(eventType) {
	var stateSelectObj;
	if ( eventType.target ) { // if called directly from state choice change
		stateSelectObj=eventType.target;
	}
	else {
		stateSelectObj=eventType; // if called after country choice change ( and no states exist )
	}
	var stateID=getSelectObjValue(stateSelectObj);
	// if they selected the default (no state) choice, reset university field, and do not proceed
	if ( stateID < 0 ) selectBoxPrompt("universityID"," -- Please select your school's state -- ");
	else {
		url="/nospring/loadData?action=universities&value="+stateID;
		selectBoxPrompt("universityID"," -- Please wait while university location data is loading -- ");
		xmlBasicRequest(url,showUnivs,"GET");
	}
}

function showCountries(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	updateSelectBox(document.getElementById("universityCountryID"),names,values,myCountryID);
	loadStates(document.getElementById("universityCountryID"));
}

function showUnivStates(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("universityLocationID");
	if ( names.length < 2 ) {
		allow2ndAjaxCall = true;
		updateSelectBox(childSelObj,names,values);
		loadUnivs(childSelObj);
	}
	else {
		names.splice(0,0," --- Please select your school's state --- ");
		values.splice(0,0,"-1");
	}
	updateSelectBox(childSelObj,names,values);
	loadUnivs(childSelObj);
}

function showStates(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("billstate");
	if ( names.length < 2 ) {
		updateSelectBox(childSelObj,names,values);
	}
	else {
		names.splice(0,0," --- Select Your State --- ");
		values.splice(0,0,"-1");
	}
	updateSelectBox(childSelObj,names,values);
}

function showShipStates(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("shipstate");
	if ( names.length < 2 ) {
		updateSelectBox(childSelObj,names,values);
	}
	else {
		names.splice(0,0," --- Please select your state --- ");
		values.splice(0,0,"-1");
	}
	updateSelectBox(childSelObj,names,values);
}

function showUnivs(thisData) {
	var names=eval('new Array('+thisData.split('\n')[0]+')');
	var values=eval('new Array('+thisData.split('\n')[1]+')');
	var childSelObj=document.getElementById("universityID");
	names.splice(0,0," --- Please select your school --- ");
	values.splice(0,0,"-1");
	updateSelectBox(childSelObj,names,values);
}

function updateSelectBox(selBoxObj,names,values,selIndex) {
  if(selBoxObj != null){
	selBoxObj.length=0;
	for ( var i=0 ; i < names.length ; i++ ) {
		selBoxObj.length++;
		newOption=new Option( names[i] );
		newOption.value= values[i];
		if ( selIndex == newOption.value ) newOption.selected=true;
		selBoxObj.options[i]=newOption;
	}
  }
}

function setSelectBoxIndex(selBoxObj,selVal) {
	for ( var i=0 ; i < selBoxObj.length ; i++ ) {
		if ( selBoxObj.options[i].value == selVal ) {
			selBoxObj.options[i].selected=true;
		}
		else {
			selBoxObj.options[i].selected=false;
		}
	}
}

function selectBoxPrompt(outputFieldID,waitMsg) {
	outputField=document.getElementById(outputFieldID);
	if(outputField !=null){
	outputField.length=0;
	outputField.length++;
	newOption=new Option(waitMsg);
	newOption.value= "-1";
	outputField.options[0]=newOption;
	}
}

function getSelectObjValue(selObj) {
	return selObj.options[selObj.selectedIndex].value;
}

function eduStatus(hasEDU) {
	hideErrors("errorTop");
	if ( get("error-message") ) hideElement( get("error-message") );
	if ( hasEDU ) {
		//changeClass(document.body,"eduPage");
		//changeClass(get("signUpFormMessage"),"eduPage");
		get("schoolEmailField").style.display="block";
		get("validEmailRequired").value="true";
	}
	else {
		//changeClass(document.body,"noEduPage");
		//changeClass(get("signUpFormMessage"),"noEduPage");
		get("schoolEmailField").style.display="none";
		get("validEmailRequired").value="false";
	}
	scroll(0,0);
	return false;
}

function getJoinForm() {
	return get("signUpFormObj");
}
		
function submitForm() {
		if ( getJoinForm().permissionToEmailBox.checked ) {
			getJoinForm().permissionToEmail.value='true';
		}
		else {
			getJoinForm().permissionToEmail.value='false';
		}
		
		if ( getJoinForm().permissionToSMSBox.checked ) {
			getJoinForm().permissionToSMS.value='true';
		}
		else {
			getJoinForm().permissionToSMS.value='false';
		}
		getJoinForm().submit();
}
		
function confirmTermsJoin() {
		if ( getJoinForm().permissionToVerify.checked ) {
			submitForm();
		}
		else {
			alert('You must check the box above the Continue button, agreeing to the Terms and Conditions.');
		}
}

function checkSMSPref(origCellValue, newCellValue) {
	if ( origCellValue == '' && newCellValue != '') {
		getJoinForm().dealsToCellPhone.checked=true;
	}
}

function uncheckSMSPref(newCellValue) {
	if ( newCellValue == '') {
		getJoinForm().dealsToCellPhone.checked=false;
	}
}

function handleCheckBoxes(){
		if(document.form1.permissionToEmail.checked){
			document.form1.permissionToEmail.value='true';
		}
		else {
			document.form1.permissionToEmail.value='false';
		}
		return true;
	}
// resets appropriate values and attempts to join
function submitJoinForm() { 
		handleCheckBoxes();
		getJoinForm().submit();
}
		
function useNoEduForm(flag) {
	getJoinForm().action='/register/saveData';
	getJoinForm().noEduForm.value=flag;
	getJoinForm().suppressErrors.value='true';
	getJoinForm().submit();
}
		
function matchEduEmail() {
    if ( getJoinForm().email.value.indexOf('.edu') >= 0 ) {
	    getJoinForm().universityEmail.value=getJoinForm().email.value;
	}
}

function popupWindowMySchoolIsNotListed(email ,firstname,lastname,universityLocationID,universityCountryID){
    popupLink='/member/sendSchoolInfo';
	
	if ( universityLocationID == '-1' ) {
		alert('Please select a state to see if your school is listed');
		return;
	}

	if (universityCountryID != -1) {
		popupLink += '?countryID=';
		popupLink += universityCountryID;
	}
	if (universityLocationID != -1) {
		popupLink += '&stateID=';
		popupLink += universityLocationID;
	}
	popupLink += '&email='+email;
	if (firstname != '' || lastname != '') {
		popupLink += '&name=';
		if ( firstname != '') {
			popupLink += firstname;
		}
		if ( lastname != '') {
			popupLink += '+'+lastname;
		}
	}
	//displayBlurb(popupLink, 600, 350);
	popupWindow(popupLink,600,350,'resizable,scrollbars')
}

function mySchoolIsNotListed(formID) {
    //popupLink='/member/sendSchoolInfo';
	var formRef=get(formID);
	var universityLocationID = formRef.universityLocationID.options[formRef.universityLocationID.selectedIndex].value;
	var universityCountryID = formRef.universityCountryID.options[formRef.universityCountryID.selectedIndex].value;
	var email = formRef.email.value;
	var firstname = formRef.firstname.value;
	var lastname = formRef.lastname.value;
	popupWindowMySchoolIsNotListed(email ,firstname,lastname,universityLocationID,universityCountryID);
//	if ( formRef.universityLocationID.options[formRef.universityLocationID.selectedIndex].value == '-1' ) {
//		alert('Please select a state to see if your school is listed');
//		return;
//	}
//
//	if (formRef.universityCountryID.options[formRef.universityCountryID.selectedIndex].value != -1) {
//		popupLink += '?countryID=';
//		popupLink += formRef.universityCountryID.options[formRef.universityCountryID.selectedIndex].value;
//	}
//	if (formRef.universityLocationID.options[formRef.universityLocationID.selectedIndex].value != -1) {
//		popupLink += '&stateID=';
//		popupLink += formRef.universityLocationID.options[formRef.universityLocationID.selectedIndex].value;
//	}
//	popupLink += '&email='+formRef.email.value;
//	if (formRef.firstname.value != '' || formRef.lastname.value != '') {
//		popupLink += '&name=';
//		if ( formRef.firstname.value != '') {
//			popupLink += formRef.firstname.value;
//		}
//		if ( formRef.lastname.value != '') {
//			popupLink += '+'+formRef.lastname.value;
//		}
//	}
//	//displayBlurb(popupLink, 600, 350);
//	popupWindow(popupLink,600,350,'resizable,scrollbars')
}

function submitSchoolInfo() {
	document.schoolInfo.country.value=document.schoolInfo.countryID.options[document.schoolInfo.countryID.selectedIndex].text;
	document.schoolInfo.state.value=document.schoolInfo.stateID.options[document.schoolInfo.stateID.selectedIndex].text;
	document.schoolInfo.submit();
}

function populateUniversityInfo() {
	if (document.form1.universityLocationID.selectedIndex != 0)
		document.form1.universityState.value=document.form1.universityLocationID.options[document.form1.universityLocationID.selectedIndex].text;
	if (document.form1.universityID.selectedIndex != 0)
		document.form1.universityName.value=document.form1.universityID.options[document.form1.universityID.selectedIndex].text;
}

function testMe() {
alert(getJoinForm().universityID.options[getJoinForm().universityID.selectedIndex].text);
}

function resendEduEmail() {
    goToURL("/register/resendemail");
}

function forgotPassword() {
    email=document.login.email.value;
	forgotPasswordURL='/membership/forgotPassword';
	if (email != null && email.indexOf('@') > 0) {
	    forgotPasswordURL += '?email='+email;
	}
	window.location=forgotPasswordURL;
}

function validateAmbassadorForm() {
	aform=get("ambassadorForm");
	if (aform.firstName.value == '' || !checkLetters(aform.firstName.value)) {
		alert('You must enter your first name.');
		aform.firstName.focus();
	}
	else if (aform.lastName.value == '' || !checkLetters(aform.lastName.value)) {
		alert('You must enter your last name.');
		aform.lastName.focus();
	}
	else if (aform.email.value == '' || aform.email.value.indexOf('@') <= 0) {
		alert('You must enter a valid email.');
		aform.email.focus();
	}
	else if (aform.phone.value == '' || !validAllPhoneNumber(aform.phone.value)) {
		alert('You must enter a phone number where we can reach you.');
		aform.phone.focus();
	}
	else if (aform.university.value == '') {
		alert('You must enter the name of your college or university.');
		aform.university.focus();
	}
	else if (aform.major.value == '') {
		alert('Please list your major or concentration at your college or university.');
		aform.major.focus();
	}
	else if (getSelectBoxValue(get("suMember")) == '') {
		alert('Please indicate whether or not you are a StudentUniverse member.');
		aform.suMember.focus();
	}
	else {
		aform.submit();
	}
}
function validAllPhoneNumber(PhoneNumber) {
	var PNum = new String(PhoneNumber);
	var regex = /^[0-9 \.\-\(\)\+\*]*$/;
	return regex.test(PNum);
}

function checkLetters(LETS)
{
	var regu = "^[a-zA-Z ]+$";
	var re = new RegExp(regu);
	if (re.test(LETS)) return true;
	else return false;
}

function imageToggle (type){
	if(type == 1){
		if(get("tpToggle").src.indexOf("nested.gif") > 0){
			get("tpToggle").src = get("tpToggle").src.replace(/nested.gif/,"expanded.gif");
		}else{
			get("tpToggle").src = get("tpToggle").src.replace(/expanded.gif/,"nested.gif");
		}
	}else{
		
		if(get("ccToggle").src.indexOf("nested.gif") > 0){
			get("ccToggle").src = get("ccToggle").src.replace(/nested.gif/,"expanded.gif");
		}else{
			get("ccToggle").src = get("ccToggle").src.replace(/expanded.gif/,"nested.gif");
		}
	}
}


