
// JavaScript Document
function CheckPhoto(frm) {
	var file = frm.photo.value;
	if(trim(file).length<3) {
		alert("Je hebt nog geen geldig fotobestand geselecteerd");
		return false;
	}
	var extensie = file.split(".",2);

	if (extensie[1].toLowerCase() != "gif" & extensie[1].toLowerCase() != "jpg" & extensie[1].toLowerCase() != "tiff" & extensie[1].toLowerCase() != "tif" & extensie[1].toLowerCase() != "bmp" ){
		alert("Je hebt geen geldig fotobestand geselecteerd.\n\nEen geldig fotobestand heeft een van volgende extensies:\n .gif, .jpg, .bmp, .tiff of .png");
		return false;
	}
	return true;
}

function UploadPhoto(frm) {
	
	strAppVersion = navigator.appVersion;
  	if (frm.photo.value != "")
  	{
    	if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
    	{
      	winstyle = "dialogWidth=375px; dialogHeight:115px; center:yes; scroll: 0; help: 0; status:0;";
      	window.showModelessDialog('framebar.asp?to=10&PID=EEDD09B0E8ED7D13&b=IE',null,winstyle);
    	}
    	else
    	{
      	window.open('framebar.asp?to=10&PID=EEDD09B0E8ED7D13&b=NN','','width=370,height=130', true);
    	}
  	}
	return true;
}
function fShowGuestbook(iMemberId) {
	
	getDialog('notloggedDialog');return false;
	
}
function fShowSendMail(iMemberId) {
	
	getDialog('notloggedDialog');
	
}
function $(elem) {
	return document.getElementById(elem);
}
defaultStatus = document.title;
// Global variables and functions used for xhr Requests
var xhrSent = false;
var xhrData = null;
var xhrErrorData = null;
var xhrSentAlertMessage = 'Het verzoek is reeds verstuurd, een ogenblikje a.u.b.';
var xhrFocusID = null;
var xhrMustFocusID = null;
//
var popWindows = new Array();
var jsonWindows = new Array();
var currPopID = null;

function fXhrError(data, ioArgs) {
	xhrSent = false;
	disableCloseButton(false);
	var errID = "Error"+createDialogID();
	var errData = {"response": {"type": "error", "id": errID, "title": "ERROR!", "message": "Er is een fout opgetreden:<ul>", "buttons": null, "width": "800px"}};
	for (var ident in data) {
		if (ident != 'responseText' && ident != 'toJSONString' && ident != 'parseJSON') {
			errData.response.message += "<li>"+ident+": "+eval("data."+ident)+"</li>";
		}
	}
	errData.response.message += "</ul>";
	if (typeof data.responseText != 'undefined') {
		xhrErrorData = data.responseText;
		errData.response.message += "<iframe name=\"FRAME"+errID+"\" id=\"FRAME"+errID+"\" src=\"/ajax/ajaxerror.asp\" style=\"width: 99%; height:250px; overflow: auto; border: 2px solid #999; background-color: #FFF; color: #000; margin-bottom: 8px;\" onload=\"fXhrFillErrorFrame('FRAME"+errID+"');\"></iframe>";
	}
	errData.response.message += 'Probeer het later nogmaals...'
	showDialog(errData.response.id, errData)
}
function fXhrFillErrorFrame(name) {
	if (xhrErrorData!=null) {
		window.frames[name].document.getElementById('errorContent').innerHTML = xhrErrorData;
		xhrErrorData = null;
	}
}
function fXhrCheckResponse(data) {	
	if (typeof data.response != 'undefined') {	
		if (typeof data.response.id == 'undefined') {data.response.id = createDialogID();}		
		showDialog(data.response.id, data);
	}
}
function fXhrCheckHTML(data) {
	if (typeof data.html != 'undefined') {
		for (var iHtml=0;iHtml<=data.html.length-1;iHtml++) {
			if ($(data.html[iHtml].id)!=null) {
				executeHTMLcommand(data.html[iHtml].id,data.html[iHtml],'');
			}
		}
	}
}
function executeHTMLcommand(elemID, commands, curLevel) {
	for (var ident in commands){
		if (ident != 'id' && ident != 'toJSONString' && ident != 'parseJSON') {
			if (typeof(eval("commands."+ident))=='object') {
				executeHTMLcommand(elemID, eval("commands."+ident), curLevel+'.'+ident);
			} else {
				eval('$(elemID)'+curLevel+'.'+ident+' = "'+ eval("commands."+ident).replace(/"/g,'\\"') + '"');
			}
		}
	}
}
function fXhrCheckCallStackAfter(data) {
	if (typeof data.callstackAfter != 'undefined') {
		for (var iStack=0;iStack<=data.callstackAfter.length-1;iStack++) {
			if (typeof data.callstackAfter[iStack].name == 'function') {
				if (typeof data.callstackAfter[iStack].waittime == 'number') {
					setTimeout(data.callstackAfter[iStack].name, data.callstackAfter[iStack].waittime);
				} else {
					data.callstackAfter[iStack].name();
				}
			}
		}
	}
}
function fXhrCheckCallStackBefore(data) {
	if (typeof data.callstackBefore != 'undefined') {
		for (var iStack=0;iStack<=data.callstackBefore.length-1;iStack++) {
			if (typeof data.callstackBefore[iStack].name == 'function') {
				if (typeof data.callstackBefore[iStack].waittime == 'number') {
					setTimeout(data.callstackBefore[iStack].name, data.callstackBefore[iStack].waittime);
				} else {
					data.callstackBefore[iStack].name();
				}
			}
		}
	}
}
function fXhrFocusAnalyzer(data) {
	var objElements = eval("document."+data.form+".elements");
	var blnFocussed = false;
	if (objElements !=null) {
		for (var i=0;i<=objElements.length-1&&!blnFocussed;i++) {
			switch(objElements[i].type) {
				case "text":
				case "textarea":
				case "password":
					if(objElements[i].value == "") {
						objElements[i].focus();
						blnFocussed = true;
					}
					break;
				default:
					break;
			}
		}
	}
}
function fXhrCallBack(data, ioArgs) {
	xhrSent = false;
	disableCloseButton(false);
	xhrData = data;
	if(data.status=='ok') {		
		fXhrCheckCallStackBefore(data);		
		fXhrCheckResponse(data);		
		fXhrCheckHTML(data);
		fXhrCheckCallStackAfter(data);
	} else {
		var respID = createDialogID();
		showDialog(respID, data);
	}
}
function fXhrReloadCurrent() {
	self.location.reload(true);
}
//
function fOver(objL) {
	window.status = objL.title;
}
function trim(str) {
   return str.replace(/^\s*|\s*$/g,"");
}
function Left(str, n) {
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
function URLEncode(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) {
				encoded += "%26";
				encoded += "%23";
				encoded += charCode;
				encoded += "%3B";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}
	return encoded;
}
function URLDecode(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 {
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	}
	return plaintext;
}
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) )
	{
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){expires = expires * 1000 * 60 * 60 * 24;}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape(value) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
function changeImg(n) {
	if (n >= 0) {
		for (i=1;i<n+1;i++) {
			$('rating'+i).className = 'on';
		}
	} else {
		for (i=1;i<=10; i++) {
			$('rating'+i).className = 'off';
		}
	}
	return true;
}
function fLink(linkID,sDefault) {
	if ($('link_'+linkID)!=null){
		if ($(linkID).value == '' && typeof sDefault == 'string') {
			$('link_'+linkID).innerHTML = URLDecode(sDefault);
			$('link_'+linkID).className = "red b";
		} else {
			$('link_'+linkID).innerHTML = $(linkID).value;
			$('link_'+linkID).className = "";
		}
	}
}
function checkEnter(e,formfieldID){
	var charCode;
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e; charCode = e.which;//character code is contained in NN4's which property
	} else {
		e = event; charCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(charCode == 13){ // Enter
		return true;
	}
	return false;
}
var emailErr = "";
function isValidEmail(emailStr) {
	var emailPat=/^(.+)@(.+)$/ ;
	var specialChars="\\(\\)<>@,;:φόδ\\\\\\\"\\.\\[\\]" ;
	var validDomChars="\[^\\s" + specialChars + "\]" ;
	var validChars = "[^a-zA-Z_0-9-+.]";
	var quotedUser="(\"[^\"]*\")" ;
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ ;
	var atom=validDomChars + '+' ;
	var word="(" + atom + "|" + quotedUser + ")" ;
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$") ;
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") ;
	emailErr = ""
	/* Finally, let's start trying to figure out if the supplied address is valid. */
	var matchArray=emailStr.match(emailPat) ;
	if (matchArray==null) { /* Too many/few @'s or something; */
		emailErr = "Het ingevoerde emailadres is niet geldig (controleer @ en .'s)";
		return false;
	}
	var user=matchArray[1] ;
	var domain=matchArray[2] ;
	// See if "user" is valid
	var userPat=new RegExp(validChars,"i");
	if (user.match(userPat)!=null) {// user is not valid
		emailErr = "Het ingevoerde emailadres is niet geldig! (controleer het gebruikersnaam gedeelte)";
		return false;
	}
	//.for @ is not falid
	if (emailStr.match(".@")==".@") {
		emailErr = "Het ingevoerde emailadres is niet geldig! (controleer het gebruikersnaam gedeelte)";
		return false;
	}
	var IPArray=domain.match(ipDomainPat) ;
	if (IPArray!=null) {// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				emailErr = "Het ingevoerde emailadres is niet geldig!";
				return false;
			}
		}
		return true;
	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat) ;
	if (domainArray==null) {
		emailErr = "Het ingevoerde emailadres is niet geldig! (controleer het domein)";
		return false;
	}

	var atomPat=new RegExp(atom,"g") ;
	var domArr=domain.match(atomPat) ;
	var len=domArr.length ;
	if (domArr[domArr.length-1].length<2 ||
		domArr[domArr.length-1].length>3) { // the address must end in a two letter or three letter word.
		emailErr = "Het ingevoerde emailadres is niet geldig!";
	   return false;
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
		emailErr = "Het ingevoerde emailadres is niet geldig!";
   		return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
	//  End -->
}

function submitFrmLogin() {
	if (xhrSent) {
		alert(xhrSentAlertMessage);
	} else {
		disableCloseButton(true);
		dojo.xhrPost({
			url: '/ajax/secure/login.asp',
			handleAs: "json",
			load: fXhrCallBack,
			error: fXhrError,
			form: "frmLogin",
			timeout: 5000
		});
		xhrSent = true;
	}
}
function submitAjaxLogin() {
	if (xhrSent) {
		alert(xhrSentAlertMessage);
	} else {
		disableCloseButton(true);
		dojo.xhrPost({
			url: '/ajax/secure/login.asp',
			handleAs: "json",
			load: fXhrCallBack,
			error: fXhrError,
			form: "frmLoginDialog",
			timeout: 5000
		});
		xhrSent = true;
	}
}
function submitAjaxForgotLogin() {
	if (xhrSent) {
		alert(xhrSentAlertMessage);
	} else {
		disableCloseButton(true);
		dojo.xhrPost({
			url: '/ajax/secure/forgotlogin.asp',
			handleAs: "json",
			load: fXhrCallBack,
			error: fXhrError,
			form: "frmForgotLoginDialog",
			timeout: 5000
		});
		xhrSent = true;
	}
}
function fCheckFrmLogin() {
	var checkRulez = {
		"fields": [
			{"id": "vovUsername", "required": true, "type": "text", "message": "Gebruikersnaam (minimaal 3 karakters)", "minlength": 3},
			{"id": "vovPassword", "required": true, "type": "text", "message": "Wachtwoord (minimaal 4 karakters)", "minlength": 4}
		],
		"messageBefore": "Om te kunnen inloggen moeten eerst alle onderstaande velden juist worden ingevuld!",
		"messageAfter" : "",
		"title": "Inloggen niet mogelijk!"
	};
	var result = fCheckForm(checkRulez);
	fXhrCheckHTML(result);
	if (result.status != "ok"){
		showDialog(result.response.id, result)
	} else {
		getDialog('waitDialog', 'callstackAfter=submitFrmLogin|250')
	}
}
function fCheckAjaxLogin() {
	var checkRulez = {
		"fields": [
			{"id": "ajaxVovUsername", "required": true, "type": "text", "message": "Gebruikersnaam (minimaal 3 karakters)", "minlength": 3},
			{"id": "ajaxVovPassword", "required": true, "type": "text", "message": "Wachtwoord (minimaal 4 karakters)", "minlength": 4}
		],
		"messageBefore": "Om te kunnen inloggen moeten eerst alle onderstaande velden juist worden ingevuld!",
		"messageAfter" : "",
		"title": "Inloggen niet mogelijk!"
	};
	var result = fCheckForm(checkRulez);
	fXhrCheckHTML(result);
	if (result.status != "ok"){
		showDialog(result.response.id, result)
	} else {
		getDialog('waitDialog', 'callstackAfter=submitAjaxLogin|250')
	}
}
function fCheckAjaxForgotLogin() {
	var checkRulez = {
		"fields": [
			{"id": "ajaxVovForgotEmail", "required": true, "type": "email"}
		],
		"messageBefore": "Om de logingegevens nogmaals te kunnen verzenden moet een geldig emailadres worden ingevuld!",
		"messageAfter" : "",
		"title": "Versturen niet mogelijk!"
	};

	var result = fCheckForm(checkRulez);
	fXhrCheckHTML(result);
	if (result.status != "ok"){
		showDialog(result.response.id, result)
	} else {
		getDialog('waitDialog', 'callstackAfter=submitAjaxForgotLogin|250')
	}
}
function getDialog(dialogID, sParams) {
	if ($(dialogID)!=null) {
		showDialog(dialogID);
	} else {
		if (xhrSent) {
			alert(xhrSentAlertMessage);
		} else {
			var sExtraParams = "";
			if (typeof sParams != 'undefined') {sExtraParams = "&"+sParams;}
			disableCloseButton(true);
			dojo.xhrGet({
				url: '/ajax/dialog/get.asp?ID='+dialogID+sExtraParams,
				handleAs: "json",
				load: fXhrCallBack,
				error: fXhrError,
				timeout: 5000
			});
			xhrSent = true;
		}
	}
}
function fCheckForm(varRulez) {
	var message = "";
	var arrErrors = new Array();
	var arrOKs = new Array();
	var minlength = null;
	var returnData = {};
	var errorStyle = {"backgroundImage": "url('/img/cross.gif')", "backgroundRepeat": "no-repeat", "backgroundPosition": "right", "paddingPight": "18px"};
	var okStyle = {"backgroundImage": "url('/img/check.gif')", "backgroundRepeat": "no-repeat", "backgroundPosition": "right", "paddingPight": "18px"};
	for (var i=0;i<=varRulez.fields.length-1;i++) {
		if (varRulez.fields[i].required) {
			if ($(varRulez.fields[i].id)==null) {				
				if (typeof varRulez.fields[i].message != 'undefined') {
					message += "<li>"+varRulez.fields[i].message+" ontbreekt!</li>";
				}
				arrErrors.push(varRulez.fields[i].id);
			} else {				
				switch(varRulez.fields[i].type) {
					case 'text':
						minlength = (typeof varRulez.fields[i].minlength == 'undefined') ? 1 : varRulez.fields[i].minlength;
						if (trim($(varRulez.fields[i].id).value).length < minlength || trim($(varRulez.fields[i].id).value)=="Jouw naam:") {
							if (typeof varRulez.fields[i].message != 'undefined') {
								message += "<li>"+varRulez.fields[i].message+"</li>";
							}
							if (!$(varRulez.fields[i].id).disabled) {arrErrors.push(varRulez.fields[i].id);}
						} else {
							if (!$(varRulez.fields[i].id).disabled) {arrOKs.push(varRulez.fields[i].id);}
						}
						break;
					case 'email':
						if (!isValidEmail(trim($(varRulez.fields[i].id).value))) {							
							if (typeof varRulez.fields[i].message != 'undefined') {
								message += "<li>"+varRulez.fields[i].message+"</li>";
							}
							if (!$(varRulez.fields[i].id).disabled) {arrErrors.push(varRulez.fields[i].id);}
						} else {
							if (!$(varRulez.fields[i].id).disabled) {arrOKs.push(varRulez.fields[i].id);}
						}
						break;
				}
			}
			if (arrErrors.length == 1 && xhrMustFocusID == null) {xhrMustFocusID = varRulez.fields[i].id;}
		}
	}
	if (arrErrors.length>0) {
		if (message!="") {
			message = varRulez.messageBefore+"<ul>"+message+"</ul>"+varRulez.messageAfter;
		} else {
			message = varRulez.messageBefore+varRulez.messageAfter;
		}
		returnData.status = "errors";
		returnData.response = {};
		returnData.response.id = createDialogID();
		if (typeof varRulez.title != 'undefined') {
			returnData.response.title = "<span class=\"red\">"+varRulez.title+"</span>";
		} else {
			returnData.response.title = null;
		}
		returnData.response.message = message;
		returnData.response.buttons = null;
		returnData.response.width = null;
//		returnData.html = [];
//		for(var i=0;i<=arrErrors.length-1;i++) {
//			returnData.html.push({"id": arrErrors[i], "style": errorStyle});
//		}
//		for(var i=0;i<=arrOKs.length-1;i++) {
//			returnData.html.push({"id": arrOKs[i], "style": okStyle});
//		}
	} else {
		returnData.status = "ok";
//		returnData.html = [];
//		for(var i=0;i<=arrOKs.length-1;i++) {
//			returnData.html.push({"id": arrOKs[i], "style": okStyle});
//		}
	}
	return returnData;
}

function DisablePopVars() {
	if ($(currPopID+"_butOK") != null){$(currPopID+"_butOK").disabled=true;}
	if ($(currPopID+"_butCancel") != null){$(currPopID+"_butCancel").disabled=true;}
	showProgressBar(true);
	disableCloseButton(true);
}
function EnablePopVars() {
	if ($(currPopID+"_butOK") != null){$(currPopID+"_butOK").disabled=false;}
	if ($(currPopID+"_butCancel") != null){$(currPopID+"_butCancel").disabled=false;}
	showProgressBar(false);
	disableCloseButton(false);
}
function disableCloseButton(blnValue) {
	if (blnValue) {
		if ($(currPopID+"_closeButton") != null){$(currPopID+"_closeButton").className = "disabled";}
	} else {
		if ($(currPopID+"_closeButton") != null){$(currPopID+"_closeButton").className = "";}
	}
}
function showProgressBar(blnValue) {
	if (blnValue) {
		if ($(currPopID+"_i_Prg") != null){$(currPopID+"_i_Prg").style.display="block";}
	} else {
		if ($(currPopID+"_i_Prg") != null){$(currPopID+"_i_Prg").style.display="none";}
	}
}
function addEvent(obj, evType, fn){
	if (obj.addEventListener){
    	obj.addEventListener(evType, fn, true);
	    return true;
	} else if (obj.attachEvent){
    	var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
    	return false;
	}
}
function removeEvent(obj, evType, fn, useCapture){
  	if (obj.removeEventListener){
    	obj.removeEventListener(evType, fn, useCapture);
    	return true;
  	} else if (obj.detachEvent){
   		var r = obj.detachEvent("on"+evType, fn);
    	return r;
  	}
}
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight;
	return window.undefined;
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;
	if (document.body) return document.body.clientWidth;
	return window.undefined;
}
function centerPopWin() {
	if(currPopID==null){return};
	var objOverlay = $("c_cW_O");
	for(var iCenter=popWindows.length-1;iCenter>=0;iCenter--) {
		var objPopWin = $(popWindows[iCenter]);
		if (objPopWin!=null) {
			if (objPopWin.style.display == "block") {
				var width = objPopWin.offsetWidth;
				var height = objPopWin.offsetHeight;
				var fullHeight = getViewportHeight();
				var fullWidth = getViewportWidth();
				var scTop = parseInt(document.documentElement.scrollTop == 0 ? document.body.scrollTop : document.documentElement.scrollTop ,10);
				var scLeft = parseInt(document.documentElement.scrollLeft == 0 ? document.body.scrollLeft : document.documentElement.scrollLeft ,10);
				if (objOverlay != null) {
					if (document.body.clientHeight < 30) {
						objOverlay.style.height = ((fullHeight - 19) - scTop) + "px";
					}
					else {
						objOverlay.style.height = fullHeight + "px";
					}
					objOverlay.style.width = (document.body.clientWidth + 14) + "px";
					objOverlay.style.top = scTop + 'px';
					objOverlay.style.left = 0;
				}
				objPopWin.style.top = (scTop + ((fullHeight - (height)) / 4)) + "px";
				objPopWin.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
			}
		}
	}
}
function hideOnTopControls() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
	if ($("banner468x60") != null) {$("banner468x60").style.visibility="hidden";}
	if ($("banner120x600") != null) {$("banner120x600").style.visibility="hidden";}
	if ($("banner234x60") != null) {$("banner234x60").style.visibility="hidden";}
}
function displayOnTopControls() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
	if ($("banner468x60") != null) {$("banner468x60").style.visibility="visible";}
	if ($("banner120x600") != null) {$("banner120x600").style.visibility="visible";}
	if ($("banner234x60") != null) {$("banner234x60").style.visibility="visible";}
}
function fillDialog(dialogID, data) {
	var sCloseFunction = "hidePopWin";
	if (typeof data.response.type != 'undefined'){if(data.response.type == "error") {sCloseFunction = "hideAllPopWins";}}
	if ($(dialogID)==null) {
		var objBody = document.getElementsByTagName("body");
		if (objBody.length>0) {
			var cDialog = document.createElement("div");
			cDialog.setAttribute("id",dialogID);
			cDialog.setAttribute("class","dialog");
			cDialog.setAttribute("oncontextmenu","return false");
			cDialog.setAttribute("ondragstart","return false");
			cDialog.innerHTML = '<div class="L" id="'+dialogID+'_l"><img src="/img/kutcom_logo_small.png" border="0" style="float:left; margin-bottom: 8px;" id="'+dialogID+'_logo"><a href="javascript:;" id="'+dialogID+'_closeButton" class="" onClick="if(this.className!=\'disabled\'){'+sCloseFunction+'();};return false;" onFocus="this.blur();"></a></div><div class="H" id="'+dialogID+'_h"></div><div class="M" id="'+dialogID+'_m"></div><div class="B" id="'+dialogID+'_b"></div>';
			objBody[0].appendChild(cDialog);
			$(dialogID).className = "dialog";
		}
	}
	$(dialogID+'_h').innerHTML = data.response.title!=null ? data.response.title : $(dialogID+'_h').innerHTML;
	$(dialogID+'_m').innerHTML = data.response.message!=null ? data.response.message : $(dialogID+'_m').innerHTML;
	$(dialogID+'_b').innerHTML = data.response.buttons!=null ? data.response.buttons : "<input type=\"button\" name=\"butOK\" id=\""+dialogID+"_butOK\" value=\"OK\" class=\"button\" onClick=\""+sCloseFunction+"();\" />";
	$(dialogID).style.width  = data.response.width!=null ? data.response.width : $(dialogID).style.width;
	if ($(dialogID+'_h').innerHTML == "") {$(dialogID+'_h').style.display = "none";}
	if ($(dialogID+'_b').innerHTML == "") {$(dialogID+'_b').style.display = "none";}
	if (typeof data.response.type != 'undefined'){
		if(data.response.type == "error") {
			$(dialogID+'_h').className = "HError";
			$(dialogID+'_m').className = "MError";
		}
	}
}
function createDialogID() {
	return "dialog"+Math.floor(Math.random()*1000000000000000);
}
function saveJsonData(DialogID, jsonData) {
	var blnExists = false;
	var jsWindow = {}
	jsWindow.id = DialogID;
	jsWindow.json = jsonData;
	for (var i=0;i<=jsonWindows.length-1;i++) {
		if (jsonWindows[i].id == DialogID) {
			blnExists = true;
			jsonWindows[i] = jsWindow;
			break;
		}
	}
	if (!blnExists) {jsonWindows.push(jsWindow);}
}
function getJsonData(DialogID) {
	for (var i=0;i<=jsonWindows.length-1;i++) {
		if (jsonWindows[i].id == DialogID) {
			return jsonWindows[i].json;
		}
	}
	return 'undefined';
}
function showDialog(DialogID, jsonData) {
	if($(DialogID)==null) {fillDialog(DialogID, jsonData);}
	if($(DialogID)!=null) {
		if(typeof jsonData != 'undefined') {saveJsonData(DialogID, jsonData);}
		popWindows.push(DialogID);
		currPopID = DialogID;
		hideOnTopControls();
		if($('mainContent')!=null) {$('mainContent').style.overflow='hidden';}
		$(currPopID).style.display='block';
		$(currPopID).style.zIndex = 10 + (popWindows.length * 2) + 1;
		$("c_cW_O").style.display = "block";
		$("c_cW_O").style.zIndex = 10 + (popWindows.length * 2);
		EnablePopVars();
		centerPopWin();
		jsonData = getJsonData(currPopID)
		if (jsonData != 'undefined') {
			if (typeof jsonData.form != 'undefined') {
				fXhrFocusAnalyzer(jsonData);
			} else {
				if ($(currPopID+"_butOK")) {try{$(currPopID+"_butOK").focus();}catch(e){}}
			}
		} else {
			if ($(currPopID+"_butOK")) {try{$(currPopID+"_butOK").focus();}catch(e){}}
		}
	}
}
function lastWindowHidden() {
	displayOnTopControls();
	if($('mainContent')!=null) {$('mainContent').style.overflow='visible';}
	currPopID = null;
	//getFormToFocus();
}
function getFormToFocus() {
	if (xhrMustFocusID != null && $(xhrMustFocusID)!=null) {
		try {$(xhrMustFocusID).focus();$(xhrMustFocusID).select();} catch(e) {}
		xhrMustFocusID = null;
	} else {
		if (xhrFocusID != null && $(xhrFocusID)!=null) {
			try {$(xhrFocusID).focus();} catch(e) {};
		} else {
			objForms = document.getElementsByTagName("FORM");
			if (objForms.length > 0) {				
				if(typeof objForms[0].name != 'undefined'){					
					fXhrFocusAnalyzer({"form": objForms[0].name});
				}
			}
		}
	}
}
function hideAllPopWins() {
	for(var iHide = popWindows.length-1;iHide>=0;iHide--) {
		hidePopWin(true);
	}
}
function hidePopWin(blnSkipFocusCheck) {
	if($(currPopID)==null){return};	
	popWindows.pop();
	if (popWindows.length == 0) {	
		$(currPopID).style.display='none';
		$("c_cW_O").style.display = "none";
		lastWindowHidden();
	} else {		
		$(currPopID).style.display='none';
		$("c_cW_O").style.zIndex = 10 + (popWindows.length * 2);
		currPopID = popWindows[popWindows.length-1];		
		var blnDoFocusCheck = true;
			
		if (typeof blnSkipFocusCheck != 'undefined') {blnDoFocusCheck = !blnSkipFocusCheck;}
		if (blnDoFocusCheck) {
			jsonData = getJsonData(currPopID)
			if (jsonData != 'undefined') {
				if (typeof jsonData.form != 'undefined') {
					fXhrFocusAnalyzer(jsonData);
				} else {
					if ($(currPopID+"_butOK")) {try{$(currPopID+"_butOK").focus();}catch(e){}}
				}
			} else {
				if ($(currPopID+"_butOK")) {try{$(currPopID+"_butOK").focus();}catch(e){}}
			}
		}
	}
}
function pageInit() {
	//getFormToFocus();
}
addEvent(window, "resize", centerPopWin);
addEvent(window, "load", pageInit);
window.onscroll = centerPopWin;

