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("msgbox","Please Check the item(s) you want to remove from Wishlist")
	else
	{
		strProgressMessage="Removing item from Wishlist...<img src='manager/images/ajax2.gif' hscpace=10>";
		document.getElementById("cp_ids").value=str;

		document.getElementById("mode").value="delete";

		document.getElementById("cart_pg_frm").submit();
		//doAjax("manager/includes/cart.php?mode=delete","cp_id="+str,"listmsgbox","POST",strProgressMessage,0);
	}
}



function renderProductOptions(str)
{
	
		//alert(str);
		hide('options');
		ax=str.toString().split("~~");
		
		if (str!="")
		{
			show('actions');
		}
		else
		{
			hide('actions');
		}
		
		for (i=0;i<ax.length-1;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(',','_')+');"  >');
				}
				
				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
			{
				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;//----------
		}
	}
	
	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)
{
	
	//alert(objID);
	
	
	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=(isNaN(objQty[i].value));
				
				//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;
			
		}
	}
	
	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);
		
		//alert(qtys);
		document.getElementById("cp_qtys").value=qtys;
		document.getElementById("cp_ids").value=ids;		
		document.getElementById("mode").value="updatecart";
		document.cart_pg_frm.submit();
	}

}
function getOptionsPrice(prod_id)
{
	strOptions=getSelectedValues("option_controls");
	
	if (strOptions!="")
	{
		strProgressMessage="<br><img src='manager/images/ajax2.gif' hscpace=10>"
		chkqty=document.getElementById("qty").value;
		param="prod_id="+prod_id+"&options="+strOptions+"&chkqty="+chkqty;	
		doAjax("manager/includes/cart.php?mode=getoptionprice",param,"option_msgbox","POST",strProgressMessage,0);
	}
}



function addToCart(prod_id)
{
	strOptions="";
	strAccessories="";
	strQty=document.getElementById("qty").value;
	if(checkSelectedValues("option_controls"))
	{
	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>"
		
		
		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
	{
		updateMessage("msgbox","Please enter one or more quantities")
	}
	
	}
	
}


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++)
			{
				if (objID[i].checked && objID[i].value!="") 
				{
					ids+=((ids=="")?"":",")+objID[i].value;
					hide("item1_"+objID[i].value);
					hide("item1_"+objID[i].value+"_line");
				}
			}
		}
		else
		{
			ids=objID.value;
			hide("item1_"+objID.value);
			hide("item1_"+objID.value+"_line");
		}
	}
	
	//alert(ids);
	//return false;
	if (ids=="")
		updateMessage("msgbox1","Nothing to move!")
	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 checkSelectedValues(control)
{
	opt=document.getElementById(control);
	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=="0" && tmp.lang=="must") 
					str=str+"Please select "+tmp.title+" \n";
								
			}
		}
	}
	
	if(str=="")
	return true;
	else
	{
		alert(str);
		return false;
	}
	
	
	
}

function getSelectedValues(control)
{
	opt=document.getElementById(control);
	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;
}
