/* $Id: al.js 16707 2008-08-27 18:54:24Z erica $ */

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// entry page
function doTerms(cid)
{
	$("cid").value = cid;
	$("termsform").submit();
}

// entry page
function filterForm()
{	
	$("form_filter").submit();
}


//changing channels according to the category selected
function setChannels(tpl_form, category, change_category)
{
	var form = $(tpl_form);
	var channels = form.getInputs('checkbox', 'channels[]');

	var i=0;
	if (change_category == "yes")
	{
		var chn_count = channels.size();
		for (i=0; i<chn_count; i++)
		{
			channels[i].checked = false;
		}
	}

	var div_blocks = $$('div.channel');
	var div_size = div_blocks.size();

	for (i=0; i<div_size; i++)
	{
		if (div_blocks[i].getAttribute('channel_block') == category)
		{
			div_blocks[i].style.display = '';
		}
		else
		{
			div_blocks[i].style.display = 'none';
		}
	}
}

function leftDoLogin()
{
	$("loginform").submit();
}

function dvdSearch()
{
	$("dvdsearch").submit();
}

function mediaAction(form, hid_id, value)
{
	$(hid_id).value = value;
	$(form).submit();
}

function deleteMediaWarning(to_hide, to_show)
{
	$(to_hide).hide();
	$(to_show).show();
}

function setRating(last_star, full_star_img, img_id)
{
	for (var i=1; i<=last_star; i++)
	{
		$(img_id+i).src = full_star_img;
	}
}

function unsetRating(last_star, empty_star_img, img_id)
{
	for (var i=1; i<=last_star; i++)
	{
		$(img_id+i).src = empty_star_img;
	}
}

function setRateMessage(message, div_id)
{
	$(div_id).innerHTML = message;
}

function filterAmateur(path, gender)
{
	window.location = path + gender + '/';
}

//AJAX-oriented - for Videos/photos/members/amateurs scroll lines



//Function to update main page videos by gender
function updateLineByGender(elementId,url,gender,membertype,offset) 
{
    //$(elementId).setStyle({backgroundColor: '#AAA'});
    new Ajax.Updater(elementId, url, 
    {
        parameters: { 
            offset: offset,
            gender: gender,
            membertype: membertype,
            to_id: elementId            
        }
    });
    
    //,onComplete: function(){$(elementId).setStyle({backgroundColor: '#FFF'});}

}


function updateLineByCategory(elementId, url, cat_id, membertype, offset) 
{
    new Ajax.Updater(elementId, url, 
    {
        parameters: { 
            offset: offset,
            cat_id: cat_id,
            membertype: membertype,
            to_id: elementId            
        }
    });
    
    //,onComplete: function(){$(elementId).setStyle({backgroundColor: '#FFF'});}

}

function updateImgsetLine(elementId,url,filename,offset,total) 
{
    //$(elementId).setStyle({backgroundColor: '#AAA'});

    new Ajax.Updater(elementId, url, 
    {
        parameters: { 
            filename: filename,
            offset: offset,
            total: total,            
            to_id: elementId            
        }
    });
    
    //,onComplete: function(){$(elementId).setStyle({backgroundColor: '#FFF'});}
}


function changePaymentMethod(type_to_show, minimum_payment, payment_methods)
{
	var payment_methods_num = payment_methods.size();
	var selected_method = type_to_show.split('_');
	var selected_type = selected_method[1];

	for (var i=0; i<payment_methods_num; i++)
	{
		if( selected_type == payment_methods[i])
		{
			$(payment_methods[i]+'_div').show();
			$(selected_type + '_type_id').value = selected_method[0];
			$(selected_type + '_minimum_id').value = minimum_payment;
		}
		else
		{
			$(payment_methods[i]+'_div').hide();
		}
	}
}

function setMinimumPayment(minimum_payment)
{
	var payment_method = $F('payment_type_id');

	var selected_method = payment_method.split('_');
	var payment_type = selected_method[1];
	
	$(payment_type + '_minimum_id').value = minimum_payment;
}

	//media_type: {'video', 'image', 'member', 'dvd'}
	function commentAction(member_id, media_id, media_type)
	{
		if ($F('action') == 'add')
		{
			addComment(member_id, media_id, media_type, 'addComment');
		}
		else
		{
			if ($F('action') == 'edit' && $F('comment_id') != '')
			{
				updateComment(member_id, $F('comment_id'), media_type, 'editComment');
				$('action').value = 'add';
			}
		}
	}
	
	function addComment(member_id, media_id, media_type, func)
	{
		var url = '/json/'+func+'/'+media_id+'/'+member_id;
	
		new Ajax.Updater('comments_block', url, 
							{parameters: {comment: $F('comment_area'), 
										  parent: $F('parent'), 
										  media_type: media_type},
							 onComplete: updateCommentsNum
							}
		);
	
		$('comment_area').value = '';
		$('parent').value = 0;
	}
	
	function editComment(comment_id, comment)
	{
		$('action').value = 'edit';
		$('comment_area').value = comment.replace(/<br \/>/g,'\n');
		$('comment_id').value = comment_id;
	
		$('comment_area').activate();
	}
	
	function updateComment(member_id, comment_id, media_type, func)
	{

		var url = '/json/'+func+'/'+member_id+'/'+comment_id+'/';
		var comment_div = 'comment_'+comment_id;
	
		new Ajax.Updater(comment_div, url, 
							{parameters: {comment: $F('comment_area'), media_type: media_type}});
	
		$('comment_area').value = '';
		$('parent').value = 0;
	}
	
	function deleteComment(member_id, media_id, media_type, comment_id, func)
	{
		var url = '/json/'+func+'/'+media_id+'/'+member_id;

		var comments_div = 'comments_block';
	
		new Ajax.Updater(comments_div, url, 
							{parameters: {comment_id: comment_id, 
										  media_type: media_type},
							 onComplete: updateCommentsNum
							}
		);
	}
	
	function setCommentParent(parent_id)
	{
		var parent = $('parent');
		parent.value = parent_id;
		$('comment_area').activate();
	}

	function updateCommentsNum()
	{
		$('comment_num').innerHTML = $('cmmt_num').innerHTML;
	}

	function commentAreaActivate()
	{
		$('comment_area').activate();
	}

	function addVote(member_id, media_id, vote, media_type, func)
	{
		var url = '/json/'+func+'/';

		new Ajax.Updater('rating_block', url, 
							{
								parameters: {member_id: member_id, media_id: media_id, vote: vote, media_type: media_type}, 
								onSuccess: function( transport, json ){},
								onComplete: showAddRatingResult
							}
		);
	}

	function showAddRatingResult(json)
	{
		rating = json.headerJSON;
		$('vote_message').innerHTML = rating.message;
		$('vote_num').innerHTML = rating.rate_num;
	}

	function displayStatusChanging(div_id)
	{
		if ($(div_id).getStyle('display') == 'none')
		{
			$(div_id).show();
		}
		else
		{
			if ($(div_id).getStyle('display') == 'block')
			{
				$(div_id).hide();
			}
		}
	}

	function setChannelMediaBlock(channel_id, member_type, div_block, func)
	{
		var url = '/json/'+func+'/';
	
		new Ajax.Updater(	div_block, url, 
							{	parameters: 
								{
									channel_id: channel_id, 
									member_type: member_type
								},
								onSuccess: function (transport)
								{
									$('channel_btn').removeClassName('boxoff');
									$('channel_btn').addClassName('boxon');
									$('member_btn').removeClassName('boxon');
									$('member_btn').addClassName('boxoff');
								}
							}
		);

	}

	function setMemberMediaBlock(member_id, div_block, func)
	{
		var url = '/json/'+func+'/';
	
		new Ajax.Updater(	div_block, url, 
							{
								parameters: {member_id: member_id},
								onSuccess: function (transport)
								{
									$('channel_btn').removeClassName('boxon');
									$('channel_btn').addClassName('boxoff');
									$('member_btn').removeClassName('boxoff');
									$('member_btn').addClassName('boxon');
								}
							}
		);
	}
