// 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("haber_ajax_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("haber_ajax_ozet");
	if (absElement != null) {
		absElement.innerHTML = ozet;
	}
	// Setting the abstract div area...
	headElement = document.getElementById("haber_ajax_baslik_ust");
	if (headElement != null) {
		headElement.innerHTML = baslik+" ...";
	}
}

// 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');
}

// 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);
}

// 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>";
			}
	    }
 	}
}