var row_num = 1; // current num of the rows
var max_id = 1; // max id
var purse_type = ''; // purse type



// hint functions

$(document).ready(function(){

	// hint show/hide
	$('#show_hint_btn').live('click', function(){
		$('#hint').animate({'opacity': 'show'}, 300);
	});
	$('.close_hint_btn').live('click', function(){
		$('#hint').animate({'opacity': 'hide'}, 300);
	});
	
	// hint show/hide
	$('.show_hint_btn2').live('click', function(){
		$('#hint').animate({'opacity': 'show'}, 300);
	});

	// help show/hide
	$('.show_help_btn').live('click', function(){
		$('#val_to').css('display', 'none');
		$('#help').animate({'opacity': 'show'}, 300);
	});
	$('.close_help_btn').live('click', function(){
		$('#help').animate({'opacity': 'hide'}, 300, function(){$('#val_to').css('display', 'block');});
	});
	
	// online show/hide
	$('.show_online_btn').live('click', function(){
		$('#online').animate({'opacity': 'show'}, 300);
	});
	$('.close_online_btn').live('click', function(){
		$('#online').animate({'opacity': 'hide'}, 300);
	});
});



// show pass function

$(document).ready(function(){
	$('.show_pass_btn').live('click', function(){
		var par = $(this).parent();
		$(this).animate({'opacity': 'hide'}, 200, function(){$(this).next('.pass_box').animate({'opacity': 'show'}, 200, function(){par.find('.inp_pass').focus();}); } );
	});
});



$(document).ready(function(){
	$('#head_count_min').text(SmallValue);
	$('#head_pers').text(SmallFee);
});


// del row

$(document).ready(function(){
	$('.del_row').live('click', function(){
		$(this).parents('tr').animate({'opacity': 'hide'}, 300, function(){$(this).remove(); calc_nums(); calc_summ();} );
		row_num -= 1;
	});
});



// protection check
/*
$(document).ready(function(){
	$('#prot_chk').click(function(){
		if ($(this).attr('checked'))
		{
			$('.warn').animate({'opacity': 'hide'}, 300);
		}
		else
		{
			$('.warn').animate({'opacity': 'show'}, 300);
		}
	});
});
*/


// calculate nums in the table after row delete

function calc_nums()
{
	var counter = 1;
	var num_class = 'thrd';

	$('#ztable tr').each(function (i) {
		if (counter%2 == 0)
		{
			$(this).removeClass('scnd');
			$(this).removeClass('thrd');
			$(this).addClass('thrd');
		}
		else
		{
			$(this).removeClass('scnd');
			$(this).removeClass('thrd');
			$(this).addClass('scnd');
		}
		$(this).find('.td-num').html(counter);
		counter= counter + 1;
	});

}


// calculator

var res_val = parseInt(0);
var summ = 0;




// nominal check

$(document).ready(function(){
	$('.nominal').live('keyup', function(){
		$(this).attr('value', $(this).attr('value').replace(new RegExp(/[^0-9\.]+/gi),"") );

/*		if ($(this).attr('value') == '')
		{
			$(this).attr('value', '0');
		}
*/

//		var s = $(this).attr('value');
//		alert (s);
//		alert (s.charAt(0) +'_'+ s.length);
/*		if ((s == '0') && (s.length > 1))
		{
			$(this).attr('value', '');
		}
*/
		// calculate summ
		calc_summ();

		
	});
});




// nominal blur

function nom_blur (elem)
{
	if (elem.value == '')
	{
		elem.value = '0';
	}

	// calculate summ
	calc_summ();
}




// nominal focus

function nom_focus (elem)
{
	if (elem.value == '0')
	{
		elem.value = '';
	}

}





// change the valute

$(document).ready(function(){
	$('#val_to').change(function(){

		if ( $(this).attr('value') == 'PP' )
		{
			popup_funcs();
		}
		// calculate summ
		calc_summ();

	});
});








// set date

$(document).ready(function(){
	$('#zdate').text(KursTime);
});



// validate mail

function is_valid_email (email)
{
	return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email);
}


// validate ukash pin

function is_valid_ukash_pin (pin)
{
//	return /^633[0-9]{16,16}$/.test(pin);
	return /^(633)?718[0-9]{13,13}$/.test(pin);
}


// validate webmoney

function is_valid_wmz (wm)
{
	return /^Z[0-9]{12}$/.test(wm);
}
function is_valid_wme (wm)
{
	return /^E[0-9]{12}$/.test(wm);
}
function is_valid_wmr (wm)
{
	return /^R[0-9]{12}$/.test(wm);
}
function is_valid_wmu (wm)
{
	return /^U[0-9]{12}$/.test(wm);
}

// validate ep
function is_valid_ep (ep)
{
	return /^[a-zA-Z0-9\-]{5,25}$/.test(ep);
}

// validate yandex
function is_valid_yandex (wm)
{
	return /^[0-9]{14}$/.test(wm);
}


// check min value
function check_min_value ()
{
	var total_amount = 0;
	$('.nominal').each(function (a) {
		total_amount = total_amount + parseInt($(this).attr('value'));
	});

	if ( (total_amount < MinValue) )
	{
		return false;
	}
	else
	{
		return true;
	}
}


/*
$(document).ready(function(){
	if ( $('.gray_window').css('display') != 'none' )
	{
		scroll_block();
		setInterval(function()
		{
			$(window).scrollTop(0);
		},
		1000);
	}
});
*/

function popup_funcs()
{
	var h = 0;
	if ( $('#main-cashu').length )
	{
		h = $('#main-cashu').height() - 79;
	}
	if ( $('#main-ukash').length )
	{
		h = $('#main-ukash').height() - 79;
	}
	if ( $('#main-paysafecard').length )
	{
		h = $('#main-paysafecard').height() - 79;
	}
	
	var gr = $('.gray_window')
	gr.height(h);
	gr.css('display', 'block');
	window.scrollTo(0, 0);
}

$(document).ready(function(){
	$('#close_btn_link').click(function(){
		$('.gray_window').css('display', 'none');
		$('#val_to').find('option:first').attr('selected', 'selected');
		return false;
	});

	$('#other_pm').click(function(){
		$('.gray_window').css('display', 'none');
		$('#val_to').find('option:first').attr('selected', 'selected');
		return false;
	});
});

// scroll_block
function scroll_block()
{
	$(window).keydown(function() {
		return false;
	});
	$(window).scroll(function() {
		return false;
	});
	$(window).mousewheel(function(event, delta) {
		return false;
	});

	$('body').keydown(function() {
		return false;
	});
	$('body').scroll(function() {
		return false;
	});
	$('body').mousewheel(function(event, delta) {
		return false;
	});

	$('.gray_window').keydown(function() {
		return false;
	});
	$('.gray_window').scroll(function() {
		return false;
	});
	$('.gray_window').mousewheel(function(event, delta) {
		return false;
	});
}
