// 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=35&height=35&dprefix="
				+ exoProjectId;
		}
		imgTag = "<img style='max-height:35px; max-width:35px;' 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:35px; width:35px;'>"
			+ 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) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1'>" + formatTypeHdr(row.SN_value) + "</span>";
	} else {
		inHtml = "<span class='col1' style='max-width:95%;width:95%'>"
			+ firstCol(row) + "</span>";
	}

	return inHtml;
}

function secondColType(row) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1'>" + formatTypeHdr(row.SN_value) + "</span>";
	} else {
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>" +
			"<span class='col2'>" + formatType(row.Type) + "</span>";
	}

	return inHtml;
}

function secondColCat(row) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1'>" + formatTypeHdr(row.SN_value) + "</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>";
	}

	return inHtml;
}

function secondColBrand(row) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1'>" + formatTypeHdr(row.SN_value) + "</span>";
	} else {
		var brand = "";
		if (row.Type == "article") {
			brand = $.trim(row.Brand);
		}
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>"
			+ "<span class='col2'>" + brand + "</span>";
	}

	return inHtml;
}

function secondColPrice(row) {
	var inHtml = row.SN_value;
	if (row.SN_type.substring(0,4) == "cat_") {
		inHtml = "<span class='col1'>" + formatTypeHdr(row.SN_value) + "</span>";
	} else {
		inHtml = "<span class='col1'>" + firstCol(row) + "</span>" +
			"<span class='col2'>" + formatPrice(row.Price) + "</span>";
	}

	return inHtml;
}

