<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Programmer<programmer@armia.com>        		              |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";
include "classes/cls_user.php";

if (get_magic_quotes_gpc()) {
    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
}

if (isset($_GET["aid"]) and $_GET["aid"] != "") {
    $aid = $_GET["aid"];
} elseif (isset($_POST["aid"]) && $_POST["aid"] != "") {
    $aid = $_POST["aid"];
} elseif (isset($_SESSION["aid"]) && $_SESSION["aid"] != "") {
    $aid = $_SESSION["aid"];
}

if ($aid != '') {
    $_SESSION["aid"] = $aid;
}

if (isset($_GET["action"]) and $_GET["action"] != "") {
    $action = $_GET["action"];
} else {
    $action = $_POST["action"];
}

$chkexpusers = getCheckoutExpiredUsers();
$chkexpusers = explode(",", $chkexpusers);
for ($i = 0; $i < count($chkexpusers); $i++) {
    adjustStock($chkexpusers[$i], "+");
}

if (isset($_GET["action"]) and $_GET["action"] != "") {
    $action = $_GET["action"];
} else if (isset($_POST["action"]) and $_POST["action"] != "") {
    $action = $_POST["action"];
}


$registered = false;
if (isset($_POST["txtUserName"])) {

    $txtUserName = $_POST["txtUserName"];
    $txtFirstName = $_POST["txtFirstName"];
    $txtLastName = $_POST["txtLastName"];
    $txtAddress1 = $_POST["txtAddress1"];
    $txtAddress2 = $_POST["txtAddress2"];
    $txtCity = $_POST["txtCity"];
    $txtState = $_POST["bill_state"];
    $ddlCountry = $_POST["bill_country"];
    $txtZIP = $_POST["txtZIP"];
    $txtEmail = $_POST["txtEmail"];
    $txtPhone = $_POST["txtPhone"];
    $txtFAX = $_POST["txtFAX"];
    $txtPassword = $_POST["txtPassword"];
    $txtCnfPassword = $_POST["txtCnfPassword"];
    $check_news = $_POST["check_news"];
    if ($check_news == 1)
        $check_news = "Y";
    else
        $check_news = "N";

    $message = "";

    if (!isNotNull($txtUserName)) {
        $message .= USERNAME_EMPTY_MSG . "<br>";
    } else {
        $qry = "SELECT  LOWER(user_name) FROM  " . $tableprefix . "users WHERE user_name='" . strtolower(addslashes($txtUserName)) . "' ";
        if (mysql_num_rows(mysql_query($qry)) > 0) {
            $message .= USERNAME_EXISTS_MSG . "<br>";
        }

        $qry1 = "SELECT  LOWER(artist_name) FROM  " . $tableprefix . "artists WHERE artist_name='" . strtolower(addslashes($txtUserName)) . "' ";
        if (mysql_num_rows(mysql_query($qry1)) > 0) {
            $message .= USERNAME_EXISTS_MSG . "<br>";
        }
    }

    /* if (!isValidUsername($txtUserName)) {
      $message .= INVALID_USER_MSG."<br>";
      } */

    if (!isNotNull($txtPassword)) {
        $message .= PASSWORD_EMPTY_MSG . " <br>";
    }
    if (!isNotNull($txtCnfPassword)) {
        $message .= PASSWORD_CONFIRM_EMPTY_MSG . " <br>";
    }

    if ($txtPassword != $txtCnfPassword) {
        $message .= PASSWORD_MISSMATCH_MSG . " <br>";
    }

    if (!isNotNull($txtFirstName)) {
        $message .= FIRST_NAME_EMPTY_MSG . " <br>";
        /* if(!preg_match("/^[a-zA-Z ]+$/", $txtFirstName))
          {
          $message .= "* First name accepts alphabets only !! <br>";
          } */
    }
    if (!isNotNull($txtLastName)) {
        $message .= LAST_NAME_EMPTY_MSG . " <br>";
    }
    /* if(isNotNull($txtLastName))
      {
      if(!preg_match("/^[a-zA-Z ]+$/", $txtLastName))
      {
      $message .= "* Last name accepts alphabets only !! <br>";
      }
      } */
    if (isNotNull($txtZIP)) {
        if (strlen($txtZIP) != 5 && $ddlCountry == "US") {
            $message .= INVALID_ZIP_CODE . "<br>";
        }
    }
    if (isNotNull($txtPhone)) {
        if (!check_phone($txtPhone, $ddlCountry)) {
            $message .= INVALID_PHONE_NUMBER . "<br>";
        }
    }

    if (!isNotNull($txtEmail)) {
        $message .= EMAIL_EMPTY_MSG . " <br>";
    } else {
        if (!isValidEmail($txtEmail)) {
            $message .= INVALID_EMAIL_MSG . " <br>";
        }
    }

    $qry2 = "select email from  " . $tableprefix . "users where email='" . addslashes($txtEmail) . "'";
    if (mysql_num_rows(mysql_query($qry2)) > 0) {
        $message .= EMAIL_ADDRESS_MSG . " <br>";
    }
    
    $qry3 = "select email from  " . $tableprefix . "artists where email='" . addslashes($txtEmail) . "'";
    if (mysql_num_rows(mysql_query($qry3)) > 0) {
        $message .= EMAIL_ADDRESS_MSG . " <br>";
    }

    /* custom fields null checking starts */

   /* $select_custom_qry = "SELECT * FROM " . $tableprefix . "custom_fields WHERE vcustom_display_field = 'Y' 
						  	  AND vcustom_delete_status !='Y' ORDER BY vcustom_sort_order";
    $result_custom_qry = mysql_query($select_custom_qry) or die(mysql_error());

    while ($custom_qry_row = mysql_fetch_array($result_custom_qry)) {

        $field_name = 'custom_field_' . $custom_qry_row['ncustom_id'];

        if ($custom_qry_row['vrequired_custom_field'] == 'Y') {


            if (!isNotNull($_POST[$field_name])) {
                //$message .= ucfirst($custom_qry_row['vcustom_field_name']).CANNOT_BE_EMPTY_TEXT." <br>";
                $message .= CANNOT_BE_EMPTY_TEXT . " <br>";
                $message = str_replace("FIELD", ucfirst($custom_qry_row['vcustom_field_name']), $message);
            }
        }

         $insert_custom_fields = "INSERT INTO ".$tableprefix."custom_fields_value(ncustom_field_id,ncustom_table_id,vfield_name_value)
          VALUES(".$custom_qry_row['ncustom_id'].","
          .$userid.","
          .GetSQLValueString($_POST[$field_name],"text").")";

          mysql_query($insert_custom_fields) or die(mysql_error()); 
    }
*/

    /* custom fields null checking ends */



    if ($message != "") { // error
        $message = "<br>" . CORRECT_ERRORS_TEXT . "<br>" . $message;
    } else { // no error so insert user details
        $sql = "INSERT INTO " . $tableprefix . "users (
			user_name ,
			password,
			first_name,
			last_name,
			address1,
			address2,
			city,
			state,
			country,
			phone,
			fax,
			zip,
			email,
			affiliate_id,
			newsLetter,
			date_registered
			) VALUES (
			'" . addslashes($txtUserName) . "',
			'" . addslashes(md5($txtPassword)) . "',
			'" . addslashes($txtFirstName) . "',
			'" . addslashes($txtLastName) . "',
			'" . addslashes($txtAddress1) . "',
			'" . addslashes($txtAddress2) . "',
			'" . addslashes($txtCity) . "',
			'" . addslashes($txtState) . "',
			'" . addslashes($ddlCountry) . "',
			'" . addslashes($txtPhone) . "',
			'" . addslashes($txtFAX) . "',
			'" . addslashes($txtZIP) . "',
			'" . addslashes($txtEmail) . "',
			'" . addslashes($aid) . "',
			'" . addslashes($check_news) . "',							
			now()
			)";

        mysql_query($sql);
        $userid = mysql_insert_id();

        //Save User Ip Address And Location
        $ipInfo     =   generalMethods::get_location();
        if(!empty($ipInfo)){
            $iplocation = '';
            if($ipInfo->city!='')
            {
                $iplocation .= $ipInfo->city . " ,";
            }
            
            if($ipInfo->region_name!='')
            {
                $iplocation .= $ipInfo->region_name . " ,";
            }
            if($ipInfo->country_name!='')
            {
                $iplocation .= $ipInfo->country_name . " ,";
            }
        $iplocation = rtrim($iplocation ," ,");    
        $ipaddress  =   $ipInfo->ip;
        $objIpVO    =   new stdclass();
        $objIpVO->ip_address        =   $ipaddress;
        $objIpVO->user_id           =   $userid;
        $objIpVO->ip_location       =   $iplocation;
        $userInfo   =    User::saveUserIpInfo($objIpVO);
        }

        // End Saving
        
        
        // Update Referal Code of User 
     /*   if(getSettingsValue('enable_referral_settings')=='Y') { 
            
            $txtReferalCode     =    $_POST['txtReferalCode'];
            $cmbRefSeller       =    $_POST['cmbRefSeller'];
            
            if($txtReferalCode!='')
            {
                $objRefVo                           =    new stdClass();
                $objRefVo->user_id                  =   $userid;
                $objRefVo->referral_code            =   $txtReferalCode;
                $objRefVo->referral_seller          =   $cmbRefSeller;
                $userRefInfo                        =    User::saveUserFeferalInfo($objRefVo);
            }
            
        }*/
        
        
        /* custom fields null checking starts */
        
        $select_custom_qry = "SELECT * FROM " . $tableprefix . "custom_fields WHERE vcustom_display_field = 'Y'
						  	  ORDER BY vcustom_sort_order";
        $result_custom_qry = mysql_query($select_custom_qry) or die(mysql_error());
        
        while ($custom_qry_row = mysql_fetch_array($result_custom_qry)) {
        
        
        	$field_name = 'custom_field_' . $custom_qry_row['ncustom_id'];
        
        	if ($custom_qry_row['vrequired_custom_field'] == 'Y') {
        
        
        		if (!isNotNull($_POST[$field_name])) {
        			//$message .= ucfirst($custom_qry_row['vcustom_field_name']).CANNOT_BE_EMPTY_TEXT." <br>";
        			$message .= CANNOT_BE_EMPTY_TEXT . " <br>";
        			$message = str_replace("FIELD", ucfirst($custom_qry_row['vcustom_field_name']), $message);
        		}
        	}
        	$insert_custom_fields = "INSERT INTO ".$tableprefix."custom_fields_value(ncustom_field_id,ncustom_table_id,user_id,vcustom_field_type,vfield_name_value,vcustom_field_name)
          VALUES(".$custom_qry_row['ncustom_id'].","
                  		.$userid.","
                  				.$userid.","
                  						.GetSQLValueString($custom_qry_row['vcustom_field_type'],"text").","
                  								.GetSQLValueString($_POST[$field_name],"text").","
                  										.GetSQLValueString($custom_qry_row['vcustom_field_name'],"text").")";
        
        	mysql_query($insert_custom_fields) or die(mysql_error());
        }
        
        
        /* custom fields null checking ends */
        


/*        $select_custom_insert = "SELECT * FROM " . $tableprefix . "custom_fields WHERE vcustom_display_field = 'Y'
						  	 	   AND vcustom_delete_status !='Y'";
        $result_custom_insert = mysql_query($select_custom_insert) or die(mysql_error());

        while ($custom_insert_row = mysql_fetch_array($result_custom_insert)) {

            $field_name_insert = 'custom_field_' . $custom_insert_row['ncustom_id'];



            $insert_custom_fields = "INSERT INTO " . $tableprefix . "custom_fields_value(ncustom_field_id,ncustom_table_id,vfield_name_value)
									VALUES(" . $custom_insert_row['ncustom_id'] . ","
                    . $userid . ",'" . mysql_real_escape_string($_POST[$field_name_insert]) . "')";

            mysql_query($insert_custom_fields) or die(mysql_error());
        }
  */      

        /* $jscript .= "}
          </script>"; */

        /* $sql = "SELECT * FROM ".$tableprefix."settings ";
          $result = mysql_query($sql);
          if(mysql_num_rows($result) != 0){
          $row = mysql_fetch_array($result);
          $txtReferralCharge = $row["referral_charge"];
          }
          if(isset($aid) && ($aid!="")){
          $sql = "INSERT INTO ".$tableprefix."affiliate_registrations (
          affiliate_id,
          user_id,
          user_name ,
          user_first_name,
          user_last_name,
          user_email,
          referral_charge,
          registration_date
          ) VALUES (
          '".addslashes($aid)."',
          '".addslashes($userid)."',
          '".addslashes($txtUserName)."',
          '".addslashes($txtFirstName)."',
          '".addslashes($txtLastName)."',
          '".addslashes($txtEmail)."',
          '".addslashes($txtReferralCharge)."',
          now()
          )";
          mysql_query($sql);
          //echo $sql;
          } */


        /* ------------Multicart 2.0 Upgradation------------ */

        //$userfullname = $txtFirstName;


        $_SESSION["sess_username"] = $txtUserName;
        $_SESSION["sess_userid"] = $userid;


        // Ending Session for Sellers, Affiliates		
        if (isset($_SESSION["sess_artistid"]) and $_SESSION["sess_artistid"] != "") { // Logging Out User  from same window
            if (function_exists('session_unregister')) {
                session_unregister($_SESSION["sess_artistid"]);
            } else {
                unset($_SESSION["sess_artistid"]);
            }
        }
        if (isset($_SESSION["sess_affiliateid"]) and $_SESSION["sess_affiliateid"] != "") { // Logging OutSeller  from same window
            if (function_exists('session_unregister')) {
                session_unregister($_SESSION["sess_artistid"]);
            } else {
                unset($_SESSION["sess_artistid"]);
            }
        }
        // End check 
        
        /* 
         * Sending Email to Affliate Regrading registration of a user with the Referral link
         * 
         */
        
        if($aid!=''){
            $select_aff_qry = "SELECT first_name,last_name,email FROM " . $tableprefix . "affiliates WHERE affiliate_id = '".  mysql_real_escape_string($aid)."' AND deleted='N' AND vapproved='Y'";
						  	  
            $result_aff = mysql_query($select_aff_qry) or die(mysql_error());
            if(mysql_num_rows($result_aff)>0){
                $row  = mysql_fetch_object($result_aff);
                $affliate_name   = $row->first_name.' '.$row->last_name;
                $detailsArray = array(
                                 'affliate_name'    => $affliate_name,
                                 'user_first'       => $txtFirstName,
                                 'user_last'        => $txtLastName,
                                 'affliate_email'   => $row->email
                              );
                
                sendAffliateReferralRegisterMail($detailsArray);
                
            }
            
        }
        
        /*
         * End Email Section Affliate
         */

        if ($txtLastName != "") {
            $userfullname .= " " . $txtLastName;
        }

        $to = $txtEmail;

        $subject = MAIL_USER_ACCOUNT_MODIFY_SUBJECT_1 . " " . SITE_NAME;

        /* -------Email Template Reading Fuction Call-------- */

        $mailcontent = readEmailTemplate('member_registration');


        $mailcontent = str_replace('[user_name]', $txtUserName, $mailcontent);
        $mailcontent = str_replace('[password]', $txtPassword, $mailcontent);

        /* ---------------User Login Url------------------- */


        $mailcontent .= "\r\n" . MAIL_PLAN_PURCHASE_TEXT_CLICK . "&nbsp;<a href=" . SITE_URL . "/login.php>" . MAIL_PLAN_PURCHASE_TEXT_HERE . "</a> " . MAIL_PLAN_PURCHASE_TEXT_TO_LOGIN . "\r\n\n";

        /* ---------------User Login Url------------------- */

        $from = "From: " . SITE_EMAIL . "\n";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: " . SITE_EMAIL . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Reply-To: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Return-Path: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Organization: " . SITE_NAME . "\r\n";
        $mailcontent = nl2br($mailcontent);

        $mail_send_details = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>' . SITE_NAME . ' - ' . MAIL_USER_REGISTRATION_TITLE . '</title>
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">
         
         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src=' . SITE_URL . '/banners/' . getSettingsValue('site_logo') . ' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>' . $mailcontent . '</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';

        //$mail_send_details = "<html><head><link href='".SITE_URL."/style/template1-admin.css' rel='stylesheet' type='text/css'></head><body><center><div align='left' id='layout'><div align='left' class='header'><div align='left' class='logo'><img src=".$logofolder."/".$logoimage." width='125' height='39'/></div></div><div>".$mailcontent."</div></div><div align='left' class='clear_float'><img src=".$imagefolder."/clear.gif width=1 height=1/></div></div></div></center></body></html>";

        $mailsent = mail($to, $subject, $mail_send_details, $headers);

        // **********************************************************************Send Mail To Administrator 


        $subject_admin = MAIL_USER_REGISTRATION_SUBJECT . " " . SITE_NAME;

        /* -------Email Template Reading Fuction Call-------- */

        $mailcontent_admin = readEmailTemplate('member_registration_admin');


        $mailcontent_admin = str_replace('[user_name]', $txtUserName, $mailcontent_admin);
        $mailcontent_admin = str_replace('[password]', $txtPassword, $mailcontent_admin);

        $mailcontent_admin = str_replace('[first_name]', $txtFirstName, $mailcontent_admin);

        $mailcontent_admin = str_replace('[last_name]', $txtLastName, $mailcontent_admin);

        /* ---------------User Login Url------------------- */


        $mailcontent_admin .= "\r\n" . MAIL_PLAN_PURCHASE_TEXT_CLICK . "&nbsp;<a href=" . SITE_URL . "/admin/login.php>" . MAIL_PLAN_PURCHASE_TEXT_HERE . "</a> " . MAIL_USER_REGISTRATION_TO_LOGIN_TO_VIEW_DETAILS_OF_MEMBER . "\r\n\n";

        /* ---------------User Login Url------------------- */

        $from = "From: " . SITE_EMAIL . "\n";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
        $headers .= "From: " . SITE_EMAIL . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Reply-To: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Return-Path: " . SITE_NAME . "<" . SITE_EMAIL . ">" . "\r\n";
        $headers .= "Organization: " . SITE_NAME . "\r\n";

        $mailcontent_admin = nl2br($mailcontent_admin);
        $mail_send_details_admin = '<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <title>' . SITE_NAME . ' - ' . MAIL_USER_REGISTRATION_TITLE . '</title>
</head>
<body>

<table width="103%" cellspacing="10" cellpadding="0" bgcolor="#EAEAEA">
   <tr>
     <td align="center" valign="top">
         
         <table width="600" border="0" cellpadding="0" cellspacing="0" bordercolor="#EAEAEA" bgcolor="#FFFFFF" class="manage_table">
            <tr>
               <td align="right" >
              </td>
            </tr>
            <tr>
               <td valign="middle" align="left"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                 <tr>
                   <td  bgcolor="#EAEAEA" > <img src=' . SITE_URL . '/banners/' . getSettingsValue('site_logo') . ' width="125" height="60"/></td>
                 </tr>
               </table></td>
            </tr>
            <tr>
              <td align="center" valign="top"><table width="100%"  border="0" cellspacing="0" cellpadding="10">
                <tr>
                  <td align="left"><p>' . $mailcontent_admin . '</p>
                  </td>
                </tr>
              </table></td>
            </tr>
            <tr>
               <td align="center" bgcolor="#EAEAEA" class="footer">
                  <p>&nbsp;</p>
              </td>
            </tr>
       </table>

     </td>
   </tr>
</table>


</body>
</html>';


        $adminemail = getSettingsValue('site_email');


        $mailsent = mail($adminemail, $subject_admin, $mail_send_details_admin, $headers);

        // End 
        // Redirect User To View Cart Page

        if (isset($_POST['action']) && $_POST['action'] == 'checkout') {

            $sql_up1 = "SELECT cart_id  FROM  " . $tableprefix . "cart where visitor_cart_id ='" . session_id() . "'  ";

            $rs_up1 = mysql_query($sql_up1) or die(mysql_error());

            if (mysql_num_rows($rs_up1) > 0) {
                $sql_up_cart = "UPDATE  " . $tableprefix . "cart set user_id ='" . $_SESSION["sess_userid"] . "' where visitor_cart_id ='" . session_id() . "'  ";

                $rs_up_cart = mysql_query($sql_up_cart) or die(mysql_error());

                header("Location:checkout.php?reg=1");
                exit;
            } else {

                header("Location:index.php?reg=1");
                exit;
            }
        } else {
            // End 

            header("Location:index.php?reg=1");
            exit;
        }


        //$message = "Registration successfully completed! Please <a class=links href='login.php'><b>login here</b>.</a>";

        /* ----------Multicart2.0 Upgradation--------------- */

        if ($action != "") {
            $_SESSION["sess_username"] = $txtUserName;
            $_SESSION["sess_userid"] = $userid;
            if (!isVisitorCartEmpty(session_id())) {
                mergeVisitorCartToUserCart(session_id(), $userid);
            }

            if ($action == "checkout") {
                header("Location:viewcart.php?reg=1");
                exit;
            }
        }

        $txtUserName = "";
        $txtFirstName = "";
        $txtLastName = "";
        $txtAddress1 = "";
        $txtAddress2 = "";
        $txtCity = "";
        $txtState = "";
        $ddlCountry = "";
        $txtZIP = "";
        $txtEmail = "";
        $txtPhone = "";
        $txtFAX = "";
        $txtPassword = "";
        $registered = true;
    }
}

//echo $jscript;

$countrylist = makeCountryList();

/* display the active template */

$active_template = displayTemplate();


include "includes/htmltop.php";

/* Top File Name */

include_once ("includes/" . $active_template[0]);
?>

<script language="javascript" src="includes/function.js"></script>
<script src="./js/registration_ajax.js"></script>
<script src="./js/javascript_check_userside.js"></script>
<script>
    
    $(document).ready(function() {
          var testing = false;
           $('#btnRegister').on('click', function (e) {
                if($('#txtEmail').val()=='')
                    {
                        alert('<?php echo REG_EMAIL_LABEL; ?>');
                        $('#txtEmail').focus();
                        return false;
                    }
                    
                    if($('#txtEmail').val()!='')
                    {
                        var email = $('#txtEmail').val();
                        if(!echeck(email))
                        {
                           
                            $('#txtEmail').focus();
                            return false;
                        }
                       
                    }
                    
                    if($('#txtUserName').val()=='')
                    {
                        alert('<?php echo REG_USERNAME_LABEL; ?>');
                        $('#txtUserName').focus();
                        return false;
                    }
                     if($('#txtUserName').val()=='')
                    {
                        alert('<?php echo REG_USERNAME_LABEL; ?>');
                        $('#txtUserName').focus();
                        return false;
                    }
                     if($('#txtPassword').val()=='')
                    {
                        alert('<?php echo REG_PASSWORD_LABEL; ?>');
                        $('#txtPassword').focus();
                        return false;
                    }
                     if($('#txtCnfPassword').val()=='')
                    {
                        alert('<?php echo REG_CONFIRM_PASSWORD_LABEL; ?>');
                        $('#txtCnfPassword').focus();
                        return false;
                    }
                    if(($('#txtCnfPassword').val()!='') && ($('#txtPassword').val()!=''))
                    {
                        var txtPassword     = $('#txtPassword').val();
                        var ConfirmPassowrd = $('#txtCnfPassword').val();
                        if(ConfirmPassowrd!=txtPassword) {
                            alert('<?php echo REG_PASSWORD_MISMATCH_LABEL; ?>');
                            $('#txtCnfPassword').focus();
                            return false;
                         }
                    }
                    
                     if($('#txtFirstName').val()=='')
                    {
                        alert('<?php echo REG_FIRSTNAME_LABEL; ?>');
                        $('#txtFirstName').focus();
                        return false;
                    }
                    
                     if($('#txtLastName').val()=='')
                    {
                        alert('<?php echo REG_LASTNAME_LABEL; ?>');
                        $('#txtLastName').focus();
                        return false;
                    }
                     
                   return true;
            });
            
           $('#txtUserName').change(function(){
            var user_name =  $('#txtUserName').val();
            $.ajax({url: "<?php echo SITE_URL?>/user_registration_check_ajax.php?uname=" + user_name, success: function(data){
              var flag =data
                //alert(data);
                       if(flag=='1')
                           {
                               alert('<?php echo USER_ALREADY_EXISTS?>');
                               $('#txtUserName').val('');
                                $('#txtUserName').focus();
                               return false;
                           }
                }});
          });
            
            
           $('#txtEmail').change(function(){
            var email =  $('#txtEmail').val();
            $.ajax({url: "<?php echo SITE_URL?>/user_registration_check_ajax.php?email=" + email, success: function(data){
              var flag =data
                //alert(data);
                       if(flag=='1')
                           {
                               alert('<?php echo EMAIL_ALREADY_EXISTS?>');
                               $('#txtEmail').val('');
                                $('#txtEmail').focus();
                               return false;
                           }
                }});
          });
          
          
          
         
          
          
     });
    
</script>

<?php
if ($_POST['bill_state'] != '') {
    $bill_state = $_POST['bill_state'];
}
?>
<div class="main_body">
    <div class="container">
        <div class="row">			
            <!--mainbody area start -->

            <form name="frmRegister" action="" method="POST" id="frmRegister">
                <input type="hidden" name="action" value="<?php echo htmlentities($action); ?>">
                <!-- The id of the country field(s).  If more than one, seperate with spaces -->
                <input type="hidden" value="billCountrySelect" name="cs_config_country_field" id="cs_config_country_field">
                <input type="hidden" value="billStateSelect" name="cs_config_state_field"   id="cs_config_state_field">


                <!-- The id of the the fields holding the default values.  If more than one, seperate with spaces -->
                <input type="hidden" value="billCountryDefault" name="cs_config_country_default" id="cs_config_country_default">
                <input type="hidden" value="billStateDefault"   name="cs_config_state_default"   id="cs_config_state_default">
                <!-- The actual default values -->
                <input type="hidden" value="US" name="billCountryDefault" id="billCountryDefault">
                <input type="hidden" value="<?php echo $bill_state; ?>"   name="billStateDefault"   id="billStateDefault">
                <SCRIPT type="text/javascript" SRC="js/country-state.js"></SCRIPT>
                <div id="item_details">
                    <!--items display area start -->


                    <div class="col-sm-12 col-lg-4 col-md-4"></div>
                    <div class="col-sm-12 col-lg-4 col-md-4">
                        <div align="left" id="items_top_area">
                            <div align="center" id="items_top_area_ttl">
                                <?php echo USER_REGISTRATION_TEXT; ?>
                                <div class="clear"></div>
                            </div>
                        </div>
                        <div class="text_information" align="center"><?php echo $message ?></div>
                        <div class="clear"></div>
                        <?php
                        if (!$registered) {
                            ?>
                            <div class="form_wrapper">
                                <div class="register_form_outer">
                                    <div class="registrationform_container">
                                        <h3><?php echo SECURE_RELIABLE_TEXT; ?></h3>
                                        <p><?php echo SECURE_RELIABLE_MSG; ?></p>
                                        <div class="field_wrapper formfield_row">
                                            <input type="text" placeholder="<?php echo EMAIL_TEXT; ?>" value="<?php echo htmlentities($txtEmail); ?>"  class="form-control" name="txtEmail" size="55" maxlength="100" id="txtEmail">
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <input class="form-control" type="text" placeholder="<?php echo USER_NAME_TEXT; ?>" value="<?php echo ($txtUserName); ?>" name="txtUserName" id="txtUserName" size="55" maxlength="100">
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <input class="form-control" type="password" placeholder="<?php echo PASSWORD_TEXT; ?>" name="txtPassword"  size="55" maxlength="30" id="txtPassword" >
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <input class="form-control" type="password" placeholder="<?php echo PASSWORD_CONFIRM_TEXT; ?>" name="txtCnfPassword" size="55" maxlength="30" id="txtCnfPassword" >
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <input  class="form-control" type="text" placeholder="<?php echo FIRST_NAME_TEXT; ?>" value="<?php echo ($txtFirstName); ?>" name="txtFirstName" size="55" maxlength="100" id="txtFirstName">
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <input  class="form-control" type="text" placeholder="<?php echo LAST_NAME_TEXT; ?>" value="<?php echo ($txtLastName); ?>" name="txtLastName" size="55" maxlength="100" id="txtLastName">
                                        </div>

                                        <?php
                                        //$j for avoiding error only 	
                                        //echo $select_custom_fields = "SELECT * FROM ".$tableprefix."custom_fields WHERE vcustom_display_field = 'Y' AND vcustom_field_form_id ='".$j."' ORDER BY vcustom_sort_order ";
                                        $select_custom_fields = "SELECT * FROM " . $tableprefix . "custom_fields WHERE vcustom_display_field = 'Y' 
									 AND vcustom_delete_status != 'Y' ORDER BY vcustom_sort_order";
                                        $result_custom_fields = mysql_query($select_custom_fields) or die(mysql_error());

                                        while ($custom_field_row = mysql_fetch_array($result_custom_fields)) {

                                            if ($custom_field_row['vrequired_custom_field'] == 'Y') {

                                                $required_class = "field_wrapper_required";
                                            } else {

                                                $required_class = "field_wrapper";
                                            }

                                            $field_name = 'custom_field_' . $custom_field_row['ncustom_id'];
                                            ?>		

                                            <div class="<?php echo $required_class; ?> field_wrapper formfield_row">
                                            <!--<label><?php echo ucfirst($custom_field_row['vcustom_field_name']) ?></label>-->

                                                <?php
                                                if ($custom_field_row['vcustom_field_type'] == "text_box") {
                                                    ?>				

                                                    <input class="text_field" type="text" value="<?php echo $_POST[$field_name] ?>" name="<?php echo $field_name ?>" size="55" maxlength="30" placeholder="<?php echo $custom_field_row['vcustom_field_name'] ?>">

                                                    <?php
                                                } else {
                                                    ?>


                                                    <textarea name="<?php echo $field_name ?>" rows="5" cols="15" class="text_field" placeholder="<?php echo $custom_field_row['vcustom_field_name'] ?>"><?php echo $_POST[$field_name] ?></textarea>

                                                    <?php
                                                }
                                                ?>																													
                                            </div>


                                            <?php
                                        }
                                        ?>
                                        <div class="field_wrapper formfield_row" >
                                            <input type="checkbox" name="check_news" value="1" checked align="absmiddle" >
                                            <span style="vertical-align: bottom;line-height: 20px;"><label class="small_txt" style="display: inline;" ><?php echo NOTIFY_UPDATES_TEXT; ?></label></span>
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <div class="secondarypannel">
                                                <input type="hidden" name="artistid" value="<?php echo $artistid; ?>">
                                                <input type="hidden" name="action" value="<?php echo $action; ?>">
                                                <input type="hidden" name="productid" value="<?php echo $productid; ?>">	
                                                <input name="submit" type="submit" class="login_btn"  name="btnRegister" id="btnRegister" value="<?php echo CREATE_ACCOUNT_BUTTON;?>" tabindex="3" />
                                               
                                            </div>
                                        </div>
                                        <div class="field_wrapper formfield_row">
                                            <div class="forgot_row">
                                                <div class="login_btm_lnks"> <a href="forgotpassword.php" class="login_btm_lnks"><?php echo FORGOTPASSWORD_LINK_TEXT; ?> </a></div>
                                            </div>
                                        </div>
                                        <div class="clear"></div>
                                    </div>
                                    <div class="clear"></div>
                                </div>
                            </div>
                            <?php
                        }
                        ?>	

                    </div>
                    <div class="col-sm-12 col-lg-4 col-md-4"></div>

                    <div class="clear"></div>																						
                </div>
            </form>
        </div>
    </div>
    <div align="left" class="clear"></div>
    <?php
    include "includes/" . $active_template[2]; /* Bottom File Name */
    ?>