var t_prod = '';

$(document).ready(function()
{
	$("#div_quickView").dialog
	(
		{
			modal: true, 
			autoOpen:false,
			width:700,
			height:750,
			resizable:false
		}
	);
});

function showQuickView(prod)
{
	$("#div_quickView").dialog(
	"open"
	);
	t_prod = prod;
	//alert(prod);
	document.getElementById('q_img').src = document.getElementById('img_' + t_prod).src;
	document.getElementById('q_prod').innerHTML = document.getElementById('prod_' + t_prod).innerHTML;
	document.getElementById('q_price').innerHTML = document.getElementById('price_' + t_prod).innerHTML;
	document.getElementById('q_retail').innerHTML = document.getElementById('retail_' + t_prod).value;
	document.getElementById('q_savings').innerHTML = document.getElementById('savings_' + t_prod).value;
	//document.getElementById('q_descr').innerHTML = document.getElementById('descr2_' + t_prod).value;
	document.getElementById('q_descr').innerHTML = document.getElementById('longdescr_' + t_prod).value;

	//var submitButton = document.getElementById('btnAdd2');
	//submitButton.setAttribute('onclick', 'q_Add(' + t_prod + ');return false');

	//now we need to determine what scents, options, etc. may be available and create a list
	var p = prod;
	var list;
	for (i=1;i<=1000;i++)
	{
		if (arrItems[i][1] == p)
		{
			if (arrItems[i+1][1] == p)
			{
				//multiple entries for this product, build a list
				list='<span class="item"><nobr><input type="checkbox" id="chkItem_' + i + '" name="chkItem_' + i + '" value="' + arrItems[i][3] + '">' + arrItems[i][4] + '</nobr></span>';
				//<input type="checkbox" id="chkItem_xx" name="chkItem_xx" value="chkItem_xx">Style 1<br />
				i++;
				while (arrItems[i][1] == p)
				{
					list+='<span class="item"><nobr><input type="checkbox" id="chkItem_' + i + '" name="chkItem_' + i + '" value="' + arrItems[i][3] + '">' + arrItems[i][4] + '</nobr></span>';
					i++;
				}
				$('#quicklist').html(list);
				$('#quicklist').height( 'auto' );
				$("#div_quickView").height( 'auto' );
				break;
			}
			else
			{
				//only one entry, so display it
				list='<span class="item"><nobr><input type="checkbox" id="chkItem_' + i + '" checked="checked" name="chkItem_' + i + '" value="' + arrItems[i][3] + '">' + arrItems[i][4] + '</nobr></span>';
				$('#quicklist').html(list);
				$('#quicklist').height( 'auto' )
				$("#div_quickView").height( 'auto' );
				break;
			}
		}
	}

	return false;
}

function q_Add(t_prod)
{
	var list = '';
	//find all the checked checkboxes
	$('input:checkbox:checked').each
	(
	  function()
	  {
	    list += jQuery(this).val()+ '|';
		//need to add the items as hidden fields on the form that will be posted!!!!
		//list='<input type="hidden" id="item|' + jQuery(this).val() + '" name="item|' + jQuery(this).val() + '" value="1">';
		$("#div_mycart1").append('<input type="hidden" id="item|' + jQuery(this).val() + '" name="item|' + jQuery(this).val() + '" value="1">');
		//<input type="hidden" id="item|" name="item|" value="1">
	  }
	);
	
	if (list == '')
	{
		alert('Please Choose at least 1 option.');
		return false;
	}
	
	//alert(list);
	$('#f_items').val(list);

	var element = $('#itemid1');
	var form = element.attr("form");

	
	//DON'T add the items to the submit url
	var url = $(form).attr("action");
	//url += '?f_items=' + list;
	$(form).attr("action",url);

	form.submit();
}

function q_Add2(t_prod)
{
	var list = '';
	list = t_prod + '|';
	//need to add the item as hidden fields on the form that will be posted!!!!

	//alert('<input type="hidden" id="item|' + t_prod + '" name="item|' + t_prod + '" value="1">');
	$("#div_mycart1").append('<input type="hidden" id="item|' + t_prod + '" name="item|' + t_prod + '" value="1">');
	
	//alert(list);
	$('#f_items').val(list);

	var element = $('#itemid1');
	var form = element.attr("form");
	
	var url = $(form).attr("action");
	$(form).attr("action",url);
	
	//alert(url);
	
	form.submit();
}

function showDetails(t_prod)
{
	//window.location="product.asp?prod=" + t_prod
	//window.location="itemdetail.asp?prod=" + t_prod
	var p = '';
	var c = '';
	for (var i=1;i<=arrItems.length;i++)
	{
		if (arrItems[i][3] == t_prod)
		{
			p = arrItems[i][3];
			c = arrItems[i][6];
			break;
		}
	}
	if (p != '') {
		var url = 'ItemDetail.asp?prodid=' + p + '&cat1=' + c;
		//alert(url);
		window.location = url;
	}

}

function doSearch()
{
	var des = document.getElementById('des').value;
	//alert (des);
	document.getElementById('keysearch1').value = des;
	document.getElementById('sdes').value = des;
	var url = 'search.asp&sdes=' + des;
	document.frmSearch.submit();
}

function doSort(sortby)
{
	//alert(document.getElementById('sortby').value);
	document.getElementById('sortby').value = sortby;
	document.getElementById('sort_by').value = sortby;
	document.getElementById('sort_by_2').value = sortby;
	sendForm();
}

function doPaging(which)
{
	if (which == 0 || which == '')
	{
		which = 1;
	}
	//alert(which);
	document.paging.action = 'search.asp?CurrentPage=' + which;
	document.paging.submit();
}


function trim(stringToTrim)
{
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function sendForm()
{
	document.sortbar1.submit();
}

function cancelForm()
{
	$("#verify-container").dialog('close');
}

function printForm()
{
	$("#ver_print").jqprint({ importCSS: true })
}


