// ------------------------------------------------

function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==""||value==" ")
  {alert(alerttxt);return false}
else {return true}
}
}function validate_registration_form(thisform)
{
with (thisform)
{
if (validate_required(firstname,"Please enter your first name")==false)
  {firstname.focus();return false}
}

with (thisform)
{
if (validate_required(surname,"Please enter your surname")==false)
  {surname.focus();return false}
}

with (thisform)
{
if (validate_required(email,"Please enter your email address")==false)
  {email.focus();return false}
}

with (thisform)
{
if (validate_required(picture,"Please fill the required fields marked with *")==false)
  {picture.focus();return false}
}

with (thisform)
{
if (validate_required(contact,"Please fill the required fields marked with *")==false)
  {contact.focus();return false}
}

}

// check email starts here
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function ValidateFormEmail(){
	var emailID=document.regform.email
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }

function ValidateFormpmtbEmail(){
	var emailID=document.regform.pmtbemail
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	}
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	return true
 }


// check email ends here

// mobile number check here 
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 8;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateMobile(){
	var Phone=document.regform.mobile
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Mobile Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Mobile Number, do not include special characters or spaces' ")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }
// mobile check ends here

// phone check starts here

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 8;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidatePhone(){
	var Phone=document.regform.phone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number, do not include special characters or spaces' ")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 }

// phone check ends here

// radio button checker


function radio_button_checker()
{
// set var radio_choice to false
var radio_choice = false;
var radio_choice2 = false;
// Loop from zero to the one minus the number of radio button selections
for (counter = 0; counter < document.regform.coursefee.length; counter++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (document.regform.coursefee[counter].checked)
radio_choice = true; 
}

for (counters = 0; counters < document.regform.paymentoption.length; counters++)
{
// If a radio button has been selected it will return true
// (If not it will return false)
if (document.regform.paymentoption[counters].checked)
radio_choice2 = true; 
}


if (!radio_choice)
{
// If there were no selections made display an alert box 
alert("Please select course fee.")
return (false);
} else if (!radio_choice2){
alert("Please select payment option.")	
}

return (true);
}




/*
function radio_button_checker()
{

for (counter = 0; counter < regform.paymentoption.length; counter++)
{
if (regform.paymentoption[counter].checked)
var radio_choice_payment = "payment";
}

if (radio_choice_payment != "payment"){
payment_radio();
}

for (counters = 0; counters < regform.coursefee.length; counters++)
{
if (regform.coursefee[counters].checked)
var radio_choice_coursefee = "coursefee";
}

if (radio_choice_coursefee != "coursefee"){
coursefee_radio();
return (true);
}
}

function payment_radio ()
{
var radio_choice_payment = "nopayment"; 

for (counter = 0; counter < regform.paymentoption.length; counter++)
{
if (regform.paymentoption[counter].checked)
var radio_choice_payment = "payment";
}

if (radio_choice_payment != "payment"){
alert("Please select the payment option")
return (false);
}
}


function coursefee_radio ()
{
var radio_choice_coursefee = "nocoursefee"; 

for (counter = 0; counter < regform.coursefee.length; counter++)
{
if (regform.coursefee[counter].checked)
var radio_choice_coursefee = "coursefee";
}

if (radio_choice_coursefee != "coursefee"){
alert("Please select the course fee")
return (false);
}
}
*/
// radio button checker ends here
// login content javascript ends here 



// payment instructions hide show start 

function divshow(tablename) 
	{
if (document.getElementById(tablename).style.display == "block") {
	document.getElementById(tablename).style.display = "none";
	} else {
		document.getElementById(tablename).style.display = "block";	
		}
//	document.getElementById("search" + id).style.display = "none";
	}
// payment instructions hide show end