// SANDARTA News Portal Extreme Pro - npX Pro Javascript file!
// Please contact for any suggestion from info@sandarta.com

var browserName=navigator.appName;
function closynoshowsme() {
	if (browserName=="Netscape") {
		//window.open('','_parent','');
		window.opener = "self";
		self.close();
	} else {
		if (browserName=="Microsoft Internet Explorer") {
			window.opener = "whocares";
			window.close();
		}
	}
} 

// Haber resim, başlık, özet değiştirici...
function changeTheNew(keyx, resim, baslik, ozet) {
	// Setting the picture div area...
	var picElement = document.getElementById("ana_haber_resim");
	if (picElement != null) {
		picElement.innerHTML = "<a href=haber.php?theKey="+keyx+" title="+ozet+"><img src=npX/picture/"+resim+".jpg border=0 width=300 height=200></a>";
	}
	// Setting the header div area...
	var absElement = document.getElementById("ana_haber_ozet");
	if (absElement != null) {
		absElement.innerHTML = ozet;
	}
	// Setting the abstract div area...
	headElement = document.getElementById("haber_baslik_ust");
	if (headElement != null) {
		headElement.innerHTML = baslik+" ...";
	}
}

// MAGAZİN Haber resim, başlık, özet değiştirici...
function changeTheMagazin(keyx, resim, kindex, aindex, ozet) {
	// Setting the picture div area...
	var picElement = document.getElementById(kindex);
	if (picElement != null) {
		picElement.innerHTML = "<a href=haber.php?theKey="+keyx+" title="+ozet+"><img src="+resim+" border=0 width=185 height=124></a>";
	}
	var absElement = document.getElementById(aindex);
	if (absElement != null) {
		absElement.innerHTML = ozet;
	}
}

// Yazdırma fonksiyonu
function printNews(theKey, typeX) {
	// Open the friendly printing page with no bars for the presented key of data!
	window.open('yazdir.php?theKey='+theKey+'&t='+typeX,'','scrollbars=yes,menubar=no,width=775,resizable=no,toolbar=no,location=no,status=no');
}

// TV açan fonksiyon
function openTV() {
	window.open('tv.php','','scrollbars=yes,menubar=no,width=620,height=380,resizable=no,toolbar=no,location=no,status=no');
}

// Radyo açan fonksiyon
function openRadio() {
	window.open('radio.php','','scrollbars=yes,menubar=no,width=550,height=250,resizable=no,toolbar=no,location=no,status=no');
}

// Gazete açan fonksiyon
function openNewsPaper() {
	w = screen.width;
	h = screen.height;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars=yes,resizable=no,toolbar=no,location=no,status=no';
	window.open('gazete.php','',settings);
}

// Ilan detay penceresi acan fonksiyon
function openAdv() {
	window.open('ilan_detay.php','','scrollbars=yes,menubar=no,width=770,height=400,resizable=no,toolbar=no,location=no,status=no');
}

// Ilan resim değiştiren fonksiyon
function changePicture(ix, txt) {
	var theElement = document.getElementById("theMainPicture");
	if (theElement != null) {
		theElement.innerHTML = "<img src='npX/picture/ilan/"+ix+".jpg' width='300' height='200' border='0' title='"+txt+"'>";
	}
}

// Seçilen yazara götüren fonksiyon
function goToWriter() {
	var theElement = document.getElementById("writer");
	if (theElement != null) {
		// Getting writer key...
		var writerK = theElement.options[theElement.selectedIndex].value;
		var locationX = "./yazar.php?theWriter="+writerK;
		window.location = locationX;
	}
}

// Yazarın seçilen yazısına götüren fonksiyon
function goToTextOfWriter() {
	var theElement = document.getElementById("otherwrites");
	if (theElement != null) {
		// Getting text key...
		var textK = theElement.options[theElement.selectedIndex].value;
		var locationX = "./yazar.php?theKey="+textK;
		window.location = locationX;
	}
}

// Metni 'arkadaşına gönder' fonksiyonu
function sendToFriend(theKey) {
	// Open the sending page with no bars for the presented key of data!
	window.open('gonder.php?theKey='+theKey,'','scrollbars=yes,menubar=no,width=450,height=500,resizable=no,toolbar=no,location=no,status=no');
}

// Haber grubu üyelik tetikleyici
function registerToNewsGroup() {
	var theMail = document.getElementById("hmail");
	if (theMail == null || theMail.value.length == 0) {
		alert("Haber grubuna kayıt olmak için e-posta adresinizi belirtmelisiniz!");
	} else {
		var req = newXMLHttpRequest();
		//register the callback handler function
		var callbackHandler = getReadyStateHandler(req, updateForm);
		req.onreadystatechange = callbackHandler;
		req.open("POST", "register.php", true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send("umail="+theMail.value);
	}
}

// This is the callback functions that gets called
// for the response from the server with the XML data
function updateForm(resultXML) {

	var mesaj = resultXML.getElementsByTagName("msg")[0];
	
	var mesajValue = mesaj.firstChild.nodeValue;
	
	document.getElementById("hmail").value = "";
	
	// Show the data...
	alert(mesajValue);
}

// Arama metin kutucuğunda <enter> tuşuna basıldıysa işlemi başlatacak olan fonksiyon!
function goForSearch(event) {
	if (navigator.appName == 'Netscape') {
		if (event.which == 13) {
			searchForText();
		}
	} else {
		if (window.event.keyCode == 13) {
			searchForText();
		}
	}
}

// Site içi arama fonksiyonu...
function searchForText() {
	// Girilen metin boş olmamalı ve en az 3 karakter uzunluğunda olmalı!
	var textElement = document.getElementById("stext");
	// Getting trimmed value!
	theValue = textElement.value;
	if (textElement != null && theValue.length>=3) {
		// Alerting for progress...
		var prArea = document.getElementById("search_status");
		if (prArea != null) {
			prArea.innerHTML = "<img src=img/progress.gif border=0 title='Arama yapılıyor...' width='16' height='16'/> <font size='-3'>...</font>";
		}
		// Tarayıcı tipi explorer ise 'sonuc.php' adresine yönlendirilmeli!
		// CDATA -> Explorer'da özel karakterler XML parser tarafından algılanamıyor
		// Sonuç verisi session'dan çekilmeli!
		var brType = "ie";
		if (browserName=="Netscape") {
			brType = "nie";
		}
		var req = newXMLHttpRequest();
		//register the callback handler function
		var callbackHandler = getReadyStateHandler(req, showResultsOfSearch);
		req.onreadystatechange = callbackHandler;
		req.open("POST", "search.php", true);
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send("stext="+theValue+"&bt="+brType);
	} else {
		alert("Arama yapmak için en az 3 karakterli söz öbeği girmelisiniz!");
	}
}

// Arama fonksiyonu sonuç gösterici...
function showResultsOfSearch(resultXML) {
	
	var alertArea = document.getElementById("g_orta");
	var prArea = document.getElementById("search_status");
	if (prArea != null) {
		prArea.innerHTML = "";
	}
	if (alertArea != null) {
	
		var mesaj = resultXML.getElementsByTagName("msg")[0];
		var result = resultXML.getElementsByTagName("rst")[0];
		
		var mesajValue = mesaj.firstChild.nodeValue;
		var resultValue = result.firstChild.nodeValue;
		
		// Error!!! Ignore user!
		if (resultValue == "false") {
			alert(mesajValue);
		} else {
			// No error. Will show result!
			var data = resultXML.getElementsByTagName("dt")[0];
			var dataValue = data.firstChild.nodeValue;
			if (dataValue == "false") {
				alertArea.innerHTML = mesajValue;
			} else {
				if (browserName=="Microsoft Internet Explorer") {
					window.location = "sonuc.php";
				} else {
					var count = resultXML.getElementsByTagName("count")[0];
					var countValue = count.firstChild.nodeValue;
					if (countValue > 0) {
						var i = 0;
						var htmlText = "<center>"+mesajValue+"</center><br><br>";
						for (i=0;i<=countValue-1;i++) {
							data = resultXML.getElementsByTagName("dt")[i];
							dataValue = data.firstChild.nodeValue;
							htmlText += dataValue+"<br><br>";
						}
						alertArea.innerHTML = htmlText;
					}
				}
			}
		}
	}
}

// The following two functions are helper infrastructure to 
//craete a XMLHTTPRequest and register a listener callback function
function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE Browser
    		// Try ActiveX
		try { 
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) { 
			// first method failed 
			try {
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				 // both methods failed 
			} 
		}
 	}
   	return xmlreq;
} 

function getReadyStateHandler(req, responseXmlHandler) {
	return function () {
		if (req.readyState == 4) {
			if (req.status == 200) {
	        	responseXmlHandler(req.responseXML);
			} else {
				var alertArea = document.getElementById("formAlertArea");
				alertArea.innerHTML = "<font color='#FF0000' size='-2'><u>HATA</u> : <strong>Islem yapilamadi! -> " + req.status + "</strong></font>";
			}
	    }
 	}
}