/*			validation			*/
function validateMe(){
	if (document.getElementById('name').value == ""){
		document.getElementById('name').style.borderColor = 'red';
		var this_name = document.getElementById('name');
		alert("Name cannot be blank, user who wishes to remain anonymous!");
		this_name.focus();
		return false;
	}
	//regex me up!
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(document.getElementById('email').value)){
		document.getElementById('email').style.borderColor = 'red';
		var this_mail = document.getElementById('email');
		alert("Email is not valid. try again.");
		this_mail.focus();
		return false;
	}
	else if (document.getElementById('body').value == ""){
		document.getElementById('body').style.borderColor = 'red';
		var this_body = document.getElementById('body');
		alert("Seriously, what is the point with a blank message?");
		this_body.focus();
		return false;
	}
	else{
		var yourName = document.getElementById('name').value;
		var yourEmail = document.getElementById('email').value;
		goCap();
	}
}

function clearErr(div){
	document.getElementById(div).style.borderColor = '';
	if (div == 'name'){
		document.getElementById('nameErr').innerHTML = '';
	}
}

function addC(){
	document.getElementById('theForm').style.display = 'none';
	document.getElementById('waiting').style.display = 'block';
	document.getElementById('submitButton').disabled = true;
	//alert('paused');
	var ajaxRequest;
	try{
		//safari, firefox - gecko based etc
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// ie
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// eek! something went wrong
				alert("Your browser is.. well as the French would say: \"le suq\"\n\nAjax request failed. Make sure you have JavaScript enabled, or are connected to the internet.");
				return false;
			}
		}
	}
	// this is where the magic begins!
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if (ajaxRequest.responseText == 1){
				document.getElementById('waiting').style.display = 'none';
				document.getElementById('commentAdded').style.display = 'block';
				theWidth = document.getElementById('comments').style.width;
				theWidth = theWidth.replace(/px/,'');
				closeWin = setTimeout('showForm()', 5000);
				getComms();
				newCap();
			}
		}
	}
	
	var chr10 = String.fromCharCode(10);
	var chr13 = String.fromCharCode(13);
	var getBody = document.getElementById('body').value;
	var c10 = new RegExp(chr10, 'gi');
	getBody = getBody.replace(c10, '<br>');
	var c13 = new RegExp(chr13, 'gi');
	getBody = getBody.replace(c13, '<br>');
	
	var hideMail = document.getElementById('hidemail').checked;
	if (hideMail == true){
		hideMail = 1;
	}
	else{
		hideMail = 0;
	}
	
	var url="inc/addCom.php";
	url=url+"?n=" + document.getElementById('name').value;
	url=url+"&e=" + document.getElementById('email').value;
	url=url+"&b=" + getBody;
	url=url+"&h=" + hideMail;
	url=url+"&sid="+Math.random();
	ajaxRequest.open("GET", url, true);
	ajaxRequest.send(null); 
}

function newCap(){
	document.getElementById('cap').value = '';
	var newCaptcha;
	try{
		//safari, firefox - gecko based etc
		newCaptcha = new XMLHttpRequest();
	} catch (e){
		// ie
		try{
			newCaptcha = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				newCaptcha = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// eek! something went wrong
				alert("Your browser is.. well as the French would say: \"le suq\"\n\nAjax request failed. Make sure you have JavaScript enabled, or are connected to the internet.");
				return false;
			}
		}
	}
	//new captcha
	newCaptcha.onreadystatechange = function(){
		if(newCaptcha.readyState == 4){
			document.getElementById('capimg').innerHTML = '<img src="images/loader.gif" border="0" alt="" />';
			setTimeout('document.getElementById(\'capimg\').innerHTML = \'<img src="inc/captcha.php?sid='+Math.random()+'" border="0" alt="dooo eeeet!" />\'', 500);
		}
	}
	var url = "inc/captcha.php";
	url = url + "?sid=" + Math.random();
	newCaptcha.open("GET", url, true);
	newCaptcha.send(null);
}

function showForm(){
	document.getElementById('commentAdded').style.display = 'none';
	document.getElementById('theForm').style.display = 'inline';
}

function getComms(){
	var ajaxRequest2;
	try{
		//safari, firefox - gecko based etc
		ajaxRequest2 = new XMLHttpRequest();
	} catch (e){
		// ie
		try{
			ajaxRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// eek! something went wrong
				alert("Your browser is.. well as the French would say: \"le suq\"\n\nAjax request failed. Make sure you have JavaScript enabled, or are connected to the internet.");
				return false;
			}
		}
	}
	// magickses
	ajaxRequest2.onreadystatechange = function(){
		if(ajaxRequest2.readyState == 4){
			NLBfadeBg('dispComments', '#FFC0CC', '#FFDAE1', 1000);
			document.getElementById('dispComments').innerHTML = ajaxRequest2.responseText;
			document.getElementById('body').value = '';
			document.getElementById('submitButton').disabled = false;
		}
	}
	var url="inc/viewCom.php";
	url = url + "?sid=" + Math.random();
	ajaxRequest2.open("GET", url, true);
	ajaxRequest2.send(null); 
}


function goCap(){
	var ajaxRequest3;
	try{
		//safari, firefox - gecko based etc
		ajaxRequest3 = new XMLHttpRequest();
	} catch (e){
		// ie
		try{
			ajaxRequest3 = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest3 = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// eek! something went wrong
				alert("Your browser is.. well as the French would say: \"le suq\"\n\nAjax request failed. Make sure you have JavaScript enabled, or are connected to the internet.");
				return false;
			}
		}
	}
	// this is where the magic begins!
	ajaxRequest3.onreadystatechange = function(){
		if(ajaxRequest3.readyState == 4){
			if (ajaxRequest3.responseText == 1){
				addC();
			}
			else if (ajaxRequest3.responseText == 0){
				alert('Wrong. Try again.');
			}
		}
	}
	var url = "inc/validCap.php";
	url = url + '?c=' + document.getElementById('cap').value;
	url = url + '&sid=' + Math.random();
	ajaxRequest3.open("GET", url, true);
	ajaxRequest3.send(null); 
}



var theColor = 0;

function startNom(){
	if (isIE6 == 0){
		hiliteNom = setInterval("showNom()", 1001);
	}
}

function showNom(){
	if (theColor == 0){
		NLBfadeBg('frame_17', '#FFFFCC', '#FFFF66', 1000);
		theColor = 1;
	}
	else{
		NLBfadeBg('frame_17', '#FFFF66', '#FFFFCC', 1000);
		theColor = 0;
	}
	
}