<!--

var domains;
				
// Valid Domains 
domains = /(.com|.net|.org|.edu|.mil|.au|.ca|.uk|.info|.biz|.tv|.us|.cc|.ws|.bz|.vg|.gs|.tc|.ms)$/gi;

function openWindow(file, width, height) {
	var left;
	var top;
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	window.open(file, '', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', scrollbars=no');
}

function openScrollableWindow(file, width, height) {
	var left;
	var top;
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	window.open(file, '', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', scrollbars=yes');
}

function openResizableWindow(file, width, height) {
	var left;
	var top;
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	window.open(file, '', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', scrollbars=yes, resizable=yes');
}


function openToolbarWindow(file, width, height) {
	var left;
	var top;
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	window.open(file, '', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', menubar=yes, toolbar=yes, scrollbars=yes');
}

function openResizableToolbarWindow(file, width, height) {
	var left;
	var top;
	left = (screen.availWidth - width) / 2;
	top = (screen.availHeight - height) / 2;
	window.open(file, '', 'top=' + top + ', left=' + left + ', width=' + width + ', height=' + height + ', resizable=yes, menubar=yes, toolbar=yes, scrollbars=yes');
}

function trim(text) {
  	text = text.replace(/^\s*/, '');
  	text = text.replace(/\s*$/, '');
  	return text;
}

function validateSearch() {	
	var value;

	// isbn, author, keyword, title 
	if (( trim(document.forms['Search'].isbn.value) == '' ) && ( trim(document.forms['Search'].author.value) == '' ) && ( trim(document.forms['Search'].keyword.value) == '' ) && ( trim(document.forms['Search'].title.value) == '' )) {	
		window.alert('Must enter criteria: We suggest isbn.');
		document.forms['Search'].isbn.focus();
		return false;
	}
	
	// isbn
	value = trim(document.forms['Search'].isbn.value).replace(/[\(\)\.\-\s]/g, '');
	if (( trim(document.forms['Search'].isbn.value) != '' )) {
	
		// /*
		if ( value.length < 10 ) {	
			window.alert('ISBN should be either 10 characters or 13 characters. Please separate multiple ISBNs with commas.');
			document.forms['Search'].isbn.focus();
			return false;
		}	
		// */

		/*
		// if ISBN does not start with '978', it must be 10 digits long
		if ((value.indexOf('978') != 0) && ( value.length != 10 )) {	
			window.alert('ISBN should be 10 characters.');
			document.forms['Search'].isbn.focus();
			return false;
		}

		// if ISBN starts with '978', it must be either 10 digits or 13 digits long
		if ((value.indexOf('978') == 0) && ( value.length != 10 ) && (value.length != 13 )) {	
			window.alert('ISBN should be either 10 characters or 13 characters.');
			document.forms['Search'].isbn.focus();
			return false;
		}
		*/		
		
	}	
	
	// keyword
	value = trim(document.forms['Search'].keyword.value).replace(/^(a\s|an\s|and\s|the\s)|(\sa(?=\s))|(\san(?=\s))|(\sand(?=\s))|(\sthe(?=\s))|(\sa|\san|\sand|\sthe)$/gi, '');
	if (( trim(document.forms['Search'].isbn.value) == '' ) && ( trim(document.forms['Search'].keyword.value) != '' ) && ( value.length < 3 )) {	
		window.alert('keyword should be at least 3 characters.');
		document.forms['Search'].keyword.focus();
		return false;
	}	
	
	// author
	if (( trim(document.forms['Search'].isbn.value) == '' ) && ( trim(document.forms['Search'].keyword.value) == '' ) && ( trim(document.forms['Search'].author.value) != '' ) && ( trim(document.forms['Search'].author.value).length < 2 )) {	
		window.alert(' should be at least 2 characters.');
		document.forms['Search'].author.focus();
		return false;
	}
	
	// title
	if (( trim(document.forms['Search'].isbn.value) == '' ) && ( trim(document.forms['Search'].keyword.value) == '' ) && ( trim(document.forms['Search'].author.value) == '' ) && ( trim(document.forms['Search'].title.value) != '' ) && ( trim(document.forms['Search'].title.value).length < 6 )) {	
		window.alert('ATKey should be at least 6 characters.');
		document.forms['Search'].title.focus();
		return false;
	}
	
	// Strip Characters
	document.forms['Search'].isbn.value = trim(document.forms['Search'].isbn.value).replace(/[\(\)\.\-\s]/g, '');
	document.forms['Search'].keyword.value = trim(document.forms['Search'].keyword.value).replace(/^(a\s|an\s|and\s|the\s)|(\sa(?=\s))|(\san(?=\s))|(\sand(?=\s))|(\sthe(?=\s))|(\sa|\san|\sand|\sthe)$/gi, '');
	
}	

function validate_qty(qty, name){

 if ( !IsNumeric(document.getElementById(name).value) && document.getElementById(name).value != ''){
 	window.alert('Please enter a vaild number.' );
 	document.getElementById(name).value = 0;
 	document.getElementById(name).focus(); 	 	
 }	

 if	( document.getElementById(name).value > qty ){
 	window.alert('Please enter '+ qty + ' or less.' );
 	document.getElementById(name).value = 0;
 	document.getElementById(name).focus(); 	
 }
 
}

function validate_qtyBB(curr, New,Used,qty){

 if ( !IsNumeric(document.getElementById(curr).value) && document.getElementById(curr).value != ''){
 	window.alert('Please enter a vaild number.' );
 	document.getElementById(curr).value = 0;
 	document.getElementById(curr).focus(); 	 	
 }	
 var total = parseInt(document.getElementById(New).value) + parseInt(document.getElementById(Used).value);
 
 if	( total > qty && document.getElementById(New).value != null && document.getElementById(Used).value != null ){
 	window.alert('The combined quantity of New and Used should not exceed '+ qty + '.' );
 	document.getElementById(curr).value = 0;
 	document.getElementById(curr).focus(); 	
 }
 
}

function validateMultiISBN() {	
	var value;

	// isbn
	if (( trim(document.forms['Search'].isbn.value) == '' )) {	
		window.alert('Must enter at least one ISBN.');
		document.forms['Search'].isbn.focus();
		return false;
	}
	
}

function validateSearchText() {	

	var value;
	
	// author, keyword, title 
	if (( trim(document.forms['Search2'].author.value) == '' ) && ( trim(document.forms['Search2'].keyword.value) == '' ) && ( trim(document.forms['Search2'].title.value) == '' )) {	
		window.alert('Please enter criteria into one of the fields.');
		document.forms['Search2'].author.focus();
		return false;
	}
	
	value = trim(document.forms['Search2'].keyword.value).replace(/^(a\s|an\s|and\s|the\s)|(\sa(?=\s))|(\san(?=\s))|(\sand(?=\s))|(\sthe(?=\s))|(\sa|\san|\sand|\sthe)$/gi, '');
	if (( trim(document.forms['Search2'].keyword.value) != '' ) && ( value.length < 3 )) {	
		window.alert('keyword should be at least 3 characters.');
		document.forms['Search2'].keyword.focus();
		return false;
	}	
	
	// author
	if (( trim(document.forms['Search2'].keyword.value) == '' ) && ( trim(document.forms['Search2'].author.value) != '' ) && ( trim(document.forms['Search2'].author.value).length < 2 )) {	
		window.alert(' should be at least 2 characters.');
		document.forms['Search2'].author.focus();
		return false;
	}
	
	// title
	if (( trim(document.forms['Search2'].keyword.value) == '' ) && ( trim(document.forms['Search2'].author.value) == '' ) && ( trim(document.forms['Search2'].title.value) != '' ) && ( trim(document.forms['Search2'].title.value).length < 6 )) {	
		window.alert('ATKey should be at least 6 characters.');
		document.forms['Search2'].title.focus();
		return false;
	}
		
}

function submitSearch() {
	document.forms['Search'].submit();	
}


function isValidEmail(str) {

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr-1){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.lastIndexOf(dot)==lstr-1){
	    return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    return false
	 }
		
	 if (str.indexOf(" ")!=-1){
	    return false
	 }

	 return true					
}

function bodyOnload() {
	if (document.forms['Search'] && document.forms['Search'].isbn != undefined)
		document.forms['Search'].isbn.focus();
	else if (document.forms['Search2'] && document.forms['Search2'].isbn != undefined)
		document.forms['Search2'].isbn.focus();
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
}

///////////////////////////
//code for Google Analytics
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-370480-6']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
///////////////////////////


//-->
