<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it" dir="ltr">
<head>
<title>Blogerino</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="css/main.css" />
<script type="text/javascript">
function _createElement(el,obj){
	var _el= document.createElement(el);
	for(var prop in obj){
		 _el.setAttribute(prop,obj[prop]);
	}
	return _el;
};
function _createTextNode(text){
	return document.createTextNode(text);
};
function _removeChild(parent,child){
	if(child != null){
		parent.removeChild(child);
	}
};
function addEvent(elm, evType, fn, useCapture){
	if (elm.addEventListener){
			elm.addEventListener(evType, fn, useCapture);
			return true;
	} else if (elm.attachEvent) {
		var r = elm.attachEvent('on' + evType, fn);
		return r;
	} else {
		elm['on' + evType] = fn;
	}
};
function cancelClick(e){
	if (window.event){
		window.event.cancelBubble = true;
		window.event.returnValue = false;
		return;
	}
	if (e){
		e.stopPropagation();
		e.preventDefault();
	}
};
function $(){
	var elements = new Array();
	for (var i = 0, len = arguments.length; i < len; i++){
		var element = arguments[i];
		if (typeof element == 'string'){
		  element = document.getElementById(element);
		}
		if (arguments.length == 1){
		  return element;
		}
		elements.push(element);
  	}
	return elements;
};
/* Validation */
function isEmpty(val) {
   return !/\S/.test(val);
} 
function isValidEmail(str) {
	// 
http://www.devpro.it/php4_id_2.html
	return Boolean(str.match(/^([a-z0-9]+[\._\-]?){1,3}([a-z0-9])*\@([a-z0-9]+[\.\-]?){1,3}([a-z0-9])*\.[a-z]{2,6}$/i));
};
function isInt(val) {
   return /^[1-9]\d{0,9}$/.test(val);
};
function isUrl(url){
	return /^(\w{2,6}:\/\/|www[0-9]*\.)\w+\.\w{2,6}/.test(url);
};
function isEmptyV(id,errMsg){
	this.el= document.getElementById(id);
alert(this.el.id);
	this.isValid= function(){
		var isValid= true;
		if(isEmpty(this.el.value)){
			this.error= errMsg;
			isValid= false;
		}
		return isValid;
	}
};
function isValidEmailV(id,errMsg){
	this.el= document.getElementById(id);
	this.isValid= function(){
		var isValid= true;
		if(!isValidEmail(this.el.value)){
			this.error= errMsg;
			isValid= false;
		}
		return isValid;
	}
};
function isIntV(id,errMsg){
	this.el= document.getElementById(id);
	this.isValid= function(){
		var isValid= true;
		if(!isInt(this.el.value)){
			this.error= errMsg;
			isValid= false;
		}
		return isValid;
	}
};
function isUrlV(id,errMsg){
	this.el= document.getElementById(id);
	this.isValid= function(){
		var isValid= true;
		if(this.el.value!='http://'){
			if(!isUrl(this.el.value)){
				this.error= errMsg;
				isValid= false;
			}
		}
		return isValid;
	}
};
function Validator() {
 	var validators= [];
	this.errors= [];
	this.values= {};
	this.add= function(objV){
		validators.push(objV);
	}
this.isValid= function(){
		var isValidFlag= true;
		for(var i=0, len= validators.length;i< len;i++){
			if(!validators[i].isValid()){
				this.errors.push({error:validators[i].error,el:validators[i].el});
				isValidFlag= false;
			}
			else{
				this.values[validators[i].el.id]=validators[i].el.value;
			}
		}
		return isValidFlag;
	}
}
function setOpacity(el,value) {
	var v= +value;
	el.style.opacity = v/10;
	el.style.filter = 'alpha(opacity=' + v*10 + ')';
}
function preloadImgs(args) {
	for(var n=0, len = arguments.length;n<len;n++) {
		preloadImg(arguments[n]);
	}	
	function preloadImg(percorso) {
		var temp=new Image();
		temp.src=percorso;
	}
}
function resetStyle(target,bCol,col){
	var inputList= target.getElementsByTagName('input');
	for(var i=0,len=inputList.length;i<len;i++){
		inputList.item(i).style.backgroundColor=bCol;
		inputList.item(i).style.color=col;
	}
	var textList= target.getElementsByTagName('textarea');
	for(var i=0,len = textList.length;i<len;i++){
		textList.item(i).style.backgroundColor=bCol;
		textList.item(i).style.color=col;
	}
};
function Comment(){
	var page= 'xhr/ajax-insert-comment.php?a=insert_comment';
	var frm= null;
	var c_save= null;
	var frmHeight= 0;
	var spacer= 30;
	var noXhr= 'Il tuo browser non supporta questo script.';
	var errMsgAuthor= 'L\'autore e\' obbligatorio.';
	var errMsgEmail= 'Inserisci un indirizzo email valido.';
	var errMsgUrl= 'Url del sito personale non valido.';
	var errMsgComment= 'Il commento e\' obbligatorio.';
	var errMsgCaptcha= 'Il codice di sicurezza e\' obbligatorio.';
	var successfull= 'Grazie. Il tuo commento sara\' pubblicato a breve.';
	function Response(xhr){}
	function Request(values){}
	function checkForm(e){
		var validator = new Validator();
		//validator.add(new isIntV('pid','Something went wrong'));
		validator.add(new isEmptyV('author',errMsgAuthor));
		//validator.add(new isValidEmailV('email',errMsgEmail));
		//validator.add(new isUrlV('url',errMsgUrl));
		validator.add(new isEmptyV('comment',errMsgComment));
		//validator.add(new isEmptyV('security',errMsgCaptcha));
		cancelClick(e);
		if(!validator.isValid()){
			//resetStyle(frm,"#f4f4f4","#000000");
			showError(frm,validator);
		}
		else{
			Request(validator.values);
		}
		addEvent(window,'load',checkForm,false);
	}
	function closeError(){
		c_save.disabled= false;
		var errorMsg= $('error-msg');
		_removeChild(frm,errorMsg);
	}
	function showError(target,objV){
		c_save.disabled= true;
		var errorMsg= buildError();
		var errorMsgBox= _createElement('div',{id:'error-msg-box'});
		errorMsgBox.style.paddingTop= Math.floor((frmHeight-spacer)/5)+'px';
		for(var i=0,len=objV.errors.length;i<len;i++){
			var wrapper= _createElement('p',{});
			wrapper.className= 'wrapper-error';
			wrapper.appendChild(_createTextNode(objV.errors[i].error));
			errorMsgBox.appendChild(wrapper);
		}
		errorMsg.appendChild(errorMsgBox);
		objV.errors[0].el.style.backgroundColor= '#FF0000';
		objV.errors[0].el.style.color= '#FFFFFF';
		target.appendChild(errorMsg);
	}
	function showLoader(){
		var wrapper= _createElement('div',{id:'loader'});
		setOpacity(wrapper,8);
		var divHeight= frmHeight-spacer;
		wrapper.style.height= divHeight+'px';
		wrapper.style.marginTop= spacer+'px';
		frm.appendChild(wrapper);
	}
	function commentBlock(){
		var commentBlock= _createElement('div',{id:'comment-block'});
		var commentBlockIn= _createElement('p',{});
		commentBlockIn.appendChild(_createTextNode(success  full));
		commentBlock.appendChild(commentBlockIn);
		var wrapper= $('comment-wrapper');
		wrapper.replaceChild(commentBlock,frm);
	}
	function buildError(){
		var errorMsg= _createElement('div',{id:'error-msg'});
		setOpacity(errorMsg,8);
		var divHeight= frmHeight-spacer;
		errorMsg.style.height= divHeight+'px';
		errorMsg.style.marginTop= spacer+'px';
		var xclose= _createElement('p',{'id':'xclose'});
		var xspan= _createElement('span',{});
		xspan.appendChild(_createTextNode('X'));
		xclose.appendChild(xspan);
		errorMsg.appendChild(xclose);
		addEvent(xspan, 'click', closeError, false);
		return errorMsg;
	}
	function showErrorServer(msg){
		var errorMsg= buildError();
		var errorMsgBox= _createElement('div',{id:'error-msg-box'});
		errorMsgBox.style.paddingTop= Math.floor((frmHeight-spacer)/5)+'px';
		var wrapper= _createElement('p',{});
		wrapper.className= 'wrapper-error';
		wrapper.appendChild(_createTextNode(msg));
		errorMsgBox.appendChild(wrapper);
		errorMsg.appendChild(errorMsgBox);
		_removeChild(frm,$('loader'));
		var security= $('security');
		security.style.backgroundColor= '#FF0000';
		security.style.color= '#FFFFFF';
		frm.appendChild(errorMsg);
	}
	function init(){
		if(!document.getElementById || !document.getElementsByTagName || !document.createTextNode){return;}
		frm= $('frm-comment');
		if(frm != null){
			preloadImgs('images/ajax-loader.gif');
			frmHeight= frm.offsetHeight;
			c_save= $('c-save');
			$('author').focus();
			addEvent(frm, 'submit', checkForm, false);
		}
	}
	init();
}
addEvent(window,'load',Comment,false);
</script>
</head>
<body>
<div id="container">
	<div id="content">
		<div id="comment-wrapper">
			<form action="www/index.php?u=new_comment" method="post" id="frm-comment">
			<h3 id="respond"><a name="nc124">Inserisciiltuocommento</a>
			</h3>
			<fieldset>
			<input name="c_post_id" type="hidden" value="124" id="pid"  />
			
<label for="author">Nome:</label>
			<input name="c_author" type="text" title="author" value="" id="author" maxlength="25" tabindex="1"  />
			</p>
			
<label for="email">Indirizzoe-mail(nonverràpubblicato):</label>
			<input name="c_email" type="text" title="email" value="" id="email" maxlength="50" tabindex="2"  />
			</p>
			
<label for="url">SitoWeb:</label>
			<input name="c_url" type="text" title="url" value="http://" id="url" maxlength="50" tabindex="3"  />
			</p>
			
<label for="comment">Commento:</label>
			<textarea name="c_comment" title="comment" id="comment" cols="30" rows="10" tabindex="4">
			</textarea>
			</p>
			<input id="c-save" name="check_insert" type="submit" value="send"  />
			</fieldset>
			
Nb.
Devi avere i cookie abilitati per commentare l'articolo.
I commenti saranno soggetti ad approvazione da parte dell'administrator.</p>
			</form>
		</div>
	</div>
	<div id="footer">
Blogerino by Whisher</p></div>
</div>
</body>
</html>