//<!-- TOPIC Javascript Libraries -->
// Functions for Index pages
// Inlcuce this file after fsa.js, amessages.js, and agen.js

var clHandleHelp;
var clHandleCust;

// Override Help in agen.js
function Help(szHelp, szLocale) {
	var szFile;
	
	if (szHelp) {
		szFile = "/help/" + szHelp   // open with a given file
	} else {
		szFile = "/help/fftoc00.htm"  // by default, open the help content file
	}

	if (szLocale && szLocale.indexOf("es_ES") > -1) {
		szFile = "/es_ES" + szFile ;
	}

	openWindow(clHandleHelp, szFile, "help", szHelpWinFeatures);
}

// redirect to previous cycle helps
function PrevHelp(szHelp, szLocale) {
	var szFile;

	if (szHelp) {
		if (szLocale && szLocale.indexOf("es_ES") > -1) {
			szFile = "/es_ES/fotw1112/help/" + szHelp   // open with a given file
		} else {
			szFile = "/fotw1112/help/" + szHelp   // open with a given file
		}
	} else {
		if (szLocale && szLocale.indexOf("es_ES") > -1) {
			szFile = "/es_ES/fotw1112/help/fftoc00.htm"  // by default, open the help content file
		} else {
			szFile = "/fotw1112/help/fftoc00.htm"  // by default, open the help content file
		}
	}

	openWindow(clHandleHelp, szFile, "help", szHelpWinFeatures);
}

// redirect to 0405 site for the help for R2T4
function R2T4Help(szHelp) {
	var szFile;

	if (szHelp) {
		szFile = "/fotw0405/help/" + szHelp   // open with a given file
	} else {
		szFile = "/fotw0405/help/fftoc00.htm"  // by default, open the help content file
	}

	openWindow(clHandleHelp, szFile, "help", szHelpWinFeatures);
}

function PrevCycle(szFile) {
	if (!szFile) {
		return;
	}

    // redirect to previous cycle
	location.href = "/FOTWWebApp/fotw1011/" + szFile;
}

function JSP(szFile, szLocale) {
	if (!szFile) {
		return;
	}
	
	// redirect index JSP page to application server
	if (szLocale && szLocale.indexOf("es_ES") > -1) {
    	location.href = "/FOTWWebApp/es_ES/" + szFile;
    } else {
    	location.href = "/FOTWWebApp/" + szFile;
    }
}

function ConfirmKey(szValue ) {
    var bRet = true
	if (szValue < "128" && szValue != "") {
		bRet = confirm(szUse128Msg)
    }
	if (bRet == false) {
		FafsaHome()
	}
    return bRet
}

function CloseHelp() {
	if (clHandleHelp) {
		clHandleHelp.close()
		clHandleHelp = null
	}
}

function CustServ(szLocale) {
	var szHelp;

	if (szLocale && szLocale.indexOf("es_ES") > -1) {
		szHelp = "/es_ES/help/cs.htm";
	} else { 
		szHelp = "/help/cs.htm";
	}
	
	openWindow(clHandleCust, szHelp, "CustomerService", szHelpWinFeatures);	
}

//open PIN site with requested page
function PIN(szFile, szLocale)
{
	var szContext="";
	if (szLocale && szLocale.indexOf("es_ES") > -1) {
		if(szFile.indexOf("?") > -1)
		{
			szFile=szFile+"&locale=es_ES";
		}
		else
		{
			szFile=szFile+"?locale=es_ES";
		}

	} 
	openWindow(clHandleExternal, szFile, "pin", szExternalWinFeatures);	
}

function FSLookup(szLocale)
{
	if (szLocale && szLocale.indexOf("es_ES") > -1) {
		location.href ="/FOTWWebApp/FSLookupServlet?locale=es_ES";
	} else {
		location.href ="/FOTWWebApp/FSLookupServlet";
	}
}

function WindowPopUp(szFile) {
    popWindow(szFile,550,600,1);
}

// function to open external website and PDF in new browser window
function openExternal(szFileName) {
	popWindow(szFileName, 800,600, 1);
}


function Search()
{
	var szWinName = "search";
	
	szWinFeatures = "width=1,height=1,menubar=0,scrollbars=yes,resizable=yes,height=850,width=700";
	
	var foundAChar = 'N';
  for(stringIndex = 0; stringIndex < document.FAFSA.q.value.length; stringIndex++){
      if(document.FAFSA.q.value.charAt(stringIndex) != ' '){
        foundAChar = 'Y';
        break;
      }
  }
  
  if(foundAChar == 'Y'){
  }else{
    return;
  }
  	
	clHandleSearch = window.open('', szWinName, szWinFeatures);
	clHandleSearch.resizeTo(850,700);
	if (clHandleSearch) {
		with(document.FAFSA)
		{
			target = szWinName;				   
			if(q.value == "")			  
				action = "";
			else
				action = '/FAFSA/searchres.jsp?q='+q.value+'&requiredfields=' + requiredfields.value + '&numresults=' + numresults.value + '&site=FAFSA23';
			submit();
		}
	}
}

// Adjust when the search stuff is pushed down (notably Mac 10.5)		
function FixSearchBox()
{
	var topBrowseHelp = jQuery("ul[class=topGrad] > li:first").position().top;
	var topSearch = jQuery("li[id=search]").position().top;
	if (topSearch > topBrowseHelp) {
		jQuery("#query").attr('size', '15');
	}
}

///////////////////////////////////////////////////////
//  FOR GOOGLE
///////////////////////////////////////////////////////

// Used by Google search navigation bar
function search_nav(iStart)
{
	with(document.FAFSA) {
		start.value = iStart;
		Search();
	}
}

// Used by Google
function spelling_suggestion(newQuery)
{
	with(document.FAFSA) {
		q.value = newQuery;
		Search();
	}
}

///////////////////////////////////////////////////////
//  FOR GOOGLE - END
///////////////////////////////////////////////////////

