function deleteProducts(obj)
{
	
	str="";
	
	if(obj)
	{
		if (obj.length)
		{
			for (i=0;i<obj.length;i++)
			{
				tmp=obj[i];
				if (tmp.checked && tmp.value!="") 
				{
					str+=((str=="")?"":",")+tmp.value;
					hide("item_"+tmp.value);
					hide("item_"+tmp.value+"_line");
				}
			}
		}
		else
		{
			tmp=obj;
			if (tmp.checked && tmp.value!="") 
			{
				str=tmp.value;
				hide("item_"+tmp.value);
				hide("item_"+tmp.value+"_line");
			}
		}
	}
	
	if (str=="")
		updateMessage("msgbox","Please Check the item(s) you want to remove from Cart")
	else
	{
		strProgressMessage="Removing item from cart...<img src='manager/images/ajax2.gif' hscpace=10>";		
		
		//doAjax("manager/includes/cart.php?mode=delete","cp_id="+str,"msgbox","POST",strProgressMessage,0);
		
		//doAjax("manager/includes/cart.php?mode=updatecart","cp_ids="+ids+"&cp_qtys="+qtys,"msgbox","POST",strProgressMessage,0);
		
		//document.getElementById("cp_qtys").value=qtys;
		document.getElementById("cp_ids").value=str;
		document.getElementById("mode").value="delete";
		document.getElementById("cart_pg_frm").submit();
	}
}

function deletewishProducts(obj)
{
	
	str="";
	
	if(obj)
	{
		if (obj.length)
		{
			for (i=0;i<obj.length;i++)
			{
				tmp=obj[i];
				if (tmp.checked && tmp.value!="") 
				{
					str+=((str=="")?"":",")+tmp.value;
					hide("item1_"+tmp.value);
					hide("item1_"+tmp.value+"_line");
				}
			}
		}
		else
		{
			tmp=obj;
			if (tmp.checked && tmp.value!="") 
			{
				str=tmp.value;
				hide("item1_"+tmp.value);
				hide("item1_"+tmp.value+"_line");
			}
		}
	}
	
	if (str=="")
		updateMessage("msgbox1","<b>Please Check the item(s) you want to remove from Wishlist</b>")
	else
	{
		strProgressMessage="Removing Item from wishlist...<img src='manager/images/ajax2.gif' hscpace=10>";
		document.getElementById("cp_ids").value=str;
		document.getElementById("mode").value="deletefromwishlist";
		document.getElementById("cart_pg_frm").submit();
		
	}
}




function renderProductOptions(str)
{
	
		hide('options');
		ax=str.toString().split("~~");
		
		
		if (str!="")
		{
			show('actions');
		}
		else
		{
			hide('actions');
		}
		
		for (i=0;i<ax.length;i++)
		{
			
			ay=ax[i].split("##");
			
			if (i==0)
			{
				if (ay[0]!=0)
				{
						updateMessage('td0','<img src="images/delete.gif" style="cursor:pointer" title="Remove" alt="Remove"  border="0" onClick="del_group('+ay[1].replace(',','_')+');"  >');
				}
				//alert(pp);
				updateMessage('td1',ay[2]);
				updateMessage('td2',ay[3]);
				updateMessage('td3',ay[4]);
				updateMessage('td4',ay[5]);
				updateMessage('td5',ay[6]);
				updateMessage('td6',ay[7]);//------
				
			}
			else
			{
				//alert("TT");
				addItemRow(ay[0],ay[1],ay[2],ay[3],ay[4],ay[5],ay[6],ay[7],0);///---------
			}
		}
}



function updateProductOptions(prod_id)
{
	//alert(prod_id);
	ids="";
	qtys="";
	prices="";
	codes="";
	weights="";
	comments="";//-------
	objID=document.form2.ids;
	objQty=document.form2.qtys;
	objPrice=document.form2.prices;
	objCode=document.form2.codes;
	objWeight=document.form2.weights;
	objComment=document.form2.comments;//-------
	
	//alert(objWeight);
	if(objID)
	{
		if (objID.length)
		{
			for (i=0;i<objID.length;i++)
			{
				
				ids+=((i==0)?"":"~~")+objID[i].value;
				qtys+=((i=="")?"":"~~")+objQty[i].value;
				prices+=((i=="")?"":"~~")+objPrice[i].value;
				codes+=((i=="")?"":"~~")+objCode[i].value;
				weights+=((i=="")?"":"~~")+objWeight[i].value;
				comments+=((i=="")?"":"~~")+objComment[i].value;//-------
			}
		}
		else
		{
			ids=objID.value;
			qtys=objQty.value;
			prices=objPrice.value;
			codes=objCode.value;
			weights=objWeight.value;
			comments=objComment.value;//----------
		}
	}
	//alert(ids);
	if (ids=="")
		updateMessage("msgbox","Nothing to update!")
	else
	{
		strProgressMessage="Updating cart...<img src='images/ajax2.gif' hscpace=10>";
		//alert(codes);
		//alert(comments);
		doAjax("includes/products.php?mode=updateproductoptions","prod_id="+prod_id+"&ids="+ids+"&qtys="+qtys+"&prices="+prices+"&codes="+codes+"&weights="+weights+"&comments="+comments,"actionmessage","POST",strProgressMessage,0,"renderProductOptions");//--------
	}	
}


function updateCart(objID,objQty)
{
	ids="";
	qtys="";
	
	var flag=false;
	if(objID)
	{
		if (objID.length)
		{
			for (i=0;i<objID.length;i++)
			{
				
				ids+=((i==0)?"":",")+objID[i].value;
				qtys+=((i=="")?"":",")+objQty[i].value;
				
				flag=(isPositiveInteger(objQty[i].value));
                if (flag==false)
					break;
				//alert(flag+"-"+objQty[i].value);
				//if(flag)
				//{
					//hide("item_"+objID[i].value);
					//hide("item_"+objID[i].value+"_line");
				//}
			}
		}
		else
		{
			ids=objID.value;
			qtys=objQty.value;
			flag=(isPositiveInteger(qtys));
			
		}
	}
	if (flag==true)
	{
		if (ids=="")
			updateMessage("msgbox","Nothing to update!")
		else
		{		
			strProgressMessage="Updating cart...<img src='manager/images/ajax2.gif' hscpace=10>";
			//doAjax("manager/includes/cart.php?mode=updatecart","cp_ids="+ids+"&cp_qtys="+qtys,"msgbox","POST",strProgressMessage,0);
			
			document.getElementById("cp_qtys").value=qtys;
			document.getElementById("cp_ids").value=ids;
			document.getElementById("mode").value="updatecart";
			document.getElementById("cart_pg_frm").submit();
		}
	}
	else
	   {
		   updateMessage("msgbox","Please Enter Valid Qty");
		   }

}
function getOptionsPrice(prod_id)
{
	strOptions=getSelectedValues("option_controls");
	
	if (strOptions!="")
	{
		strProgressMessage="<br><img src='manager/images/ajax2.gif' hscpace=10>"
		param="prod_id="+prod_id+"&options="+strOptions;	
		doAjax("manager/includes/cart.php?mode=getoptionprice",param,"option_msgbox","POST",strProgressMessage,0);
	}
}



function addToCart(prod_id,msg)
{
	strOptions="";
	strAccessories="";
	strQty=document.getElementById("qty").value;
	
		if(isPositiveInteger(strQty))
	{
		strOptions=getSelectedValues("option_controls")
		strAccessories=getSelectedValues("acc_controls")
		strProgressMessage="Adding product to Cart...<br><br><img src='manager/images/ajax2.gif' hscpace=10>"
		
		
		document.getElementById("frm_qty").value=strQty;
		document.getElementById("frm_prod_id").value=prod_id;
		document.getElementById("frm_options").value=strOptions;
		document.getElementById("frm_accessories").value=strAccessories;
		document.getElementById("mode").value="add";
		document.getElementById("cart_frm").submit();
		
		
		//param="prod_id="+prod_id+"&qty="+strQty+"&options="+strOptions+"&accessories="+strAccessories;	
		//doAjax("manager/includes/cart.php?mode=add",param,"msgbox","POST",strProgressMessage,0);		
		//window.location="manager/includes/cart.php?mode=add&"+param;
	}

	else
	{
		//var msg="Please enter one or more quantities"
		updateMessage("msgbox",msg);
	}
	
}


function addToWishlist(prod_id)
{
	strOptions="";
	strAccessories="";
	strQty=document.getElementById("qty").value;
	
	if(strQty>0)
	{
		strOptions=getSelectedValues("option_controls")
		strAccessories=getSelectedValues("acc_controls")
		strProgressMessage="Adding product to Cart...<br><br><img src='manager/images/ajax2.gif' hscpace=10>"
		param="prod_id="+prod_id+"&qty="+strQty+"&options="+strOptions+"&accessories="+strAccessories;	
		
		document.getElementById("frm_qty").value=strQty;
		document.getElementById("frm_prod_id").value=prod_id;
		document.getElementById("frm_options").value=strOptions;
		document.getElementById("frm_accessories").value=strAccessories;
		document.getElementById("mode").value="addlist";
		document.getElementById("cart_frm").submit();
		//doAjax("manager/includes/cart.php?mode=addlist",param,"msgbox","POST",strProgressMessage,0);
		
	}
	else
	{
		updateMessage("msgbox","Please enter one or more quantities")
	}
	
}


function moveProducts(objID)
{
	
	ids="";
	var flag=false;
	if(objID)
	{
		if (objID.length)
		{
			for (i=0;i<objID.length;i++)
			{
				tmp=objID[i];
				if (tmp.checked && tmp.value!="") 
				{
					ids+=((ids=="")?"":",")+tmp.value;
					//hide("item_"+tmp.value);
					//hide("item_"+tmp.value+"_line");
				}
			}
		}
		else
		{
			tmp=objID;
			if (tmp.checked && tmp.value!="") 
			{
				ids=tmp.value;
				//hide("item_"+tmp.value);
				//hide("item_"+tmp.value+"_line");
			}
		}
		
	}
	
	if (ids=="")
		updateMessage("msgbox1","<b>Nothing to move!</b>")
	else
	{		
		strProgressMessage="Updating cart...<img src='manager/images/ajax2.gif' hscpace=10>";
		//document.getElementById("cp_qtys").value=qtys;
		document.getElementById("cp_ids").value=ids;
		document.getElementById("mode").value="movelist";
		document.getElementById("cart_pg_frm").submit();
		//doAjax("manager/includes/cart.php?mode=movelist","cp_ids="+ids,"msgbox","POST",strProgressMessage,0);
	}

}


function getSelectedValues(control)
{
	//alert(control);
	opt=document.getElementById(control);
	//alert(opt.value);
	controls=opt.value.split(",");
	str="";
	
	if (controls!="") //product has options
	{
		
		for (i=0;i<controls.length;i++)
		{
			tmp=eval("document.getElementById('"+controls[i]+"')");
			if (tmp.type=="checkbox")
			{
				if (tmp.checked && tmp.value!="") 
					str+=((str=="")?"":",")+tmp.value;
			}
			else if (tmp.type=="select-one")
			{
				if (tmp.value!="") 
					str+=((str=="")?"":",")+tmp.value;
			}
		}
	}
	return str;
}


function isPositiveInteger (s)
   {   var secondArg = false;

       if (isPositiveInteger.arguments.length > 1)
          secondArg = isPositiveInteger.arguments[1];

       // The next line is a bit byzantine.  What it means is:
       // a) s must be a signed integer, AND
       // b) one of the following must be true:
       //    i)  s is empty and we are supposed to return true for
       //        empty strings
       //    ii) this is a positive, not negative, number

       return (isSignedInteger(s, secondArg)
          && ( (isEmpty(s) && secondArg)  || (parseInt (s) > 0) ) );
   }
   function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

   function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }
function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

   function isSignedInteger (s)

   {   if (isEmpty(s))
      if (isSignedInteger.arguments.length == 1) return false;
      else return (isSignedInteger.arguments[1] == true);

      else {
         var startPos = 0;
         var secondArg = false;

         if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];

         // skip leading + or -
         if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
            startPos = 1;
         return (isInteger(s.substring(startPos, s.length), secondArg))
      }
   }


