/*-------------------------------------------------------------------------
|Amac: Test için kullanilan javascript'leri içerir.                       |
|                                                                         |
|-------------------------------------------------------------------------|
|Function'lar:										               	      |
|		- at                                                              |
|		- DisObj                                                          |
|                                                                         |
|-------------------------------------------------------------------------|
|Gerekli Dosyalar: Dim.js, Utils.js                                       |
|-------------------------------------------------------------------------|
|                    Gordion Bilgi Hizmet Ltd. Sti.                       |
|                      http://www.gordion.com.tr                          |
-------------------------------------------------------------------------*/




//------------------------------------------------------------------------------------------------------
//Sadece testlerde kullaniliyor.
//Sayfaya eger daha once eklenmemisse bir TextArea 
//ekleyip parametre olarak aldigi degeri icerisinde 
//gosterir. Daha once girilmis bir deger varsa, 
//bu degeri bir cizgi ile ayirip alta devam eder.
var bATD = false;//alertTextDisabled
function at(m)
{
	if(bATD) return;	

	var el = document.getElementById("zuzuzuzu");
	if(typeof el  == "undefined" || el == null)	
	{		
		el = _initilizeAlertText();
	}
	if(el.value == "") 
		el.value = "";
	else
		el.value += "\n\n\n---------------------------------------------------";
	
	el.value += "\n" + m;
}



//------------------------------------------------------------------------------------------------------
//Bir object'in tum property ve method'larini display eder
function DisObj(obj)
{
	//En uzun member ismi
	var maxLen = 0;
	for(var e in obj)
	{
		if(e > "Z" && e.length > maxLen)
			maxLen = e.length;
	}
	maxLen++;

	var i = 0;
	var ar = new Array();
	for(var e in obj)
	{
		ar[i] = "\n" + e;

		//member'in type'ini siralamak icin tampon
		for(var j = 0; j < (maxLen - e.length); j++)
			ar[i] += " ";
		var type = "";
		var attrVal;
		try {
			attrVal = eval("obj." + e);
			type = typeof(eval("obj." + e));
		}
		catch(exp) {
			type = "unknown";
		}
		ar[i] += " " + type;
		
		if(type == "unknown") {
			i++;
			continue;
		}

		
		//Null olan stringler belirtilir.
		if(type == "string" && attrVal != null && attrVal != "")
			ar[i] += "      " + attrVal.toString().replace(/(?:\n|\r)+/g, "");
		
		//Null olan objectler belirtilir.
		else if(type == "object" && attrVal == null)
			ar[i] += "      null";

		//member'in tipi function ise body'si display edilir.
		else if(type == "function")
			ar[i] += "    " + attrVal.toString().replace(/\s+/g, " ").replace(/.*\{/, "{");		
			
		//Number ise
		else if(type == "number" && attrVal != null)
			ar[i] += "      " + attrVal;
			
		//Boolean ise
		else if(type == "boolean" && attrVal != null)
			ar[i] += "     " + attrVal;

		i++;
	}  
	ar.sort();
	at(ar.toString());
}



//TEST------------------------------------------------------------------------------------------------------

function _initilizeAlertText()
{	
	var frame = document.createElement("div");
	frame.id = "zuzuzuzu_tbl";
	frame.style.position = "absolute";
	frame.style.left = "580px";
	frame.style.top = "200px";
	frame.style.zIndex = 500; 
	frame.style.backgroundColor = "#222222";
	frame.style.border = "solid 1px #999999";	
	frame.style.padding = "3px";
	frame.onclick = isIE ? function() {window.event.cancelBubble = true;} : function(e) {e.stopPropagation();};
		
	//MovePanel
	var movePanel = document.createElement("div");
	frame.appendChild(movePanel);
	movePanel.style.cursor = "move";
	movePanel.onmousedown = zuzuBeginDrag;
	
	//Button On / Off
	var btnOnOff = createZuzuBtn();
	movePanel.appendChild(btnOnOff);
	btnOnOff.id = "zuzuzuzu_onoff";
	btnOnOff.value = "    On / Off   ";
	btnOnOff.style.width = "120px";	
	btnOnOff.onclick = function(e) {
		bATD=!bATD;
		var s = isIE ? window.event.srcElement : e.target;
		s.style.color = bATD ? "red" : "white";	
	};
	
	//Button Clear
	var btnClear = createZuzuBtn();
	movePanel.appendChild(btnClear);
	btnClear.id = "zuzuzuzu_clear";
	btnClear.value = " Clear ";
	btnClear.style.width = "120px";
	btnClear.onclick = function(e) {document.getElementById("zuzuzuzu").value = "";};
	
	//Button Close
	var btnClose = createZuzuBtn();
	movePanel.appendChild(btnClose);
	btnClose.id = "zuzuzuzu_close";
	btnClose.value = "X";
	btnClose.style.position = "relative";
	btnClose.style.left = "180px";
	btnClose.style.width = "30px";
	btnClose.onclick = function(e) {document.body.removeChild(document.getElementById("zuzuzuzu_tbl"));};
	btnClose.onmouseover = function(e) {var s = e ? e.target : event.srcElement; s.style.color = "red";};
	btnClose.onmouseout = function(e) {var s = e ? e.target : event.srcElement; s.style.color = "white";};	
	
	//TextArea
	var el = document.createElement("textarea");
	frame.appendChild(el);
	el.id = "zuzuzuzu";
	el.style.border = "0";
	el.style.fontSize = "8pt";
	el.rows = 19;
	el.cols = 64;	
	
	//CommandLine Panel
	var cmdLine = document.createElement("div");
	cmdLine.id = "zuzuzuzu_CmdLine";
	cmdLine.style.display = "none";
	frame.appendChild(cmdLine);
	
	//Command Line Eval Button
	var btnEval = createZuzuBtn();
	cmdLine.appendChild(btnEval);
	btnEval.id = "zuzuzuzu_eval";
	btnEval.type = "button";
	btnEval.value = "E";
	btnEval.style.width = "30px";
	btnEval.onclick = function(e) {
		eval(document.getElementById("zuzuzuzu_commandLine").value.replace(/^at (.*)$/gm, "at($1);"), "unsafe");
	}
	
	//Command Line Clear Button
	var btnClearCommand = createZuzuBtn();
	cmdLine.appendChild(btnClearCommand);
	btnClearCommand.id = "zuzuzuzu_ShowCommand";
	btnClearCommand.value = " Clear ";
	btnClearCommand.style.width = "120px";
	btnClearCommand.onclick = function(e) {document.getElementById("zuzuzuzu_commandLine").innerHTML = "";}
	
	//Command Line
	var commandLine = document.createElement("textarea");
	cmdLine.appendChild(commandLine);
	commandLine.id = "zuzuzuzu_commandLine";
	commandLine.style.border = "0";
	commandLine.style.fontSize = "8pt";
	commandLine.rows = 10;
	commandLine.cols = 64;
	commandLine.style.display = "block";
	commandLine.onkeypress = function(e) {
		var kc = e ? e.which : window.event.keyCode;
		if(kc == 199)
		{
			//TODO: Mozilla icin degisiklik
			var selectedText = "";
			if(isIE)
				selectedText = document.selection.createRange().text
			else
				selectedText = e.target.value.slice(e.target.selectionStart, e.target.selectionEnd);

			if(selectedText.length > 0)
				eval(selectedText.replace(/^at (.*)$/gm, "at($1);"), "unsafe");
			else
				btnEval.click();
						
			return false;
		}
		
		return true;
	}
	commandLine.onkeydown = function(e) {
		//Tab yapabilmeyi saglar
		var kc = e ? e.which : window.event.keyCode;
		if(kc == 9)
		{
			//TODO Moz
			if(isIE)
				document.selection.createRange().text = "\t";
			else
			{
				var ctr = e.target;
				var ss = ctr.selectionStart;
				var se = ctr.selectionEnd;
				ctr.value = ctr.value.slice(0, ss) + "\t" + ctr.value.slice(se, ctr.value.length);
				ctr.setSelectionRange(ss + 1, ss + 1);
				setTimeout("document.getElementById('" + ctr.id + "').focus();", 0);
			}
			return false;
		};
	};
	
	//Command Line Open	
	var openCmdLine  = document.createElement("div");
	frame.appendChild(openCmdLine);
	openCmdLine.innerHTML = "V V V";
	openCmdLine.isOpened = false;
	openCmdLine.style.textAlign = "center";
	openCmdLine.style.fontSize = "5pt";
	openCmdLine.style.backgroundColor = "#444";
	openCmdLine.style.color = "gray";
	openCmdLine.style.fontWeight = "bold";
	openCmdLine.style.height = "10px";
	openCmdLine.style.width = "460px";
	openCmdLine.style.cursor = isIE ? "hand" : "pointer";
	openCmdLine.onclick = function(e) {
		var src = e ? e.target : window.event.srcElement;
		if(src.isOpened)
		{
			document.getElementById("zuzuzuzu_CmdLine").style.display = "none";
			src.isOpened = false;
			src.innerHTML = "V V V";
		}
		else
		{
			document.getElementById("zuzuzuzu_CmdLine").style.display = "";
			src.isOpened = true;
			src.innerHTML = str("$923 $923 $923");
		}		
	}
	
	document.body.appendChild(frame);
	return el;
}

function createZuzuBtn()
{
	var btn = document.createElement("input");
	btn.type = "button";
	btn.style.border = "solid thin #999";
	btn.style.font = "bold 8pt Tahoma";
	btn.style.marginRight = "5px";
	btn.style.backgroundColor = "#666";
	btn.style.color = "white";
	return btn;
}


var zuzuCurX = 0;
var zuzuCurY = 0;

function zuzuBeginDrag(e)
{
	if(isIE)
	{
		document.attachEvent("onmousemove", zuzuDrag);
		document.attachEvent("onmouseup", zuzuEndDrag);
		document.attachEvent("onselectstart", ReturnFalse);
	}
	else
	{
		document.addEventListener("mousemove", zuzuDrag, false);
		document.addEventListener("mouseup", zuzuEndDrag, false);
	}
	zuzuCurX = e ? e.clientX : event.clientX;
	zuzuCurY = e ? e.clientY : event.clientY;
}

function zuzuDrag(e)
{
	var x = e ? e.clientX : event.clientX;
	var y = e ? e.clientY : event.clientY;
	ctr = document.getElementById("zuzuzuzu_tbl");
	ctr.style.left = ctr.offsetLeft + x - zuzuCurX + "px";
	ctr.style.top = ctr.offsetTop + y - zuzuCurY + "px";
	zuzuCurX = x;
	zuzuCurY = y;
}

function zuzuEndDrag()
{	
	if(isIE)
	{
		document.detachEvent("onmousemove", zuzuDrag);
		document.detachEvent("onmouseup", zuzuEndDrag);
		document.detachEvent("onselectstart", ReturnFalse);
	}
	else
	{
		document.removeEventListener("mousemove", zuzuDrag, false);
		document.removeEventListener("mouseup", zuzuEndDrag, false);
	}
}

if(document.addEventListener)
{
	document.addEventListener("onkeypress", function(e) {
		if(e.ctrlKey && e.shiftKey && e.charCode == 20)	
		{
			at("");
			document.getElementById("zuzuzuzu_commandLine").value = 'var z = document.getElementById("zuzuzuzu");\nvar cmd = document.getElementById("zuzuzuzu_commandLine");\nz.value = "";';
		}	
	}, true);
}
else if(document.attachEvent)
{
	document.attachEvent("onkeypress", function()
	{
		//sol ctrl + sol shilft + t harfine basarsa
		if(event.ctrlLeft && event.shiftLeft && event.keyCode == 20)
		{
			at("");
			document.getElementById("zuzuzuzu_commandLine").innerText = 'var z = document.getElementById("zuzuzuzu");\nvar cmd = document.getElementById("zuzuzuzu_commandLine");\nz.innerText = "";';
		}
	});
}

function zuzuFltrEvents()
{
	var z = document.getElementById("zuzuzuzu");
	z.innerText = z.innerText.replace(/^(?!on).+$/gm, "");
	z.innerText = z.innerText.replace(/^(\b\w*\b\s*){2}null.*$/gm, "");
	z.innerText = z.innerText.replace(/[\r\n][\r\n]+(?!on)/g, "");
}

function ReturnFalse()
{
	return false;
}

