// JavaScript Document

//FUNCTION TO CHECK IF FIELD IS EMPTY
function isemp(field,message) {

if (field.value == "")

{

	alert("Please key in your "+message)
	
	field.focus();

    	return false;

}



return true;

}


//--------------------------------------------------------------------------------------------------------
//FUNCTION TO CHECK IF FIELD IS EMPTY FOR (ADMINISTRATIVE QUESTIONS)
function isempquestion(field,message) {

if (field.value == "")

{

	alert("Please tell us "+message)

	field.focus();

    	return false;

}



return true;

}


//--------------------------------------------------------------------------------------------------------
//FUNCTION TO CHECK IF EMAIL IS VALID
function isValidEmail(field) {



validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;



   // search email text for regular exp matches

    if (field.value.search(validRegExp) == -1)

   {

   	alert('Please key in a valid email address.');

      	field.focus();

      	return false;

	

   }



return true;

}


//--------------------------------------------------------------------------------------------------------
//VALIDATE SELECTBOX
function isselect(field,message) {



if (field.selectedIndex <= 0)

{

	alert("Please select "+message)

	field.focus();

    	return false;

}



return true;

}


//--------------------------------------------------------------------------------------------------------
//VALIDATE CHECKBOX
function ischeck(field,message)
{
	
	valid=false
	for(i=0;i<field.length;i++)
	{
		if(field[i].checked)
		{
			valid=true;
		}
	}

	if(!valid)
	{
		alert("Please select an "+message);
		field[0].focus();

		return false;
	}
	else
	{return true;}

}


//***** ***** ***** ***** *****     ***** ***** ***** ***** *****//
function IsCheckBoxGroupChecked(FormName, CheckBoxName, TotalCheckBox, ErrorMessage)
{
  var c1 = 0;
  var TotalCheckBoxChecked = 0;

  for(c1 = 1; c1 <= TotalCheckBox; c1++)
  {
    if(document.forms[FormName].elements[CheckBoxName + "-" + c1].checked == true)
    {
      TotalCheckBoxChecked = TotalCheckBoxChecked + 1;
    }
  }

  if(TotalCheckBoxChecked > 0)
  {
    return true;
  }
  else
  {
    document.forms[FormName].elements[CheckBoxName + "-1"].focus();
    alert(ErrorMessage);
    return false;
  }
}


//--------------------------------------------------------------------------------------------------------
//VALIDATE RADIO BUTTON
function isradio(field,message)
{
	var chosenradio = false;
	for (counterA = 0; counterA < field.length; counterA++)
	{
 		if (field[counterA].checked)
		 chosenradio = true;
 	}
 	if (!chosenradio)
 	{
		alert ("Please choose your "+message);
		field[0].focus();
 		return false;
 	}
 	else
	{
	return true;
	}

}


//--------------------------------------------------------------------------------------------------------
//VALIDATE TEXTAREA
function validtextarea(field,message)
{
	if (field.value.length < 1)
	{
		alert("Please fill in your "+message)
		field.focus();
		return false;
		
	}

return true;

}



//--------------------------------------------------------------------------------------------------------
//FUNCTION THAT PERFORMS ALL FUNCTIONS, DEFINED IN THE ONSUBMIT EVENT HANDLER
function check(registration)

{
  if (isselect(document.registration.title,"Title"))
	 {
	   if (isemp(document.registration.name,"Name"))
		  {
		    if (isradio(document.registration.nationality,"Nationality")) 
		       {
		        if (isemp(document.registration.ic,"IC (New)/Passport No")) 									                      
					{
					  if (isselect(document.registration.occupation,"Occupation"))  
						  {
						   if (isemp(document.registration.address,"Residential Address")) 
						    {
							if (isemp(document.registration.city,"City"))
							 {
							  if (isselect(document.registration.state,"State")) 
							  {
								if (isemp(document.registration.postcode,"Postcode")) 
								{
								 if (isselect(document.registration.contactway,"Preferred Contact way")) 
								  {
									if (isemp(document.registration.hp1,"Contact No. - Area Code")) 
									   {
									     if (isemp(document.registration.hp2,"Contact No."))
										  {
	                                        if (isemp(document.registration.hp3,"Contact No.")) 
											   {
									            if (isemp(document.registration.of1,"Office No. - Area Code")) 
                                         {
									      if (isemp(document.registration.of2,"Office No.")) 
										  {
	                                       if (isemp(document.registration.of3,"Office No.")) 
										    {
									      if (isemp(document.registration.mp1,"Mobile Phone No. - Area Code")) 
										    {
									      if (isemp(document.registration.mp2,"Mobile Phone No."))
										  {
	                                      if (isemp(document.registration.mp3,"Mobile Phone No.")) 
										    {
						           if (isemp(document.registration.email,"Email"))
					                   {
						                if (isValidEmail(document.registration.email))
										{
										 if (isselect(document.registration.project,"project")) 
										   {
										    if (isselect(document.registration.budget,"budget")) 
										       {
										        if (isselect(document.registration.way,"The way you come to find out about our properties")) 
				                                                           {
																			 return true;
																				
																		  }
																	    } 
                                                                     }
	                                                               }
	                                                              }
	                                                             }
	                                                            }
	                                                           }
	                                                          }
	                                                         }
	                                                        }
	                                                        }
	                                                     }
	                                                     }
	                                                     }
	                                                   }
	                                                  }
	             									 }
		                                           }
	 											}
			   								}
		  							}
	 						}
						}
   return false;
   

}
