/*--[ SEARCH BOX ]-------------------------------------------------------------------
*  Use the following 3 functions if a search box is required in the template.
*  Ensure you give the search box an id='txtSearch' attribute
*  callAdvancedSearch is for the 'search' button.  This will send the search criteria
*    useage: <a href="#" id="submitSearch" >Search</a>
*  getChars will check the box each keypress to see if they pressed Enter, which
*       will transfer them to the search page.
*    useage: <input class="search_box" type="text" width="115" id="txtSearch" name="txtSearch">
*	You will need to change the url in callAdvancedSearch function.
*-----------------------------------------------------------------------------------*/
function callAdvancedSearch(lang) { 
	var criteria = document.getElementById('txtSearch').value;
	var url ="/carte_gourmet2/index" + lang + ".aspx?ArticleID=721@criteria=" + criteria;
	window.location=url;
	return false;	
}
function getChars(e, lang) {     
	if (!e) var e = window.event;        //Internet Explorer Event
	//Grab the keycode for all browsers
	var characterCode=(e.charCode)?e.charCode: ((e.keyCode)?e.keyCode:((e.which)?e.which:0));
	if (characterCode == 13) {        //13=Enter button    
		//Cancel default form submission action
		e.cancelBubble = true;        
		e.returnValue = false;    
		
		if (e.which ) e.preventDefault();
		
		//Run the search
		callAdvancedSearch(lang);            
	}
	return false;
}

/*---[ Language Link ]-------------------------------------------------------------
*  This is used if the language link is inside an image map.
*  Otherwise, use the default language link by the WCMS.
*  Useage: change_links() to the window.onload function on the main page
*---------------------------------------------------------------------------------*/
function change_links()
{
	var address = document.location.href;
	var home_link = address;
	home_link = home_link.split('?');

	var rExp = 'index_e';
	start = address.search(rExp);		//check to see if its on english page
	if (start==(-1)){					//english, change to french
		address = address.replace("index_f","index_e");	//replace f with e
	} else {
		address = address.replace("index_e","index_f");	//replace e with f
	}
	
	document.getElementById('switch_lang').href = address;	//change switch_lang to whatever id you need
	document.getElementById('home_link').href = home_link[0];

}

/*---[ Resize Text ]-------------------------------------------------------------
*  Will change the text size
*  Useage: <a href="#" onClick="resizeText(1)">Change Text Size</a>
*---------------------------------------------------------------------------------*/
function resizeText(multiplier) {
  if (document.getElementById('main').style.fontSize == "") {
    document.getElementById('main').style.fontSize = "0.8em";
  }
  if (document.getElementById('main').style.fontSize == '1em') {multiplier = (-1);}
  document.getElementById('main').style.fontSize = parseFloat(document.getElementById('main').style.fontSize) + (multiplier * 0.2) + "em";
}

/*---[ Change Title ]-------------------------------------------------------------
*  Appends the site name to the title until the WCMS does it 
*  Useage: changeTitle('Default Site');
*---------------------------------------------------------------------------------*/
function changeTitle(pageTitle) {
	document.title = (document.title + " - " + pageTitle);
}
