function checkfirst_nameForLength(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (txt.length >= 1) {

		fieldset.className = "welldone";
        document.getElementById("error_fName").innerHTML="";
	}
	else {

		fieldset.className = "";
	}

}

// This function checks if the username field is at least 6 characters long. If so, it attaches class="welldone" to the containing fieldset.

function checklast_nameForLength(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (txt.length > 1) {

		fieldset.className = "welldone";
        document.getElementById("error_lName").innerHTML="";
	}

	else {

		fieldset.className = "";

	}

}

// This function checks if thephone field is at least 6 characters long. If so, it attaches class="welldone" to the containing fieldset.



function checkEmail(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/.test(txt)) {

		fieldset.className = "welldone";
        document.getElementById("error_email").innerHTML="";

	} else {

		fieldset.className = "";


	}

}



// This function checks the phone number to be sure it follows a certain pattern: xxx-xxx-xxxx. If so, it assigns class="welldone" to the containing fieldset.



function checkphone(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (/^[01]?\s*[\(\.-]?(\d{3})[\)\.-]?\s*(\d{3})[\.-](\d{4})$/.test(txt)) {

		fieldset.className = "welldone";
        document.getElementById("error_phone").innerHTML="";

	} else {

		fieldset.className = "";

	}

}



function checkcodeForLength(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (txt.length > 5) {

		fieldset.className = "welldone";
        document.getElementById("error_code").innerHTML="";
	}

	else {

		fieldset.className = "";

	}

}

function checkcaptchaForLength(whatYouTyped) {

	var fieldset = whatYouTyped.parentNode;

	var txt = whatYouTyped.value;

	if (txt.length > 4) {

		fieldset.className = "welldone";
        document.getElementById("error_captcha").innerHTML="";
	}

	else {

		fieldset.className = "";

	}

}


// this part is for the form field hints to display only on the condition that the text input has focus. otherwise, it stays hidden.



function addLoadEvent(func) {

  var oldonload = window.onload;

  if (typeof window.onload != 'function') {

    window.onload = func;

  } else {

    window.onload = function() {

      oldonload();

      func();

    }

  }

}


function prepareInputsForHints() {

  var inputs = document.getElementsByTagName("input");

  for (var i=0; i<inputs.length; i++){

    inputs[i].onfocus = function () {

      this.parentNode.getElementsByTagName("span")[0].style.display = "inline";

    }

    inputs[i].onblur = function () {

      this.parentNode.getElementsByTagName("span")[0].style.display = "none";

    }

  }

}

 function validate(){
        var flag = true;
        var res = "";


        if(document.getElementById("first_name").value == null || document.getElementById("first_name").value == ""){
            flag = false;
            document.getElementById("error_fName").innerHTML = "*Enter First Name";
        }

        if(document.getElementById("last_name").value == null || document.getElementById("last_name").value == ""){
            document.getElementById("error_lName").innerHTML="*Enter last Name";
            flag = false;

        }

        if(document.getElementById("email").value == null || document.getElementById("email").value == ""){
            document.getElementById("error_email").innerHTML="*Enter Email Address"
            flag = false;

        }

        if(document.getElementById("phone").value == null || document.getElementById("phone").value == ""){
            document.getElementById("error_phone").innerHTML="*Enter your phone number";
            flag = false;

        }

         if(document.getElementById("code").value == null || document.getElementById("code").value == ""){
            document.getElementById("error_code").innerHTML="*Please enter code";
            flag = false;

        }


         if(document.getElementById("captcha").value == null || document.getElementById("captcha").value == ""){
            document.getElementById("error_captcha").innerHTML="*Enter Captcha Code";
            flag = false;
        }
        if(document.getElementById("terms").checked==false){
            document.getElementById("error_check").innerHTML="*Check the terms and condition";
            flag = false;
        }

        if(flag == false){
            return false;

        }
        else{
               return true;
        }
    }

    addLoadEvent(prepareInputsForHints);