function selectSubmit(form) {
	var el = document.getElementById(form);
	el.submit();
}

function popUp(URL, left, top) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=795,height=200,left = " + left + ",top = " + top + "');");
	window.status = "view profile";
}

function popUpDateHelp(URL, left, top) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=795,height=200,left = " + left + ",top = " + top + "');");
	window.status = "view profile";
}

function analysePassword(passField, outputID) {
   var pass = document.getElementById(passField).value;
   var strLevel = 0; //alert(strLevel);
   strLevel += parseInt(analyseLowerCase(pass)); //alert(strLevel);
   strLevel += parseInt(analyseNumbers(pass)); //alert(strLevel);
   strLevel += parseInt(analyseUpperCase(pass)); //alert(strLevel);
   strLevel += parseInt(analyseCharacters(pass)); //alert(strLevel);
   strLevel += parseInt(analyseLength(pass)); //alert(strLevel);

   //alert(strLevel);
   var colorValue = getColorValue(strLevel);

   var output = document.getElementById(outputID);
   output.innerHTML = " Password Strength Meter <div style='background: "+colorValue+"; width: "+strLevel+"px; display: block; text-align: center;'>"+strLevel+"%</div>";
}

function analyseUpperCase(pass) {
   for (i = 0; i < pass.length; i++) {

       if(pass.charCodeAt(i) >= 65 && pass.charCodeAt(i) <= 90 ) {
           return 20;
       }

   }
   return 0;
}

function analyseNumbers(pass) {
   for (i = 0; i < pass.length; i++) {

       if(pass.charCodeAt(i) >= 48 && pass.charCodeAt(i) <= 57 ) {
           return 20;
       }

   }
   return 0;
}

function analyseLowerCase(pass) {
   for (i = 0; i < pass.length; i++) {

       if(pass.charCodeAt(i) >= 97 && pass.charCodeAt(i) <= 122 ) {
           return 10;
       }

   }
   return 0;
}

function analyseCharacters(pass) {
   for (i = 0; i < pass.length; i++) {

       if( ( pass.charCodeAt(i) >= 33 && pass.charCodeAt(i) <= 48 )
           || (  pass.charCodeAt(i) >= 123 )
           || ( pass.charCodeAt(i) >= 58 && pass.charCodeAt(i) <= 64 ) ){
           return 40;
       }

   }
   return 0;
}

function analyseLength(pass) {
   if (pass.length >= 8) {
       return 10;
   } else {
       return 0;
   }
}

function getColorValue(level) {

   if (level >= 70) {
       return '#0f0';
   } else if (level > 30) {
       return '#ff0';
   } else {
       return '#f00';
   }
}

function comparePasswords(p, p2, out) {
	var pass = document.getElementById(p).value;
	var pass2 = document.getElementById(p2).value;

	var passPortion = pass.substring(0,pass2.length);


	if (pass2 == "") {
		document.getElementById(out).innerHTML = "";
	} else if (passPortion != pass2)  {
		document.getElementById(out).innerHTML = "<span style='font-weight: bold; color: #f00;'>Passwords do not match</span>";
	} else {
		document.getElementById(out).innerHTML = "";//"<span style='font-weight: bold; color: #0f0;'>Passwords match</span>";
	}
}

