var errWindow = document.getElementById("errWindow");
var allValue = new Array("cContent");

function FormControl(getValue){
	var lastStatus = true;
	errWindow.innerHTML = "";
	var docValue = getValue.cContent;
	if (docValue.value == ""){
		errWindow.innerHTML = errWindow.innerHTML + "<a>Lütfen yorum yazınız</a>";
		lastStatus = false;
	}
	if (docValue.value.length < 10){
		errWindow.innerHTML = errWindow.innerHTML + "<a>Lütfen bir kaç kelime yazınız</a>";
		lastStatus = false;
	}
	return lastStatus;
}

for (f=0; f < allValue.length; f++){
	document.getElementById(allValue[f]).onblur = function(){ FormControl(document.getElementById("saveComment")); }
	document.getElementById(allValue[f]).onfocus = function(){ FormControl(document.getElementById("saveComment")); }
}

function characterCut(getValue, chaNum){
	var Z = chaNum - getValue.value.length; 
	if (Z < 0){getValue.value = getValue.value.substring(0, getValue.value.length + Z); Z = 0};
	FormControl(document.getElementById("saveComment"));
	document.getElementById("countChar").innerHTML = Z;
}

function CommentSave(getValue){
	if (FormControl(getValue)){;
		errWindow.innerHTML = "<a style='color:#005500;'><b>Lütfen bekleyin...</b></a>";
		document.getElementById("sendComment").disabled = true;

		xmlHttp = GetXmlHttpObject();
		if(xmlHttp == null){
			alert("Browserınız HTTP Request'i Desteklemiyor.");
			return
		}

		var url = cDomain + "commentSave.php";
		var sc = "cComment="+ document.getElementById("cContent").value +'&cWhere='+ document.getElementById("cWhere").value +'&cUrl='+ document.getElementById("cUrl").value;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=iso-8859-9");
		xmlHttp.setRequestHeader("Content-length", sc.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.onreadystatechange = CommentSaveExecute;
		xmlHttp.send(sc);
	}

	/*
	if (FormControl(getValue)){;
		errWindow.innerHTML = "<a style='color:#005500;'><b>Lütfen bekleyin...</b></a>";
		document.getElementById("sendComment").disabled = true;
		XmlExecute(cDomain + "commentSave.php?cWhere=" + cWhere + "&cComment=" + document.getElementById("cContent").value, CommentSaveExecute, '');
	}
	*/
}

function CommentSaveExecute(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		if (200 == xmlHttp.status){
			var Result = xmlHttp.responseXML.getElementsByTagName("RESULT")[0].childNodes[0].nodeValue;
			if (Result == "ok"){
				errWindow.innerHTML = "<a style='color:#005500;'>Yorumunuz iletildi. Editörler tarafından onaylanınca yayına verilecektir.</a>";
				document.getElementById("cContent").value = "";
				document.getElementById("sendComment").disabled = false;
			}
			else { errWindow.innerHTML = errWindow.innerHTML + "<a>Lütfen üye önce üye olunuz.</a>"; }
		}
	}
}