//This is a javascript file for the IUP COSC Dept./By Mbonisi Masilela

function redirect(loc)
{
	/*
		Description
		-----------
		This function is used to redirect a page to another site
		
		Usage
		-----
		i.)  javascript:redirect('http://targetsite.com');
		ii.) javascript:redirect('target.html');
		
	*/
	
	location.replace(loc) 
}

function showobj(e, e2)
{
	/*
		Description
		-----------
		This function toggle an image(e2) and a display area (e)
		These must be ids of an image and a area referenced by the given id
		
		Usage
		-----
		i.)  javascript:showobj('mytextarea','myimage');
	*/
	
	chgimg(e2);
	element = document.getElementById(e).style;
	element.display == 'none' ? element.display = 'block' : element.display = 'none';
}

function showobj2(e, e2, e3)
{
	/*
		Description
		-----------
		Performs the same function as showobj except that it manipulates the text in the
		target area to a specification of moverclass and moutclass. These 2 classes must be 
		defined in the document or in the css that controls the document.
		
		Usage
		-----
		i.)  javascript:showobj2('mytextarea','myimage','myclickabletext');
	*/
	
	chgimg(e2);
	element = document.getElementById(e).style;
	element2 = document.getElementById(e3);
	if(element.display == 'none')
	{
		element.display = 'block';
		element2.className = 'moverclass';
	}
	

	else
	{
		element.display = 'none';
		element2.className = 'moutclass';
	}
}

function showobj3(e, e2)
{
	/*
		Description
		-----------
		Performs the same function as showobj except that it manipulates the text in the
		target area to a specification of moverclass and moutclass. These 2 classes must be 
		defined in the document or in the css that controls the document.
		
		Usage
		-----
		i.)  javascript:showobj2('mytextarea','myimage','myclickabletext');
	*/
	
	chgimg(e2);
	element = document.getElementById(e).style;
	if(element.display == 'none')
	{
		element.display = 'block';
	}
	

	else
	{
		element.display = 'none';
	}
}

function chgimg(e)
{
	/*
		Description
		-----------
		This function toggle an image(e). The .src attribute can be changed to what ever
		images you would like to use when toggling back and forth.
		These must be ids of an image and a area referenced by the given id
		
		Usage
		-----
		i.)  javascript:chgimg('myimage');
	*/
	
	element = document.getElementById(e);
	element.src == 'http://www.iup.edu/mcnair/images/button-collapsed.gif' ? element.src = 'http://www.iup.edu/mcnair/images/button-expanded.GIF' : element.src = 'http://www.iup.edu/mcnair/images/button-collapsed.gif';
}

function chgimg2(e, e2, e3)
{
	/*
		Description
		-----------
		This function toggle an image(e). The e2 and e3 elements identify the 2 source locations of the
		images you would like to use when toggling back and forth.
		These must be ids of an image and a area referenced by the given id
		
		Usage
		-----
		Supposing that you have an image img2.gif that has an id called myimage. You want that when a user clicks on that image
		the images changes to img3.gif. And then when the user clicks on the image again it changes back to img2.gif. The function
		is used like this:
		
		i.)  javascript:chgimg2('myimage', 'http://mysite.com/images/img2.gif', 'http://mysite.com/images/img3.gif');
		
		Please note the full url to the images is used. This is what should be done. The following is an example
		that my lead to failded results. 
		
		DO NOT DO IT THIS WAY
				
		i.)  javascript:chgimg2('myimage', 'images/img2.gif', 'images/img3.gif');
		
		NB: This is used to create an effect like in windows explorer when you are browsing folders.
	*/
	
	element = document.getElementById(e);
	element.src == e2 ? element.src = e3 : element.src = e2;
}

function showPopupCenter(loc, w, h)
{
	var wh = (screen.width - w) / 2;
	var ht = (screen.height - h) / 2;
	var str = 'scrollbars=yes, resizable=yes, height=' + h + ',width=' + w + ',toolbar=0,top=' + ht + ',left=' + wh;
	window.open(loc, 'popup', str);
}

function onMoutChgColor(e, e2, e3, e4)
{
	el = document.getElementById(e).style;
	el2 = document.getElementById(e2).style;

	el2.display == 'block' ? el.background = e3 : el.background = e4; //'#ffeea3' : el.background = '#ffffd1';
}

function make_window_semi_full_screen()
{
	/*Makes a window 75% of the screen dimensions and centers it (kinda buggy)*/
	var wh = (screen.width - w) / 2;
	var ht = (screen.height - h) / 2;
	
	var w = (screen.width * 75) / 100;
	var h = (screen.height * 75) / 100;	
	
	window.resizeTo(w, h);
	window.moveTo(wh, ht);
}