
function showHideInput(chk)
{
	var str = "";
	chkname = chk.id;
	str = chkname.substring(3);
	layername = "divRel" + str;
	if(chk.checked)
	{
		document.getElementById(layername).className = "visible"
	}	
	else
	{
		document.getElementById(layername).className = "invisible"
	}


}

function showHideSpouse(sel)
{
	 if(sel.selectedIndex == "1")
	 {
		 document.getElementById("Rel8").checked = false;
		 document.getElementById("divRelName8").className = "invisible"; 
		 document.getElementById("divRel8").className = "invisible";
	 }
	 else
	 {
		 document.getElementById("divRelName8").className = "visible";
	 }
}

// For Contact Number
			// 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 + "+";

			var NumberDelimiters = "-";
			// characters which are allowed in international phone numbers
			// (a leading + is OK)
			var validChars = NumberDelimiters;
			// Minimum no of digits in an international phone no.
			var minDigitsInIPhoneNumber = 6;

			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 isInteger(s)
	{   var i;
		for (i = 0; i < s.length; i++)
		{   
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		return true;
	}
	
var sErr1,sErr2 ;
sErr2="";
sErr1="Please fill in the missing information\n\n";


function check()
{
var frm = document.ApplForm; 
var citizenship_choice = false;

 sErr2 = "";
 if(frm.FName.value == "")
 {
    sErr2=sErr2+"First Name\n";
	document.getElementById("FName").style.backgroundColor="#F9F9C7";
 }
 else
 {
	 document.getElementById("FName").style.backgroundColor="";
 }
 
 if(frm.LName.value == "")
 {
   sErr2=sErr2 + "Last Name\n";
   document.getElementById("LName").style.backgroundColor="#F9F9C7";
   
 }
 else
 {
	 document.getElementById("LName").style.backgroundColor="";
 }
 
 if(frm.Nationality[frm.Nationality.selectedIndex].value == "")
 {
   sErr2=sErr2 + "Nationality\n"
   document.getElementById("Nationality").style.backgroundColor="#F9F9C7";
 }
 else
 {
	 document.getElementById("Nationality").style.backgroundColor="";
 }
 
  if(frm.Nationality.value.toUpperCase()=="BAHRAINI")  
    { 
		if(frm.CPR.value=="")
			{
				sErr2=sErr2+"CPR\n"
				document.getElementById("CPR").style.backgroundColor="#F9F9C7";
			}
			else
			{
				document.getElementById("CPR").style.backgroundColor="";
			}
    }
    else if(frm.Nationality.value.toUpperCase()!="BAHRAINI")
     {
      if(frm.CPR.value=="" && frm.Passport.value == "")
      	{
			sErr2=sErr2+"CPR or Passport\n"
			document.getElementById("CPR").style.backgroundColor="#F9F9C7";
			document.getElementById("Passport").style.backgroundColor="#F9F9C7";
		}
		else
		{
			document.getElementById("CPR").style.backgroundColor="";
			document.getElementById("Passport").style.backgroundColor="";
		}			
     }	 
	if(frm.CPR.value!="")	
	{
		if(!isInteger(frm.CPR.value))
		  {
			sErr2=sErr2 + "Invalid CPR Number\n"
		  }
		 if (frm.CPR.value.length<9 || frm.CPR.value.length>9)
		  {
			sErr2=sErr2 + "Invalid CPR Lenght\n";
		  }	
	document.getElementById("CPR").style.backgroundColor="#F9F9C7";
	}

	else
	{
		document.getElementById("CPR").style.backgroundColor="";
	}
 

	  
 if (frm.NoofChidren.value != "" && isNaN(frm.NoofChidren.value)==true)
 {
   sErr2=sErr2+"Number of Children must be a number\n"
   document.getElementById("NoofChidren").style.backgroundColor="#F9F9C7";
 }
 else
 {
	 document.getElementById("NoofChidren").style.backgroundColor="";
 }
 if (frm.Gender.value == "") 
 {
   sErr2=sErr2+"Gender\n";
   document.getElementById("Gender").style.backgroundColor="#F9F9C7";
 }
 else
 {
	document.getElementById("Gender").style.backgroundColor=""; 
 }
 if (frm.DOBdd.value == "" || frm.DOBmm.value=="" || frm.DOByy.value=="")
 {
   sErr2=sErr2+"DOB\n";
   document.getElementById("DOBdd").style.backgroundColor="#F9F9C7"; 
   document.getElementById("DOBmm").style.backgroundColor="#F9F9C7"; 
   document.getElementById("DOByy").style.backgroundColor="#F9F9C7"; 
 }
 else
 {
   document.getElementById("DOBdd").style.backgroundColor=""; 
   document.getElementById("DOBmm").style.backgroundColor=""; 
   document.getElementById("DOByy").style.backgroundColor="";  
 }
   
 if( frm.MaritalStatus.value == "")
 {
   sErr2=sErr2+"Marital Status\n";
   document.getElementById("MaritalStatus").style.backgroundColor="#F9F9C7"; 
 }
 else
 {
	 document.getElementById("MaritalStatus").style.backgroundColor=""; 
 }
 if(frm.Telephone.value == "" )
 {
   sErr2=sErr2+"Telephone\n";
   document.getElementById("Telephone").style.backgroundColor="#F9F9C7"; 
 }
 else
 {
	 if (frm.Telephone.value != "" && checkInternationalPhone(frm.Telephone.value)==false)
   {
	   sErr2=sErr2+"Invalid Telephone number\n";
	   document.getElementById("Telephone").style.backgroundColor="#F9F9C7";
   }
   else
   {
	   document.getElementById("Telephone").style.backgroundColor="";
   }
 }

if(frm.Mobile.value =="")
 {
   sErr2=sErr2+"Mobile\n"
   document.getElementById("Mobile").style.backgroundColor="#F9F9C7";
 }
 else
 {
	if (frm.Mobile.value != "" && checkInternationalPhone(frm.Mobile.value)==false)
   {
	   sErr2=sErr2+"Invalid Mobile number\n";
	   document.getElementById("Mobile").style.backgroundColor="#F9F9C7";
   }
   else
   {
	   document.getElementById("Mobile").style.backgroundColor="";
   }
 }
 
if ((frm.citizenship.value == "BAHRAINI") && (frm.Nationality.value.toUpperCase()!="BAHRAINI"))
 {
	sErr2=sErr2 + "Only Bahraini Eligible for this post\n";
 } 
 
if ((frm.citizenship.value == "NONBAHRAINI") && (frm.Nationality.value.toUpperCase()=="BAHRAINI"))
 {
	sErr2=sErr2 + "Only Expat Eligible for this job\n";
 }
 
 //if(frm.Email.value =="")   
  // sErr2=sErr2+"Email\n"
 //if(frm.SiteKnowHow.value =="")   
  // sErr2=sErr2+"How did you know of this site?\n"
   
 //checkdob();
   
if (sErr2 != "" )
{
  alert(sErr1+sErr2);
  return false;
}
else 
{
  //if(CheckEmail() && checkdob())
   if(checkdob())
    return true;  
   else
    return false;  
 }  
}
function checkdob()
{
var yval =document.ApplForm.DOByy.value;
var mval =document.ApplForm.DOBmm.value;
var dval =document.ApplForm.DOBdd.value;
if (isNaN(mval) || mval<1 || mval > 12) 
{ 
 alert("Invalid Month")
 document.ApplForm.DOBmm.focus();
 return false;
}
 if (isNaN(dval)|| dval < 1 || dval > 31)
{ 
 alert("Invalid Date")
 document.ApplForm.DOBdd.focus();
 return false;
}
 if (isNaN(yval))
{ 
 alert("Year is not a number")
 document.ApplForm.DOByy.focus();
 return false;
}
if(yval.length == 1 || yval.length == 3 )
{
  alert("Pl. enter year in yyyy format")
  document.ApplForm.DOByy.focus();
  return false;
}
return true;
}



function checkForm()
{
var frm = document.frm; 
 sErr2 = "";
 if(frm.txtName.value == "")
 {
    sErr2=sErr2+"First Name\n";
 }
   
 if(frm.txtTel.value == "")
 {
    sErr2=sErr2+"Tel Number\n";
 }
   
 if(frm.txtEmail.value == "")
 {
    sErr2=sErr2+"Tel Number\n";
 }

var occChoice_choice = false;
var counter=0;
var wChoice_choice = false;
var wcounter=0;
			
			
for (counter = 0;  counter < frm.rdoOccasion.length; counter++)
	{
	if (frm.rdoOccasion[counter].checked)
	occChoice_choice = true; 
	}
	

	if (!occChoice_choice)
	{
	sErr2=sErr2+"Occasion\n";
	}

  if((frm.rdoOccasion[0].checked==true) && (frm.selOccasion[frm.selOccasion.selectedIndex].value == ""))
		{
			sErr2=sErr2+"Please select Occasion\n";
		}
   else if((frm.rdoOccasion[1].checked==true) && (frm.txtOccasion.value == ""))
		{
			sErr2=sErr2+"Please enter Occasion\n";
		}

 if(frm.txtDate.value == "")
 {
    sErr2=sErr2+"Date\n";
 }
 
 if(frm.txtGuest.value == "")
 {
    sErr2=sErr2+"No of Guest\n";
 }
 
  if (frm.txtGuest.value != "" && isNaN(frm.txtGuest.value)==true)
 {
   sErr2=sErr2+"Number of Guest must be a number\n";
 }
 
for (wcounter = 0;  wcounter < frm.rdoWhere.length; wcounter++)
	{
	if (frm.rdoWhere[wcounter].checked)
	wChoice_choice = true; 
	}
	

	if (!wChoice_choice)
	{
	sErr2=sErr2+"Where? \n";
	}

  if((frm.rdoWhere[0].checked==true) && (frm.selWhere[frm.selWhere.selectedIndex].value == ""))
	{
		sErr2=sErr2+"Please select Where\n";
	}
	else if((frm.rdoWhere[1].checked==true) && (frm.txtOccasion.value == ""))
	{
		sErr2=sErr2+"Please enter Where\n";
	}
	

   

if (sErr2 != "" )
{
  alert(sErr1+sErr2);
  return false;
}
else
{
	return true;
}
}
function checkdob()
{
var yval =document.ApplForm.DOByy.value;
var mval =document.ApplForm.DOBmm.value;
var dval =document.ApplForm.DOBdd.value;
if (isNaN(mval) || mval<1 || mval > 12) 
{ 
 alert("Invalid Month")
 document.ApplForm.DOBmm.focus();
 return false;
}
 if (isNaN(dval)|| dval < 1 || dval > 31)
{ 
 alert("Invalid Date")
 document.ApplForm.DOBdd.focus();
 return false;
}
 if (isNaN(yval))
{ 
 alert("Year is not a number")
 document.ApplForm.DOByy.focus();
 return false;
}
if(yval.length == 1 || yval.length == 3 )
{
  alert("Pl. enter year in yyyy format")
  document.ApplForm.DOByy.focus();
  return false;
}
return true;
}

function FocusOn()
{
document.ApplForm.FName.focus();
}

function CheckEmail()
 {
 var sEmail=document.frm.Email.value
if (sEmail.indexOf("@")==-1 || sEmail.indexOf(".")==-1)
		{
		alert("Please Enter a valid Email");
		return false;
		}
		else
		return true;
 }
 
 function calccharleft(f,i)
{
   var maxlen = 255;
   var x;
   var obj;
   x=f.value;
   obj=eval("document.ApplForm.numChar"+i)
   
     charleft = maxlen - f.value.length;
   
      obj.value = charleft
   
     if(obj.value<0)
        obj.value = 0;
     if(f.value.length > 255)
       f.value=x.substring(0,255) 
}
   // --->
