// JavaScript Document: All site scripts

	// CALENDAR

		dayName = new Array ("SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY");
		monName = new Array ("JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER");
		now     = new Date;

        function calendar() {
           document.write("<NOBR>" + dayName[now.getDay()] +  ", " + monName[now.getMonth()] +  " " + now.getDate() + ", " + now.getFullYear() + "</NOBR>")
		}
	// end CALENDAR

function focusLogIn() {
    document.frmLogin.user_name.focus();
}











// ROLL-OVER BUTTONS

   // preload images
   
butHome_on = new Image ( );
butHome_off = new Image ( );
butHome_on.src = "../multimedia/images/butHome_on.jpg";
butHome_off.src = "../multimedia/images/butHome_off.jpg";

butCatalog_on = new Image ( );
butCatalog_off = new Image ( );
butCatalog_on.src = "../multimedia/images/butCatalog_on.jpg";
butCatalog_off.src = "../multimedia/images/butCatalog_off.jpg";

butContact_on = new Image ( );
butContact_off = new Image ( );
butContact_on.src = "../multimedia/images/butContact_on.jpg";
butContact_off.src = "../multimedia/images/butContact_off.jpg";

butRegister_on = new Image ( );
butRegister_off = new Image ( );
butRegister_on.src = "../multimedia/images/butRegister_on.jpg";
butRegister_off.src = "../multimedia/images/butRegister_off.jpg";

butLogIn_on = new Image ( );
butLogIn_off = new Image ( );
butLogIn_on.src = "../multimedia/images/butLogIn_on.jpg";
butLogIn_off.src = "../multimedia/images/butLogIn_off.jpg";


   // function

function button_on ( imgId )
{
  if ( document.images )
  {
    butOn = eval ( imgId + "_on.src" );
    document.getElementById(imgId).src = butOn;
  }
}

function button_off ( imgId )
{
  if ( document.images )
  {
    butOff = eval ( imgId + "_off.src" );
    document.getElementById(imgId).src = butOff;
  }
}

// end ROLL-OVER BUTTONS


// POP-UP WINDOWS SMALL


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=600px,height=400px,toolbar=no,left='+leftPos+',top='+topPos+',location=no,scrollbars=auto'
		);
		menu.focus();
}

// end POP-UP WINDOW SMALL



function promptDelete() {
	GP_popupConfirmMsg("Do you want to delete this record?");
	return document.MM_returnValue;
}








// RANDOM IMAGE ON THE HOME PAGE

function rotate() {
	if (document.images) {
		if (firstTime){
			thisAd = Math.floor((Math.random() * imgCt));
				firstTime = false;
		}
		else {
			thisAd++;
			if (thisAd == imgCt) {
					thisAd = 0;
			}
		}
		
		document.myPicture.src = adImages[thisAd];
	}
}

// end RANDOM




// PRELOADING MAIN IMAGES to fix

var image1 = new Image();
image1.src = "moveup.gif";
var image2 = new Image();
image2.src = "movedown.gif";
var image3 = new Image();
image3.src = "an1.gif";
var image4 = new Image();
image4.src = "an2.gif";



	// GALLERY SLIDE SHOW

function chgSlide(direction) {
	if(document.images) {
		thisPic = thisPic + direction;
		if (thisPic > imgCt) {
			thisPic = 0;
		}
		if (thisPic < 0) {
			thisPic = imgCt;
		}
		document.showPic.src = slideShow [thisPic];
		
	}

}
	// end GALLERY



// DROP-DOWN LIST FOR VENDORS
	
		function otherVendors(list){
  				companyID     = list.options[list.selectedIndex].value;
				
    			if (companyID != "") {
       				window.location.href = "cat_vendor_Collections.php?id_company=" + companyID;
    			}
  		}
		
	//end DROP-DOWN
	
	// DROP-DOWN LIST FOR VENDOR-COLLECTIONS
	
		function vendorCollections(list){
  				collectionID     = list.options[list.selectedIndex].value;
				companyID        = document.companyIDForm.companyIDField.value;
				
    			if (collectionID != "") {
       			    window.location.href = "cat_vendor_CollectionSubcollections.php?id_collection="+collectionID + "&id_company=" + companyID;
    			}
  		}
		
	//end DROP-DOWN


   // DROP-DOWN LIST FOR VENDOR-COLLECTION-CATEGORY-SUBCATEGORIES
	
		function vendorCollectionCategorySubcategories(list){
  				categoryID     = list.options[list.selectedIndex].value;
				companyID      = document.companyCollectionIDForm.companyIDField.value;
				collectionID   = document.companyCollectionIDForm.collectionIDField.value;
				
				if (categoryID != "") {
       			    window.location.href = "cat_vendor_CollectionCategorySubcategories.php?id_category=" + categoryID + "&id_company=" + companyID + "&id_collection=" + collectionID;
    			}
  		}
		
	//end DROP-DOWN

    // DROP-DOWN LIST FOR VENDOR-COLLECTION-CATEGORY-SUBCATEGORIES
	
		function vendorCollectionCategorySubcategoryItems(list){
  				subcategoryID  = list.options[list.selectedIndex].value;
				companyID      = document.companyCollectionCategoryIDForm.companyIDField.value;
				collectionID   = document.companyCollectionCategoryIDForm.collectionIDField.value;
				categoryID     = document.companyCollectionCategoryIDForm.categoryIDField.value;
				if (subcategoryID != "") {
       			    window.location.href = "cat_vendor_CollectionCategorySubcategoryItems.php?id_category=" + categoryID + "&id_company=" + companyID + "&id_collection=" + collectionID  + "&id_subcategory=" + subcategoryID;
    			}
  		}
		
	//end DROP-DOWN

    // DROP-DOWN LIST FOR CATEGORIES
	
		function Categories(list){
  				categoryID  = list.options[list.selectedIndex].value;
				if (categoryID != "") {
       			    window.location.href = "cat_CategorySubcategories.php?id_category=" + categoryID;
    			}
  		}
		
	//end DROP-DOWN


    // DROP-DOWN LIST FOR SUBCATEGORIES
	
		function CategorySubcategories(list){
  				subcategoryID  = list.options[list.selectedIndex].value;
				categoryID     = document.categoryIDForm.categoryIDField.value;
				if (subcategoryID != "") {
       			    window.location.href = "cat_CategorySubcategoryItems.php?id_category=" + categoryID + "&id_subcategory=" + subcategoryID;
    			}
  		}
		
	//end DROP-DOWN











	// ITEM POP-UP

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

    // end ITEM POP-UP


























    // DROP-DOWN LIST FOR VENDOR-COLLECTION-SUBCOLLECTIONS
	
		function vendorCollectionSubcollectionCategories(list){
  				collectionID  = list.options[list.selectedIndex].value;
				companyID     = document.companyIDForm.companyIDField.value;
    			if (collectionID != "") {
       				window.location.href = "cat_vendor_CollectionSubcollectionCategories.php?id_collection=" + collectionID + "&id_company=" + companyID;
    			}
  		}
		
	//end DROP-DOWN













function jumpItemQuickList(list) {
itemID     = list.options[list.selectedIndex].value;
    if (itemID != "") {
       parent.mainFrame.location.href = "frItemQuickListMain.php?ItemNo="+itemID;
    }
}





// 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();
}






// 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   = '16px';
                     s[i].style.clip     = 'rect(auto,auto,auto,'+(s[i].clientWidth-19)+')';
                     // FOR onChange FUNCTION PLACED RIGHT IN THE FILE WITH THE FORM
                     output              +='<input type="text" name="'+s[i].name+'Box" value="'+s[i][s[i].selectedIndex].text+'" style="position: absolute; left: 291px; height: 16px; top:-5px; width: 210px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-19)+',auto,auto);" 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);" 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);" 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, Universities and Departments combo-box
               else if(s[i].type == 'select-one' && (s[i].combo=='comboOther' || 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:183px; z-index: 2; clip:rect(auto,'+(s[i].clientWidth-18)+',auto,auto);" 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);" 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;
               }
  }
 }
}


         // 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, UNIVERSITIES AND DEPARTMENTS VALUE FOUND - PROCEED
function setTextBoxOther(list,f){
	if (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?')) {
		     parent.document.location.href = 'BookAdoptions.php';
             document.location.href        = 'frBookAdoptionsMain.php?flag=1&id='+profIDMain+'&Order=Dated%20DESC&deleteProfessorID='+profIDMain;
		  }
  }


// 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';
		  }
}


