var modelessPopup;
var nowOpen			=null;
var nowOpenStatus	=null;
var ttype=null;
function openNode(num,normal,t)
{
	focusNode(num);
	if(nowOpen==num){
		document.all("img"+num).src="images/close_"+nowOpenStatus+".gif";
		document.all("div"+num).style.display="none";
		nowOpen			=null;
		nowOpenStatus	=null;
		return;
	}
	if(nowOpen!=null){
		document.all("img"+nowOpen).src="images/close_"+nowOpenStatus+".gif";
		document.all("div"+nowOpen).style.display="none";			
	}
	document.all("img"+num).src="images/open_"+normal+".gif";
	document.all("div"+num).style.display="inline";
	nowOpen			=num;
	nowOpenStatus	=normal;
	if(document.all("div"+num).innerHTML==""){
		document.all("div"+num).innerHTML="<img align='absmiddle' src='images/line_v.gif'><b class='blank'></b><img align='absmiddle' src='images/none_end.gif'><font color=red style='font-size:9pt'> Loading...</font><br>";
	}
	
}

var nowFocus=null;
function SetRichLink(obj){
	try{
		obj.style.borderWidth="1px";
		obj.style.borderStyle="solid";
		obj.style.borderColor="#efefef";
		obj.style.backgroundColor="silver";
		obj.blur();
	}catch(e){}
}
function ClearRichLink(obj){
	try{
		obj.style.borderWidth="0px";
		obj.style.backgroundColor="";
	}catch(e){}
}
function focusNode(num)
{
	if(document.all("link"+nowFocus))
	{
		ClearRichLink(document.all("link"+nowFocus));
	}
	nowFocus=num;
	SetRichLink(document.all("link"+num));
}	

function popup(url,width,height)
{
	var centered;
	x = (screen.availWidth - width) / 2;
	y = (screen.availHeight - height) / 2;
	centered =',width=' + width + ',height=' + height + ',left=' + x + ',top=' + y + ',scrollbars=yes,resizable=yes,status=yes';
	var popup = window.open(url, '_blank', centered);
    	if (!popup.opener) popup.opener = self;
	popup.focus();
}

function showModelessPopup(url, width, height)
{
	var centered;
	x = (screen.availWidth - width) / 2;
	y = (screen.availHeight - height) / 2;
	centered =',width=' + width + ',height=' + height + ',left=' + x + ',top=' + y + ',scrollbars=no,resizable=no,status=no';
	modelessPopup = window.open(url, 'modelessPopup', centered);
	
	window.onfocus=focusModelessPopup;
	
    if (!modelessPopup.opener) modelessPopup.opener = self;    
	modelessPopup.focus();
}

 function focusModelessPopup()
 {
  	if(eval(modelessPopup))
  	{
  		modelessPopup.focus();
  	}
  }

function confirm_action(url, message)
{
	if (confirm(message))
	{
		window.location=url
	}
}

function get_object(name)
{
	if (document.getElementById)
	{
		return document.getElementById(name);
 	}
 	else if (document.all)
	{
  		return document.all[name];
 	}
 	else if (document.layers)
	{
  		return document.layers[name];
	}
	return false;
}

function check_checkbox(id)
{
	if(check_box = get_object(id))
	{
		if (!check_box.disabled)
		{
			check_box.checked = !check_box.checked;
			if (check_box.onclick)
			{
				check_box.onclick();
			}
		}
	}
}

function select_radio(id)
{
	if(radio_but = get_object(id))
	{
		radio_but.checked = true;
		if (radio_but.onclick)
		{
			radio_but.onclick();
		}
	}
}


function getSelected(opt) 
{
	var selected = new Array();
	var index = 0;
	for (var i=0; i<opt.length;i++) 
	{
		if ((opt[i].selected) || (opt[i].checked)) 
		{
			index = selected.length;
			selected[index] = new Object;
			selected[index].value = opt[i].value;
			selected[index].index = i;
		}
	}
	return selected;
}


function copy_clip(copytext)
{

 	 if (window.clipboardData) 
   {
   
   // the IE-manier
   window.clipboardData.setData("Text", copytext);
   
   // waarschijnlijk niet de beste manier om Moz/NS te detecteren;
   // het is mij echter onbekend vanaf welke versie dit precies werkt:
   }
   else if (window.netscape) 
   { 
   
   // dit is belangrijk maar staat nergens duidelijk vermeld:
   // you have to sign the code to enable this, or see notes below 
   netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
   
   // maak een interface naar het clipboard
   var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
   if (!clip) return;
   
   // maak een transferable
   var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
   if (!trans) return;
   
   // specificeer wat voor soort data we op willen halen; text in dit geval
   trans.addDataFlavor('text/unicode');
   
   // om de data uit de transferable te halen hebben we 2 nieuwe objecten nodig   om het in op te slaan
   var str = new Object();
   var len = new Object();
   
   var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
   
   var copytext=copytext;
   
   str.data=copytext;
   
   trans.setTransferData("text/unicode",str,copytext.length*2);
   
   var clipid=Components.interfaces.nsIClipboard;
   
   if (!clip) return false;
   
   clip.setData(trans,null,clipid.kGlobalClipboard);
   
   }
   return false;
}

//Password enhanced
function PasswordStrength(showed){	
	this.showed = (typeof(showed) == "boolean")?showed:true;
	this.styles = new Array();	
	this.styles[0] = {backgroundColor:"#EBEBEB",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BEBEBE",borderBottom:"solid 1px #BEBEBE"};	
	this.styles[1] = {backgroundColor:"#FF4545",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #BB2B2B",borderBottom:"solid 1px #BB2B2B"};
	this.styles[2] = {backgroundColor:"#FFD35E",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #E9AE10",borderBottom:"solid 1px #E9AE10"};
	this.styles[3] = {backgroundColor:"#95EB81",borderLeft:"solid 1px #FFFFFF",borderRight:"solid 1px #3BBC1B",borderBottom:"solid 1px #3BBC1B"};
	
	this.labels= ["Low","Middle","Strong"];

	this.divName = "pwd_div_"+Math.ceil(Math.random()*100000);
	this.minLen = 5;
	
	this.width = "150px";
	this.height = "16px";
	
	this.content = "";
	
	this.selectedIndex = 0;
	
	this.init();	
}
PasswordStrength.prototype.init = function(){
	var s = '<table cellpadding="0" id="'+this.divName+'_table" cellspacing="0" style="width:'+this.width+';height:'+this.height+';">';
	s += '<tr>';
	for(var i=0;i<3;i++){
		s += '<td id="'+this.divName+'_td_'+i+'" width="33%" align="center"><span style="font-size:1px">&nbsp;</span><span id="'+this.divName+'_label_'+i+'" style="display:none;font-family: Courier New, Courier, mono;font-size: 12px;color: #000000;">'+this.labels[i]+'</span></td>';
	}	
	s += '</tr>';
	s += '</table>';
	this.content = s;
	if(this.showed){
		document.write(s);
		this.copyToStyle(this.selectedIndex);
	}	
}
PasswordStrength.prototype.copyToObject = function(o1,o2){
	for(var i in o1){
		o2[i] = o1[i];
	}
}
PasswordStrength.prototype.copyToStyle = function(id){
	this.selectedIndex = id;
	for(var i=0;i<3;i++){
		if(i == id-1){
			this.$(this.divName+"_label_"+i).style.display = "inline";
		}else{
			this.$(this.divName+"_label_"+i).style.display = "none";
		}
	}
	for(var i=0;i<id;i++){
		this.copyToObject(this.styles[id],this.$(this.divName+"_td_"+i).style);			
	}
	for(;i<3;i++){
		this.copyToObject(this.styles[0],this.$(this.divName+"_td_"+i).style);
	}
}
PasswordStrength.prototype.$ = function(s){
	return document.getElementById(s);
}
PasswordStrength.prototype.setSize = function(w,h){
	this.width = w;
	this.height = h;
}
PasswordStrength.prototype.setMinLength = function(n){
	if(isNaN(n)){
		return ;
	}
	n = Number(n);
	if(n>1){
		this.minLength = n;
	}
}
PasswordStrength.prototype.setStyles = function(){
	if(arguments.length == 0){
		return ;
	}
	for(var i=0;i<arguments.length && i < 4;i++){
		this.styles[i] = arguments[i];
	}
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.write = function(s){
	if(this.showed){
		return ;
	}
	var n = (s == 'string') ? this.$(s) : s;
	if(typeof(n) != "object"){
		return ;
	}
	n.innerHTML = this.content;
	this.copyToStyle(this.selectedIndex);
}
PasswordStrength.prototype.update = function(s){
	if(s.length < this.minLen){
		this.copyToStyle(0);
		return;
	}
	var ls = -1;
	if (s.match(/[a-z]/ig)){
		ls++;
	}
	if (s.match(/[0-9]/ig)){
		ls++;
	}
 	if (s.match(/(.[^a-z0-9])/ig)){
		ls++;
	}
	if (s.length < 6 && ls > 0){
		ls--;
	}
	 switch(ls) { 
		 case 0:
			 this.copyToStyle(1);
			 break;
		 case 1:
			 this.copyToStyle(2);
			 break;
		 case 2:
			 this.copyToStyle(3);
			 break;
		 default:
			 this.copyToStyle(0);
	 }
}