 function Search() {
	// requires two global js variables: 
	// customSearchId - Custom Search engine ID or website url
	// siteSearch  - Search term

   var searchControl = new google.search.SearchControl();

  // Set the Search Control to get the most number of results
  searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
 

 // site restricted web search using a custom search engine
      siteSearch = new google.search.WebSearch();
      siteSearch.setSiteRestriction(customSearchId);
	  
      searchControl.addSearcher(siteSearch);

  // Set the options to draw the control in tabbed mode
  var drawOptions = new google.search.DrawOptions();
 drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);

  // Draw the control onto the page
  searchControl.draw(document.getElementById("searchResults"), drawOptions);

  // Search!
  searchControl.setNoResultsString("No results found for <strong>"+searchVar+"</strong>, please refine your search");

  searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF)
  searchControl.execute(searchVar);
      }



function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function HighlightMenu(){
	// current tab on navigation
	if ($(menuIdToHighlight)) {
		$(menuIdToHighlight).addClassName('currentPage');
	}
}



var PopUpWindow = Class.create();
PopUpWindow.prototype = {
 	initialize: function(id,url,features) {
		if($(id)){
		Event.observe(id, 'click', function(event) {
		var theWindow = window.open(url, '_blank', features);
    	Event.stop(event);
		theWindow.focus();
		});
	}
}}

var DropDownMenu = Class.create();
DropDownMenu.prototype = {
	// suckerfish menus:navigation,region selector
 	initialize: function(menuElement) {
	 	if($(menuElement)){
		 	$(menuElement).childElements().each(function(node){
			var submenu = $A(node.getElementsByTagName("ul")).first();
			node.onmouseover = function(){this.addClassName('sfhover');}		
			node.onmouseout = function(){this.removeClassName('sfhover')}
		});
	 }
}}

var SwfRegionSelector = Class.create();
SwfRegionSelector.prototype = {
	// sends js events to flash region selector
 initialize: function(id,swf_id) {
	var flashObject=$(swf_id);
                $$(id).each(function(element){
               		element.onmouseover=function(){flashObject.SetVariable("classNameOver", element.up().className)}
                    element.onmouseout=function(){flashObject.SetVariable("classNameOut", element.up().className)}
                    element.onclick=function(){pageTracker._trackEvent("Region Selector", "HTML" ,element.up().className)}
                });
}}

var OpenNewWindow = Class.create();
OpenNewWindow.prototype = {
	// opens links with "_blank" class in new window, target="_blank" is deprecated.
 	initialize: function(className) {
 		  $$(className).each(function(element){
          element.observe('click',function(event){element.writeAttribute("target", "_blank")});
	});
}}

var TrackDownloads = Class.create();
TrackDownloads.prototype = {
	
 	initialize: function(fileType,regex) {
	 	var filename;
		$$('a['+regex+']').each(function(element){
            element.observe('click',function(event){		
			filename=element.toString();
			pageTracker._trackEvent(fileType, filename.substring(filename.indexOf('\/')+1), document.location.pathname);
		});
	});
}}

var CookieUtil = Class.create();
CookieUtil.prototype = {
 	CreateFromURL:function(name,ids){
		var hash = getUrlVars();
		var c = new Object();
		var queryfound=false;
			ids.each(function(element){
				if(hash[element]){
					eval("c."+element+"='"+hash[element]+"'");	
					queryfound=true;
				}else{
					if(subcookiejar.fetch(name,element)){
					eval("c."+element+"='"+subcookiejar.fetch(name,element)+"'");
					}
				}
			});
			if(queryfound){
				CookieUtil.prototype.Bake(name,c);
			}
	
	},Bake:function(name,c){
		subcookiejar.bake (name, c, 230,"/");
	},PopulateFormField:function(name,h){
			var h = $H(h);
			h.each(function(pair){ 
				if($(pair.key)){
					if(subcookiejar.fetch(name,pair.value)){
						$(pair.key).value=subcookiejar.fetch(name,pair.value);
						}
				}
			});
	},PopulateLeadSources:function(name,id,delimeter){
		value=subcookiejar.fetch(name,id);
		if(value){
			myArray=value.split(delimeter); 
			if(myArray[0] && $("LeadSource")){
					$("LeadSource").value=myArray[0];
			}
			if(myArray[1] && $("LeadSourceVersion")){
					$("LeadSourceVersion").value=myArray[1];
			}
		}
	}
}

var AppendGoogleVars = Class.create();
AppendGoogleVars.prototype = {
	initialize: function(id) {
		if($(id)){
			var inputid=$(id)
			inputid.value=pageTracker._getLinkerUrl(inputid.value);
		}
	}
}

var SearchLinks = Class.create();
SearchLinks.prototype = {
initialize: function(name,branchid,url,notdotcomdomain) {
	// loop thru links and append campaign variables to eloqua/signup links
	//pageTracker._linkByPost
	//alert(pageTracker._linkByPost('http://www.newsite.com'));
	if(!url){
		url="mk.customhouse.com\/forms|customhouse.com\/signup";	
	}
	//alert(url);
	var cookie_ls= subcookiejar.fetch(name,'ls');
	var cookie_b= subcookiejar.fetch(name,'b');
	if(!cookie_b){cookie_b=branchid;}
	var cookie_elq= subcookiejar.fetch(name,'elq');

	$$('a').each(function(element){
		if(element.href.search(url)>0){
			// found  link
			// don't change email links
			// don't change email or 'jump to' links or links with query parameters
			if(element.href.indexOf('mailto')<=0 && element.href.indexOf('#')<=0 && element.href.indexOf('?')<=0){
				// ie bug store element text
				var tempHTML=element.innerHTML;
				element.writeAttribute("href", element.readAttribute("href")+SearchLinks.prototype.BuildLink({ 'ls': cookie_ls, 'b': cookie_b, 'elq': cookie_elq}));
			element.innerHTML=tempHTML;
				if(notdotcomdomain){
					//element.href=pageTracker._getLinkerUrl(element.href);
					//pageTracker._link(element.href)
					element.observe('click',function(event){
						pageTracker._link(element.href);
						Event.stop(event);
					});	
				}	
			}	
		}
	});
},BuildLink:function(h){
	query="";
	i=0;
	var h = $H(h);
	h.each(function (pair){
		if(!pair.value){
			h.unset(pair.key);
		}else{
			if(i==0){
				query+="?";
			}else{query+="&";}
		query+=pair.key+"="+pair.value;
		i++;
		}
	});
		return query;
	}
}

// forms
var TextAreaCounter = Class.create();
TextAreaCounter.prototype = {
 	initialize: function(fieldhint2,fieldhint,message) {

	$(fieldhint2).removeClassName("hide-div");

	maximumLength=$(fieldhint).innerHTML;
	Validation.addAllThese([
	['textbox-120', 'You have too many characters('+maximumLength+' Max)', function(v) {
				return  ((v == null) || (v.length <= maximumLength)); // || /^\s+$/.test(v));
			}]
			]);

		$(fieldhint).innerHTML=maximumLength-$(message).value.length;
		this.UpdateCounter(fieldhint,message);
		Event.observe($(message), 'keyup', function(){TextAreaCounter.prototype.UpdateCounter(fieldhint,message)});
},UpdateCounter: function(fieldhint,message){
			$(fieldhint).innerHTML=maximumLength-$(message).value.length;
			if(maximumLength-$(message).value.length<0){
				$(fieldhint).innerHTML=0;
			}
		}

}

// populates field based on query value
var PopulateSelectField = Class.create();
PopulateSelectField.prototype = {
initialize: function(element,query) {
	var hash = getUrlVars();
	$$(element).each(function(option){
		if(hash[query] && hash[query]==option.value){
			option.selected="selected";
		}
	});
}}

// populate field based on coded value
var PopulateSelectFieldElq = Class.create();
PopulateSelectFieldElq.prototype = {
	initialize: function(field,value) {
		field.each(function(option){
			if(option.value==value)
			{
				option.selected="selected";
			}
	});
}}



// prototype conversion ends


function addTransaction(name,category,sku){
	pageTracker._setLocalRemoteServerMode();

	// Some simple code to create a fake order ID
	var timeObj        = new Date;
	var unixTimeMs   = timeObj.getTime();
	var unixTime      = parseInt(unixTimeMs / 1000);
	var orderID        = pageTracker._visitCode() + '-' + unixTime;
	
	pageTracker._addTrans(
		  orderID, // required
		  "",
		  "",
		  "",
		  "",
		  "",
		  "",
		  ""
	); 
	
	pageTracker._addItem(
		  orderID, // required
		  sku, // product sku
		  name,// product name
		  category, // product category
		  "1",  // required
		  "1"   //required
	); 
	
	pageTracker._trackTrans();
	
}




/**
 * Cookies.js, providing easy access to cookies thru the cookiejar object. Enabling so-called "subcookies" thru the subcookiejar 
 * object.
 * See this related blogpost for more information on how to use these objects:
 * 	<http://www.whatstyle.net/articles/28/subcookies>
 * Check out this other blogpost for information about the new version:
 *  <http://www.whatstyle.net/articles/46/subcookies_v2>
 * 
 * @author Harmen Janssen <http://www.whatstyle.net>
 * @version 2.0
 * 
 */

/* based on http://www.quirksmode.org/js/cookies.html, by Peter-Paul Koch */
var cookiejar = {
	/* set a cookie */
	bake: function(cookieName,cookieValue,days,path) {
		var expires='';
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			expires = "; expires="+date.toGMTString();
		}
		var thePath = '; path=/';
		if (path) {
			thePath = '; path=' + path;
		}
		document.cookie = cookieName+'='+escape(cookieValue)+expires+thePath;
		return true;
	},
	/* get a cookie value */
	fetch: function(cookieName) {
		var nameEQ = cookieName + '=';
		var ca = document.cookie.split(';');
		for (var i=0; i<ca.length; i++)	{
			var c = ca[i];
			while (c.charAt(0) == ' ') {
				c = c.substring(1, c.length);
			}
			if (c.indexOf(nameEQ) == 0) {
				return unescape(c.substring(nameEQ.length, c.length));
			}
		}
		return null;
	},
	/* delete a cookie */
	crumble: function(cookieName) {
		return cookiejar.bake(cookieName,'',-1);
	}
};

/* circumventing browser restrictions on the number of cookies one can use */
var subcookiejar = {
	nameValueSeparator: '$$:$$',
	subcookieSeparator: '$$/$$',
	/* set a cookie. subcookieObj is a collection of cookies to be. Every member of subcookieObj is the name of the cookie, its value
	 * the cookie value
	 */
	bake: function(cookieName,subcookieObj,days,path) {
		var existingCookie;
		/* check for existing cookie */
		if (existingCookie = subcookiejar.fetch (cookieName)) {
			/* if a cookie by the same name is found, 
			 * append its values to the subcookieObj.
			 */
			for (var i in existingCookie) {
				if (!(i in subcookieObj)) {
					subcookieObj[i] = existingCookie[i];
				}
			}
		}
		var cookieValue = '';
		for (var i in subcookieObj)	{
			cookieValue += i + subcookiejar.nameValueSeparator;
			cookieValue += subcookieObj[i];
			cookieValue += subcookiejar.subcookieSeparator;
		}
		/* remove trailing subcookieSeparator */
		cookieValue = cookieValue.substring(0,cookieValue.length-subcookiejar.subcookieSeparator.length);
		return cookiejar.bake(cookieName,cookieValue,days,path);
	},
	/* get a subcookie */
	fetch: function(cookieName,subcookieName) {
		var cookieValue = cookiejar.fetch(cookieName);
		/* proceed only if a cookie was found */
		if (!cookieValue) {
			return null;
		}
		var subcookies = cookieValue.split(subcookiejar.subcookieSeparator);
		var cookieObj = {};
		for (var i=0,sclen=subcookies.length; i<sclen; i++)	{
			var sc = subcookies[i].split(subcookiejar.nameValueSeparator);
			cookieObj [sc[0]] = sc[1];
		}
		/* if subcookieName is given, return that subcookie if available, or null.
		 * else, return the entire cookie as an object literal
		 */
		if (subcookieName != undefined) {
			if (subcookieName in cookieObj) {
				return cookieObj[subcookieName];
			}
			return null;
		}
		return cookieObj;
	},
	/* delete a subcookie */
	crumble: function(cookieName,subcookieName,days,path) {
		var cookieValue = cookiejar.fetch(cookieName);
		if (!cookieValue) {
			return false;
		}
		var newCookieObj = {};
		var subcookies = cookieValue.split(subcookiejar.subcookieSeparator);
		for (var i=0, sclen=subcookies.length; i<sclen; i++)	{
			var sc = subcookies[i].split(subcookiejar.nameValueSeparator);
			if (sc[0] != subcookieName) {
				newCookieObj[sc[0]] = sc[1];
			}
		}
		return subcookiejar.bake(cookieName,newCookieObj,days,path);
	}
};