/*
** Search script for PublicDomainReprints.org
** Copyright (C) 2008 by Yakov Shafranovich <code /at/ shaftek [dot] org>
**
** This code is copyrighted and may not be used without permission.
*/

function doSearch() {
    var $source = $('source').value;
    var $title = $('title').value;
    var $author = $('author').value;
    var $publisher = $('publisher').value;
    var $keywords = $('keywords').value;
    
    if($source == 'IA') {
	$base = 'http://www.archive.org/search.php';
	$url = 'query=';
	$url = $url + "mediatype:texts AND ";
	$url = $url + "possible-copyright-status:'NOT_IN_COPYRIGHT' ";
	if($title.length > 0) {
    	    $url = $url + " and title:'" + $title + "' ";
	}
	if($author.length > 0) {
        	$url = $url + " and creator:'" + $author + "' ";
	}
	if($publisher.length > 0) {
    	    $url = $url + " and publisher:'" + $publisher + "' ";
	}
	if($keywords.length > 0) {
    	    $url = $url + " and " + $keywords + " ";
	}
	pageTracker._trackPageview('/outgoing/search/archive.org' + '?' + $url);
	window.open($base + '?' + $url);
	//location.href = $base + '?' + $url;
    }
    
    if($source == 'GB') {
	$base = 'http://books.google.com/books';
	$url = 'as_brr=1&q=date:0-1923 ';
	
	if($title.length > 0) {
    	    $url = $url + " intitle:'" + $title + "' ";
	}
	if($author.length > 0) {
        	$url = $url + " inauthor:'" + $author + "' ";
	}
	if($publisher.length > 0) {
    	    $url = $url + " inpublisher:'" + $publisher + "' ";
	}
	if($keywords.length > 0) {
    	    $url = $url + " " + $keywords + " ";
	}
	pageTracker._trackPageview('/outgoing/search/books.google.com' + '?' + $url);
	window.open($base + '?' + $url);
	//location.href = $base + '?' + $url;
    }        
}
