// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// Almila Information Technology
// Global JavaScript Functions
// Version : 3.0.0802
// Author  : İsmail Türkay
// Http    : www.almila.com
// E-Mail  : ismailturkay@almila.com
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------

	var FlagChange = false;
	var UserSkinPath = '/AlmilaLib/Skins/Default';
	var eventx = 0, eventy = 0;
	var IDS_WIDTH_OFFSET = 30;
	var IDS_HEIGHT_OFFSET = 30;
		
	NetscapeCssFixCheckIn();

	if (isIE()) window.opener = false;
	
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------

function WindowClose()
{
	return !(window.top.opener.top && !window.top.opener.top.closed);
}

// --------------------------------------------------------------------------------------------------------------------
function WindowOpen(strURL, strWinTarget, strWinFeatures) 
{
	var pWindow = window.top.open(strURL, strWinTarget, strWinFeatures);
	if (pWindow) pWindow.focus();
}

// --------------------------------------------------------------------------------------------------------------------
function WindowRefresh()
{
	window.top.history.go(0);
}

// --------------------------------------------------------------------------------------------------------------------
function GetWindowFeatures(strWindowFeature, pWindowBasedOn)
{
	var strFeature; 
	
	if (strWindowFeature == "") 
	{
		strFeature = UseDefaultSize(pWindowBasedOn);
	}
	else 
	{
		strFeature = strWindowFeature;
	}
	return strFeature;
}	

// --------------------------------------------------------------------------------------------------------------------
function UseDefaultSize(pWindow)
{
	var	lWidth = WBC_getWindowWidth(pWindow);
	var lHeight = WBC_getWindowHeight(pWindow);
	var strFeature;
	var lLeft;
	var lTop;

	if (isIE())
	{	// IE case
		lTop = pWindow.screenTop + IDS_HEIGHT_OFFSET;
		lLeft = pWindow.screenLeft + IDS_WIDTH_OFFSET;
		
		strFeature = "left=" + lLeft + ",top=" + lTop + ",width=" + lWidth + ",height=" + lHeight + ",resizable,scrollbars,status=yes";
	}
	else
	{	// Netscape case	
		lTop = pWindow.screenY + IDS_HEIGHT_OFFSET;
		lLeft = pWindow.screenX + IDS_WIDTH_OFFSET;
		strFeature = "screenX=" + lLeft + ",screenY=" + lTop + ",outerWidth=" + lWidth + ",outerHeight=" + lHeight + ",resizable,scrollbars,status=yes";
	}

	return strFeature;
}

// --------------------------------------------------------------------------------------------------------------------
function GetWindowWidth(pWin)
{
	if (isIE()) 
	{
		return pWin.document.body.clientWidth;
	} 
	else if (isNetscape()) 
	{
		return pWin.outerWidth;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function GetWindowHeight(pWin)
{
	if (isIE()) 
	{
		return pWin.document.body.clientHeight;
	} 
	else if (isNetscape()) 
	{
		return pWin.outerHeight;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function isIE() {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return true;
	} else {
		return false;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function isNetscape() {
	if (navigator.appName.indexOf("Netscape") != -1) {
		return true;
	} else {
		return false;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function SubmitForm(strFormName, strFormActionURL) {
	document.forms[strFormName].action = strFormActionURL;
	document.forms[strFormName].submit();
}

// --------------------------------------------------------------------------------------------------------------------
function PreloadImages () {
	if (document.images) {
		var arrayPreload = new Array();
		for (var i = 0; i < arguments.length; i++) {
			arrayPreload[i] = new Image;
			arrayPreload[i].src = arguments[i];
		}
	}
}

// --------------------------------------------------------------------------------------------------------------------
function ChangeImgSafe(imgDOM, imgSrcReplacedBy)
{
	if (document.images[imgDOM] != null)
	{
		document.images[imgDOM].src = imgSrcReplacedBy;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function GetBrowserVersion() {
	if (isNetscape()) {
		var strUserAgent = navigator.userAgent;
		var nBrowserUserAgentStart = strUserAgent.indexOf("(");
		if (nBrowserUserAgentStart != -1) {
			var strBrowserUserAgent = strUserAgent.substring(nBrowserUserAgentStart)
			var nBrowserVerStart = strBrowserUserAgent.indexOf(".") - 1;
			while ( !isNaN(parseInt(strBrowserUserAgent.charAt(nBrowserVerStart))) && (nBrowserVerStart > 0)) {
				nBrowserVerStart = nBrowserVerStart - 1;
			}
			return parseInt(strBrowserUserAgent.substring(nBrowserVerStart));
		}
	}
	return parseInt(navigator.appVersion);
}

// --------------------------------------------------------------------------------------------------------------------
function NetscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

// --------------------------------------------------------------------------------------------------------------------
function NetscapeCssFixCheckIn() {
  	if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    	if (typeof document.WM == 'undefined'){
      		document.WM = new Object;
    	}
	    if (typeof document.WM.WM_scaleFont == 'undefined') {
	      document.WM.WM_netscapeCssFix = new Object;
	      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
	      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
	    }
	    window.onresize = NetscapeCssFix;
  	}
}

// --------------------------------------------------------------------------------------------------------------------
function GetFormElement(pForm, strName, arrayElements) 
{
	var j = 0;
	for (var i = 0; i < pForm.elements.length; i++) {
		if (pForm.elements[i].name == strName) {
			arrayElements[j] = pForm.elements[i];
			j++;
		}
	}
}

// --------------------------------------------------------------------------------------------------------------------
function VerifyInputName(strName) {
	if ((strName.value.split(" ").length == strName.value.length + 1) || (strName.value.indexOf("#") >= 0) || (strName.value.indexOf("&") >= 0) || (strName.value.indexOf("%") >= 0) || (strName.value.indexOf("+") >= 0) || (strName.value.indexOf("/") >= 0) || (strName.value.indexOf("|") >= 0)) {
		return false;
	} else {
		return true;
	}
}

// --------------------------------------------------------------------------------------------------------------------
function FindObj(item) {
	if (document.all) return(document.all[item]);
	if (document.getElementById) return(document.getElementById(item));
	return(false);
}

// --------------------------------------------------------------------------------------------------------------------
function SetSkinPath(skinpath) {
	if (skinpath && skinpath !='') UserSkinPath = '/AlmilaLib/Skins/' + skinpath;	
}

// --------------------------------------------------------------------------------------------------------------------
function SkinIcon(name, desc, size) {
	var result = '', ed;
	
	if (!size) size = 16;
	if (!desc) desc = '';
	if (desc && desc != '') desc = ' alt="' + desc + '"';
	desc += ' width="' + size + '" height="' + size + '"';
	
	if (name && name != '') {
		if (size == 16) return('<img src="' + UserSkinPath + '/16x16/' + name + '.gif"' + desc + '>');
		if (size == 32) return('<img src="' + UserSkinPath + '/32x32/' + name + '.gif"' + desc + '>');
		if (size == 48) return('<img src="' + UserSkinPath + '/48x48/' + name + '.gif"' + desc + '>');
	} else return('');
}
	
// --------------------------------------------------------------------------------------------------------------------
function SkinImage(imgfile, imgtitle, imgw, imgh) {
	if (imgfile == '') return('');
	var imgsrc = '';
	var imgdsc = '';
	
	if (imgtitle && imgtitle != '') imgdsc = ' alt="' + imgtitle + '"';	
	if (imgw) imgdsc += ' width="' + imgw + '"';
	if (imgh) imgdsc += ' height="' + imgh + '"';

	imgsrc = UserSkinPath + '/Images/' + imgfile;
	if (imgfile.indexOf('.gif') == -1 && imgfile.indexOf('.jpg') == -1) imgsrc += '.gif';

	return('<img src="' + imgsrc + '"' + imgdsc + '>');
}

// --------------------------------------------------------------------------------------------------------------------
function SkinImageName(imgfile) {
	imgsrc = UserSkinPath + '/Images/' + imgfile;
	if (imgfile.indexOf('.gif') == -1 && imgfile.indexOf('.jpg') == -1) imgsrc += '.gif';
	return(imgsrc);
}

// --------------------------------------------------------------------------------------------------------------------
function hideElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "hidden";
	}
}

// --------------------------------------------------------------------------------------------------------------------
function showElement(elmID)
{
	for (i = 0; i < document.all.tags(elmID).length; i++)
	{
		obj = document.all.tags(elmID)[i];
		if (! obj || ! obj.offsetParent)
			continue;
		obj.style.visibility = "";
	}
}

// --------------------------------------------------------------------------------------------------------------------
function MouseOverControl(obj) {
	var ol, ot, ow, oh;	
	//var obj = FindObj(objname);
	ol = ParentLeft(obj) + obj.offsetLeft;
	ot = ParentTop(obj) + obj.offsetTop;
	ow = ol + obj.offsetWidth;
	oh = ot + obj.offsetHeight;
	if (eventx < ol || eventx > ow || eventy < ot || eventy > oh) return(false); else return(true);
}

// --------------------------------------------------------------------------------------------------------------------
function ParentLeft(idname) {
	var result = 0;
	var ownObj = idname.offsetParent;
	while (ownObj != null) {
		result += ownObj.offsetLeft;
		ownObj = ownObj.offsetParent;
	}
	//result = result + idname.offsetLeft;
	return(result);
}

// --------------------------------------------------------------------------------------------------------------------
function ParentTop(idname) {
	var result = 0;
	var ownObj = idname.offsetParent;
	while (ownObj != null) {
		result += ownObj.offsetTop;
		ownObj = ownObj.offsetParent;
	}
	//result = result + idname.offsetLeft;
	return(result);
}

// --------------------------------------------------------------------------------------------------------------------
function MouseTrack() {	
	eventx = event.x;
	eventy = event.y;
}

// --------------------------------------------------------------------------------------------------------------------
function changeRoll(imgName,imgObj) {	
	if (document.images)
		eval('document.images["' + imgName + '"].src = ' + imgName + imgObj + '.src') 
	else 
		document.images[imgName].src = eval(imgName + imgObj + ".src");

}

// --------------------------------------------------------------------------------------------------------------------
function preload_roll(imgObj,imgSrc) {
	if (document.images) {
    	eval(imgObj+' = new Image()')
        eval(imgObj+'.src = "'+imgSrc+'"')
        }
}
