function is_array(value)
{
	if(typeof value === 'object' && value && value instanceof Array)
		return true;
	else
		return false;
}

function str_replace(s,r,c)
{
	if(is_array(s))
	{
		for(i=0; i < s.length; i++)
			c = c.split(s[i]).join(r[i]);
	}
	else
	{
		c = c.split(s);
		c = c.join(r);
	}
	return c;
}

function setFactsheetProduct(nr,color,factsheets)
{
	for(i = 1; i <= factsheets; i++)
	{
		if(nr==i)
		{
			document.getElementById('f-link-'+i).style.background='#'+color;
			document.getElementById('f-content-'+i).style.display='block';
		}
		else
		{
			document.getElementById('f-link-'+i).style.background='';
			document.getElementById('f-content-'+i).style.display='none';
		}
	}
}

function focusIt(obj_id)
{
	var myobj = document.getElementById(obj_id);
	myobj.focus();
}

function checkNumber(num)
{
	if(isNaN(num)==true)
		return false;
	else
		return true;
}

function checkradio(field) {
	for (i=0; i<field.length; i++) {
		if(field[i].checked == true) {
			return field[i].value;
		}
	}
}

String.prototype.reverse = function()
{
	return this.split("").reverse().join("");
}

function get_scroll_position()
{
	var scroll_x = 0,
	scroll_y = 0;
	
	if(typeof( window.pageYOffset ) == 'number')
	{ // Netscape
		scroll_y = window.pageYOffset; scroll_x = window.pageXOffset;
	}
	else if(document.body && (document.body.scrollLeft || document.body.scrollTop))
	{ // DOM
		scroll_y = document.body.scrollTop; scroll_x = document.body.scrollLeft;
	}
	else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop))
	{ // IE6
		scroll_y = document.documentElement.scrollTop; scroll_x = document.documentElement.scrollLeft;
	}
	return [scroll_x,scroll_y];
}

function get_page_size()
{
	if(window.innerHeight && window.scrollMaxY)
	{
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if(self.innerHeight)
	{ // all except Explorer
		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth;
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if(document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	}
	else
	{
		pageHeight = yScroll;
	}
	
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{
		pageWidth = xScroll;
	}
	else
	{
		pageWidth = windowWidth;
	}
	
	return [pageWidth,pageHeight];
}

function setDarkBG(mode) {
	if(mode==true) {
		mode='block';
	}
	else {
		mode='none';
	}
	document.getElementById('darkDiv').style.display=mode;
	
	pagesize = get_page_size();
	document.getElementById('darkDiv').style.width = pagesize[0]+'px';
	document.getElementById('darkDiv').style.height = pagesize[1]+'px';
}

function setPopup(object,mode) {
	if(mode==true) {
		setDarkBG(true);
		mode='block';
		if(detect_ie6()==true) {
			document.getElementById('content').style.display='none';
		}
	}
	else {
		setDarkBG(false);
		mode='none';
		if(detect_ie6()==true) {
			document.getElementById('content').style.display='block';
		}
	}
	scrollpos = get_scroll_position();
	document.getElementById(object).style.top=(scrollpos[1]+70)+'px';
	document.getElementById(object).style.display=mode;
}

function toggle(object1,object2) {
	document.getElementById(object1).style.display='block';
	document.getElementById(object2).style.display='none';
}

function toggle_switch(object) {
	if(document.getElementById(object).style.display=='block') {
		document.getElementById(object).style.display='none';
	}
	else {
		document.getElementById(object).style.display='block';
	}
}

function detect_ie6() {
	if(navigator.userAgent.indexOf("MSIE 6")!=-1)
		return true;
	else
		return false;
}

function number_format(number, decimals, dec_point, thousands_sep) {
	var exponent="";
	var numberstr=number.toString();
	var eindex=numberstr.indexOf("e");
	if(eindex>-1) {
		exponent=numberstr.substring(eindex);
		number=parseFloat(numberstr.substring(0,eindex));
	}
	if(decimals!=null) {
		var temp=Math.pow(10,decimals);
		number=Math.round(number*temp)/temp;
	}
	var sign=number<0?"-":"";
	var integer=(number>0?Math.floor(number):Math.abs(Math.ceil(number))).toString();
	var fractional=number.toString().substring(integer.length+sign.length);
	dec_point=dec_point!=null?dec_point:".";
	fractional=decimals!=null&&decimals>0||fractional.length>1?(dec_point+fractional.substring(1)):"";
	if(decimals!=null&&decimals>0) {
		for(i=fractional.length-1,z=decimals;i<z;++i) {
			fractional+="0";
		}
	}
	thousands_sep=(thousands_sep!=dec_point||fractional.length==0)?thousands_sep:null;
	if(thousands_sep!=null&&thousands_sep!="") {
		for(i=integer.length-3;i>0;i-= 3) {
			integer=integer.substring(0,i)+thousands_sep+integer.substring(i);
		}
	}
	return sign +integer+fractional+exponent;
}

function replaceAjaxAnd(string) {
	asdf=string.replace(/\&/g, "[xJf6rHfgs5rhfZe6hfa3g]");
	alert(asdf);
	return asdf;
}

function changeDisplay(id,mode)
{
	min_height= 70;
	obj = document.getElementById('order-in-'+id);
	if(mode=='open')
	{
		mode='red';
		mode_div='open';
		obj2 = document.getElementById('order-open-bar-details-'+id);
	}
	else if(mode=='success')
	{
		mode='white';
		mode_div='success';
		obj2 = document.getElementById('order-success-bar-details-'+id);
	}
	else
	{
		mode='white';
		mode_div='success';
		obj2 = document.getElementById('order-success-bar-details-'+id);
	}
	if(obj.offsetHeight==min_height)
	{
		obj.style.height='auto';
		obj2.style.backgroundImage="url(templates/f-print/images/details_hide_"+mode+".gif)";
	}
	else
	{
		obj.style.height=min_height+'px';
		obj2.style.backgroundImage="url(templates/f-print/images/details_show_"+mode+".gif)";
	}
}

function setUpload(order)
{
	document.getElementById("upload_dir").value = order;
	setPopup('popupFileUpload',true);
}

function callback_fileupload(filename) {
	alert(filename);
}	

function serialize (mixed_value) {
    // Returns a string representation of variable (which can later be unserialized)  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/serialize    // +   original by: Arpad Ray (mailto:arpad@php.net)
    // +   improved by: Dino
    // +   bugfixed by: Andrej Pavlovic
    // +   bugfixed by: Garagoth
    // +      input by: DtTvB (http://dt.in.th/2008-09-16.string-length-in-bytes.html)    // +   bugfixed by: Russell Walker (http://www.nbill.co.uk/)
    // +   bugfixed by: Jamie Beck (http://www.terabit.ca/)
    // +      input by: Martin (http://www.erlenwiese.de/)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // -    depends on: utf8_encode    // %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
    // *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});    // *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'
    var _getType = function (inp) {
        var type = typeof inp, match;
        var key;
        if (type == 'object' && !inp) {            return 'null';
        }
        if (type == "object") {
            if (!inp.constructor) {
                return 'object';            }
            var cons = inp.constructor.toString();
            match = cons.match(/(\w+)\(/);
            if (match) {
                cons = match[1].toLowerCase();            }
            var types = ["boolean", "number", "string", "array"];
            for (key in types) {
                if (cons == types[key]) {
                    type = types[key];                    break;
                }
            }
        }
        return type;    };
    var type = _getType(mixed_value);
    var val, ktype = '';
    
    switch (type) {        case "function": 
            val = ""; 
            break;
        case "boolean":
            val = "b:" + (mixed_value ? "1" : "0");            break;
        case "number":
            val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
            break;
        case "string":            mixed_value = this.utf8_encode(mixed_value);
            val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\"";
            break;
        case "array":
        case "object":            val = "a";
            /*
            if (type == "object") {
                var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
                if (objname == undefined) {                    return;
                }
                objname[1] = this.serialize(objname[1]);
                val = "O" + objname[1].substring(1, objname[1].length - 1);
            }            */
            var count = 0;
            var vals = "";
            var okey;
            var key;            for (key in mixed_value) {
                ktype = _getType(mixed_value[key]);
                if (ktype == "function") { 
                    continue; 
                }                
                okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key);
                vals += this.serialize(okey) +
                        this.serialize(mixed_value[key]);
                count++;            }
            val += ":" + count + ":{" + vals + "}";
            break;
        case "undefined": // Fall-through
        default: // if the JS object has a property which contains a null value, the string cannot be unserialized by PHP            val = "N";
            break;
    }
    if (type != "object" && type != "array") {
        val += ";";    }
    return val;
}

function unserialize (data) {
    // Takes a string representation of variable and recreates it  
    // 
    // version: 1006.1915
    // discuss at: http://phpjs.org/functions/unserialize    // +     original by: Arpad Ray (mailto:arpad@php.net)
    // +     improved by: Pedro Tainha (http://www.pedrotainha.com)
    // +     bugfixed by: dptr1988
    // +      revised by: d3x
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)    // +        input by: Brett Zamir (http://brett-zamir.me)
    // +     improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: Chris
    // +     improved by: James
    // +        input by: Martin (http://www.erlenwiese.de/)    // +     bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     improved by: Le Torbi
    // +     input by: kilops
    // +     bugfixed by: Brett Zamir (http://brett-zamir.me)
    // -      depends on: utf8_decode    // %            note: We feel the main purpose of this function should be to ease the transport of data between php & js
    // %            note: Aiming for PHP-compatibility, we have to translate objects to arrays
    // *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
    // *       returns 1: ['Kevin', 'van', 'Zonneveld']
    // *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');    // *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}
    var that = this;
    var utf8Overhead = function(chr) {
        // http://phpjs.org/functions/unserialize:571#comment_95906
        var code = chr.charCodeAt(0);        if (code < 0x0080) {
            return 0;
        }
        if (code < 0x0800) {
             return 1;        }
        return 2;
    };
 
     var error = function (type, msg, filename, line){throw new that.window[type](msg, filename, line);};
    var read_until = function (data, offset, stopchr){
        var buf = [];
        var chr = data.slice(offset, offset + 1);
        var i = 2;        while (chr != stopchr) {
            if ((i+offset) > data.length) {
                error('Error', 'Invalid');
            }
            buf.push(chr);            chr = data.slice(offset + (i - 1),offset + i);
            i += 1;
        }
        return [buf.length, buf.join('')];
    };    var read_chrs = function (data, offset, length){
        var buf;
 
        buf = [];
        for (var i = 0;i < length;i++){            var chr = data.slice(offset + (i - 1),offset + i);
            buf.push(chr);
            length -= utf8Overhead(chr); 
        }
        return [buf.length, buf.join('')];    };
    var _unserialize = function (data, offset){
        var readdata;
        var readData;
        var chrs = 0;        var ccount;
        var stringlength;
        var keyandchrs;
        var keys;
         if (!offset) {offset = 0;}
        var dtype = (data.slice(offset, offset + 1)).toLowerCase();
 
        var dataoffset = offset + 2;
        var typeconvert = function(x) {return x;}; 
        switch (dtype){
            case 'i':
                typeconvert = function (x) {return parseInt(x, 10);};
                readData = read_until(data, dataoffset, ';');                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case 'b':                typeconvert = function (x) {return parseInt(x, 10) !== 0;};
                readData = read_until(data, dataoffset, ';');
                chrs = readData[0];
                readdata = readData[1];
                dataoffset += chrs + 1;            break;
            case 'd':
                typeconvert = function (x) {return parseFloat(x);};
                readData = read_until(data, dataoffset, ';');
                chrs = readData[0];                readdata = readData[1];
                dataoffset += chrs + 1;
            break;
            case 'n':
                readdata = null;            break;
            case 's':
                ccount = read_until(data, dataoffset, ':');
                chrs = ccount[0];
                stringlength = ccount[1];                dataoffset += chrs + 2;
 
                readData = read_chrs(data, dataoffset+1, parseInt(stringlength, 10));
                chrs = readData[0];
                readdata = readData[1];                dataoffset += chrs + 2;
                if (chrs != parseInt(stringlength, 10) && chrs != readdata.length){
                    error('SyntaxError', 'String length mismatch');
                }
                 // Length was calculated on an utf-8 encoded string
                // so wait with decoding
                readdata = that.utf8_decode(readdata);
            break;
            case 'a':                readdata = {};
 
                keyandchrs = read_until(data, dataoffset, ':');
                chrs = keyandchrs[0];
                keys = keyandchrs[1];                dataoffset += chrs + 2;
 
                for (var i = 0; i < parseInt(keys, 10); i++){
                    var kprops = _unserialize(data, dataoffset);
                    var kchrs = kprops[1];                    var key = kprops[2];
                    dataoffset += kchrs;
 
                    var vprops = _unserialize(data, dataoffset);
                    var vchrs = vprops[1];                    var value = vprops[2];
                    dataoffset += vchrs;
 
                    readdata[key] = value;
                } 
                dataoffset += 1;
            break;
            default:
                error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);            break;
        }
        return [dtype, dataoffset - offset, typeconvert(readdata)];
    };
        return _unserialize((data+''), 0)[2];
}

function startDummyservice()
{
	loadGroupById(6);
}
