function SwitchVisibility(elId) {
	var elContent = document.getElementById(elId + 'Content');
	var elTriangle = document.getElementById(elId + 'Triangle');

	if (elContent != null) {
		if (elContent.style.display != 'none') {
			elContent.style.display = 'none';
			elTriangle.innerHTML = '&#9658;';
		} else {
			elContent.style.display = 'block';
			elTriangle.innerHTML = '&#9660;';
		}
	}
}

// show / hide tip text
function onfocus_input(tipText, ID, className) {
	var inputControl = document.getElementById(ID);
	inputControl.className = className;

	if (inputControl.value == tipText)
		inputControl.value = "";
}
function onblur_input(tipText, ID, className) {
	var inputControl = document.getElementById(ID);

	if (inputControl.value == "") {
		inputControl.className = className;
		inputControl.value = tipText;
	}
}

function check_submit(e, url) 
{
    var characterCode;
    if(window.event) // IE
        characterCode = e.keyCode;
    else if(e.which) // Firefox/Opera/Safari
        characterCode = e.which;
    if(characterCode == 13)
        RefineSearchSearch(url, 'inputSearchBox', 'Search');
    return true;
}

function RefineSearchYears(url, ctrYearLowName, ctrYearHighName) {
	var newQuery = '';
	var path = '';

	if (url.indexOf('?') != -1) {
		path = url.substring(0, url.indexOf('?') + 1);
		newQuery = url.substring(url.indexOf('?') + 1);
	} else
		path = url;

	if (newQuery.length > 0)
		newQuery += '&';
	else
		newQuery = '?';

	var ctrYearLow = document.getElementById(ctrYearLowName);
	var ctrYearHigh = document.getElementById(ctrYearHighName);
	var yearLow, yearHigh;
	if (ctrYearLow.value > ctrYearHigh.value) {
	    yearLow = ctrYearHigh.value;
	    yearHigh = ctrYearLow.value;
    } else {
	    yearLow = ctrYearLow.value;
	    yearHigh = ctrYearHigh.value;
    }
	newQuery = path + newQuery + ctrYearLow.name + '=' + yearLow + '&' + ctrYearHigh.name + '=' + yearHigh;
	window.location.href = newQuery;
}

function RefineSearchSearch(url, ctrSearchInputId, tipText) {
	var ctrSearchInput = document.getElementById(ctrSearchInputId);
	var newQuery = '';
	var path = '';

	if (ctrSearchInput.value == '' || ctrSearchInput.value == tipText)
		return;

	if (url.indexOf('?') != -1) {
		path = url.substring(0, url.indexOf('?') + 1);
		newQuery = url.substring(url.indexOf('?') + 1);
	} else
		path = url;

	if (newQuery.length > 0)
		newQuery += '&';
	else
		newQuery = '?';

	newQuery = path + newQuery + '_search=' + ctrSearchInput.value;
	window.location.href = newQuery;
}

function setPageSize(rows, refreshURL) {
	var expire = new Date();

	expire.setTime (expire.getTime() + (2592000000)); //30 days from now!
	document.cookie = 'EBizAutosBuyersSiteCookiePageSize=' + rows + ';expires=' + expire.toGMTString() + ';path=/';

	if (refreshURL == '?') {
		refreshURL = document.URL;

		var pos = refreshURL.indexOf('?');

		if (pos != -1)
			refreshURL = refreshURL.substr(0, pos);
	}

	if (refreshURL == '')
		refreshURL = document.URL;
	
	if (document.all){ // if is IE
		window.navigate(refreshURL);
	} else {
		window.location.reload(true);
		window.location.href = refreshURL;
	}
}

function TruncateChromeDescription(link){
    var description = document.getElementById('DescriptionText');
    if (description != null){
		var descriptionText = description.innerHTML;
		if (description.offsetHeight > 45) {
			var truncatedDescription = '';
			var wordsArray = descriptionText.split(' ');
			for (i=0; i< wordsArray.length;i++){
				description.innerHTML = truncatedDescription + ' ' + wordsArray[i] + ' ...';
				if (description.offsetHeight > 45) 
					break;
				truncatedDescription = truncatedDescription + ' ' + wordsArray[i];
			}
			description.innerHTML = truncatedDescription + ' <a href=\"' + link + '\">...</a>';
		}
		description.style.visibility = 'visible';
	}
}

function selectShowLocation(showLocation, url) {
	var value = showLocation.options[showLocation.selectedIndex].value
	if (value != "none") {
		window.location.href= url + value;
	}
 } 