// JavaScript Document

	function HideContent(d) {
		if(d.length < 1) { return; }
		document.getElementById(d).style.visibility = "hidden";
	}
	function ShowContent(d) {
		if(d.length < 1) { return; }
		document.getElementById(d).style.visibility = "visible";
	}
	function ShowOverflow(d) {
		if(d.length < 1) { return; }
		document.getElementById(d).style.overflow = "visible";
		document.getElementById('more').style.visibility = "hidden";
		document.getElementById('less').style.visibility = "visible";
	}
	function HideOverflow(d) {
		if(d.length < 1) { return; }
		document.getElementById(d).style.overflow = "hidden";
		document.getElementById('less').style.visibility = "hidden";
		document.getElementById('more').style.visibility = "visible";
	}
	// clear field of any default text
	function doClear(theText) {
		 if (theText.value == theText.defaultValue) {
			 theText.value = ""
		 }
	}
	// submit on enter
	function submitenter(myfield,e){
		var keycode;
		if (window.event) keycode = window.event.keyCode;
		else if (e) keycode = e.which;
		else return true;
	
		if (keycode == 13) {
		   myfield.form.submit();
		   return false;
		} else
		   return true;
	}
	function dss_addLoadEvent(fn) {
		if(typeof(fn)!="function")return;
		var tempFunc=window.onload;
		window.onload=function() {
		if(typeof(tempFunc)=="function")tempFunc();
			fn();
		}
	}
	function changeInputType(
	oldElm, // a reference to the input element
	iType, // value of the type property: 'text' or 'password'
	iValue, // the default value, set to 'password' in the demo
	blankValue, // true if the value should be empty, false otherwise
	noFocus) {  // set to true if the element should not be given focus
		if(!oldElm || !oldElm.parentNode || (iType.length<4) || 
		!document.getElementById || !document.createElement) return;
		var newElm = document.createElement('input');
		newElm.type = iType;
		if(oldElm.name) newElm.name = oldElm.name;
		if(oldElm.id) newElm.id = oldElm.id;
		if(oldElm.className) newElm.className = oldElm.className;
		if(oldElm.size) newElm.size = oldElm.size;
		if(oldElm.tabIndex) newElm.tabIndex = oldElm.tabIndex;
		if(oldElm.accessKey) newElm.accessKey = oldElm.accessKey;
		newElm.onfocus = function(){return function(){
			if(this.hasFocus) return;
			var newElm = changeInputType(this,'password',iValue,
			(this.value.toLowerCase()==iValue.toLowerCase())?true:false);
			if(newElm) newElm.hasFocus=true;
		}}();
		newElm.onblur = function(){return function(){
			if(this.hasFocus)
			if(this.value=='' || (this.value.toLowerCase()==iValue.toLowerCase())) {
				changeInputType(this,'text',iValue,false,true);
			}
		}}();
		// hasFocus is to prevent a loop where onfocus is triggered over and over again
		newElm.hasFocus=false;
		oldElm.parentNode.replaceChild(newElm,oldElm);
		if(!blankValue) newElm.value = iValue;
		if(!noFocus || typeof(noFocus)=='undefined') {
			window.tempElm = newElm;
			setTimeout("tempElm.hasFocus=true;tempElm.focus();",1);
		}
		return newElm;
	}
	dss_addLoadEvent(function(){
	var ua = navigator.userAgent.toLowerCase();
	if(!((ua.indexOf('konqueror')!=-1) && (document.all || 
	(ua.indexOf('khtml/3.4')!=-1))) && !(((ua.indexOf('safari')!=-1) && 
	!window.print) || (document.defaultCharset && !window.print))) {
		// Set the third value to the text you want to appear in the field.
		changeInputType(document.forms[0].password,'text','enter password',false,true);
	}
	});
	// adds confirmation to actions like delete or status changes
	function affirm(q,m,m2,to) {
		var answer = confirm(q)
		if (answer){
			alert(m)
			window.location = to;
		}
		else{
			alert(m2)
		}
	}

	function popUp(URL) {
		day = new Date();
		id = day.getTime();
		eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=700,left = 340,top = 162');");
	}
	
	// some javascript to hide emails using class: change
	function mangle() {
		var at = / at /;
		var dot = / dot /g;
		var address = this.getAttribute("title");
	
		address = address.replace(at, "@");
		address = address.replace(dot, ".");
	
		this.innerHTML = address;
		this.setAttribute("href", "mailto:"+address);
		this.setAttribute("title", "");
		this.onmouseover = null;
	}
	
	function fixLinks() {
		if (!document.getElementsByTagName && !document.createElement &&
			!document.createTextNode) return;
		var nodes = document.getElementsByTagName("*");
		for(var i=nodes.length-1;i>=0;i--) {
			if (nodes[i].className.search("change")>=0) {
				var node = document.createElement("a");
				node.setAttribute("href", "mailto:");
				node.setAttribute("title", nodes[i].innerHTML);
				node.innerHTML = nodes[i].innerHTML;
				node.onmouseover = mangle;
	
				var prnt = nodes[i].parentNode;
				for(var j=0;j<prnt.childNodes.length;j++)
					if (prnt.childNodes[j] == nodes[i]) {
						if (!prnt.replaceChild) return;
						prnt.replaceChild(node, prnt.childNodes[j]);
						break;
					}
			}
		}
	}
	// Dreamweaver JS
	function MM_swapImgRestore() { //v3.0
	  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}
	
	function MM_preloadImages() { //v3.0
	  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
		var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}
	
	function MM_findObj(n, d) { //v4.01
	  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
	  if(!x && d.getElementById) x=d.getElementById(n); return x;
	}
	
	function MM_swapImage() { //v3.0
	  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
	   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}
	
	function PassStrengthMeter(passwd,minpasslength) {
		var description = new Array();
		description[0] = "<table><tr><td>Password Strength: </td><td><b>Too Short</b></td><tr><td colspan=2><table cellpadding=0 cellspacing=2><tr><td height=4 width=200 bgcolor=#cccccc></td></tr></table></td></tr></table>";
		description[1] = "<table><tr><td>Password Strength: </td><td><b>Weak</b></td><tr><td colspan=2><table cellpadding=0 cellspacing=2><tr><td height=4 width=50 bgcolor=orange></td><td height=4 width=150 bgcolor=tan></td></tr></table></td></tr></table>";
		description[2] = "<table><tr><td>Password Strength: </td><td><b>Fair</b></td><tr><td colspan=2><table cellpadding=0 cellspacing=2><tr><td height=4 width=100 bgcolor=orange></td><td height=4 width=100 bgcolor=tan></td></tr></table></td></tr></table>";
		description[3] = "<table><tr><td>Password Strength: </td><td><b>Strong</b></td><tr><td colspan=2><table cellpadding=0 cellspacing=2><tr><td height=4 width=150 bgcolor=green></td><td height=4 width=50 bgcolor=tan></td></tr></table></td></tr></table>";
		description[4] = "<table><tr><td>Password Strength: </td><td><b>Strongest</b></td><tr><td colspan=2><table><tr><td height=4 width=200 bgcolor=green></td></tr></table></td></tr></table>";
		description[5] = "<table><tr><td>Password Strength: </td><td><b>Too Short</b></td><tr><td colspan=2><table cellpadding=0 cellspacing=2><tr><td height=4 width=200 bgcolor=#cccccc></td></tr></table></td></tr></table>";
		
		var intScore   = 0
		var strVerdict = 0
		
		// PASSWORD LENGTH
		if (passwd.length<minpasslength || !passwd.length) // length 0
		{
			intScore = -1
		}
		else if (passwd.length>5 && passwd.length<8) // length between 6 and 7
		{
			intScore = (intScore+6)
		}
		else if (passwd.length>7 && passwd.length<12)// length between 8 and 15
		{
			intScore = (intScore+12)
		}
		else if (passwd.length>11)                    // length 16 or more
		{
			intScore = (intScore+18)
		}
		// LETTERS 
		if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
		{
			intScore = (intScore+1)
		}
		if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
		{
			intScore = (intScore+5)
		}
		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5)
		}
		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5)
		}														 
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))  // [verified] at least two special characters
		{
			intScore = (intScore+5)
		}
		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2)
		}
		if (passwd.match(/(\d.*\D)|(\D.*\d)/))                    // [FAILED] both letters and numbers, almost works because an additional character is required
		{
			intScore = (intScore+2)
		}				  
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))  // [verified] letters, numbers, and special characters
		{
			intScore = (intScore+2)
		}
		
		if (passwd.length<minpasslength || !passwd.length) // length 0
		{
			intScore = -1
		}
		
		if(intScore == -1)
		{
		   strVerdict = description[5];
		}
		else if(intScore > -1 && intScore < 16)
		{
		   strVerdict = description[1];
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = description[1];
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = description[2];
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = description[3];
		}
		else
		{
		   strVerdict = description[4];
		}
			
		document.getElementById("Prompt").innerHTML= (strVerdict);
		
	}
