﻿/*
    http://dpcproject.com main javascript file.
    Put all js code here if possible.

*/

function mp_onload() {
    if (window.body_onload != null)
        window.body_onload();
}


function IsLoggedIn() {
    var cookieName = "LoggedIn";
    var theCookie = "" + document.cookie;
    var ix = theCookie.indexOf(cookieName);
    if (ix == -1 || cookieName == "") return "";
    else return theCookie;
}


function body_onload() {

    var isLoggedIn = false;
    // Get boolean to see if one is logged in.
    isLoggedIn = (IsLoggedIn() != "");

    if (isLoggedIn) {
        document.getElementById('nav-teacher-tools').className = 'nav-show';
    }
    
         
    // This turns on the class for the mouse over affect for the navs.
    if (location.pathname.search('Contact.aspx') > -1) {
        document.getElementById("nav-contact-list").setAttribute("class", "selected");
    }
    else if (location.pathname.search('Registration.aspx') > -1 || location.pathname.search('RegTrack.aspx') > -1)
        document.getElementById('nav-register-list').className = 'selected';
    else if (location.pathname.search('winners') > -1)
        document.getElementById('nav-winners-list').className = 'selected';
    else if (location.pathname.search('Resources.aspx') > -1 || location.pathname.search('ResourceCenter.aspx') > -1 || location.pathname.search('StepByStep.aspx') > -1 || location.pathname.search('Faq.aspx') > -1) {
        document.getElementById('nav-resources-list').className = 'selected';
    }
    else if (isLoggedIn && location.pathname.search('TeacherAdmin.aspx') > -1) {
    // Check for cookie if yes then display TeacherTools nav.
        document.getElementById('nav-teacher-tools').className = 'selected';
    }
}

function CountChar(div, hf, max) {
    var hiddenfield = document.getElementById(hf);
    var textarea = document.getElementById(hiddenfield.value);
    var mydiv = document.getElementById(div);

    if (textarea.value.length > max) {
        textarea.value = textarea.value.substring(0, max);
        return false;
    }
    
    mydiv.innerHTML = max - textarea.value.length + ' characters remaining';
    
}


/**
 * DHTML textbox character counter script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)


maxL=1400;
var bName = navigator.appName;
function taLimit(taObj) {
	if (taObj.value.length==maxL) return false;
	return true;
}

function taCount(taObj,Cnt) { 
	objCnt=createObject(Cnt);
	objVal=taObj.value;
	if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
	if (objCnt) {
		if(bName == "Netscape"){	
			objCnt.textContent=maxL-objVal.length;}
		else{objCnt.innerText=maxL-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 imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length < MaxLen+1);
}

 */
