
/** Small Search Form Javascript **/


/**
 * This function takes the query for a search page and adds it onto the URL for SEO purposes.
 *
 * @param string formID This is the ID of the form to get the search term from and to submit. ID should not have a '#'.
 */
var originalSmallSearchFormAction = '';
function CheckSmallSearchForm(formID){
	var search = $('#' + formID + ' .smallSearch_Query').val();
	search = search.replace(/ /g, '+');
	search = escape(search);

	$('#' + formID).attr('action',  originalSmallSearchFormAction + '/' + search);
}

/**
 * This function opens a popup window to display the search tips
 */

function launchSearchTips() {
	var urlToOpen = iwp_global_siteurl + "/searchtips.html";
	var day = new Date();
	var id = day.getTime();
	window.open(urlToOpen, "'" + id + "'", 'toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=0,resizable=1,width=600,height=500');
}

$(document).ready(function() {
	var url = '';
	url = document.location.href;
	if(url.substr(-1, 1) == '/'){
		url = url.substr(0, (url.length - 1));
	}

	// @TODO: Add in a fix for finding the current URL for links that are using /site/path instead of http://www.example.com/site/path

	$('.tplIsCurrentItem:has(a[href='+url+'])').each(function(){
		$(this).addClass('currentItem');
	});

	$('.tplIsCurrentItem:has(a[href='+url+'/])').each(function(){
		$(this).addClass('currentItem');
	});


	$('.smallSearchForm').each(function(){
		var formID = $(this).attr('id');
		originalSmallSearchFormAction = $(this).attr('action');

		$(this).submit(function (){
			CheckSmallSearchForm(formID);
		});
	});
});

