/* 
==============================
YourStudentCentre.com Basic Javascrit Functions
==============================
This Javascript cucumber was pickled by:
>> Robin Wallar at See Design
>> www.seedesign.ca | robin [at] seedesign.ca
------------------------------
Written with massive mits on while scraping ice of the screen
of my icicle that serves as a monitor. 
------------------------------

------------------------------
Feel free to use this to educate
yourself on the wonders of javascript.
If you plan on copying something directly please contact us. 
------------------------------
*/

var checkflag = "false";

function check(field) {
	if (checkflag == "false")
	{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = true;
		}
		checkflag = "true";
		return "Uncheck All"; 
	}else{
		for (i = 0; i < field.length; i++)
		{
			field[i].checked = false;
		}
		checkflag = "false";
		return "Check All";
	}
}

function confirm_do()
{
	var confirmed = confirm("Are you sure you want to do that?");
	if(confirmed)
	{
		return true;
	}else{
		return false;
	}
}

function check_form(error, get_field)
{
	if(get_field=="")
	{
		alert(error);	
		return false;
	}else{
		return true;
	}

}

/*this will get the style attributes of a css element - ussualyl a div or span */
function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

      


/*********************************************************************************************************************************************
BEGIN HEADLINE ROTATION SET UP
*********************************************************************************************************************************************/
var the_timeout;
var j=2;
var k = 1;
var timer = null;
var headlines_arr = new Array();
var headline_loaded=1;
var initiate_headlines=false;

/*this function will receive the array and allocate the data*/
function make_headline(type, title, date, file, content, location)
{
	this.type = type;
	this.title = title;
	this.date = date;
	this.file = file;
	this.content = content;
	this.location = location;
	this.write = show_headline;
}

	

function slide_headline()
{
	if(this.initiate_headlines)
	{
		document.getElementById('headline_next').innerHTML = headlines_arr[j];
	
	  // get the stylesheet
	  var style_show = getStyleObject('headline_show');
	  var style_next = getStyleObject('headline_next');
	 
	  if (style_show)
	  {
		// get the current coordinate and add 5
		var current_opac = (style_show.opacity);
			
		/*make firefox eat a luminous pickle for being stupid and slow*/
		var browser=navigator.appVersion; 
		if(browser=="5.0 (Macintosh; en-US)" || browser=="5.0 (Windows; en-US)" )
		{
			var new_opac = current_opac - .06;
		}else{
			var new_opac = current_opac - .015;
		}
	
		style_show.opacity = new_opac;
		style_show.filter = 'alpha(opacity=' + new_opac*100 + ')';
	
		if (new_opac >= 0)
		{
			setTimeout('slide_headline();', 0);
		}else{
			var len = headlines_arr.length;
			if(k >= len)
			{
				k = 0;
			}
			
			if(k+1<len)
			{
				j=k+1;	
			}else{
				j=0;
			}
	
			document.getElementById('headline_show').innerHTML = headlines_arr[k];
	
			style_show.opacity = 1;
			style_show.filter = 'alpha(opacity=100)';
			
			k++;
					
			timer = setTimeout('slide_headline();',4000);	
		}
	  }
	}
}

function pause_headline()
{
	if (timer != null)
	{
		clearTimeout(timer);
		timer = null;
	}
}

function play_headline()
{
	if (timer == null)
	{
		timer = setTimeout('slide_headline();', 4000);
	}
}

/*********************************************************************************************************************************************
END HEADLINE ROTATION SET UP
*********************************************************************************************************************************************/
function load_admin(div, url_in)
{
	height = document.getElementById(div).offsetHeight + 100 + 'px';
	var url = url_in + '&height=' + height;
	window.location.href = url;
}	

function view_news(url)
{
	window.location.href = url;
}	

/* Nav Hack for IE */
function startList() 
{
	if(document.all && document.getElementById)
	{
		navRoot = document.getElementById("nav_primary");
		for (i=0; i<navRoot.childNodes.length; i++)
		{
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI")
			{
				node.onmouseover=function()
				{
					this.className+=" over";
				}
				node.onmouseout=function()
				{
					this.className=this.className.replace
					(" over", "");
			 	}
			}
		}
	}
}
/* End Nav Hack for IE */

/*preload images function*/
var preloaded = new Array();
function preload_images()
{
    for (var i = 0; i < arguments.length; i++)
	{
        preloaded[i] = document.createElement('img');
        preloaded[i].setAttribute('src',arguments[i]);
    };
};

/*validate the contact form*/
function  validate_contact()
{
	if(document.contact.name.value!="")
	{
		var email_reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if(email_reg.test(document.contact.email.value))
		{
			if(document.contact.body_txt.value!="")
			{					
				return true;
			}else{
				alert("Please enter content");
				return false;
			}
		}else{
			alert("Please enter a real email");
			return false;
		}
	}else{
		alert("Please enter your name");
		return false;
	}			
}		

/*validate the email list subscription and send to server for processing*/
function mlist_send_signup()
{
	var email_reg=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var div = document.getElementById('mlist_signup');
	if(email_reg.test(div.value))
	{			
		var poststr = "email=" + encodeURI(div.value ) +
				"&mlist=mlist";
					
		makePOSTRequest('ajax/mlist_signup.php', poststr, 'mlist');
		return true;
	}else{
		alert("Please enter a real email");
		return false;
	}
}



/*this will be used to post ajax forms on enter - making IE sit in corner */
function submit_on_enter(input)
{
    input.onkeydown = function(e)
	{
		e = e || window.event;

		if (e.which)
		{
			if(e.which ==13)
			{
				mlist_send_signup(document.getElementById('mlist_signup'))
			}
		}else if(e.keyCode){
			if(e.keyCode ==13)
			{
				mlist_send_signup(document.getElementById('mlist_signup'))
			}
		}
	}
	return false;
}

/*being div closer*/
/*use this to close open divs that have been "opened" by the user. it will activated via an onclick on the body tag*/
/*these are the variables that control whether to open or close*/
var v_mlist_open = false;
var v_mlist_open_tracker = false; /*this will follow whether or not a div is being hovered on which will prevent it from closing*/

function div_closer()
{
	if(this.v_mlist_open && !this.v_mlist_open_track)
	{
		
		v_mlist_open = false;
		document.getElementById('mlist').style.top='160px';
	}
}

/*functions controlled by the div_closer*/
function mlist_open()
{
	this.v_mlist_open = true;
	this.v_mlist_open_track = true;
	document.getElementById('mlist').style.top="100px";	
}

function mlist_open_out()
{
	this.v_mlist_open_track = false;
}
/*end div closer*/

/*div hiding and showing*/
function show_div(id)
{
	gebi(id).style.overflow = "visible";
	gebi(id).style.visibility = "visible";
	gebi(id).style.height = "13px";		
}

function hide_div(id)
{
	gebi(id).style.overflow = "hidden";
	gebi(id).style.visibility = "hidden";
	gebi(id).style.height = "0";	
}
