function winopen(doc)
{
	if (doc == 'terms') {var page = 'terms_of_service.html';}
	if (doc == 'priv') 	{var page = 'privacy_policy.html';}
	window.open(page, doc, 'height=500, width=600, status=yes, location=no, resizable=yes, scrollbars=yes');
}

// --------------------------------------------------------------------

function textarea_limit(taObj)
{
	if (taObj.value.length == textarea_max) return false;
	return true;
}

function textarea_counter(taObj,Cnt)
{
	objCnt = createObject(Cnt);
	objVal = taObj.value;	
	if (objVal.length > textarea_max) objVal = objVal.substring(0,textarea_max);
	if (objCnt)
	{
		objCnt.innerText = textarea_max - objVal.length;
	}
	return true;
}

function createObject(objId)
{
	if (document.getElementById) return document.getElementById(objId);
	else if (document.layers) return eval("document." + objId);
	else if (document.all) return eval("document.all." + objId);
	else return eval("document." + objId);
}

// --------------------------------------------------------------------

function tooltip(t,c)
{
	// fixed attribute works nicely on all but IE
	
    //var xxx = event.screenX - 350;
    //var yyy = event.screenY - 325;
    //overlib(t, FIXX, xxx, FIXY, yyy, CAPTION, c);
    
    overlib(t, LEFT, CAPTION, c);
}

// --------------------------------------------------------------------

function show_lightbox(t)
{
	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.createElement('div');
	overlay.id			= 'overlay';
	lb					= document.createElement('div');
	lb.id				= 'lightbox';
	lb.innerHTML		= t;
				
	bod.appendChild(overlay);
	bod.appendChild(lb);
	
	//document.getElementById('lightbox').style.border = 'double 25px green';
	
	document.getElementById('overlay').style.display = 'block';
	document.getElementById('lightbox').style.display = 'block';
	
	//document.getElementById('lightbox').style.verticalAlign  = 'middle';	
}

function close_lightbox()
{	
	document.getElementById('overlay').style.display = '';
	document.getElementById('lightbox').style.display = '';

	bod 				= document.getElementsByTagName('body')[0];
	overlay 			= document.getElementById('overlay');
	lb					= document.getElementById('lightbox');
				
	bod.removeChild(overlay);
	bod.removeChild(lb);		
}

// --------------------------------------------------------------------
	
function check_username(user,feed)
{
	if (user.value == '')
	{
		document.getElementById(feed).innerHTML = '';
		return;
	}
	
	var url = "/check_username.php?u=" + user.value;

	var xmlhttp;	
	
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState==4)
		{				
			// To make sure valid response is received from the server, 200 means response received is OK
			if(xmlhttp.status == 200)
			{			
				if (xmlhttp.responseText != 0)
				{
					document.getElementById(feed).innerHTML = '<span style="color: red;">Not Available</span>';
				}
				else
				{
					document.getElementById(feed).innerHTML = '<span style="color: green;">Available</span>';
				}						
			}
			else
			{
				alert("Problem retrieving data from the server, status code: "  + xmlhttp.status);
			}	
		}					
	}	
	
	xmlhttp.open("GET",url,true);	
	xmlhttp.send(null);
}

// --------------------------------------------------------------------		

function chkdel()
{		
	var found = 0;
	var v;		
		
	for(e=0; e<document.fullform.elements.length; e++)
	{
		if (document.fullform.elements[e].type == 'checkbox')
		{
			v = document.fullform.elements[e].name;	
			
			if (v.substring(0,3) == 'del')
			{			
				if (document.fullform.elements[e].checked == true) {found = 1}	
			}
		}

	}

	if (found == 0)
	{
		alert('You have not selected any quizzes to delete.');
		return false;
	}
	else
	{
		return confirm('Are you sure you want to delete the selected quizzes?');
	}
}

function chkarc()
{		
	var found = 0;
	var v;		
		
	for(e=0; e<document.fullform.elements.length; e++)
	{
		if (document.fullform.elements[e].type == 'checkbox')
		{
			v = document.fullform.elements[e].name;	
			
			if (v.substring(0,3) == 'arc')
			{			
				if (document.fullform.elements[e].checked == true) {found = 1}	
			}
		}

	}

	if (found == 0)
	{
		alert('You have not selected any quizzes to archive.');
		return false;
	}
	else
	{
		return true;
	}
}

function chkact()
{		
	var found = 0;
	var v;		
		
	for(e=0; e<document.fullform.elements.length; e++)
	{
		if (document.fullform.elements[e].type == 'checkbox')
		{
			v = document.fullform.elements[e].name;	
			
			if (v.substring(0,3) == 'act')
			{			
				if (document.fullform.elements[e].checked == true) {found = 1}	
			}
		}

	}

	if (found == 0)
	{
		alert('You have not selected any quizzes to transfer.');
		return false;
	}
	else
	{
		return true;
	}
}

// menu dropdowns

var menu=function(){
	var t=5,z=50,s=6,a;
	function dd(n){this.n=n; this.h=[]; this.c=[]}
	dd.prototype.init=function(p,c){
		a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0;
		for(i;i<l;i++){
			var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i];
			h.onmouseover=new Function(this.n+'.st('+i+',true)');
			h.onmouseout=new Function(this.n+'.st('+i+')');
		}
	}
	dd.prototype.st=function(x,f){
		var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0];
		clearInterval(c.t); c.style.overflow='hidden';
		if(f){
			p.className+=' '+a;
			if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0}
			if(c.mh==c.offsetHeight){c.style.overflow='visible'}
			else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)}
		}else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)}
	}
	function sl(c,f){
		var h=c.offsetHeight;
		if((h<=0&&f!=1)||(h>=c.mh&&f==1)){
			if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'}
			clearInterval(c.t); return
		}
		var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh;
		c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')';
		c.style.height=h+(d*f)+'px'
	}
	return{dd:dd}
}();
