// JavaScript Document

// The following has been commented out because it's incredibly annoying:
/*if (navigator.userAgent.indexOf('MSIE') > 0){
	window.location.replace("index_ms.php");
}
else if ( navigator.userAgent.indexOf('Firefox') < 0 ){
getfox = confirm('This Site has been designed for use with the Mozilla Firefox browser. You may download Firefox for free at http://www.mozilla.com/firefox/');
if (getfox) {window.open('http://www.mozilla.com/firefox/', '_blank');}
}
*/

var username = "";

var logOut = new Asynchronous;
var logObj = new Asynchronous;
var recPol = new Asynchronous;



logObj.complete = function (status, statusText, responseText, responseXML)
{
	//if (responseText != ''){
	document.getElementById("loginFormTxt").innerHTML = innerBox(250, 200, 'loginFormTxt', 'Login', responseText);
}

function openInfo(url)
{ 
	openWindow(url, '_info', 600, 670);
}

function openBoards(){
	openWindow('messageboards.php', '_input', 420, 550);
}

function openAdvice(){
	openWindow('advicecolumn.php', '_input', 420, 550);
}

function openWindow(url, target, h, w)
{
	window.open(url, target, 'height='+h+', width='+w+', top = 0, left = 0, resizable= yes, menubar = no, location = no, toolbar = no, scrollbars = yes', false);
}

function init(id)
{	
	loginBox();
	loginUser(id);
}

// Does this do anything?
function openForm(id)
{
	document.getElementById(id).style.visibility = 'visible';
}




//Changes the contents of a Div Tag for login and registration input
function innerBox(h, w, id, title, bodyText)
{
	var str = '';
	str += '<div class="title">'+title;
	str += '</div>';
	str += '<div ';
	str += 'style="';
	str += 'width:'+w+';font-size:12px;" align=right><a class=close href="#" onClick="document.getElementById(\''+id+'\').style.visibility=\'hidden\'">Close X</a></div>';
	str += '<div class="FormTxt" id="FormBody"';
	str += 'style="';
	str += 'height:'+h+';';
	str += 'width:'+w+';';
	str +=  '">'+bodyText+'</div>';
	document.getElementById(id).style.height = h+25;
	return str;
}

//The actual form that gets put into the box
function loginForm(){
	var loc = 'phplog.php';
	var str = "";
	 str += '<p>Enter your username and password.';
	 str += '<form name="login" id=login method="post" action="javascript:logObj.call(\'GET\', \'' + loc + '\', compileLog() );">';
	 str += '<table><tr><td><strong>User ID</strong></td><td><input type="text" id="username" value="" width="110" size="13"></td></tr>';
     str += '<tr><td><strong>Password</strong></td><td><input type="password" id="password" value="" width="110" size="13"></td></tr></table>';
	 str += '<input type="submit" name="login" value="Login"><input type="hidden" name="action" value="login"></p>';
	 str += '</form>';
	 return str;
}

function openLogin(){
document.getElementById('loginFormTxt').style.visibility = 'visible';
document.getElementById('loginFormTxt').innerHTML = innerBox(130, 185, 'loginFormTxt', 'Login', loginForm())
document.getElementById('username').focus();
}

function loginBox(){
	var id = 'loginFormTxt';
	makeBox(id);
	moveBox(id, 450, 150)
}

function logout(){
	document.getElementById('logStatus').innerHTML = 'You are not logged in.';
	username = "";
	logOut.call('GET', 'signout.php', '');
}

function compileLog(){
	var str = "";
	str += "username=" + document.getElementById('username').value + "&";
	str += "password=" + document.getElementById('password').value + "&";
	str += "action=login";
	return str;
}

function loginUser(id){
	if (id != '' && id != null){
	username = id;
	var str = "";
	str += '<div align="center">';
	str += '<font size="-1">'+ id + '</font> is logged in.';
	str += '<br/ >';
	str += '<a href="javascript:logout()">Click here</a> to sign out.';
	str += '</div>';
	document.getElementById('logStatus').innerHTML = str;
}
}

function forgotPass(){
	var loc = 'phplog.php';
	var str = "<p>Submit your User ID to see your hint.</p>";
	str += '<form name="login" id=login method="post" action="javascript:logObj.call(\'GET\', \'' + loc + '\', requestHint() );">';
	str += '<table><tr><td><strong>User ID</strong></td><td><input type="text" id="username" value="" width="110" size="13"></td></tr>			    </table>';
 	str += '<input type="submit" name="submit" value="Submit"><input type="hidden" name="action" value="login"></p></form>';
 
document.getElementById("loginFormTxt").innerHTML = innerBox(130, 185, 'loginFormTxt', 'Password Hint', str);
openForm("loginFormTxt");
}

function requestHint(){
	var str = "";
	str += "username=" + document.getElementById('username').value + "&";
	str += "hint=true&";
	str += "action=login";
	return str;
}


function openReg(){	
	var str = '';
	if (username == 'Admin')
{
	str += '?reg=admin';
}
	window.location='registration.php'+str;
	
}

function compileForm(form){
	var str = "";
	var formObj = document.getElementById(form);
	var i = 0;
	var str = "name="+form;
	do{
	str += "&";
	formObj[i].name == 'submit' ? nameValue = "" : nameValue = formObj[i].name + "=" + formObj[i].value;
	str += nameValue;
	}while(formObj[++i]);
	return str;
}

function privacyPolicy(){
	var str = "";
	openForm('Privacy Policy');
	str += "<p>All information is strictly confidential.</p>";
	str += "<p>To print the policy, Click here.</p>";
	str += "<p>To open the policy in a new window, Click here.</p>";
	document.getElementById("loginFormTxt").innerHTML = str;
}

function MeetingTimes(s){
var str = "";
	switch (s)
	{
		case 1:
			str += "<h3>Canyon Crest</h3>";
			str += "<strong>";
			str += "Fridays during lunch<br />";
			str += "(11:29 - 11:59)<br/>";
			str += "(Late start 11:59 - 12:29)<br/>";
			str += "in Room E202";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;
		case 2:
			str += "<h3>Hoover</h3>";
			str += "<strong>";
			str += "Thursdays during lunch<br/>";
			str += "(12:29 - 1:04)<br/>";
			str += "in Room B7";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;
		case 3:
			str += "<h3>La Costa</h3>";
			str += "<strong>";
			str += "Mondays during lunch<br/>";
			str += "(11:55 - 12:25)<br/>";
			str += "in room 340";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;			
		case 4:
			str += "<h3>Mission Bay</h3>";
			str += "<strong>";
			str += "Wednesdays during lunch<br/>";
			str += "(12:03 - 12:40)<br/>";
			str += "in Room 265";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;
		case 5:
			str += "<h3>San Dieguito</h3>";
			str += "<strong>";
			str += "Tuesdays during lunch<br/>";
			str += "(11:23 - 11:58)<br/>";
			str += "in Room 90";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;
		case 6:
			str += "<h3>Torrey Pines</h3>";
			str += "<strong>";
			str += "Wednesdays during lunch<br/>";
			str += "(11:55 - 12:25)<br/>";
			str += "in Room E206";
			str += "</strong>";
			document.getElementById('meetingText').innerHTML = str;
			break;
		default:
			str += "<br/>Want to talk?<br/>Want more info?<br/>Want free stuff?<br/>";
        	str +=  "Come to Project Options during lunch and get free pizza and drinks";
			document.getElementById('meetingText').innerHTML = str;
	}
}

//Creates initial Div Tag for login and registration input
function makeBox(id){
	var str = '';
	str += '<div class="popDiv" id='+id+' style="visibility:hidden;z-index:99;"></div>';	
	document.getElementById("container").innerHTML = str + document.getElementById("container").innerHTML;
}
function moveBox(id, x, y){
document.getElementById(id).style.top = y
document.getElementById(id).style.left = x	
}

recPol.complete = function (status, statusText, responseText, responseXML){ 
//alert(responseText);
}

function getPoll(xml){
	//	recPol.call('GET', 'polls.php', xml); 	
}

function hotTopics(){
	//if (username != ''){
		window.location='ht/';
	//} else {
	//	alert('Please log in or register first.'); 	
	//}
}

function streetSmarts(){
	if (username != ''){
		window.location='ss/';
	} else {
		alert('Please log in or register first.'); 	
	}
}
function funGames(){
	if (username != ''){
		window.location='games/';
	} else {
		alert('Please log in or register first.'); 	
	}
}

function dealwStress(){
	if (username != ''){
		window.location='stress/';
	} else {
		alert('Please log in or register first.'); 	
	}
}
