/**
 * onArcade 2.0.0
 * Copyright © 2006-2007 Hans Mäesalu & Eveterm OÜ, All Rights Reserved
 **/

function bookmark() {
	if (document.all) {
		window.external.AddFavorite(siteurl, "Giochi Gratis");
	} else { 
		window.sidebar.addPanel("Giochi Gratis", siteurl, "");
	}
}
 
function verify_comment() {
	if (document.comment_form.message.value=="") {
		new_notification(comment_not_blank);
		return false;
	} else {
		return true;
	}
}

function verify_contact() {
	if (document.form.message.value=="") {
		new_notification(message_not_blank);
		return false;
	} else {
		return true;
	}
}

function confirm_delete() {
	var ok=confirm(sure_want_delete_message);
	if (ok) {
		return true ;
	} else {
		return false ;
	}
}

function goto_link(link_url) {
	opener.document.location.href = link_url;
	window.close();
}

function verify_link_add() {
	if (document.form.link_title.value=="" || document.form.link_url.value=="" || document.form.link_description.value=="" || document.form.link_email.value=="") {
		new_notification(all_fields_required);
		return false;
	} else {
		return true;
	}
}

function verify_submit_content() {
	if (document.submit_form.title.value=="" || document.submit_form.description.value=="" || document.submit_form.upload_file.value=="" || document.submit_form.upload_image.value=="") {
		new_notification(all_fields_required);
		return false;
	} else {
		return true;
	}
}

function verify_pm_send() {
	if ($('#pm_form input[name=message_recipient]').val() == "") {
		new_notification(recipient_not_blank);
		$('#pm_form input[name=message_recipient]').focus();
		return false;
	} else if ($('#pm_form textarea[name=message_text]').val() == "") {
		new_notification(message_not_blank);
		$('#pm_form textarea[name=message_text]').focus();
		return false;
	}
	return true;
}

function check_all(){
	for (var i=0;i<document.pm_form.elements.length;i++) {
		var e=document.pm_form.elements[i];
		if ((e.name != "all") && (e.type=="checkbox")) {
			e.checked=document.pm_form.all.checked;
		}
	}
}

function new_notification(text, loc) {
	if ($('#alert_box').length == 0)
		$('body').prepend('<div id="alert_box">' + text + '<span id="close_box" title="' + close_title + '">X</span></div>');
	else
		$("#alert_box").html(text + '<span id="close_box" title="' + close_title + '">X</span>');

	$('#alert_box').fadeIn(500, function() {
		$('#alert_box').animate({
			backgroundColor: '#FF887F'
		}, 800, function() {
			$('#alert_box').animate({
				backgroundColor: '#FFF15F'
			}, 600);
		});
	}).click(function(e) {
		if (e.target.id == 'close_box') {
			$('#alert_box').fadeOut(500, function() {
				$('#alert_box').remove();
			});
		} else if (loc !== undefined) {
			window.location = loc;
		}
	});
}

function edit_comment (comment_id) {
	document.getElementById('edit_comment_' + comment_id).innerHTML = '<input type="text" size="15" maxlength="100" id="edit_score_comment" /><input type="submit" value="' + submit_button + '" onclick="edit_score_comment(' + comment_id + ')" />';
}

function report_broken (file_id, what_is_wrong_with) {
	document.getElementById('report_broken').innerHTML = what_is_wrong_with + '<br /><input type="text" size="30" maxlength="100" id="report_broken_comment" /><input type="submit" value="' + submit_button + '" onclick="report_broken_submit(' + file_id + ')" />';
}

function addsmilie(code) {
	document.getElementById("comment_message").value += code;
}

function link_out(link_id) {
	window.open(siteurl + '/links.php?a=out&l=' + link_id);
	return false;
}

function verify_sponsor() {
	if (document.getElementById("os0").value == '' || document.getElementById("os1").value == '' || document.getElementById("os1").value == 'http://') {
		alert(all_fields_required);
		return false;
	} else {
		return true;
	}
}

function showPopup(file) {
	document.getElementById('file').style.display = 'none';
	window.open(file, 'Fullscreen', 'scrollbars=0,toolbar=0,location=0,fullscreen=1');
}

function preload_swf() {
	var preloader_bar = document.getElementById('preloader_bar');
	preloader_bar.style.width = 0;
	function add_percent() {
		if (parseInt(preloader_bar.style.width) >= 184) {
			show_game();
		} else {
			preloader_bar.style.width = parseInt(preloader_bar.style.width)+1 + 'px';
			document.getElementById('percent').innerHTML = Math.floor(parseInt(preloader_bar.style.width) / 184 * 100);
			setTimeout(add_percent, 44);
		}
	}
	add_percent();
}

function switch_location(cbox) {
	var status = false;
	var display = 'none';
	if (cbox.checked) { status = true; display = 'block'; }
	document.getElementById('selReg').disabled = status;
	document.getElementById('selProv').disabled = status;
	document.getElementById('selCom').disabled = status;
	document.getElementById('altLoc').style.display = display;
	document.getElementById('altLoc').getElementsByTagName('input')[0].focus();
}

function show_game() {
	document.getElementsByTagName('object')[0].style.visibility = 'visible';
	document.getElementsByTagName('object')[0].style.position = 'static';
	document.getElementById('ad_before').style.display = 'none';
}

function reset_field(field, val, blur) {
	if (blur && field.value == '')
		field.value = val;
	else if (field.value == val)
		field.value = '';
}