function checkObject(currObject, caption)
{

	if(currObject.value.length < 1)
	{
   		alert("Please Enter " + caption);
		currObject.focus();
		return false;
	}
	return true;
}
function chechkvalid1()
{
	if (!checkObject (document.frmadd.userid, 'User Name'))
			return false;
	if (!checkObject (document.frmadd.password, 'Password'))
			return false;	
	if (!checkObject (document.frmadd.email, 'E-Mail Address'))
			return false;
/*	if (!checkValidEmail(document.frmadd.email, 'Enter valid E-Mail Id'))
			return false;
*/
	if (!checkObject (document.frmadd.cemail, 'E-Mail Address confirmation.'))
			return false;
	if (!checkCommonEmail (document.frmadd.email,document.frmadd.cemail,'Email addresses do not match.'))
			return false;
	
/*
	if (!checkObject (document.frmadd.vAddress1, 'Address line 1'))
			return false;
	if (!checkObject (document.frmadd.vState, 'State'))
			return false;
	if (!checkObject (document.frmadd.vCountry, 'Country'))
			return false;						
	if (!checkObject (document.frmadd.iPostcode, 'Postcode.'))
			return false;
	if (!checkObject (document.frmadd.tTeleNo, 'Telephone No.'))
			return false;
*/
	if (!checkValidEmail(document.frmadd.vIMAddress, 'Enter valid IMAddress'))
			return false;
	if (!checkValidEmail(document.frmadd.vICQAddress , 'Enter valid ICQAddress '))
			return false;
	if (!checkValidEmail(document.frmadd.vYIMAddress , 'Enter valid YIMAddress '))
			return false;
	if (!checkObject (document.frmadd.eViewMyEmail, 'E-Mail Address Permission'))
			return false;
	return true;
}


function checkValidEmail(obj, msg)
{
	var i;
	var input = obj.value ;
	var lenth = input.length ;
	var ctr=0 ;
	if(input !="")
	{
		if ( ( obj.value.charAt(i) == '!' ) || ( 	obj.value.charAt(i) == '#' ) )
    	{
	  		alert(msg) ;
	  		obj.focus();
      		return false;
    	}
/*		if (input =="")
		{
			alert("Please Enter Email Address") ;
			obj.value="";
	    	obj.focus();
			return false ;
		}*/
		if(input.length >= 40)
		{
			alert(msg) ;
	    	obj.focus();
			return false ;
		}
		for ( i=0; i < lenth; i++ )
		{
			var oneChar = input.charAt(i) ;
			if(oneChar == "@")
			{
				ctr = ctr+1 ;
			}
			if ( (i == 0 && oneChar == "@") || (i == 0 && oneChar == ".") || 
			( oneChar == " " ) )
			{
				alert (msg) ;

	        	obj.focus();
				return false ;
			}
			if ( (oneChar == "@" && input.charAt(i+1) == ".") || 
			(oneChar == "." && input.charAt(i+1) == "@") ||
			(oneChar == "." && input.charAt(i+1) == ".") )
			{
				alert (msg) ;

	        	obj.focus();
				return false ;
			}
			if( input.indexOf("@") < 2 )
			{
				alert (msg) ;

	        	obj.focus();
				return false ;
			}
			if(input.indexOf(".")<4)
			{
				alert (msg) ;

	        	obj.focus();
				return false ;
			}
			if (ctr > 1)
			{
				alert (msg) ;
	        	obj.focus();
				return false ;
			}
		
		}
	}	// End Email Validation Script
	return true;
}

function checkValidPhone(obj, msg)
{
	validCharacters = "0123456789-()";
	compareValue = obj.value;
	if(!checkCharFormat(validCharacters, compareValue))
	{
		alert(msg);
		obj.focus();
		return false;
	}
	return true;
}


function checkCommonEmail(obj1,obj2,msg)
{
	email1 =obj1.value;
	email2 =obj2.value;
	if(email2!==email1)
	{
		alert(msg);
		obj2.focus();
		return false;
	}
	return true; 
}
