function validateRButton(button)
{
   var flag = false;
	
	 for(var i = 0; i < button.length; i++) 
		if (button[i].checked == true)
		{
			flag = true;	
		}

	    if(flag == false) 
		{
			
			return false;
		}
}

function validateChkBox(chkBox)
{
   var flag = false;
	
	 for(var i = 0; i < chkBox.length; i++) 
		if (chkBox[i].checked == true)
		{
			flag = true;	
		}

	    if(flag == false) 
		{
			
			return false;
		}
}

function submitFrm()
{ 
   f = document.myForm;
   
    if(f.firstname.value=="")
    {
      alert("Please key in the required First Name field");
      f.firstname.focus();
      return;
    }
	
    
    if(f.lastname.value=="")
    {
      alert("Please select the required Last Name field");
      f.lastname.focus();
      return;
    }
     
    
    if(f.company.value=="")
    {
      alert("Please key in the required Company field");
      f.company.focus();
      return;
    } 	

      	
    if(f.designation.value=="")
    {
      alert("Please key in the required designation field");
      f.designation.focus();
      return;
    }
 	
   
    if(f.add1.value=="")
    {
      alert("Please key in the required Address field");
      f.add1.focus();
      return;
    } 
	
    
    if(f.postal.value=="")
    {
      alert("Please key in the required postal field");
      f.postal.focus();
      return;
    } 

	    
    if(f.country.value=="")
    {
      alert("Please select the required Country field");
      f.country.focus();
      return;
    } 

    
/*    if(f.telCtry.value=="")
    {
      alert("Please key in the required Telephone Country Code field");
      f.telCtry.focus();
      return;
    } 

    
    if(isNaN(f.telCtry.value)==true)
    {
      alert("Please key in integer value in the required Telephone Country Code field ")
      f.telCtry.focus()
      return;
    }
*/	

    if(f.telNo.value=="")
    {
      alert("Please key in the required Telephone No. field");
      f.telNo.focus();
      return;
    }

   	
    if(isNaN(f.telNo.value)==true)
    {
      alert("Please key in integer value in the required Telephone No. field ")
      f.telNo.focus()
      return;
    }

	
    if(f.email.value=="")
    {
      alert("Please key in the required Email field");
      f.email.focus();
      return;
    } 
	
    
    if ((f.email.value != "" >0) && (f.email.value.indexOf("@") == -1 || f.email.value.indexOf(".") == -1)) 
    {
	  alert("Please include a proper Email address");
	  f.email.focus();
	  return;
    }
	
    
    if (validateRButton(f.how) == false)
    { 
	  alert("Please indicate how did you hear about the event");
	  f.how[0].focus();
	  return;
    } 		
    
    
    if (f.how[5].checked == true && f.how_others1.value=="")
    { 
	  alert("Please specify Travel agent state name /country");
	  f.how_others1.focus();
	  return;
    }	  

    
    if (f.how[9].checked == true && f.how_others2.value=="")
    { 
	  alert("Please specify Friends/family/associates");
	  f.how_others2.focus();
	  return;
    }
		  
    
    if (f.how[10].checked == true && f.how_others3.value=="")
    { 
	  alert("Please specify Associations");
	  f.how_others3.focus();
	  return;
    }
		  
    
    if (f.how[11].checked == true && f.how_others4.value=="")
    { 
	  alert("Please specify Magazines adverts");
	  f.how_others4.focus();
	  return;
    }	  
       	
    
    if (f.how[12].checked == true && f.how_others5.value=="")
    { 
	  alert("Please specify Newspaper Adverts");
	  f.how_others5.focus();
	  return;
    }	 

    if (f.how[13].checked == true && f.how_others6.value=="")
    { 
	  alert("Please specify Other websites");
	  f.how_others6.focus();
	  return;
    }	  

    //if (validateRButton(f.member) == false)
    //{ 
	//  alert("Please select type of registration");
	//  f.member(0).focus();
	//  return;
    //} 
	
	if(f.amt.value=="" || f.book.value=="" || f.amt.value==null || f.book.value== null)
    {
      alert("Please specify the NUMBER of delegate badges.");
      f.book.focus();
      return;
    }
	
	if (f.book.value != "")
	{	
		if (f.book.value < 1) {
			alert("Please enter a valid number no less than 1.");
			f.book.focus();
			return;
		}
		
		if (isNaN(f.book.value)) {
			alert("Please enter a valid quantity");
			f.book.focus();
			return;
		}
	}


    if (validateRButton(f.payment) == false)
    { 
	  alert("Please select type of payment");
	  f.payment[0].focus();
	  return;
    }   
    
    if ((f.payment[1].checked== true)&& (f.draf_no.value == ""))
    {
	  alert("Please key in Cheque/Draft No ");
	  f.draf_no.focus();
	  return;

    }	 
	
    if ((f.payment[1].checked== true)&& (f.bank.value == ""))
	{
	  alert("Please key in Bank");
	  f.bank.focus();
	  return;
	}
	
	if ((f.payment[1].checked== true)&& (f.amount_enclose.value == ""))
	{
	  alert("Please key in Total Amount Enclosed");
	  f.amount_enclose.focus();
	  return;
	}
	
	if ((f.payment[1].checked== true)&& (f.amount_enclose.value != ""))
	{
		if(isNaN(f.amount_enclose.value)==true)
    	{
      	alert("Please key in integer value in the required Total Amount Enclosed field ")
      	f.amount_enclose.focus()
      	return;
    	}
	}		 

	f.amt_value.value = f.amt.value;
	
	if (f.agree.checked==false)
	{
		alert("Kindly check the agreement box to proceed!");
		f.agree.focus();
		return;	
	}
	else

    index = document.myForm.country.selectedIndex;
		if (index != "") {
			document.myForm.CountryName.value = document.myForm.country[index].text;
		}
		
	f.action="reg_process.asp";
	f.submit();
	
}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function calculateCost() 
{		
var amt = 0;
var total = 0;		
       
var book = document.myForm.book.value;	

if (document.myForm.book.value != "")
{	
	if (document.myForm.book.value < 1) {
			alert("Please enter a valid number no less than 1.");
			document.myForm.book.focus();
			return;
	}
	
	if (isNaN(book)) {
			alert("Please enter a valid quantity");
			document.myForm.book.focus();
			return;
	}
	
	//total = 393.76 * parseInt(book);				
	total = document.myForm.conventionrate.value * parseInt(book);
	document.myForm.amt.value = formatCurrency(total);
	
	//if (document.myForm.member(0).checked== true)
	//{ 
		//total = 393.76 * parseInt(book);				
		//total = document.myForm.conventionrate.value * parseInt(book);
		//document.myForm.amt.value = formatCurrency(total);
	//}else
	//if (document.myForm.member(1).checked== true){
		//total = 578 * parseInt(book);				
		//document.myForm.amt.value = formatCurrency(total);
	//}else
	//{
		//total = 428 * parseInt(book);				
		//document.myForm.amt.value = formatCurrency(total);
	//}	
}
else {
	alert("Please enter number of delegates");
	document.myForm.book.focus();
	return;	
}	

}

function setNo()
{
  
  totalNo = document.myForm.book.value;
  document.myForm.book1.value = totalNo;
  //document.myForm.book2.value = totalNo;
  //document.myForm.book3.value = totalNo;
  calculateCost();
}

