<?
	include("config/connect.php");
	//include("sendmail.php");
	include("functions.php");

	if($_GET["ref"]!="")
	{
		$_SESSION["refid"] = $_GET["ref"];
	}
	if($_SESSION["refid"]){
		$refid = $_SESSION["refid"];
	}else{
		$refid = 0;
	}

	if($_POST["username"]!="")
	{
		$username = $_POST["username"];
		$gender = $_POST["gender"];
		$fname = $_POST["firstname"];
		$lname = $_POST["lastname"];
		$bdate = setdate($_POST["month"],$_POST["date"],$_POST["year"]);
//		$bdate = $_POST["month"]."-".$_POST["date"]."-".$_POST["year"];
		$pass = $_POST["password"];
		$email = $_POST["email"];
		$mobile = $_POST["mobileno"];
		$terms = $_POST["terms"];
		$privacy = $_POST["privacy"];		
		$news = $_POST["newslatter"];
		$rndcode = strtolower($_POST["rndcode"]);
		$countryinfo = explode("|",$_POST["countrycode"]);
		$countrycode = $countryinfo[0];
		$countryID = $countryinfo[1];
		$fullmobile = "+".$countrycode.$mobile;
		
		$addressline1 = $_POST["addressline1"];
		$addressline2 = $_POST["addressline2"];
		$city = $_POST["city"];
		$state = $_POST["state"];
		$phoneno = $_POST["phoneno"];
		$postcode = $_POST["postcode"];
		
// user duplication check

		$qrysel = "select * from registration where username='$username' or email='$email'";
		$ressel = mysql_query($qrysel);
		$totalrows = mysql_affected_rows();
		$obj = mysql_fetch_object($ressel);
		if($totalrows>0)
		{
			if($email==$obj->email)
			{
			$err=1;
			}
			else
			{
			$err=2;
			}
		}
		elseif($_SESSION['security_code']!=$rndcode)
		{
			$err3=3;
		}
// end duplication check
		else
		{
			$verifycode = md5($username);
		$qryins = "Insert into registration (username, firstname, lastname, sex,birth_date, email, password, terms_condition, privacy, newslatter,sponser,mobile_no,register_date,country,full_mobileno,addressline1,addressline2,city,state,phone,verify_code,postcode) values('$username','$fname','$lname','$gender','$bdate','$email','$pass','$terms','$privacy','$news','$refid','$mobile',NOW(),'$countryID','$fullmobile','$addressline1','$addressline2','$city','$state','$phoneno','$verifycode','$postcode')";
		//echo $qryins;
		mysql_query($qryins) or die(mysql_error());
		$_SESSION["uid"] = mysql_insert_id();

		$uid = $_SESSION["uid"];
		
		$auction_username = $username;
		$auction_userid = $_SESSION["uid"];
//		$encode_userid = base64_encode($_SESSION["uid"]);
//		$encode_username = base64_encode($username);
//		$encode_password = base64_encode($pass);

		$emailcont1 = sprintf($lng_emailcontent_registraion,$fname,$auction_username,$auction_userid,$verifycode);
		
		$subject=$lng_mailsubjectaccinfo;
		$from="";
		//$from=$adminemailadd;
		
		SendHTMLMail($email,$subject,$emailcont1,$from);

//		header("location: registration.php");
		}
	}	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?=$lng_characset;?>" />
<title><?=$AllPageTitle;?></title>
<!--LINK media=screen href="css/library.css" type=text/css rel=stylesheet-->
<!--LINK media=screen href="css/index.css" type=text/css rel=stylesheet-->
<link href="css/style_youbid.css" rel="stylesheet" type="text/css" />
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
<link href="css/menu_ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script language="javascript" src="pwd_strength.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript" src="function.js"></script>
<script language="javascript" type="text/javascript" src="basic.js"></script>
<script language="javascript">
function Check()
{
	/*
	if(document.registration.firstname.value=="")
	{
		alert("<?=$lng_regenterfirstname;?>");
		document.registration.firstname.focus();
		return false;
	}
	
	if(document.registration.lastname.value=="")
	{
		alert("<?=$lng_regenterlastname;?>");
		document.registration.lastname.focus();
		return false;
	}
	
	if(document.registration.date.value=="dd")
	{
		alert("<?=$lng_regselbirthdate;?>");
		document.registration.date.focus();
		return false;
	}
	
	if(document.registration.month.value=="mm")
	{
		alert("<?=$lng_regselbirthdate;?>");
		document.registration.month.focus();
		return false;
	}
	
	if(document.registration.year.value=="yyyy")
	{
		alert("<?=$lng_regselbirthdate;?>");
		document.registration.year.focus();
		return false;
	}
	
	if(document.registration.addressline1.value=="")
	{
		alert("<?=$lng_regenteraddress;?>");
		document.registration.addressline1.focus();
		return false;
	}
	
	if(document.registration.city.value=="")
	{
		alert("<?=$lng_regentercity;?>");
		document.registration.city.focus();
		return false;
	}

	if(document.registration.state.value=="")
	{
		alert("ÇëÊäÈëÊ¡!");
		document.registration.state.focus();
		return false;
	}

	if(document.registration.postcode.value=="")
	{
		alert("<?=$lng_regenterpostcode;?>");
		document.registration.postcode.focus();
		return false;
	}
  */
	if(document.registration.phoneno.value=="")
	{
		alert("<?=$lng_regenterphoneno;?>");
		document.registration.phoneno.focus();
		return false;
	}

	if(document.registration.username.value.length < 6)
	{
		alert("<?=$lng_regusernametooshort;?>");
		document.registration.username.focus();
		document.registration.username.select();
		return false;
	}
	
	if(document.registration.password.value=="")
	{
		alert("<?=$lng_regenterpassword;?>");
		document.registration.password.focus();
		return false;
	}
	
	if(document.registration.password.value.length<6)
	{
		alert("<?=$lng_regpasstooshort;?>");
		document.registration.password.focus();
		return false;
	}
	
	if(document.registration.cnfpassword.value=="")
	{
		alert("<?=$lng_regconfpassword;?>");
		document.registration.cnfpassword.focus();
		return false;
	}
	
	if(document.registration.password.value!=document.registration.cnfpassword.value)
	{
		alert("<?=$lng_regpassmismatch;?>");
		document.registration.cnfpassword.focus();
		return false;
	}
	
	if(document.registration.email.value=="")
	{
		alert("<?=$lng_regenteremailadd;?>");
		document.registration.email.focus();
		return false;
	}
	else
	{
		if(!validate_email(document.registration.email.value,"<?=$lng_entervalidemail;?>"))
			{
				document.registration.email.select();
				return false;
			}
	}
	if(document.registration.cnfemail.value=="")
	{
		alert("<?=$lng_regenterconfemail;?>");
		document.registration.cnfemail.focus();
		return false;
	}
	
	if(document.registration.email.value!=document.registration.cnfemail.value)
	{
		alert("<?=$lng_regemailmismatch;?>");
		document.registration.cnfemail.focus();
		return false;
	}
	
	if(document.registration.terms.checked!=true)
	{
		alert("<?=$lng_regreadterms;?>");
		document.registration.terms.focus();
		return false;
	}
	
	if(document.registration.privacy.checked!=true)
	{
		alert("<?=$lng_regreadprivacy;?>");
		document.registration.privacy.focus();
		return false;
	}
	
	if(document.registration.rndcode.value=="")
	{
		alert("<?=$lng_regenterseccode;?>");
		document.registration.rndcode.focus();
		return false;
	}
//	document.registration.submit();
}

	function validate_email(field,alerttxt){
		with (field){
			var value;
			value = document.registration.email.value;
			apos=value.indexOf("@");
			dotpos=value.lastIndexOf(".");
			if (apos<1||dotpos-apos<2){
				alert(alerttxt);return false;
			}else{
				return true;
			}
		}
	}
</script>
</head>

<body>
<div id="main_div">
<?
	include("header.php");
?>
		<div id="middle_div">
		<div class="openAuction_bar_mainDIV">
			<div class="openAction_bar-left"></div>
			<div class="openAction_bar-middle"><div class="page_title_font"><?=$lng_tabregister;?></div></div>
			<div class="openAction_bar-right"></div>
		 </div>
		 <div class="openAuction_bar_mainDIV2">
<?
	if($_SESSION["uid"]=="")
	{
?>
	 <div style="height: 20px;">&nbsp;</div>
		  <!--ul style="text-align: left;">
			  <li><?=$lng_frregistration;?></li>
			  <li><?=$lng_vouchermessage;?></li>
			  <li><?=$lng_amazingproducts;?></li>
		  </ul>
		  <p>&nbsp;</p>
		  <p align="left" style="padding-left: 50px;"><font size="+1"><?=$lng_registrationdata;?>:</font></p-->
			<?
				if($err!="")
				{
					$errr = $err;
			?>
				<p align="left" style="margin-top: 25px; padding-left: 50px;" class="red-text-12-b"><?=$errr==1?$lng_emailexists:$lng_usernameexists;?></p>
			<?
				}
				if($err3!="")
				{
			?>		
					<p align="left" style="margin-top: 35px; padding-left: 50px;" class="red-text-12-b"><?=$lng_correctcode;?></p>
			<?		
				}
			?>
		  <div style="height: auto; text-align: left;">
		  <form id="registration" name="registration" method="post" action="registration.php">				  
			<!--div style="height: 20px;">&nbsp;</div>
			<div class="register-form"><h4><?=$lng_personalinfo;?></h4></div>
			<div class="register-form">
					<div class="box">
					<div class="row"><strong><?=$lng_firstname;?></strong></div>
					<div class="row"><input type="text" class="input" name="firstname" maxlength="100" value="<?=$fname!=""?$fname:"";?>" /></div>				
					</div>
					<div class="box">
					<div class="row"><strong><?=$lng_lastname;?></strong></div>
					<div class="row"><input type="text" class="input" name="lastname" maxlength="100" value="<?=$lname!=""?$lname:"";?>" /></div>				
					</div>
													
			 </div>	
			<div class="register-form">
<div class="box">
					<div class="row"><strong><?=$lng_birthdate;?></strong></div>
					<div class="row">
					<select size="1" style="width:45px" name="date">
				        <option value="dd">DD</option>
							<?
								for($i=1;$i<=31;$i++)
								{
							?>
							  <option <?=$_POST["date"]==$i?"selected":"";?> value="<?=$i<=9?"0".$i:$i;?>"><?=$i<=9?"0".$i:$i;?></option>
							 <?
								}
							 ?>
		            </select>
					<select size="1" style="width:75px" name="month">
						<option selected="selected" value="mm">MM</option>
						<option <?=$_POST["month"]=="01"?"selected":"";?> value="01">January</option>
						<option <?=$_POST["month"]=="02"?"selected":"";?> value="02">February</option>
						<option <?=$_POST["month"]=="03"?"selected":"";?> value="03">March</option>
						<option <?=$_POST["month"]=="04"?"selected":"";?> value="04">April</option>
						<option <?=$_POST["month"]=="05"?"selected":"";?> value="05">May</option>
						<option <?=$_POST["month"]=="06"?"selected":"";?> value="06">June</option>
						<option <?=$_POST["month"]=="07"?"selected":"";?> value="07">July</option>
						<option <?=$_POST["month"]=="08"?"selected":"";?> value="08">August</option>
						<option <?=$_POST["month"]=="09"?"selected":"";?> value="09">September</option>
						<option <?=$_POST["month"]=="10"?"selected":"";?> value="10">October</option>
						<option <?=$_POST["month"]=="11"?"selected":"";?> value="11">Nevember</option>
						<option <?=$_POST["month"]=="12"?"selected":"";?> value="12">December</option>
            </select>
			<select name="year">
              <option selected="selected" style="width:40px" value="yyyy">YYYY</option>
					<?
						for($i=1950;$i<=2020;$i++)
						{
					?>
					  <option <?=$_POST["year"]==$i?"selected":"";?> value="<?=$i;?>"><?=$i;?></option>
					 <?
						}
					 ?>
		    </select>
					</div>
					</div>
					<div class="box">
					<div class="row"><strong>&nbsp;&nbsp;<?=$lng_gender;?></strong></div>
					<div class="row">&nbsp;
						<select size="1" style="width:60px" name="gender">
							<option selected="selected" value="Male"><?=$lng_male;?></option>
							<option <?=$gender=="Female"?"selected":"";?> value="Female"><?=$lng_female;?></option>
			            </select>
					</div>		
					</div>								
			 </div>	
			<div class="register-form">
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_addressline1;?></strong></div>
					<div class="row"><input type="text" class="input" name="addressline1" maxlength="100" value="<?=$addressline1!=""?$addressline1:"";?>" /></div>
				</div>				
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_addressline2;?></strong></div>
					<div class="row"><input type="text" class="input" name="addressline2" maxlength="100" value="<?=$addressline2!=""?$addressline2:"";?>" /></div>
				</div>
			 </div>	
			<div class="register-form">
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_towncity;?></strong></div>
					<div class="row"><input type="text" class="input" name="city" maxlength="100" value="<?=$city!=""?$city:"";?>" /></div>
				</div>
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_postcode;?></strong></div>
					<div class="row"><input type="text" class="input" name="postcode" maxlength="100" value="<?=$postcode!=""?$postcode:"";?>" /></div>
				</div>						
			 </div>	
			<div class="register-form">
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_country;?></strong></div>
					<div class="row">
					  <select name="countrycode" style="width: 268px;">
					  	<?
							$qrycou = "select * from countries order by printable_name";
							$rescou = mysql_query($qrycou);
							$totalcou = mysql_num_rows($rescou);
							for($i=1;$i<=$totalcou;$i++)
							{
								$country = mysql_fetch_object($rescou);
						?>
						<option value="<?=$country->countrycode."|".$country->countryId;?>"><?=$country->printable_name;?></option>
						<?
							}
						?>
					  </select>
					</div>
				</div>			
				<div class="box">
					<div class="row" style="margin-top: 10px;"><strong><?=$lng_phoneno;?></strong></div>
					<div class="row"><input type="text" class="input" name="phoneno" maxlength="100" value="<?=$phoneno!=""?$phoneno:"";?>" /></div>
				</div>				
			 </div>	

			<div style="height: 20px;">&nbsp;</div>
			<div class="register-form"><h4><?=$lng_logininfo;?></h4></div-->
			<div class="register-form" style="height: auto">
				<div class="box">
					<div class="row"><strong><?=$lng_username;?></strong></div>
					<div class="row">
					  <? if($errr==2){ ?>					
						<input name="username" type="text" class="input" maxlength="16" />
					  <? } else { ?>
						<input name="username" type="text" class="input"  maxlength="16" value="<?=$username!=""?$username:"";?>" />
					  <? } ?>	
					</div>	
					<div class="row"><?=$lng_characterlong;?> </div>			
					<div class="row" style="padding-top:5px"><strong><?=$lng_mobilenumber;?></strong></div>	
					<div class="row"><input name="mobileno" type="text" class="input" maxlength="20" value="<?=$mobile!=""?$mobile:"";?>" /></div>
				</div>			
				<div class="box">
					<div class="row"><strong><?=$lng_password;?></strong></div>
					<div class="row"><input name="password" type="password" maxlength="16" value="<?=$pass!=""?$pass:"";?>" class="input" onkeyup="pwd_test_password(this.value);" /></div>
					<div class="row"><?=$lng_characterlong;?> </div>
					<div class="row" style="padding-top:5px"><strong><?=$lng_retypepassword;?></strong></div>	
					<div class="row"><input name="cnfpassword" type="password" class="input" maxlength="16" value="<?=$pass!=""?$pass:"";?>" /></div>
					<div class="row">
					<!--div style="float:left; padding-top:10px"><?=$lng_passsecurity;?>:</div>
					<div style="background:url(images/securty-bg.gif) no-repeat 5px; width:123px; height:28px; float:left;"-->
				  <div style="width: 100px; margin-left: 10px; margin-top: 4px;"> 
					<div id="pwd_text" style="font-size: 10px;"></div>
					<div id="pwd_bar" style="font-size: 1px; height: 5px; width: 0px; border: 1px solid white;"></div> 
				  </div>
					</div>
					</div>
				</div>				
			 </div>	
			<div class="register-form" style="padding-top: 10px;">
				<div class="box">
					<div class="row"><strong><?=$lng_emailaddress;?></strong></div>
					<div class="row">
					<? if($errr==1){ ?>		
					  <input name="email" type="text" class="input" maxlength="150" />
				    <? } else { ?>
					  <input name="email" type="text" class="input" maxlength="150" value="<?=$email!=""?$email:"";?>" />
				    <? } ?>
					</div>
				</div>			
				<div class="box">
					<div class="row"><strong><?=$lng_confirmemail;?></strong></div>
					<div class="row">
					 <? if($errr==1){ ?>		
					  <input name="cnfemail" type="text" class="input" maxlength="150" />
					 <? } else { ?>
					  <input name="cnfemail" type="text" class="input" maxlength="150" value="<?=$email!=""?$email:"";?>" />
					 <? } ?>
					</div>				
					</div>				
			 </div>	
			 <div class="register-form" style="height: auto">
				  <div style="height: 25px;"><?=$lng_picturecharct;?> </div>
				  <div style="height: 85px;"><img src="CaptchaSecurityImages.php?width=250&height=100&character=6"  width="175" height="70" class="security-image" border="1" /></div>
				  <div style="height: 35px;"><span class="row">
					<input name="rndcode" type="text" class="input" style="width:173PX" />
				  </span></div>
				  <div style="height: 25px;"><?=$lng_casesensitive;?></div>
				  <div style="height: 25px;"><input class="checkbox" type="checkbox" name="terms" value="1" checked /><?=$lng_acceptterms;?></div>
				  <div style="height: 25px;"><input class="checkbox" type="checkbox" name="privacy" value="1" checked /><?=$lng_acceptprivacy;?></div>
				  <div style="height: 25px;"><input class="checkbox" type="checkbox" name="newslatter" value="1" checked /><?=$lng_acceptnewsletter;?></div>
				  <div></div>
		   	  </div>			 
			  <div style="height: 15px;">&nbsp;</div>
			 <div class="register-form" style="padding-left: 55px;">
			 	<input type="image" src="<?=$lng_imagepath;?>register_btn1.gif" onmouseover="this.src='<?=$lng_imagepath;?>register_btn-hover1.gif'" onmouseout="this.src='<?=$lng_imagepath;?>register_btn1.gif'" name="register"  onclick="return Check();" />
		     </div>			  
		</form>
		</div>
<?
	}
	else
	{
		$qrys = "select email from registration where id='".$_SESSION["uid"]."'";
		$ress = mysql_query($qrys);
		$rows = mysql_fetch_object($ress);
?>
		<div style="height: 25px;">&nbsp;</div>
		<div style="padding-left: 30px; width: 800px; float: left">
			<p align="justify"><?=$lng_confirmregister;?></p> 
			<p align="justify"><?=$lng_sentemailto;?><?=$rows->email;?></p>
			<p align="justify"><?=$lng_registernote;?></p>
			<p align="justify" class="red-text-12-b"><?=$lng_importantword;?></p>
			<p align="justify"><?=$lng_dontreceivenote;?></p>
		<div style="height: 25px;">&nbsp;</div>
		</div>
<?
		unset($_SESSION["uid"]);	
	}
?>
		 </div>
		 <div id="cleaner"></div>
		 <div class="openAuction_bar_bottom">
		 	<div class="openAuction_leftcorner"></div>
			<div class="openAuction_bar_middle"></div>
		 	<div class="openAuction_rightcorner"></div>
		 </div>
		
<?
	include("footer2.php");
?>		
</div>
</body>
</html>
