<?php
include('init.php');
include('libs/functions.php');

//session_start();

$types = "";
$sql = "select * FROM tb_court_system_type Order By court_type_id";
$rs = $db->Execute($sql);
while (!$rs->EOF)
  { 
$court_type_id = $rs->fields('court_type_id');
$court_type = $rs->fields('court_type');


$types = $types . "<option value=\"$court_type_id\">$court_type</option>\n";

$rs->MoveNext();
  } 
 
 
//$ident1 = RAND(1,20);
//$ident2 = RAND(1,20);

$ident1 = substr(md5(microtime()),rand(0,26),7);
$ident1 = strtoupper($ident1);

$tc_text = "Terms and Conditions PlaceHolder Text";
//start of crazy state stuff
print_header();
?>
<script src="jQuery/jq-custom/js/jquery-1.9.1.js"></script>
<script src="jQuery/jq-custom/js/jquery-ui-1.10.3.custom.js"></script>
<script src="jQuery/jq-custom/js/jquery-ui-1.10.3.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="jQuery/jq-custom/css/flick/jquery-ui-1.10.3.custom.css">



<script type="text/javascript">
	/*jQuery(document).ready(
		function() {
			var lowerBound = 1;
			var upperBound = 10;
			
			
			// generate random numbers between lowerBound and upperBound (inclusive)
			var a = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
			var b = Math.floor(Math.random() * (upperBound - lowerBound + 1)) + lowerBound;
			var c = a + b;
			
			//$("#captcha").html("<tr id='captcha_q'><td width='200'>What is " + a + "+" + b + "?</td><td width='200'><input type='text' name='captcha_a' id='captcha_a' maxlength='2' size='2'></td></tr>");
			$("#captcha_q").html("What is " + a + " + " + b + "? <input type='captcha_a' name='captcha_a' size='3' value=''>");

		}
		)
*/		
var msg = "";

//stop users from submitting for using "enter" - stops ajax username/email check bypass
function stopRKey(evt) { 
  var evt = (evt) ? evt : ((event) ? event : null); 
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 
} 


document.onkeypress = stopRKey; 

	function pullAjax(){
        	var a;
	        try{
	          a=new XMLHttpRequest()
	        }
	        catch(b)
	        {
	          try
	          {
	            a=new ActiveXObject("Msxml2.XMLHTTP")
	          }catch(b)
	          {
	            try
	            {
	              a=new ActiveXObject("Microsoft.XMLHTTP")
	            }
	            catch(b)
	            {
	              alert("Your browser broke!");return false
	            }
	          }
	        }
	        return a;
	      }
 //this function does the ajax call, and appends counties into the counties dropdown
      function populate_counties(x)
      {
        obj=pullAjax();
        var counties_list=document.getElementById('court_county');

        obj.onreadystatechange=function()
        {
          if(obj.readyState==4)
          {
            //returns comma separated list of counties after successful ajax request
            var tmp=obj.responseText;

            //split function returns array of county
            counties=tmp.split(',');

            //if second dropdown already has some data, CLEAR it
            if(counties_list.length>1)
              clean_counties(counties_list);

            //for loop to append the counties
            var i=0;
            for(i=0;i<counties.length;i++)
              append_county(counties[i]);
          }
        };
	var county_URL = "counties_data.php?state=" + x.value + "&nocache=" + new Date().getTime();
        obj.open("GET",county_URL,true);
        obj.send(null);
      }

      function append_county(county_value)
      {
        var counties_list=document.getElementById('court_county');
        counties_list.options[counties_list.options.length]=new Option(county_value,county_value,false,false);
      }

      //CLEARs the dropdown
      function clean_counties()
      {
        var counties_list=document.getElementById('court_county');
        counties_list.options.length=1;
      }


	  function email_check(x)
      {
        obj=pullAjax();
	 
        var uEmail = document.forms.registration.email.value;
        obj.onreadystatechange=function()
        {
          if(obj.readyState==4)
          {
            //returns email exists
            var tmp=obj.responseText;
	
		if (tmp > 0){
			//alert("Email address already exists.");
			msg += "Email address already exists.";
			document.getElementById("btnSubmit").disabled = true; 
			document.getElementById("emailError").innerHTML = "<b><font color='red'>Email address already exists.</font></b>"
			document.forms.registration.email.focus();
			return false;
			
			
		}
		else{
			document.getElementById("btnSubmit").disabled = false;
			document.getElementById("emailError").innerHTML = "";
 			
			username_check();
		}
          }
        };
	var email_URL = "check_email.php?email=" + uEmail + "&nocache=" + new Date().getTime();
        obj.open("GET",email_URL,true);
        obj.send(null);
      }

      function username_check(x)
      {
        obj=pullAjax();
	 
        var uName = document.forms.registration.user.value;
        obj.onreadystatechange=function()
        {
          if(obj.readyState==4)
          {
            //returns email exists
            var tmp=obj.responseText;
	
		if (tmp > 0){
			//alert("Username already exists.");
			msg += "Username already exists.";
			document.getElementById("unameError").innerHTML = "<b><font color='red'>Username already exists.</font></b>"
			document.getElementById("btnSubmit").disabled = true; 
			return false;

			
		}	
		else{
			document.getElementById("btnSubmit").disabled = false; 	
			document.getElementById("unameError").innerHTML = "";	

			email_check();
		}	
          }
        };
	var username_URL = "check_username.php?user=" + uName + "&nocache=" + new Date().getTime();
        obj.open("GET",username_URL,true);
        obj.send(null);
      }


function cupcake(){
	var court_type;
	court_type=document.getElementById('court_type').options[document.getElementById('court_type').selectedIndex].value;
	
	var court_state;
	court_state=document.getElementById('state').options[document.getElementById('state').selectedIndex].value;
	
	var court_county;
	court_county=document.getElementById('court_county').options[document.getElementById('court_county').selectedIndex].value;
	
	
	
	if ((court_type == "0")){
		document.getElementById("court_state_row").style.display='none';
		document.getElementById("court_county_row").style.display='none';
		document.getElementById("court_name_row").style.display='none';
		
		document.getElementById('state').selectedIndex= 0;
		document.getElementById('court_county').selectedIndex= 0;
		document.getElementById('court_name').value = "";
		
		
	}
	else{
		if ((court_type != "0")){
		document.getElementById("court_state_row").style.display='';
		
			if ((court_state != "0")){
				document.getElementById("court_county_row").style.display='';
			
				if ((court_county != "0")){
					document.getElementById("court_name_row").style.display='';
				}
			}			
		}
	
	}
	
}

function check_form() {
var errs=0;

var msg = "";
if (document.forms.registration.fname.value == "") {
	msg += "- Please enter your first name.\n";
}
if (document.forms.registration.lname.value == ""){
	msg += "- Please enter your last name.\n";
}

//-----------------------------email validation---------------------
var x = document.forms.registration.email.value;
var filter = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;

if (!document.forms.registration.email.value == ""){
	if (!filter.test(x)){ 
		msg += "- Please enter a valid email address.\n";
	}
}

if (document.forms.registration.email.value == ""){
	msg += "- Please enter a valid email address.\n";
}


//----------------------------end email-----------------------------

//-----------------------------phone validation---------------------
    var phone_re = /^[0-9]+$/;
if ((document.forms.registration.phone.value == "") || (document.forms.registration.phone.value.length < 10) || (document.forms.registration.phone.value.length > 10) || (!phone_re.test(document.forms.registration.phone.value))){
	msg += "- Please enter a valid 10-digit phone number.\n";
}
//-----------------------------end phone validation---------------------

if (document.getElementById('court_type').options[document.getElementById('court_type').selectedIndex].value < 1) {
	msg += "- Please select a court system type.\n";
}

if (document.getElementById('state').options[document.getElementById('state').selectedIndex].value < 1) {
	msg += "- Please select a court system state.\n";
}

if (document.getElementById('court_county').options[document.getElementById('court_county').selectedIndex].value < 1) {
	msg += "- Please select a court system county.\n";
}

if ((document.forms.registration.court_name.value == "") || (document.forms.registration.court_name.value.length > 100)) {
	msg += "- Please enter a court system name. (between 1-100 characters)\n";
}

if (document.forms.registration.user.value == ""){
	msg += "- Please enter a username.\n";
}
if (document.forms.registration.user.value.length < 4) {
	msg += "- Username must be at least 4 characters in length.\n";
}
if (document.forms.registration.user.value.length > 16) {
	msg += "- Your username is too long. Please enter a username less than 16 characters.\n";
}

if (!document.forms.registration.user.value == ""){
	username_check(document.forms.registration.user.value);
}



//--------------------------------password validation---------------------------

if (document.forms.registration.password.value == '') {
	msg+= "- Please enter a desired password.\n";
}
if (document.forms.registration.password.value != document.forms.registration.password2.value) {
	msg += "- Passwords do not match.\n";
}

var pwd1 = document.forms.registration.password.value;
var pwd2 = document.forms.registration.password2.value;



if ((document.forms.registration.password.value.length < 8) || (document.forms.registration.password2.value.length < 8)) {
        msg += "- Passwords must contain at least eight (8) characters, a number and upper and lower case letters.\n";
     }

if ((document.forms.registration.password.value.length > 20) || (document.forms.registration.password2.value.length > 20)) 
     {
        msg += "- Passwords must not contain more than twenty (20) characters.\n";
     }

     re = /[0-9]/;
     if ((!re.test(pwd1)) || (!re.test(pwd2))) 
     {
        msg += "- Password must contain at least one number (0-9).\n";
     }
     re = /[a-z]/;
     if ((!re.test(pwd1)) || (!re.test(pwd2))) 
     {
        msg+= "- Password must contain at least one lowercase letter (a-z).\n";
     }
     re = /[A-Z]/;
     if ((!re.test(pwd1)) || (!re.test(pwd2)))  
     {
        msg += "- Password must contain at least one uppercase letter (A-Z).\n";
     }

	// Create regular expression for password and login id
	var re = new RegExp("[^A-Za-z0-9 ]","i");

//-----------------------------end password validation----------------------------

if (msg != "") { 
	alert(msg);
	return false;
}
else {
	return true;
}

}



function automated_check(){

var tc_title = "VRSS Automated Uploads - Terms and Conditions";
var terms_cond_text = "<br>Terms and Conditions Text Placeholder"
var tc_div = "<div id='tc_div'>" + terms_cond_text + "</div>";


	//$("#vrss_automated").change( function(e){

					//var isChecked=$this.is(':checked');
						$("#vrss_automated").unbind('change');
						$("#vrss_automated").unbind('click');

					if( $("#vrss_automated").is(':checked'))
						$('body').append(tc_div);
						$('#tc_div').prop('title' , tc_title);
						$('#tc_div').dialog({
									closeOnEscape: false,
									open: function(event, ui) { $(".ui-dialog-titlebar-close", ui.dialog).hide(); },
									resizable: false,
									draggable: false,
									height:250,
									width:450,
									modal: true,
									buttons: {		
											"I Agree": function() {

												document.getElementById('vrss_automated').checked=true;	
												$('#tc_div').dialog('destroy').remove();			
											},

											"I Disagree": function() {

												document.getElementById('vrss_automated').checked=false;
												$('#tc_div').dialog('destroy').remove();
											}
										}
						});
						$("#tc_div").dialog("open");

			//});
}




</script>


<p class="page-title"><!-- START: PAGE TITLE -->Court System User Account Registration<!-- END: PAGE TITLE --></p>
        <!-- END: PAGE TITLE AREA -->
        
        <!-- START: PAGE CONTENT -->

<p>Please complete the following registration form to request an account for the Veterans Re-Entry Search System. After submitting this information, your request must be reviewed by a VA Administrator. You will receive an email confirmation when your account has been approved.</p>

<script type="text/javascript" src="password.js"></script>
<style>
#passwordStrength { height:10px; display:block; float:left; } .strength0 { width:250px; background:#cccccc; } .strength1 { width:50px; background:#ff0000; } .strength2 { width:100px; background:#ff5f5f; } .strength3 { width:150px; background:#56e500; } .strength4 { background:#4dcd00; width:200px; } .strength5 { background:#399800; width:250px; }
</style>
<body>

<form name="registration" action="newCSuser.php" method="post" onSubmit="return check_form();">
<table width=550>
<tr class="va-section-header" width="550">
<td colspan=5>Account Information</td>
</tr>
<tr>
<td width="550" colspan="5">
    Please complete the following fields to register for a VRSS Court System Account.
<br>
Note: All fields are required.
<br><br>
<tr>
<td width="200"><label for="fname">First Name</label></td>
<td width="400"><input type="text" name="fname" id="fname" size="20" maxlength="20"></td>
</tr>
<tr>
<td width="200"><label for="lname">Last Name</label></td>
<td width="400"><input type="text" name="lname" id="lname" size="20" maxlength="20"></td>
</tr>
<tr>
<td width="200"><label for="email">Email</label></td>
<td width="400"><input type="text" name="email" id="email" size="40" maxlength="120" onchange="return email_check();"></td>
<TD colspan="3" width="200" id="emailError" name="emailError"></TD>
</tr>
<tr>
<td width="200"><label for="phone">Phone</label></td>
<td width="250"><input type="text" name="phone" id="phone" size="20" maxlength="20"></td>
<td width="250"><label for="ext">Extension</label>.</td>
<td width="250"><input type="text" name="ext" id="ext" size="10" maxlength="10"></td>
<td width="250">(Optional)</td>
</tr>
</table>


<br><br>

<table width=550>
<tr class="va-section-header" width="550">
<td colspan=5>Upload Automation</td>
</tr>
<tr>
<td width="300px"><label for="vrss_automated">Enable automated file uploads</label></td>
<td width="300px"><input type="checkbox" name="vrss_automated" id="vrss_automated" value="1" onclick="automated_check();"></td>
</tr>
</table>


<table width=550>
<tr class="va-section-header" width="550">
<td colspan="5">Court System Selection</td>
</tr>

<br><br>
<tr><td colspan=2>
Note: All fields are required.<br><br>
</td></tr>
<tr id="court_type_row">
<td width="200"><label for="court_type">Court System Type</label></td>
<td>
<SELECT style="width: 100%;" name="court_type" id="court_type" onchange="cupcake();">
<OPTION VALUE="0" ><label>Select Court System Type</label>...</OPTION>
<?echo $types;?>
</SELECT>
</td>
</tr>
<br><br>

<tr id="court_state_row" style="display:none;">
<td width="200" ><label for="state">Court System State</td>
<td width="200"><SELECT style="width: 100%;" name="state" id="state" onchange="cupcake(); populate_counties(this);">
<OPTION VALUE="0" >Select State...</OPTION>

<?

$sql = "select state, state_code FROM tb_state_county Group By state, state_code";
$rs = $db->Execute($sql);
while (!$rs->EOF)
  { 
$code = $rs->fields('state_code');
$state = $rs->fields('state');

print "<option value=\"$code\">$state</option>\n";

$rs->MoveNext();
  } 


?>
</SELECT></td>
</tr>
    
    
<tr id="court_county_row" style="display:none;">
<td width="200"><label for="court_county">Court System County</label></td>
<td width="200"><SELECT style="width: 100%;" name="court_county" id="court_county" onchange="cupcake();">
<OPTION VALUE="0" >Select County...</OPTION>
</SELECT></td>
</tr>

<tr id="court_name_row" style="display:none;">
<td width="200"><label for="court_name">Court System Name</label></td>
<td width="200">
<input type="text" name="court_name" id="court_name" maxlength="100" size="50">
</td>
</tr>

</table>
<br /><br />
<br /><br />

<TABLE width=550>

<tr class="va-section-header" width="550">
<td colspan=5>Create a New Username</td>
</tr>

<tr>
<td width="500">
    Please create a username to log into your account.
<br>
Note: Usernames must be between 4 and 16 characters in length, and may not contain spaces or special characters.
    <br><br>
<TABLE>

<TR><TD><label for="user">Desired Username</label></TD>
<TD>
<input type="text" name="user" id="user" size="20" value="" onchange="return username_check();">
</TD>
<TD width="200" id="unameError" name="unameError"></td>                      
</TR>
</TABLE>
<br /><br />
</td></tr>
<tr class="va-section-header" width="550">
<td colspan=5>Create a New Password</td>
</tr>

<tr>
<td width="500">
Please create a new password to log into your account.
<br>
Note: Passwords must be between 8 and 20 characters in length and contain both uppercase and lowercase letters, and at least one number.
<br />
<br />

<TABLE>        
<TR><TD><label for="password">Desired Password</label></TD>
<TD><input type="password" name="password" id="password" size="20" value="" onkeyup="passwordStrength(this.value)">
</TD><TD>
</TD>
</TR>
<TR><TD></TD>
<TD><div id="passwordDescription">Password not entered</div> <div id="passwordStrength" class="strength0"></div><br /></TD></TR>
<TR><TD><label for="password2">Confirm Password</label></TD>
<TD><input type="password" name="password2" id="password2" size="20" value="">
</TD><TD>
</TD>
</TR>
</TABLE>
<br />
</td></tr>

<TR><TD colspan=5 align=center>
<HR>
<INPUT TYPE=SUBMIT VALUE="Create Account" id="btnSubmit"> <button onclick="location.href='../login.php'">Cancel</button> 
<HR>
</TD></TR>
</TABLE>
</form>
</td>



<td valign="top" align="left" width="168"><table bordercolor="#000066" cellspacing="0" cellpadding="0" width="320" border="1">
<tbody>
<tr>
<td width="320"><table cellspacing="0" cellpadding="0" width="320" border="0">
<tbody>

<tr>
<td width="320"><br /><ul>
<TABLE>
<TR><TD>
<B>Need Help?</B>
<BR><BR>
<A HREF=support.php>Click here for Support</A>
<BR><BR>
<b><u>VA Health Resource Center Help Desk</u></b>
<br><b>Phone:</b> 1-800-983-0935
<br><b>Hours:</b> 7 AM - 5 PM (CST), Monday - Friday

<BR>
<BR><table width="135" border="0" cellpadding="2" cellspacing="0" title="Click to Verify - This site chose VeriSign SSL for secure e-commerce and confidential communications.">
<tr>
<td align="center" valign="top"><img alt="Click to Verify - This site chose VeriSign SSL for secure e-commerce and confidential communications." src="vcs_ss_v.png">
</td>
</tr>
</table>
</TD></TR>
</TABLE>
<br /></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>

			
<?php

print_footer();

?>
