// JavaScript Document: All site scripts


// POP-UP CONFIRMATION
function GP_popupConfirmMsg(msg) { //v1.0
  document.MM_returnValue = confirm(msg);
}


function menuWindow(newURL) {
		leftPos=0;
		topPos=0;
		if (screen){
			leftPos = screen.width/2-250;
		}
		if (screen){
			topPos = screen.height/2-340;
		}
		menu = window.open(
				newURL,
				'menuWin',
				'width=450,height=600,toolbar=no,left='+leftPos+',top='+topPos+',location=no,scrollbars=auto'
		);
		menu.focus();
}


function menuWindow400(newURL) {
		leftPos=0;
		topPos=0;
		if (screen){
			leftPos = screen.width/2-250;
		}
		if (screen){
			topPos = screen.height/2-340;
		}
		menu = window.open(
				newURL,
				'menuWin',
				'width=360,height=400,toolbar=no,left='+leftPos+',top='+topPos+',location=no,scrollbars=no'
		);
		menu.focus();
}


function menuWindow500(newURL) {
		leftPos=0;
		topPos=0;
		if (screen){
			leftPos = screen.width/2-475;
		}
		if (screen){
			topPos = screen.height/2-350;
		}
		menu = window.open(
				newURL,
				'menuWin',
				'width=360,height=500,toolbar=no,left='+leftPos+',top='+topPos+',location=no,scrollbars=no'
		);
		menu.focus();
}


function menuWindowSmall(newURL) {
		leftPos=0;
		topPos=0;
		if (screen){
			leftPos = screen.width/2-250;
		}
		if (screen){
			topPos = screen.height/2-340;
		}
		menu = window.open(
				newURL,
				'menuWin',
				'width=250px,height=50px,toolbar=no,left='+leftPos+',top='+topPos+',location=no,scrollbars=auto'
		);
		menu.focus();
}




// AUTOFILL SCRIPT

    // true = all select boxes; false = only select boxes with the attribute combo="combo"
var comboAll       = false;

    // true = typed value must exist in the drop-down on blur; false = any value accepted on blur.
var forceMatch     = true;

    // true = only allows values in the drop-down to be typed; false = any value accepted.
var forceAutoMatch = true;


        // INITIALIZE THE SCRIPT
window.onload      = initCbo;        
var f;

        // DROP DOWN LIST - PROFESSORS

function initCbo(){
 if(document.layers){return false}
 var output             = '';
 
 for(var f=0;f<document.forms.length;f++){
           var s = document.forms[f].elements;
           for(var i=0;i<s.length;i++){

   // for Professors combo-box
               if(s[i].type == 'select-one' && (s[i].combo=='comboProfessors' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '18px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxProfessors(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 291px; height: 18px; top:-5px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }

    // for Books combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboBooks' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '15px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxBooks(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 15px; top:-5px; width: 308px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }


    // for Query Professors-by-Book combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboQryProfessorsByBook' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '15px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setQryProfessorsByBook(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 15px; top:-5px; width: 308px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }


   // for Titles combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboTitles' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '14px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxOther(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 14px; top:-4px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }

   // for Universities combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboUniversities' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '14px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxOther(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 14px; top:-4px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }


   // for Departments combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboDepartments' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '14px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxOther(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 14px; top:-4px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }
			   
	// for BookRequests combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboBookRequests' || comboAll==true)){
                     output              = '';
                     s[i].style.height   = '14px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-18)+')';
                     s[i].onChange       = 'setTextBoxOther(this,this.form)';
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 0px; height: 14px; top:-4px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto); font-size:11px;" onKeyUp="autoComplete(this,this.form(\''+s[i].name+'\'),\'text\')" onNotInList="'+s[i].onNotInList+'">';
                     output              = '<span style="position:relative;">'+s[i].outerHTML+output+'</span>&nbsp;';
                     s[i].outerHTML      = output;
               }
  }
 }
}


         // PROFESSOR VALUE FOUND - PROCEED
function setTextBoxProfessors(list,f){
  var box    = f[list.name+"Box"]
  box.value  = list[list.selectedIndex].text;
  box.select();
  box.focus();
  
  ProfID     = list.options[list.selectedIndex].value;
  if(ProfID != "") {
       parent.mainFrame.location.href = "frBookAdoptionsMain.php?flag=1&Order=Dated%20DESC&id="+ProfID;
  }
}

         // BOOKS VALUE FOUND - PROCEED
function setTextBoxBooks(list,f){
  var box    = f[list.name+"Box"]
  box.value  = list[list.selectedIndex].text;
  box.select();
  box.focus();
  BooID     = list.options[list.selectedIndex].value;
  if(BooID != "") {
	  parent.frBookEditMain.location.href = "frBookEditMain.php?flag=&BookID="+BooID;
  }
}

         // IN QryProfessorsByBook BOOKS VALUE FOUND - PROCEED
function setQryProfessorsByBook(list,f){
  var box    = f[list.name+"Box"]
  box.value  = list[list.selectedIndex].text;
  box.select();
  box.focus();
  BooID     = list.options[list.selectedIndex].value;
  if(BooID != "") {
	  parent.frQryProfessorsByBookMain.location.href = "frQryProfessorsByBookMain.php?BookID="+BooID+"&Order=LastName";
  }
}


         // TITLES, DEPARTMENTS, UNIVERSITIES VALUE FOUND - PROCEED
function setTextBoxOther(list,f){
  var box    = f[list.name+"Box"]
  box.value  = list[list.selectedIndex].text;
  box.select();
  box.focus();
}


         // AUTO COMPLETE

function autoComplete (field, select, property) {
  var found   = false;
  for (var i=0;i<select.options.length;i++) {
    if(select.options[i][property].toUpperCase().indexOf(field.value.toUpperCase()) == 0) {
      found   = true;
	  break;
    }
  }
  if (found) {
	  select.selectedIndex = i;
  }

else { select.selectedIndex = -1; }
  if (field.createTextRange) {
    if (forceAutoMatch && !found) {
      field.value = field.value.substring(0,field.value.length-1); 
      return;
    }
    var cursorKeys ="8;46;37;38;39;40;33;34;35;36;45;";
    if (cursorKeys.indexOf(event.keyCode+";") == -1) {
      var r1 = field.createTextRange();
      var oldValue = r1.text;
      var newValue = found ? select.options[i][property] : oldValue;
      if (newValue != field.value) {
        field.value = newValue;
        var rNew = field.createTextRange();
        rNew.moveStart('character', oldValue.length) ;
        rNew.select();
      }
    }
  }
}

// END AUTOFILL



// DELETE PROFESSOR

function deleteProfessorMain(id_profMain) {
	      profIDMain = id_profMain;
          if (confirm('Are you sure you want to delete this entry?')) {
             document.location.href ='frBookAdoptionsMain.php?deleteProfessorID=' + profIDMain;
             parent.document.location.href = 'BookAdoptions.php';
		  }
}


// DELETE BOOKS

function deleteBook(id_book) {
	      booID = id_book;
          if (confirm('Are you sure you want to delete this entry?')) {
             document.location.href ='frBookEditMain.php?deleteBookID=' + booID;
             parent.window.location.href = 'winBookEdit.php';
		  }
}

