window.onerror = ReportScriptError;

function HideScriptError(msg, url, line)
{

	return true;

}

function ReportScriptError(msg, url, line)
{

	try
	{

		window.onerror = HideScriptError;

		var strErrorInfo = "Line:" + line + ", Error: " + msg;

		var strStackTrace = GetStackTrace(arguments.caller);

		var strBrowserInfo = navigator.userAgent;

		var strUrl = "404.asp?kaynak=" + escape(window.location)
			+ "&hata=" + escape(strErrorInfo) 
			+ "&Trace=" + escape(strStackTrace) 
			+ "&tarayici=" + escape(strBrowserInfo);

		var xmlHttp = GetXMLHttp();

		if (null != xmlHttp)
		{

			xmlHttp.open("GET", strUrl, true );
			xmlHttp.send(null);
		}

	}
	catch (e) { }

	return true;

}


function FChkSrchTxt(wz)
{
	var ws=/^[\s]*$/;
	return wz&&!ws.test(wz);
}

function FocSrchTxt(o)
{
	if (o && o.value)
	{
		if (strNonSearchString != null && strNonSearchString != 'undefined' && o.value == strNonSearchString && !fEnteredText)
		{
			o.value = '';
		}
		else
		{
			o.select();
		}
		setSearchOnColor(o);
		fEnteredText=true;
	}
}

function FTrySearch(e, strFormName, index)
{
	fSearchFocus = false;
	searchclose();

	var oSrchFrm = document.getElementById(strFormName);

	if ('undefined' != typeof(oSrchFrm) && null != oSrchFrm && SelectAction(oSrchFrm, index))
		{

		try {external.AutoCompleteSaveForm(oSrchFrm);} catch (err) {}
		oSrchFrm.submit();
		}

	if (e && e.stopPropagation)
		e.stopPropagation(); 

	return false;
}

function FEntTextbox(e, strFormName, index)
{
	if (e && 13 == e.keyCode)
		return FTrySearch(e, strFormName, index);

	return true;
}

function FBSCTrySearch(strFrmName, strSrchErr, strResultsUrl, iScope)
{
	var oSrchFrm = G(strFrmName);

	if (!oSrchFrm)
		return false;

	if (!FChkSrchTxt(G('BSCQU').value))
	{
		alert(strSrchErr);
		return false;
	}

	if (!oSrchFrm.av)
	{
		var inputAV = document.createElement("input");
		inputAV.id = "av";
		inputAV.name = "av";
		inputAV.type = "hidden";		
		oSrchFrm.appendChild(inputAV);
	}

	oSrchFrm.qu.value = G('BSCQU').value;
	oSrchFrm.av.value = G('BSCAV').value;
	oSrchFrm.sc.value = iScope;
	oSrchFrm.action = strResultsUrl;
	oSrchFrm.submit();
	return false;
}


function StrXMLEncode(s)
{
	if (typeof(s) == 'undefined')
		return "";

	s = s.replace(/&/g, "&amp;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/'/g, "&apos;");
	s = s.replace(/"/g, "&quot;");	
	return s;
}

function StrXMLDecode(s)
{
	if (typeof(s) == 'undefined')
		return "";

	var re;

	re = /&amp;/g;
	s = s.replace(re, "&");

	re = /&gt;/g;
	s = s.replace(re, ">");

	re = /&lt;/g;
	s = s.replace(re, "<");

	re = /&apos;/g;
	s = s.replace(re, "'");

	re = /&quot;/g;
	s = s.replace(re, "\"");

	return s;
}

function StrTrim(str)
{
	if (typeof(str) == "undefined" || null == str)
		return null;

	while (str.length > 0 && str.charCodeAt(0) <= 32)
		str = str.substring(1);

	while (str.length > 0 && str.charCodeAt(str.length-1) <= 32)
		str = str.substring(0, str.length-1);

	return str;
}


function SafePrintWindow()
{
	try
		{
		window.print();
		}
	catch(e)
		{

		}
}

function ResizeTabDivs(strCtrlId)
{

	if (typeof(navigator) != 'undefined' &&
		null != navigator &&
		typeof(navigator.appName) != 'undefined' &&
		null != navigator.appName)
		{
			if (navigator.appName.indexOf('Internet Explorer') >= 0 &&
				typeof(navigator.appVersion) != 'undefined' &&
				null != navigator.appVersion &&
				navigator.appVersion.indexOf('MSIE 7') >= 0)
			{
				return;
			}

			if (navigator.appName.indexOf('Netscape') >= 0)
				return;
	}

	var strExtraLinkDivId = null;
	eval("if (typeof(strExtraLinkDivId_" + strCtrlId + ") != 'undefined')" +
		"strExtraLinkDivId = strExtraLinkDivId_" + strCtrlId + ";");

	var nExtraLinkDivOrigHeight = -1;
	if (null != strExtraLinkDivId)
		eval("nExtraLinkDivOrigHeight = nExtraLinkDivOrigHeight_" + strCtrlId + ";");

	var strPrefix = "divTabCtrl_" + strCtrlId + "_";
	var fNeedDivs = false;
	var rgDivs = null;

	eval("if (null == rgTabCtrlDivs_" + strCtrlId + ") fNeedDivs = true;");
	if (fNeedDivs)
	{
		rgDivs = new Array();
		rgAllDivs = document.getElementsByTagName("div");
		for (var i=0; i < rgAllDivs.length; i++)
		{
			if (typeof(rgAllDivs[i].id) == "undefined" ||
				null == rgAllDivs[i].id ||
				0 != rgAllDivs[i].id.indexOf(strPrefix))
			{
				continue;
			}

			rgDivs[rgDivs.length] = rgAllDivs[i];
		}

		eval("rgTabCtrlDivs_" + strCtrlId + " = rgDivs;");
	}
	else
	{
		eval("rgDivs = rgTabCtrlDivs_" + strCtrlId + ";");
	}

	var nMaxHeight = 0;
	var nNewHeight = 0;
	for (var i=0; i < rgDivs.length; i++)
	{
		var nHeight = rgDivs[i].offsetHeight;
		if (nHeight > nMaxHeight)
			nMaxHeight = nHeight;

		if (null != strExtraLinkDivId && rgDivs[i].id == strExtraLinkDivId)
		{
			if (nHeight > 0 && nExtraLinkDivOrigHeight <= 0)
			{
				eval("nExtraLinkDivOrigHeight_" + strCtrlId + " = " + nHeight.toString() + ";");
				nExtraLinkDivOrigHeight = nHeight;
			}

			nNewHeight = nHeight;
		}
	}

	var strMaxHeight = nMaxHeight.toString();
	for (var i=0; i < rgDivs.length; i++)
		rgDivs[i].style.height = strMaxHeight + "px";

	if (nNewHeight > 0)
	{
		nNewHeight = nMaxHeight + 8 - nExtraLinkDivOrigHeight;
		var tdExtraLinkPadding = ElmGetSafeElement("tdExtraLinkPadding_" + strCtrlId);
		tdExtraLinkPadding.style.height = nNewHeight.toString() + "px";
	}
}

function TabCtrlTabClick(strCtrlId, strTabId)
{
	ResizeTabDivs(strCtrlId);

	var strLastCat = "";
	eval("strLastCat = strTabCtrlLastTopCat_" + strCtrlId + ";");

	var tdLast = ElmGetSafeElement("tdTabCtrl_" + strCtrlId + "_" + strLastCat);
	var tdLastLeft = ElmGetSafeElement("tdTabCtrlLeft_" + strCtrlId + "_" + strLastCat);
	var tdLastRight = ElmGetSafeElement("tdTabCtrlRight_" + strCtrlId + "_" + strLastCat);
	var divLast = ElmGetSafeElement("divTabCtrl_" + strCtrlId + "_" + strLastCat);
	var aLast = ElmGetSafeElement("aTabCtrl_" + strCtrlId + "_" + strLastCat);

	var tdNew = ElmGetSafeElement("tdTabCtrl_" + strCtrlId + "_" + strTabId);
	var tdNewLeft = ElmGetSafeElement("tdTabCtrlLeft_" + strCtrlId + "_" + strTabId);
	var tdNewRight = ElmGetSafeElement("tdTabCtrlRight_" + strCtrlId + "_" + strTabId);
	var divNew = ElmGetSafeElement("divTabCtrl_" + strCtrlId + "_" + strTabId);
	var aNew = ElmGetSafeElement("aTabCtrl_" + strCtrlId + "_" + strTabId);

	if (null != tdLast)
	{
		tdLast.className = "cdBCTCTabCell";
		tdLastLeft.className = "cdBCTCTabCellLeft";
		tdLastRight.className = "cdBCTCTabCellRight";
	}

	if (null != divLast)
		divLast.style.display = "none";

	if (null != aLast)
		aLast.style.cursor = "auto";

	if (null != tdNew)
	{
		tdNew.className = "cdBCTCTabCellSel";
		tdNewLeft.className = "cdBCTCTabCellSelLeft";
		tdNewRight.className = "cdBCTCTabCellSelRight";
	}

	if (null != divNew)
		divNew.style.display = "block";

	if (null != aNew)
		aNew.style.cursor = "default";

	eval("strTabCtrlLastTopCat_" + strCtrlId + " = strTabId;");
}

function LNProdSelected(strValue)
{
	if (null != strValue && strValue.length > 0)
	{
		if ('*' == strValue.charAt(0))
			window.open(strValue.substring(1, strValue.length), '_blank');
		else
			location.href = strValue;
	}
}

function DeleteChildElement(strChild)
{
	elmChild = document.getElementById(strChild);
	if ('undefined' == typeof(elmChild) || null == elmChild)
		return;

	var elmParent = elmChild.parentNode;
	if ('undefined' == typeof(elmParent) || null == elmParent)
		return;

	elmParent.removeChild(elmChild);
}

function offset(object, alignment) {
	var nOffset = 0;

	if (object == null)
		return nOffset;

	while (object.offsetParent) {
		nOffset += ((alignment == 'x') ? object.offsetLeft : object.offsetTop);
		object = object.offsetParent;
	}

	return nOffset;
}

function setNonSearchString(searchBox)
{
	if (searchBox != null && searchBox != 'undefined' && searchBox.value == '')
	{
		searchBox.value = strNonSearchString;
		setSearchOffColor(searchBox);
		fEnteredText = false;
	}
}

function setSearchOffColor(searchBox)
{
	searchBox.className = 'cdsearchbox cdSearchBoxOffColor';
}

function setSearchOnColor(searchBox)
{
	searchBox.className = 'cdsearchbox cdSearchBoxOnColor';
}

function delayedclose()
{
	fSearchFocus = false;
	window.setTimeout('searchclose()', 400);
}

function setSearchFocus()
{
	fSearchFocus = true;
}

function searchclose()
{
	var searchdrop = document.getElementById('cdsearchoutcdsdrop');
	if (searchdrop != null && searchdrop != 'undefined')
	{
		if (fSearchFocus == false)
		{
			searchdrop.style.display = 'none';
			fSearchOn = false;
		}
	}
}

function searchout()
{
	var searchdrop = document.getElementById('cdsearchoutcdsdrop');
	if (searchdrop != null && searchdrop != 'undefined' && fSearchOn == true)
	{
		searchdrop.style.display = 'none';
		fSearchOn = false;
	}
	else
	{
		var buttonleft = document.getElementById('cdsdropleft');
		var buttonmiddle = document.getElementById('cdsdrop');

		if (buttonleft != null && buttonleft != 'undefined' &&
			buttonmiddle != null && buttonmiddle != 'undefined' && 
			searchdrop != null && searchdrop != 'undefined')

		{
			var newleft = offset(buttonleft, 'x');
			var newtop = offset(buttonleft, 'y');

			searchdrop.style.display = 'none';
			searchdrop.style.position = 'absolute';

			if (fIsRTL)
			{				
				newleft = offset(buttonmiddle, 'x');
				searchdrop.style.left = newleft + 'px';
			}
			else
			{			
				searchdrop.style.left = newleft + 'px';
			}
			searchdrop.style.top = newtop + buttonmiddle.offsetHeight + 'px';

			searchdrop.style.display = 'block';

			fSearchOn = true;
		}
	}
}

function resizeSearchBox()
{
	var input = document.getElementById('frmSearch_tbQueryStr');
	var container = document.getElementById('tdSearchBox');
	if (input != null && input != 'undefined' && container != null && container != 'undefined')
	{
		var conwidth = container.offsetWidth;
		input.style.width = conwidth - 10 + 'px';

		if (input.value != strNonSearchString)
		{
			fEnteredText = true;
			setSearchOnColor(input);
		}
	}
}

function NSelBasketCalcSpeed()
{
	return 56;
}

function FIsMPFPrefered()
{
	return
		!("CIL" == GetCookie("AWS_DownloadMethod_Sess").toUpperCase() ||
		(0 == GetCookie("AWS_DownloadMethod_Sess").length &&
			"CIL" == GetCookie("AWS_ClientURL_Sess").toUpperCase()));
}

