﻿function apAutoLoad() {
	try {
		if (sessionStorage.mini == 'true') apStartEditor();
	} catch (e) {}
}

function apStartEditor() {
	if (typeof Mini == 'undefined') {
		var script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('src', 'http://it.altervista.org/alterpages/script.php?cb='+(new Date()).valueOf());
		document.getElementsByTagName('head')[0].appendChild(script);
	} else if (Mini.status.ap) {
		Mini.stopEditor();
	} else {
		Mini.restartEditor();
	}
	return false;
}

function apMailerCheck(form) {
	if (form.subject.value == '') {
		alert("Non hai specificato l'oggetto");
		return false;
	}
	if (form.from.value == '') {
		alert("Non hai specificato l'indirizzo per le risposte");
		return false;
	}
	if (form.message.value == '') {
		alert("Non hai scritto nulla nel messaggio");
		return false;
	}

	if (document.getElementById('apmailer-div')) {
		document.getElementById('apmailer-div').style.display = 'block';
	} else {
		var div = document.createElement('div');
		div.id = 'apmailer-div';
		div.className = 'apmailer-popup';
		div.style.position = 'fixed';
		div.style.top = '100px';
		div.style.left = '100px';

		var div2 = document.createElement('div');
		div2.className = 'apmailer-head';
		var img = document.createElement('img');
		img.src = 'http://im.altervista.org/alterpages/cross-button.png';
		var cb = function(){document.getElementById("apmailer-div").style.display="none"};
		if (img.attachEvent) img.attachEvent('onclick', cb); else img.addEventListener('click', cb, false);
		div2.appendChild(img);
		
		div.appendChild(div2);

		var iframe = document.createElement('iframe');
		iframe.style.width = '100%';
		iframe.style.height = '380px';
		iframe.name = 'apmailer';
		iframe.id = 'apmailer-iframe';
		div.appendChild(iframe);
		(document.getElementsByTagName('body')[0]).appendChild(div);
	}

	return true;
}

if (window.attachEvent) window.attachEvent('onload', apAutoLoad);
else if (document.attachEvent) document.attachEvent('onload', apAutoLoad);
else if (window.addEventListener) window.addEventListener('load', apAutoLoad, false);
else if (document.addEventListener) document.addEventListener('load', apAutoLoad, false);
else if (window.onLoad) window.onLoad = apAutoLoad;
