/**
***************************************************************************
*       @developed by 	Mediafamily SRL,
* 						web: http://www.mediafamily.ro
* 						email: office@mediafamily.ro
* 						address:	str Tudor Vladimirescu nr. 63/14, 540014, Targu Mures, Romania
*
*		This script make uses of prototype and scriptaculous JS libraries.
***************************************************************************
*/


function showCheckBoxResponse(response)
{
		var s = response.responseText;
		var res = s.split(",");
		var group = res[0];
		var id = res[1];
		var index = res[2];
		var message = res[3];

		showOkWindow();
}


function check_box_status_changed(group, id, e)
{

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

	// get the checkbox status
	var status = $F('checkbox_'+group+'_'+id);
	status = (status == 1)?1:0;
	if(group=='PrivateLinkP'){
		if(status==1){
			document.getElementById('checkbox_PrivateLink_'+id).checked=true;
		}else{
			document.getElementById('checkbox_PrivateLink_'+id).checked=false;
		}
	}
	var url = "/direct-checkbox_ajax-save_checkbox-" + group + "-" + id + "-" + status + ".php";
	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}
function button_status_changed(group, id, e)
{

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

// get the checkbox status

	if(group=='FavRSS'){
		var status = 1;
	}else{
		var status = $F('checkbox_'+group+'_'+id);
	}
	if(group=='FavoriteButton'){
		if(status =='Add To Favourite'){
			status='add';
		}else{
			status='remove';
		}
	}

	if(group=='RankButton'){
		var status = $F('rate_def');
	}
	var url = "/direct-checkbox_ajax-save_button-" + group + "-" + id + "-" + status + ".php";

	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
	if(group=='FavoriteButton'){
		if(status=='add'){
			document.getElementById('checkbox_'+group+'_'+id).value='Is Favourite';
		}else{
			document.getElementById('checkbox_'+group+'_'+id).value='Add To Favourites';
		}
	}

}
function button_status_changed2(group, id, e,title)
{

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

// get the checkbox status


	var url = "/direct-checkbox_ajax-save_button-" + group + "-" + id + "-" + title + ".php";

	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});


}

function setimage_position(position,image_id,e){
	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

	var url = "/direct-formelements-updateimagepos.php";
	var myAjax = new Ajax.Request(
			url,
			{
				asynchronous: true,
				method: 'post',
				postBody: 'position='+position+'&id='+image_id+'',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}

function setvideo_title(title,image_id,e){

	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

	var url = "/direct-formelements-updatevideotitle.php";
	var myAjax = new Ajax.Request(
			url,
			{
				asynchronous: true,
				method: 'post',
				postBody: 'title='+title+'&id='+image_id+'',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}

/**
 *
 * @access public
 * @return void
 **/
function save_selection(group, id, e,formname){
	// save the event position;
	getMousePosition(e);

	// show the waiting message window
	showSpinnerWindow();

// get the checkbox status
	var idx=document.getElementById('selectbox_'+group+'_'+id).selectedIndex;
	var status=document.getElementById('selectbox_'+group+'_'+id)[idx].value;
	if(group=='PrivateLinkP'){
		if(status==1){
			document.getElementById('selectbox_PrivateLink_'+id).selectedIndex=0;
		}else if(status==2){
			document.getElementById('selectbox_PrivateLink_'+id).selectedIndex=1;
		}else{
			document.getElementById('selectbox_PrivateLink_'+id).selectedIndex=2;
		}
	}
	var url = "/direct-checkbox_ajax-save_selectbox-" + group + "-" + id + "-" + status + ".php";
	var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				onComplete: showCheckBoxResponse,
				onFailure: hideMsgWindow,
				onException: hideMsgWindow
			});
}
