My_AJAX_Object = new vB_AJAX_Handler(true);


function change_page_with_confirmation_message(message, new_location)
{
	var answer = confirm(message);
	if (answer)
	{
		window.location = new_location;
	}
}


function disable_click()
{
	return false;
}


function vote(story_id, vote_type, vote_value, session_var)
{
	//alert('story_id = ' + story_id);
	//alert('vote_type = ' + vote_type);

	score_el = document.getElementById('score_' + story_id);
	up_btn_el = document.getElementById('up_btn_' + story_id);
	down_btn_el = document.getElementById('down_btn_' + story_id);

	target_btn_el = document.getElementById('up_btn_' + story_id);
	vote_type_string = "up";

	if(parseInt(vote_type)==2)
	{
		// negative vote
		target_btn_el = document.getElementById('down_btn_' + story_id);
		vote_type_string = "down";
		score_el.innerHTML = parseInt(score_el.innerHTML) - vote_value;
	}
	else
	{
		// positive vote
		score_el.innerHTML = parseInt(score_el.innerHTML) + vote_value;
	}

	target_btn_el.className = "vote " + vote_type_string + "_voted";
	up_btn_el.onclick = disable_click;
	down_btn_el.onclick = disable_click;


	voting_buttons_id = 'voting_buttons_' + story_id;
	voting_buttons_el = document.getElementById(voting_buttons_id);
	voting_buttons_el.style.visibility='hidden';


	vote_value_id = 'vote_value_' + story_id;
	vote_value_el = document.getElementById(vote_value_id);
	vote_value_el.innerHTML = vote_value;

	if(parseInt(vote_type)==1)
	{
	  	vote_value_el.innerHTML = '+' + vote_value_el.innerHTML;
	  	vote_value_el.className = 'positive_vote';
	}
	else
	{
	  	vote_value_el.innerHTML = '-' + vote_value_el.innerHTML;
	  	vote_value_el.className = 'negative_vote';
	}
	var fadeIn = new YAHOO.util.Anim(vote_value_id, { opacity: { from: 0, to: 1 }}, 0.5);
	fadeIn.animate();

	var params = session_var + "action=record-story-vote&story_id=" + story_id + "&vote_type=" + vote_type;
	//alert(params);
	My_AJAX_Object.send('press-operations.php', params);

	return false;
}


function setCheckedValue(radioObj, newValue)
{
	if(!radioObj) return;

	var radioLength = radioObj.length;
	if(radioLength == undefined)
	{
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}

	for(var i = 0; i < radioLength; i++)
	{
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString())
		{
			radioObj[i].checked = true;
		}
	}
}


function digit_check(event, element_to_clear_id, allow_negative_sign)
{
	var unicode = event.charCode ? event.charCode : event.keyCode;

	if (allow_negative_sign == null)
	{
		allow_negative_sign = false;
	}

	// alert(unicode);

	switch(unicode)
	{
		case 8:
		case 35:
		case 36:
		case 37:
		case 39:
		case 46:
		{
			break;
		}

		case 45:
		{
			if (!allow_negative_sign) return false;
			break;
		}

		default:
		{
			if ( (unicode < 48) || (unicode > 57) ) return false;
		}
	}


return true;
}


function limit_length(obj, length)
{
	var maxlength = length;
	if (obj.value.length > maxlength) obj.value = obj.value.substring(0, maxlength);
}


function compute_exchange_rate()
{
	var exchange_amount_val = parseFloat(document.getElementById('exchange_amount').value);

	if (!isNaN(exchange_amount_val))
	{
		var source_currency_val = parseFloat(document.getElementById('source_currency').value);
		var target_currency_val = parseFloat(document.getElementById('target_currency').value);
		var exchange_result = exchange_amount_val * source_currency_val / target_currency_val;

		document.getElementById('exchange_result').value = Math.round(exchange_result * 100) / 100;
		document.getElementById('exchange_result_with_vat').value = Math.round(exchange_result * 100 * 1.19) / 100;
		document.getElementById('exchange_vat').value = Math.round(exchange_result * 100 * 0.19) / 100;
	}
	else
	{
		document.getElementById('exchange_result').value = '';
		document.getElementById('exchange_result_with_vat').value = '';
		document.getElementById('exchange_vat').value = '';
	}
}


function rp_make_selection()
{
	var selected_category = document.getElementById('select_category');
	var selected_language = document.getElementById('select_language');

	var selected_category_val = selected_category.options[selected_category.selectedIndex].value;
	var selected_language_val = selected_language.options[selected_language.selectedIndex].value;

	var story_status_id = document.getElementById('story_status_id');
	var order_type_id = document.getElementById('order_type_id');
	var base_url_val = document.getElementById('base_url').value; 

	var new_url = base_url_val + "/revista-presei.php?category_id=" + selected_category_val + "&language_id=" + selected_language_val +
			"&story_status_id=" + story_status_id.value + "&order_type_id=" + order_type_id.value;
	window.location = new_url;
}


function redirect_to_login()
{
	var base_url_val = document.getElementById('base_url').value; 
	var new_url = base_url_val + "/login.php";
	window.location = new_url;
}


