// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function doselect(value){
    if (value != "") {
        this.location.href = value;
    }
}

function doSubmit(pForm) {
	id = pForm.split("_").last();
	$("img_"+id).src = "/images/ajax-loader.gif";
	$("img_"+id).style.marginLeft = "8px";
	new Ajax.Request("/story/insert?"+Form.serialize($(document.forms[pForm])), {
		onSuccess: function(transport)
		{
			$("img_"+id).style.display = "none";
			$("loaded_"+id).style.display = "block";
		}
	});
}

window.onload=montre;
function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}


// -------------------------------------------------------------------
// Fonction pour filtrer des caractères lors de la saisie
// -------------------------------------------------------------------
function genericFilter(pEvent,pAcceptedChars) {
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (pEvent) {
			key = pEvent.which;
		} else {
			return true;
	}
	keychar = String.fromCharCode(key);
	keychar = keychar.toLowerCase();
	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) ) {
		return true;
	}
	// alphas and numbers
	else if ((pAcceptedChars.indexOf(keychar) > -1))
		return true;
	else
		return false;
}


function filterALPHA(e) {
	return genericFilter(e,"abcdefghijklmnopqrstuvwxyz0123456789");
}

function filterALPHA2(e) {
	return genericFilter(e,"abcdefghijklmnopqrstuvwxyz0123456789 -éèêëïîüûöôâç");
}

function filterNUM(e) {
	return genericFilter(e,"0123456789");
}

function filterHEXA(e) {
	return genericFilter(e,"abcdef0123456789");
}

function filterDATE(e) {
	return genericFilter(e,"/0123456789");
}

function filterTIME(e) {
	return genericFilter(e,":0123456789");
}

function filterPHONE(e) {
	return genericFilter(e,"+0123456789() ");
}

function filterEMAIL(e) {
	return genericFilter(e,"abcdefghijklmnopqrstuvwxyz0123456789@.-_");
}

function filterURL(e) {
	return genericFilter(e,"abcdefghijklmnopqrstuvwxyz0123456789.-_?/");
}
