﻿function QuickInfo(id) {
	ItemInfo.ItemInfoWebService.PageHtml("QuickInfo.aspx?id="+id,"ProductPopup", function () {
		var html = arguments[0];
		ShowModal(html, "ModalDiv",'550px','425px');
	});
}

var inkandtonerTimer;
function InkAndTonerStartTimer() {
	inkandtonerTimer = setTimeout('ShowInkAndToner()', 800);
}
function InkAndTonerStopTimer() {
	clearTimeout(inkandtonerTimer);
}

//	$("#simplemodal-wrap").height($('#InkTonerPopup').height() + 4);
//	$("#simplemodal-wrap").width($('#InkTonerPopup').width() + 4);


function ShowModal(html, containerid, height,width) {
	$("#" + containerid).html(html);
	$("#" + containerid).modal({
		overlayClose: true
					, opacity: 20
					, zIndex: 9999999
					, containerCss: { height: height,width: width, minHeight:height  }
	}); 		
	$("#simplemodal-container").height(height);
	$("#simplemodal-container").width(width);
}

function ShowModalResize(html,containerid, id) {
			$("#" + containerid).html(html);
			$("#" + containerid).modal({
				overlayClose: true
					, opacity: 20
					, zIndex: 9999999
			});
			//$("#simplemodal-container").height($("#"+id).height() + 4);
//			$("#simplemodal-container").width($("#"+id).width() + 4);
}
//MyList functions
function RefreshListCount() {
	ItemInfo.ItemInfoWebService.ListCount(UpdateListCount);
}

function AddToList(id, tbid) {
	var qty = 1;
	if (!tbid) tbid = 'txtQuantity_' + id;
	var tb = $('#' + tbid);
	if(!isNaN(tb[0].value) )	qty=tb[0].value;
	ItemInfo.ItemInfoWebService.AddListItem(id, qty, 0, UpdateListCount);
}

function ShowItemAdded(con, c) {
  $(con).html('<a>ITEM ADDED</a>');
  //var cl = c ? c : "addedtolist";
	//$(con).append("<div class='" + cl+ "'>*Item Added<div>");
}


function UpdateMyListHtml(html) {
	RefreshListCount();
	$("#ShoppingList").html(html);
}

function UpdateListCount(result) {
	$('#CartItemCount').text(result);
}

//CompareList functions
var compareEventSource = 0;  //0-no event, 1=product checkboxes, 2=compare images
function RefreshCompareImages() {
	ItemInfo.ItemInfoWebService.CompareHtml(UpdateCompareImages);
}
function RemoveFromCompareList(index) {
	compareEventSource = 2;
	ItemInfo.ItemInfoWebService.RemoveCompareItemAt(index, UpdateCompareImages);
}
function UpdateCompareImages(comparehtml) {
	$(".ComparePics").html(comparehtml);
	checkboxCount = comparehtml.split('http').length - 1;
	if (compareEventSource == 2) {
		compareEventSource = 0;
		RefreshCompareCheckBoxes();
	}
}
var checkboxCount = 0;
function RefreshCompareCheckBoxes() {
	ItemInfo.ItemInfoWebService.CompareIDList(UpdateCompareCheckBoxes);
}
function UpdateCompareItem(chkbox) {
	compareEventSource = 1;
	var s = chkbox.id;
	if (checkboxCount == 3 && chkbox.checked) {
		alert("No more than 3 products may be compared.\r  Please uncheck a product.");
		//		$('#'+s).removeAttr("checked");
		RefreshCompareCheckBoxes();
	} else {
		var id = s.substring(11);
		ItemInfo.ItemInfoWebService.AddCompareItem(id, UpdateCompareImages);
	}
	compareEventSource = 0;
}

function UpdateCompareCheckBoxes(idlist) {
	var s = new Array();
	s = idlist.split(",");
	$("input[id*='chkCompare_']").removeAttr("checked");
	for (i = 0; i < s.length; i++) {
		$("#chkCompare_" + s[i]).attr("checked", "true");
	}
}


function QuickInfoImageClick(action, url, winid, parameters) {
	if (action == 0) {
		$('#' + parameters).attr('src', url);
	} else if(action==1) {
		window.open(url, winid, parameters)
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	opacity = (opacity < 0) ? 0 : opacity;

	// IE/Win
	obj.style.filter = "alpha(opacity:" + opacity + ")";

	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity / 100;

	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity / 100;

	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity / 100;
}
