var xmlHttp;

function CreateRequest() {
 	var msie = new Array( 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' );
	for ( var i = 0; i < msie.length; i++ ) {
		try {xmlHttp = new ActiveXObject( msie[i] );}
		catch (e) {xmlHttp = null;}
	}
 	if( !xmlHttp ) {xmlHttp = new XMLHttpRequest();}
}

function StartRequest(type, url) {
	CreateRequest();
	xmlHttp.onreadystatechange = HandleStateChange;
	xmlHttp.open(type, url, true);
	if(type == "POST") {
		xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length",requestQuery.length);
		xmlHttp.setRequestHeader("Connection","close");
		xmlHttp.send(requestQuery);
	}
	xmlHttp.send(null);
}

function HandleStateChange() {
	if(xmlHttp.readyState==4) {
		if(xmlHttp.status==200) {
			ParseResults();
		}
	}
}

function ParseResults() {
	eval(parse_function);
}

var items;
var item_no = 0;
var interval;
var item_count = 0;

function CommentsHome() {
	var response = xmlHttp.responseXML;
	items = response.getElementsByTagName('item');
	item_count = items.length;
	var itm = items[0];
	document.getElementById('comments').innerHTML = '<li>'+itm.childNodes[0].nodeValue+'<br /><br /><strong>'+itm.getAttribute('isim')+' - '+itm.getAttribute('meslek')+'</strong><br /></li><li>Müşteri yorumlarının tamamı için <a href="yorumlar.html">tıklayın.</a></li>';
	interval = setTimeout(commentPaste, 5000);
}

function CommentsPage() {
	var response = xmlHttp.responseXML;
	items = response.getElementsByTagName('item');
	item_count = items.length;
	var doc = document.getElementById('comments');
	for(var i=0; i<item_count; i++) {
		doc.innerHTML = doc.innerHTML + '<div class="divider"></div><h1><strong>'+items[i].getAttribute('isim')+' - '+items[i].getAttribute('meslek')+'</strong></h1><p align="justify">'+items[i].childNodes[0].nodeValue+'</p>';
	}
}

function commentPaste() {
	item_no++;
	if(item_no == item_count) {
		item_no = 0;
	}
	var itm = items[item_no];
	clearTimeout(interval);
	interval = setTimeout(commentPaste, 5000);
	document.getElementById('comments').innerHTML = '<li>'+itm.childNodes[0].nodeValue+'<br /><br /><strong>'+itm.getAttribute('isim')+' - '+itm.getAttribute('meslek')+'</strong><br /></li><li>Müşteri yorumlarının tamamı için <a href="yorumlar.html">tıklayın.</a></li>';
}

var count = false;
var parse_function = null;

function GetComments(num) {
	count = num;
	if(num) {
		parse_function = "CommentsHome()";
	}
	else {
		parse_function = "CommentsPage()";
	}
	StartRequest("GET", "src/comments.xml");
}
