//setting events handlers
document.onmouseup = up;
//document.onmousemove= moveObject;

//browser detection.
var isNav4, isIE4, isMac, isNav6;
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
  isStd = (navigator.appName == "Netscape") ? true : false
  isIE  = (navigator.appName.indexOf("Microsoft") != -1) ? true : false
  isMac = (navigator.platform.indexOf("Mac") != -1) ? true : false
  isPNG = (isIE && ! isMac) ? false : true
}

//some variables
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all


//creating the list of products 


var id;
var draggingImage;
var iAmOverShoppingBag = false;
var snap = false;
var scrollDiv=0;
var scrollOn = false;
var isOneSelected = false;

//preloading a image
pic1= new Image(32,32); 
pic1.src="../images/wait.gif"; 

//function to create the product object
function product(code, name, src, width, height, selected, price, at1List , at2List, at3List, at4List, at5List) {
  this.code = code;  //product ID
  this.name = name;  //product name
  this.src = src;    //image picture
  this.width = width; //image width
  this.height = height; //image height
  this.selected = false; // is true if is dragged
  this.left = 0; //initially is set to 0 , on click the values are modified
  this.top = 0; //same here
  this.price = price;
  this.at1List = at1List;
  this.at2List = at2List;
  this.at3List = at3List;
  this.at4List = at4List;
  this.at5List = at5List;
}

function addProduct(code, name, src, width, height, selected , price , at1List , at2List, at3List, at4List, at5List) {
  productList[code] = new product(code, name, src, width, height, selected , price , at1List , at2List, at3List, at4List, at5List);
}

// shopping cart objects
function bagProductObject(id , code, quantity , at1, at2, at3, at4 , at5 ) {
  this.id = id;
  this.code = code;  //product ID
  this.quantity = quantity;
  this.at1 = at1;
  this.at2 = at2;
  this.at3 = at3;
  this.at4 = at4;
  this.at5 = at5;  
}

function addBagProduct(id , code, quantity , at1, at2, at3, at4 , at5) {
  bagProducts[id] = new bagProductObject(id , code, quantity, at1, at2, at3, at4 , at5);
}

//lovs functions
// shopping cart objects
function LOV(id , value) {
  this.id = id;
  this.value = value;  //product ID
}

function addLOV(id , value) {
  LOVS[id] = new LOV(id , value);
}


//function to drag the object 
function drag(e) {
	
	var theCode='';
	for (var i in productList)
	{
		if (productList[i].selected == true)
		{
			theCode= productList[i].code;
			//dragImageWidth = Math.round(productList[i].width / 2);
          	//dragImageHeight = Math.round(productList[i].height / 2);
			dragImageWidth = Math.round(40 / 2);
          	dragImageHeight = Math.round(40 / 2);
		}
	}
	
	
  if (theCode != "") {
    
    if (isStd) {
      // Nav6: Track the difference, and add the starting position to it  
      theLayer.style.left = startX + e.clientX - oldX;
      theLayer.style.top = startY + e.clientY - oldY;
	  
	  //window.alert("DRAG! Start: " + startX + "," + startY + " - Pg: " + e.pageX + "," + e.pageY + " - Old: " + oldX + "," + oldY + " - L/T: " + theLayer.style.left + "," + theLayer.style.top + " TEST: " + document.body.scrollTop);
    }
    else 
	{
      if (isMac) {
        document.all[document.getElementById(theCode)].style.pixelLeft = window.event.clientX - dragImageWidth;
        document.all[document.getElementById(theCode)].style.pixelTop  = (window.event.clientY) + document.body.scrollTop - dragImageHeight;
        // window.status = "Drag On: " + window.event.clientX + " / " + window.event.clientY + " - " + oldX + " / " + oldY;
      }
      else {
        // On windows, the Y is fixed not relative to page scroll, so compensate
		var c = document.getElementById(theCode);
       c.style.pixelLeft = window.event.clientX - dragImageWidth;
       c.style.pixelTop  = (window.event.clientY) + document.body.scrollTop - dragImageHeight;
      }
    }
    
	//check if mouse is over the shopping bag 
	iAmOverShoppingBag = isOverShoppingBag(theCode, e);
	if (iAmOverShoppingBag == true)
	{
		productIsOverShoppingBag('on');
	}
	else
	{
		productIsOverShoppingBag('off');
	}

  }
  return false;
}


function up (e)
{	
	
	if (isOneSelected==true) return false;
	document.onmousemove = null;
	theCode ='';
	for (var i in productList)
	{
		if (productList[i].selected==true)
			theCode = productList[i].code;
	}
	if (theCode=='') return false;
	
	//getting from where the product came from 
	startX = productList[theCode].left;
	startY = productList[theCode].top;
	
	theProduct = document.getElementById(theCode);
	
	
	if (isStd) {
        snapEndX = parseInt(theProduct.style.left);
        snapEndY = parseInt(theProduct.style.top);  
        snapCurrent = 0;     
		if (iAmOverShoppingBag==true)
		{
        	snapTimer = setInterval("snapBack(theCode, startX, startY, snapEndX, snapEndY, 1)", 10);
		}
		else
		{
			snapTimer = setInterval("snapBack(theCode, startX, startY, snapEndX, snapEndY, 15)", 10);
		}
      }
      else {
        snapEndX = document.getElementById(theCode).style.pixelLeft;
        snapEndY = document.getElementById(theCode).style.pixelTop;   
        snapCurrent = 0;     
        if (iAmOverShoppingBag==true)
		{
        	snapTimer = setInterval("snapBack(theCode, startX, startY, snapEndX, snapEndY, 1)", 10);
		}
		else
		{
			snapTimer = setInterval("snapBack(theCode, startX, startY, snapEndX, snapEndY, 15)", 10);
		}
      }
	
	productIsOverShoppingBag('off');
	
	//we update the shopping cart , even reload the page
	if (iAmOverShoppingBag==true)
	{
		addToShoppingCart(theCode);
	}
	
		
	//all products can be dragged, none are selected
	for (var i in productList)
		productList[i].selected=false;
	//no products are being dragged	
	isOneSelected = false;	
	
	//get the position where mouse up was triggered
	 if (isStd) {
		  NclickX = e.pageX;
		  NclickY = e.pageY;
	 }
	 else
	 {
		  NclickX = event.clientX;
		  NclickY = event.clientY;
	 }
	 //if only click not drag , then we open the view_productpage
	//window.alert(clickX + " " + NclickX + " " +clickY+ " " +NclickY);
	if(clickX==NclickX && clickY==NclickY)
	 {
		window.location ='product_display.php?productid=' + theCode;
	 }
	
}


function selectObject(code, e) {
	
	if (isOneSelected==true) return false;
	
	for (var i in productList)
	{
		if (productList[i].selected== true) return false;
	}
	
	
	if (isStd) {
        theButton = e.which;
      }
      else {
        theButton = event.button;
      }

	if (theButton == 1)
	{

	productList[code].selected = true; 
	
	setProductStartCoordinates(code);
	
	selectedImage = document.getElementById(code);
	selectedImage.id = code + "-selected";
	
	draggingImage = document.getElementById("draggingImage");
	draggingImage.id = code;
	draggingImage.src = productList[code].src;
	draggingImage.height=40;
	draggingImage.width=40;
	
	if (isStd) {
     document.getElementById(code).style.left = productList[code].left + document.body.scrollLeft;
     document.getElementById(code).style.top = productList[code].right + document.body.scrollTop;
   }
   else {
      document.getElementById(code).style.pixelLeft = productList[code].left;
      document.getElementById(code).style.pixelTop = productList[code].right;
   }
	//setting the initial coordinates for the object
	
	toggleVisibility(code);

	
	
	
	 if (isStd) {
          xWin = e.pageX;
	      yWin = e.pageY;
		  
		  //where it was clicked 
		  clickX = e.pageX;
		  clickY = e.pageY;
		  
          //dragImageWidth = Math.round(productList[code].width / 2);
          //dragImageHeight = Math.round(productList[code].height / 2);
		  dragImageWidth = Math.round(40 / 2);
          dragImageHeight = Math.round(40 / 2);
     
	 	  theLayer = document.getElementById(code);
	 
          theLayer.style.left = xWin - dragImageWidth;
          theLayer.style.top = yWin - dragImageHeight;
		  
		
		  
        }
		else
		{
			offsetx=ie5? event.clientX : e.clientX
			offsety=ie5? event.clientY : e.clientY
	
			clickX = event.clientX;
		 	clickY = event.clientY;
	
			//middleY = Math.round(productList[code].width / 2 );
			//middleX = Math.round(productList[code].height / 2);
			middleY = Math.round(40 / 2 );
			middleX = Math.round(40 / 2);

			document.getElementById(code).style.left = offsetx - middleY;
			document.getElementById(code).style.top = offsety - middleX;
		}
	
	
	if (isStd) { 
  	  	  document.captureEvents(Event.MOUSEMOVE);
          oldX = e.clientX;
          oldY = e.clientY;
          startX = parseInt(theLayer.style.left)
	  	  startY = parseInt(theLayer.style.top)
		  
        } else {
	      oldX = window.event.offsetX;
	      oldY = window.event.offsetY;
        }
	
	document.onmousemove = drag;
	}
	return false;
	
}

//function to get shopping bag coordinates
function getShoppingBagCoordinates()
{
	if (isStd) {
      dropID = document.getElementById("shopping_bag");
      bagTop = dropID.offsetTop + document.body.scrollTop;
	  bagLeft = dropID.offsetLeft + document.body.scrollLeft;
	  dropID = document.getElementById("bag_with_goods");
	  bagTop += dropID.offsetTop + document.body.scrollTop;
	  bagLeft += dropID.offsetLeft + document.body.scrollLeft;
	  
    }
    if (isIE) {
      dropID = document.getElementById("shopping_bag");
      bagTop = dropID.offsetTop; 
	  bagLeft = dropID.offsetLeft;
	  dropID = document.getElementById("bag_with_goods");
	  bagTop += dropID.offsetTop; 
	  bagLeft += dropID.offsetLeft;
    }
	
	
	height = document.getElementById("bag_with_goods").offsetHeight;
	bagHeight = '155px';
	bagTop = '250';
	bagLeft = '650';
	//document.getElementById("shopping_cart").style.height;
	bagWidth = '150px';
	//document.getElementById("shopping_cart").style.width;
	
	bagHeight = parseInt(bagHeight.replace(/px/,""));
	bagWidth = parseInt(bagWidth.replace(/px/,""));
	//window.alert( bagLeft + "-" + bagTop + "-" +height + "-" + bagWidth);
}

//function to get shopping bag coordinates
function setProductStartCoordinates(code)
{
	if (isStd) {
      dropID = document.getElementById(code);
      productList[code].top = dropID.offsetTop + document.body.scrollTop;
	  productList[code].left = dropID.offsetLeft + document.body.scrollLeft;
    }
    if (isIE) {
      dropID = document.getElementById(code);
      productList[code].top = dropID.offsetTop; 
	  productList[code].left = dropID.offsetLeft; 
    }

}

//function to determine if an object is dragged over the shopping bag
function isOverShoppingBag(code , e)
{
	if (isStd) {
          xWin = e.pageX;
	      yWin = e.pageY;
    }
	else
	{
		xWin=event.clientX + document.body.scrollLeft;
		yWin=event.clientY + document.body.scrollTop;
	}
	
	var is= false;
	
	if (yWin >= bagTop -20)
	{
		if (yWin <= parseInt(bagTop) + parseInt(bagHeight) - 20 + bagItems* 40)
		{
			if (xWin >= bagLeft -20)
			{
				if (xWin <= parseInt(bagLeft) + parseInt(bagWidth) + 20)
				{
				is = true;			
				var tt = bagLeft + bagWidth;
				//window.alert( bagLeft + "-" + bagTop + "-" + bagHeight + "-" + tt + "\r\n" + xWin + "-" + yWin);
				}
			}
		}
	}
	/*if (is==true)
	{
		document.getElementById("img_bag").src='./images/bag/bag_on.gif';
		document.getElementById("img_bag1").src='./images/bag/bag1_on.gif';
		document.getElementById("img_bag3").src='./images/bag/bag3_on.gif';
	}
	else
	{
		document.getElementById("img_bag").src='./images/bag/bag.gif';
		document.getElementById("img_bag1").src='./images/bag/bag1.gif';
		document.getElementById("img_bag3").src='./images/bag/bag3.gif';
	}*/
	return is;
}

// show and hide the products image that will be dragged 
function toggleVisibility(code) {

   // alert("Here");

   if (isStd) {
     theObj = document.getElementById(code);
     if (theObj.style.visibility == "hidden" || theObj.style.visibility == "") {
       theObj.style.visibility = "visible";
     } else {
       theObj.style.visibility = "hidden";
     }
   }
   else {
     if (document.getElementById(code).style.visibility == "hidden" || document.getElementById(code).style.visibility == "") {
       document.getElementById(code).style.visibility = "visible";
     } else {
       document.getElementById(code).style.visibility = "hidden";
     }
   }
}

//function to animate the shopping bag 
function snapBack(layerToSnap, startX, startY, endX, endY, steps) {
   isOneSelected = true;
   if (snap==false)
   {
	   snap = true;
   snapCurrent++;

   if (snapCurrent == 1) {
       multi = 0;
   } else { 
       multi = (1 - Math.pow(0.9, snapCurrent - 1)) / (1 - Math.pow(0.9, steps - 1));
   }

   snapX = endX + (startX - endX) * multi;
   snapY = endY + (startY - endY) * multi;

   // alert("Snap Back Step #" + snapCurrent + "/" + steps + " (move to " + snapX + " / " + snapY);
 
   if (isStd) {
     document.getElementById(layerToSnap).style.left = snapX;
     document.getElementById(layerToSnap).style.top = snapY;
   }
   else {
      document.getElementById(layerToSnap).style.pixelLeft = snapX;
      document.getElementById(layerToSnap).style.pixelTop = snapY;
   }
   
   if (snapCurrent == steps) {
     clearInterval(snapTimer);
	 isOneSelected =false;
     toggleVisibility(layerToSnap);
	 
    draggingImage = document.getElementById(layerToSnap);
	draggingImage.id = "draggingImage";
	
	oldLayer = document.getElementById(layerToSnap + "-selected");
	oldLayer.id = layerToSnap;
   }
   snap = false;
   }
   
}

//function that will change the look of the shopping bag if product is dragged over it
function productIsOverShoppingBag(on_off)
{
	if (on_off == 'on')
	{
		document.getElementById("shopping_cart").style.color = "#CC0000";
	}
	else
	{
		document.getElementById("shopping_cart").style.color = "#000000";
	}
}
//function to update the shopping cart | separates products , - separates caracteristics
function addToShoppingCart(theCode) {
	quantity = parseInt(document.getElementById("quantity-"+ theCode).value);
	window.document.getElementById("checkout_button").src='images/wait.gif';
	window.document.getElementById("checkout_button").disabled=true;
	
	var found=0;
	
	for (var i in bagProducts)
	{
		if (bagProducts[i].code==theCode && bagProducts[i].id != -1)
		{
				found=1;
				bagProducts[i].quantity += quantity;
		}
	}
	if (found==0)
	{
	totalItems++;
	id = totalItems +1;
	addBagProduct(id , theCode, quantity , getFirstLov1(theCode), getFirstLov2(theCode), getFirstLov3(theCode), getFirstLov4(theCode) , getFirstLov5(theCode));
	shoppingBagCodes = shoppingBagCodes + "|" + theCode + "-" + id + "-" + quantity + "-"+ getFirstLov1(theCode) +"-"+ getFirstLov2(theCode)+"-"+ getFirstLov3(theCode) +"-"+ getFirstLov4(theCode) +"-"+ getFirstLov5(theCode) ;
	}
    shoppingBagCodes = shoppingBagCodes + "|" + theCode + "-" + id + "-" + quantity + "-"+ getFirstLov1(theCode) +"-"+ getFirstLov2(theCode)+"-"+ getFirstLov3(theCode) +"-"+ getFirstLov4(theCode) +"-"+ getFirstLov5(theCode) ;
	document.getElementById("shoppingCartFrame").src = 'shopping_bag.php?code=' + theCode + '&q=' + quantity + '&id=' + id + "&at1=" + getFirstLov1(theCode) + "&at2=" + getFirstLov2(theCode)+ "&at3=" + getFirstLov3(theCode)+ "&at4=" + getFirstLov4(theCode)+ "&at5=" + getFirstLov5(theCode) ;
	//window.location = 'shopping_bag.php?code=' + theCode + '&q=' + quantity + '&id=' + id + "&at1=" + getFirstLov1(theCode) + "&at2=" + getFirstLov2(theCode)+ "&at3=" + getFirstLov3(theCode)+ "&at4=" + getFirstLov4(theCode)+ "&at5=" + getFirstLov5(theCode) ;
	
	writeHTML(document.getElementById("shopping_cart"), drawShoppingCartCode());
	
	//document.getElementById("img_bag").src='./images/bag/bag.gif';
		//document.getElementById("img_bag1").src='./images/bag/bag1.gif';
		//document.getElementById("img_bag3").src='./images/bag/bag3.gif';
}


function innerHTML(html) {
  while (this.hasChildNodes()) this.removeChild(this.lastChild);
  var range = document.createRange();
  range.setStartAfter(this);
  this.appendChild(range.createContextualFragment(html));
}

function writeHTML(o,html) {
  if (document.getElementById)       o.innerHTML = html;
  else if (document.all)             o.innerHTML = html;
  else if (document.layers) {
    o.document.open();
    o.document.write(html);
    o.document.close();
  }
}
// the html that will be written to draw the shopping cart
function drawShoppingCartCode() {
	var output='';
	//first get all the prodcuts
	bagItems =0;
	bagPrice =0;
	var j=0;
	for (var i in bagProducts)
	{
		//then we split them into caracteristics
		if (j>=0)
		{
		code = bagProducts[i].code;
		id = bagProducts[i].id;
		
		if (id > -1)
		{
		bagItems++;
		quantity = bagProducts[i].quantity;
		prodPrice = productList[code].price;
		bagPrice += quantity * prodPrice;
		//window.alert(bagPrice + " " + quantity + " " + prodPrice + " " + productList[code].price);
		//var diiv = 
	
		/*
	    if (productList[code].at1List == "")
		{
			Lov1="";
		}
		else
		{
		var Lov1 = '<tr><td colspan="2" height="25"><select class="lovs" name="at1_' + id +'_in_bag" id="at1_'+ id +'_in_bag""';
			
			var bb = productList[code].at1List;
			
			var b = bb.split('|');
			for (var jj=0; jj < b.length-1; jj++)
			{
				
				var  xx = b[jj];
				//window.alert(b.length + "-" + xx + "-" + jj);
				Lov1 = Lov1 + '<option value="'+ jj +'">'+ LOVS[xx].value + '</option>';
			}
			Lov1 = Lov1 + '</select></td></tr>';
		}
		*/
		//alert(productList[code].price);
		 xx = parseFloat(productList[code].price);
		 xx = xx.toFixed(2);
		output += '<tr><td height="5"></td></tr><tr><td align="left">' + 
		'<table cellspacing="0" cellpadding="0" border="0" width="146">'+
		'<tr valign="top"><td rowspan="2" width="46" align="right">' + 
		'<img src="' + productList[code].src + '" width = "40" height="40" class="shbag"></td>' + 
		'<td colspan="5" width="102" align="center"><span class="anormal">'+ productList[code].name +'</span></td></tr>' +
		'<tr><td width="50" align="center"><span class="anormal" style="font-size:7pt;">&pound; '+ xx +'</span></td>'+
		'    <td width="13"><input type="text" class="qquantity" size="1" name="q_' + id +'_in_bag" id="q_'+ id +'_in_bag" value="'+ quantity +'" readonly="true"></td>' +
		'    <td width="13"><a href="javascript:quantityDown('+ id +')"><img src="./images/buttons/q_minus.gif" class="prod" border="0" alt="Click to Decrease Quantity"></a></td>'+
		'	 <td width="13"><a href="javascript:quantityUp('+ id +')"><img src="./images/buttons/q_plus.gif" class="prod" border="0" alt="Click to Increase Quantity"></td>'+
		'    <td width="13"><img src="./images/buttons/q_delete.gif" onClick="removeFromCart('+ id +')" style="cursor:pointer;"></td></tr>'+
		'</table>' + 
		'</td></tr>'; 
		
		}
		j++;
		}
	}
	
	
	if (bagItems==0)
	{
		output = "<td width='400' height='100'><center><span class='normal' >Your shopping bag is empty. <br> Please drag and drop products into the shopping bag.</span></center></td>"
	}
	// we put the products into a table
	
    output = '<div id="shbag_bg">'+
	'<table cellspacing="0" cellpadding="0" border="0">' +
		output +
	'</table>' +
	'</div>';
		
	bagPrice = bagPrice.toFixed(2);
	var bag_value_html = "<center><span class='normal' style='font-size:8pt'><u>"+bagItems + " Items</u> | <u>Total &pound;" + bagPrice +"</u></span><center>"; 
	writeHTML(document.getElementById("bag_value"), bag_value_html);
	//+ shoppingBagCodes
	return output;
}

function makeVisible(code)
{
	if (isStd) {
     theObj = document.getElementById(code);
       theObj.style.visibility = "visible";
   }
   else {
       document.getElementById(code).style.visibility = "visible";
   }
}

function makeHidden(code)
{
	if (isStd) {
     theObj = document.getElementById(code);
     theObj.style.visibility = "hidden";
   }
   else {
       document.getElementById(code).style.visibility = "hidden";
   }
}


//scrolling functions 
function pageScrollRight() {
	
	var LayerWidth = bagItems * 90 - 3 * 90;

	if (scrollDiv > -LayerWidth)
	{	
		scrollOn = true;
		scrollDiv -= 10;
		var Layer = document.getElementById("list_of_products");
		Layer.style.left = scrollDiv + "px";
    	scrolldelay = setTimeout('pageScrollRight()',50); // scrolls every 100 milliseconds
	}
}

function pageScrollLeft() {
		
		if (scrollDiv<0)
		{
			
		scrollOn = true;
		scrollDiv += 10;
		var Layer = document.getElementById("list_of_products");
		Layer.style.left = scrollDiv + "px";
    	scrolldelay = setTimeout('pageScrollLeft()',50); // scrolls every 100 milliseconds
		}
}


function stopScroll() {
	if (scrollOn==true)
	{
    	clearTimeout(scrolldelay);
		scrollOn = false;
	}
}
//--------------------function to modify the quantity for a product
function quantityUp(code)
{
	var obj = document.getElementById("q_" + code + "_in_bag");
	var oldQ;
	oldQ = obj.value;
	newQ = parseInt(oldQ) + 1;
	obj.value = newQ;
	bagProducts[code].quantity = newQ;
	document.getElementById("shoppingCartFrame").src = 'edit_quantity.php?id=' + code + '&w=0';
	writeHTML(document.getElementById("shopping_cart"), drawShoppingCartCode());
}
function quantityDown(code)
{
	var oldQ;
	oldQ = document.getElementById("q_" + code + "_in_bag").value;
	newQ = oldQ - 1;
	if (newQ==0)
	{
			newQ=1;
	}
	document.getElementById("q_" + code + "_in_bag").value = newQ;
	bagProducts[code].quantity = newQ;
	document.getElementById("shoppingCartFrame").src = 'edit_quantity.php?id=' + code + '&w=1';
	writeHTML(document.getElementById("shopping_cart"), drawShoppingCartCode());
}

//--------------------- function to remove object from cart ------------
function removeFromCart(id)
{
	bagProducts[id].id = -1;
	writeHTML(document.getElementById("shopping_cart"), drawShoppingCartCode());
	if (scrollDiv>0)
	{
	scrollDiv -= 90;
	}
	//var Layer = document.getElementById("list_of_products");
	//var tmpLeft = Layer.style.left
	//Layer.style.left = tmpLeft - scrollDiv + "px";
	document.getElementById("shoppingCartFrame").src = 'remove_from_bag.php?id=' + id;
	//document.location = 'remove_from_bag.php?id=' + id;
}

//get first LOV
function getFirstLov1(code)
{
	var b = productList[code].at1List
	if (b=="")
	{
			return 0
	}
	var temp = new Array();
	temp = b.split('|');
	return temp[0];	
}
function getFirstLov2(code)
{
	var b = productList[code].at2List
	if (b=="")
	{
			return 0
	}
	var temp = new Array();
	temp = b.split('|');
	return temp[0];	
}
function getFirstLov3(code)
{
	var b = productList[code].at3List
	if (b=="")
	{
			return 0
	}
	var temp = new Array();
	temp = b.split('|');
	return temp[0];	
}
function getFirstLov4(code)
{
	var b = productList[code].at4List
	if (b=="")
	{
			return 0
	}
	var temp = new Array();
	temp = b.split('|');
	return temp[0];	
}
function getFirstLov5(code)
{
	var b = productList[code].at5List
	if (b=="")
	{
			return 0
	}
	var temp = new Array();
	temp = b.split('|');
	return temp[0];	
}