var review_nav_inprogress = false;
var review_page = 1;
var review_last_idsticker = 0;
var review_last_idgirl = 0;
var review_last_rtype = 1;
var review_last_id_lang = 1;
var review_lightbox = new lightbox_create();



function initialize_review_lightbox() {
	review_lightbox.content = document.getElementById('review_box');
}

function review_setWorkingStatus(status) {
	var statustxt = '';
	if (status==-1) statustxt=lng.ajax_status_unavailable;
	if (status==0) statustxt='';
	if (status==1) statustxt=lng.ajax_status_loading;
	if (status==2) statustxt=lng.ajax_status_sending;
	$('review_lbLoadMessage').innerHTML='<br /><br /><h3>'+statustxt+'</h3><br /><br />';
	if (statustxt=='') {
		$('review_status_box').style.display = 'none';
    } else {
		$('review_content_box').style.display = 'none';
		$('review_status_box').style.display = '';
    }
}

function review_close() {
	review_lightbox.deactivate();
}

function writeReview(id_sticker,id_girl) {
	if (review_nav_inprogress) return;
	review_nav_inprogress = true;
	review_lightbox.activate();
	review_setWorkingStatus(1);
	AjaxRequest.get({
		'url':base_href+'girlreview?type=review_write',
		'parameters': {'id_sticker':id_sticker,'id_girl':id_girl},
		'onSuccess': function(req) {
						review_setWorkingStatus(0);
						review_nav_inprogress = false;
						$('review_content_box').innerHTML = req.responseText;
						$('review_content_box').style.display = '';
						document.location = "#";
					 },
		'onError': function (req) { review_setWorkingStatus(-1); review_nav_inprogress = false; }
    });
}

function review_show_int(id_sticker,id_girl,page,rtype,id_lang) {
	if (review_nav_inprogress) return;
	review_nav_inprogress = true;
	review_setWorkingStatus(1);

	AjaxRequest.get({
		'url':base_href+'girlreview?type=review_read',
		'parameters': {'id_sticker':id_sticker,'id_girl':id_girl,'page':page,'rtype':rtype,'id_lang':id_lang},
		'onSuccess': function(req) {
						review_setWorkingStatus(0);
						review_nav_inprogress = false;
						$('review_content_box').innerHTML = req.responseText;
						$('review_content_box').style.display = '';
						review_page = page;
						review_last_idsticker = id_sticker;
						review_last_idgirl = id_girl;
						review_last_rtype = rtype;
						review_last_id_lang = id_lang;
						document.location = "#";
					 },
		'onError': function (req) { review_setWorkingStatus(-1); review_nav_inprogress = false; }
	});

}

function showReview(id_sticker,id_girl,id_lang) {
	if (review_nav_inprogress) return;
	review_lightbox.activate();
	review_show_int(id_sticker,id_girl,1,1,id_lang);
}
function showReviewUnpublished(id_sticker,id_girl,id_lang) {
	if (review_nav_inprogress) return;
	review_lightbox.activate();
	review_show_int(id_sticker,id_girl,1,4,id_lang);
}

function review_Prior() {
	review_show_int(review_last_idsticker,review_last_idgirl,review_page-1,review_last_rtype,review_last_id_lang);
}

function review_Next() {
	review_show_int(review_last_idsticker,review_last_idgirl,review_page+1,review_last_rtype,review_last_id_lang);
}

function review_Page(tnPage) {
	review_show_int(review_last_idsticker,review_last_idgirl,tnPage,review_last_rtype,review_last_id_lang);
}




function saveReview() {
	var txt_obj = document.forms['review_edit'].elements['review'];
	if (txt_obj.value.length < 10) {
		alert(lng.review_text_to_short);
		return;
	} else if (txt_obj.value.length > 2000) {
		alert(lng.review_text_to_long.replace('%num%',2000));
		return;
	}
	if (review_nav_inprogress) return;
	review_nav_inprogress = true;
	review_setWorkingStatus(2);
	AjaxRequest.submit(document.forms['review_edit'],{
		'parameters': {'type':'review_save'},
		'onSuccess': function(req) {
						data = eval("(" + req.responseText + ")");
						if(data=='-2'){
							review_nav_inprogress = false;
							review_setWorkingStatus(0);
							$('review_content_box').style.display = '';
							alert(lng.overcapsed_text);
						} else {
							review_setWorkingStatus(0);
							review_nav_inprogress = false;
							$('review_content_edit').style.display = 'none';
							$('review_content_saved').style.display = '';
							$('review_content_box').style.display = '';
						}
					 },
		'onError': function (req) { review_setWorkingStatus(-1); review_nav_inprogress = false; }
	});
}

function review_show_vote(wich,suffix) {
	$('review_selfvote'+suffix).style.display = (wich==0)?'':'none';
	//$('review_acceptusers').style.display = (wich==1)?'':'none';
	//$('review_rejectusers').style.display = (wich==2)?'':'none';
}

function saveReviewVote(suffix) {
	
	if (review_nav_inprogress) return;
	review_nav_inprogress = true;
	review_setWorkingStatus(2);
	AjaxRequest.submit(document.forms['review_vote'+suffix],{
		'parameters': {'type':'review_vote'},
		'onSuccess': function(req) {
						review_setWorkingStatus(0);
						review_nav_inprogress = false;
						review_show_int(review_last_idsticker,review_last_idgirl,review_page,review_last_rtype,review_last_id_lang);
					 },
		'onError': function (req) { review_setWorkingStatus(-1); review_nav_inprogress = false; }
	});
	
}



function review_showUserPointsInfo(suffix){
	$('review_body'+suffix).style.display = 'none';
	$('review_user_points_info'+suffix).style.display = '';
	//$('review_box').style.height = '250px';	
}

function review_hideUserPointsInfo(suffix) {
	$('review_user_points_info'+suffix).style.display = 'none';
	$('review_body'+suffix).style.display = '';
	//$('review_box').style.height = '352px';
}

function hint_unpublished_show() {
	lightbox.content = $('hint_unpublished');
	lightbox.activate();
}

function hint_unpublished_close() {
	lightbox.deactivate();
}

var ppu_already_payed = new Array();
function showReviewUnpublishedPay(id_sticker,id_girl) {
	if (review_nav_inprogress) return;

	for(var i=0;i<ppu_already_payed.length;i++) {
		if (ppu_already_payed[i]==id_sticker+"_"+id_girl) {
			showReviewUnpublished(id_sticker,id_girl);
			return;
		}
	}

	lightbox.content = $('pay_prompt_unpublished');
	lightbox.activate();
	if ($('ppu_pay_sms_id_sticker'))		$('ppu_pay_sms_id_sticker').value = id_sticker;
	if ($('ppu_pay_sms_id_girl'))			$('ppu_pay_sms_id_girl').value = id_girl;
	if ($('ppu_pay_balance_id_sticker'))	$('ppu_pay_balance_id_sticker').value = id_sticker;
	if ($('ppu_pay_balance_id_girl'))		$('ppu_pay_balance_id_girl').value = id_girl;

	if ($('ppu_pay_sms_code'))				$('ppu_pay_sms_code').value = '';
	if ($('ppu_sms_pay_progress_block'))	$('ppu_sms_pay_progress_block').style.display = 'none';
	if ($('ppu_sms_pay_result_block'))		$('ppu_sms_pay_result_block').style.display = 'none';
	if ($('ppu_sms_pay_pay_block'))			$('ppu_sms_pay_pay_block').style.display = '';
	if ($('ppu_balance_pay_progress_block'))$('ppu_balance_pay_progress_block').style.display = 'none';
	if ($('ppu_balance_pay_result_block'))	$('ppu_balance_pay_result_block').style.display = 'none';
	if ($('ppu_balance_pay_pay_block'))		$('ppu_balance_pay_pay_block').style.display = '';
}
function pay_prompt_unpublished_close() {
	lightbox.deactivate();
}
function ppu_sms_operator_changed() {
	$('ppu_sms_number').innerHTML = $('ppu_sms_operator').value?$('ppu_sms_operator').value:lng.sms_select_operator_first;
}
var ppu_sms_pay_in_progress = false;
function ppu_sms_pay() {
	if ($('ppu_pay_sms_code').value=='') {
		alert(lng.enter_code);
		$('ppu_pay_sms_code').focus();
		return;
	}
	if (ppu_sms_pay_in_progress) return;
	ppu_sms_pay_in_progress = true;

	$('ppu_sms_pay_pay_block').style.display = 'none';
	$('ppu_sms_pay_result_block').style.display = 'none';
	$('ppu_sms_pay_progress_block').style.display = 'block';

	AjaxRequest.post({
		'url':base_href+'portal/purse',
		'parameters': {'action':'pay_sms','code':$('ppu_pay_sms_code').value,'id_girl':$('ppu_pay_sms_id_girl').value},
		'onSuccess': function(req) {
						ppu_sms_pay_in_progress=false;
						$('ppu_sms_pay_progress_block').style.display = 'none';
						$('ppu_sms_pay_result_block').style.display = 'none';
						$('ppu_sms_pay_pay_block').style.display = '';
						var data = eval("(" + req.responseText + ")");
						if (data.RESULT==1) {
							if (data.BALANCE!='' && this.UserBalanceChanged) {
								UserBalanceChanged(data.BALANCE);
							}
							if (data.USER_POINTS!='' && this.UserPointsChanged) {
								UserPointsChanged(data.USER_POINTS);
							}
							$('ppu_sms_pay_result_block').innerHTML = lng.access_granted;
							$('ppu_sms_pay_result_block').style.display = '';
							$('ppu_pay_sms_code').value = '';

							ppu_already_payed.push($('ppu_pay_sms_id_sticker').value+"_"+$('ppu_pay_sms_id_girl').value);

							pay_prompt_unpublished_close();
							showReviewUnpublished($('ppu_pay_sms_id_sticker').value,$('ppu_pay_sms_id_girl').value);
						} else if (data.RESULT==0) {
							$('ppu_sms_pay_result_block').innerHTML = lng.invalid_code;
							$('ppu_sms_pay_result_block').style.display = '';
						} else {
							$('ppu_sms_pay_result_block').innerHTML = lng.popol_error+' ('+data.RESULT+')';
							$('ppu_sms_pay_result_block').style.display = '';
						}
					 },
		'onError': function (req) {
						ppu_sms_pay_in_progress=false;
						$('ppu_sms_pay_progress_block').style.display = 'none';
						$('ppu_sms_pay_pay_block').style.display = '';
						$('ppu_sms_pay_result_block').innerHTML = lng.try_again_later;
						$('ppu_sms_pay_result_block').style.display = '';
	 				}
	});
}
var ppu_balance_pay_in_progress = false;
function ppu_balance_pay() {
	if (ppu_balance_pay_in_progress) return;
	ppu_balance_pay_in_progress = true;

	$('ppu_balance_pay_pay_block').style.display = 'none';
	$('ppu_balance_pay_result_block').style.display = 'none';
	$('ppu_balance_pay_progress_block').style.display = 'block';

	AjaxRequest.post({
		'url':base_href+'portal/purse',
		'parameters': {'action':'pay_balance','id_girl':$('ppu_pay_balance_id_girl').value},
		'onSuccess': function(req) {
						ppu_balance_pay_in_progress=false;
						$('ppu_balance_pay_progress_block').style.display = 'none';
						$('ppu_balance_pay_result_block').style.display = 'none';
						$('ppu_balance_pay_pay_block').style.display = '';
						var data = eval("(" + req.responseText + ")");
						if (data.RESULT==1||data.RESULT==-2) {
							if (data.BALANCE!='' && this.UserBalanceChanged) {
								UserBalanceChanged(data.BALANCE);
							}
							if (data.USER_POINTS!='' && this.UserPointsChanged) {
								UserPointsChanged(data.USER_POINTS);
							}
							$('ppu_balance_pay_result_block').innerHTML = lng.access_granted;
							$('ppu_balance_pay_result_block').style.display = '';

							ppu_already_payed.push($('ppu_pay_balance_id_sticker').value+"_"+$('ppu_pay_balance_id_girl').value);

							pay_prompt_unpublished_close();
							showReviewUnpublished($('ppu_pay_balance_id_sticker').value,$('ppu_pay_balance_id_girl').value);
						} else if (data.RESULT==-1) {
							$('ppu_balance_pay_result_block').innerHTML = lng.balance_too_low;
							$('ppu_balance_pay_result_block').style.display = '';
						} else if (data.RESULT==0) {
							$('ppu_balance_pay_result_block').innerHTML = lng.payment_impossible;
							$('ppu_balance_pay_result_block').style.display = '';
						} else {
							$('ppu_balance_pay_result_block').innerHTML = lng.popol_error+' ('+data.RESULT+')';
							$('ppu_balance_pay_result_block').style.display = '';
						}
					 },
		'onError': function (req) {
						ppu_balance_pay_in_progress=false;
						$('ppu_balance_pay_progress_block').style.display = 'none';
						$('ppu_balance_pay_pay_block').style.display = '';
						$('ppu_balance_pay_result_block').innerHTML = lng.try_again_later;
						$('ppu_balance_pay_result_block').style.display = '';
	 				}
	});
}

	
//---------------------show/hide full/short list of accept/reject users
function show_users(tpElement) {
	toggle_display(tpElement);
	toggle_display(tpElement+'_short');		
}

//-----------------------------------------------------------------------

function showReviewTextInfo(text){
	
	$('review_box').className = 'c_hidden';
	//$('text_info_box').className = 'lightbox';
	$("text_info").innerHTML = text;
	$('text_info').style.display = '';
	$('text_info_box').style.display = 'block';
	
	
}
function closeReviewTextInfo(){	
	$('text_info_box').style.display = 'none';
	$('text_info').style.display = 'none';
	$('review_box').className = 'lightbox';	
	//$('review_box').style.left = '27%';
}
