function openXStage()
{
	window.open ("/custom_xstage/index.php", "XStage", "location=0,status=0,scrollbars=1,width=810,height=580,left=350,top=107'");
}

function openXStage2()
{
	var xstage_win = window.open ("/custom_xstage/xstage.php?accept=1", "XStage2", "location=0,status=0,scrollbars=1,width=810,height=580,left=204,top=130'");
	xstage_win.focus();
}

function openXStage3()
{
	window.open ("/custom_xstage/xstage.php?accept=1");
}

function openXstageHHSite()
{
	if ((typeof XS_HHWindow == 'undefined') || !XS_HHWindow || XS_HHWindow.closed) {
	    XS_HHWindow = window.open("http://www.haagsehogeschool.nl/", "XS_HHWindow", "location=yes,status=yes,scrollbars=yes,resizable=yes,toolbar=yes,titlebar=yes,width=756,height=576,left=18,top=18'");
    }
    XS_HHWindow.focus();
}

if (typeof String.prototype.pad == 'undefined') {
     String.prototype.pad                = function( chr, count, edge )
     {
     	var padStr = "";
     	for (var i=this.length; i< count; i++) padStr += chr;

     	switch (dir) {
     	   case 'l':
     	   case 'left':
     	       return padStr + this;
     	   case 'both': //  can't handle this yet
     	   case 'r':
     	   case 'right':
     	   default:
     	       return this + padStr;
     	}
     }
     String.prototype.padr               = function( chr, count ) { return this.pad( 'right' ); }
     String.prototype.padl               = function( chr, count ) { return this.pad( 'left' ); }

}
// trim the string - pass a single param of true in order to have double spaces removed also.
if (typeof String.prototype.trim == 'undefined') {
     String.prototype.trim                   = function(remDoubleSpaces)
     {
         var retValue = this.replace( /^\s+|\s+$/g, "" );

         if (isBoolean(remDoubleSpaces) && remDoubleSpaces) {
             while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
                 retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
             }
         }

         return retValue;
     }
}

// simple replacement of a string
String.prototype.str_replace            = function(fStr, rStr, honorCase)
{
     re = new RegExp( fStr, (honorCase ? 'g': 'ig'));
     return this.replace( re, rStr );
}

// New C# style string formatter
String.prototype.stringFormat           = function (arrInput)
{
     var idx            = 0;
     var placeholderlen = 2;
     var strOutput      = this.toString();
     if (arrInput instanceof Array) {
         var thisArgs = arrInput;
     } else {
         var thisArgs = arguments;
     }

     for (var i=1; i < thisArgs.length; i++) {
         while ((idx = strOutput.indexOf('{' + (i-1) + '}', idx)) != -1) {
             strOutput = strOutput.substring(0, idx) + thisArgs[i] + strOutput.substr(idx + placeholderlen + idx.toString().length);
         }
     }


     return strOutput;
}


function isString(a)    { return (typeof a == 'string'); }

function isFunction(a)  { return (typeof a == 'function'); }

function joinFunctions()
{
     var newfunc = '';
     for (var c = 0;c < arguments.length;c++) {
         if ( arguments[c] ) {
             var func=arguments[c].toString();
             newfunc+=func.substr(func.indexOf("{")-1);
         }
     }
     return new Function(newfunc);
}
function isAlien(a)     { return (isObject(a) && (typeof a.constructor != 'function')); }
function isArray(a)     { return (isObject(a) && (a.constructor == Array)); }
function isBoolean(a)   { return (typeof a == 'boolean'); }
function isNull(a)      { return ((typeof a == 'object') && !a); }
function isInteger(a)   { re = /^-?\d+$/g; return re.test(a); }
function isObject(a)    { return ((typeof a == 'object' && !!a) || isFunction(a)); }
// I think that this function does not work! passing an undefined var to a function causes an error IIRC.
function isUndefined(a) { return (typeof a == 'undefined'); } // don't trust this function yet - what exactly is it saying
function isEmpty(o) {
     var i, v;
     if (isObject(o)) {
         for (i in o) {
             v = o[i];
             if (!!isUndefined(v) && !!isFunction(v)) {
                 return false;
             }
         }
     }
     return true;
}

//////////////////////////////////////
///////////////////////////////////////


// add/remove CSS classes properly (nondestructively)
var ___addCSSClass          = function (cc)
{
     if (isString(cc) && (typeof this.className !== 'undefined')) {
         if ((this.className.indexOf(" "+cc) == -1) && (this.className.indexOf(cc+" ") == -1) && (this.className != cc)) {
             this.className = this.className + " " + cc;
         } else if (this.className.trim() == '' && cc.length) {
             this.className = cc;
         }
     }
}
var ___removeCSSClass       = function(cc)
{
	 if (isString(cc) && (typeof this.className !== 'undefined')) {
         if (this.className.indexOf(' '+cc) != -1) {
             this.className = this.className.str_replace(' '+cc, '').trim();
         } else if (this.className.indexOf(cc+' ') != -1) {
             this.className = this.className.str_replace(cc+' ', '').trim();
         } else if (this.className == cc) {
             this.className = '';
         }
     }
}

var ___bindCSSFuncs = function()
{
		var inputs = document.getElementsByTagName('INPUT');
		for (var i=0; i < inputs.length; i++) {
			inputs[i].addCSSClass    = ___addCSSClass;
			inputs[i].removeCSSClass = ___removeCSSClass;
			inputs[i].onfocus 		 = function() { this.addCSSClass('beenhereBox'); this.addCSSClass('highlightBox');    };
			inputs[i].onblur		 = function() { this.removeCSSClass('highlightBox'); };
		}

		var selects = document.getElementsByTagName('SELECT');
		for (var i=0; i < selects.length; i++) {
			selects[i].addCSSClass    = ___addCSSClass;
			selects[i].removeCSSClass = ___removeCSSClass;
		}

}

/* next part throws an error
if (isFunction(window.onload)) {
	window.onload = joinFunctions(
		window.onload,
		___bindCSSFuncs
	);
} else {
	window.onload = ___bindCSSFuncs;
}*/

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function workpieceProject(selObj){ //v3.0
  self.location='workpieces.php?project_id='+selObj.options[selObj.selectedIndex].value;
}
function documentProject(selObj){ //v3.0
  self.location='documents.php?project_id='+selObj.options[selObj.selectedIndex].value;
}
function pictureProject(selObj){ //v3.0
  self.location='pictures.php?project_id='+selObj.options[selObj.selectedIndex].value;
}


// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
//
// You may copy these functions providing that
// (a) you leave this copyright notice intact, and
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(plaintext)
{
    if (!plaintext || !plaintext.length) {
        return plaintext;
    }

    var SAFECHARS = "0123456789" +                  // Numeric
                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +  // Alphabetic
                    "abcdefghijklmnopqrstuvwxyz" +
                    "-_.!~*'()";                    // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var encoded = "";
    for (var i = 0; i < plaintext.length; i++ ) {
        var ch = plaintext.charAt(i);
        if (ch == " ") {
            encoded += "+";             // x-www-urlencoded, rather than %20
        } else if (SAFECHARS.indexOf(ch) != -1) {
            encoded += ch;
        } else {
            var charCode = ch.charCodeAt(0);
            if (charCode > 255) {

//                alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
//                        "(URL encoding only supports 8-bit characters.)\n" +
//                        "A space (+) will be substituted." );

                encoded += "+";
            } else {
                encoded += "%";
                encoded += HEX.charAt((charCode >> 4) & 0xF);
                encoded += HEX.charAt(charCode & 0xF);
            }
        }
    } // for

    return encoded;
};

function URLDecode(encoded)
{
    if (!encoded || !encoded.length) {
        return encoded;
    }

    // Replace + with ' '
    // Replace %xx with equivalent character
    // Put [ERROR] in output if %xx is invalid.

    var HEXCHARS = "0123456789ABCDEFabcdef";
    var plaintext = "";
    var i = 0;
    while (i < encoded.length) {
       var ch = encoded.charAt(i);
       if (ch == "+") {
           plaintext += " ";
           i++;
       } else if (ch == "%") {
            if (i < (encoded.length-2)
                    && HEXCHARS.indexOf(encoded.charAt(i+1)) != -1
                    && HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
                plaintext += unescape(encoded.substr(i,3));
                i += 3;
            } else {

//                alert( 'Bad escape combination near ...' + encoded.substr(i) );

                plaintext += "%[ERROR]";
                i++;
            }
        } else {
           plaintext += ch;
           i++;
        }
    } // while
   return plaintext;
};
