/**
 * @author: RB
 * @date: 23-10-2008
 * @version: 1.0
 * 
 * @fileoverview:
 * Contains functionality to display / hide the google custom search box background image on user click
 * including ASP.NET implementation
 * 
 */

(
function()  {
	
	// standard google custom search implementation using form
	var f = document.getElementById('cse-search-box'); 
	
	if (!f)  {
		f = document.getElementById('searchbox_demo');
	}
	
	if (f) {
	    var q = f.q;
	}
	else {
	    // ASP.NET implementation of google custom search
	    var g = document.getElementById('googletxtid');
    	
	    if (g) {
	        var q = document.getElementById(g.value);
	    }
	}
	
	if (q) {
		var n = navigator;
		var l = location;
		
		if (n.platform == 'Win32') {
			q.style.cssText = 'border: 1px solid #7e9db9; padding: 2px;';
		}
		
		var b = function() {
		
			if (q.value == '') {
				q.style.background = '#FFFFFF url(http:\x2F\x2Fwww.google.com\x2Fcoop\x2Fintl\x2Fen\x2Fimages\x2Fgoogle_custom_search_watermark.gif) left no-repeat';
			}
		};
		
		var f = function() {
			q.style.background = '#ffffff';
		};
		
		q.onfocus = f;
		q.onblur = b;
		
		if (!/[&?]q=[^&]/.test(l.search)) {
			b();
		}
		
		// ie back button fix
		var wo = function() {
		    if ((q.value == null) || (q.value == ''))
		    {
		        b();
		    }
		    else {
		        f();
		    }
		}
		
		if (window.attachEvent) {
			window.attachEvent('onload', wo);
		}
		else {
			window.addEventListener('load', wo, false);
		}
	}
})();