function openHelp()
	{
	var winmain=open("help.htm","help","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=250,height=250,top=100,left=100")
	winmain.focus()
    }


function checkfm(fr)
	{
	for(i=0;i<fr.Product.length;i++)
		{
		if(fr.Product[i].checked==true)
			{
			BuyItems(fr);			
			return true;
			}
		}
	alert("Please select at least one Product to add in Query Basket!")
	fr.Product[0].focus()
	return false;
	}

function BuyItems(fr)
	{
	for(i=0;i<fr.Product.length;i++)
		{
		if(fr.Product[i].checked==true)
			{
			buyItem(fr.Product[i].value)
			}
			}
	alert("Selected Products Added to Query Basket !\n\nPlease Click SUBMIT QUERY Button to send query")
	}


function buyItem(newItem,newCategory,newQuantity,newComment)
	{
	newCategory="None"
	newQuantity="None"
	newComment="None"
              index = document.cookie.indexOf("TheBasket");
              countbegin = (document.cookie.indexOf("=", index) + 1);
              countend = document.cookie.indexOf(";", index);
              if (countend == -1) {
                      countend = document.cookie.length;
              }
              document.cookie="TheBasket="+document.cookie.substring(countbegin, countend)+"["+newItem+","+newCategory+"^"+newComment+"~"+newQuantity+"]";
              }

//alert(document.cookie)

function basket()
	{
	window.location.href='query-now.asp';
	}

	
var index = new Array(10);
var qty = new Array(10);
function showItems() {
	index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
	document.writeln('<table border="1" align="center" cellpadding="3" cellspacing="3" bordercolor="#E9E9E9" width="80%">');
	document.writeln('<tr><td width="10%" bgcolor="#7B9194"><b><font face="Verdana" size="1.5" color="#ffffff">Sr. No.</font></b></td><td width="74%" bgcolor="#7B9194"><b><font face="Verdana" size="1.5" color="#ffffff">Product Name</font></b></td><td width="18%" bgcolor="#7B9194">&nbsp;</td></tr>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemlist=itemlist+1;
	document.writeln('<tr><td width="11%"><p align="right"><font face="Verdana" size="1.5">'+itemlist+'.</font></td><td width="74%"><font face="Verdana" size="1.5">'+theitem+'</font></td><td width="18%" align="center"><font face="Verdana" size="1.5"><a href="javascript:removeItem('+itemlist+')"><font color="#5F3405">Remove</font></a></font></td></tr>');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '^') {
				thecat = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '~') {
				thecomm = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}
	document.writeln('</TABLE>');
	}

	function removeItem(itemno) {
		newItemList = null;
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				theitem = fulllist.substring(itemstart, itemend);
				itemlist=itemlist+1;
				if (itemlist != itemno) {
					newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
				}
			}
		}
		index = document.cookie.indexOf("TheBasket");
		document.cookie="TheBasket="+newItemList;
			window.location = "query-now.asp";
		}
	function clearBasket() {
		if (confirm('Are you Sure To Clear your Query Basket?')) {
			index = document.cookie.indexOf("TheBasket");
			document.cookie="TheBasket=.";
			alert("Your Query basket is Empty ! You Are Being Redirect to First Page.")
			self.location.href = "query-now.asp";
		}
	}
        function resetShoppingBasket() {
                index = document.cookie.indexOf("TheBasket");
                document.cookie="TheBasket=.";
        }

	function UpdateBasket() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
		indexx = document.cookie.indexOf('[',index);
		if(indexx == -1)
		{
			alert("Can't make changes on Empty Basket");
		}
		else
		{
			if (countend == -1) {
	            		countend = document.cookie.length;
	        	}
			fulllist = document.cookie.substring(countbegin, countend);
        resetShoppingBasket();
			itemlist = 0;
			for (var i = 0; i <= fulllist.length; i++) {
				if (fulllist.substring(i,i+1) == '[') {
					itemstart = i+1;
				} else if (fulllist.substring(i,i+1) == ']') {
					itemend = i;
					thequantity = fulllist.substring(itemstart, itemend);
			buyItem(theitem,thecat,document.frmquery.elements[itemlist].value,thecomm);
					itemlist=itemlist+1;
				} else if (fulllist.substring(i,i+1) == ',') {
					theitem = fulllist.substring(itemstart, i);
					itemstart = i+1;
				} else if (fulllist.substring(i,i+1) == '^') {
					thecat = fulllist.substring(itemstart, i);
					itemstart = i+1;
				} else if (fulllist.substring(i,i+1) == '~') {
					thecomm = fulllist.substring(itemstart, i);
					itemstart = i+1;
				}
			}
			alert("The respective changes have been made.");
		}
	}

	function checkbsk() {
		index = document.cookie.indexOf("TheBasket");
		countbegin = (document.cookie.indexOf("=", index) + 1);
	        	countend = document.cookie.indexOf(";", index);
		indexx = document.cookie.indexOf('[',index);
		if(indexx == -1)
		{
			alert("Can't Send Query on Empty Basket");
		}
		else
		{
		document.frmquery.submit();
		}
	}

function showItems1() {
	index = document.cookie.indexOf("TheBasket");
	countbegin = (document.cookie.indexOf("=", index) + 1);
        	countend = document.cookie.indexOf(";", index);
        	if (countend == -1) {
            		countend = document.cookie.length;
        	}
		fulllist = document.cookie.substring(countbegin, countend);
	document.writeln('<table border="1" align="center" cellpadding="4" cellspacing="3" bordercolor="#E9E9E9" width="80%">');
	document.writeln('<tr><td width="10%" bgcolor="#7B9194"><b><font face="Verdana" size="2" color="#ffffff">Sr. No.</font></b></td><td width="90%" bgcolor="#7B9194"><b><font face="Verdana" size="2" color="#ffffff">Product Code</font></b></td></tr>');
		itemlist = 0;
		for (var i = 0; i <= fulllist.length; i++) {
			if (fulllist.substring(i,i+1) == '[') {
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == ']') {
				itemend = i;
				thequantity = fulllist.substring(itemstart, itemend);
				itemtotal = 0;
				itemlist=itemlist+1;
	document.writeln('<INPUT TYPE="hidden" NAME="Product'+itemlist+'" VALUE="hb-'+theitem+'" >');           
	document.writeln('<tr><td width="10%"><p align="right"><font face="Verdana" size="2">'+itemlist+'.</font></td><td width="90%"><font face="Verdana" size="2">hb-'+theitem+'</font></td></tr>');
			} else if (fulllist.substring(i,i+1) == ',') {
				theitem = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '^') {
				thecat = fulllist.substring(itemstart, i);
				itemstart = i+1;
			} else if (fulllist.substring(i,i+1) == '~') {
				thecomm = fulllist.substring(itemstart, i);
				itemstart = i+1;
			}
		}
	document.writeln('</TABLE>');
	}
