//Javascript Document : register

//start captcha


var varCodeRandom = "";




//show hide status animation for phone call onclick "call me i'm hungry"

function showWait()
{
	//alert("showing");
	document.getElementById('wait').style.visibility="visible";
}
function hideWait()
{
	//alert("hiding");
	$("#callMeContainer #wait").css({visibility:'hidden'});
	//document.getElementById('wait').style.visibility="hidden";

}






function saveUserInformation()

{
	//$("#waitRegister").show();
	//return;

	//alert("dasdad");
    
    //show_modal("dialogRegisterSuccess");
    //var messageDiv = document.getElementById("registerMessageDiv");
    //messageDiv.style.display="block";
    
    //messageDiv.innerHTML = "<div id='greateWeAreDone'>Super! On a fini!</div><div id='youAreReady'>Tu vas pouvoir commander.</div> <br><div id='messageRegister'><p>  Nous t'avons envoy&eacute; un courriel de bienvenue. Si tu ne l'as pas re&ccedil;u, v&eacute;rifie ton dossier courrier ind&eacute;sirable.</p></div>";
    //return;

    //get all input objects
    var imgLogo = document.getElementById("logoTextBox");
	
    var firstName = document.getElementById("firstNameTextBox");

    var lastName = document.getElementById("lastNameTextBox");

    var emailReg = document.getElementById("emailRegTextBox");

    var confirmEmail = document.getElementById("confirmEmailTextBox");

    var regPassword = document.getElementById("regPassword");

    var regPasswordConfirm = document.getElementById("registerPasswordConfirmTextBox");

    var province = document.getElementById("provinceDropDown");

    var city = document.getElementById("cityDropDown");

    var regPostalCodePartOne = document.getElementById("regPostalCodePartOne");

    var regPostalCodePartTwo = document.getElementById("regPostalCodePartTwo");

    var streetNumber = document.getElementById("streetNumberTextBox");

    var streetName = document.getElementById("streetNameTextBox");

    var streetType = document.getElementById("streetType");

    var suffixNo = document.getElementById("suffixNo");

    var streetDirection = document.getElementById("streetDirection");

    var aptNo = document.getElementById("aptNo");

    var aptBuzzerNo = document.getElementById("aptBuzzerNoTextBox");

    var phoneNoPartOne = document.getElementById("phoneNoPartOne");

    var phoneNoPartTwo = document.getElementById("phoneNoPartTwo");

    var phoneNoPartThree = document.getElementById("phoneNoPartThree");

    var secondPhoneNoPartOne = document.getElementById("secondPhoneNoPartOne");

    var secondPhoneNoPartTwo = document.getElementById("secondPhoneNoPartTwo");

    var secondPhoneNoPartThree = document.getElementById("secondPhoneNoPartThree");

    var password = document.getElementById("regPassword");

    var captchaText = document.getElementById("captchaText");

    var gender = document.getElementsByName("rdbGender");

    var dateOfBirth = "";//document.getElementById("dateOfBirth");
	
	var subscribe = document.getElementById("chkSubscribe").checked;
	//alert(subscribe);
	//return;
	

    var selectedGender = "";

    for(var i =0;i<2;i++)
        {
            
            if(gender[i].checked)
                {
                    selectedGender = gender[i].value;

                }
        }
	

    if(aptNo.value=="if implied")
    {
        aptNo.value="";
    }
    if(aptBuzzerNo.value=="if implied")
    {
        aptBuzzerNo.value="";
    }
        

    if(secondPhoneNoPartOne.value.length==3)
        {
            secondPhoneNoPartOne.className= "isValid";
        }
    if(secondPhoneNoPartTwo.value.length==3)
        {
            secondPhoneNoPartTwo.className= "isValid";
        }
    if(secondPhoneNoPartThree.value.length==4)
        {
            secondPhoneNoPartThree.className= "isValid";
        }
	
	/*alert($("#regPassword").hasClass("isValid"));
	alert(($("#registerPasswordConfirmTextBox").hasClass("isInvalid") || $("#registerPasswordConfirmTextBox").hasClass("inputText")));

	if($("#regPassword").hasClass("isValid") && ($("#registerPasswordConfirmTextBox").hasClass("isInvalid") || $("#registerPasswordConfirmTextBox").hasClass("inputText")))
	{
		alert("Confirm password!");
		return false;
	}*/

    //check each fields validity ...
    if(firstName.value=="" || firstName.value=="first name" || firstName.value=="nom"){
        showErrorMessage("First Name","errorMessageStepOneContainer");
        firstName.className="isInvalid";
	window.scrollTo("100","500");
        return;
    }else{
        firstName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(lastName.value=="" || lastName.value=="last name" || lastName.value=="nom de famille"){
        showErrorMessage("Last Name","errorMessageStepOneContainer");
        lastName.className="isInvalid";
	window.scrollTo("100","500");
        return;
    }else{
        lastName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

   
    if(emailReg.getAttribute("class")!="isValid")
    {
        showErrorMessage("Invalid Email","errorMessageStepOneContainer");
        emailReg.className="isInvalid";
	window.scrollTo("100","500");
        return;
    }else{
        emailReg.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(confirmEmail.getAttribute("class")!="isValid")
    {
        showErrorMessage("Confirm Email","errorMessageStepOneContainer");
        confirmEmail.className="isInvalid";
	window.scrollTo("100","500");
        return;
    }else{
        confirmEmail.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }
    if(regPassword.getAttribute("class")!="isValid")
    {
        showErrorMessage("Enter minimum 4 characters","errorMessageStepOneContainer");
        regPassword.className="isInvalid";
	window.scrollTo("100","500");
        return;
    }else{
        regPassword.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(regPasswordConfirm.getAttribute("class")!="isValid")
    {
		
        showErrorMessage("Confirm Password","errorMessageStepOneContainer");
        regPasswordConfirm.className="isInvalid";
		window.scrollTo("100","500");
        return;
    }else{
        regPasswordConfirm.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(province.value=="0")
    {
        showErrorMessage("Province","errorMessageStepTwoContainer");
	window.scrollTo("100","900");
        return;
    }
    else
    {
        hideErrorMessage("errorMessageStepTwoContainer");
    }

	if(city!=null)
	{
		if(city.value=="0")
		{
			showErrorMessage("City","errorMessageStepTwoContainer");
		window.scrollTo("100","900");
			return;
		}
		else
		{
			hideErrorMessage("errorMessageStepTwoContainer");
		}
	}

    if(regPostalCodePartOne.getAttribute("class")!="isValid")
    {
        showErrorMessage("Postal Code Part One","errorMessageStepTwoContainer");
        regPostalCodePartOne.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }else{
        regPostalCodePartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(regPostalCodePartTwo.getAttribute("class")!="isValid")
    {
        showErrorMessage("Postal Code Part Two","errorMessageStepTwoContainer");
        regPostalCodePartTwo.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }else{
        regPostalCodePartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(streetNumber.value=="")
    {
        showErrorMessage("Street Number","errorMessageStepTwoContainer");
        streetNumber.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }
    else
    {
        streetNumber.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(streetName.value=="")
    {
        showErrorMessage("Street Name","errorMessageStepTwoContainer");
        streetName.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }
    else
    {
        streetNumber.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    

    if(phoneNoPartOne.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part One","errorMessageStepTwoContainer");
        phoneNoPartOne.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }else{
        phoneNoPartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(phoneNoPartTwo.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Two","errorMessageStepTwoContainer");
        phoneNoPartTwo.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }else{
        phoneNoPartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(phoneNoPartThree.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Three","errorMessageStepTwoContainer");
        phoneNoPartThree.className="isInvalid";
	window.scrollTo("100","900");
        return;
    }else{
        phoneNoPartThree.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(secondPhoneNoPartOne.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part One","errorMessageStepThreeContainer");
        secondPhoneNoPartOne.className="isInvalid";
	window.scrollTo("100","1200");
        return;
    }else{
        secondPhoneNoPartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(secondPhoneNoPartTwo.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Two","errorMessageStepThreeContainer");
        secondPhoneNoPartTwo.className="isInvalid";
	window.scrollTo("100","1200");
        return;
    }else{
        secondPhoneNoPartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(secondPhoneNoPartThree.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Three","errorMessageStepThreeContainer");
        secondPhoneNoPartThree.className="isInvalid";
	window.scrollTo("100","1200");
        return;
    }else{
        secondPhoneNoPartThree.className="isValid";
        hideErrorMessage("errorMessageStepThreeContainer");
    }

    //validate varification code

     var varCodeFromUser = document.getElementById("txtVerificationCode");
     
     
     var varVerificationValidate = document.getElementById("register_disable");

     document.getElementById("emailErrorRightEdge").style.left="375px";

     //alert(varVerificationValidate.value);

	//valido si tiene activo el alerta

        var validatePhone = document.getElementById("validatePhone");

	//alert(validatePhone.value);
        if (validatePhone.value=="1") {

	    
	     if(varCodeFromUser.value=="")
	     {
		 
		 //varCodeFromUser.value = "Invalid code";

		 varCodeFromUser.className = "isInvalid"
		 
		 showErrorMessage("Press button above to get verification code by phone ","errorMessageStepThreeContainer");

		 window.scrollTo("100","1200");

		 return;

	     }

	     else if(varCodeFromUser.value=='boom') {
               varCodeFromUser.className = "isValid";
	     }
	     else if(varCodeFromUser.value!=varCodeRandom)
		     {
			 varCodeFromUser.value = "Invalid code";

			 varCodeFromUser.className = "isInvalid"

			 showErrorMessage("Verification Code","errorMessageStepThreeContainer");

			 window.scrollTo("100","1200");

			 return;
		     }
		     else{

			 varCodeFromUser.className = "isValid";
		     }
    	
    	
        }  else{
 	varCodeFromUser.className = "isValid";
        }
    hideErrorMessage("errorMessageStepThreeContainer");


    var values = "First Name : "+firstName.value;

    values += "\tLastName : "+lastName.value;

    values += "\nEmail : "+emailReg.value;

    values += "\nProvince : "+province.value;
	
	if(city!=null)
	{
		values += "\tCity : "+city.value;
	}
	else
	{
		values += "\tCity : 0";
	}

    values += "\nPostal Code : "+regPostalCodePartOne.value+" - "+regPostalCodePartTwo.value;

    values += "\nStreet Number : "+ streetNumber.value;

    values += "\tStreet Name : "+ streetName.value;

    values += "\nStreet Type : "+ streetType.value;

    values += "\tStreet Direction : "+ streetDirection.value;

    values += "\nApartment No. : "+ aptNo.value;

    values += "\tApartment Buzzer No. : "+ aptBuzzerNo.value;

    values += "\nPhone no : "+ phoneNoPartOne.value +"-"+phoneNoPartTwo.value+"-"+phoneNoPartThree.value;

    values += "\nSecond Phone no : "+ secondPhoneNoPartOne.value+"-"+secondPhoneNoPartTwo.value+"-"+secondPhoneNoPartThree.value;

    values += "\n\nCaptcha Text : "+captchaText.value;



	preparePost = "registrationInformation.php? firstName=" + firstName.value + "&LastName=" + lastName.value + "&email=" + emailReg.value + "&province="+ province.value+"&postalCodeOne=" +regPostalCodePartOne.value+"&postalCodeTwo="+regPostalCodePartTwo.value +

				  "&streetNumber="+streetNumber.value + "&streetName="+streetName.value + "&streetType="+streetType.value + "&streetSuffix="+suffixNo.value + "&streetDirection="+streetDirection.value+

				  "&apartmentNo="+aptNo.value + "&buzzerNo="+aptBuzzerNo.value+ "&phoneNumber="+ phoneNoPartOne.value +"-"+phoneNoPartTwo.value+"-"+phoneNoPartThree.value +"&password="+password.value+"&gender="+selectedGender+"&dateOfBirth="+dateOfBirth.value+"&subscribe="+subscribe+"&logo="+imgLogo.value;

	if(city!=null)
	{
		preparePost +=  "&city=" + city.value;
	}
	else
	{
		preparePost +=  "&city=0";
	}
    

	//alert(preparePost);
	//return;
    showPostCode(preparePost);



    varCodeRandom="";
	
}



function showPostCode(preparePost)

{

document.getElementById("waitRegister").style.display="inline";

//alert("you changed something" +str);

var xmlhttpPostCode;



if (preparePost.length==0)

  {

   

  return;

  }

if (window.XMLHttpRequest)

  {// code for IE7+, Firefox, Chrome, Opera, Safari

  xmlhttpPostCode=new XMLHttpRequest();

  }

else

  {// code for IE6, IE5

  xmlhttpPostCode=new ActiveXObject("Microsoft.XMLHTTP");

  }

xmlhttpPostCode.onreadystatechange=function()

  {

  if (xmlhttpPostCode.readyState==4 && xmlhttpPostCode.status==200)

    {

        document.getElementById("waitRegister").style.display="none";
        //document.getElementById("registerWait").style.display="none";

        //show_modal("registrationDoneDiv");
        

        var messageDiv = document.getElementById("registerMessageDiv");


        messageDiv.style.display="block";
        messageDiv.style.left="350px";
		//alert(xmlhttp.responseText);

        if(xmlhttpPostCode.responseText=="")

        {
			if($("#hiddenSelectedLanguage").attr("value")=="english" || $("#hiddenSelectedLanguage").attr("value")=="_en")
			{
				//messageDiv.innerHTML = "<div id='greateWeAreDone'>Great, we are done!</div><div id='youAreReady'>You are ready to order now.</div> <br><div id='messageRegister'><p>  we sent you a welcome e-mail if you don't get it, check your junk mail box, its important that you get our e-mails, we will send you e-mail confirmation after you order</p></div>";
			}
            else
			{
				//messageDiv.innerHTML = "<div id='greateWeAreDone'>Super! On a fini!</div><div id='youAreReady'>Tu vas pouvoir commander.</div> <br><div id='messageRegister'><p>  Nous t'avons envoy&eacute; un courriel de bienvenue. Si tu ne l'as pas re&ccedil;u, v&eacute;rifie ton dossier courrier ind&eacute;sirable.</p></div>";
			}

        }

        else{

            messageDiv.innerHTML="Register :<br><p style='margin-top:10px;font-size:15px;font-family:verdana;font-weight:bold;'>"+xmlhttpPostCode.responseText+"</p>";

        }





        //get the height of the window screen
        if ($("#next_href").val() != '') {
            window.location.href = $("#next_href").val()
        } else {
 		show_modal("registrationDoneDiv");
        }
                
        //var windowtop=document.all? iebody.scrollTop : pageYOffset



        //document.getElementById("registrationDoneDiv").style.top = (windowtop + 100) + "px";

        //document.getElementById("registrationDoneDiv").style.left = "350px";



    	//alert(xmlhttp.responseText);



        //clearForm();

        //document.getElementById('postCodeHintDropDown').click();

    }

  }

xmlhttpPostCode.open("GET",preparePost,true);

xmlhttpPostCode.send();

}







function generateRandomString(strLength)

{

    var text = "";

    var possible = "0123456789";



    for( var i=0; i < strLength; i++ )

    {

        text += ' ' + possible.charAt(Math.floor(Math.random() * possible.length));

    }



    return removeSpaces(text);

}


function checkValidityOfPrevData(){

    var firstName = document.getElementById("firstNameTextBox");

    var lastName = document.getElementById("lastNameTextBox");

    var emailReg = document.getElementById("emailRegTextBox");

    var confirmEmail = document.getElementById("confirmEmailTextBox");

    var regPassword = document.getElementById("regPassword");

    var regPasswordConfirm = document.getElementById("registerPasswordConfirmTextBox");

    var province = document.getElementById("provinceDropDown");

    var city = document.getElementById("cityDropDown");

    var regPostalCodePartOne = document.getElementById("regPostalCodePartOne");

    var regPostalCodePartTwo = document.getElementById("regPostalCodePartTwo");

    var streetNumber = document.getElementById("streetNumberTextBox");

    var streetName = document.getElementById("streetNameTextBox");

    var streetType = document.getElementById("streetType");

    var streetDirection = document.getElementById("streetDirection");

    var phoneNoPartOne = document.getElementById("phoneNoPartOne");

    var phoneNoPartTwo = document.getElementById("phoneNoPartTwo");

    var phoneNoPartThree = document.getElementById("phoneNoPartThree");
    
    var gender = document.getElementsByName("rdbGender");

    var dateOfBirth = "";//document.getElementById("dateOfBirth");

    var selectedGender = "";

    for(var i =0;i<2;i++)
    {

        if(gender[i].checked)
            {
                selectedGender = gender[i].value;

            }
    }


    if(firstName.value==""){
        showErrorMessage("First Name","errorMessageStepOneContainer");
        firstName.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        firstName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(lastName.value==""){
        showErrorMessage("Last Name","errorMessageStepOneContainer");
        lastName.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        lastName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    /*if(selectedGender==""){
        showErrorMessage("Gender","errorMessageStepOneContainer");
        window.scrollTo("100","500");
        return false;
    }else{
        hideErrorMessage("errorMessageStepOneContainer");
    }
    */
//    if(validateDateOfBirth(dateOfBirth)==false){
//        showErrorMessage("Date of Birth","errorMessageStepOneContainer");
//        dateOfBirth.style.border="solid thin red;";
//        dateOfBirth.focus();
//        window.scrollTo("100","500");
//        return false;
//    }else{
//        dateOfBirth.style.border="solid thin #bdbdbd;";
//        hideErrorMessage("errorMessageStepOneContainer");
//    }

    if(emailReg.getAttribute("class")!="isValid")
    {
        showErrorMessage("Invalid Email","errorMessageStepOneContainer");
        emailReg.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        emailReg.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(confirmEmail.getAttribute("class")!="isValid")
    {
        showErrorMessage("Confirm Email","errorMessageStepOneContainer");
        confirmEmail.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        confirmEmail.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }
    if(regPassword.getAttribute("class")!="isValid")
    {
        showErrorMessage("Enter minimum 4 characters","errorMessageStepOneContainer");
        regPassword.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        regPassword.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(regPasswordConfirm.getAttribute("class")!="isValid")
    {
        showErrorMessage("Confirm Password","errorMessageStepOneContainer");
        regPasswordConfirm.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        regPasswordConfirm.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(province.value=="0")
    {
        showErrorMessage("Province","errorMessageStepTwoContainer");
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(city.value=="0")
    {
        showErrorMessage("City","errorMessageStepTwoContainer");
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(regPostalCodePartOne.getAttribute("class")!="isValid")
    {
        showErrorMessage("Postal Code Part One","errorMessageStepTwoContainer");
        regPostalCodePartOne.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }else{
        regPostalCodePartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(regPostalCodePartTwo.getAttribute("class")!="isValid")
    {
        showErrorMessage("Postal Code Part Two","errorMessageStepTwoContainer");
        regPostalCodePartTwo.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }else{
        regPostalCodePartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(streetNumber.value=="")
    {
        showErrorMessage("Street Number","errorMessageStepTwoContainer");
        streetNumber.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        streetNumber.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(streetName.value=="")
    {
        showErrorMessage("Street Name","errorMessageStepTwoContainer");
        streetName.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        streetNumber.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    /*if(streetType.value=="0" || streetType.value=="1")
    {
        showErrorMessage("Street Type","errorMessageStepTwoContainer");
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(streetDirection.value=="0" || streetDirection.value=="1")
    {
        showErrorMessage("Street Direction","errorMessageStepTwoContainer");
	window.scrollTo("100","900");
        return false;
    }
    else
    {
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    */


    if(phoneNoPartOne.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part One","errorMessageStepTwoContainer");
        phoneNoPartOne.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }else{
        phoneNoPartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(phoneNoPartTwo.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Two","errorMessageStepTwoContainer");
        phoneNoPartTwo.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }else{
        phoneNoPartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
    if(phoneNoPartThree.getAttribute("class")!="isValid")
    {
        showErrorMessage("Phone Number Part Three","errorMessageStepTwoContainer");
        phoneNoPartThree.className="isInvalid";
	window.scrollTo("100","900");
        return false;
    }else{
        phoneNoPartThree.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    return true;
}


/*function validateStepOne(){
    var firstName = document.getElementById("firstNameTextBox");

    var lastName = document.getElementById("lastNameTextBox");

    var emailReg = document.getElementById("emailRegTextBox");

    var confirmEmail = document.getElementById("confirmEmailTextBox");

    var regPassword = document.getElementById("regPassword");

    var regPasswordConfirm = document.getElementById("registerPasswordConfirmTextBox");

    var gender = document.getElementsByName("rdbGender");

    var dateOfBirth = document.getElementById("dateOfBirthDropDown");

    var selectedGender = "";

    for(var i =0;i<2;i++)
    {

        if(gender[i].checked)
            {
                selectedGender = gender[i].value;

            }
    }


    if(firstName.value==""){
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        firstName.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        firstName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(lastName.value==""){
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        lastName.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        lastName.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(selectedGender==""){
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        window.scrollTo("100","500");
        return false;
    }else{
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(dateOfBirth.value=="0"){
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        window.scrollTo("100","500");
        return false;
    }else{
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(emailReg.getAttribute("class")!="isValid")
    {
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        emailReg.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        emailReg.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(confirmEmail.getAttribute("class")!="isValid")
    {
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        confirmEmail.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        confirmEmail.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }
    if(regPassword.getAttribute("class")!="isValid")
    {
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        regPassword.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        regPassword.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

    if(regPasswordConfirm.getAttribute("class")!="isValid")
    {
        showErrorMessage("Step 1 before placing a call","errorMessageStepOneContainer");
        regPasswordConfirm.className="isInvalid";
	window.scrollTo("100","500");
        return false;
    }else{
        regPasswordConfirm.className="isValid";
        hideErrorMessage("errorMessageStepOneContainer");
    }

}

function validateStepTwo(){
    var province = document.getElementById("provinceDropDown");

    var city = document.getElementById("cityDropDown");

    var regPostalCodePartOne = document.getElementById("regPostalCodePartOne");

    var regPostalCodePartTwo = document.getElementById("regPostalCodePartTwo");

    var streetNumber = document.getElementById("streetNumberTextBox");

    var streetName = document.getElementById("streetNameTextBox");

    var streetType = document.getElementById("streetType");

    var streetDirection = document.getElementById("streetDirection");

    var phoneNoPartOne = document.getElementById("phoneNoPartOne");

    var phoneNoPartTwo = document.getElementById("phoneNoPartTwo");

    var phoneNoPartThree = document.getElementById("phoneNoPartThree");
}*/

//Ajax function to send the verification code to the server

function sendVerificationCode()

{
	
	if($.browser.msie)
		{
			if(isLoggedIn==true || isSendPasswd==true)
				return;
		}
    var prevFormDataIsValid = checkValidityOfPrevData();
    
    if(prevFormDataIsValid==false)
        {
            return;
        }
    
    //check valid phone no.

    var secondPhoneNoPartOne = document.getElementById("secondPhoneNoPartOne");

    var secondPhoneNoPartTwo = document.getElementById("secondPhoneNoPartTwo");

    var secondPhoneNoPartThree = document.getElementById("secondPhoneNoPartThree");



    if((secondPhoneNoPartOne.getAttribute("class")!="isValid")||

              (secondPhoneNoPartTwo.getAttribute("class")!="isValid")||(secondPhoneNoPartThree.getAttribute("class")!="isValid"))

    {

        showErrorMessage("Phone No. is invalid","errorMessageStepThreeContainer");

        return;

    }



    //check valid captcha
    /*
    if(!ValidCaptcha())

        {

            showErrorMessage("Invalid captcha","errorMessageStepThreeContainer");

            return;

        }

    */

    hideErrorMessage("errorMessageStepThreeContainer");

    var phoneNumber = secondPhoneNoPartOne.value+""+secondPhoneNoPartTwo.value+""+secondPhoneNoPartThree.value;

    //generate random string ....

    varCodeRandom = generateRandomString(4)
	
	//showWait();
    $("#callMeContainer #wait").css({visibility:'visible'});   
	

    //alert("Random(global var) : "+varCodeRandom);

   // alert("Verification code: "+varCodeRandom);

    
   //  var txtVerificationCode = document.getElementById("txtVerificationCode");

    //txtVerificationCode.style.display="block";
    
   // txtVerificationCode.style.display="block";

   // txtVerificationCode.value="";

   // txtVerificationCode.focus();

//	$("#enter,#verificationCodeInstructions").hide();


  //  txtVerificationCode.value= varCodeRandom;
    //url to the request

    var url = "phoneVerification.php";

    var param = "code="+varCodeRandom+"&phoneNumber="+phoneNumber;

    //alert(url);

    

    var xmlhttp_sendVarCode;



    if (window.XMLHttpRequest)

    {// code for IE7+, Firefox, Chrome, Opera, Safari

         xmlhttp_sendVarCode=new XMLHttpRequest();

    }

    else

    {// code for IE6, IE5

        xmlhttp_sendVarCode=new ActiveXObject("Microsoft.XMLHTTP");

    }

    xmlhttp_sendVarCode.onreadystatechange=function()

    {

        if (xmlhttp_sendVarCode.readyState==4 && xmlhttp_sendVarCode.status==200)

        {

           //do something with the result
			//hideWait();
           //alert("Varification code sent successfuly!"+xmlhttp_sendVarCode.responseText);
		   	setTimeout('hideWait();', 20000)

        }

    }
    setTimeout('hideWait();', 20000)



    xmlhttp_sendVarCode.open("POST",url,true);



    xmlhttp_sendVarCode.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

    //xmlhttp.setRequestHeader("Content-length", param.length);

    xmlhttp_sendVarCode.setRequestHeader("Connection", "close");

    xmlhttp_sendVarCode.send(param);



}





//Ajax function to check the availability of the email

function checkEmailAvailability(object)

{

    //first validate the email id ...

    validate(object,'Email');

    if(object.getAttribute("class")=="isInvalid")

    {

        return;

    }

    $("#waitEmailAvailDiv").show();

    //ajax code

        //url to the request

        var url = "checkUniqueEmail.php";

        var param = "email="+object.value;



        var xmlhttp_checkEmail;



        if (window.XMLHttpRequest)

        {// code for IE7+, Firefox, Chrome, Opera, Safari

             xmlhttp_checkEmail=new XMLHttpRequest();

        }

        else

        {// code for IE6, IE5

            xmlhttp_checkEmail=new ActiveXObject("Microsoft.XMLHTTP");

        }

        xmlhttp_checkEmail.onreadystatechange=function()

        {

            if (xmlhttp_checkEmail.readyState==4 && xmlhttp_checkEmail.status==200)

            {

               //do something with the result

               var result = xmlhttp_checkEmail.responseText;

				$("#waitEmailAvailDiv").hide(); 

               if(result == "isAvailable")

                   {	

                       object.className = "isValid";//set the email textbox class to isValid
						
					   ///Show confirm email box .....
					   //alert("asdad");
					    
					    $("#confirmEmailNameLabel").fadeIn("200");	
						$("#confirmEmailTextBox").focus();
						$("#regPassword").removeClass("isInvalid").addClass("inputText");
						$("#emailMatchingError").hide();
						$("#lineBreakOne").css({top:'210px'});

						if($("#hiddenFormName").attr("value")=="Voucher")
						{
                                                    if($("#hiddenSelectedTemplate").val()=="1") {
                                                            $("#middleContentContainer").css({'top':'192px'});
                                                            $("#lineBreakOne").css({'top':'215px'})
                                                            $("#registerStepTwoContainer").css({'top':'290px'})
                                                        //if($("#validatePhone").attr("value")=="0") {
                                                        //    $("#regStepThreeContainer").css({'top':'400px'})
							//} else {
							//    $("#regStepThreeContainer").css({'top':'515px'})
							//}
                                                     } else {
							$("#registerStepOneContainer").css({'top':'205px'});
                                                        $("#lineBreakOne").css({'top':'215px'});
                                                        //$("#registerStepTwoContainer").css({'top':'415px'});
                                                       // $("#regStepThreeContainer").css({'top':'635px'});
                                                        $("#verificationCode").css({'top':'42px'});
                                                     }
						}
						else if($("#hiddenFormName").attr("value")=="Register")
					    {
							
							$("#registerStepTwoContainer").css({top:'300px'});
							//$("#regStepThreeContainer").css({top:'530px'});
							//$("#highlightedMessage").css({top:'1345px'});
							$("#lineBreakOne").css({top:'210px'});
						}
						else if($("#hiddenFormName").attr("value")=="MyProfile")
					    {
							//$("#lineBreakOne").css({top:'310px'});
							//$("#registerStepTwoContainer").css({top:'780px'});
						}
						
						if($("#confirmEmailTextBox").val().length==0)
					    {
							showErrorMessage("re-enter email","errorMessageStepOneContainer");
						}
                   }
               else
                   {
                        showErrorMessage("Email Id already taken, choose another one","errorMessageStepOneContainer");
						$("#updateProfileDiv #doneText").css({fontSize:'17px',textAlign:'left'});
						if($("#hiddenSelectedLanguage").val()=="french" || $("#hiddenSelectedLanguage").val()=="_fr")
						{
							$("#updateProfileDiv #doneText").html("Votre email est déjà enregistré avec nous ou avec un autre restaurant Powered par ClickMySlice. Si vous ne me souviens pas votre mot de passe s'il vous plaît cliquer sur \"login\" en haut à droite de l'écran puis \"Vous avez oublié votre mot de passe\"");
						}
						else
						{
							$("#updateProfileDiv #doneText").html("Your email is already registered with us or with another restaurant powered by ClickMySlice. If you don't remember your password please click \"login\" on the top right of the screen and then \"forgot your password\"");
						}
						show_modal("updateProfileDiv");
                        object.className = "isInvalid";//set the email textbox to isInvalid
                        object.value="";
                   }
            }

        }



        xmlhttp_checkEmail.open("POST",url,true);

        xmlhttp_checkEmail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

        //xmlhttp.setRequestHeader("Content-length", param.length);

        xmlhttp_checkEmail.setRequestHeader("Connection", "close");

        xmlhttp_checkEmail.send(param);


}


function showVerificationCodeTextBox()

{

    var txtVerificationCode = document.getElementById("txtVerificationCode");

    txtVerificationCode.style.display="block";

    txtVerificationCode.value="";

    txtVerificationCode.focus();

	$("#enter,#verificationCodeInstructions").hide();

}


function hideVerificationCodeTextBox()

{

    var txtVerificationCode = document.getElementById("txtVerificationCode");

    if(txtVerificationCode.value=="")

    {

        txtVerificationCode.style.display="none";

        txtVerificationCode.value="enter code";

		$("#enter,#verificationCodeInstructions").show();

    }

    

    

}



/*function showErrorMessage(message)

{

    var errorMessagesContainer = document.getElementsByClassName("errorMessageContainer");

    for(var index=0;index<errorMessagesContainer.length;index++)

    {

        //alert(errorMessagesContainer[index].innerHTML);

        errorMessagesContainer[index].style.display="block";

    }



    var errorMessage = document.getElementsByClassName("errorMessage");

    for (var i=0; i < errorMessage.length; i++)

    {

        //alert(errorMessage[i].innerHTML);

        errorMessage[i].innerHTML = message;

    }

}*/



function showErrorMessage(message,messageContainer)

{

    var errorMessagesContainer = document.getElementsByClassName(messageContainer);

    

    for(var index=0;index<errorMessagesContainer.length;index++)

    {

        //alert(errorMessagesContainer[index].innerHTML);

        errorMessagesContainer[index].style.display="block";

    }



    var errorMessageClass = messageContainer.substring(0, messageContainer.indexOf("Container"));



    var errorMessage = document.getElementsByClassName(errorMessageClass);

    for (var i=0; i < errorMessage.length; i++)

    {

        //alert(errorMessage[i].innerHTML);

        errorMessage[i].innerHTML = message;

    }

	if(message=="First Name")
	{
		if($("#hiddenSelectedLanguage").attr("value")=="english" || $("#hiddenSelectedLanguage").attr("value")=="_en")
		{
			$("#firstNameTextBox").val("first name");
		}
		else
		{
			$("#firstNameTextBox").val("nom");
		}
	}
	else if(message=="Last Name")
	{
		if($("#hiddenSelectedLanguage").attr("value")=="english" || $("#hiddenSelectedLanguage").attr("value")=="_en")
		{
			$("#lastNameTextBox").val("last name");
		}
		else
		{
			$("#lastNameTextBox").val("nom de famille");
		}
		
	}

	//alert(message=="re-enter password" || message=="re-enter email");
	
	if(message=="re-enter password" || message=="re-enter email")
	{
		$("#pleaseCorrect").hide();				
	}
	else
	{
		$("#pleaseCorrect").show();
	}
}



/*function hideErrorMessage()

{

    var errorMessagesContainer = document.getElementsByClassName("errorMessageContainer");

    for(var index=0;index<errorMessagesContainer.length;index++)

    {

        errorMessagesContainer[index].style.display="none";

    }



}*/







function clearForm()

{

    document.getElementById("firstNameTextBox").value="";

    document.getElementById("lastNameTextBox").value="";

    document.getElementById("emailRegTextBox").value="";

    document.getElementById("confirmEmailTextBox").value="";

    document.getElementById("regPassword").value="";

    document.getElementById("registerPasswordConfirmTextBox").value="";

    document.getElementById("provinceDropDown").value="-- Choose One --";

    document.getElementById("cityDropDown").value="-- Choose One --";

    document.getElementById("regPostalCodePartOne").value="";

    document.getElementById("regPostalCodePartTwo").value="";

    document.getElementById("streetNumberTextBox").value="";

    document.getElementById("streetNameTextBox").value="";

    document.getElementById("streetType").value="type";

    document.getElementById("suffixNo").value="suffix";

    document.getElementById("streetDirection").value="direction";

    document.getElementById("aptNo").value="if implies";

    document.getElementById("aptBuzzerNoTextBox").value="if implies";

    document.getElementById("phoneNoPartOne").value="";

    document.getElementById("phoneNoPartTwo").value="";

    document.getElementById("phoneNoPartThree").value="";

    document.getElementById("secondPhoneNoPartOne").value="";

    document.getElementById("secondPhoneNoPartTwo").value="";

    document.getElementById("secondPhoneNoPartThree").value="";

    document.getElementById("regPassword").value="";

    document.getElementById("captchaText").value="enter numbers on the left";

    document.getElementById("txtVerificationCode").value="";



}





function close_register_modal(modal_id){

        //hide the mask

        document.getElementById("mask").style.display="none";



        //hide modal window

        document.getElementById(modal_id).style.display="none";


		var postCode = document.getElementById("regPostalCodePartOne"); 


        //window.location="postalCodeLoggedInFinal.php";

		window.location="restolist.php?postCode="+postCode.value;

    }



function showPhoneNumberOnFocus(){

    var phoneNoPartOne = document.getElementById("phoneNoPartOne");

    var phoneNoPartTwo = document.getElementById("phoneNoPartTwo");

    var phoneNoPartThree = document.getElementById("phoneNoPartThree");

    var secondPhoneNoPartOne = document.getElementById("secondPhoneNoPartOne");

    var secondPhoneNoPartTwo = document.getElementById("secondPhoneNoPartTwo");

    var secondPhoneNoPartThree = document.getElementById("secondPhoneNoPartThree");

    

    if(secondPhoneNoPartOne.value=="" && secondPhoneNoPartTwo.value=="" && secondPhoneNoPartThree.value=="")

        {

            secondPhoneNoPartOne.value=phoneNoPartOne.value;

            secondPhoneNoPartTwo.value=phoneNoPartTwo.value;

            secondPhoneNoPartThree.value=phoneNoPartThree.value;

        }

    

}



function showPhoneNumber(source,target){

    //validate phone number

    validateTextOnly(source,false);



    //copy phone number to second one
	document.getElementById(target).value=source.value;
	
    

    //alert(source.value.length);
    if(source.id=="phoneNoPartOne" || source.id=="phoneNoPartTwo")
        {
            if(source.value.length==3){

               document.getElementById(target).className="isValid";
               hideErrorMessage("errorMessageStepThreeContainer");
            }else
                {
                    document.getElementById(target).className="isInvalid";
                    //showErrorMessage("Invalid Phone Number","errorMessageStepThreeContainer");
                }
        }
    else if(source.id=="phoneNoPartThree")
        {
            if(source.value.length==4){

               document.getElementById(target).className="isValid";
               hideErrorMessage("errorMessageStepThreeContainer");
            }else
                {
                    document.getElementById(target).className="isInvalid";
                }
        }
    

}

function addYears(){
    
    var yearsDropDown = document.getElementById("dateOfBirthDropDown");

    var years = "";

    var currentYear = new Date().getUTCFullYear();

    //alert(currentYear-80);

    if(years!=null)
        {
            years = "<option value='0'> -- Select -- </option>";

            for(var i=currentYear-79; i<=currentYear-10 ;i++)
                {
                    years += "<option value='"+i+"'>"+i+"</option>";
                }

           yearsDropDown.innerHTML = years;
        }
}


function validateDateOfBirth(object){
    var regXDate = validationObjectType["date"];
    if(object.value!=""){
        if(!(regXDate).test(object.value))  //validation fail
            {
                return false;
            }
        return true;
    }
    return false;
}

function validateDelivery2(postalcode) {
	flag = 1;
	$(function () {
		$.ajax({
			url:"validarpostalcode.php?p=" + postalcode,
			dataType: 'json',
			async:false,
			success: function (data) {
				console.log(data);
				if (data.type == '0') {
					if (data.lang == '_fr') {
						alert("Nous sommes désolés, nous ne proposons pas de livraison services dans votre emplacement actuel");
					} else {
						alert("We are sorry, we don’t offer delivery services in your current location");
					}
					flag = 0;
				}
			}
		});
	})
	return flag;
}
function updateProfile()
{
	var regPostalCodePartOne = document.getElementById("regPostalCodePartOne");
	mt = document.getElementById("menuTool_h");
	if (mt && mt.getAttribute("href")) {
		if (!validateDelivery2(regPostalCodePartOne.value)) {
			return false;
		}
	}

	if( $.browser.msie )
		{
			if(isLoggedIn == true || isSendPasswd == true)
				return;
		}
	var firstNameTextBox = document.getElementById("firstNameTextBox");
	var lastNameTextBox = document.getElementById("lastNameTextBox");
	var emailRegTextBox = document.getElementById("emailRegTextBox");
	var confirmEmail = document.getElementById("confirmEmailTextBox");
	var regPostalCodePartOne = document.getElementById("regPostalCodePartOne");
	var regPostalCodePartTwo = document.getElementById("regPostalCodePartTwo");
	var streetNumberTextBox = document.getElementById("streetNumberTextBox");
	var streetNameTextBox = document.getElementById("streetNameTextBox");
	var aptNo = document.getElementById("aptNo");
	var aptBuzzerNoTextBox = document.getElementById("aptBuzzerNoTextBox");
	var phoneNoPartOne = document.getElementById("phoneNoPartOne");
	var phoneNoPartTwo = document.getElementById("phoneNoPartTwo");
	var phoneNoPartThree = document.getElementById("phoneNoPartThree");
	var dateOfBirth = "";//document.getElementById("dateOfBirth");
	var provinceDropDown = document.getElementById("provinceDropDown");
	var cityDropDown = document.getElementById("cityDropDown");
	var suffixNo = document.getElementById("suffixNo");
	var streetType = document.getElementById("streetType");
	var streetDirection = document.getElementById("streetDirection");
	var chkNewsLettersAndSpecials = document.getElementById("chkNewsLettersAndSpecials");
	var password = document.getElementsByName("regPassword");
	var confirmPassword = document.getElementsByName("registerPasswordConfirmTextBox");
	var subscription="false";

	
	//var gender = document.getElementsByName("rdbGender");
	//var selectedGender = "";
    /*for(var i =0;i<2;i++)
    {

        if(gender[i].checked)
            {
                selectedGender = gender[i].value;

            }
    }*/
	
	if(chkNewsLettersAndSpecials && chkNewsLettersAndSpecials.checked)
	{
			subscription="true";
	}
	else
	{
			subscription="false";
	}
	
	if(firstNameTextBox.value.length==0 || firstNameTextBox.value=="first name" || firstNameTextBox.value=="nom")
	{
	alert("Enter first name");
	firstNameTextBox.value="";
	return false;
	}

	if(lastNameTextBox.value.length==0 || lastNameTextBox.value=="last name" || lastNameTextBox.value=="nom de famille")	
	{
		alert("Ener the lastname");
		lastNameTextBox.value=""
		return false;
	}
	if(emailRegTextBox.value.length==0 || emailRegTextBox.getAttribute("class")=="isInvalid")
	{
		alert("Enter email address");
		emailRegTextBox.focus();
		return false;
	}
	if($(confirmEmail).hasClass("changed")||$(confirmEmail).hasClass("isInvalid"))
	{
		alert("Confirm email address");
		confirmEmail.focus();
		return false;
	}
	if($(password).hasClass("isInvalid"))
	{
		alert("Enter Password of minimum 4 characters!");
		password.focus();
		return false;
	}

	if($("#regPassword").hasClass("isValid") && ($("#registerPasswordConfirmTextBox").hasClass("isInvalid") || $("#registerPasswordConfirmTextBox").hasClass("inputText")))
	{
		alert("Confirm password!");
		return false;
	}

	if(regPostalCodePartOne.getAttribute("class")=="isInvalid")
    {
        showErrorMessage("Postal Code Part One","errorMessageStepTwoContainer");
        regPostalCodePartOne.className="isInvalid";
		//window.scrollTo("100","900");
        return false;
    }
	else
	{
        regPostalCodePartOne.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }

    if(regPostalCodePartTwo.getAttribute("class")=="isInvalid")
    {
        showErrorMessage("Postal Code Part Two","errorMessageStepTwoContainer");
        regPostalCodePartTwo.className="isInvalid";
		//window.scrollTo("100","900");
        return false;
    }
	else
	{
        regPostalCodePartTwo.className="isValid";
        hideErrorMessage("errorMessageStepTwoContainer");
    }
	if(streetNumberTextBox.value.length==0)
	{
		alert("Enter street number");
		streetNumberTextBox.value="";
		return false;
	}
	if(aptNo.value.length==0)
 	{
		alert("Enter appartment no");
		aptNo.value="";
		return false;
	}	 

	if(aptBuzzerNoTextBox.value.length==0)
 	{
		alert("Enter appratment buzzer no");
		aptBuzzerNoTextBox.value="";
		return false;
 	}
		
	if(phoneNoPartOne.value.length==0 || phoneNoPartOne.getAttribute("class")=="isInvalid")
 	{
		alert("Enter part one of Phone no");
		phoneNoPartOne.focus();
		return false;
 	}
     
	if(phoneNoPartTwo.value.length==0 || phoneNoPartTwo.getAttribute("class")=="isInvalid")
 	{
		alert("Enter part two of Phone no");
		phoneNoPartTwo.focus();
		return false;
 	}
	
	if(phoneNoPartThree.value.length==0 || phoneNoPartThree.getAttribute("class")=="isInvalid")
 	{
		alert("Enter part three of Phone no");
		phoneNoPartThree.focus();
		return false;
 	}
		
	/*if(dateOfBirth.value.length==0)
 	{
		alert("Enter the date of birth");
		dateOfBirth.value="";
		return false;
 	}*/
		
	if(provinceDropDown.value==0)
 	{
		alert("Select Province");
		provinceDropDown.value="";
		return false;
 	}
	
	
	if(cityDropDown!=null)
	{
		if(cityDropDown.value==0)
		{
			alert("Select City");
			cityDropDown.value="";
			return false;
		}
	}
		
	if(suffixNo.value==0 || suffixNo.value=="none")
 	{
			suffixNo.value="0";
 	}

		
	if(streetType.value==0||streetType.value=="none")
 	{
		streetType.value="0";
 	}
		
	if(streetDirection.value==0||streetDirection.value=="none")
 	{
		streetDirection.value="0";
 	}
	

	
	var params = "firstNameTextBox="+firstNameTextBox.value+"&lastNameTextBox="+lastNameTextBox.value+"&emailRegTextBox="+emailRegTextBox.value+"&regPostalCodePartOne="+regPostalCodePartOne.value+"&regPostalCodePartTwo="+regPostalCodePartTwo.value+"&streetNumberTextBox="+streetNumberTextBox.value+"&streetNameTextBox="+streetNameTextBox.value+"&aptNo="+aptNo.value+"&aptBuzzerNoTextBox="+aptBuzzerNoTextBox.value+"&phoneNoPartOne="+phoneNoPartOne.value+"&phoneNoPartTwo="+phoneNoPartTwo.value+"&phoneNoPartThree="+phoneNoPartThree.value+"&dateOfBirth="+dateOfBirth.value+"&chkNewsLettersAndSpecials="+subscription+"&provinceDropDown="+provinceDropDown.value+"&suffixNo="+suffixNo.value+"&streetType="+streetType.value+"&streetDirection="+streetDirection.value;
	
	if(cityDropDown!=null)
	{
		params += "&cityDropDown="+cityDropDown.value;
	}
	else
	{
		params += "&cityDropDown=0";
	}

	if(	$("#registerPasswordConfirmTextBox").hasClass("isValid"))
	{
		params += "&newPassword="+$("#registerPasswordConfirmTextBox").val();
	}
	else
	{
		params += "&newPassword=0";
	}
	
	//alert(params);
		var xmlHTTPupdateInfo;
		if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlHTTPupdateInfo=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
        xmlHTTPupdateInfo=new ActiveXObject("Microsoft.XMLHTTP");
      }

    xmlHTTPupdateInfo.onreadystatechange=function()
      {
          if (xmlHTTPupdateInfo.readyState==4 && xmlHTTPupdateInfo.status==200)
          {
		        //alert(xmlHTTPupdateInfo.responseText);
				show_modal('updateProfileDiv');
				//define universal dsoc left point
				//var dsocleft=document.all? iebody.scrollLeft : pageXOffset
				//define universal dsoc top point
				//var dsoctop=document.all? iebody.scrollTop : pageYOffset
				$("#mask").css({height:'1320px'});
		  }
		  
	  }
	  /*alert("updateUserProfile.php?firstNameTextBox="+firstNameTextBox.value+"&lastNameTextBox="+lastNameTextBox.value+"&emailRegTextBox="+emailRegTextBox.value+"&regPostalCodePartOne="+regPostalCodePartOne.value+"&regPostalCodePartTwo="+regPostalCodePartTwo.value+"&streetNumberTextBox="+streetNumberTextBox.value+"&&aptNo="+aptNo.value+"&aptBuzzerNoTextBox="+aptBuzzerNoTextBox.value+"&phoneNoPartOne="+phoneNoPartOne.value+"&phoneNoPartTwo="+phoneNoPartTwo.value+"&phoneNoPartThree="+phoneNoPartThree.value+"&dateOfBirth="+dateOfBirth.value+"&chkNewsLettersAndSpecials="+chkNewsLettersAndSpecials.value);*/
	  
	  
	  
	   xmlHTTPupdateInfo.open("GET","updateUserProfile.php?"+params,true);
	   xmlHTTPupdateInfo.send();
}


$(document).ready(function(){
	$("#aptNo, #aptBuzzerNoTextBox").trigger("blur");
	
	$("#regPassword").change(function(){
		$(this).addClass("changed");	
	});

	$("#emailRegTextBox").change(function(){
		
		$("#confirmEmailTextBox").addClass("changed");	
	});

	$("#emailRegTextBox").blur(function(){
		if($("#confirmEmailTextBox").hasClass("changed"))
		{
			checkEmailAvailability(document.getElementById("emailRegTextBox"));
		}
	});
	
	if($("#hiddenFormName").attr("value")=="Voucher")
	{
		$("#registerStepOneContainer,#registerStepTwoContainer,#regStepThreeContainer").css({left:'30px'});
	}
	if($("#hiddenFormName").attr("value")=="MyProfile")
	{
		$("#emailRegTextBox,#regPassword,#confirmEmailTextBox,#registerPasswordConfirmTextBox").css({left:'-10px'});
		//$("#firstNameTextBox,#lastNameTextBox, #firstNameLabel span").css({top:'102px'});
		$("#firstNameTextBox").css({left:'145px'});
		$("#yearOfBirthLabel").hide();

		$("#cityLabel,#cityDropDownContainer,#waitCity").css({top:'45px'});
	}
	else
	{
		if($("#hiddenSelectedLanguage").attr("value")=="french" || $("#hiddenSelectedLanguage").val() == '_fr')
		{
			$("#firstNameTextBox").val("nom");
			$("#lastNameTextBox").val("nom de famille");			
		}
		else
		{
			$("#firstNameTextBox").val("first name");
			$("#lastNameTextBox").val("last name");
		}

	}

	
	$("#firstNameTextBox").click(function(){
		//alert($(this).val()=="first name" || $(this).val()=="nom");
		if($(this).val()=="first name" || $(this).val()=="nom")
		{
			$(this).val("");
		}
	});

	$("#firstNameTextBox").focus(function(){
		if($(this).val()=="first name" || $(this).val()=="nom")
		{
			$(this).val("");
		}
	});

	$("#lastNameTextBox").click(function(){
		//alert($(this).val()=="last name" || $(this).val()=="nom de famille");
		if($(this).val()=="last name" || $(this).val()=="nom de famille")
		{
			$(this).val("");
		}
	});

	$("#lastNameTextBox").focus(function(){
		if($(this).val()=="last name" || $(this).val()=="nom de famille")
		{
			$(this).val("");
		}
	});

	$("#cityDropDownContainer").css({top:'46px'});
	//$("#finalMessages").css({top:'90px'});
	//$("#doneButton").css({top:'125px'});
	//$("#verificationCode").css({top:'170px'});

	/////Remove Drop downs step 2  16/03/11
		
			$("#suffixNo,#streetType,#streetDirection").hide();

	//$(".lineBreak").css({marginTop:'-2px'});
	//$(".errorMessageContainer").css({marginTop:'2px'});
});




