var datepicker_options = {
    dateFormat: 'dd.mm.yy',
    gotoCurrent: true,
    yearRange: '2008:2020',
    firstDay: 1,
    showOtherMonths: true,
    numberOfMonths: 1,
    showAnim: 'fadeIn',
    duration: 'fast'
};

var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 
var opera = navigator.appName.indexOf('Opera') == -1 ? false : true;

function openNewWindow(URL, name, top, left, width, height) {
    if (name = ''){ name = '_blank'; }
	newwindow = window.open(URL, name, 
		'top=' + top + 
		',left=' + left + 
		',width=' + width + 
		',height=' + height + 
		',scrollbars=0,menubar=0,status=0,resizable=0,toolbar=0,directories=0,location=0'); 
	return newwindow; 
}

function openNewWindowNormal(URL, name, top, left, width, height) {
    if (name = ''){ name = '_blank'; }
	newwindow = window.open(URL, name, 
		'top=' + top + 
		',left=' + left + 
		',width=' + width + 
		',height=' + height + 
		',scrollbars=2,menubar=0,status=1,resizable=1,toolbar=0,directories=0,location=0'); 
	return newwindow; 
}
function openNewWindowNormalFullSize(URL, name) {
    if (name = ''){ name = '_blank'; }
    sizes = getWindowSize();
	newwindow = window.open(URL, name, 
		'top=0' +
		',left=0' + 
		',width=' + sizes[0] + 
		',height=' + sizes[1] + 
		',scrollbars=2,menubar=1,status=1,resizable=1,toolbar=1,directories=0,location=1'); 
	return newwindow; 
}

<!-- This code is in the public domain. Feel free to link back to http://jan.moesen.nu/ -->
function sprintf(){
	if (!arguments || arguments.length < 1 || !RegExp)
	{
		return;
	}
	var str = arguments[0];
	var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	var a = b = [], numSubstitutions = 0, numMatches = 0;
	while (a = re.exec(str))
	{
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);

		numMatches++;
		if (pType == '%')
		{
			subst = '%';
		}
		else
		{
			numSubstitutions++;
			if (numSubstitutions >= arguments.length)
			{
				alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
			}
			var param = arguments[numSubstitutions];
			var pad = '';
			       if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
			  else if (pPad) pad = pPad;
			var justifyRight = true;
			       if (pJustify && pJustify === "-") justifyRight = false;
			var minLength = -1;
			       if (pMinLength) minLength = parseInt(pMinLength);
			var precision = -1;
			       if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
			var subst = param;
			       if (pType == 'b') subst = parseInt(param).toString(2);
			  else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
			  else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
			  else if (pType == 'u') subst = Math.abs(param);
			  else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
			  else if (pType == 'o') subst = parseInt(param).toString(8);
			  else if (pType == 's') subst = param;
			  else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
			  else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	}
	return str;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}

function clickRadio(obj, value){
    for(var i = 0; i < obj.length; i++){
        if (obj[i].value == value){
            obj[i].checked = true;
            break;
        }
    }
}

function hideId(id){
    if (document.getElementById(id)){
        document.getElementById(id).style.visibility = 'hidden';
        document.getElementById(id).style.display = 'none';
    }
}

function showId(id){
    if (document.getElementById(id)){
        document.getElementById(id).style.visibility = 'visible';
        document.getElementById(id).style.display = 'block';
    }
}

function setDatePeriod(v){
    if (v <= 1){
        return;
    }
    var d1 = new Date();
    var d2 = new Date(d1.getTime());
    switch(parseInt(v)){
        //Yesterday
        case 3:
            d1.setTime(d1.getTime() - 24 * 3600 * 1000);
            d2 = d1;
            break;
        //This month
        case 4:
            d1.setDate(1);
            break;
        //Prev month
        case 5:
            d1.setDate(1);
            if (d1.getMonth() == 0){
                d1.setMonth(11);
                d1.setFullYear(d1.getFullYear() - 1);
            } else {
                d1.setMonth(d1.getMonth() - 1);
            }
            d2.setDate(1);
            d2.setTime(d2.getTime() - 24 * 3600 * 1000);
            break;
        //All time
        case 6:
            d1.setDate(1);
            d1.setMonth(0);
            d1.setFullYear(2008);
            break;
    }
    var date1 = '' + (d1.getDate() < 10 ? '0' : '' ) + d1.getDate() + '.' + (d1.getMonth() < 9 ? '0' : '' ) + (d1.getMonth() + 1) + '.' + d1.getFullYear();
    var date2 = '' + (d2.getDate() < 10 ? '0' : '' ) + d2.getDate() + '.' + (d2.getMonth() < 9 ? '0' : '' ) + (d2.getMonth() + 1) + '.' + d2.getFullYear();
    document.getElementById('date_start').value = date1;
    document.getElementById('date_end').value = date2;
}
