

function clearbox(val){
if(val=='Email')
	document.getElementById('email').value="";
if(val=='Password'){
	var input=document.getElementById('password'); 
	var input2= input.cloneNode(false); 
	input2.type='password'; 
	input.parentNode.replaceChild(input2,input); 	
	document.getElementById('password').value="";
	}
if(val=='Search')
	document.getElementById('Search').value="";
}


function user_billing_same(cb)
{
	if(cb.checked==true)
	{
		document.getElementById('UserBillAdd1').value=document.getElementById('UserShipAdd1').value;
		document.getElementById('UserBillAdd2').value=document.getElementById('UserShipAdd2').value;
		document.getElementById('UserBillAdd3').value=document.getElementById('UserShipAdd3').value;
		document.getElementById('UserBillCountry').value=document.getElementById('UserShipCountry').value;
		document.getElementById('UserBillZip').value=document.getElementById('UserShipZip').value;
	}
}


function checkout_billing_same(cb)
{
	if(cb.checked==true)
	{
		document.getElementById('ShoppingCartBillAdd1').value=document.getElementById('ShoppingCartShipAdd1').value;
		document.getElementById('ShoppingCartBillAdd2').value=document.getElementById('ShoppingCartShipAdd2').value;
		document.getElementById('ShoppingCartBillAdd3').value=document.getElementById('ShoppingCartShipAdd3').value;
		document.getElementById('ShoppingCartBillCountry').value=document.getElementById('ShoppingCartShipCountry').value;
		document.getElementById('ShoppingCartBillZip').value=document.getElementById('ShoppingCartShipZip').value;
	}
}

function change_category(obj)
{
	if(obj.value!="")
		obj.form.submit();
}
//for advance search
function change_producttype(val)
{
	window.location="http://ubsfs/ubspress2/advancesearch.php?show_form=" + val;	
}

function viewBySubject(subject)
{
	var form=document.getElementById('ProductSearchForm');
	
	document.getElementById('SearchCategory').value=subject;
	
	form.submit();
	
}

function change_sort(obj)
{
	if(obj.value!="")
		obj.form.submit();
}


function update_qty(action, qty, product_id)
{
	if(action=='I')
	{
		document.getElementById(product_id+'Qty').value=parseInt(document.getElementById(product_id+'Qty').value)+qty;
	}
	
	if(action=='D')
	{
		if(parseInt(document.getElementById(product_id+'Qty').value)>0)
			document.getElementById(product_id+'Qty').value=parseInt(document.getElementById(product_id+'Qty').value)-qty;
		else
			alert("You cannot reduce the Qty anymore...");
	}
}

function move_option_from_a_to_b(listA,listB)
{
	//var optionsA=listA.options;
	//var optionsB=listB.options;
	//var valueA=listA.value;
	if (listA.selectedIndex >= 0)
	{
		//remove from listA
		for (i =0; i<listA.length; i++) 
		{
			if (listA.options[i].selected) 
			{
				for (k =0; k<listB.length; k++) //check if it's in listB
				{
					if(listB.options[k].value==listA.options[i].value)
					{
						alert("Selected library already in destination list.");
						listA.remove(i);
						return false;
					}
				}
				
				var newOpt = document.createElement('option');
				newOpt.text = listA.options[i].text;
				newOpt.value = listA.options[i].value;
				try {
					listB.add(newOpt, null); // standards compliant; doesn't work in IE
				}
				catch(ex) {
					listB.add(newOpt); // IE only
				}

				listA.remove(i);
				
			}
		}

	}
}

function profile_putin_library()
{
	var listA=document.getElementById('UserLibraries');
	var listB=document.getElementById('UserUserLibraries');
	
	move_option_from_a_to_b(listA,listB);
	
	var interested_libraries="";
	for (k =0; k<listB.length; k++) //check if it's in listB
	{
		if(interested_libraries!="")
			interested_libraries+="|";
		interested_libraries+=listB.options[k].value;
	}
	document.getElementById('UserInterestedLibraries').value=interested_libraries;
	
}

function profile_takeout_library()
{
	var listA=document.getElementById('UserUserLibraries');
	var listB=document.getElementById('UserLibraries');
	
	move_option_from_a_to_b(listA,listB);
	
	var interested_libraries="";
	for (k =0; k<listA.length; k++) //check if it's in listB
	{
		if(interested_libraries!="")
			interested_libraries+="|";
		interested_libraries+=listA.options[k].value;
	}
	document.getElementById('UserInterestedLibraries').value=interested_libraries;
}


function add_cart(product_id,action_cart,urlbase)
{
	var url=urlbase+'/action:A/item:'+product_id+'/qty:1/cart:'+action_cart;
	//alert(url);
	$.get(
		url, 
		function(data){
  			//alert("Data Loaded: "+data);
			document.getElementById('shopping_cart_div').innerHTML=data;
		},
		'html'
	);

	
}

function ubs_select_all(obj,cbx_list)
{
	for(i=0;i<cbx_list.length;i++)
	{
		document.getElementById(cbx_list[i]).checked=obj.checked;
	}
}

function ubs_check_select(cbx_list)
{
	
	var i=0;
	var rtn=false;
	for(i=0;i<cbx_list.length;i++)
	{
		if(document.getElementById(cbx_list[i]).checked)
		{
			rtn=true;
		}
	}
	
	return rtn;
}
