
function openWindow(theURL, theName, width, height)
	{
		theWindow = window.open(theURL , ""+theName+"" ,"width=" + width + ",height="+ height + ",toolbar=no,directories=0,menubar=no,status=no,resizable=1,location=0,scrollbars=1,copyhistory=0,alwaysRaised=yes");
		theWindow.title = theName;
		theWindow.focus();
	}
	

function addOption(){
	// allows arguments to be string or select box
	//second argument if exists contains existing string for appending
	var strList = "";
	if (arguments[1])
		strList = arguments[1] + ' ';	
	if (arguments[0].options) {
		for (i=0;i<arguments[0].options.length;i++){
			if (arguments[0].options[i].selected){
				if (!String(strList).match(arguments[0] + ' '))
				strList = arguments[0].options[i].value + ' '
				}
		}
	}	
	else{
		if (!String(strList).match(arguments[0] + ' '))
		strList = arguments[0] + ' ';
	}
	var intLen = String(strList).length
	if (String(strList).substring(intLen,intLen-1)==' ')
		strList = String(strList).substring(0,intLen-1);
	return strList;
}

function PadDigits(n, totalDigits) 
{ 
    n = n.toString(); 
    var pd = ''; 
    if (totalDigits > n.length) 
    { 
        for (i=0; i < (totalDigits-n.length); i++) 
        { 
            pd += '0'; 
        } 
    } 
    return pd + n.toString(); 
} 

function CleanISBNs() {

	var x = document.forms[0].elements;
	var blob = '';
	// loop through everything and check it
	for (var i=0;i<x.length;i++)
	{
		var sreg = /identifier|isbn/ig;
		if (sreg.test(x[i].value)){
			var reg = /\-|\s+/g;
			x[i+1].value = x[i+1].value.replace(reg, '');
		}
		//blob += x[i].name + ' ' + x[i].value + "\n";
	}
	//alert(blob);	
}


function checkEnter(e){ 
	
	var characterCode = '';
	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	}
	else{
		e = event;
		characterCode = e.keyCode;
	}
	if(characterCode == 13){ 
		document.frmSearch.submit();
		return false;
	}
	else{
		return true;
	}
}

function hvalidate() {
	var x = document.forms[0].elements;
	var blob = '';
	// loop through everything and check it
	for (var i=0;i<x.length;i++)
	{
		var sreg = /identifier/ig;
		if (sreg.test(x[i].value)){
			var reg = /\-|\s+/g;
			x[i+1].value = x[i+1].value.replace(reg, '');
		}
		//blob += x[i].name + ' ' + x[i].value + "\n";
	}
	//alert(blob);	
}

function copy(text2copy) {
	alert("Copying the following text to the Clipboard:\n\n" + text2copy + "\n");
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="/gad/admin/include/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(flashcopier).innerHTML = divinfo;
  }
}

function GetISBNs(iTxt){
	
	var myhash = new Hash(); 
	var blob = "";
	var reg = /\-/g;
	iTxt = iTxt.replace(reg, "");
	
	var reg = /(\d{10}|\d{9}X)/ig;
	var parts = iTxt.match(reg, "$1");
	if(parts){
		for (var i=0; i<parts.length; i++)
		{
			if(parts[i].substring(0,3) != ('978'||'979') ){
				myhash.set(parts[i], '');  
			}
		}
	}

	var reg = /(978\d{10}|979\d{10})/ig;
	var parts = iTxt.match(reg, "$1");
	if(parts){
		for (var i=0; i<parts.length; i++)
		{
			myhash.set(parts[i], '');  
		}
	}
	
	myhash.each(function(item) {
    blob += item.key + '\n';
		//blob += item.value + '\n';
	});
	
	document.searchISBN.ISBNList.value = blob;
}

// Highlight text stuff..
var times = 0;
var regex = false;
var phrase = false;
var cases = false;
function hex( n ) { return ( n<16 ? '0' : '' ) + n.toString(16); }
function highlight( s, o ) {
  if( !s ) { return 0; }
  var d = document;
  if( !regex ) { s = s.replace( /([\\|^$()[\]{}.*+?])/g, '\\$1' ); }
  if( /^\s*$/.test(s) ) { return 0; }
  if( !phrase ) { s = s.split( /\s+/ ).join( '|' ); }
  o = [ o || d.documentElement || d.body ];
  var r = new RegExp( s, cases ? 'g' : 'gi' ),
    h = d.createElement('b'), i = 0, j, k, l, m, n=0, t;
  h.style.color = '#000';
  h.style.backgroundColor = '#ffcc00';

  times++;
  do {
    m = o[i];
    if( m.nodeType===3 ) {
      r.lastIndex = 0;
      l = r.exec(m.nodeValue);
      if( l !== null ) {
        k = l[0].length;
        if( r.lastIndex > k ) {
          m.splitText( r.lastIndex - k );
          m = m.nextSibling;
        }
        if( m.nodeValue.length > k ) {
          m.splitText(k);
          o[i++] = m.nextSibling;
        }
        t = h.cloneNode( true );
        t.appendChild( d.createTextNode( l[0] ) );n++;
        m.parentNode.replaceChild( t, m );
      }
    } else {
      j = m.childNodes.length;
      while (j) { o[i++] = m.childNodes.item(--j); }
    }
  } while(i--); return n;
}

function unhighlight( s, o ) {
 var d = document;
 o = o || d.documentElement || d.body;
 s = s.replace(/([\\|^$()[\]{}.*+?])/g, '\\$1');
 var a = o.getElementsByTagName('b'), i = a.length, j,
  re = new RegExp( '^' + s + '$', 'i' );
 while(i--) {
  j = a[i].firstChild;
  if( j ) {
   if( j.nodeType===3 && re.test( j.nodeValue ) ) {
    a[i].parentNode.replaceChild( document.createTextNode( j.nodeValue ), a[i] );
   }
  }
 }
 return false;
}

function ToggleThis(MyId){

	if(document.getElementById(MyId).style.display == 'none'){ 
		new Effect.BlindDown(MyId, {duration: 0.6});
	}else{
		new Effect.BlindUp(MyId, {duration: 0.1});
	}
}
