// JavaScript Document

var i = 1;

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.min = (this.ns||this.ie)
}

function startError(theform){
	theform.errortype.disabled = true;
	document.getElementById('commentsdiv').style.display = "block";
	document.getElementById('submitdiv').style.display = "block";
	var errtype = theform.errortype[theform.errortype.selectedIndex].value;
	theform.typeoferror.value = errtype;

	if(errtype == 'comp'){
		document.getElementById('compmore').style.display = "block";
	}
	if(errtype == 'other'){
			addFormDiv(theform);
	}
}
function addFormDiv(theform){
	var x = i;
	i++;
	var errtype = theform.errortype[theform.errortype.selectedIndex].value;
	theform.typeoferror.value = errtype;

	is = new BrowserCheck();

	if(errtype == 'comp'){
		document.getElementById('compmore').style.display = "block";
		
		if(is.ns){
			var mini = document.createElement('SPAN');
		
			mini.innerHTML += "ISBN:<br/>";
			addField(mini, 'text', 'isbn1_' + x, '', 1, 1, "this,'up',1,this.form.isbn2_" + x, "this,'down',1");
			var tag = "isbn1_" + x;
			mini.innerHTML += "-";
			addField(mini, 'text', 'isbn2_' + x, '', 3, 3, "this,'up',3,this.form.isbn3_" + x, "this,'down',3");
			mini.innerHTML += "-";
			addField(mini, 'text', 'isbn3_' + x, '', 5, 5, "this,'up',5,this.form.isbn4_" + x, "this,'down',5");
			mini.innerHTML += "-";
			addField(mini, 'text', 'isbn4_' + x, '', 1, 1, "this,'up',1,this.form.info_" + x, "this,'down',1");
		
			mini.innerHTML += "<br/>Information:<br/>(Please include as much information as you can such as title, grade, edition, discipline, copyright year and printing code)<br/>";
			addTextarea(mini, 'info_' + x, '', 25, 5);
		
			mini.innerHTML += "<br/><hr/>";
		
			theform.sets.value = x;
			theform.appendChild(mini);
			}
			
	else if(is.ie){
			theform.sets.value = x;
		
			var dash = document.createTextNode("-");
			var dash1 = document.createTextNode("-");
			var dash2 = document.createTextNode("-");
			var infotext = document.createTextNode("Information:");
			var isbntext = document.createTextNode("ISBN:");
			var infotext2 = document.createTextNode("(Please include as much information as you can such as title, grade, edition, discipline, copyright year and printing code)");
			var br = document.createElement('BR');
			var br1 = document.createElement('BR');
			var br2 = document.createElement('BR');
			var br3 = document.createElement('BR');
			var hr = document.createElement('HR');
				
			theform.appendChild(isbntext);
			theform.appendChild(br);
	
			addField(theform, 'text', 'isbn1_' + x, '', 1, 1, "this,up,1,this.form.isbn2_" + x, "this,down,1");
			theform.appendChild(dash);
			addField(theform, 'text', 'isbn2_' + x, '', 3, 3, "this,up,3,this.form.isbn3_" + x, "this,down,3");
			theform.appendChild(dash1);
			addField(theform, 'text', 'isbn3_' + x, '', 5, 5, "this,up,5,this.form.isbn4_" + x, "this,down,5");
			theform.appendChild(dash2);
			addField(theform, 'text', 'isbn4_' + x, '', 1, 1, '','');
			theform.appendChild(br1);
			theform.appendChild(infotext);
			theform.appendChild(br2);
			theform.appendChild(infotext2);
			theform.appendChild(br3);
			addTextarea(theform, 'info_' + x, '', 25, 5);
			theform.appendChild(hr);
			}
		}
		else{
		document.getElementById('othermore').style.display = "block";

		if(is.ns){
			var mini = document.createElement('SPAN');
		
			mini.innerHTML += "Page Number: ";
			addField(mini, 'text', 'page_' + x, '', 5, 5, "", "");
			mini.innerHTML += "<br/>Error Information:<br/>";
			addTextarea(mini, 'info_' + x, '', 50, 5);
		
			mini.innerHTML += "<br/><hr/>";
		
			theform.sets.value = x;
			theform.appendChild(mini);
			}
			
	else if(is.ie){
			theform.sets.value = x;
		
			var infotext = document.createTextNode("Information:");
			var pagetext = document.createTextNode("Page Number: ");
			var br = document.createElement('BR');
			var br1 = document.createElement('BR');
			var br2 = document.createElement('BR');
			var hr = document.createElement('HR');
				
			theform.appendChild(pagetext);
			theform.appendChild(br);
	
			addField(theform, 'text', 'page_' + x, '', 5, 5, "", "");
			theform.appendChild(br);
			theform.appendChild(br1);
			theform.appendChild(infotext);
			theform.appendChild(br2);
			addTextarea(theform, 'info_' + x, '', 50, 5);

			theform.appendChild(hr);
			}

		}
}

function addField (form, fieldType, fieldName, fieldValue, fieldSize, fieldMax, onkeyu, onkeyd) {

var stru = "TabNext(" + onkeyu + ")";
var strd = "TabNext(" + onkeyd + ")";

  if (document.getElementById) {
    var input = document.createElement('INPUT');

      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
//		var up_array = onkeyu.split(",");
//		var dn_array = onkeyd.split(",");

        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
        input.size = fieldSize;
        input.maxLength = fieldMax;
//		input.onkeyup = function(){ TabNext(this, 'up', 1, eval('testf'));};
//		input.onkeydown = function(){ TabNext(this, 'down', 1);};
		}
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
        input.setAttribute('size', fieldSize);
        input.setAttribute('maxlength', fieldMax);
		input.setAttribute('onkeyup', stru);
		input.setAttribute('onkeydown', strd);
      }

	  
    form.appendChild(input);
	
}
}
function addTextarea (form, fieldName, fieldValue, fieldCols, fieldRows) {
  if (document.getElementById) {
    var input = document.createElement('TEXTAREA');
      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
        input.name = fieldName;
        input.value = fieldValue;
        input.cols = fieldCols;
        input.rows = fieldRows;
      }
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
        input.setAttribute('cols', fieldCols);
        input.setAttribute('rows', fieldRows);
      }
    form.appendChild(input);
  }
}

function getField (form, fieldName) {
  if (!document.all)
    return form[fieldName];
  else  // IE has a bug not adding dynamically created field 
        // as named properties so we loop through the elements array 
    for (var e = 0; e < form.elements.length; e++)
      if (form.elements[e].name == fieldName)
        return form.elements[e];
  return null;
}        
function removeField (form, fieldName) {
  var field = getField (form, fieldName);
  if (field && !field.length)
    field.parentNode.removeChild(field);
}
function toggleField (form, fieldName, value) {
  var field = getField (form, fieldName);
  if (field)
    removeField (form, fieldName);
  else
    addField (form, 'hidden', fieldName, value);
}

function submitForm(theform) {
	
	i = 1;

	if(theform.email){
		if(ValidateEmail(theform)){
		document.getElementById('newsearch').style.display = 'none'; 
		document.getElementById('newerror').style.display = 'none'; 
	
		var status = AjaxRequest.submit(
		theform
		,{
		  'onSuccess':function(req){
			 document.getElementById('newform').innerHTML = req.responseText;
			 document.getElementById('newform').style.display = 'block';
			 }
		}
	  );
	  return status;
			
		}
	}
	else{
		document.getElementById('newsearch').style.display = 'none'; 
		document.getElementById('newerror').style.display = 'none'; 
	
		var status = AjaxRequest.submit(
		theform
		,{
		  'onSuccess':function(req){
			 document.getElementById('newform').innerHTML = req.responseText;
			 document.getElementById('newform').style.display = 'block';
			 }
		}
	  );
	  return status;
	}
}

function submitAdminForm(theform) {
	
	var status = AjaxRequest.submit(
	theform
    ,{
		onSuccess: function(req) {
		 document.getElementById('obiadminmain').innerHTML = req.responseText;
        }
//		,
//        onError: function(req) {
//           alert(req.responseText);
//        }
    }
  );
	
  return status;
}

var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

function getMyHTML(serverPage, objID) {
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}

/*
function myOnKeyPress(evt) {
          if(evt.charCode == Sys.UI.Key.enter) {
             evt.preventDefault();
          }
       }
*/
function stopRKey(evt) {
   var evt = (evt) ? evt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

document.onkeypress = stopRKey; 
 
