<!--

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 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 trim(text) {
  	text = text.replace(/^\s*/, '');
  	text = text.replace(/\s*$/, '');
  	return text;
}

function validateSearch() {	
	var value;

	// isbn, author, keyword, title 
	if (( trim(document.forms[0].isbn.value) == '' ) && ( trim(document.forms[0].author.value) == '' ) && ( trim(document.forms[0].keyword.value) == '' ) && ( trim(document.forms[0].title.value) == '' )) {	
		window.alert('Must enter criteria: We suggest isbn.');
		document.forms[0].isbn.focus();
		return false;
	}
	
	// isbn
    value = trim(document.forms[0].isbn.value).replace(/[\(\)\.\-\s]/g, '');
    if (( trim(document.forms[0].isbn.value) != '' )) {
	
		if (( value.length != 10 ) && (value.length != 13 )) {	
	       	window.alert('ISBN should be either 10 characters or 13 characters.');
	       	document.forms[0].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[0].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[0].isbn.focus();
	       	return false;
        }
        */		
	}		

	// keyword
	value = trim(document.forms[0].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[0].isbn.value) == '' ) && ( trim(document.forms[0].keyword.value) != '' ) && ( value.length < 3 )) {	
		window.alert('keyword should be at least 3 characters.');
		document.forms[0].keyword.focus();
		return false;
	}	
	
	// author
	if (( trim(document.forms[0].isbn.value) == '' ) && ( trim(document.forms[0].keyword.value) == '' ) && ( trim(document.forms[0].author.value) != '' ) && ( trim(document.forms[0].author.value).length < 2 )) {	
		window.alert(' should be at least 2 characters.');
		document.forms[0].author.focus();
		return false;
	}
	
	// title
	if (( trim(document.forms[0].isbn.value) == '' ) && ( trim(document.forms[0].keyword.value) == '' ) && ( trim(document.forms[0].author.value) == '' ) && ( trim(document.forms[0].title.value) != '' ) && ( trim(document.forms[0].title.value).length < 4 )) {	
		window.alert('title should be at least 4 characters.');
		document.forms[0].title.focus();
		return false;
	}
	
	// Strip Characters
	document.forms[0].isbn.value = trim(document.forms[0].isbn.value).replace(/[\(\)\.\-\s]/g, '');
	document.forms[0].keyword.value = trim(document.forms[0].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 submitSearch() {
	document.forms[0].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					
}

//-->