function ShowPicture(containerName, picName, mouseStyle) {
	var truePath;
	if(picName.indexOf('/') != -1){
		truePath = picName;
	}
	else{
		truePath = "images/" + picName;
	}

	$(containerName).src = truePath;
	if(mouseStyle == ''){
		$(containerName).style.cursor = 'pointer';
	}
	else{
		$(containerName).style.cursor = mouseStyle;
	}
	
	return;
}


//////////////////////////////////////////////////////////////
var newWindow = null;
function CloseWin(){
	if(newWindow != null){
		if(!newWindow.closed){
			newWindow.close();
		}
	}
	
	return;
}

function Open(url, strWidth, strHeight){
	CloseWin();
	tools = "resizable,toolbar=no,location=no,scrollbars=yes ,menubar=no,width="+strWidth+",height="+strHeight +",top=0,left=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
	return;
}

function OpenPos(url, strWidth, strHeight, top, left){
	CloseWin();
	tools = "resizable,toolbar=no,location=no,scrollbars=yes ,menubar=no,width="+strWidth+",height="+strHeight +",top="+top +",left="+left +"";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
	return;
}
/////////////////////////////////////////////////////////////////////

function $(element){
	return document.getElementById(element);
}

// Image Handler
function $(element){
	return document.getElementById(element);
}

function ShowPicture(containerName, picName, mouseStyle) {
	var truePath;
	if(picName.indexOf('/') != -1){
		truePath = picName;
	}
	else{
		truePath = "images/" + picName;
	}

	$(containerName).src = truePath;
	if(mouseStyle == ''){
		$(containerName).style.cursor = 'pointer';
	}
	else{
		$(containerName).style.cursor = mouseStyle;
	}
	
	return; 
}

var xmlHttp;
var xmlHolder;
var xmlReturnPath;

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try{
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	}
	catch (e){
	  // Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	 	catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function CheckAjax(){
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null){ 
		alert ("Your browser does not support AJAX!"); 
		return;
	}	
}


function GetResult(url, holder, returnPath, runFunc){
	this.CheckAjax();
	xmlHolder = holder;
	xmlReturnPath = returnPath;
	xmlHttp.onreadystatechange = _GetResult;
	xmlRunFunction = runFunc;
	
	var browserName=navigator.appName; 
	if(browserName=="Microsoft Internet Explorer"){
		url2send = utf8encode(url) + '&token=' + Math.random();
	}
	else{
		url2send = url + '&token=' + Math.random();	
	}
	
	xmlHttp.open("GET", url2send, true);
	xmlHttp.send(null); 
}

function _GetResult(){
	if (xmlHttp.readyState==4){ 
		if(xmlHolder!=null){
			$(xmlHolder).innerHTML=xmlHttp.responseText;
		}
		else{
			$('popupDiv').innerHTML = xmlHttp.responseText;
			//
			if(xmlReturnPath!=null){
				$('popupDiv').innerHTML += '<a href="#" onclick="ChangeSelectVisibility(true); GetResult(xmlReturnPath, \'menuResult\', null); $(\'popupDiv\').style.visibility=\'hidden\';">Kapat</a>';
			}
			else{
				$('popupDiv').innerHTML += '<a href="#" onclick="ChangeSelectVisibility(true); $(\'popupDiv\').style.visibility=\'hidden\';">Kapat</a>';
			}
		}
		
		if (xmlRunFunction != null)
			eval(xmlRunFunction + '()');
	}
	else{
		if(xmlHolder!=null){
			$(xmlHolder).innerHTML = '<div class="center"><img class="no-border" src="images/loader.gif" width="220" height="19" alt="Yükleniyor..." /><br>Yükleniyor';
		}
		else{
			ChangeSelectVisibility(false); 
			$('popupDiv').style.visibility='visible';
		}
	}
	
	return;
}

function ChangeSelectVisibility(param){
	
	var svn = document.getElementsByTagName("SELECT");
	var visibility;
	
	if(param){
		visibility = 'visible';
	}
	else{
		visibility = 'hidden';	
	}

	for (i=0; i<svn.length; i++){
		svn[i].style.visibility = visibility;			
	}
	return;
}

function utf8encode(strText) {
	strText=strText.replace(/ı/g,"%C4%B1");
	strText=strText.replace(/Ü/g,"%C3%9C");
	strText=strText.replace(/ü/g,"%C3%BC");
	strText=strText.replace(/ğ/g,"%C4%9F");
	strText=strText.replace(/Ğ/g,"%C4%9E");
	strText=strText.replace(/ü/g,"%C3%BC");
	strText=strText.replace(/Ü/g,"%C3%9C");
	strText=strText.replace(/İ/g,"%C4%B0");
	strText=strText.replace(/ş/g,"%C5%9F");
	strText=strText.replace(/Ş/g,"%C5%9E");
	strText=strText.replace(/ç/g,"%C3%A7");
	strText=strText.replace(/Ç/g,"%C3%87");
	strText=strText.replace(/ö/g,"%C3%B6");
	strText=strText.replace(/Ö/g,"%C3%96");
	
	return strText;	
}

	
function NumbersOnly(myfield, e, dec) {
	var key;
	var keychar;
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}
