/*=================================================================
*	provision_log.js
*   ----------------
*   Description : JavaScript functions
*   Copyright   : (c) 2009 Arthur Aminov, EAI Developer, Smile 012
*   Last build  : 30.06.2009 @ 18:00
=================================================================*/
	var lastMenuID = "";
	var lastFXMenuID = "";

	function getValueByID(id)
	{
	    var obj = returnOBJ(id);
	    return obj.value;
	}
//=================================================================
// check if variable is defined
//=================================================================
	function isDefined(variable)
	{
		return typeof(variable) != 'undefined' ? true : false;
	}
//=================================================================
// set div html
//=================================================================
	function divHTML(id, responseTxt)
	{
		if (!isDefined(id) || id == '') {
			alert(responseTxt);
		} else {
			var obj = returnOBJ(id);
			obj.innerHTML = responseTxt;
			document.title = "(: JOBnik! :) [BASS_FX, DSP effects...]";
		}
	}

	function divHTMLLogged(id, responseTxt)
	{
		if (responseTxt.indexOf('frmLogin') >= 0) {
			alert('wrong username/password...');
			return;
		}

		var obj = returnOBJ(id);
		obj.innerHTML = responseTxt;

		dateTime(dateTimeID);
		timerStartStop(0, 'dateTime(dateTimeID)', 800);
		clickByID('submitSearch');
		document.title = 'Access Log System: ' + document.getElementById('selEnv').value;
	}
//=================================================================
// time trigger
//=================================================================
	THandle = 0;
	dateTimeID = 'dateTime';

	function dateTime(id)
	{
		var now = new Date();

		id = returnOBJ(id);
		id.innerHTML = now.toLocaleString();
	}

	function timerStartStop(handle, func, interval)
	{
		if (handle) return clearTimeout(handle);
		THandle = setInterval(func, interval);
		return THandle;
	}
//=================================================================
// return browser type
//=================================================================
	function detectBrowserType()
	{
	    var bt = null;

	    if (document.all) bt = "ie";
	    if (document.getElementById && !document.all) bt = "ns6";
	    if (document.layers) bt = "ns4";

	    return bt;
	}
//=================================================================
// return object by its ID depending on browser type
//=================================================================
    function returnOBJ(id)
    {
        if(detectBrowserType() == "ie") return document.all[id];
        if(detectBrowserType() == "ns6") return document.getElementById(id);
    }
//=================================================================
// on index page load
//=================================================================
	function onLoadStuff(id)
	{
		focusByID(id);
	}
//=================================================================
// focus on by id
//=================================================================
	function focusByID(id)
	{
	    var obj = returnOBJ(id);
	    obj.focus();
	}
//=================================================================
// stimulate a click by id
//=================================================================
	function clickByID(id)
	{
	    var obj = returnOBJ(id);
	    obj.click();
	}
//=================================================================
// change page cursor from default to choosed
//=================================================================
	function bodyCursor(c)
	{
		document.body.style.cursor = c ? c : 'default';
	}
//=================================================================
// change div display
//=================================================================
	function divDisplay(div_id, display)
    {
		document.getElementById(div_id).style.display = display;
    }
//=================================================================
// turn div on/off
//=================================================================
	function divOnOff(divID)
	{
	    var obj = returnOBJ(divID);

	    if(obj.style.display == 'block') {
		    obj.style.display = 'none';
	    } else {
		    obj.style.display = 'block';
	    }
	}
//=================================================================
// resize div
//=================================================================
	function doOnResize(idTD, idDiv)
	{
	    var objDiv = returnOBJ(idDiv);
	    if (objDiv.offsetHeight > 600) {
			objDiv.style.height = "600px";
		} else {
		    objDiv.style.height = "";
		}
	}
//=================================================================
// disable any key
//=================================================================
	function disableKey(e, key)
	{
		var k;
		if(window.event) { // IE
			k = e.keyCode;
		} else if(e.which) { // Netscape/Firefox/Opera
			k = e.which;
		}

		if(k == key) return false;
		return true;
	}
//=================================================================
// check which key is pressed
//=================================================================
	function checkKey(e, key)
	{
		var k;
		if(window.event) { // IE
			k = e.keyCode;
		} else if(e.which) { // Netscape/Firefox/Opera
			k = e.which;
		}

		if(k == key) return true;
		return false;
	}
//=================================================================
// get screen height
//=================================================================
	function getHeight(){
		// opera Netscape 6 Netscape 4x Mozilla
		if (window.innerWidth || window.innerHeight){
			return window.innerHeight;
		}
		// IE Mozilla
		if (document.body.clientWidth || document.body.clientHeight){
			return document.body.clientHeight;
		}
	}
//=================================================================
// get screen width
//=================================================================
	function getWidth(){
		// opera Netscape 6 Netscape 4x Mozilla
		if (window.innerWidth || window.innerHeight){
			return window.innerWidth;
		}
		// IE Mozilla
		if (document.body.clientWidth || document.body.clientHeight){
			return document.body.clientWidth;
		}
	}
//=================================================================
// trim string spaces from left and right
//=================================================================
	function trim(stringToTrim)
	{
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
//=================================================================
// trim string spaces from left
//=================================================================
	function ltrim(stringToTrim)
	{
		return stringToTrim.replace(/^\s+/,"");
	}
//=================================================================
// trim string spaces from right
//=================================================================
	function rtrim(stringToTrim)
	{
		return stringToTrim.replace(/\s+$/,"");
	}
//=================================================================
// if enter pressed then stimulate a click
//=================================================================
	function inputUserIDEnter(e)
	{
		//if (checkKey(e, 13)) document.getElementById('submitSearch').click();
	}
//=================================================================
// open referrer url in new window
//=================================================================
	function OpenReferrer(url)
	{
		if (url) window.open(url);
	}
//=================================================================
// open ip info in new window
//=================================================================
	function OpenIPInfo(ipadd)
	{
		// if (ipadd) window.open('http://www.ripe.net/perl/whois?searchtext=' + ipadd);
		if (ipadd) window.open('http://www.dnsstuff.com/tools/whois.ch?ip='+ipadd+'&email=on');
	}
//=================================================================
// open country info from wikipedia.org in new window
//=================================================================
	function OpenCountryInfo(country)
	{
		if (country) window.open('http://en.wikipedia.org/wiki/Special:Search/' + country);
	}
//=================================================================
// checkbox - check/uncheck/delete selected
//=================================================================
    var OPTION_VALIDATE = 1, OPTION_CHKUNCHK = 2, OPTION_CHKALLBOX = 3;

    function checkBoxes(options, rst, col, mcol, prefix)
	{
        var c = 1, tmp = true;
		var toDelete = "";

		if (col) {
			col = col.split(":");
			mcol = mcol.split(":");
		}

		if (prefix.indexOf("stat") < 0) {
	        if (rst) document.frmAccessLogSystem.allbox.checked = false;

    	    for (var i = 0; i < document.frmAccessLogSystem.elements.length; i++) {
	            var e = document.frmAccessLogSystem.elements[i];
	            if ((e.name != 'allbox') && (e.name != 'allboxstat') && (e.type == 'checkbox') && (e.name.indexOf("stat") < 0)) {
	                switch(options){
	                    case OPTION_VALIDATE:
	                        if (e.checked) {
								c++;
								toDelete += e.value+",";
							}
	                    break;
	                    case OPTION_CHKUNCHK:
	                        if (document.frmAccessLogSystem.allbox.checked) {
	                            document.getElementById('tr'+c+prefix).style.backgroundColor = (c % 2) ? mcol[0] : mcol[1];
	                        } else {
	                            document.getElementById('tr'+c+prefix).style.backgroundColor = (c % 2) ? col[0] : col[1];
	                        }
	                        e.checked = document.frmAccessLogSystem.allbox.checked;
	                        c++;
	                    break;
	                    case OPTION_CHKALLBOX:
	                        if (!e.checked) tmp = false;
	                    break;
	                }
	            }
			}
        } else {
	        if (rst) document.frmAccessLogSystem.allboxstat.checked = false;

    	    for (var i = 0; i < document.frmAccessLogSystem.elements.length; i++) {
	            var e = document.frmAccessLogSystem.elements[i];
	            if ((e.name != 'allbox') && (e.name != 'allboxstat') && (e.type == 'checkbox') && (e.name.indexOf("stat") >= 0)) {
	                switch(options){
	                    case OPTION_VALIDATE:
	                        if (e.checked) {
								c++;
								toDelete += e.value+",";
							}
	                    break;
	                    case OPTION_CHKUNCHK:
	                        if (document.frmAccessLogSystem.allboxstat.checked) {
	                            document.getElementById('trstat'+c+prefix).style.backgroundColor = (c % 2) ? mcol[0] : mcol[1];
	                        } else {
	                            document.getElementById('trstat'+c+prefix).style.backgroundColor = (c % 2) ? col[0] : col[1];
	                        }
	                        e.checked = document.frmAccessLogSystem.allboxstat.checked;
	                        c++;
	                    break;
	                    case OPTION_CHKALLBOX:
	                        if (!e.checked) tmp = false;
	                    break;
	                }
	            }
			}
		}

        switch(options){
            case OPTION_VALIDATE:
				c--;
                if (!c) return 0;
                var answer = confirm (c + ' - rows selected.\nDelete all selected rows?');
                if (!answer) return 0;
                return "&evcDelSelected=" + toDelete.substring(0, toDelete.length - 1);
            break;
            case OPTION_CHKALLBOX:
				if (prefix.indexOf("stat") < 0) {
                	document.frmAccessLogSystem.allbox.checked = tmp;
				} else {
                	document.frmAccessLogSystem.allboxstat.checked = tmp;
				}
            break;
        }
    }
//=================================================================
// [EOF]
//=================================================================
/*
	var toDelete = "";
	var toCount = 0;

    function deleteCheckBoxes(y)
	{
if (y){
		var a = document.getElementsByName("delrow[]");
		var c = 1;
		toDelete = "";
		toCount = 0;

        for (var i = 0; i < document.frmAccessLogSystem.elements.length; i++) {
            var e = document.frmAccessLogSystem.elements[i];
            if ((e.name != 'allbox') && (e.type == 'checkbox')) {
				if (e.checked) {
					c++;
					toDelete += e.value+",";
				}
			}
		}
		toCount = c - 1;
		 //alert(toDelete);
/*		for (var i = 0; i < a.length; i++)
		{
			if (a.checked) c++;
		}*/
//alert(a[1].value);
//return toDelete;//.substring(toDelete.length-1);
/*return toDelete.substring(0,toDelete.length-1);
} else {
if (toCount) {
                var answer = confirm (toCount + ' - rows selected.\nDelete all selected rows?');
                if(!answer) return true;
} else {
return true;
}
}

                return false;
    }
*/