/*
---------------------------------------------------------------------------
-------------------------SORTABLE CATEGORIES FOR CONTEST-------------------
---------------------------------------------------------------------------
*/
document.observe("dom:loaded", function()
{
	var myRegEx;
	var myRegEx2;
	var pars;

//-------------------------------------------------------------------
//	format for each contest container.

	myRegEx = /^qaAdmin(\d+)$/i;
//-------------------------------------------------------------------

//-------------------------------------------------------------------
//	format for each category container

	myRegEx2 = /^Contest.Category(\d+)$/i;			//cleaner

//-------------------------------------------------------------------

	$$('div.contestQAAdminDiv').each(function(containerCell)
	{
		Sortable.create(containerCell, 
		{
			onUpdate: function(elementBeingDragged)
			{
				var containerCellID = $(containerCell).readAttribute('id');
				var contestID = myRegEx.exec(containerCellID)[1];

				var listorder = Sortable.serialize(containerCellID, {tag:'div', name:'arrCategories'});
				var pars = listorder + "&contestID="+contestID+"&date="+Date();
				new Ajax.Request(daDomain + "/blimda/Contests/OrderCategoriesByArray.asp",
				{
					method: "get",
					parameters: pars,
					onSuccess: function(a){ },
					onFailure: function(a){ alert(a.responseText); }
				});
			},
			tag:'div',
			only:'categoryAdminDiv', 
			constraint: false,
			handle: 'categoryMoveHandle',
			dropOnEmpty: true,
//			format: myRegEx,
			SERIALIZE_RULE: myRegEx
		});
	});
});


function setAuthorContest(authorID, contestID, lockValue)
{
	var success = 'j';
	var pars = 'authorID='+authorID+'&contestID='+contestID+'&lockValue='+lockValue+'&date='+Date();
	new Ajax.Request(daDomain+'/blimda/Contests/SetAuthorContest.asp', {
		parameters: pars,
		asynchronous: false,
		onSuccess: function(a){success = true;},
		onFailure: function(a){alert(a.responseText); success = false;}
	});

	return success;
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/

function setAuthorCategoryContest(authorID, categoryID, contestID, lockValue)
{
	var success = 'j';
	var pars = 'authorID='+authorID+'&categoryID='+categoryID+'&contestID='+contestID+'&lockValue='+lockValue+'&date='+Date();
	new Ajax.Request(daDomain+'/blimda/Contests/SetAuthorCategoryContest.asp', {
		parameters: pars,
		asynchronous: false
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function addAuthorCategoryContest(authorID, categoryID, contestID)
{
	var success = 'j';
	var pars = 'authorID='+authorID+'&categoryID='+categoryID+'&contestID='+contestID+'&date='+Date();
	new Ajax.Request(daDomain+'/blimda/Contests/AddAuthorCategoryContest.asp', {
		parameters: pars,
		asynchronous: false
//		onSuccess: function(a){success = a.responseText;},
//		onFailure: function(a){alert(a.responseText); success = false;}
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function moveThing(thingID, thingType, categoryID, contestID, offset)
{
	var success = 'j';
	var pars = 'thingID='+thingID+'&thingType='+thingType+'&categoryID='+categoryID+'&contestID='+contestID+'&offset='+offset+'&date='+Date();
	new Ajax.Request(daDomain+'/blimda/Contests/MoveThing.asp', {
		parameters: pars,
		asynchronous: false
//		onSuccess: function(a){alert(a.responseText);},
//		onFailure: function(a){alert(a.responseText); success = false;}
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function castVote(thingID, thingType, categoryID, contestID, voteAmount, authorID)
{
	  var pars = 'thingID='+thingID+'&thingType='+thingType+'&categoryID='+categoryID+'&contestID='+contestID+'&voteAmount='+voteAmount+'&authorID='+authorID+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/CastVote.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function editVote(voteID, newAmount)
{
	  var pars = 'voteID='+voteID+'&newAmount='+newAmount+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/EditVote.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function removeVote(voteID)
{
	var pars='voteID='+voteID+'&date='+Date();
	ajax =  new Ajax.Updater(
		'',
		daDomain+'/blimda/Contests/RemoveVote.asp',        // URL
		{                // options
		method:'get',
		parameters: pars,
		asynchronous: false
	});

}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function conditionalCastVote(thingID, thingType, categoryID, contestID, voteAmount, authorID)
{
	  var pars = 'thingID='+thingID+'&thingType='+thingType+'&categoryID='+categoryID+'&contestID='+contestID+'&voteAmount='+voteAmount+'&authorID='+authorID+'&date='+Date();
	   ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/ConditionalCastVote.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function toggleCategoryContest(categoryID, contestID)
{
	var pars = 'categoryID='+categoryID+'&contestID='+contestID+'&date='+Date();
	ajax =  new Ajax.Updater(
	'',
	daDomain+'/blimda/Contests/ToggleCategoryContest.asp',        // URL
	{                // options
		method:'get',
		parameters: pars,
		onFailure: function(a){ alert(a.responseText); },
		asynchronous: false
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function addContest(contestName, contestStartDate, contestStopDate)
{
	  var pars = 'contestName='+contestName+'&contestStartDate='+contestStartDate+'&contestStopDate='+contestStopDate+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/AddContest.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function addContestWithCategories(contestName, contestStartDate, contestStopDate, categories)
{
	  var pars = 'contestName='+contestName+'&contestStartDate='+contestStartDate+'&contestStopDate='+contestStopDate+'&categories='+categories+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/AddContestWithCategories.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function addCategory(categoryName)
{
	  var pars = 'categoryName='+categoryName+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/AddCategory.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function addAndAssociateCategory(categoryName, contestID)
{
	  var pars = 'categoryName='+categoryName+'&contestID='+contestID+'&date='+Date();
	   ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/AddAndAssociateCategory.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function toggleTCCAssociation(thingID, thingType, categoryID, contestID)
{
	var pars = 'thingID='+thingID+'&thingType='+thingType+'&categoryID='+categoryID+'&contestID='+contestID+'&date='+Date();
	ajax =  new Ajax.Updater(
	'',
	daDomain+'/blimda/Contests/ToggleTCCAssociation.asp',        // URL
	{                // options
		method:'get',
		parameters: pars,
		onFailure: function(a){ alert(a.responseText); },
		asynchronous: false
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function selectCategoriesForm(contestID)
{
	  var pars = 'contestID='+contestID+'&date='+Date();
       ajax =  new Ajax.Updater(
         '',
         daDomain+'/blimda/Contests/SelectCategoriesForm.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function categoryChooser(thingID, thingType, contestID, divID)
{
	  var pars = 'thingID='+thingID+'&thingType='+thingType+'&contestID='+contestID+'&divID='+divID+'&date='+Date();
       ajax =  new Ajax.Updater(
         divID,
         daDomain+'/blimda/Contests/CategoryChooser.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function getScore(thingID, thingType, categoryID, contestID, divID)
{
	  var pars = 'thingID='+thingID+'&thingType='+thingType+'&categoryID='+categoryID+'&contestID='+contestID+'&date='+Date();
       ajax =  new Ajax.Updater(
         divID,
         daDomain+'/blimda/Contests/GetScore.asp',        // URL
         {                // options
         method:'get',
         parameters: pars,
		 asynchronous: false
             });
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/
function showElementContestForm(elementID, categoryID, contestID, divID)
{
	var pars = 'elementID='+elementID+'&categoryID='+categoryID+'&contestID='+contestID+'&divID='+divID+'&date='+Date();
	ajax =  new Ajax.Updater(
		divID,
		daDomain+'/blimda/Contests/ShowElementContestForm.asp',        // URL
		{                // options
		method:'get',
		parameters: pars,
		asynchronous: false
	});
}
/**------------------------------------------------------------------------------------------------------------------------------------**/

/**------------------------------------------------------------------------------------------------------------------------------------**/