// JavaScript Document
// ---------------------------------SUPPORT BULLETIN-----------------------------------------------------------------------
function openbulletin()	{
	newAlertBox("popup_bulletin");
}
function closeBulletinBox()	{
	document.getElementById('popup').style.display = 'none'; 
	document.getElementById('popup_bulletin').style.display = 'none'; 
} 
function support_bulletin(val)
{
	var emailArray = document.getElementById('bulletin_email').value.split(',');
	var i=0;
	var alerttxt = 'Please enter a valid Email ID.';
	if(isEmpty(document.getElementById('bulletin_email').value))	{
		alert('Please enter a valid Email ID.');
		return false;
	}
	var len = emailArray.length;
	var iscomma = false;
		for(i = 0; i < emailArray.length; i++)	{
		if((len-1) == i && isEmpty(emailArray[i]))	{
		iscomma = true;
		}
		else if(!isEmail(emailArray[i]))	{
			alert(alerttxt);
			return false;
		}
		alerttxt = 'Please enter valid Email IDs.';
		}
		if(iscomma)
		document.getElementById('bulletin_email').value = document.getElementById('bulletin_email').value.substring(0,document.getElementById('bulletin_email').value.lastIndexOf(","));
	
	var url="ajax_support_bulletin.php?bulletin_email="+document.getElementById('bulletin_email').value+"&type="+val;
	http=createRequestObject();
	http.onreadystatechange=Ajax_support_bulletin; 
	http.open("GET",url);
	http.send(null);
}
function Ajax_support_bulletin()	{
	if(http.readyState==4)	{
		var r=http.responseText;
		//document.getElementById("Loading_bulletin").style.display='none';
		document.getElementById("popup_bulletin").style.display='none';
		document.getElementById("popup").style.display='none';
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) 		{
			selects[i].style.visibility = 'visible';
		}
	}
	//document.getElementById("Loading_bulletin").style.display='block';
}
// ---------------------------------SUPPORT BULLETIN-----------------------------------------------------------------------

// ----------------------------------- Force Password --------------------------------------------
function change_password(){
var employee_addressid=global_employee_addressid;
var pass1=document.getElementById('new_password').value;
var pass2=document.getElementById('confirm_password').value;

//alert("New pswd="+pass1+"confirm pswd="+pass2+"emp addressid="+employee_addressid);
if(pass1==''){
alert('Please Enter New Password!');
return false;
}
else
if(pass2==''){
alert('Please Enter Confirm Password!');
return false;
}
else
if(pass2!=pass1){
alert('The confirmation password and New password are not identical!');
return false;
}
else
if(((pass1.length==pass2.length)&&(pass1.length<6))){
alert("Password length should be more than six characters");
return false;
}
var str_parameter="employeeid="+employee_addressid+"&NewPassword="+pass1;
makePOSTRequest_password('ajax_force_password.php',str_parameter);
}
  var http_request_new = false;
  var objid='';

   function makePOSTRequest_password(url, parameters) {
  // parameters = ReplaceAll("+",'@@@',parameters);
      http_request_new = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request_new = new XMLHttpRequest();
         if (http_request_new.overrideMimeType) {
            http_request_new.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request_new = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request_new = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request_new) {
         alert('Cannot create XMLHTTP instance');

         return false;
      }

      http_request_new.onreadystatechange = savePassword;
      http_request_new.open('POST', url, true);
      http_request_new.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request_new.setRequestHeader("Content-length", parameters.length);
      http_request_new.setRequestHeader("Connection", "close");
      http_request_new.send(parameters);
   }
   
   function savePassword() {
    if (http_request_new.readyState == 4) {
    if (http_request_new.status == 200) {
		var r=http_request_new.responseText;
          //alert(r);
		//document.getElementById("Loading_bulletin").style.display='none';
		document.getElementById("popup_bulletin").style.display='none';
		document.getElementById("popup").style.display='none';
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) 		{
			selects[i].style.visibility = 'visible';
		}
	}
	}
	//document.getElementById("Loading_bulletin").style.display='block';
   }

function testPassword(passwd)
{
var description = new Array();
/* description[0] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=20 bgcolor=#ff0000></td><td height=15 width=120 bgcolor=#dddddd></td></tr></table></td><td class=bold>Weakest</td></tr></table>";
description[1] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=50 bgcolor=#bb0000></td><td height=15 width=90 bgcolor=#dddddd></td></tr></table></td><td class=bold>Weak</td></tr></table>";
description[2] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=80 bgcolor=#ff9900></td><td height=15 width=60 bgcolor=#dddddd></td></tr></table></td><td class=bold>Medium</td></tr></table>";
description[3] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=110 bgcolor=#00bb00></td><td height=15 width=30 bgcolor=#dddddd></td></tr></table></td><td class=bold>Strong</td></tr></table>";
description[4] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=140 bgcolor=#00ee00></td></tr></table></td><td class=bold>Strongest</td></tr></table>";
description[5] = "<table border=0 cellpadding=0 cellspacing=0><tr><td class=bold width=90>Strength:</td><td><table cellpadding=0 cellspacing=2><tr><td height=15 width=140 bgcolor=#dddddd></td></tr></table></td><td class=bold nowrap>Begin Typing</td></tr></table>"; */

description[0] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=20 bgcolor=#ff0000></td><td height=10 width=120 bgcolor=#dddddd></td></tr><tr><td colspan=2>Weakest</td></tr></table>";
description[1] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=50 bgcolor=#bb0000></td><td height=10 width=90 bgcolor=#dddddd></td></tr><tr><td colspan=2>Weak</td></tr></table>";
description[2] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=80 bgcolor=#ff9900></td><td height=10 width=60 bgcolor=#dddddd></td></tr><tr><td colspan=2>Medium</td></tr></table>";
description[3] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=110 bgcolor=#00bb00></td><td height=10 width=30 bgcolor=#dddddd></td></tr><tr><td colspan=2>Strong</td></tr></table>";
description[4] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=140 bgcolor=#00ee00></td></tr></tr><tr><td>Strongest</td></tr></table>";
description[5] = "<table cellpadding=0 cellspacing=2><tr><td height=10 width=140 bgcolor=#dddddd></td></tr></tr><tr><td>Begin Typing</td></tr></table>";
		var intScore   = 0
		var strVerdict = 0

		// PASSWORD LENGTH
		if (passwd.length==0 || !passwd.length)                         // length 0
		{
			intScore = -1
		}
		else if (passwd.length>0 && passwd.length<5) // length between 1 and 4
		{
			intScore = (intScore+3)
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 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 (Not exactly implemented as dictacted above because of my limited understanding of Regex)
		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)
		}

																 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			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)
		}

																  // [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2)
		}


		if(intScore == -1)
		{
		   strVerdict = description[5];
		}
		else if(intScore > -1 && intScore < 16)
		{
		   strVerdict = description[0];
		}
		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("Words").innerHTML= (strVerdict);

}

// ----------------------------------- /Force Password --------------------------------------------

