var loaded = false;
function trapint(e){
	key=(document.all) ? e.keyCode : e.which;
	if (key>46 && key<58){
		return true;
	}else{
		e.returnValue = false;
		return false;
	}
}
function trapfloat() {
	if (event.keyCode==13 || event.keyCode==8 || (event.keyCode>45 && event.keyCode<58)) {
		return true;
	} else {
		event.returnValue = false;
		return false;
	}
}

function Is() {
    var agent   = navigator.userAgent.toLowerCase();

    this.major  = parseInt(navigator.appVersion);
    this.minor  = parseFloat(navigator.appVersion);

    this.ns     = ((agent.indexOf('mozilla')   != -1) &&
                  (agent.indexOf('spoofer')    == -1) &&
                  (agent.indexOf('compatible') == -1) &&
                  (agent.indexOf('opera')      == -1) &&
                  (agent.indexOf('webtv')      == -1));
    this.ns2    = (this.ns && (this.major      ==  2));
    this.ns3    = (this.ns && (this.major      ==  3));
    this.ns4    = (this.ns && (this.major      ==  4));
    this.ns6    = (this.ns && (this.major      >=  5));
    this.ie     = (agent.indexOf("msie")       != -1);
    this.ie3    = (this.ie && (this.major      <   4));
    this.ie4    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 5.0")   == -1));
    this.ie5    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 5.0")   != -1));
    this.ie6    = (this.ie && (this.major      ==  4) &&
                  (agent.indexOf("msie 6.0")   != -1));
    this.ieX    = (this.ie && !this.ie3 && !this.ie4);
	this.opera  = (agent.indexOf('opera')      == 0)
}

var is = new Is();
function trapinteger(event) {
	if(is.ns4||is.ns6||is.opera) {
		if (event.which>47 && event.which<58 || event.which==8 || event.which==127 || event.which==0) {
			return true;
		} else {
			event.preventDefault();
		}
	}else{
		if (event.keyCode>47 && event.keyCode<58 || event.keyCode==8 || event.keyCode==127 || event.keyCode==0) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	}
}

function trapspace(event) {
	if(is.ns4||is.ns6||is.opera) {
		if (event.which!=32) {
			return true;
		} else {
			event.preventDefault();
		}
	}else{
		if (event.keyCode!=32) {
			return true;
		} else {
			event.returnValue = false;
			return false;
		}
	}
}

function launch(newURL, newName, newFeatures, orgName) {
	var PopWin = open(newURL, newName, newFeatures);
	if (PopWin.opener == null) // if something went wrong
		alert('Warning, a popup was blocked.  Please disable popup blocking for full functionality on this website.')
		PopWin.opener = window;
		PopWin.opener.name = orgName;
	return PopWin;
}

var ah = 480;
var aw = 640;

function launchPop(url,toolbar,resize,scroll,size,menubar,status) {
	if(is.ns4||is.ns6||is.opera) {
		available_width=innerWidth;
		available_height=innerHeight;
	} else if(is.ie4||is.ie5||is.ie6) {
		available_width=screen.width;
		available_height=screen.height;
	}
	if(size=='login') {
		ah = 320;
		aw = 400;
	} else if(size=='aim') {
		ah = 10;
		aw = 10;
	} else if(size=='calendar') {
		ah = 140;
		aw = 160;
	} else if(size=='landscape') {
		ah = 480;
		aw = 700;
	} else if(size=='help') {
		ah = 500;
		aw = 720;
	} else if(size=='portrait') {
		ah = 500;
		aw = 530;
	} else if(size=='printer') {
		ah = available_height;
		aw = 600;
	} else if(size=='full') {
		ah = available_height;
		aw = available_width;
	} else if(size=='zoom') {
		ah = 600;
		aw = 500;
	}else {
		ah = 500;
		aw = 600;
	}

	var popLeft = (available_width/2)-(aw/2);
	var popTop = 0;
	if(size=='aim'){
		var popLeft = 9999;
		var popTop = 0;
	}
	var str = "left="+popLeft+",screenX="+popLeft+",top="+popTop+",screenY="+popTop;

	if (!window.myPop || window.myPop.closed) {
		str += ",height=" + ah;
		str += ",innerHeight=" + ah;
		str += ",width=" + aw;
		str += ",innerWidth=" + aw;
		if(scroll){
			str += ",scrollbars=yes";
		}else if(!scroll){
			str += ",scrollbars=no";
		}
		if(status){
			str += ",status=yes";
		}else if(!status){
			str += ",status=no";
		}
		if(menubar){
			str += ",menubar=yes";
		}else if(!menubar){
			str += ",menubar=no";
		}
		if(toolbar){
			str += ",toolbar=yes";
		}else if(!toolbar){
			str += ",toolbar=no";
		}
		if(resize){
			str += ",resizable";
		}else if(!resize){
			str += ",resize=no";
		}
		myPop = open(url, "myPop", str);
		myPop.focus();
	} else {
		myPop.location.href = url;
		myPop.focus();
	}
}
function save_maybes(){
	opener.location.href='index.html?action=login&save_maybes=true';
	self.close();
}

function closer(){
	opener.focus();
	self.close();
}
function MakeArray(n) {
	this.length = n;
	for (var i = 1; i <= n; i++) {
		this[i] = 0;
	}
	return this;
}
function pickSelectedId(elId, elVal) {
	var el = window.opener.document.getElementById(elId);
	for (i = 0; i < el.options.length; i++) {
		if (elVal == el.options[i].value) {
			el.selectedIndex = i;
		}
	}
	window.opener.focus();
	self.close();
}
function pickSelected(form,formField,Index){
	var frm = window.opener.document.forms[form];
	var field = frm.elements[formField];
	field.selectedIndex = Index;
	window.opener.focus();
	self.close();
}
function qfRequireState(a,b,c) {
	var stateVal = b;
	stateObj = document.getElementById(c);
	if (stateObj.options.length < 2) {
		// selected country has no states
		return true;
	}
	if ('' == stateVal) {
		return false;
	}
	return true;
	
}
var loadedStates = new Array();
var stateObj;
var updateStateRunning = false;
function updateStates(stateId, countryId) {
	if (true == updateStateRunning) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',100);
		return;
	}
	if (false == window.loaded) {
		setTimeout('updateStates("'+stateId+'","'+countryId+'")',10);
		return;
	}
	updateStateRunning = true;
	countryObj = document.getElementById(countryId);
	var selectedCountry = countryObj.options[countryObj.selectedIndex].value;
	stateObj = countryObj.form[stateId];
	var numOpts = stateObj.options.length;
	if (numOpts) {
		stateObj.options[0].selected = true;
		stateObj.options[0].innerHTML = 'Loading...';
		for (var i = numOpts; i > 0; i--) {
			stateObj.options[i] = null;
		}
	}
	if (loadedStates[selectedCountry]) {
		setStateOptions(selectedCountry);
	} else {
		var stateScript = document.body.appendChild(document.createElement('iframe'));
		stateScript.setAttribute('height', 0);
		stateScript.setAttribute('width', 0);
		stateScript.setAttribute('src', '/jsrpc.html?action=loadStates&countryCode='+selectedCountry+'&stateId='+stateId);
		stateScript.setAttribute('id', 'loadStates'+selectedCountry);
	}
}
function setStateOptions(selectedCountry) {
	var opt;
	var selected;
	if (loadedStates[selectedCountry]) {
		eval('selected = '+stateObj.id+';');
		for (var key in loadedStates[selectedCountry]) {
			opt = document.createElement('option');
			opt.setAttribute('value', key);
			if (key == selected) {
				opt.setAttribute('selected', true);
			}
			opt.innerHTML = loadedStates[selectedCountry][key];
			stateObj.appendChild(opt);
		}
		stateObj.options[0].innerHTML = 'Select State Province';
	} else {
		stateObj.options[0].innerHTML = 'No Known States for '+selectedCountry;
	}
	updateStateRunning = false;
	return false;
}
function show_calendar(id,type,future,year,month,day){
	var value = document.getElementById(id).value;
	var values = value.split("-");

	url = "/calendar.html?y="+values[2]+"&m="+values[0]+"&d="+values[1]+"&id="+id+"&type="+type+"&future="+future+"&year="+year+"&month="+month+"&day="+day;

	size = 240;
	win = window.open(url, 'calendar', 'height='+size+',width='+size+',status=no,location=no');
	win.moveTo((screen.width-size)/2, (screen.height-size)/2);
	return win;
}

function setDays(form) {

  var y = form.year.options[form.year.selectedIndex].value;
  var m = form.month.selectedIndex;
  var d;
  if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
    days = 30;
  }
  else if (m == 1) {
	if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
      days = 29
    else
      days = 28
  }
  else {
    days = 31;
  }

  if (days > form.day.length) {
    for (i = form.day.length; i < days; i++) {
      form.day.length = days;
      form.day.options[i].text = i + 1;
      form.day.options[i].value = i + 1;
    }
  }
  
  if (days < form.day.length) {
    form.day.length = days;
    if (form.day.selectedIndex == -1) 
      form.day.selectedIndex = days - 1;
  }

}
function pickdate(id){
	var frm = self.opener.document.getElementById(id);
	var y = document.getElementById('qf_0_year').value;
	var m = document.getElementById('qf_0_month').value;
	var d = document.getElementById('qf_0_day').value;
	var mdy = m+'-'+d+'-'+y;
	frm.value = mdy;
	self.close();
	self.opener.focus();
}
function erase(p_item){
	frm = document.getElementById(p_item);
	frm.value='';
}
function strpos(haystack, needle) {
	nlen = needle.length;
	for (var i = 0; i < haystack.length; i++)
	if (haystack.substring(i, i+nlen) == needle) return i;
	return -1;
}
function checkEmail(element) {
	val = element.value;
	name = element.name;
	if (val.length) {
		fs = document.body.appendChild(document.createElement('iframe'));
		fs.setAttribute('height', 0);
		fs.setAttribute('width', 0);
		fs.setAttribute('src','/jsrpc.html?action=checkEmail&email='+val+'&element='+name);
		fs.setAttribute('id', 'checkEmail');
	}
}
function in_array(n, h) {
	for (var i=0; i<h.length; i++) {if (n == h[i]) {return true;}}return false;
}

	function photoPop(img_dir, photo, length, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/photograph.html?img_dir=" + img_dir + "&photo=" + photo + "&length=" + length;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 525;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) {popWindow.opener = self;}
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
	function screenPop(photo, pWidth, pHeight, scrollSet) {

		var popWindow = null;
		var photoPage = "/popup.html?action=screen_grab&photo=" + photo;

		if (!pWidth) {
			var pWidth = 550;
		}	
		
		if (!pHeight) {
			var pHeight = 520;
		}	

		if (!scrollSet) {
			var scrollSet = 0;
		}

			var displayString = "width=" + pWidth + ",height=" + pHeight + ",scrollbars=" + scrollSet +",resizable";   
			
    		popWindow = window.open(photoPage,'PopWindow',displayString);

				if (popWindow != null) {
					if (popWindow.opener == null) {popWindow.opener = self;}
					popWindow.opener.name = "popDaddy";
				} 		
		
	}
	
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function updAddrNm(a,b,c) {
	if ((aa = document.getElementById(a)) && (bb = document.getElementById(b)) && (cc = document.getElementById(c))) aa.value=bb.value+' '+cc.value;
}
function alternateRows(tab, cls1, cls2) {
	rows = tab.getElementsByTagName('tr');
	for (j=0; j<rows.length; j++) {
		if (j%2 == 0) {
			cls = cls1;
		} else {
			cls = cls2;
		}
		rows[j].setAttribute('class', cls);
	}
}	
function initPage() {
	if (bcn = document.getElementById('navLevel3')) {var hideNav3 = true;for (i=0; i<bcn.childNodes.length; i++) {if (bcn.childNodes[i].childNodes.length > 0) {hideNav3 = false;}}if (hideNav3) {bcn.style.display = 'none';}}if (hrarh = document.getElementById('hrAboveResultsHeader')) {if (sechdr = document.getElementById('sectionHeader')) {if (sechdr.childNodes.length < 2 && !hideNav3) {hrarh.style.display = 'none';}}}
	dbEnt = getElementsByClass('dbEntity');
	for (i=0; i<dbEnt.length; i++) {
		alternateRows(dbEnt[i], 'alt', '');
	}
	window.loaded=true;
}
function getElementsByClass(className) {
	var out = new Array();
	allElements = document.getElementsByTagName('*');
	j = 0;
	for (i=0; i<allElements.length; i++) {
		if (className == allElements[i].className) {
			out[j++] = allElements[i];
		}
	}
	return out;
}

//***************************************************** code for ajax

var http = getHTTPObject(); // We create the HTTP Object

var keyStr = "ABCDEFGHIJKLMNOP" +
                "QRSTUVWXYZabcdef" +
                "ghijklmnopqrstuv" +
                "wxyz0123456789+/" +
                "=";

function decode64(input) {
      var output = "";
      var chr1, chr2, chr3 = "";
      var enc1, enc2, enc3, enc4 = "";
      var i = 0;

      input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

      do {
         enc1 = keyStr.indexOf(input.charAt(i++));
         enc2 = keyStr.indexOf(input.charAt(i++));
         enc3 = keyStr.indexOf(input.charAt(i++));
         enc4 = keyStr.indexOf(input.charAt(i++));

         chr1 = (enc1 << 2) | (enc2 >> 4);
         chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
         chr3 = ((enc3 & 3) << 6) | enc4;

         output = output + String.fromCharCode(chr1);

         if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
         }
         if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
         }

         chr1 = chr2 = chr3 = "";
         enc1 = enc2 = enc3 = enc4 = "";

      } while (i < input.length);

      return output;
}

//AJAX Generating the field schools when the Faculty logs on
function updateText(url,udiv,tdiv,form,col,is_school){
		//document.getElementById(tdiv).style.visibility="visible";
        if(is_school){
            var cookie_date = new Date ( );  // current date & time
            cookie_date.setTime ( cookie_date.getTime() - 1 );
            document.cookie = "qf_0_coursepacks_school_id_=''; expires=" + cookie_date.toGMTString();
            document.cookie = "qf_0_school=''; expires=" + cookie_date.toGMTString();
            document.getElementById('qf_0_coursepacks_school_id_').value = '';
        }
        lnvisible(col,'true');
        var value = document.getElementById(udiv).value.toLowerCase();
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value;
        http.open("GET",getstr);
        http.onreadystatechange = handleHttpResponse;
        http.send(null);
}
function handleHttpResponse() {
if (http.readyState == 4)
	document.getElementById(updatediv).innerHTML = http.responseText;
else
	document.getElementById(updatediv).innerHTML = "<img src='/images/loading.gif' align='absmiddle'>";
}

//AJAX Generating the Dropdowns for the Student when School is selected
var http_updateTxts = new getHTTPObject();
function updateTexts(url,udiv,tdiv,form,col){
		//document.getElementById(tdiv).style.visibility="visible"; 
		lnvisible(col,'true');
        var value = document.getElementById(udiv).value.toLowerCase();
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value;
        http_updateTxts.open("GET",getstr);
        http_updateTxts.onreadystatechange = handleHttpResponsea;
        http_updateTxts.send(null);
}
function handleHttpResponsea() {
	if (http_updateTxts.readyState == 4) {
		document.getElementById('schoolSelectDIV').innerHTML = http_updateTxts.responseText;
		
		setdropdowninstructortonull= "<select id='instructor'><option value='0'></option></select>";
		document.getElementById('instructor_SelectDIV').innerHTML = setdropdowninstructortonull;
		setdropdowntermtonull= "<select id='term'><option value='0'></option></select>";
		document.getElementById('term_SelectDIV').innerHTML = setdropdowntermtonull;
		setdropdownyeartonull= "<select id='schoolyear'><option value='0'></option></select>";
		document.getElementById('schoolyear_SelectDIV').innerHTML = setdropdownyeartonull;
		setdropdownclassnametonull= "<select id='class_name_selection'><option value='0'></option></select>";
		document.getElementById('classname_SelectDIV').innerHTML = setdropdownclassnametonull;
    }
    else {
    	document.getElementById('schoolSelectDIV').innerHTML = "<img src='../images/loading.gif' align='absmiddle'>";
    }
}

//AJAX Generating the Faculty Instructor when School is selected
var http_instructor = new getHTTPObject();
function updateDropDownInstructor(url,udiv,udiv2,tdiv,form,col){
		lnvisible(col,'true');
        var value = udiv2;
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value;
	    http_instructor.open("GET",getstr);
        http_instructor.onreadystatechange = handleHttpResponsed;
        http_instructor.send(null);
}
function handleHttpResponsed() {
	if (http_instructor.readyState == 4) {
		document.getElementById('schoolSelectDIV').innerHTML = "";
        document.getElementById('instructor_SelectDIV').innerHTML = http_instructor.responseText;
		
		setdropdowntermtonull= "<select id='term'><option value='0'></option></select>";
		document.getElementById('term_SelectDIV').innerHTML = setdropdowntermtonull;
		setdropdownyeartonull= "<select id='schoolyear'><option value='0'></option></select>";
		document.getElementById('schoolyear_SelectDIV').innerHTML = setdropdownyeartonull;
		setdropdownclassnametonull= "<select id='class_name_selection'><option value='0'></option></select>";
		document.getElementById('classname_SelectDIV').innerHTML = setdropdownclassnametonull;
	}
	else {
    	document.getElementById('instructor_SelectDIV').innerHTML = document.getElementById('instructor_SelectDIV').innerHTML +  "<img src='../images/loading.gif' align='absmiddle'>";
    }
}
	
//AJAX Generating the Drop Down Term when School and Instructor are selected
var http_term = new getHTTPObject();
function updateDropDownTerm(url,udiv,udiv2,udiv3,udiv4,tdiv,form,col){
		//document.getElementById(tdiv).style.visibility="visible"; 
		lnvisible(col,'true');
        var value = udiv2;
        var value2=udiv4;
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value + '&' + udiv3+'='+value2;
	    http_term.open("GET",getstr);
        http_term.onreadystatechange = handleHttpResponsee;
        http_term.send(null);
}
function handleHttpResponsee() {
	if (http_term.readyState == 4) {
		document.getElementById('term_SelectDIV').innerHTML = http_term.responseText;
		setdropdownyeartonull= "<select id='schoolyear'><option value='0'></option></select>";
		document.getElementById('schoolyear_SelectDIV').innerHTML = setdropdownyeartonull;
		setdropdownclassnametonull= "<select id='class_name_selection'><option value='0'></option></select>";
		document.getElementById('classname_SelectDIV').innerHTML = setdropdownclassnametonull;
    }
    else {
    	document.getElementById('term_SelectDIV').innerHTML = document.getElementById('term_SelectDIV').innerHTML +  "<img src='../images/loading.gif' align='absmiddle'>";
    }
        
}
//AJAX Generating the Drop Down Year when School, Instructor and Term are selected
var http_year = new getHTTPObject();
function updateDropDownYear(url,udiv,udiv2,udiv3,udiv4,udiv5,udiv6,tdiv,form,col){
		//document.getElementById(tdiv).style.visibility="visible"; 
		lnvisible(col,'true');
        var value = udiv2;
        var value2=udiv4;
        var value4=udiv6;
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value + '&' + udiv3+'='+value2+ '&' + udiv5+'='+value4;
		http_year.open("GET",getstr);
        http_year.onreadystatechange = handleHttpResponsef;
        http_year.send(null);
}
function handleHttpResponsef() {
	 if (http_year.readyState == 4) {
        document.getElementById('schoolyear_SelectDIV').innerHTML = http_year.responseText;
        if ((document.getElementById('class_name_selection').value) == 0) {}
        else {
            setdropdownclassnametonull= "<select id='class_name_selection'><option value='0'></option></select>";
        	document.getElementById('classname_SelectDIV').innerHTML = setdropdownclassnametonull;
        }
    }
    else {
    	document.getElementById('schoolyear_SelectDIV').innerHTML = document.getElementById('schoolyear_SelectDIV').innerHTML +  "<img src='../images/loading.gif' align='absmiddle'>";
    }
    
}
//AJAX Generating the Drop Down Class Name when School, Instructor,Term, Year are selected
var http_class = new getHTTPObject();
function updateDropDownCName(url,udiv,udiv2,udiv3,udiv4,udiv5,udiv6,udiv7,udiv8,tdiv,form,col){
	    var value = udiv2;
        var value2=udiv4;
        var value4=udiv6;
        var value6=udiv8;
        camp = udiv;
        updatediv = tdiv;
        updateurl = url;
        var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value + '&' + udiv3+'='+value2+ '&' + udiv5+'='+value4 + '&' + udiv7+'='+value6;
		http_class.open("GET",getstr);
        http_class.onreadystatechange = handleHttpResponsec;
        http_class.send(null);
}
function handleHttpResponsec() {
	if (http_class.readyState == 4) {
        document.getElementById('classname_SelectDIV').innerHTML = http_class.responseText;
    }
    else {
    	document.getElementById('classname_SelectDIV').innerHTML = document.getElementById('classname_SelectDIV').innerHTML +  "<img src='../images/loading.gif' align='absmiddle'>";
    }
}

function updateWA2(url){
	document.getElementById('wa2').src=url;
}

function getHTTPObject() {
    var xmlhttp;
    /*@cc_on
    @if (@_jscript_version >= 5)
       try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
       } catch (e) {
          try {
             xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) { xmlhttp = false; }
       }
    @else
    xmlhttp = false;
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
       try {
          xmlhttp = new XMLHttpRequest();
       } catch (e) {xmlhttp = false;}
    }
    return xmlhttp;
}
//function if you log on as an instructor or faculty member
function copyfield(valor,valorid,fieldhidden,col){
	document.getElementById(camp).value = valor;
	document.getElementById(fieldhidden).value = valorid;
	lnvisible(col,'false');
    document.cookie = camp+'='+valor;
    document.cookie = fieldhidden+'='+valorid;
}

// functions if you log on as a student
//function copy values from the school to instructor
function copyfield1(valor,valorid,fieldhidden,col){
	document.getElementById(camp).value = valor;
	document.getElementById(fieldhidden).value = valorid;
	updateDropDownInstructor('/instructor.php','qf_0_school',valorid,'instructor_SelectDIV','',3)
}

//function copy values schook,instructor to generate term
function copyfieldHidden(valor,fieldhidden,valueschool){
	document.getElementById(fieldhidden).value = valor;
	updateDropDownTerm('/term_year.php','qf_0_instructor_id',valor,'qf_0_school',valueschool,'term_SelectDIV','',3)
}

//function copy values school,instructor,term to generate year
function copyfieldHiddenY(valor,fieldhidden,valueschool,valueterm){
	document.getElementById(fieldhidden).value = valueterm;
	updateDropDownYear('/year_class.php','qf_0_instructor_id',valor,'qf_0_school',valueschool,'qf_0_term_id',valueterm,'schoolyear_SelectDIV','',4)
}

//function copy values school,instructor,term,year to generate classname
function copyfieldHiddenCN(valor,fieldhidden,valueschool,valueterm,valueschoolyear){
	document.getElementById(fieldhidden).value = valueschoolyear;
	updateDropDownCName('/list.php','qf_0_instructor_id',valor,'qf_0_school',valueschool,'qf_0_term_id',valueterm,'qf_0_school_year_id',valueschoolyear,'classname_SelectDIV','',4)
	
}
// copy value of the coursepack id from list.php to retrieve it to confirm form
function copyfields(valorid,fieldhidden){
	document.getElementById(fieldhidden).value = valorid;
	
}
//end functions if you log on as a student

//if you log on as a faculty to display and hide fields
function lnvisible(num,value,ntop){
	if (ntop != null){
		for (var i=num;i<=ntop;i++){
		if (value == 'false')
			document.getElementById('tbl').getElementsByTagName('tr')[i].style.display="none";
		else
			document.getElementById('tbl').getElementsByTagName('tr')[i].style.display="";
		}
	}
	else
	{
		if (value == 'false')
			document.getElementById('tbl').getElementsByTagName('tr')[num].style.display="none";
		else
			document.getElementById('tbl').getElementsByTagName('tr')[num].style.display="";
	}
}

function lncolor(num,color){
var theCells = null;
theCells = tbl.getElementsByTagName('tr');
var rowCellsCnt = theCells.length;
for (c = 0; c < rowCellsCnt; c++) {
	theCells[c].setAttribute('bgcolor','#ffffff');}
document.getElementById('tbl').getElementsByTagName('tr')[num].setAttribute('bgcolor',color);
}

function loadPageParam(elemt,url,dspdiv){
var value = elemt.value;
var url_param = url + '&param='+value;

if (dspdiv == null) window.location.href=url_param;
else loadPageAjax(url_param,dspdiv)
}

function confirmPage(text){
if (confirm(text))return true
else return false;
}

function loadPageAjax(url,dspdiv){

    if(document.getElementById('drmserver') != null){
        url = url +'&drm=' + document.getElementById('drmserver').value;
    }
    
	updatediv = dspdiv;
	http.open("GET",url);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}


/* select a value from a select change*/
function optionSelect(aSelect, aElementId, aSchoolId) {
	copyfieldHidden(aSelect.options[aSelect.selectedIndex].value, aElementId, aSchoolId)
}
function optionSelectt(aInstructorId ,aElementId, aSchoolId,aSelect) {
	copyfieldHiddenY(aInstructorId, aElementId, aSchoolId, aSelect.options[aSelect.selectedIndex].value)
}
function optionSelecty(aInstructorId ,aElementId, aSchoolId,aTermId,aSelect) {
	copyfieldHiddenCN(aInstructorId, aElementId, aSchoolId,aTermId, aSelect.options[aSelect.selectedIndex].value)
}

function updateTexth(url,courspackid1,udiv,value,tdiv){
	    var courspackid=courspackid1;
	   	camp = udiv;
        updatediv = tdiv;
        updateurl = url;
		var getstr = '';
        var myRandom=parseInt(Math.random()*99999999);  // cache buster
        getstr = url + '?' + udiv+'='+value +'&courspackid='+courspackid;
        http.open("GET",getstr);
        http.onreadystatechange = handleHttpResponseh;
        http.send(null);
}
function handleHttpResponseh() {
if (http.readyState == 4)
	document.getElementById(updatediv).innerHTML = http.responseText;
else
	document.getElementById(updatediv).innerHTML = "<img src='/images/loading.gif' align='absmiddle'>";
}
function hide_display(div, hid, isOpen,courspackid){
	var allDivs = document.getElementsByTagName("DIV");
	//close divs
	for (var i = 0; i < allDivs.length; i++) {
		if (allDivs[i].name == "harvard_DIVX") { 
			allDivs[i].style.display="none";
		}
	}
	if (isOpen == div) {
		document.getElementById(div).style.display="none";	
		isOpen = "";
	}
	else {
		isOpen = div;
		document.getElementById(div).style.display="block";	
		var valueh=hid;
		updateTexth('/harvard_items.php',courspackid,'harvard_cases_id',valueh,div);
	}
	return isOpen;
}

function text_nroOrder(id,div){
	if(id == 'single_order'){
		document.getElementById(div).style.display='block'; 
	}
	else{
		document.getElementById(div).style.display='none'; 
	}
}

function text_nroOrderUser(id){
	if(id == 'single_order'){
		document.getElementById('Div_text').style.display='block';
        document.getElementById('Div_text2').style.display='none';
        document.getElementById('usertxt').value = '';
	}
	else if(id == 'usernametxt'){
        document.getElementById('Div_text').style.display='none';
		document.getElementById('Div_text2').style.display='block';
        document.getElementById('orderId').value = '';
	}
	else if(id == 'all_order'){
        document.getElementById('Div_text').style.display='none';
		document.getElementById('Div_text2').style.display='none';
        document.getElementById('orderId').value = '';
        document.getElementById('usertxt').value = '';
	}
	else if(id == 'select_report'){
        document.getElementById('Div_text').style.display='none';
		document.getElementById('Div_text2').style.display='none';
        document.getElementById('orderId').value = '';
        document.getElementById('usertxt').value = '';
	}
    return true;
}

function validateForm(qf_0){

    if(document.qf_0.school.value.length == 0){
        alert('School Name is required.');
        return false;
    }

    if(document.qf_0.instructor.value == 0){
        alert('Instructor Name is required.');
        return false;
    }

    if(document.qf_0.term.value == 0){
        alert('Term is required.');
        return false;
    }

    if(document.qf_0.schoolyear.value == 0){
        alert('School year is required.');
        return false;
    }

    if(document.qf_0.class_name_selection.value == 0){
        alert('Class Name - Number is required.');
        return false;
    }

    document.qf_0.submit();

}

function validateFormCoursePacks(){
    
    if(document.getElementById('qf_0_school').value.length == 0){
        alert('School Name is required.');
        return false;
    }

//    if(document.getElementById('qf_0_coursepacks_school_id_').value.length == 0){
//        alert('A Valid School Name is required.');
//        return false;
//    }
    if(document.getElementById('qf_0_instructor_name')){
        if(document.getElementById('qf_0_instructor_name').value.length == 0){
            alert('Instructor Name is required.');
            return false;
        }
    }
    if(document.getElementById('qf_0_coursepacks_user_id_')){
        if(document.getElementById('qf_0_coursepacks_user_id_').value.length == 0){
            alert('A Valid Instructor Name is required.');
            return false;
        }
    }

    if(document.getElementById('qf_0_coursepacks_class_name_').value.length == 0){
        alert('Class Name is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_class_number_').value.length == 0){
        alert('Class Number is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_term_id_').value == ''){
        alert('Term is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_school_year_id_').value == ''){
        alert('Year is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_expected_enrollement_').value.length == 0){
        alert('Expected Enrollment is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_desk_copies_').value.length == 0){
        alert('Desk Copies is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_first_day_').value.length == 0){
        alert('First Day is required.');
        return false;
    }

    if(document.getElementById('qf_0_coursepacks_last_day_').value.length == 0){
        alert('Last Day is required.');
        return false;
    }

    document.qf_0.submit();

}
//used on admin_info to show uploaded files
function toggle_it(itemID,num){ 
    // Toggle visibility between none and inline
    if (num==1){
        document.getElementById(itemID).style.display = 'block';
    } else {
        document.getElementById(itemID).style.display = 'none';
    }
}

function showArea(val,div){
    if(val){
        document.getElementById(div).style.display = 'block';
    }else{
        document.getElementById(div).style.display = 'none';
    }
}

/*esta funcion abre un popup para crear un reporte en csv*/
function runReport(){
    var displayProperties = "width= 200 , height=200, scrollbars=0,resizable=0, left=570, screenX=20 ,top=400,screenY=40";
    var statId = document.getElementById('statusOr').value;

    var lasDate = document.getElementById('dater').checked;
    var from = document.getElementById('date1').value;
    var to = document.getElementById('date2').value;
    if(lasDate){
        if(document.getElementById('date1').value.length == 0){
            alert('Range date is required.');
            return false;
        }

        if(document.getElementById('date2').value.length == 0){
            alert('Range date is required.');
            return false;
        }
    }

    window.open('/orderExpirationReport.php?status='+statId+'&whereDate='+lasDate+'&from='+from+'&to='+to, 'OrderReport', displayProperties);
}