$(document).ready(function() {
	initDialog();
});

function initDialog(){ // de pus: $(document).ready(function() {  initDialog() });
	$("#dialog").dialog({
		autoOpen: false,
		modal: true,
		closeText: ''
	});
}

function showDialog(title, message){
	$("#dialog")
		.html(message)
		.dialog("open");
	$('#dialog').dialog('option', 'title', title);

	$('#dialog').dialog('option', 'buttons', {
		"OK":function(){
			$(this).dialog("close");
		}
	});

	return false;
}

//usage : confirmDialog("titlu","mesaj", nume_functie_yes)
function confirmDialog(title, message, yesCallback){
	yesCallback = handleYes || function(){return true};

	$("#dialog")
		.html(message)
		.dialog("open");
	$('#dialog').dialog('option', 'title', title);

	$('#dialog').dialog('option', 'buttons', {
		"Yes":function(){
			yesCallback();
			$(this).dialog("close");

		},
		"No":function(){
			$(this).dialog("close");
		}
	});
	return false;
}

////check if enter
var isNavEnter, isIEEnter;
if (parseInt(navigator.appVersion)>=4) {
	if(navigator.appName == "Netscape")
	{
		isNavEnter = true;
	}
	else
	{
		isIEEnter = true;
	}
}

function checkEnter(evt, action) {
	var key;
	if (isNavEnter)
	{
		key = evt.which;
	}
	else
	{
		key = window.event.keyCode;
	}
	if (key==13)
	{
		eval(action);

	}
}

function searchFast() {
	if (jQuery.trim($('#searchSimpleTerm').val()) != '' && jQuery.trim($('#searchSimpleTerm').val()) != defaultVal) {
		$('#searchSimpleForm').submit();
	} else {
		showDialog(errorTitle, errorMess);
	}
}

function defaultValues() {
	if (jQuery.trim($('#searchSimpleTerm').val()) == '' ) {
		$('#searchSimpleTerm').val(defaultVal);
	}
}

function refreshCaptcha(){
	var _url =  site_url + "/ajax/a_captchaRefresh";
	url_parts = split("http://", _url);
	part2_url = url_parts[1].replace("//", "/");
	full_url = "http://" + part2_url;

	$.ajax({
		type: "POST",
		url: full_url,
		success: function(msg) {
			$("#captchaImg").html(msg);
		}
	});
}

function displayArticleFor(pID) {
	$('#searchSimplePersonID').val(pID);
	$('#searchSimpleTerm').val('');
	$('#searchSimpleForm').submit();
}

function displayArticleForTag(tag) {
	$('#searchSimpleTerm').val(tag);
	$('#searchSimpleForm').submit();
}

function displayArticleForDomain(dID) {
	$('#searchSimpleDomainID').val(dID);
	$('#searchSimplePersonID').val(0);
	$('#searchSimpleTerm').val('');
	$('#searchSimpleForm').submit();
}

