function openWin(fname){  //open new window

	//var winParam = "width=800,height=600,toolbar,location,directories,status,menubar,scrollbars,resizable";
	//var param = 'width=400,height=400';	// default size
	var param = 'width=900,height=700';	// default size
	if (fname.indexOf('contact') != -1){param = 'width=550,height=650';}
	else if (fname.indexOf('mission.html') != -1){param = 'width=500,height=450';}
	else if (fname.indexOf('help_form') != -1){param = 'width=500,height=520';}
	else if (fname.indexOf('userinfo') != -1){param = 'width=600,height=400';}
	else if (fname.indexOf('financialaid') != -1){param = 'width=500,height=450';}
	else if (fname.indexOf('howtofind') != -1){param = 'width=600,height=400';}
	else if (fname.indexOf('http') != -1){param += ',toolbar,menubar';}
	else if (fname.indexOf('whatis') != -1){param += ',toolbar,location=yes';}
	param += ",resizable,scrollbars";
	window.open(fname,'',param);
}

function uscnews(id) {	//display uscnews story
	
	var url = "http://www.usc.edu/uscnews/stories/_id_.html";
	url = url.replace('_id_',id);
	var winParam = "width=800,height=600,scrollbars,toolbar,resizable";
	var w = window.open("","",winParam);
	w.window.focus();
	w.window.location = url;
}

function gopibbs(basename) {	// open pibbs faculty webpage

	var url = "http://www.usc.edu/pibbs/faculty/_base_.htm";
	window.location.href=url.replace('_base_',basename);
}

function pubmed(term){  //search pubmed

	// the following enables full-text access to some journals
	// http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?otool=uscnmlib 

	var url = "";
	var host = "http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?";
	//var host = "http://eutils.ncbi.nlm.nih.gov/entrez/query.fcgi?";

	if (term == "") 
		{url = "http://www.usc.edu/pibbs/pubmed.html";}
	else if (term.match(/^\d{6,}/))
		{url = host + "cmd=retrieve&db=pubmed&dopt=abstract&otool=uscnmlib&list_uids=";}
	else 
		{url = host + "cmd=search&db=pubmed&otool=uscnmlib&term=";}

	var winParam = "width=800,height=600,scrollbars,toolbar,resizable";
	var newWin = window.open("","", winParam);
	newWin.window.focus();
	newWin.window.location = url+term;
}

function crisp(query){	//search crisp database (nih grants)

	terms = query.split(',');
	var p_nlast = "p_nlast=" + terms[0];
	var p_nfirst = "&p_nfirst=" + terms[1];
	var p_query = "";
	if (terms[2]) {
		p_query = "&p_query=" + terms[2];
	}
	var p_fy ="&p_fy=2009,2008,2007,2006,2005,2004";	// last 5 years
	var p_state = "&p_state='CA',";
	var p_maxhit = "&p_maxhit=3000";

	var p_inst = "";
	var inst = terms[3];
	if (inst == 'usc'){
		p_inst = "&p_inst=University of Southern California";
	} else if (inst == 'chla') {
		p_inst = "&p_inst=Children's Hospital Los Angeles";
	} else if (inst == 'dei') {
		p_inst = "&p_inst=Doheny Eye Institute";
	}
	
	var url = "http://crisp.cit.nih.gov/crisp/crisp_lib.query?";
	url += p_nlast + p_nfirst + p_query + p_state + p_maxhit + p_inst + p_fy;
	var winParam = "scrollbars,toolbar,resizable";
	var newWin = window.open("","", winParam);
	newWin.window.focus();
	newWin.window.location = url;
}

function google(term){	//search usc using google

	//var url = "http://www.google.com/search?q=" + term + "+site:http://www.usc.edu";
	var url = "http://www.google.com/univ/usc?q=" + term;
	var winParam = "width=800,height=600,scrollbars,toolbar,resizable";
	var newWin = window.open("","", winParam);
	newWin.window.focus();
	newWin.window.location = url;
}

function keywords() {  //faculty keywords list - not used anymore

	var words = document.form.keywords.value;
	var name = "<div style=\"color:#0000bb\"><b>" + document.form.fac_name.value + "</b></div><br>" ;
	var w = window.open('','','width=600,height=500,resizable,scrollbars').document;
	w.write("<html><body onload=\"javascript:window.focus();\">");
	w.write("<h3><div style=\"color:#990000\">PIBBS Faculty Research Keywords</div></h3>");
	w.write(name + words);
	w.write("<p>Please <a href=\"javascript:window.close();\">click here</a> to close this window.");
	w.write("</body></html>");
	w.close();
}

function updateWin(){  //create faculty information update window

	var msg = document.form.fac_name.value;
	var subject = msg;
	var name = "\n<input type=\"text\" name=\"FH_Name\" size=\"30\" value=\"" + msg + "\"/>";
	msg = document.form.fac_email.value;
	var email = "\n<input type=\"text\" name=\"FH_Email\" size=\"30\" value=\"" + msg + "\"/>";
	msg = document.form.fac_research.value;
	var research = "<br>\n<textarea wrap=\"virtual\" name=\"Research\" rows=\"30\" cols=\"100\">" + msg + "</textarea>";
	var passwd = "\n<input type=\"text\" name=\"Password\" size=\"30\" value=\"\"/>";

	var w = window.open('','','resizable,scrollbars,menubar,toolbar').document;
	w.write("<html><head><title>PIBBS Faculty Information Update Form</title>");
	w.write("<link rel=\"stylesheet\" href=\"http://www.usc.edu/assets/css/default.css\" type=\"text/css\" media=\"screen\" /></head>");
	w.write("<body onload=\"self.focus()\" marginheight=\"0\" marginwidth=\"0\" background=\"http://www.usc.edu/assets/std/bg-stripes-light.gif\">")
	w.write("<div style=\"background-color:#990000;margin-bottom:10px;\"><img src=\"http://www.usc.edu/assets/uschead/usc-name-red.gif\"></div>")
	w.write("<table border=\"0\" width=\"80%\" cellspacing=\"5\" cellpadding=\"0\" align=\"center\"><tr><td>")

	w.write("<h3><div style=\"color:#990000\">PIBBS Faculty Information Update Form</div></h3>");
	w.write("\n<form method=\"post\" action=\"http://www.usc.edu/cgi-bin/form_handler\" name=\"faculty_update\">");

	w.write("<input type=\"hidden\" name=\"FH_Recipients\" value=\"pibbs@usc.edu,pibbsadm@usc.edu,rmostell@usc.edu\" />");
	w.write("<input type=\"hidden\" name=\"FH_Subject\" value=\"" + subject + "\" />");
	w.write("<input type=\"hidden\" name=\"FH_Topic\" value=\"Faculty Update Form\" />");
	w.write("<input type=\"hidden\" name=\"FH_RequireValidEmail\" value=\"yes\" />");
	w.write("<input type=\"hidden\" name=\"FH_Required_Fields\" value=\"FH_Name,FH_Email,Password,Research\" />");
	w.write("<input type=\"hidden\" name=\"FH_Display_Order\" value=\"FH_Name,FH_Email,Password,Research\" />");

	w.write("\nPlease update your information below and then click on the Submit button at the bottom of the page.  If you prefer, you may send your updated information by E-mail to <a href=\"mailto:pibbs@usc.edu\">pibbs@usc.edu</a> &nbsp; If you do not wish to change your information at this time, please <a href=\"javascript:window.close();\">click here</a> to close this window. Thank you.");
	w.write("\n<br><br><b>Your name:</b>&nbsp;" + name);
	w.write("\n<br><br><b>Your email address:</b>&nbsp;" + email);
	w.write("\n<br><br><b>Your password - IP Address :</b>&nbsp;" + passwd);
	w.write(" &nbsp; <a href=\"\" onclick=\"javascript:window.open('http://www.usc.edu/pibbs/ip','','width=400,height=400,resizable,scrollbars,menubar'); return false;\">Click here for IP Address</a>");
	w.write("\n<br><br><b>Your research information:</b> &nbsp; Please see Instructions below or click here for more <a href=\"http://www.usc.edu/pibbs/help_formatting.html\" target=\"help\">Help in Formatting</a>." + research);
	w.write("\n<br><br><input type=\"submit\" value=\"Submit Revised Form Now\"/>");
	w.write("&nbsp; &nbsp; or &nbsp; &nbsp; <input type=\"reset\" value=\"Reset Form to original (unrevised) content\"/>");
	w.write("\n<br></form>");
	w.write("<b>Instructions:</b> Please edit or paste your changes in the text box above. Use plain text only (ASCII text). Avoid formatting such as bold, underline, superscript, etc., or special non-ASCII characters (e.g. Greek alphabet). Separate paragraphs with a blank line (2 carriage returns).");
	w.write(" &nbsp; Please click here for more <a href=\"http://www.usc.edu/pibbs/help_formatting.html\" target=\"help\">Help in Formatting</a>.")
	w.write("</td></tr></table></body></html>");
	w.close();
}

function sendmail(fac_name,fac_email){  //create pibbs faculty/staff email form

	// staff, non-faculty name contains underscore character
	if (fac_name.indexOf('_') != -1){
		fac_name = fac_name.replace(/_/g,' ');
		var lastname = fac_name;
		var formname = "PIBBS Website E-mail Form";
	} else {	// extract faculty last name
		var temp = fac_name.split(",")[0]
		temp = temp.split(" ")
		var lastname = "Professor " + temp[temp.length -1]
		var formname = "PIBBS Faculty E-mail Form";
	}
		
	// user input fields
	var name = "\n<input type=\"text\" name=\"FH_Name\" size=\"30\" value=\"\"/>";
	var email = "\n<input type=\"text\" name=\"FH_Email\" size=\"30\" value=\"\"/>";
	var subject = "\n<input type=\"text\" name=\"Subject\" size=\"30\" value=\"\"/>";
	var msg = "\n<textarea wrap=\"virtual\" name=\"Message\" rows=\"10\" cols=\"60\"></textarea>";

	// setup window
	var w = window.open('','','width=600,height=600,resizable,scrollbars').document;
	w.write("<html><head><title>" + formname + "</title><link rel=\"stylesheet\" href=\"http://www.usc.edu/assets/css/default.css\" type=\"text/css\" media=\"screen\" /></head>")
	w.write("\n<body onload=\"self.focus()\" marginheight=\"0\" marginwidth=\"0\" background=\"http://www.usc.edu/assets/std/bg-stripes-light.gif\">")
	w.write("\n<div style=\"background-color:#990000;margin-bottom:10px;\"><img src=\"http://www.usc.edu/assets/uschead/usc-name-red.gif\"></div>")
	w.write("\n<table border=\"0\" width=\"80%\" cellspacing=\"5\" cellpadding=\"0\" align=\"center\"><tr><td>")

	w.write("\n<h3><div style=\"color:#990000\">" + formname + "</div></h3><hr size=\"1\">");
	w.write("\n<form method=\"post\" action=\"http://www.usc.edu/cgi-bin/form_handler\" name=\"email_form\">");

	w.write("\n<input type=\"hidden\" name=\"FH_Recipients\" value=\"" + fac_email + "\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_Subject\" value=\"" + fac_name + "\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_Topic\" value=\"PIBBS E-mail Form\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_RequireValidEmail\" value=\"yes\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_Required_Fields\" value=\"FH_Name,FH_Email,Subject,Message\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_Display_Order\" value=\"FH_Name,FH_Email,Subject,Message\"/>");
	w.write("\n<input type=\"hidden\" name=\"FH_OK_URL\" value=\"http://www.usc.edu/pibbs/email_confirmation.html\" />");

	w.write("\n<b>To: &nbsp; <font color=\"#000088\">" + fac_name + " &nbsp; &lt;" + fac_email + "&gt;</font></b>");
	w.write("\n<br><br><b>From &nbsp; - &nbsp; Your name:</b>&nbsp;" + name);
	w.write("\n<br><br><b>Your E-mail address:</b>&nbsp;" + email);
	w.write("\n<br><br><b>Subject:</b>&nbsp;" + subject);
	w.write("\n<br><br><b>Your message to &nbsp;&nbsp;<font color=\"#000088\">" + lastname + " :</font></b><br>" + msg);
	w.write("\n<br><br><input type=\"submit\" value=\"Submit E-mail Form\"/>");
	w.write("\n&nbsp; &nbsp; <input type=\"reset\" value=\"Reset E-mail Form\"/>");
	w.write("\n<br></form>");
	w.write("\n<br><br><b>Did you Google for PIBBS?</b>");
	w.write("\n</td></tr></table></body></html>");
	w.close();
}
