function mlmttgq() {
un="mai";
deux="lto";
trois=":glar";
quatre="osag@o";
cinq="ten";
six="e";
sept="t.gr";
document.location=un + deux + trois + quatre + cinq + six + sept;
}

// restores default value if field is empty, and erases it if contains the default value.
function erasedefaultcontent(obj) {
//alert(obj.name + " " + obj.value + " " + document.formfields[obj.name].defaultvalue);
	// content of calling field
	if(obj.value==document.formfields[obj.name].defaultvalue) {
		setSingleInputValue (obj, "");
		obj.className = "formtext";
	}
	// the other fields (restore to default value if empty)
	for(key in document.formfields) {
		if(key==obj.name) continue;
		tmp = eval("document.user_form." + key);
		if(tmp.value=="") {
			tmp.value = document.formfields[key].defaultvalue;
			tmp.className = "formtextfaded";
		}
	}
}

function submitform(userformname, lg, confirmpage) {
	// creates hidden form
	var sent_form = window.document.createElement("form");
	sent_form.name = 'hidden_form';
	sent_form.method="post";
	sent_form.enctype="multipart/form-data";
	sent_form.action = confirmpage + '_' + lg + '.php';

	// copy all fields in hidden form
	for(key in document.formfields) {
		user_field = eval("document." + userformname + "." + key);
		var newElem = window.document.createElement("input");
		newElem.type = "hidden";
		newElem.name = key;
		varform = getSingleInputValue(user_field);
//alert(userformname + " " + key + " " + user_field.type + " " + varform + " " + document.formfields[key].defaultvalue);
		if((user_field.type=="text" || user_field.type=="textarea")
			&& varform==document.formfields[key].defaultvalue) {

			varform="";
		}
		newElem.value = varform;
		sent_form.appendChild(newElem);
	}

	document.body.appendChild(sent_form);

	sent_form.submit();
}
// controls this is a valid email (if there is one) and returns the cleaned email
function ctrlemail(emailtxt) {
	// removes %20, %0A, \r and \n
	forbid = new Array("%0A","%0a","%20","\r","\n","\R","\N");
	for(i=0;i<forbid.length;i++) {
		pos = emailtxt.indexOf(forbid[i]);
		emailtxt = (pos>=0?emailtxt.substring(0,pos):emailtxt);
	}

	if(emailtxt=="") {
		return false;
	}

	if(emailtxt.search(' ')>=0) {
		return false;
	}
	posarobace = emailtxt.search('@');
	poslastdot = emailtxt.lastIndexOf('.');
	if((poslastdot<0)||(poslastdot<posarobace)||(posarobace<0)) {
		return false;
	}

	return(emailtxt);
}
// must have at least a name or a remark to be sent...
function ctrlmsg() {
	if(document.user_form.firstname.value==document.formfields["firstname"].defaultvalue &&
		document.user_form.lastname.value==document.formfields["lastname"].defaultvalue) {
		return false;
	}
	return true;
}

// returns date in ms, or false if not valid, or true if all args are 0.
/*
function date2ms(d,m,y) {
	if(d=="0" && m=="0" && y=="0") return true;
	if(d=="0" || m=="0" || y=="0") return false;
	date = new Date(y,m-1,d-1);
	return date;
}*/

// reads the content of a form element of type radio, checkbox, text, hidden, textarea, select
function getSingleInputValue (obj) {
	switch(obj.type) {
	case 'radio':
	case 'checkbox':
		return (obj.checked?obj.value:"");
	case 'text':
	case 'hidden':
	case 'textarea':
		return obj.value;
	case 'password': return obj.value;
	case 'select-one':
		if(obj.options==null) {return "";}
		if(obj.selectedIndex<0) {return "";}
		return obj.options[obj.selectedIndex].value;
	case 'select-multiple':
		if(obj.options==null) {return null;}
		var values=new Array();
		for(var i=0;i<obj.options.length;i++) {
			if(obj.options[i].selected) {
				values[values.length]=obj.options[i].value;
			}
		}
		return(values.length==0)?"":values;
	}
	return "";
}

// writes the content of a form element of type radio, checkbox, text, hidden, textarea, select
function setSingleInputValue(obj, newvalue) {
	switch(obj.type) {
	case 'radio':
	case 'checkbox':
		// TODO
		return;
	case 'text':
	case 'hidden':
	case 'textarea':
		obj.value = newvalue;
	case 'select-one':
		if(obj.options==null) {return;}
		for(var i=0;i<obj.options.length;i++) {
//alert(i + " " + obj.name + " " + obj.options[i].value + " =? " + newvalue);
			if(obj.options[i].value==newvalue) {
				obj.options[i].selected = true;
				return;
			}
		}
		return;
	case 'select-multiple':
		// TODO
		return;
	}
	return null;
}

