function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

String.prototype.trim = trimString;

// transfer text from textfield to appropriate fields
// in main form.
function myhandler(f) {
   var s = f.pasted.value;
   var lines = s.split("\n");

   // some fields should be deleted
   document.mainform.subject.value = '';

   var heading = "";
   for (var i=0; i < lines.length; i++) {

     // split the line at the first ':'
     var k = lines[i].indexOf(':');

     var p0;
     var p1;

     if (k >= 0) {
       // if we found a ':', this line contains a heading and a value
       p0 = lines[i].substring(0,k);
       p1 = lines[i].substr(k+1);
     } else {
       // we did not find a ':'; this line is a continuation of previous line
       p0 = heading;
       p1 = lines[i];
     }
	 
     var pu = p0.toUpperCase();
     p1 = p1.trim();

     if ((k == -1) && (p1.length == 0)) {
       continue;
     }

     switch (pu) {
     case "LC CONTROL NO.":
     case "LCCN":
       document.mainform.lccn.value = p1;
       heading = "LCCN";
       break;
     case "PERSONAL NAME":
     case "AUTHOR":
       document.mainform.author.value = p1;
       heading = "AUTHOR";
       break;
     case "PUBLISHED/CREATED":
     case "PUBLISHER":
       document.mainform.publisher.value = p1;
       heading = "PUBLISHER";
       break;
     case "PUBLICATION DATE":
       document.mainform.publisher.value += ' ' + p1;
       break;
     case "MAIN TITLE":
     case "TITLE":
       //var pp = p1.split('/');
       //document.mainform.title.value = pp[0].trim();
       document.mainform.title.value = p1;
       heading = "TITLE";
       break;
     case "DESCRIPTION":
     case "PHYSICAL DESCRIPTION":
       document.mainform.description.value = p1;
       heading = "DESCRIPTION";
       break;
     case "ISBN":
       p1 = p1.substr(0,10);
       document.mainform.isbn.value = p1;
       heading = "ISBN";
       break;
     case "SUBJECTS":
       if (p1.length > 0) {
	 s = document.mainform.subject.value;
	 if (s.length > 0) {
	   s += ';';
	 }
	 s += p1;
	 document.mainform.subject.value = s;
       }
       heading = "SUBJECTS";
       break;
     case "EDITION INFORMATION":
     case "EDITION":
       document.mainform.edition.value = p1;
       heading = "EDITION";
       break;
     case "RELATED NAMES":
       document.mainform.author.value += ' , ' + p1;
       heading = "RELATED NAMES";
       break;
     case "VARIANT SERIES":
     case "SERIES":
       document.mainform.series.value = p1;
       heading = "SERIES";
       break;
     case "CONTENTS":
       document.mainform.contents.value = p1;
       heading = "CONTENTS";
       break;
     case "NOTES":
       if (p1.length > 0) {
	 s = document.mainform.notes.value;
	 if (s.length > 0) {
	   document.mainform.notes.value += ' ; ' + p1;
	 } else {
	   document.mainform.notes.value = p1;
	 }
       }
       heading = "NOTES";
       break;
     case "SUMMARY":
       if (p1.length > 0) {
	 s = document.mainform.notes.value;
	 if (s.length > 0) {
	   document.mainform.summary.value += ' ; ' + p1;
	 } else {
	   document.mainform.summary.value = p1;
	 }
       }
       heading = "SUMMARY";
       break;
     case "LC CLASSIFICATION":
     case "CALL NUMBER":
       document.mainform.callno.value = p1;
       //document.mainform.callvalid.checked = true;
       subject = false;
       break;
     default:
       heading = "";
       break;
     }
   }

   return false;
}

function xhandler(f)
{
   return false;
}	
