 <?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts VistaCart                     |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php echo $javascript->link('jquery.js'); ?>
<?php //echo $javascript->link('alphanumeric.js'); ?>
<script language="javascript" type="text/javascript">
function chk(){
	    var errorstr = '';
	    var msgstr = "Sorry, we cannot complete your request.\nKindly provide us the missing or incorrect information enclosed below.\n\n";
	    var i=0;		
		var fcs_fld=new Array();
		var illegalChars = /\W/; /* For User name validtion*/
		var illegalChars1 = /[\W_]/;  /* For Password validtion*/
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;   /* For Email Address*/
		
		if ($.trim($('#UserUname').val())=='') { errorstr += "- Please enter User Name.\n";  fcs_fld[i]='UserUname'; i++;}
		if ($.trim($('#UserUname').val())!='') 
		{
         if ($.trim($('#UserUname').val()).length < 5) { errorstr += "- Username should contain atleast 5 characters.\n";   fcs_fld[i]='UserUname'; i++;}
		}
		
		 var chk_uname=$.trim($('#UserUname').val());
		 if (chk_uname.indexOf(' ') != -1) 
         { errorstr += "- Please remove spaces from username.\n";  fcs_fld[i]='UserUname'; i++;}	
		//if (illegalChars.test($('#UserUname').val())) { errorstr += "- The username contains illegal characters.\n";   fcs_fld[i]='UserUname'; i++;}
		
		if ($.trim($('#UserEmail').val())=='') { errorstr += "- Please enter Email Address.\n";   fcs_fld[i]='UserEmail'; i++;}
		if ($.trim($('#UserEmail').val())!='') 
		{
		 if(reg.test($.trim($('#UserEmail').val())) == false) { errorstr += "- Invalid Email Address.\n";   fcs_fld[i]='UserEmail'; i++;}
		}	
		
		if ($.trim($('#UserPassword').val())=='')  { errorstr += "- Please enter Password.\n";  fcs_fld[i]='UserPassword'; i++;}		
		 var chk_pswd=$('#UserPassword').val();
		 if (chk_pswd.indexOf(' ') != -1) 
         { errorstr += "- Password cannot contain spaces.\n";  fcs_fld[i]='UserUname'; i++;}	
		 		
		if ($.trim($('#UserPassword').val())!='') 
		{
         if ($.trim($('#UserPassword').val()).length < 6) { errorstr += "- Password should contain atleast 6 characters.\n";   fcs_fld[i]='UserPassword'; i++;}
		}
		
		/*
		if ($.trim($('#UserPassword').val()).length >=  6 ) {
		  if (illegalChars1.test($('#UserPassword').val())) { errorstr += "- The password should contain letters and numbers only.\n";   fcs_fld[i]='UserPassword'; i++;}
	    }		
		*/
		
		if ($.trim($('#UserPassword').val()).length >= 6 && $.trim($('#UserPassword').val())!='') {
		if ($.trim($('#UserConpassword').val())=='') { errorstr += "- Please Confirm Password.\n";   fcs_fld[i]='UserConpassword'; i++;}
		}
		if ($.trim($('#UserConpassword').val())!='') {
		if ($.trim($('#UserPassword').val()) != $.trim($('#UserConpassword').val())) { errorstr += "- Password Mismatch.\n";  fcs_fld[i]='UserConpassword'; i++;}					
		}
	
	if (errorstr != '')
	{
		msgstr = msgstr + errorstr;
		alert(msgstr);
		$('#'+fcs_fld[0]+'').focus();$('#'+fcs_fld[0]+'').select();
		return false;
	}
	else
	{
		return true;
	}
}
</script>
<div align="left" class="main_body">
<div class="col-sm-6 col-sm-offset-3">
        <h2 class="title text-center mainhd">New User Sign Up!</h2>
        <div class="invalid_user"><?php $session->flash(); ?></div>
        <div class="signup-form"><!--sign up form-->
                <?php echo $form->create('User', array('action' => 'register','name' =>'User')); ?>                    
             <?php echo $form->input('uname', array('label' => '','placeholder' => '* Username','size' => 27 ,'onBlur' => "javascript:while(''+this.value.charAt(0)==' ')this.value=this.value.substring(1,this.value.length);" )); ?>
                        <?php echo $form->input('email', array('label' => '','placeholder' => '* Email Address','size' => 27 ,'onBlur' => "javascript:while(''+this.value.charAt(0)==' ')this.value=this.value.substring(1,this.value.length);")); ?>
                          <?php echo $form->input('password', array('label' => '','placeholder' => '* Password','type' => 'password','size' => 27 , 'maxlength' => 25 )); ?>
                        <?php echo $form->input('conpassword', array('label' => '','placeholder' => '* Re-type Password','type' => 'password','size' => 27 , 'maxlength' => 25)); ?>
                         <?php echo $form->input('news_letter', array('label' => 'Subscribe Newsletter','type' => 'checkbox','checked' => true)); ?>
                		[Uncheck if you do not want to receive Newsletters] 
                         <div class="clearfix"></div>
						<div class="btngroup">
				            <button type="submit" class="btn btn-default signupbtn" onClick="return chk();">Sign Up</button>
				            <button type="reset" class="btn btn-default resetbtn" >Reset</button>
				        </div>
                 <?php echo $form->end(); ?>
        </div><!--/sign up form-->
</div>
<div class="clearfix"></div>
        
        
     
        <div class="clear"></div>
        </div>
    <script>
	//$('#UserPassword').alphanumeric();
	//$('#UserConpassword').alphanumeric();
	</script>