var user_agent = navigator.userAgent;
var isOpera = user_agent.indexOf("Opera") >= 0;
var isFirefox = user_agent.indexOf("Firefox") >= 0;
var isWin32up = user_agent.indexOf("Win32") >= 0 
	|| user_agent.indexOf("Win64") >= 0
	|| user_agent.indexOf("Windows NT") >= 0;

// disallow Opera faking IE
var isIE = !isOpera && user_agent.indexOf("MSIE") >= 0;
var isIE55up = isIE && isWin32up && user_agent.match(/MSIE ((5\.5)|[6789])/);
var isIE70up = isIE && isWin32up && user_agent.match(/MSIE ([789])/);
var isIE55dn = isIE && !isIE55up;
var browser = "other";

if (isFirefox)
	browser = "firefox";
else if (isOpera) 
	browser = "opera";
else if (isIE55up) 
	browser = "ie55p";
else if (isIE55dn) 
	browser = "ie55d";

function getWindowClientSize() {
	var CScreenWidth;
	var CScreenHeight;

	// if (typeof(window.innerWidth) != "undefined") {
	if (window.innerWidth) {
		CScreenWidth = window.innerWidth;
		CScreenHeight = window.innerHeight;
	} else if (document.body.clientWidth) {
		CScreenWidth = document.body.clientWidth;
		CScreenHeight = document.body.clientHeight;
	} else {
		CScreenWidth = 0;
		CScreenHeight = 0;
	}
	return {width: CScreenWidth, height: CScreenHeight};
}

function navigateOpener(url) {
	if (window.opener)
		window.opener.document.location.href = url;
	else
		self.location.href = url;
}

function setInnerHTML(elementID, HTML) {
	var targetElement = document.getElementById(elementID);
	if (targetElement != null)
		targetElement.innerHTML = HTML;
}

/** returns a browser specific alpha image layer.
* - imgPNG - PNG with alpha channel
* - imgGIF - failsafe transparent GIF image
*/
function alphaImg(width, height, imgPNG, imgGIF, alt, title) {
	var imgSpacer = I_URL + "sp.gif";
	var html;
	var alt_title;
	
	if (alt != null)
		alt_title = " alt=\"" + alt + "\"";
	else
		alt_title = " alt=\"\"";

	if (title != null)
		alt_title += " title=\"" + title + "\"";

	if (isIE70up || isOpera || isFirefox) {
		// use PNGs directly
		html = '<img src="' + imgPNG + '" width="' + width + '" height="' + height + '"' + alt_title + '>';
	} else if (isIE55up) {
		// use directX filters
		html = '<img style="width: ' + width + 'px; height: ' + height + 'px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgPNG + '\',sizingMethod=\'scale\');\" src="' + imgSpacer + '" width="' + width + '" height="' + height + '"' + alt_title + '>';
	} else {
		// use failsafe GIF images
		html = '<img src="' + imgGIF + '" width="' + width + '" height="' + height + '"' + alt_title + '>';
	}
	
	document.write(html);
}

/** returns a browser specific alpha image background.
* - imgPNG - PNG with alpha channel
* - imgGIF - failsafe transparent GIF image
*/
function alphaImgBG(imgPNG, imgGIF) {
	var html;
	
	if (isIE70up || isOpera || isFirefox) {
		// use PNGs directly
		html = 'background-image: url(' + imgPNG + ');';
	} else if (isIE55up) {
		// use directX filters
		html = 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgPNG + '\',sizingMethod=\'scale\');';
	} else {
		// use failsafe GIF images
		html = 'background-image: url(' + imgGIF + ');';
	}
	
	return html;
}

/* Begin: MBG Ajax functions */
var arrMBGAjaxObjects = new Array();

function set_parameters()
{
	var params='';
	
	if(document.getElementsByTagName('input'))  
	{
		var inpts = document.getElementsByTagName('input');
		for ( i=0;i<inpts.length;i++)
		{
			if(inpts[i].type == "checkbox")
			{
				if(inpts[i].checked == true)
				{
	//				alert(inpts[i].name+'='+inpts[i].value)
					params+=inpts[i].name+'='+inpts[i].value+'&';
				}
			}
			else
				params+=inpts[i].name+'='+inpts[i].value+'&';
		}
	}
	  
	if(document.getElementsByTagName('textarea'))  
	{
		var txtars = document.getElementsByTagName('textarea');
		for ( i=0;i<txtars.length;i++)
		{
			params+=txtars[i].name+'='+txtars[i].value+'&'
		}
	}
	
	if(document.getElementsByTagName('select'))  
	{
		var slcts = document.getElementsByTagName('select');
		for ( i=0;i<slcts.length;i++)
		{
			params+=slcts[i].name+'='+slcts[i].value+'&'
		}
	}
	
	params = params.substring(0,params.length-1)
//	alert(params);
	return params;
} // function set_parameters()

function MBGAjaxProcessChange( index ) {
	var oMBGAjax = arrMBGAjaxObjects[index];
	if (oMBGAjax == null) return;
	
	// State 4 ise Sayfa yuklenmistir.
	//Ve tabii ki HTTP status 200 olmali
	if (oMBGAjax.XML.readyState == 4 && oMBGAjax.XML.status == 200) {
		// do callback if it is set
		if (oMBGAjax.callback != null)
			oMBGAjax.callback(oMBGAjax.XML.responseText);
		else if (oMBGAjax.targetDivID != null) {
			var obj = document.getElementById(oMBGAjax.targetDivID);
			if (obj != null)
				obj.innerHTML = oMBGAjax.XML.responseText;
		}
			
		// clear the referred object after it is used
		arrMBGAjaxObjects[index] = null;
	}
}

function MBGAjaxPOST(url, callback, params) {
	MBGAjaxInternal(url, callback, "POST", params);
}

function MBGAjax(url, callback, method, params) {
	MBGAjaxInternal(url, callback, method, params);
}

function MBGAjaxDIV(url, targetDivID, params) {
	MBGAjaxInternal(url, null, "POST", params, targetDivID);
}

// Executes an asynchronous AJAX operation using GET method and launches 
// the callback with the response text when the request finishes.
function MBGAjaxInternal(url, callback, method, params, targetDivID) {
	if (method == null) method = "GET";
	
	var oXML = null;
	
	// Internet Explorer ise
	try {
		oXML = new ActiveXObject( "Msxml2.XMLHTTP" );
	} catch( e ) {
		try {
			oXML = new ActiveXObject( "Microsoft.XMLHTTP" );
		}
		catch( oc ) { req = null; }
	}

	// Mozailla veya Safari ise
	if ( oXML == null && typeof(XMLHttpRequest) != "undefined" ) {
		oXML = new XMLHttpRequest();
	}

	// save fields to a new object
	var index = arrMBGAjaxObjects.length;
	arrMBGAjaxObjects[index] = new Object();
	arrMBGAjaxObjects[index].XML = oXML;
	arrMBGAjaxObjects[index].callback = callback;
	arrMBGAjaxObjects[index].targetDivID = targetDivID;
	
	// Sayfa yuklendiyse processChange fonksiyonunu cagiriyoruz.
	if ( oXML != null ) {
		oXML.onreadystatechange = function() {
			MBGAjaxProcessChange(index);
		};
		oXML.open( method, url, true );
		if (strICompare(method, "POST") == 0)
			oXML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		oXML.send( params );
	}
}
/* End: MBG Ajax functions */


function dgid(obj)
{
	return document.getElementById(obj);
} // function dgid(obj)

function displayDIVBlock(id) {
	var obj = document.getElementById(id);
	if (obj != null) obj.style.display = "block"
}

function hideDIVBlock(id) {
	var obj = document.getElementById(id);
	if (obj != null) obj.style.display = "none"
}