function headchanger(id){
	var id;
	var elements = document.getElementsByTagName("dd");
	for(i=0; i<elements.length; i++){
		if(elements[i].id == id.replace("tag", "dsc")){
			elements[i].style.zIndex = "50";
		}else{
			elements[i].style.zIndex = "0";
		}
	}
	
	var paraphs = document.getElementsByTagName("p");
	for(i=0; i<paraphs.length; i++){
		if(paraphs[i].id == id.replace("tag", "midhline")){
			paraphs[i].style.zIndex = "1000";
		}else{
			paraphs[i].style.zIndex = "0";
		}
	}
	
	var headdt = document.getElementsByTagName("dt");
	for(i=0; i<headdt.length; i++){
		
		if(headdt[i].id == id){
			headdt[i].className = "onDT";
		}else{
			headdt[i].className = "offDT";
		}
	}
	
}


function midchanger(id){

	var id; 
	
	var elements = document.getElementById("midnews").getElementsByTagName("div");
	for(i=0; i<elements.length; i++){
		if(elements[i].id == id.replace("midhead", "midhold")){
			elements[i].style.zIndex = "50";
		}else{
			elements[i].style.zIndex = "0";
		}
	}
	
	
	var midheads = document.getElementById("midlines").getElementsByTagName("li");
	
	for(i=0; i<midheads.length; i++){
		if(midheads[i].id == id){
			midheads[i].className = "midheadOn";
		}else{
			midheads[i].className = "midheadOff";
		}
	}
	
	var hliners = document.getElementById("hlineholder").getElementsByTagName("p");
	
	for(i=0; i<hliners.length; i++){
		if(hliners[i].id == id.replace("midhead", "midhline")){
			hliners[i].style.zIndex = "50";
		}else{
			hliners[i].style.zIndex = "0";
		}
	}
}

function comChanger(tab){
	var com = document.getElementById('com');
	var cms = document.getElementById('cms');
	var tbs = document.getElementById(tab);
	
	if(tab == "comment"){
		cms.className = "";
		com.className = "ocomms";
		tbs.style.zIndex = "1";
		document.getElementById('comform').style.zIndex = "0";
	}else{
		cms.className = "ocomms";
		com.className = "";
		tbs.style.zIndex = "1";
		document.getElementById('comment').style.zIndex = "0";
	}
}


function sendComm(receive, newsid){
	var receive, newsid;
	
	name	= document.getElementById('adsoyad').value;
	mess	= document.getElementById('yorum').value;
	
	post = "name="+name+"&mess="+mess+"&n="+newsid;
	
	if(!name || name.length < 3){
		document.getElementById("errors").innerHTML = "Adınız <font style='color:#CC0000;'>Gerekli!</font>";
	}
	
	if(!mess || mess.length < 3){
		document.getElementById("errors").innerHTML = "Mesajınız <font style='color:#CC0000;'>Gerekli!</font>";
	}
	
	req.open('post','/actions/comment.php',true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	req.send(post);
	req.onreadystatechange = function(){
		if(req.readyState == 4){
			if(req.responseText.indexOf("iletildi") != -1){
				document.getElementById("errors").innerHTML = "<b>Teşekkürler!</b></div>";
				document.getElementById("button").setAttribute("onclick","");
				document.getElementById("button").disabled = true;
			}
		}else{
			return false;
		}
	}	
}


function changeBook(id){

	var id; 
	
	var elements = document.getElementById("bookses").getElementsByTagName("div");
	for(i=0; i<elements.length; i++){
		if(elements[i].id == id.replace("chan", "book")){
			elements[i].style.zIndex = "50";
		}else{
			elements[i].style.zIndex = "0";
		}
	}
}


function popen(url){
	var w,h,s;
	if(!w){w = 500;}
	if(!h){h = 370;}
	if(!s){s = "no";}
	LeftPosition = (screen.width)?(screen.width-w)/2:100;
	TopPosition = (screen.height)?(screen.height-h)/2:100;
	settings ='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+s+',location=no,addressbar=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(url,'',settings);
}




function markStar(starID){
	stars = document.starsForm.getElementsByTagName('img');
	for(i=0; i<stars.length; i++){
		if(stars[i].id == starID){
			stars[i].src = "/images/tools/star.png";
			for(j=0; j<i; j++){
				stars[j].src = "/images/tools/star.png";
			}
		}else{
			stars[i].src = "/images/tools/staro.png";
		}
	}
}

function unmarkStar(){
	stars = document.starsForm.getElementsByTagName('img');
	for(i=0; i<stars.length; i++){
		if(stars[i].id == document.starsForm.starid.value){
			for(j=0; j<i+1; j++){
				stars[j].src = "/images/tools/star.png";
			}
		}else{
			stars[i].src = "/images/tools/staro.png";
		}
	}
}

function selectStar(starID, bookID){
	stars = document.starsForm.getElementsByTagName('img');
	for(i=0; i<stars.length; i++){
		if(stars[i].id == starID){
			doRate(starID, bookID);
		}
		stars[i].setAttribute("onclick","");
		stars[i].style.cursor = "default";
		
		stars[i].setAttribute("onmouseout","");
		stars[i].style.cursor = "default";
		
		stars[i].setAttribute("onmouseover","");
		stars[i].style.cursor = "default";

	}
}


function doRate(count, bookID){
	
	post = "count="+count+"&bookID="+bookID;
	
	req.open('post','/actions/rating.php',true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	req.send(post);
	req.onreadystatechange = function(){
		if(req.readyState == 4){
		alert(req.responseText);
		}else{
			return false;
		}
	}	
}

function ilikeit(count, bookID){
	
	post = "count="+count+"&bookID="+bookID;
	
	req.open('post','/actions/ilike.php',true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	req.send(post);
	req.onreadystatechange = function(){
		if(req.readyState == 4){
			alert(req.responseText);
		}else{
			return false;
		}
	}	
}

function commentForm(){
	
	message	= document.getElementById("commentMessage").value;
	bookid	= document.getElementById("commentBookid").value;
	
	post = "message="+message+"&bookid="+bookid;
	
	
	if(message == ""){
		document.getElementById("commentResponse").innerHTML = "<font class=\"font\" style=\"color:brown;\"><b>Lütfen yorumunuzu yazın</b></font>";
	}
	
	
	req.open('post','/actions/commentForm.php',true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
	req.send(post);
	req.onreadystatechange = function(){
		if(req.readyState == 4){
			if(req.responseText.indexOf("iletildi") != -1){
				document.getElementById("buttonComment").setAttribute("onclick","");
				document.getElementById("buttonComment").style.cursor = "default";
				document.getElementById("commentResponse").innerHTML = "<font class=\"font\" style=\"color:brown;\"><b>Yorumunuz iletildi. Teşekkür ederiz</b></font>";
			}
		}else{
			return false;
		}
	}	
}