function EmailValid(aemail)
        {

                 //if email field is empty - warning displays and return false
                if(aemail=="")
                {
                        alert ("Please enter your email ID.");
                        return false;
                }
                //get email string length
                len = aemail.length;
                //alert(len);
                //check position of @ character.
                //it may be anywhere but not in the beginning or at the end of string.
                if((aemail.charAt(0)=='@')||(aemail.charAt(0)=='.')){
                        alert ("Invalid email! Please enter a valid email");
                        return false;
                }

                if((aemail.charAt(len-1)=='@')){
                        alert ("Invalid email! Please enter a valid email");
                        return false;
                }

                if((aemail.charAt(len-2)=='@')||(aemail.charAt(len-2)=='.')){
                        alert ("Invalid email! Please enter a valid email")
                        return false
                }
                 //count number of @ occurrences and number of dot occurrences
                count=0;
                dotcount=0;
                for (i=0; i< aemail.length; i++)
                {
                        if(aemail.charAt(i)=='@')
                                count++;
                        if(aemail.charAt(i)=='.')
                                dotcount++;
                }
                //if @ or dot occurs not once display warning and return false
                if((count!=1)||(dotcount<1))
                {
                        alert ("Invalid email! Please enter a valid email");
                        return false;
                }
                if (document.IF.yemp.checked)
                {
			if(!(aemail.substring(aemail.indexOf('@'))=='@yahoo-inc.com'))
                        {
                                alert ("Invalid Yahoo Email ID. Please enter your official email id");
                                return false;
                        }
                }
                return true
        }


        function validate() {
        if (leftTrim(document.IF.name.value) == '') {
                alert('Please enter your name');
                document.IF.name.value = '';
                document.IF.name.focus();
                return false;
        }
        if (leftTrim(document.IF.org_name.value) == '') {
                alert('Please enter your organization name');
                document.IF.org_name.value = '';
                document.IF.org_name.focus();
                return false;
        }
        if (!document.IF.yemp.checked)
        {
                if (leftTrim(document.IF.designation.value) == '') {
                        alert('Please enter your designation');
                        document.IF.designation.value = '';
                        document.IF.designation.focus();
                        return false;
                }
                if (leftTrim(document.IF.address.value) == '') {
                        alert('Please enter your address');
                        document.IF.address.value = '';
                        document.IF.address.focus();
                        return false;
                }
                if (leftTrim(document.IF.city.value) == '') {
                        alert('Please enter your city');
                        document.IF.city.value = '';
                        document.IF.city.focus();
                        return false;
                }
                if (leftTrim(document.IF.state.value) == '') {
                        alert('Please enter your state');
                        document.IF.state.value = '';
                        document.IF.state.focus();
                        return false;
                }
                if (leftTrim(document.IF.zip.value) == '') {
                        alert('Please enter the zip code');
                        document.IF.zip.value = '';
                        document.IF.zip.focus();
                        return false;
                }
                if (leftTrim(document.IF.phone.value) == '') {
                        alert('Please enter the phone number');
                        document.IF.phone.value = '';
                        document.IF.phone.focus();
                        return false;
                }
                if(!isNum(leftTrim(document.IF.phone.value))){
            		alert("Enter only integers in phone number");
            		document.IF.phone.focus();
            	    return false;
                }
                if(!EmailValid(document.IF.email.value))
                {
                document.IF.email.focus();
                return false
                }
                if (leftTrim(document.IF.source.value) == '') {
                        alert('Please let us know how you heard about us');
                        document.IF.source.value = '';
                        document.IF.source.focus();
                        return false;
                }
                /*if (document.IF.YI_who_encouraged[3].checked && document.IF.YI_who_encouraged_other.value == '' ) {
                        alert('Please enter What/who encouraged you to apply to yahoo?');
                        document.IF.YI_who_encouraged_other.focus();
                        return false;
                }*/
        }else
        {
                if (leftTrim(document.IF.phone.value) == '') {
                        alert('Please enter the phone number');
                        document.IF.phone.value = '';
                        document.IF.phone.focus();
                        return false;
                }
                if(!isNum(leftTrim(document.IF.phone.value))){
                		alert("Enter only integers in phone number");
                		document.IF.phone.focus();
                	    return false;
                }
                if(!EmailValid(document.IF.email.value))
                {
                        document.IF.email.focus();
                        return false
                }
                //if (document.IF.email.value == '') {
                 //       alert('Please enter the email id');
                 //       document.IF.email.focus();
                 //       return false;
               // }
        }
        if(!(document.IF.event1.checked) && !(document.IF.event2.checked) && !(document.IF.event3.checked) && !(document.IF.event4.checked))
        //if(!(document.IF.event2.checked) && !(document.IF.event3.checked) && !(document.IF.event4.checked))
	{
		alert('Please select atleast one event to register'); 	 
	                 return false;
	}

                return true;
}

function showHide()
{
        if(!(document.IF ==undefined))
        {
        if (document.IF.yemp.checked)
        {
                document.IF.org_name.value = "Yahoo!";
                document.getElementById("divtag1").style.display = "none";
                document.getElementById("divtag2").style.display = "none";
                document.getElementById("divtag3").style.display = "none";
        }else
        {
//              document.IF.org_name.value = "";
                document.getElementById("divtag1").style.display = "block";
                document.getElementById("divtag2").style.display = "block";
                document.getElementById("divtag3").style.display = "block";
        }
//      document.getElementById("page_item").style.display = "block";
        }
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

var numb = ' ()+-0123456789';

function isNum(parm) {return isValid(parm,numb);}

function isValid(parm,val) {
	var i;
	if (parm == "") return true;
		for (i=0; i<parm.length; i++) {
			if (val.indexOf(parm.charAt(i),0) == -1) return false;
		}
	return true;
}
