// JavaScript Document
function validate()
	{
	var frm=document.donor;
	reg=frm.fname;
	if (reg.value.length==0)
		{
		alert("Please enter the Name !!!");
		reg.focus();
		return false;
		}	
	reg=frm.lname;
	if (reg.value.length==0)
		{
		alert("Please enter your Father Name !!!");
		reg.focus();
		return false;
		}			
	reg=frm.Day;
	if (reg.value.length==0)
		{
		alert("Please enter the your date of birth !!!");
		reg.focus();
		return false;
		}			
	reg=frm.Month;
	if (reg.value.length==0)
		{
		alert("Please enter the your date of birth !!!");
		reg.focus();
		return false;
		}		
	
	reg=frm.Year;
	if (reg.value.length==0)
		{
		alert("Please enter the your date of birth !!!");
		reg.focus();
		return false;
		}			
	reg=frm.blood;
	if (reg.value.length==0)
		{
		alert("Please select the Blood Group !!!");
		reg.focus();
		return false;
		}		
		/*reg=frm.address;
	if (reg.value.length==0)
		{
		alert("Please enter the your address !!!");
		reg.focus();
		return false;
		}			*/
	reg=frm.city;
	if (reg.value.length==0)
		{
		alert("Please select the city !!!");
		reg.focus();
		return false;
		}
		
	reg=frm.country;
	if (reg.value.length==0)
		{
		alert("Please select the country !!!");
		reg.focus();
		return false;
		}		
	reg=frm.mobile;
	if (reg.value.length==0)
		{
		alert("Please enter your mobile no !!!");
		reg.focus();
		return false;
		}		
		reg=frm.email;
if (reg.value.length !=0)
{
  if (!valid_email(document.donor.email))
	  {
		return false;
	  }		
}
	  
		reg=frm.contacttime;
	if (reg.value.length==0)
		{
		alert("Please enter the your Contact Time !!!");
		reg.focus();
		return false;
		}


return true;
}
	
var checkflag = "false";
function check(field) {
if (checkflag == "false") {
  for (i = 0; i < field.length; i++) {
  field[i].checked = true;}
  checkflag = "true";
  return "Uncheck all"; }
else {
  for (i = 0; i < field.length; i++) {
  field[i].checked = false; }
  checkflag = "false";
  return "Check all"; }
}


function delete_confirm(id)
{
  if(confirm("Are you sure you want to delete?"))
    return true;
  else
    return false;
}	

function SelectOption(OptionListName, ListVal)
{
	for (i=0; i < OptionListName.length; i++)
	{
		if (OptionListName.options[i].value == ListVal)
		{
			OptionListName.selectedIndex = i;
			break;
		}
	}
}		

function has_user_checked_declaration()
{
  if (document.frmResume.agreement.checked == true)
  {
    return(true);
  }
  else
  {
     alert("You must agree to the Declaration before you can apply for this vacancy.");
     document.frmResume.agreement.focus();
     return(false);
  }
}

function valid_email(email_field)
{
  // DEFAULT VALUES FOR PARAMETERS
  var mandatory = 1;
  var focus = 1;
  var name = 'Email Address';

  // COMPARISON VARIABLE FOR UNDEFINED email_field
  var is_undefined;

  var checkOK = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.@\'';
  
  // ARRAY OF ARGUMENT VALUES
  var argv = valid_email.arguments;
  // THE NUMBER OF ARGUMENTS PASSED TO THIS FUNCTION
  var argc = argv.length;

  // THE OBJECT PASSED MUST EXIST OTHERWISE NONE OF THE CHECKS WORK
  if(email_field === is_undefined)
  {
    alert("Object passed to valid_email is undefined");
    return (false);
  }

  // REGULAR EXPRESSION FOR PARAMETERS
  var pattern = /^(\w+)=/;

  // LOOP THROUGH THE ARGUMENTS (1 THROUGH N-1)
  for (var i = 1; i < argc; i++)
  {
    
    var param_name = pattern.exec(argv[i]);

    switch(param_name[1])
    {
      case "not_mandatory":
        if(argv[i].substr(param_name[0].length) == 1)
        {
          mandatory = 0;
        }
        break;
      case "no_focus":
        if(argv[i].substr(param_name[0].length) == 1)
        {
          focus = 0;
        }
        break;
      case "display_name":
        name = argv[i].substr(param_name[0].length);
        break;
      default:
        alert("Unknown parameter " + argv[i] + " passed to valid_email");
        break;
    }  
  }
 
  // IF THE FIELD IN MANDATORY AND NOT FILLED OUT
  if(mandatory == 1)
  {
    if (email_field.value == "")
    {
       alert("Please enter a value for the " + name + " field.");
       if(focus == 1)
       {
          email_field.focus();
       }
       return (false);
     }
  }

  if(mandatory == 0 && email_field.value == "")
  {
    return (true);
  }

  // EMAIL ADDRESSES MUST CONTAIN 1 '@' AND 1 '.' 
  if (email_field.value.indexOf("@")  == -1 || email_field.value.indexOf(".") == -1)
  {
    alert("Invalid email address - " + name + " field. \n A valid email address will contain: letters, numbers and the following characters (not including the double-quotes) \"-'_.@\". It must contain one @ sign and at least one dot.");

    if(focus == 1)
    {
      email_field.focus();
    }
    return false;
  }

  // COMPARED WITH THE LIST OF VALID CHARACTERS IN THE check_ok VARIABLE  
  for (i = 0;  i < email_field.value.length;  i++)
  {
    ch = email_field.value.charAt(i);

    if (checkOK.indexOf(ch) == -1)
    {
      alert("Invalid email address - " + name + " field. \n A valid email address will contain: letters, numbers and the following characters (not including the double-quotes) \"-'_.@\". It must contain one @ sign and at least one dot.");

      if(focus == 1)
      {
        email_field.focus();
      }
      return(false);
    }
  }

  return(true);
}

function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
			alert ("please ener only numarice values"); 
         	blnResult = false;
         }
      }
   return blnResult;
   }
