// JavaScript Document

var terms = true;
 
function show_result(z)
{
  document.getElementById('preloader').style.visibility = 'hidden';
  if(z == 1)
     document.getElementById('dv_1').innerHTML = "<font style='color:#fe0000'>This User ID is not available</font>";
  else
     document.getElementById('dv_1').innerHTML = "<font style='color:#99cc01'>This User ID is available</font>";	   
}

function show_result1(z)
{
  document.getElementById('preloader').style.visibility = 'hidden';
  
  if(z==1)
  {
     alert("This User ID is not available");
	 document.getElementById('dv_1').innerHTML = "<font style='color:#fe0000'>This User ID is not available</font>";  
  }
  else if(z==2)
     window.location = 'registered.php';	 
  else
     alert("We are unable to create your account. Please try again.");	 
}

function validate()
{
  var member = new Array();
  member[0]=document.getElementById("username").value + 'x|x';
  member[1]=document.getElementById("password").value + 'x|x';
  member[2]=document.getElementById("rpassword").value + 'x|x';
  scq=document.getElementById("sc_question");
  scq1=scq.options[scq.selectedIndex].text;
  member[3]=scq1 + 'x|x';
  member[4]=document.getElementById("sc_answer").value + 'x|x';
  member[5]=document.getElementById("fname").value + 'x|x';
  member[6]=document.getElementById("lname").value + 'x|x';
  gen=document.getElementById("gender");
  gen1=gen.options[gen.selectedIndex].text;
  member[7]=gen.options[gen.selectedIndex].text + 'x|x';
  member[8]=document.getElementById("dob").value + 'x|x';
  member[9]=document.getElementById("address").value + 'x|x';
  coun=document.getElementById("country");
  coun1=coun.options[coun.selectedIndex].text;
  member[10]=coun1 + 'x|x';
  if(coun1.match("Bangladesh")){
    dis=document.getElementById("district");
    member[11]=dis.options[dis.selectedIndex].text + 'x|x';
  }
  else
    member[11]=document.getElementById("city").value + 'x|x';
  member[12]=document.getElementById("code").value + 'x|x';
  member[13]=document.getElementById("phone").value + 'x|x';
  member[14]=document.getElementById("email").value + 'x|x,';
  var at=document.getElementById("email").value.indexOf("@");
  
  submitOK="true";
  
  if(member[0].length<4)
  {
    alert("User ID field can't be blank");
    submitOK="false";
    document.getElementById("username").focus();
    return false;
  }
  
  if(member[1].length<4)
  {
    alert("Password field can't be blank");
    submitOK="false";
    document.getElementById("password").focus();
    return false;
  }
  
  if(member[1].length<9)
  {
    alert("The password size should be minimum 6 characters");
    submitOK="false";
    document.getElementById("password").focus();
    return false;
  }
  
  if(member[2].length<4)
  {
    alert("Re-type password field can't be blank");
    submitOK="false";
    document.getElementById("rpassword").focus();
    return false;
  }
  
  if(member[1] != member[2])
  {
    alert("Password can't match")
    document.getElementById("rpassword").focus()
    return false
  }
  
  if(scq1.match("--- Select One ---"))
  {
    alert("Select one security question");
    document.getElementById("sc_question").focus();
    submitOK="false";
    return false;
  }
  
  if(member[4].length<4)
  {
    alert("Answer field can't be blank");
    submitOK="false";
    document.getElementById("sc_answer").focus();
    return false;
  }
  
  if(member[5].match("First Name") || member[5].length<4)
  {
    alert("First name field can't be blank");
    submitOK="false";
    return false;
  }
   
  if(member[6].match("Last Name") || member[6].length<4)
  {
    alert("Last name field can't be blank");
    submitOK="false";
    return false;
  }
  
  if(gen1.match("Select"))
  {
    alert("Select your gender");
    document.getElementById("gender").focus();
    submitOK="false";
    return false;
  }
  
  if(member[8].length<4)
  {
    alert("Date of Birth field can't be blank");
    submitOK="false";
    document.getElementById("dob").focus();
    return false;
  }
  
  if(member[9].length<4)
  {
    alert("Street address field can't be blank");
    submitOK="false";
    document.getElementById("address").focus();

    return false;
  }
  
  if(!coun1.match("Bangladesh"))
  {
    if(member[11].length<4)
	{
	   alert("City field can't be blank");
       submitOK="false";
       document.getElementById("city").focus();
       return false;
	}
  }
  
  if(member[12].length<4)
  {
    alert("Postal Code field can't be blank");
    submitOK="false";
    document.getElementById("code").focus();
    return false;
  }
  
  if(member[13].length<4)
  {
    alert("Contact Phone field can't be blank");
    submitOK="false";
    document.getElementById("phone").focus();
    return false;
  }
  
  if(member[14].length<5)
  {
    alert("E-mail field can't be blank");
    submitOK="false";
    document.getElementById("email").focus();
    return false;
  }
  
  if(at==-1)
  {
    alert("Not a valid e-mail address!");
    submitOK="false";
    document.getElementById("email").focus();
    return false;
  }
  
  if(!terms)
  {
    alert("Please accept the user agreement and privacy policy.");
    submitOK="false";
    return false;
  }
  
  if(submitOK=="false")
     return false;
  else
  {
     for(i=0;i<member.length;i++)
	 {
	     while(member[i].indexOf("+")!=-1)
		       member[i]=member[i].replace("+","&plus;");
	 }
	 
	 document.getElementById('preloader').style.visibility = 'visible';
     document.getElementById('preloader').innerHTML = 'Please wait ...';
	 x_insert_member(member,show_result1);
  }	 
}

function check(value)
{
    terms = value; 
}

function display_first()
{
  text=document.getElementById("fname").value
  
  if(text.match("First Name"))
  {
     document.getElementById("fname").value = "";
	 document.getElementById("fname").style.color = '#545454';
  }	 
}
 
function display_last()
{
  text=document.getElementById("lname").value
  
  if(text.match("Last Name"))
  {
     document.getElementById("lname").value = "";
	 document.getElementById("lname").style.color = '#545454';
  }
}

function valid_user()         
{
  var user=document.getElementById("username").value;
  
  submitOK="true";

  if(user.length<1)
  {
    alert("User ID field can't be blank");
    submitOK="false";
    document.getElementById("username").focus();
    return false;
  }

  if(submitOK=="false")
  {
    return false;
  }
  else
  {	
	while(user.indexOf("+")!=-1)
		  user=user.replace("+","&plus;");
	 
	document.getElementById('preloader').style.visibility = 'visible';
    document.getElementById('preloader').innerHTML = 'Checking ...';
	x_check_user(user,show_result);
  }
}

function show_city()
{
   var coun=document.getElementById("country");
   var coun1=coun.options[coun.selectedIndex].text;
   
   if(coun1.match("Bangladesh"))
   {
	  document.getElementById('dv_2').innerHTML = "District";
	  document.getElementById('dv_3').innerHTML = "<select name='district' id='district' style='width:110px;' class='drop'><option>B. Baria</option><option>Bagerhat</option><option>Bandarban</option><option>Barisal</option><option>Bhola</option><option>Bogra</option><option>Borguna</option><option>Chandpur</option><option>Chapainawabganj</option><option>Chittagong</option><option>Chuadanga</option><option>Comilla</option><option>Cox's Bazar</option><option selected='selected'>Dhaka</option><option>Dinajpur</option><option>Faridpur</option><option>Feni</option><option>Gaibandha</option><option>Gazipur</option><option>Gopalgonj</option><option>Hobigonj</option><option>Jamalpur</option><option>Jessore</option><option>Jhalokathi</option><option>Jhenaidah</option><option>Joypurhat</option><option>Khagrachari</option><option>Khulna</option><option>Kishorgonj</option><option>Kurigram</option><option>Kushtia</option><option>Lalmonirhat</option><option>Laxmipur</option><option>Madaripur</option><option>Magura</option><option>Manikgonj</option><option>Meherpur</option><option>MoulaviBazar</option><option>Munshigonj</option><option>Mymensingh</option><option>Naogaon</option><option>Narail</option><option>Narayangonj</option><option>Narshingdi</option><option>Natore</option><option>Netrokona</option><option>Nilphamari</option><option>Noakhali</option><option>Pabna</option><option>Panchagahr</option><option>Patuakhali</option><option>Pirojpur</option><option>Rajbari</option><option>Rajshahi</option><option>Rangamati</option><option>Rangpur</option><option>Satkhira</option><option>Shariatpur</option><option>Sherpur</option><option>Sirajgonj</option><option>Sunamgonj</option><option>Sylhet</option><option>Tangail</option><option>Thakurgaon</option></select>"; 
   }
   else
   {
	  document.getElementById('dv_2').innerHTML = "City";
	  document.getElementById('dv_3').innerHTML = "<input type='text' name='city' id='city' class='textbox' style='width:106px;'/>";
   }  
}