// JavaScript Document
//function for type "individual or PODUser"

// JavaScript Document
//function for type "individual or PODUser"




var illegalChars = /\W/;
var patron = new Array(3,3,4)
var patron2 = new Array(1,3,3,3,3)
function mascara(d,sep,pat,nums){
if(d.valant != d.value){
	val = d.value
	largo = val.length
	val = val.split(sep)
	val2 = ''
	for(r=0;r<val.length;r++){
		val2 += val[r]	
	}
	if(nums){
		for(z=0;z<val2.length;z++){
			if(isNaN(val2.charAt(z))){
				letra = new RegExp(val2.charAt(z),"g")
				val2 = val2.replace(letra,"")
			}
		}
	}
	val = ''
	val3 = new Array()
	for(s=0; s<pat.length; s++){
		val3[s] = val2.substring(0,pat[s])
		val2 = val2.substr(pat[s])
	}
	for(q=0;q<val3.length; q++){
		if(q ==0){
			val = val3[q]
		}
		else{
			if(val3[q] != ""){
				val += sep + val3[q]
				}
		}
	}
	d.value = val
	d.valant = val
	}
}
function santoshschoolinput1()
{
document.frmSignup.password.value="Tweet123";
//document.frmSignup.password.disabled="true";
document.frmSignup.password1.value="Tweet123";
//document.frmSignup.password1.disabled="true";
document.frmSignup.address.value="9355 lee highway";
//document.frmSignup.address.disabled="true";
document.frmSignup.city.value="fairfax";
//document.frmSignup.city.disabled="true";
document.frmSignup.postalcode.value="22031";
//document.frmSignup.postalcode.disabled="true";
document.frmSignup.school.value="george mason university";
//document.frmSignup.school.disabled="true"
document.frmSignup.locality.selectedIndex ="49";
//document.frmSignup.locality.disabled="true";
document.frmSignup.parentemail.value="parentname@provider.com";
}
function santoshschoolinput2()
{
//document.frmStep2.firstname.disabled="true";
//document.frmStep2.lastname.disabled="true";
document.frmStep2.cellularphone.value="123-456-7890";
document.frmStep2.parentphone.value="123-456-7890";
document.frmStep2.target_weight.value="0";
document.frmStep2.target_weight.disabled="0";

//document.frmStep2.parentname.disabled="true";
}


function valyourphone(){ 
    var elementos= document.frmStep2.yourphone;
    for (i=0;i<elementos.length;i++){ 
		if(elementos[i].checked){
	  document.frmStep2.isfon.value = elementos[i].value;
	  //alert(elementos[i].value);
	  return true;
		}
	}

} 

function valphonemessage(){ 
    var elementos= document.frmStep2.receivedmess;
    for (i=0;i<elementos.length;i++){ 
		if(elementos[i].checked){
	  document.frmStep2.ismessage.value = elementos[i].value;
	  //alert(elementos[i].value);
	  return true;
		}
	}

} 


function vallevel(){ 
    var elementosuno= document.frmSignup.rblevel;
    for (i=0;i<elementosuno.length;i++){ 
		if(elementosuno[i].checked){
	  document.frmSignup.level.value = elementosuno[i].value;
	  //alert(elementosuno[i].value);
	  return true;
		}
	}

} 

function validatePwd(fieldname) {
 
 
//Initialise variables
var errorMsg = "";
var space  = " ";
fieldname   = document.frmSignup.password; 
fieldvalue  = fieldname.value; 
fieldlength = fieldvalue.length; 

 
//It must not contain a space
if (fieldvalue.indexOf(space) > -1) {
     errorMsg += "\nPasswords cannot include a space.\n";
}     
 
//It must contain at least one number character
if (!(fieldvalue.match(/\d/))) {
     errorMsg += "\nStrong passwords must include at least one number.\n";
}
//It must start with at least one letter     
if (!(fieldvalue.match(/^[a-zA-Z]+/))) {
     errorMsg += "\nStrong passwords must start with at least one letter.\n";
}
//It must contain at least one upper case character     
if (!(fieldvalue.match(/[A-Z]/))) {
     errorMsg += "\nStrong passwords must include at least one uppercase letter.\n";
}
//It must contain at least one lower case character
if (!(fieldvalue.match(/[a-z]/))) {
     errorMsg += "\nStrong passwords must include one or more lowercase letters.\n";
}
//It must contain at least one special character
//if (!(fieldvalue.match(/\W+/))) {
//     errorMsg += "\nStrong passwords must include at least one special character - #,@,%,!\n";
//}
//It must be at least 7 characters long.
if (!(fieldlength >= 6)) {
     errorMsg += "\nStrong passwords must be at least 6 characters long.\n";
}
//If there is aproblem with the form then display an error
     if (errorMsg != ""){
          msg = "______________________________________________________\n\n";
          msg += "Please correct the problem(s) with your password test it again.\n";
          msg += "______________________________________________________\n";
          errorMsg += alert(msg + errorMsg + "\n\n");
          fieldname.focus();
          return false;
     }
     
     return true;
}

function validstep1()
{
	var filtro  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	/*---------------first name----------------------*/
	if(document.frmSignup.firstname.value=="")
	{
		alert('Please fill the field First Name');
		document.frmSignup.firstname.focus();
		return 0;
	}
	/*---------------last name----------------------*/
	if(document.frmSignup.lastname.value =="")
	{
		alert('Please fill the field Last Name');
		document.frmSignup.lastname.focus();
		return 0;
	}

	/*---------------email----------------------*/
	//santosh change if(document.frmSignup.email.value=="" || document.frmSignup.email.value.indexOf('@') == -1 || document.frmSignup.email.value.indexOf('.') == -1 )
    if((document.frmSignup.email.value==""))

    {
		alert('Please fill the field User name or wrong invalid User name');
		document.frmSignup.email.focus();
		return 0;
	}
	 if (illegalChars.test(document.frmSignup.email.value)) {
      
		alert('The User name contains illegal characters'); 
		document.frmSignup.email.focus();
		return 0;
		}
	/*if(!filtro(document.frmSignup.txtemail.value))
	{
        alert("Wrong email address")
		document.frmSignup.txtemail.focus()
		return 0;
	}*/

	/*---------------password----------------------*/
	if(document.frmSignup.password.value=="")
	{
		alert('Please fill the field Create Password');
		document.frmSignup.password.focus();
		return 0;
	}
	if(!validatePwd('password'))
	{
		return 0;
	}

	/*---------------password length----------------------*/
	if(document.frmSignup.password.length <=5)
	{
		alert('The password must by 6 characters minimun');
		document.frmSignup.password.focus();
		return 0;
	}

	/*---------------password uno----------------------*/
	if(document.frmSignup.password1.value=="")
	{
		alert('Please fill the field Confirm Password');
		document.frmSignup.password1.focus();
		return 0;
	}

	if(document.frmSignup.password.value != document.frmSignup.password1.value)
	{
		alert('The field Confirm password is not the same like Create Password');
		return 0;
	}

	/*---------------address----------------------*/
	if(document.frmSignup.address.value=="")
	{
		alert('Please fill the field Address');
		document.frmSignup.address.focus();
		return 0;
	}
	/*---------------city----------------------*/
	if(document.frmSignup.city.value=="")
	{
		alert('Please fill the field City');
		document.frmSignup.city.focus();
		return 0;
	}
	/*---------------state----------------------*/
	if(document.frmSignup.locality.selectedIndex==0)
	{
		alert('Please Select State');
		document.frmSignup.locality.focus();
		return 0;
	}
	/*---------------postal code----------------------*/
	/*
	if(document.frmSignup.postalcode.value=="")
	{
		alert('Please fill the field Zipcode');
		document.frmSignup.postalcode.focus();
		return 0;
	}
	if(isNaN(document.frmSignup.postalcode.value))
	{
		alert('Your Postal Code must by numeric');
		document.frmSignup.postalcode.focus();
		return 0;
	}
	if(document.frmSignup.postalcode.value==0)
	{
		alert('Your age should be greater to zero');
		document.frmSignup.postalcode.focus();
		return 0;
	}
	*/
	/*---------------age----------------------*/
	if(document.frmSignup.age.value=="")
	{
			alert('Please fill the field Age');
			document.frmSignup.age.focus();
		return 0;
	}
	if(isNaN(document.frmSignup.age.value))
	{
		alert('Your Age must by numeric');
		document.frmSignup.age.focus();
		return 0;
	}
	if(document.frmSignup.age.value==0)
	{
		alert('Your age should be greater to zero');
		document.frmSignup.age.focus();
		return 0;
	}
	/*---------------gender----------------------*/
	if(document.frmSignup.gender.selectedIndex==0)
	{
		alert('Please select Gender');
		document.frmSignup.gender.focus();
		return 0;
	}
	/*---------------ethnicity----------------------*/
	if(document.frmSignup.ethnicity.selectedIndex==0)
	{
		alert('Please select Ethnicity');
		document.frmSignup.ethnicity.focus();
		return 0;
	}

	/*---------------level----------------------*/
	if(!vallevel())
	{
		alert('Please select Level of Physical Ability');
		return 0;
	}

	/*---------------school----------------------*/
	/*if(document.frmSignup.school.value=="")
	{
		alert('Please fill the field School');
		document.frmSignup.school.focus();
		return 0;
	}*/
	/*---------------grade----------------------*/
	/*if(document.frmSignup.grade.value=="")
	{
		alert('Please fill the field Grade');
		document.frmSignup.grade.focus();
		return 0;
	}*/
	/*---------------Parent name----------------------*/
	if(document.frmSignup.parentname.value=="")
	{
		alert('Please fill the field Parent/Guardian ');
		document.frmSignup.parentname.focus();
		return 0;
	}
	/*---------------grade----------------------*/
	if(document.frmSignup.parentemail.value=="")
	{
		alert('Please fill the field Parent E-mail');
		document.frmSignup.parentemail.focus();
		return 0;
	}
	document.frmSignup.submit();
}

function isEmailAddress(theElement, nombre_del_elemento )
{
var s = theElement.value;
var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;
if (s.length == 0 ) return true;
   if (filter.test(s))
      return true;
   else
     alert("Wrong email address");
theElement.focus();
return false;
}


function validstep2()
{
miFechaActual = new Date();
anoActual = miFechaActual.getFullYear();

		/*---------------first name----------------------*/
	if(document.frmStep2.homephone.value=="")
	{
		alert('Please fill the field Home Phone');
		document.frmStep2.homephone.focus();
		return 0;
	}
//	if(isNaN(document.frmStep2.homephone.value))
//	{
//		alert('The field Home Phone must by numeric');
//		document.frmStep2.homephone.focus();
//		return 0;
//	}
	if(document.frmStep2.cbomonth.selectedIndex==0)
	{
		alert('Please Select month of Birth Date')
		document.frmStep2.cbomonth.focus()
		return 0;
	}
	if(document.frmStep2.cbodate.selectedIndex == 0)
	{
		alert('Please Select date of Birth Date');
		document.frmStep2.cbodate.focus();
		return 0;
	}
	if(document.frmStep2.yearbirthdate.value=="")
	{
		alert('Please fill the field YEAR of Birth Date');
		document.frmStep2.yearbirthdate.focus();
		return 0;
	}
	if(isNaN(document.frmStep2.yearbirthdate.value))
	{
		alert('YEAR of Birth Date must by numeric');
		document.frmStep2.yearbirthdate.focus();
		return 0;
	}
	if(anoActual==document.frmStep2.yearbirthdate.value)
	{
		alert('Please change YEAR of Birth Date');
		document.frmStep2.yearbirthdate.focus();
		return 0;
	}

/*
	if(document.frmStep2.lifestyle.selectedIndex == 0)
	{
		alert('Please Select Lifestyle');
		document.frmStep2.lifestyle.focus();
		return 0;
	}
*/
	if(document.frmStep2.heightfeet.selectedIndex == 0)
	{
		alert('Please Select Height');
		document.frmStep2.heightfeet.focus();
		return 0;
	}
	if(document.frmStep2.heightinches.selectedIndex == 0)
	{
		alert('Please Select Inches');
		document.frmStep2.heightinches.focus();
		return 0;
	}

	if(document.frmStep2.weight.value == "")
	{
		alert('Please fill the field weight');
		document.frmStep2.weight.focus();
		return 0;
	}
	if(isNaN(document.frmStep2.weight.value))
	{
		alert('The field Weight must by numeric');
		document.frmStep2.weight.focus();
		return 0;
	}
/*
	if(document.frmStep2.target_weight.value == "")
	{
		alert('You must enter a weight');
		document.frmStep2.target_weight.focus();
		return 0;
	}
	if(isNaN(document.frmStep2.target_weight.value))
	{
		alert('The field Target Weight must by numeric');
		document.frmStep2.target_weight.focus();
		return 0;
	}

	if(document.frmStep2.cbomonth1.selectedIndex==0)
	{
		alert('Please Select Weight Goal MONTH')
		document.frmStep2.cbomonth1.focus()
		return 0;
	}
	if(document.frmStep2.cbodate1.selectedIndex == 0)
	{
		alert('Please Select Weight Goal DATE');
		document.frmStep2.cbodate1.focus();
		return 0;
	}

	if(document.frmStep2.yearbirthdate1.value=="")
	{
		alert('Please fill the field Weight Goal YEAR');
		document.frmStep2.yearbirthdate1.focus();
		return 0;
	}
	*/

	if(document.frmStep2.parentphone.value=="")
	{
		alert('Please fill the field Day Phone');
		document.frmStep2.parentphone.focus();
		return 0;
	}
	if(document.frmStep2.parentphonother.value=="")
	{
		alert('Please fill the field Phone (Cell or Home)');
		document.frmStep2.parentphonother.focus();
		return 0;
	}
	if(document.frmStep2.acknowledge.checked==false)
	{
		alert('You must agree to the injury waver terms and conditions before you may continue');
		document.frmStep2.acknowledge.focus();
		return 0;
	}
	if(document.frmStep2.initials.value=="")
	{
		alert('You must enter your initials to show compliance with the injury waiver');
		document.frmStep2.initials.focus();
		return 0;
	}
	if(document.frmStep2.acknowledgew.checked==false)
	{
		alert('You must agree to the injury waver terms and conditions before you may continue');
		document.frmStep2.acknowledgew.focus();
		return 0;
	}

	document.frmStep2.submit();
//		alert('validados');

}

function poptastic(image)
{
			myimg=window.open('./images/'+image,'mec','left=20,top=20,width=800,height=845,toolbar=1,resizable=1;');
			myimg.focus();
}

function showbmicalculator()
{
			bmicalc=window.open('./bmicalc.html','bmicalculator','left=20,top=20,width=700,height=400,toolbar=0,resizable=1;');
			bmicalc.focus();
}

function addcontact()
{
		/*---------------email----------------------*/
	if(document.frmContact.firstname.value=="")
	{
		alert('Please fill the field First Name');
		document.frmContact.firstname.focus();
		return 0;
	}
	if(document.frmContact.email.value=="")
	{
		alert('Please fill the field E-mail');
		document.frmContact.email.focus();
		return 0;
	}
	if(document.frmContact.phone.value=="")
	{
		alert('Please fill the field Phone');
		document.frmContact.phone.focus();
		return 0;
	}
		document.frmContact.submit();
}

function validaContactCoach()
{
	if(document.frmContactCoach.Comments.value=="")
	{
		alert('Please fill the field Comments');
		document.frmContactCoach.Comments.focus();
		return 0;
	}
		document.frmContactCoach.submit();
}
/*=======================================*/
function validfirststep()
{
	var filtro  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

	/*---------------first name----------------------*/
	if(document.frmFirst.firstname.value=="")
	{
		alert('Please fill the field Name in Full');
		document.frmFirst.firstname.focus();
		return 0;
	}
	/*---------------last name----------------------*/
	if(document.frmFirst.lastname.value =="")
	{
		alert('Please fill the field Last Name');
		document.frmFirst.lastname.focus();
		return 0;
	}

	/*---------------age----------------------*/
	if(document.frmFirst.age.value=="")
	{
			alert('Please fill the field Age');
			document.frmFirst.age.focus();
		return 0;
	}
	if(isNaN(document.frmFirst.age.value))
	{
		alert('Your Age must by numeric');
		document.frmFirst.age.focus();
		return 0;
	}
	if(document.frmFirst.age.value==0)
	{
		alert('Your age should be greater to zero');
		document.frmFirst.age.focus();
		return 0;
	}

	/*---------------email----------------------*/
	if(document.frmFirst.email.value=="")
	{
		alert('Please fill the field E-mail');
		document.frmFirst.email.focus();
		return 0;
	}
	/*if(!filtro(document.frmSignup.txtemail.value))
	{
        alert("Wrong email address")
		document.frmSignup.txtemail.focus()
		return 0;
	}*/
	/*---------------state----------------------*/


	/*---------------school----------------------*/
	if(document.frmFirst.school.value=="")
	{
		alert('Please fill the field School');
		document.frmFirst.school.focus();
		return 0;
	}
	document.frmFirst.submit();
}

function checkcoderegister()
{
	/*---------------check code----------------------*/
	if(document.frmCheckcode.code.value=="")
	{
		alert('Please type the code');
		document.frmCheckcode.code.focus();
		return 0;
	}
	document.frmCheckcode.submit();
}

function uploadfoto()
{
		if(document.frmimage.foto.value=="")
	{
		alert('Please select photo for upload');
		document.frmimage.foto.focus();
		return 0;
	}
	document.frmimage.submit();
}

function comprueba_extension(formulario, archivo, publico) { 
	extensiones_permitidas = new Array(".gif", ".jpg", ".png", ".jpeg", ".pjpeg"); 
   mierror = ""; 
   if (publico==0) { 
      //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario 
       mierror = "Please select if is Public or Private this Photo"; 

   }else if (!archivo) { 
      //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario 
       mierror = "Please select photo for upload"; 
   }else{ 
      //recupero la extensiÛn de este nombre de archivo 
      extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase(); 
      //alert (extension); 
      //compruebo si la extensiÛn est· entre las permitidas 
      permitida = false; 
      for (var i = 0; i < extensiones_permitidas.length; i++) { 
         if (extensiones_permitidas[i] == extension) { 
         permitida = true; 
         break; 
         } 
      } 
      if (!permitida) { 
         mierror = "Plase check the file extension.\nOnly you can upload: " + extensiones_permitidas.join(); 
       }else{ 
          //submito! 
         //alert ("Todo correcto. Voy a submitir el formulario."); 
         	document.frmimage.submit();
         return 1; 
       } 
   } 
   //si estoy aqui es que no se ha podido submitir 
   alert (mierror); 
   return 0; 
} 

function imagenpublica()
{
	   if(document.frmimage.cboPublic.selectedIndex==0)
	   {
		   alert('Please select if this record is Public or Private');
		   document.frmimage.cboPublic.focus();
		   return 0;
	   }
}

function sendsearch()
{
	if(document.frmsearch.searchtext.value=="")
	{
		   alert('You need type a word to search');
		   document.frmsearch.searchtext.focus();
		   return 0;
	}
   if(document.frmsearch.typesearch.selectedIndex==0)
   {
	   alert('Please select where  you want to search');
	   document.frmsearch.typesearch.focus();
	   return 0;
   }
	document.frmsearch.submit();
}
