// Javascript support for Support pages

var client;
var host = 'http://www.bendpak.com';
var path;
var title;

// *** Support "summary" page functions *****

function updateProductSeries(seriesName) {
	// Based on the seriesName (page of products), gets ListFeed of products in that category...
	$("body *").css('cursor', 'wait');
	$("#frmProduct").css('background-color', '#ddd');

	pixelsilk.getListItems(seriesName.replace(host, ''), "sort1=SortOrder,asc", "", 1000, 1, function(json) {
		getProductsIntoForm(json);
	});
}

function getProductsIntoForm(objProducts) {
	//var objProducts = eval('(' + text + ')');
	var select = document.getElementById('frmProduct');
	var i;

	clearProducts();

	// List via Title...
	for (i = 0; i < objProducts.length; i++) {
		select.options[select.options.length] = new Option(objProducts[i].Title, objProducts[i].Title);
	}

	$("body *").css('cursor', 'default');
	$("#frmProduct").css('background-color', '#fff');
}

function clearProducts() {
	var select = document.getElementById('frmProduct');
	var options = select.getElementsByTagName('option');
	var i;

	for (i = options.length - 1; i > 0; i--) {
		select.removeChild(options[i]);
	}
}

// *** Support "detail" page functions *****
function getProductDetailAjax() {
	var vars = location.search.split('&');

	var q = vars[0].split('=');
	path = unescape(q[1]);

	q = vars[1].split('=');
	title = q[1];

	if (path.indexOf("ranger") != -1) {
		$("#pageHeader").css("background-image", "url('/page-header-ranger.gif')");
	}

	pixelsilk.getListItems(path.replace(host, ''), "sort1=SortOrder,asc", "filter1=Title,eq," + title, 1000, 1, function(json) {
	getProductDetail(json);
	});
}

function getProductDetail(objProduct) {
	// Set the request form "Model" field to indicate it came from a specific page
	$("#Model").val(objProduct[0].Title);

	$('div#breadcrumbs a.bcProductName').text(objProduct[0].Title);
	$('div#breadcrumbs a.bcProductName').attr('href', '#');

	// Set the visible detail fields for the Product
	$("h1#productTitle").html(objProduct[0].Title);
	$("#productDetailLink a").attr('href', path + objProduct[0].Title + '.aspx');
	$("#productDetailSKU").html(objProduct[0].Sku);
	$("#productDetailModel").html(objProduct[0].Title);
	//$("#productDetailDesc").html(objProduct[0].BriefDescription + '&nbsp;');
	$("#productDetailDesc").html(objProduct[0].Name + '&nbsp;');
	$("#productDetailGroup").html(objProduct[0].Category);
	var downloads = '';
	if (objProduct[0].Manual != null && objProduct[0].Manual != '') {
		downloads += '<a href="' + objProduct[0].Manual + '" target="_blank">&raquo; Manual: ' + objProduct[0].Manual.substring(1) + '</a><br />';
	}
	if (objProduct[0].Attachment1 != null && objProduct[0].Attachment1 != '') {
		downloads += '<a href="' + objProduct[0].Attachment1 + '" target="_blank">&raquo; ' + objProduct[0].Attachment1.substring(1) + '</a><br />';
	}
	if (objProduct[0].Attachment2 != null && objProduct[0].Attachment2 != '') {
		downloads += '<a href="' + objProduct[0].Attachment2 + '" target="_blank">&raquo; ' + objProduct[0].Attachment2.substring(1) + '</a><br />';
	}
	if (objProduct[0].Attachment3 != null && objProduct[0].Attachment3 != '') {
		downloads += '<a href="' + objProduct[0].Attachment3 + '" target="_blank">&raquo; ' + objProduct[0].Attachment3.substring(1) + '</a><br />';
	}
	if (objProduct[0].Attachment4 != null && objProduct[0].Attachment4 != '') {
		downloads += '<a href="' + objProduct[0].Attachment4 + '" target="_blank">&raquo; ' + objProduct[0].Attachment4.substring(1) + '</a><br />';
	}
	if (downloads != '') {
		$("#productDetailDownloads").html(downloads);
	} else {
		$("#downloadsDetail").css('display', 'none');
	}
	if (objProduct[0].DemoVideo != null && objProduct[0].DemoVideo != '') {
		$("#divFlashVideoPlayer").html("<OBJECT type='application/x-shockwave-flash' height='294' width='523' data='/videoPlayer.swf' id='flashVideoPlayer'><PARAM NAME='Movie' VALUE='/videoPlayer.swf'><PARAM NAME='Src' VALUE='/videoPlayer.swf'><PARAM NAME='Quality' VALUE='High'><param name='wmode' value='transparent'><param name='flashvars' value='playVid=" + objProduct[0].DemoVideo + "&vidWidth=523&vidHeight=294'></OBJECT>");
	} else {
		$("#demoDetail").css('display', 'none');
	}
}

function doPrint() {
	if (window.print) {
		window.print();
	} else {
		alert('Please choose the print button from your browser.  Usually in the menu dropdowns at File: Print');
	}
}

