function addToCart(id,cpt)
{
	divId = id;
	encr = 1;

	Pdiv_link = document.getElementById('o_link_addtocart_'+divId+'_'+cpt);
	Pdiv_wait = document.getElementById('o_wait_addtocart_'+divId+'_'+cpt);
	Pdiv_ready = document.getElementById('o_ready_addtocart_'+divId+'_'+cpt);
	
	if (document.getElementById('oUpdate_encr_original'))
	{
		encr = document.getElementById('oUpdate_encr_original').value;
		if (encr > 1) 
		{
			id = encr;
			encr = null;
		}
	}
	
	if (id!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
	
		updater = new Ajax.Updater (
			'o_ready_addtocart_'+divId+'_'+cpt,
			'/AddToCart.php',
			{
				method: 'post',
				parameters: {action:'ajax',item_id:id,cpt:cpt,divId:divId,encr:encr},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function addToWishlist(id,cpt)
{
	Pdiv_link = document.getElementById('o_link_addtowishlist_'+id+'_'+cpt);
	Pdiv_wait = document.getElementById('o_wait_addtowishlist_'+id+'_'+cpt);
	Pdiv_ready = document.getElementById('o_ready_addtowishlist_'+id+'_'+cpt);
				
	if (id!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
	
		updater = new Ajax.Updater (
			'o_ready_addtowishlist_'+id+'_'+cpt,
			'/AddToWishlist.php',
			{
				method: 'post',
				parameters: {action:'ajax',item_id:id,cpt:cpt},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function addToFavorite(id,cpt)
{
	Pdiv_link = document.getElementById('o_link_addtofavorite_'+id+'_'+cpt);
	Pdiv_wait = document.getElementById('o_wait_addtofavorite_'+id+'_'+cpt);
	Pdiv_ready = document.getElementById('o_ready_addtofavorite_'+id+'_'+cpt);
				
	if (id!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
	
		updater = new Ajax.Updater (
			'o_ready_addtofavorite_'+id+'_'+cpt,
			'/AddToFavorite.php',
			{
				method: 'post',
				parameters: {action:'ajax',item_id:id,cpt:cpt},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function createVirtalItem(id)
{
	Pdiv_wait = document.getElementById('o_wait_createvirtualitem_'+id);
	Pdiv_ready = document.getElementById('o_ready_createvirtualitem_'+id);
				
	if (id!='') {
		Pdiv_wait.style.display = ''; 

		updater = new Ajax.Updater (
			'o_ready_createvirtualitem_'+id,
			'/private/management/EditCornucopiaValuepacks.php',
			{
				method: 'post',
				parameters: {action:'createvirtualitem',valuepack_id:id},
				insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function applyItemMembership(id, type, discount)
{
	Pdiv_link = document.getElementById('o_link_applyItem_'+type);
	Pdiv_wait = document.getElementById('o_wait_applyItem_'+type);
	Pdiv_ready = document.getElementById('o_ready_applyItem_'+type);
				
	if (id!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
		
		updater = new Ajax.Updater (
			'o_ready_applyItem_'+type,
			'/artists/editItemMembership.php',
			{
				method: 'post',
				parameters: {action:'apply',id:id, type:type, discount:discount},
				insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function showVirtalItemForm(id)
{
	Pdiv_button = document.getElementById('createvirtualitem_button_'+id);
	Pdiv_button.style.display = 'none';
	createVirtalItem(id);
}

function payMeNow(userid)
{
	Pdiv_link = document.getElementById('o_link_paymenow');
	Pdiv_wait = document.getElementById('o_wait_paymenow');
	Pdiv_message = document.getElementById('o_message_paymenow');
				
	if (userid!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
		Pdiv_message.style.display = ''; 
	
		updater = new Ajax.Updater (
			'o_message_paymenow',
			'/affiliate/do_payment.php',
			{
				method: 'post',
				parameters: {action:'ajax',user_id:userid},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
	else alert('The fields cannot be empty!');
}

function updateNbItemsInCart(root)
{
	Pdiv_nbitems = document.getElementById('o_nb_items_in_cart');	

	updater = new Ajax.PeriodicalUpdater (
		'o_nb_items_in_cart',
		root+'/ajax_functions.php',
		{
			method: 'post',
			parameters: {action:'update_nbitemsincart'},
			//insertion: Insertion.Bottom,
			evalScripts: true,
			frequency: 5
		}
	);
}

function refreshCategory(id, type_id, category_id)
{
	Pdiv_link = document.getElementById('o_link_refreshcategory_'+id);
	Pdiv_wait = document.getElementById('o_wait_refreshcategory_'+id);
	Pdiv_ready = document.getElementById('o_ready_refreshcategory_'+id);
				
	if (type_id!='') {
		Pdiv_link.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 
	
		updater = new Ajax.Updater (
			'o_wait_refreshcategory_'+id,
			'/private/management/Refresh_categories.php',
			{
				method: 'post',
				parameters: {action:'ajax',div_id:id ,type:type_id ,category:category_id},
				insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
}

function confirmValuepackDectection(valuepackid, customerid)
{
	Pdiv_link = document.getElementById('o_link_confirmvaluepackdectection_'+valuepackid);
	Pdiv_wait = document.getElementById('o_wait_confirmvaluepackdectection_'+valuepackid);
	Pdiv_ready_yes = document.getElementById('o_ready_confirmvaluepackdectection_yes_'+valuepackid);
	Pdiv_ready_no = document.getElementById('o_ready_confirmvaluepackdectection_no_'+valuepackid);
	Pdiv_ready = document.getElementById('o_ready_confirmvaluepackdectection_'+valuepackid);
	if (valuepackid!='') {
		updater = new Ajax.Updater (
			'confirm_valuepack_detection_'+valuepackid,
			'ajax_functions.php',
			{
				method: 'post',
				parameters: {action:'confirm_valuepack_detection',valuepack_id:valuepackid, customer_id:customerid},
				insertion: Insertion.Top,
				evalScripts: true
			}
		);
	}
}

function changeStats()
{
	changeStatsPioneer();
	changeStatsActiveUser();
}

function changeStatsPioneer()
{
	var value = document.getElementById("o_period_pioneer").value;

	if (value!='') {
		Pdiv_stats_pioneer = document.getElementById('o_stats_pioneer');
		Pdiv_wait = document.getElementById('o_stats_pioneer_wait');
					
		Pdiv_stats_pioneer.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 

		updater = new Ajax.Updater (
			'o_stats_pioneer',
			'/private/management/displayStatsPioneer.php',
			{
				method: 'post',
				parameters: {filename:value},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
}

function changeStatsActiveUser()
{
	var value = document.getElementById("o_period_activeuser").value;

	if (value!='') {
		Pdiv_stats_activeuser = document.getElementById('o_stats_activeuser');
		Pdiv_wait = document.getElementById('o_stats_activeuser_wait');
					
		Pdiv_stats_activeuser.style.display = 'none'; 
		Pdiv_wait.style.display = ''; 

		updater = new Ajax.Updater (
			'o_stats_activeuser',
			'/private/management/displayStatsActiveuser.php',
			{
				method: 'post',
				parameters: {filename:value},
				//insertion: Insertion.Bottom,
				evalScripts: true
			}
		);
	}
}

function createListCustomerSpecialOfferModuleUpgrage()
{
	Pdiv_link = document.getElementById('o_link_createListCustomerSpecialOfferModuleUpgrage');
	Pdiv_wait = document.getElementById('o_wait_createListCustomerSpecialOfferModuleUpgrage');
	Pdiv_ready = document.getElementById('o_ready_createListCustomerSpecialOfferModuleUpgrage');
				
	Pdiv_link.style.display = 'none'; 
	Pdiv_wait.style.display = ''; 

	updater = new Ajax.Updater (
		'o_wait_createListCustomerSpecialOfferModuleUpgrage',
		'/private/management/Refresh_personal_promo_upgrade.php',
		{
			method: 'post',
			parameters: {},
			insertion: Insertion.Bottom,
			evalScripts: true
		}
	);
}

function updateCustomerDisplayOptions()
{
	Pdiv_link = document.getElementById('o_link_updateCustomerDisplayOptions');
	Pdiv_wait = document.getElementById('o_wait_updateCustomerDisplayOptions');
	Pdiv_ready = document.getElementById('o_ready_updateCustomerDisplayOptions');
				
	Pdiv_link.style.display = 'none'; 
	Pdiv_wait.style.display = ''; 

	updater = new Ajax.Updater (
		'o_wait_updateCustomerDisplayOptions',
		'/private/management/UpdateCustomerDisplayOptions.php',
		{
			method: 'post',
			parameters: {},
			insertion: Insertion.Bottom,
			evalScripts: true
		}
	);
}

function updateApplicableProducts(version)
{
	Pdiv_link = document.getElementById('o_link_updateApplicableProducts_'+version);
	Pdiv_wait = document.getElementById('o_wait_updateApplicableProducts_'+version);
				
	Pdiv_link.style.display = 'none'; 
	Pdiv_wait.style.display = ''; 
	
	updater = new Ajax.Updater (
		'o_wait_updateApplicableProducts_'+version,
		'/private/management/UpdateApplicableProducts.php',
		{
			method: 'post',
			parameters: {version: version},
			insertion: Insertion.Bottom,
			evalScripts: true
		}
	);
}

function updateConstProductTypes()
{
	Pdiv_link = document.getElementById('o_link_updateConstProductTypes');
	Pdiv_wait = document.getElementById('o_wait_updateConstProductTypes');
				
	Pdiv_link.style.display = 'none'; 
	Pdiv_wait.style.display = ''; 

	updater = new Ajax.Updater (
		'o_wait_updateConstProductTypes',
		'/private/management/UpdateConstProductTypes.php',
		{
			method: 'post',
			parameters: {},
			insertion: Insertion.Bottom,
			evalScripts: true
		}
	);
}

function UpdatePoserFileList(directory)
{
	var folder = document.getElementById('o_file_0').value;
	
	if (folder == '' || folder == 'POSER' || folder == 'Runtime' || folder == 'textures' || folder == 'libraries') {
		alert('Please, choose a directory.');
		return;
	}
	
	var finalDirectory = directory + 'POSER/' + folder;
	
	Pdiv_link = document.getElementById('oPoserFileList_link');
	Pdiv_wait = document.getElementById('oPoserFileList_wait');
				
	Pdiv_link.style.display = 'none'; 
	Pdiv_wait.style.display = ''; 

	updater = new Ajax.Updater (
		'oPoserFileList_link',
		'/artists/ListPoserFiles.php',
		{
			method: 'post',
			parameters: {finalDirectory:finalDirectory},

			evalScripts: true
		}
	);
}

// for content testers' account
function onSetAvailability()
{
    var usr = document.getElementById('userid').value;
    var avl = document.getElementById('availability').value;
    var itemRevLink = document.getElementById('itemReviewLink');
    
    updater = new Ajax.Updater (
		'contenttester_availability',
		'/artists/contenttester.php',
		{
			method: 'post',
			parameters: {action:'changeAvailability', user:usr, availability:avl},

			evalScripts: true
		}
	);
}

function onSetAwayPeriod()
{
    var usr = document.getElementById('userid').value;
    var avl = document.getElementById('availability').value;
    var back_text = document.getElementById('backin_text');
    var back_select = document.getElementById('backin').value;
    
    updater = new Ajax.Updater (
		'contenttester_availability',
		'/artists/contenttester.php',
		{
			method: 'post',
			parameters: {action:'changeAwayPeriod', user:usr, awayfor:back_select},

			evalScripts: true
		}
	);
}

function updateCreditCardInfo()
{
	if (!verifCCardFormUpdate()) return;

	var div_original = document.getElementById('areaCreate');
	var div_wait = document.getElementById('areaCreateWait');
	var div_done = document.getElementById('areaCreateDone');
	
	div_original.style.display = 'none';
	div_done.style.display = 'none';
	div_wait.style.display = '';
	
	if (document.getElementById('oCreditCard')) {
		var cid = document.getElementById('cid').value;
		var pwd = document.getElementById('pwd').value;
		var amount = document.getElementById('amount').value;
		var creditcardtype = document.getElementById('oSelCreditCard').value;
		var creditcardname = document.getElementById('oNameOnCard').value;
		var creditcardnumber1 = document.getElementById('oCreditCardNumber1').value;
		var creditcardnumber2 = document.getElementById('oCreditCardNumber2').value;
		var creditcardnumber3 = document.getElementById('oCreditCardNumber3').value;
		var creditcardnumber4 = document.getElementById('oCreditCardNumber4').value;
		var creditcardsecuritycode = document.getElementById('oCreditCardSecurityCode').value;
		var creditcardexpirationmonth = document.getElementById('oSelExpirationMonth').value;
		var creditcardexpirationyear = document.getElementById('oSelExpirationYear').value;
		
		var Address = document.getElementById('Address').value;
		var City = document.getElementById('City').value;
		var State = document.getElementById('State').value;
		var ZipCode = document.getElementById('ZipCode').value;
		var Country = document.getElementById('Country').value;
		
		var tos = document.getElementById('oTos').value;
	}
	
	var updater = new Ajax.Updater (
		div_original,
		'/SeeInvoices.php',
		{
			method: 'post',
			parameters: {action:'updateCreditCardInfo', 
							cid:cid,
							pwd:pwd,
							amount:amount,
							creditcardtype:creditcardtype,
							creditcardname:creditcardname,
							creditcardnumber1:creditcardnumber1,
							creditcardnumber2:creditcardnumber2,
							creditcardnumber3:creditcardnumber3,
							creditcardnumber4:creditcardnumber4,
							creditcardsecuritycode:creditcardsecuritycode,
							creditcardexpirationmonth:creditcardexpirationmonth,
							creditcardexpirationyear:creditcardexpirationyear,
							Address:Address,
							City:City,
							State:State,
							ZipCode:ZipCode,
							Country:Country,
							tos:tos
						},
			evalScripts: true
		}
	); 
	
}
