var formArrElem = new Array();
var formArrElemError = new Array();

function addToFormValidator(elem, errorText) {
      if(typeof this.arrCounter == 'undefined')
          this.arrCounter = 0;
      formArrElem[arrCounter] = elem;
 	  formArrElemError[arrCounter] = errorText;
      this.arrCounter++;
}

function formValidator() {
    var validates = true;
    for (i=0, n=formArrElem.length; i<n; i++) {
		if (isEmpty(document.getElementById(formArrElem[i]),formArrElemError[i])) {
			validates = false;
			break;
    	}
    }
    return validates; 
}

function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return true;
	}
	return false;
}

function loginValidator( form ) {
if (form.user.value == "" || form.pass.value == "") {
	return false; 
  }
  return true;
} 

function changeScreenSize(w,h) {
  window.resizeTo( w,h );
}

function OpenInScherm(the_url) {
  window.open(the_url, null, 'location=no, resizable=no, toolbar=no, menubar=no, statusbar=no');
}

function confirmAction(text) {
var agree=confirm(text);
if (agree)
	return true ;
else
	return false ;
}

function confirmDelete() {
var agree=confirm("Are you sure you want to DELETE?");
if (agree)
	return true ;
else
	return false ;
}

function js_array_to_php_array (a)
// This converts a javascript array to a string in PHP serialized format.
// This is useful for passing arrays to PHP. On the PHP side you can 
// unserialize this string from a cookie or request variable. For example,
// assuming you used javascript to set a cookie called "php_array"
// to the value of a javascript array then you can restore the cookie 
// from PHP like this:
//    <?php
//    session_start();
//    $my_array = unserialize(urldecode(stripslashes($_COOKIE['php_array'])));
//    print_r ($my_array);
//    ?>
// This automatically converts both keys and values to strings.
// The return string is not URL escaped, so you must call the
// Javascript "escape()" function before you pass this string to PHP.
{
    var a_php = "";
    var total = 0;
    for (var key in a)
    {
        ++ total;
        a_php = a_php + "s:" +
                String(key).length + ":\"" + String(key) + "\";s:" +
                String(a[key]).length + ":\"" + String(a[key]) + "\";";
    }
    a_php = "a:" + total + ":{" + a_php + "}";
//    a_php = escape(a_php);
    a_php = encodeBase64(a_php);
    return a_php;
}

var END_OF_INPUT = -1;

var base64Chars = new Array(
    'A','B','C','D','E','F','G','H',
    'I','J','K','L','M','N','O','P',
    'Q','R','S','T','U','V','W','X',
    'Y','Z','a','b','c','d','e','f',
    'g','h','i','j','k','l','m','n',
    'o','p','q','r','s','t','u','v',
    'w','x','y','z','0','1','2','3',
    '4','5','6','7','8','9','+','/'
);

var reverseBase64Chars = new Array();
for (var i=0; i < base64Chars.length; i++){
    reverseBase64Chars[base64Chars[i]] = i;
}

var base64Str;
var base64Count;
function setBase64Str(str){
    base64Str = str;
    base64Count = 0;
}
function readBase64(){    
    if (!base64Str) return END_OF_INPUT;
    if (base64Count >= base64Str.length) return END_OF_INPUT;
    var c = base64Str.charCodeAt(base64Count) & 0xff;
    base64Count++;
    return c;
}
function encodeBase64(str){
    setBase64Str(str);
    var result = '';
    var inBuffer = new Array(3);
    var lineCount = 0;
    var done = false;
    while (!done && (inBuffer[0] = readBase64()) != 

END_OF_INPUT){
        inBuffer[1] = readBase64();
        inBuffer[2] = readBase64();
        result += (base64Chars[ inBuffer[0] >> 2 ]);
        if (inBuffer[1] != END_OF_INPUT){
            result += (base64Chars [(( inBuffer[0] << 4 ) & 0x30) 

| (inBuffer[1] >> 4) ]);
            if (inBuffer[2] != END_OF_INPUT){
                result += (base64Chars [((inBuffer[1] << 2) & 

0x3c) | (inBuffer[2] >> 6) ]);
                result += (base64Chars [inBuffer[2] & 0x3F]);
            } else {
                result += (base64Chars [((inBuffer[1] << 2) & 

0x3c)]);
                result += ('=');
                done = true;
            }
        } else {
            result += (base64Chars [(( inBuffer[0] << 4 ) & 

0x30)]);
            result += ('=');
            result += ('=');
            done = true;
        }
        lineCount += 4;
        if (lineCount >= 76){
            result += ('\n');
            lineCount = 0;
        }
    }
    return result;
}

function showPhoto(filename,width,height)
{
	var source = filename;
	var w = Number(width) + 20;
	var h = Number(height) + 20;
	w = String(w);
	h = String(h);
	var bigfoto = window.open('',null,'resizable=yes,scrollbars=yes,top=10,left=10,width='+w+',height='+h);
	bigfoto.document.write('<html><head><title>Gallery</title><style>img\{border-color:#ccc;\}</style></head>')
	bigfoto.document.write('<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0" bgcolor="#FFFFFF" onBlur="window.close();" onClick="window.close();"><center><img src="'+source+'" border="2"></center></body></html>')
	bigfoto.document.close()
}

// ** The following is a trick to make expanding CSS menus is IE6
//sfHover = function() {//	var sfEls = document.getElementById("nav").getElementsByTagName("LI");//	for (var i=0; i<sfEls.length; i++) {//		sfEls[i].onmouseover=function() {//			this.className+=" sfhover";//		}//		sfEls[i].onmouseout=function() {//			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");//		}//	}//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);
