//ValetimeGroup JS code

// ~~~~~ ##### ~~~~~  Useful Functions   ~~~~~ ##### ~~~~~ //

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}



// ~~~~~ ##### ~~~~~  Header ~~~~~ ##### ~~~~~ //

// Text Resize functions
// ~~ pretty basic. Could do with limiting to context of CONTENT

function resizeText(multiplier) {   
  if (document.body.style.fontSize == "") {   
    document.body.style.fontSize = "1.0em";   
  }   
  document.body.style.fontSize = parseFloat(document.body.style.fontSize) + (multiplier * 0.2) + "em";   
}  


// ~~~~~ ##### ~~~~~  Content   ~~~~~ ##### ~~~~~ //

// Get favicon's for external links - Using this on favicon styled lists

function faviconizeFavilist() { 
  if (!document.getElementsByTagName) return false;
  if (!document.createElement) return false;
  var ul = document.getElementsByTagName("ul");
  for (var i=0; i<ul.length; i++) {
  	if (ul[i].className == "favilist") {
  		var links = ul[i].getElementsByTagName("a");
  		for (var j=0; j<links.length; j++) {
  			var hoststring = /^http:/;
  			var hrefvalue = links[j].getAttribute("href",2);
			if (hrefvalue.search(hoststring) != -1) {
				var domain = hrefvalue.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/);
				domain = RegExp.$2;
				var cue = document.createElement("img");
				cue.className = "faviconimg";
				var cuesrc = "http://"+domain+"/favicon.ico";
				cue.setAttribute("src",cuesrc);
				cue.onerror = function () {
					this.src = "/wp/wp-content/themes/vt_theme/images/icons/external.gif";
					}
				links[j].parentNode.insertBefore(cue,links[j]);
			}
		}
  	}
  }
 return false;
}
addLoadEvent(faviconizeFavilist);



// ~~~~~ ##### ~~~~~  Footer ~~~~~ ##### ~~~~~ //


//<![CDATA[

function onResultsReady() {
 var resultsHTML = new Array();
 var found = false;
 for (var i = 0; i < searcher.results.length; i++) {
  found = true;
  var thisResult = searcher.results[i];  
   resultsHTML.push( "<p>" );
   resultsHTML.push( "<a href='" );
   resultsHTML.push( thisResult.url );
   resultsHTML.push( "'>" );
   resultsHTML.push( thisResult.title );
   resultsHTML.push( "<\/a><br \/>" );
   resultsHTML.push( thisResult.content )
   resultsHTML.push( "<br \/>" );
   resultsHTML.push( "<span class='url'>" );
   resultsHTML.push( thisResult.url );
   resultsHTML.push( "<\/span>" );
   if (thisResult.cacheUrl) {
    resultsHTML.push( " - <a class='cached' href=\"" );
    resultsHTML.push( thisResult.cacheUrl );
    resultsHTML.push( "\">Cached<\/a>" );
   }
   resultsHTML.push( "<\/p>" );
  }
 if (!found) {
  resultsHTML.push("<p><b>No results were found.</b><br />Please try another search term or, use the quick link site map above.</p>");
 }         
 var panel = document.getElementById( "resultsPanel" );
 panel.innerHTML = resultsHTML.join( "" );
}              

function performQuery() {        
 var theForm = document.vtgsearch;
 var panel = document.getElementById( "searchResults" );
 //Slide the panel
 panel.style.display = "block";
 var panel = document.getElementById( "resultsPanel" );
 var img = "<img src='images/footer-loading.gif' width=16 height=16 alt='loading' />&nbsp;";
 panel.innerHTML = img + "Searching for '" + theForm.q.value + "'. Please wait...";		//alert(theForm.q.value);
 //Do the Search
 searcher.execute( theForm.q.value );
}

//Setup the Google Search

var searcher = new GwebSearch();
var options  = new GsearcherOptions();
searcher.setSiteRestriction("valetimegroup.com");
searcher.setUserDefinedLabel("valetimegroup.com");
searcher.setNoHtmlGeneration();
searcher.setSearchCompleteCallback( null, onResultsReady );


 //]]>


