/*
 * 
 * /js/search-input.js
 *
 */
 
 // Check whether string s is empty.
 function isEmpty(s)
 { return ((s == null) || (s.length == 0)) }
 
 // Checks to see if the string is only whitespace.
 function isWhitespace(s)
 {
    var i;
    var whitespace = " \t\n\r";
 
    // Is s empty?
    if (isEmpty(s)) return true;
 
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
 
    for (i = 0; i < s.length; i++)
    {
      // Check that current character isn't whitespace.
      var c = s.charAt(i);
 
      if (whitespace.indexOf(c) == -1) return false;
    }
 
    // All characters are whitespace.
    return true;
 }

 function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/")+1, end);
 }

 function clearForm()
 {
    document.SearchForm.reset();
 } 

 function inputLoad() {
   
    var queryInput = document.SearchForm.elements['query-input'];
    
 	if (returnDocument() == 'index.html') {
	  var bgurl = 'url(images/search-form-bg.png) no-repeat left 0px';
	}
	else {
	  var bgurl = 'url(../images/search-form-bg.png) no-repeat left 0px';
	}
	 		
    if (!isWhitespace(queryInput.value)) {
 	  queryInput.style['background'] = bgurl;
    }
    else {
      queryInput.value = '';
 	  queryInput.style['background'] = bgurl;
    }
 }
 
 function inputFocus() {
 
    var queryInput = document.SearchForm.elements['query-input'];

 	if (returnDocument() == 'index.html') {
	  queryInput.style['background'] = 'url(images/search-form-bg.png) no-repeat left 0px';
	}
	else {
	  queryInput.style['background'] = 'url(../images/search-form-bg.png) no-repeat left 0px';
	}
	
 }
 
 
 function inputBlur() {
    var queryInput = document.SearchForm.elements['query-input'];
	 		
    if (!isWhitespace(queryInput.value)) {
	  if (returnDocument() == 'index.html') {
	    queryInput.style['background'] = 'url(images/search-form-bg.png) no-repeat left 0px';
	  }
	  else {
	    queryInput.style['background'] = 'url(../images/search-form-bg.png) no-repeat left 0px';
	  }    
    }
    else {
      queryInput.value = '';
	  if (returnDocument() == 'index.html') {
	    queryInput.style['background'] = 'url(images/search-form-bg-noinput.png) no-repeat left 0px';
	  }
	  else {
	    queryInput.style['background'] = 'url(../images/search-form-bg-noinput.png) no-repeat left 0px';
	  }    
    }
 }
	  
 function inputVerify() {
    var queryInput = document.SearchForm.elements['query-input'];
 
    if (!isWhitespace(queryInput.value)) {
 	  return true;
    }
    else {
      return false;
    }
 }
	  
	  
