// Scott Borys
// scott.borys@gmail.com
// Freshman Advising 2009

// populate fields with default values on page load

// clear default value from field when selected
function fieldclear(field) 
{
  if (field.defaultValue==field.value) 
      field.value = "";
}
// clear null value and return to default value when blurred
function fieldrestore(field)
{
  if (field.value == "")
      field.value = field.defaultValue;
}

// takes a string message and updates website with message
function updateMessage (message)
{
   var displaystring = "<p style=\"text-align: center;\">" + message + "</p>";
   success=document.getElementById('login_update').innerHTML = displaystring; 
}

// Adds nicEditor support (RTE)
function addEditor()
{
     nicEditors.allTextAreas();
}

// OnLoad processes
function process()
{
    // do nothing;
}

// loads the center channel with parameter in style XXXX.php
function load(page)
{
	var ajaxRequest;  // The variable that makes Ajax possible!
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				// Something went wrong
				alert("Login Error.  Please email scottborys@gmail.com"); 
				return false;
			} } }
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function()
        {
		if (ajaxRequest.readyState == 4)
                {
                      document.getElementById('content').innerHTML = ajaxRequest.responseText;
                      document.getElementById("page").style.width = "900px";
                      document.getElementById("content").style.width = "720px";
		}
	} 
        var r = Math.floor(Math.random()*1000001)
        var params = "?r=" + r;
	ajaxRequest.open("GET", "/pages/" + page + params, true);
	ajaxRequest.send(null);
} 

// loads the center channel with parameter in style XXXX.php
function loadNavigation(direction)
{
        var replace;
        if ("rfiyd" == direction)
        {
             replace = "<a class=\"burgundy\" href=\"javascript:load('rfiyd-whoweare.php')\">Who We Are</a> | <a class=\"burgundy\" href=\"javascript:load('rfiyd-whatwedo.php')\">What We Do</a> | <a class=\"burgundy\" href=\"javascript:load('rfiyd-whatyoucando.php')\">What You Can Do</a> | <a class=\"burgundy\" href=\"javascript:load('rfiyd-partners.php')\">Partners</a> | <a class=\"burgundy\" href=\"javascript:load('rfiyd-contact.php')\">Contact</a>";
             document.getElementById("texttop").innerHTML = replace;
        }
        else if ("blg" == direction)
        {
             replace = "<a class=\"burgundy\" href=\"javascript:load('blg.php')\">Home</a> | <a class=\"burgundy\" href=\"javascript:load('blg-blog.php')\">Blog</a> | <a class=\"burgundy\" href=\"javascript:load('blg-events.php')\">Events</a> | <a class=\"burgundy\" href=\"javascript:load('blg-participants.php')\">Participants</a> | <a class=\"burgundy\" href=\"javascript:load('blg-journeyforward.php')\">Journey Forward</a> | <a class=\"burgundy\" href=\"javascript:load('blg-partners.php')\">Partners</a> | <a class=\"burgundy\" href=\"javascript:load('blg-media.php')\">Media</a>";
             document.getElementById("texttop").innerHTML = replace;
        }
        else
        {
               alert("stop hacking my site, bro");
        }
} 

function loadHome()
{
        document.getElementById("content").innerHTML = "<a href=\"javascript:load('blg.php')\"><img src=\"photos/opening.jpg\" alt=\"Alexis and Rwandan Youths\" style=\"border-style: none\" onclick=\"javascript:loadNavigation('blg')\"></a>";
        var replace = "";
        document.getElementById("texttop").innerHTML = replace;
        document.getElementById("content").style.width = "525px";
        document.getElementById("page").style.width = "700px";

}

// Checks variable field for "" string
function isBlank(field)
{   
     if (field == "")
     {
         return true;
     }
     else
     {
         return false;
     }
}

// Checks email for presence of @ and .
function isEmailValid(email)
{   
     if (email.indexOf("@") < 0 || email.indexOf(".") < 0)
     {
         return false;
     }
     else
     {
         return true;
     }
}
function resizeLarge()
{
   document.getElementById("page").style.width = "900px";
   document.getElementById("content").style.width = "720px";
}