function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function changeChapter(ch, redir) {
        document.location.href='loader.php?chapter=' + ch + '&redirect='+ redir;
}
function openLink(url) {
			var popupWin2 = window.open(url,'lessonsample',"menubar=yes,width=800,height=600,scrollbars=yes,resizable=yes,left=15,top=10");
			popupWin2.focus();
}
function uploadFile() {
	var noError = true;
	var theform = document.fileupload;
	var len = theform.length;
	var theError = "";
  	for (var n = 0; n < len; n++) {
		if ((theform[n].type == "text") || (theform[n].type == "password") || (theform[n].type == "select-one"))
			theform[n].style.background = "white";
	}
	if (!hasValue(theform.title))
		noError = false;
	if (!noError) {
		if (theError)
			writeError(theError);
		else
			writeError("<img src='images/notice_small.gif' /> Please fill in all required fields.");
	}
	return noError;
}
function hasValue(theElement) {
	if (theElement.value == "") {
		theElement.style.background = "#ffcccc";
		return false;
	}
	return true;
}
function writeError(theError) {
	var id = "error";
	var x;
	if (document.getElementById) {
		x = document.getElementById(id);
		x.innerHTML = '';
		x.innerHTML = theError;
	}
	else if (document.all) {
		x = document.all[id];
		x.innerHTML = theError;
	}
}
function openWindow(url) {
        var popupWin2 = window.open(url,'extras',"width=800,height=600,scrollbars=no,resizable=no,left=15,top=10");
	popupWin2.focus();
}
function Hide(which){
   document.getElementById("p"+which).style.display = "inline";
   document.getElementById("m"+which).style.display = "none";
   document.getElementById("l"+which).style.display = "none";
};

function Show(which){
   document.getElementById("p"+which).style.display = "none";
   document.getElementById("m"+which).style.display = "inline";
   document.getElementById("l"+which).style.display = "block";
};

function newRegister() 
{
    var hasError = false;
    var theform = document.register;
    var len = theform.length;
    var theError = "";
    for (var n = 0; n < len; n++) {
        if ((theform[n].type == "text") || (theform[n].type == "password") || (theform[n].type == "select-one"))
            theform[n].style.background = "white";
    }
    if (!hasValue(theform.name))
        hasError = true;
    if (!hasValue(theform.job))
        hasError = true;
    if (!hasValue(theform.ssystem))
        hasError = true;
    if (!hasValue(theform.school))
        hasError = true;
    if (!hasValue(theform.address))
        hasError = true;
    /*if (!hasValue(theform.phone))
        hasError = true;
        if (!is_valid_phone(theform.phone)) 
        {
            hasError = true;
            theError = "<img src='images/notice_small.gif' /> Please fill out your complete phone number, including any area codes.";
        }*/
        if (!hasValue(theform.email))
            hasError = true;
        if (!is_valid_email(theform.email)) 
        {
            hasError = true;
            theError = "<img src='images/notice_small.gif' /> Please enter a valid e-mail address.";
        }
    /*if (!hasValue(theform.username))
        hasError = true;
    if (!hasValue(theform.password))
        hasError = true;
    if (!hasValue(theform.cpassword))
        hasError = true;
    
    if (theform.referrer.value == 0) 
    {
        theform.referrer.style.background = "#ffcccc";
        hasError = true;
    }
    
    if ( theform.password.value != theform.cpassword.value )
    {
        theform.password.style.background = "#ffcccc";
        theform.cpassword.style.background = "#ffcccc";
        theError = "<img src='images/notice_small.gif' /> The two passwords don't match.";
        hasError = true;
    }*/
    if (hasError) {
        if (theError)
            writeError(theError);
        else
            writeError("<img src='images/notice_small.gif' /> Please fill in all required fields.");
    }
    return !hasError;
}

function is_valid_email (target) 
{
        target.value = trim (target.value);
        var filter = RegExp("(^[a-z]([a-z0-9\-_\.]*)@([a-z0-9_\.]*)([.][a-z0-9_\]{3})$)|(^[a-z]([a-z0-9\-_\.]*)@([a-z0-9_\.]*)(\.[a-z0-9_\]{3})(\.[a-z]{2})*$)","i");
    if (filter.test(target.value))
                return true;
    target.style.background = "#ffcccc";
        return false;
}

function trim(strText) {
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}

function forgotLink() {
	if(document.getElementById('teacher').checked == true) {
	   //alert("Teacher Selected.");
		document.getElementById('studentNote').style.display = 'none';
		document.getElementById('forgotLink').style.display = 'inline';
		document.getElementById('teacherReg').style.display = 'block';
		
	} else {
		document.getElementById('studentNote').style.display = 'block';
		document.getElementById('forgotLink').style.display = 'none';
		document.getElementById('teacherReg').style.display = 'none';
		
	}
}  

