var sp08Quiz = new Class({
	
	lockme : false,
	
	initialize : function()
	{
		//ie fixes..
		
		if(window.ie)
		{
			$$(".cblabel")[0].setStyles({
				width:133,
				lineHeight:27
			});
		}
		
	},
	
	gotoForm : function()
	{

		var hasAns = $("ans0").checked || $("ans1").checked;
		//console.log(hasAns);
		if(!hasAns)
		{
			//$("lbl0").effects({duration:500}).start({"color":["#ff0000","#000000"]});
			//$("lbl1").effects({duration:500}).start({"color":["#ff0000","#000000"]});
			$$("#sp08qfrage p")[0].effects({duration:500}).start({"color":["#ff0000","#0e5fb0"]});
			return;
		}


		
		if(this.lockme)return;
		this.lockme = true;
		
		$("sp08qfrage").effects({duration:500,onComplete:function()
			{
				sp08q.showForm();
			}}).start({opacity:[1,0]});
	},
	
	showForm : function()
	{
		$("sp08qform").setStyles({"opacity":0,"display":"block"});
		$("sp08qform").effects({duration:500,onComplete:function()
			{
				sp08q.lockme = false;
			}}).start({opacity:[0,1]});
	},
	
	
	
	validateForm : function()
	{
		if(this.lockme)return;
		
		var Err = 0;
		Err += this.validateElem($("sp08qf_vorname"),{lengthmin:1,lengthmax:50,re:'textonly'});
		Err += this.validateElem($("sp08qf_name"),{lengthmin:1,lengthmax:50,re:'textonly'});
		Err += this.validateElem($("sp08qf_email"),{lengthmin:1,lengthmax:50,re:'email'});
		
		if(Err > 0)return;
		this.lockme = true;

		new Json.Remote("/index.php?id="+docID+"&receivejson=true",{
			onComplete : function()
			{
				$("sp08qform").effects({duration:30,onComplete:function()
				{
					sp08q.showThanks();
				}}).start({opacity:[1,0]});
				
			}
		}).send({
			vorname : $("sp08qf_vorname").value,
			email : $("sp08qf_email").value,
			nachname : $("sp08qf_name").value,
			nl : $("sp08qf_nl").checked?"ja":"nein",
			antwort : $("ans0").checked?"0":"1"
			});


		
	},
	
	showThanks : function()
	{
		
		$("sp08qthanks").setStyles({"opacity":0,"display":"block"});
		$("sp08qthanks").effects({duration:500,onComplete:function()
			{
				sp08q.lockme = false;
			}}).start({opacity:[0,1]});		
	},	
	
	validateElem : function(elem,vObj)
	{
	
		var valid = this.validateInput(elem.value,vObj);
		if(!valid)
		{
			//elem.setStyle("border","1px solid #ff0000");
			elem.effects({duration:200}).start({"backgroundColor":["#ff0000","#ffffff"]});
		}
		else
		{
			//elem.setStyle("border","");
		}
		
		return valid?0:1;
	},
	
	
	validateInput : function(vStr, vObj)
	{
		var re = [], valid = true;
		re['textonly'] = /^[0-9A-Za-z ÄÜÖäöüßéáàèóòÈÉÁÀÒÓîÎùúÚÙûÛôÔâÂêÊ-]*$/;
		re['numonly'] = /^[0-9]*$/;
		re['tel'] = /^[0-9 +-]*$/;
		re['email'] = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	
		if(vObj.re && vStr.search(re[vObj.re]) == -1)valid = false;
		if(vObj.lengthmin && vStr.length < vObj.lengthmin)valid = false;
		if(vObj.lengthmax && vStr.length > vObj.lengthmax)valid = false;
		
		return valid;
	}
	
	
});


dlhooks[dlhooks.length] = function()
{
	sp08q = new sp08Quiz();
}
