// Initialise the effects
var showhide;
window.onload = function() {
 showhide = new fx.Combo('myelementid', {height: true, opacity: false, duration: 200});
//Load some data when the page load
//but give general Javascript some time load
//setTimeout("loadit('data.php');", 300);
}
//This is the function that you call with the php var (in this case)
//or any var or url (change the script called in ajax var
function loadit(fragment_url, loadingID) {
	
	//Toggle off the layer 
var element = document.getElementById('showhide');
if (element.innerHTML != '') {
element.innerHTML = 'Hide';
}

showhide.toggle();
scrollToAnchor('comments');
	//Let some time for the effect to take place 
	//and then call the ajax/httprequest function
	//NOTE HERE that the setTimeout(string, int) need to be 100ms more than in your fx.Combo
	var element = document.getElementById('loading'); 
	element.style.display = 'block';
	setTimeout("getajax(\""+fragment_url+"\");", 300);
}
//Ajax httpRequest
function getajax(fragment_url){
	new ajax(fragment_url, { method: 'get', update: $('load'),
		onComplete: function() {
			//Oncomplete toggle back the layer and voila
			trythis();
		}
	});
}
//Let some time for the effect to take place again!!! Short time 100 or so
function trythis() {
	setTimeout("showhide.toggle();", 100);
	var element = document.getElementById('loading');
	element.style.display = 'none';
	document.getElementById('commentlink').onclick = closeit;
}

function closeit() {
var element = document.getElementById('showhide');
var scrolla;
if (element.innerHTML != '') {
	
if (element.innerHTML == 'Hide') {
element.innerHTML = 'Show';
scrolla = 'top';

} else {
element.innerHTML = 'Hide';
scrolla = 'comments';
}
}

showhide.toggle();
scrollToAnchor(scrolla);
 }
 
 function postajax(elementos){
	 
var errorn = ''
var foco = '';
var elemento = ''; 
var elemento_c = '';
var mensaje ='';

function isValidEmail(mainelemento,nombre,elid) {
elemento = document.getElementById(mainelemento);
elemento_c = document.getElementById(mainelemento+'_c');
mensaje = 'The E-mail provided is not valid.';

   if ( (elemento.value.indexOf(".") > 2) && (elemento.value.indexOf("@") > 0) ) {
elemento_c.innerHTML = '';	   
} else {
errorn = '1'; 
elemento_c.innerHTML = '<span class="rojo">*</span>';
alert(mensaje);
}
}

function checktext(mainelemento,nombre,elid) { 
elemento = document.getElementById(mainelemento);
elemento_c = document.getElementById(mainelemento+'_c');
mensaje = 'The field "'+ nombre + '" is required'; 

if (elemento.value == '') { 
errorn = '1'; 
elemento_c.innerHTML = '<span class="rojo">*</span>';
alert(mensaje);
} else { elemento_c.innerHTML = ''; }
}

checktext('nombre','Name',1);
isValidEmail('email','E-mail',2);
checktext('comentario','Comment',4);

if (errorn == '') { 	 
var elementosx = '';
for (x in elementos) {
	if (elementos[x] == 'showemail') {
	$('showemail').checked == false ? $('showemail').value = '0' : $('showemail').value = '1';
	}
	
	elementosx += "&"+elementos[x]+"="+ escape( $(elementos[x]).value);
	}	 
new ajax ('postcomment.php', {postBody: elementosx.substring(1), update: $('formacontacto')});
}
 }
	