// ----------------------------------------------------------------------------------------------------------------------------------------

function element(id) {
	return document.getElementById(id); 
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function showDIV(divObj) {
	if (divObj!=null) {
		if (divObj.style.visibility!='visible') {
			divObj.style.visibility='visible';
			divObj.style.display='inline';
		}
	}
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function hideDIV(divObj) {
	if (divObj!=null) {
		if (divObj.style.visibility!='hidden') {
			divObj.style.visibility='hidden';
			divObj.style.display='none';
		}
	}
}

//----------------------------------------------------------------------------------------------------------------------------------------

function is_numeric( mixed_var ) {
    return !isNaN(mixed_var * 1);
}

//----------------------------------------------------------------------------------------------------------------------------------------

function findPosX(obj) {
	var top = 0, left = 0;

	var myTarget=obj;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;
		left += myTarget.offsetLeft;
		myTarget = myTarget.offsetParent;
	}

	return left;
}

// ----------------------------------------------------------------------------------------------------------------------------------------

function findPosY(obj) {
	var top = 0, left = 0;

	var myTarget=obj;
	while(myTarget!= document.body) {
		top += myTarget.offsetTop;
		left += myTarget.offsetLeft;
		myTarget = myTarget.offsetParent;
	}

	return top;
}

//----------------------------------------------------------------------------------------------------------------------------------------

function stateElement(itemDIV) {
	var obj=element(itemDIV);
	
	//alert('display='+obj.style.display+'\nvisibility='+obj.style.visibility);
	
	if ((obj.style.display=='' && obj.style.visibility=='') || (obj.style.display=='none' && obj.style.visibility=='hidden')) return "HIDDEN";
	if ((obj.style.display=='inline') && obj.style.visibility=='visible') return "VISIBLE";
}

//----------------------------------------------------------------------------------------------------------------------------------------

function mktime() {
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;

    if (argc > 0){
        d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
    }
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ var set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if (isNaN(no)) {
            return false;
        } else {
            // arg is number, let's manipulate date object
            if(!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }

    return Math.floor(d.getTime()/1000);
}

//----------------------------------------------------------------------------------------------------------------------------------------

function str_replace(search, replace, subject) {
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;

    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };

    return sa ? s : s[0];
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function gotoBranche() {
	var selectBoxObj=element('otherBranchesList');
	window.location="http://"+selectBoxObj.value;
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function hideOtherBranches() {
	hideDIV(element('otherBranches'));
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showHideOtherBranches() {
	if (stateElement('branchList')=="VISIBLE") {
		hideDIV(element('branchList'));
		return false;
	}

	var ajaxConnector=new sack();
	ajaxConnector.requestFile=domainroot+"/index.php?ajaxsubmit=getotherbranches";
	ajaxConnector.onCompletion=function () {
		var response=ajaxConnector.response;
		var elements=response.split("#");

		hideDIV(element('branchList'));
		var html='<select id="otherBranchesList" name="otherBranchesList" style="font-size: 10px; width: 180px;" onchange="gotoBranche();">';

		if (elements.length>0) {
			html+="<option value=''>** Selecteer een branche</option>";

			var maxElements=(elements.length)-1;
			for (idx=0;idx<maxElements;idx++) {
				option=elements[idx].split("=");
				html+="<option value='"+option[0]+"'>"+option[1]+"</option>";
			}

			html+="</select>";

			element('otherBranches').innerHTML=html;

			showDIV(element('branchList'));
			showDIV(element('otherBranches'))
			element('otherBranchesList').focus();
		}
	}

	ajaxConnector.runAJAX();
}

// ----------------------------------------------------------------------------------------------------------------------------------------------------------------------

function showLoginPopupBox() {
	if (stateElement('light_loginbox')=="VISIBLE") {
		hideDIV(element('light_loginbox'));
		hideDIV(element('fade_loginbox'));
		return false;
	}

	showDIV(element('fade_loginbox'));
	showDIV(element('light_loginbox'));
	element('username').focus();
}

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------

