var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		xmlhttp = false;
	}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	}
	catch(e) {
		xmlhttp = false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	}
	catch(e) {
		xmlhttp = false;
	}
}

function onceki(elem) {
	do {
		elem = elem.previousSibling;
	} while (elem && elem.nodeType != 1);
	return elem;
}

function sonraki(elem) {
	do {
		elem = elem.nextSibling;
	} while (elem && elem.nodeType != 1);
	return elem;
}

function chnIm() {
	on_air = true;
	img_id = img_id % im_on_air.length;
	while (on_air) {
		with (Math) res_id = round(random()*resimler.length);
		
		if (resimler[res_id]) {
			on_air = false;
			for (var i = 0; i < im_on_air.length; i++) {
				if (resimler[res_id] == im_on_air[i][0]) {
					on_air = true;
					break;
				}
			}
		}
		if (!on_air)
			im_on_air[img_id] = [resimler[res_id], genler[res_id], yukler[res_id]];
	}

	tst_im.src = 'thumb.php?op=makeThumb&resim=' + resimler[res_id] + '&rs=150&rt=gen';
	tst_im.onload  = function () {
		document.getElementById('et'+img_id).src = tst_im.src;
		img_id++;
		setTimeout('chnIm()', 10000);
	}
}


function resimGoster(resim, ww, hh) {
	if (!arguments[1]) {
		ww    = im_on_air[resim][1];
		hh    = im_on_air[resim][2];
		resim = im_on_air[resim][0];
	}
	lnk = 'resim_koy.php?resim=' + resim;
	boyut = 'status, width=' + (ww*1 + 20) + ', height=' + (hh*1 + 20);
	window.open(lnk, '', boyut);
}

var isIE = (document.getElementById && document.all) ? true : false;
var isNS4 = (document.layers) ? true : false;
var isNS6 = (document.getElementById && !document.all) ? true : false;
var newWidth;
var scroller_timer;

// Genişlik 2'ye bölünüyor mu?
function setWidth() { 
	tableObj = (isIE) ? document.all("table") : document.getElementById("table"); 
	obj = (isIE) ? document.all.div1 : document.getElementById("div1");	 
	objWidth = getOffset(tableObj, "height");
	newWidth = objWidth + 1;
	obj.style.width = newWidth
	moveLayer(obj, newWidth);
	
}

// Bir piksel kaydır
function moveLayer(obj, width) {
	if (obj.style.top == "") {
		obj.style.top = 0;
	}
	
	if (parseInt(obj.style.top) < (0 - newWidth)) {
		obj.style.top = 0
	} else {
		obj.style.top = parseInt(obj.style.top) - 1;
	}
	scroller_timer = setTimeout ("moveLayer(obj, " + width + ");", 5); 
}

// Katmanın genişlik ve yüksekliğini al
function getOffset(obj, dim) {
	if (dim=="width") {
		oWidth = obj.offsetWidth;
		return oWidth;
	} else if (dim=="height") {
		oHeight = obj.offsetHeight;
		return oHeight;
	}		
}

function stopScroller(elm) {
	elm.style.cursor = 'pointer';
	clearTimeout(scroller_timer);
}

function runScroller() {
	if (!isNS4) {
		setWidth();
	}
}

/* from http://www.quirksmode.org/js/detect.html */
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent) || this.searchVersion(navigator.appVersion) || "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i = 0; i < data.length; i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			} else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{	// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 	// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

var marked_row = new Array;
var theDefaultColor = '#FFFFFF';
var thePointerColor = '#CCFFCC';
var theMarkColor = '#FFCC99';

function setPointer(theRow, theRowNum, theAction) {
	var theCells = null;
//	1. Pointer and mark feature are disabled or the browser can't get the row -> exits
	if ((thePointerColor == '' && theMarkColor == '') || typeof(theRow.style) == 'undefined') {
		return false;
	}

//	2. Gets the current row and exits if the browser can't get it
	if (typeof(document.getElementsByTagName) != 'undefined') {
		theCells = theRow.getElementsByTagName('td');
	} else if (typeof(theRow.cells) != 'undefined') {
		theCells = theRow.cells;
	} else {
		return false;
	}

//	3. Gets the current color...
	var rowCellsCnt  = theCells.length;
	var domDetect	= null;
	var currentColor = null;
	var newColor	 = null;
//	3.1 ... with DOM compatible browsers except Opera that does not return valid values with "getAttribute"
	if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
		domDetect	= true;
	} else {
//	3.2 ... with other browsers
		currentColor = theCells[0].style.backgroundColor;
		domDetect	= false;
	} // end 3

//	4. Defines the new color
//	4.1 Current color is the default one
	if (currentColor == null || currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
		if (theAction == 'over' && thePointerColor != '') {
			newColor = thePointerColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true;
		}
	} else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
//	4.1.2 Current color is the pointer one
		if (theAction == 'out') {
			newColor = theDefaultColor;
		} else if (theAction == 'click' && theMarkColor != '') {
			newColor = theMarkColor;
			marked_row[theRowNum] = true;
		}
	} else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
//	4.1.3 Current color is the marker one
		if (theAction == 'click') {
			newColor = (thePointerColor != '') ? thePointerColor : theDefaultColor;
			marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) ? true : null;
		}
	} // end 4
//	5. Sets the new color...
	if (newColor) {
		var c = null;
//	5.1 ... with DOM compatible browsers except Opera
		if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
		} else {
//	5.2 ... with other browsers
			for (c = 0; c < rowCellsCnt; c++) {
				theCells[c].style.backgroundColor = newColor;
			}
		}
	} // end 5

	return true;
}
// end of the 'setPointer()' function

function setOpacity(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari<1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
}

function fadeIn(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 99) {
			setOpacity(obj, opacity);
			opacity += 5;
			setTimeout("fadeIn('" + objId + "', " + opacity + ")", 100);
		} else
			setTimeout("getNewImage()", 3000);
	}
}

function fadeOut(objId, opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity >= 5) {
			setOpacity(obj, opacity);
			opacity -= 3;
			setTimeout("fadeOut('" + objId + "'," + opacity + ")", 100);
		} else {
			document.getElementById('padre').innerHTML = clone_div;
			obj = document.getElementById(objId);
			setOpacity(obj, 5);
			document.getElementById('image_holder').style.display = '';
			fadeIn(objId, 5);
		}
	}
}

function getNewImage() {
	var lnk = 'ajaxCalls.php', q = 'op=chnYayinImage', ret;
	
	xmlhttp.open('POST', lnk, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; text/html; charset=iso-8859-9");
	xmlhttp.setRequestHeader("Content-length", q.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(q);

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			ret = xmlhttp.responseText;
			if (ret == '0' || ret == 'na-bi') return;
			else {
				re = /src=\"(.+?)\"/;
				found = re.exec(ret);
				im = new Image();
				im.src = found[1];
				im.onerror = getNewImage;
				im.onload = function() {
					clone_div = ret;
					fadeOut('yayin_resim', 99);
				}
			}
		}
	}
}

function teyit() {
	var ikod = prompt("intikal kodu:", "");
	if (ikod == null || ikod == '' || typeof ikod == 'undefined') return;
	var lnk = 'tr_rapor_calls.php', q = 'op=intikal&ikod=' + ikod;
	
	xmlhttp.open('POST', lnk, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; text/html; charset=iso-8859-9");
	xmlhttp.setRequestHeader("Content-length", q.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(q);

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.responseText == '0')
				return alert("talep icra edildi.");
			else
				return alert("hata!");
//				return alert(xmlhttp.responseText);
		}
	}
}

function sendXMLHttpQuery(lnk, q) {
	xmlhttp.open('POST', lnk, true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; text/html; charset=iso-8859-9");
	xmlhttp.setRequestHeader("Content-length", q.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(q);
}

function secim_ac(url) {
	window.open(url, '_blank', 'width=500, height=500, resizable=yes, top=100, left=600');
}

function openNewWindow(theURL, winName, features) {
	window.open(theURL, winName, features);
}
