// SN template
// Copyright exorbyte GmbH, 2008-2010. All rights reserved.
function redirect(event, data, formatted) {
	if (data.URL != "") {
		location.assign(data.URL.replace("http:", location.protocol));
	} else {
		jQuery(searchFieldPath).parents("form").submit();
	}
}

function formatTypeHdr(s) {
	switch (s) {
	 case "article":
	  return "Artikel";
	 case "category":
	  return "Kategorien";
	 case "brand":
	  return "Hersteller";
	}
	return s;
}

function formatType(s) {
	switch (s) {
	 case "article":
	  return "Artikel";
	 case "category":
	  return "Kategorie";
	 case "brand":
	  return "Hersteller";
	}
	return s;
}

function formatPrice(p) {
	var currencySymbolAfterPrice = true;
	var decimalPoint = ",";
	var currencySymbol = "&euro;";
	var pFormat;

	if (p) {
		if (currencySymbolAfterPrice) {
			pFormat = p.replace(".", decimalPoint) + " "
				+ currencySymbol;
		} else {
			pFormat = currencySymbol
				+ p.replace(".", decimalPoint);
		}
		return pFormat;
	}
	return p;
}

function makeImgTag(url, useImgCache) {
	var imgTag = "";
	if (url) {
		var imgUrl = url.replace("http:", location.protocol);
		if (useImgCache && url.split("?").length == 1) {
			var imgLink = url.replace(/^https?:\/\//, "");
			var first = imgLink.indexOf("/");
			var imgHost = imgLink.substr(0,first);
			var last = imgLink.lastIndexOf("/");
			var imgFile = imgLink.substr(first+1);
			imgUrl = location.protocol
				+ "//logs.exorbyte.com/imageserver/" + imgFile
				+ "?location=" + imgHost + "&width=50&height=50&dprefix="
				+ exoProjectId;
		}
		imgTag = "<img style='max-height:50px; max-width:50px;' src='" + imgUrl + "' alt=''/>";
	}
	return imgTag;
}

function firstCol(row) {
	var showImg = 1;
	var useImgCache = true;
	var out;
	if (showImg && row.Type == "article") {
		out = "<div style='float:left; display:block; height:50px; width:50px;'>"
			+ makeImgTag(row.Image, useImgCache) + "</div>"
			+ "&nbsp;<span style='vertical-align:top'>"
			+ row.SN_value + "</span>";
	} else {
		out = row.SN_value;
	}
	return out;
}

function secondColNone(row, i, count, dispStr, term) {
	var inHtml;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1' style='padding-left:0;'>"
			+ "<img width='14' height='14' alt='' src='/exorbyte/img/group-category.gif'/> "
			+ formatTypeHdr(row.SN_value) + "</span>";
	} else {
		inHtml = "<span class='col1' style='max-width:95%;width:95%'>"
			+ firstCol(row) + "</span>";
	}

	if (i == 2) {
		// Remove the top border on the first header line
		jQuery(".ac_cat:first").css({borderTop: 0});
	}

	return inHtml;
}

function secondColType(row, i, count, dispStr, term) {
	var inHtml;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1' style='padding-left:0;'>"
			+ "<img width='14' height='14' alt='' src='/exorbyte/img/group-category.gif'/> "
			+ formatTypeHdr(row.SN_value) + "</span>"
			+ "<span class='col2'> </span>";
	} else {
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>"
			+ "<span class='col2'>" + formatType(row.Type) + "</span>";
	}

	if (i == 2) {
		// Remove the top border on the first header line
		jQuery(".ac_cat:first").css({borderTop: 0});
	}

	return inHtml;
}

function secondColCat(row, i, count, dispStr, term) {
	var inHtml;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1' style='padding-left:0;'>"
			+ "<img width='14' height='14' alt='' src='/exorbyte/img/group-category.gif'/> "
			+ formatTypeHdr(row.SN_value) + "</span>"
			+ "<span class='col2'> </span>";
	} else {
		var cat = "";
		if (row.Type == "article") {
			cat = $.trim(row.Category.split(categoryDelimiter)[0]);
		}
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>"
			+ "<span class='col2'>" + cat + "</span>";
	}

	if (i == 2) {
		// Remove the top border on the first header line
		jQuery(".ac_cat:first").css({borderTop: 0});
	}

	return inHtml;
}

function secondColBrand(row, i, count, dispStr, term) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1' style='padding-left:0;'>"
			+ "<img width='14' height='14' alt='' src='/exorbyte/img/group-category.gif'/> "
			+ formatTypeHdr(row.SN_value) + "</span>"
			+ "<span class='col2'> </span>";
	} else {
		var brand = "";
		if (row.Type == "article") {
			brand = $.trim(row.Brand);
		}
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>"
			+ "<span class='col2'>" + brand + "</span>";
	}

	if (i == 2) {
		// Remove the top border on the first header line
		jQuery(".ac_cat:first").css({borderTop: 0});
	}

	return inHtml;
}

function secondColPrice(row, i, count, dispStr, term) {
	var inHtml;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1' style='padding-left:0;'>"
			+ "<img width='14' height='14' src='/exorbyte/img/group-category.gif'/> "
			+ formatTypeHdr(row.SN_value) + "</span>"
			+ "<span class='col2'> </span>";
	} else {
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>"
			+ "<span class='col2'>" + formatPrice(row.Price) + "</span>";
	}

	if (i == 2) {
		// Remove the top border on the first header line
		jQuery(".ac_cat:first").css({borderTop: 0});
	}

	return inHtml;
}

function formatHead() {
	var inHtml = "<div id='snHeader'><span id='snHdrLeft'>&nbsp;</span>"
		+ "<span id='snHdrMid'>Suchergebnisse f&uuml;r &lsquo;"
		+ "<a href='javascript: void(0);' onmousedown='jQuery(searchFieldPath).parents(\"form\").submit();'>"
		+ jQuery(searchFieldPath).val() + "</a>&rsquo;</span>"
		+ "<span id='snHdrRight'>&nbsp;</span></div>";
	return inHtml;
}



