$(document).ready(function(){
hideHint('#need_tuition_hint');
$('#container_t').hide();
$('#s_name').focus(function(){
showHint("#name_hint","Please Enter Your Name!");
});
$('#s_email').focus(function(){
showHint("#email_hint","Your e-mail address won't be published on your profile, so others won't see it. Plz don't use Hotmail/Rediffmail");
});
$('#s_aemail').focus(function(){
showHint("#aemail_hint","Enter Your Alternate Email, If you have.");
});
$('#s_password').focus(function(){
showHint("#password_hint","Password should be minimum 6 characters and maximum 12 characters.");
});
$('#s_cpassword').focus(function(){
showHint("#cpassword_hint","Please type your password once again!");
});
$('#s_zipcode').focus(function(){
showHint("#zipcode_hint","Your Zipcode is hidden to others!");
});
$('#s_phone').focus(function(){
showHint("#phone_hint","Please Enter Valid Phone No!");
});
$('#s_details').focus(function(){
showHint("#details_hint","Other Information. Eg.education ranks etc.!");
});


$('#s_city').focus(function(){
showHint("#city_hint","Please Enter Your City Name!");
});

//input blur


$('#s_name').blur(function(){
hideHint("#name_hint");		
});

$('#s_email').blur(function(){
hideHint("#email_hint");		
});

$('#s_aemail').blur(function(){
hideHint("#aemail_hint");		
});

$('#s_password').blur(function(){
hideHint("#password_hint");	
});

$('#s_cpassword').blur(function(){
hideHint("#cpassword_hint");	
});

$('#s_zipcode').blur(function(){
hideHint("#zipcode_hint");	
});
$('#s_phone').blur(function(){
hideHint("#phone_hint");	
});
$('#s_details').blur(function(){
hideHint("#details_hint");	
});
$('#s_tuition_level').blur(function(){
hideHint("#tuition_level_hint");	
});

$('#s_city').blur(function(){
hideHint("#city_hint");	
});
$('#s_state').blur(function(){
hideHint("#state_hint");	
});


$('#s_class').blur(function(){
$('#class_hint').hide();	
});
$('#s_tuition_frequency').blur(function(){
$('#frequency_hint').hide();	
});

$('#s_dob_date,#s_dob_month,#s_dob_year').blur(function(){
$('#dob_hint').hide();	
});

$('#s_country').blur(function(){
$('#country_hint').hide();	
});

$('#s_state').blur(function(){
$('#state_hint').hide();	
});

//unique function
function showHint(id,msg)
{
$(id).removeClass("error_hint");
$(id).empty();
$(id).addClass("hint_help");
$(id).html(msg);
$(id).fadeIn("5000");

}



function showErrHint(id,msg)
{
$(id).removeClass("hint_help");
$(id).empty();
$(id).addClass("error_hint");
$(id).html(msg);
$(id).fadeIn("5000");
$(id).focus();
//$(id).css("borderColor","red");

}

//hide_help_hint

function hideHint(id)
{
$(id).fadeOut("5000");
$(id).empty();
$(id).removeClass("hint_help");

//$(id).hide();

}
//-------------------------------------
// Form validation begins

$('#student_reg_form').submit(function(){
var isValid=true;
var s_email=escape($('#s_email').val());
var s_name=escape($('#s_name').val());
var s_password=escape($('#s_password').val());
var s_cpassword=escape($('#s_cpassword').val());
var s_tuition_level=escape($('#s_tuition_level').val());
var s_class=escape($('#s_class').val());
var s_tuition_frequency=escape($('#s_tuition_frequency').val());
var s_details=escape($('#s_details').val());
var s_dob_date=escape($('#s_dob_date').val());
var s_dob_month=escape($('#s_dob_month').val());
var s_dob_year=escape($('#s_dob_year').val());
var s_country=escape($('#s_country').val());
var s_state=escape($('#s_state').val());
var s_city=escape($('#s_city').val());
var s_zipcode=escape($('#s_zipcode').val());
var s_phone=escape($('#s_phone').val());
var s_mobile=escape($('#s_mobile').val());


/*---------- email-------------- */
var emailmust=/^.+@.+\..{2,3,4,6}$/;
var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
var forbemail= "rediffmail";
var forbmail= "hotmail";

if (s_email.match(illegalChars) || s_email.length<8) {
showErrHint("#email_hint","Invalid Email Address!")
error_msg=" - Email";
isValid=false;

}

if (s_email.match(forbemail)){
showErrHint("#email_hint","Please do not use Rediffmail!")
isValid=false;
}

if (s_email.match(forbmail)){
showErrHint("#email_hint","Please do not use Hotmail!")
isValid=false;
}

if(s_email.indexOf("@")==-1 || s_email.indexOf(".")==-1)
{
showErrHint("#email_hint","Invalid Email Address!");
isValid=false;
}




/*---------------------*/

/*---------------------username-------------*/
/*
var illegalchar2 = /\W/;
if (illegalchar2.test(s_username) || s_username.length<6 || s_username.length>15) {
showErrHint("#username_hint","Invalid username. Only Letters & Numbers (a-z,0-9) allowed!");
isValid=false;
    } 
*/
/*-----------NAME-------------------*/
if(s_name.length<2)
{
showErrHint("#name_hint","Please Enter Your Name!");
isValid=false;	
}
/*--------------------------*/

/*-----------PASSWORD-------------------*/
if(s_password.length<6|| s_password.length>12)
{
showErrHint("#password_hint","Password must be within 6-12 characters!");
isValid=false;	
}
/*--------------------------*/
/*-----------CONFIRM PASSWORD-------------------*/
if(s_cpassword.length<6|| s_password.length>12)
{
showErrHint("#cpassword_hint","Passwords doesn't match!");
isValid=false;	
}

if($('#s_password').val()!=$('#s_cpassword').val())
{
showErrHint("#cpassword_hint","Passwords doesn't match!");
isValid=false;	
}
/*--------------------------*/
/*-------------------NEED TUITION---------------------*/
var need_2tion=$("input[@name=need_tuition]:checked").val();
if(need_2tion!='yes' && need_2tion!='no')
{
showErrHint("#need_tuition_hint","Please Select Your Tuition Requirement Status!");
isValid=false;

}
else
{
hideHint('#need_tuition_hint');
}

/*-----------DATE OF BIRTH-------------------*/
if(s_dob_date=='DD' || s_dob_month=='MMM' || s_dob_year=='YYYY')
{
showErrHint("#dob_hint","Please Select Your Date of Birth!");
isValid=false;	
}

/*--------------------------*/
/*-----------COUNTRY-------------------*/
if(s_country=='Select')
{
showErrHint("#country_hint","Please Select Your Country!");
isValid=false;	
}

/*--------------------------*/


/*--------------------------*/


/*-----------CITY-------------------*/
if($('#s_city').val().length<3)
{
showErrHint("#city_hint","Please Enter Your City!");
isValid=false;	
}
/*-------------------------*/




if(need_2tion=='yes')
{

if($('#s_tuition_level').val()=='Select'){
showErrHint("#tuition_level_hint","Please Select Tuition Level!");
isValid=false;
}

if($('#s_tuition_level').val()!='Select')
{
if($('#s_class').val()=='Select'){
showErrHint("#class_hint","Please Select Class!");
isValid=false;
}
else{
hideHint('#class_hint');
}
if($('#s_subject').val()=='Select'){
showErrHint("#subject_hint","Please Select Subject!");
isValid=false;
}

if($('#s_tuition_frequency').val()=='Select'){
showErrHint("#frequency_hint","Please Select Tuition Frequency!");
isValid=false;
}
}
}
/*--------------------------*/

/*-----------ZIPCODE-------------------*/
if($('#s_zipcode').val().length<5)
{
showErrHint("#zipcode_hint","Please Enter Valid ZipCode!");
isValid=false;	
}

/*--------------------------*/



/*-----------------PHONE------------*/
var phone = s_phone.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if (isNaN(parseInt(phone)) || phone.length<6) {
showErrHint("#phone_hint","Please Enter Valid Phone No!");
isValid=false;
}
/*----------------------------*/
/*-----------------PHONE------------*/
var mobile = s_mobile.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
if(mobile.length>0){
if (isNaN(parseInt(mobile))) {
showErrHint("#mobile_hint","Please Enter Valid Mobile No!");
isValid=false;
}
}
/*----------------------------*/

/*--------------------------*/

if(isValid==false){
return false;
}
else{
return true;
}
	
});
$('a.username_availability').click(function(){
 showHint("#username_hint","Loading...");
  

 
var usrname=$('#s_username').val();
var illegalchar2 = /\W/;

if (illegalchar2.test(usrname) || usrname.length<6 || usrname.length>15) {
showErrHint("#username_hint","Invalid username. Only Letters & Numbers (a-z,0-9) allowed!");
  } 
  else{
//var rand=Math.floor(Math.random()*num)+1;
$.get("check_username.php",{q:$('#s_username').val(),b:5},function(response){
$('#username_hint').removeClass("hint_help");
$('#username_hint').removeClass("error_hint");
$('#username_hint').html(response);
$('#username_hint').fadeIn("8000");
});
}
});
/*****************/
$('#s_country').change(function(){
 if($(this).val()!='Select')
{
$('#s_state').attr("disabled",true);
$.get("state_list.php",{cid:$('#s_country').val()},function(response){
$('#s_state').remove();
 
$('#state_container').append(response);
$('#s_state').attr("disabled",false);
});
}
else{
$('#s_state').attr("disabled",true);
}
/**************/

});


//----------------------------------------


$('#s_tuition_level').change(function(){
 if($(this).val()!='Select')
{
$('#s_class').attr("disabled",true);
$.get("class_list.php",{lid:$('#s_tuition_level').val()},function(response){
$('#s_class').remove();
 
$('#class_container').append(response);
$('#s_class').attr("disabled",false);
});
}
else{
$('#s_class').attr("disabled",true);
$('#class_hint').hide();
}

});

//****************************/

/*******************************/
$('#s_subject').change(function(){
if($('#s_subject').val()=='Others')
{
$('#other_subject').empty();
$('#other_subject').append("Enter Subject <input style='width:120px' type='text' id='subject_other' name='subject_other' size='12'>");


}
else
{
$('#other_subject').empty();
$('#other_subject').append("<span id='subject_hint' class='hint'></span>");	
}

	
});
$('#subject_other').focus(function(){
$('#subject_other').val()="";
});

$('#s_class').blur(function(){
$('#class_hint').hide();	
});

$('#need_yes').click(function(){
$('#container_t').show();
});

$('#need_no').click(function(){
$('#container_t').hide();
});


});
