function empty(e, msg)
{
    if (e.value == '')
    {
        alert('Please input ' + msg);
        e.focus();
        return true;
    }

    return false;
}

function email(e, msg)
{
    if (e.value.search(/^\S+\@\S+\.\S+$/) == -1)
    {
        alert('Please enter a valid email address');
        e.focus();
        return false;
    }

    return true;
}

function common_chk()
{
    var countryname;
    countryname = window.document.reg_form.country.options[window.document.reg_form.country.selectedIndex].text;
	
    if (empty(window.document.reg_form.name, 'Name'))
        return false;
/*
    if (empty(window.document.reg_form.company, 'Company'))
        return false;
*/
    if (empty(window.document.reg_form.address, 'Address'))
        return false;
    if (empty(window.document.reg_form.country, 'Country'))
        return false;
    if (window.document.reg_form.country.value == 'others' && window.document.reg_form.other_country.value == '')
    {
		alert("Please Insert others country.");
		window.document.reg_form.other_country.focus();
		return false;
    }
    if (empty(window.document.reg_form.postal, 'Postal / Zip Code'))
        return false;
    if (document.reg_form.telc.value.length > 3)
    {
		alert('Country code for Tel cannot be more than 3 digits');
		document.reg_form.telc.focus();
		return false;
	}
	if (document.reg_form.tela.value.length > 4)
    {
		alert('Area code for Tel cannot be more than 4 digits');
		document.reg_form.telc.focus();
		return false;
	}
    if ((empty(window.document.reg_form.telno, 'Telephone no'))||(empty(window.document.reg_form.telc, 'Telephone Country Code'))||(empty(window.document.reg_form.tela, 'Telephone Area Code')))
		   return false;


/*       	
    if (document.reg_form.hpc.value.length > 3)
    {
		alert('Country code for Handphone cannot be more than 3 digits');
		document.reg_form.hpc.focus();
		return false;
	}
	if (document.reg_form.hpa.value.length > 4)
    {
		alert('Area code for Hpndphone cannot be more than 4 digits');
		document.reg_form.hpa.focus();
		return false;
	}
    if (empty(window.document.reg_form.hpno, 'Handphone no'))
       	return false;
*/       	
	if (document.reg_form.faxc.value.length > 3)
    {
		alert('Country code for Fax cannot be more than 3 digits');
		document.reg_form.telc.focus();
		return false;
	}
	if (document.reg_form.faxa.value.length > 4)
    {
		alert('Area code for Fax cannot be more than 4 digits');
		document.reg_form.telc.focus();
		return false;
	}
               	
    if (!email(window.document.reg_form.email, 'Email'))
        return false;

    return true;
}

function blank(e)
{
    if (e.value == '')
        return true;
    else
	return false;
}

function chk_visitor()
{
	var f = document.reg_form;
    if (common_chk())
    {
	
    	if (chk_check(f.fa) == 0 && (f.faf_others.value == '' || f.fal_others.value == ''))
    	{
    	alert("Please tick at least 1 option for question 1");
	    return false;
	    }
	    if (chk_check(f.fb) == 0 && f.fb_others.value == '')
    	{
    	alert("Please tick at least 1 option for question 2");
	    return false;
	    }
	    if (chk_check(f.fc) == 0 && f.fc_others.value == '')
    	{
    	alert("Please tick at least 1 option for question 3");
	    return false;
	    }
	    if (chk_check(f.fd) == 0)
    	{
    	alert("Please tick at least 1 option for question 4");
	    return false;
	    }
/*	    if (chk_check(f.fe) == 0 && f.fe_others.value == '')
    	{
    	alert("Please tick at least 1 option for question 5");
	    return false;
	    }
*/	    if (chk_check(f.ff) == 0)
    	{
    	alert("Please tick at least 1 option for question 6");
	    return false;
	    }
/*	    if (chk_check(f.fg) == 0)
    	{
    	alert("Please tick at least 1 option for question G");
	    return false;
	    }
	    if (chk_check(f.fh) == 0)
    	{
    	alert("Please tick at least 1 option for question H");
	    return false;
	    }
*/	    
		return chk_text(f.fh);
	    
    }
    return false;
}

function chk_text(obj)
{
	var f = document.reg_form;
	if (chk_check(f.fh) > 0) {
	for (i=0;i<obj.length;i++)
	{

		if(obj[i].value == 'Newspaper' && obj[i].checked && f.fh_newspaper.value == '')
		{
			alert("Please insert Newspaper for question H.");
			f.fh_newspaper.focus();
			return false;
		}
		if(obj[i].value == 'Radio' && obj[i].checked && f.fh_radio.value == '')
		{
			alert("Please insert Radio for question H.");
			f.fh_radio.focus();
			return false;
		}
		if(obj[i].value == 'Publication' && obj[i].checked && f.fh_publication.value == '')
		{
			alert("Please insert Publication for question H.");
			f.fh_publication.focus();
			return false;
		}
		if(obj[i].value == 'Internet' && obj[i].checked && f.fh_internet.value == '')
		{
			alert("Please insert Internet for question H.");
			f.fh_internet.focus();
			return false;
		}
		if(obj[i].value == 'Others' && obj[i].checked && f.fh_others.value == '')
		{
			alert("Please insert Others for question H.");
			f.fh_others.focus();
			return false;
		}	
	}
	}
	return true;	
}

function chk_check(obj)
{
	var t = 0;
	for (i=0;i<obj.length;i++)
	{
	 if (obj[i].checked) t++; 
	}
	return t;
}

function seminar_chk()
{
    if (common_chk()) 
    {
    	if (!window.document.reg_form.s1.checked && !window.document.reg_form.s2.checked && !window.document.reg_form.s3.checked) {
    	    alert('Please select at least one seminar');
    	    return false;
    	}	 
    	return true;   
    }
    return false;
}
