

/// used by save.cgi

function checkForm(formFields) {
	
	var formOK = true;

	for (var i in formFields) {
		var fieldName = "";
		if (formFields[i].name == "comment") fieldName = "comment"
		if (formFields[i].name == "affil")   fieldName = "affiliation"
		if (formFields[i].name == "name")    fieldName = "name"
		if (formFields[i].name == "email")   fieldName = "email"
		if (formFields[i].name == "email2")  fieldName = "email"

		if (fieldName == "comment" && formFields[i].value.length>2000) {
			formOK = false;
			alert("Your comment is limited to 2000 characters. Please make your comment shorter and try again.");
		}
	
		if (formFields[i].value.indexOf(";")!=-1) {
			formOK = false;
			alert("Semicolons (;) are not allowed in the " + fieldName + " field.");
		}
	}
	return formOK
}



/// used by tableau.cgi
function updateCookie(item,value) {

	if (value != 1) value = 0 ;
	
	var pref = parseInt(document.cookie.substring(document.cookie.indexOf("pref:")+5,document.cookie.length)) ||0;
	var  newPref = -1
	if (item == "segIndex")  newPref = 1;
	if (item == "lums")      newPref = 2;
	if (item == "rlumseq")   newPref = 4;
	if (item == "moras")     newPref = 8;
	if (item == "syllables") newPref = 16;
	if (item == "links")     newPref = 32;
	if (newPref > -1) {
		if(value) {
			pref = pref | newPref;
		} else {
			pref = pref & (63-newPref);
		}
	}
	
	d = new Date("January 01 2010");
	document.cookie = "pref:" + pref + ";expires=" + d.toGMTString();
	updateDocument(item,value);

}

function updateDocument(item,value) {

	document.forms["display"][item].checked = value;
	if (document.getElementsByTagName) {
		spanList = document.getElementsByTagName("SPAN");
		for (var i=0; i<spanList.length ; i++) {
			if (spanList[i].className == item){
				spanList[i].style.display = (value) ? "inline" : "none";
			}
		}
	}
}

function initDisplay() {

	var pref = parseInt(document.cookie.substring(document.cookie.indexOf("pref:")+5,document.cookie.length)) || 0;

	if (document.getElementById) {
		if (pref&1)  updateDocument("segIndex",1);
		if (pref&2)  updateDocument("lums",1);
		if (pref&4)  updateDocument("rlumseq",1);
//		if (pref&8)  updateDocument("moras",1);
//		if (pref&16) updateDocument("syllables",1);
		if (pref&32) updateDocument("links",1);
	}
}


// called by page tableau.cgi
function rerank(position,direction,inputIndex) {

	var CON; 
	if (document.cookie.indexOf("CON=")!=-1) {
		CON = document.cookie.substring(document.cookie.indexOf("CON=")+4,document.cookie.length);
		if (CON.indexOf(";")!=-1) CON = CON.substring(0,CON.indexOf(";"));
		CON = unescape(CON);
	}
	var CONarr = CON.split(",");
	
	if (position!=null && direction!=null && (position+direction)>=0 && (position+direction) < CONarr.length) {
		var temp = CONarr[position+direction];
		CONarr[position+direction] = CONarr[position];
		CONarr[position] = temp;
		document.cookie = "CON=" + CONarr.join(",");
		location.reload();
	}
}


/// called by Ranking pages
function newCON() {
	document.cookie = "CON=";
	location.href = "CONEditor.cgi";
}

