function checkFormValidate(){
	if(document.frmRegister.title.value == ''){
		alert('Please enter title \n');
		document.frmRegister.title.focus();
		return false;
	}else if(document.frmRegister.fname.value == ''){
		alert('Please enter first name \n');
		document.frmRegister.fname.focus();
		return false;
	}else if(document.frmRegister.lname.value == ''){
		alert('Please enter last name \n');
		document.frmRegister.lname.focus();
		return false;
	}else if(document.frmRegister.phone.value == ''){
		alert('Please enter phone \n');
		document.frmRegister.phone.focus();
		return false;
	}else if(!isInteger(document.frmRegister.phone.value)){
		alert('Please enter correct phone number \n');
		document.frmRegister.phone.focus();
		return false;
	}else if(document.frmRegister.email.value == ''){
		alert('Please enter valid email address \n');
		document.frmRegister.email.focus();
		return false;
	}
	else if(!echeck(document.frmRegister.email.value)){
		 document.frmRegister.email.focus();
		 return false;
	}
	else if(!isRadioButtonSelected('rbAttend[]')){
		alert('Please select atleast one option for attending \n');
		return false;
	}
	
	document.frmRegister.submit();
	return true;
}

function checkvalidation(){
	if(document.frmComments.visit_email.value == ''){
		alert('Please enter valid email address \n');
		document.frmComments.visit_email.focus();
		return false;
	}
	else if(!echeck(document.frmComments.visit_email.value)){
		 document.frmComments.visit_email.focus();
		 return false;
	}
	
	if(document.frmComments.visit_Coments.value == ''){
		alert('Please enter Comments \n');
		document.frmComments.visit_Coments.focus();
		return false;
	}
	
	document.frmComments.submit();
	return true;
}
function echeck(str) {
	var at="@"
	var dot="."
	var comma=","
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Please enter a vaild Email Address.")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==(lstr-1)){
	   alert("Please enter a vaild Email Address.")
	   return false
	}
	
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==(lstr-1)){
		alert("Please enter a vaild Email Address.")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Please enter a vaild Email Address.")
		return false
	 }
	  
	if (str.indexOf(comma)!=-1){
		alert("Please enter a vaild Email Address.")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Please enter a vaild Email Address.")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Please enter a vaild Email Address.")
		return false
	 }
	 
	 if (str.substring(lstr-1,lstr-0)==dot){
		alert("Please enter a vaild Email Address.")
		return false
	 }
	 
	if (str.substring(lstr-1,lstr-0)==at){
		alert("Please enter a vaild Email Address.")
		return false
	 } 
	
	 if (str.indexOf(" ")!=-1){
		alert("Please enter a vaild Email Address.")
		return false
	 }
	 return true					
}

function isValidPattern_InterNatnPhnNo(strPhone){
	s = stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/*********************US/Canada Zip Code Validations**************************/
function isValidPattern_ZipCode(str){
	regEx = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
	
	return regEx.test(str);
}
/*****************************************************************************/

/*********************International Phone Number Validation*******************/
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isValidPattern_PhoneNo(str){
	// Declaring required variables
	var digits = "0123456789";
	// non-digit characters which are allowed in phone numbers
	var phoneNumberDelimiters = "()- =?\\\"!+~@#$%^&*_[]{}\|;:'<>,./";
	// characters which are allowed in international phone numbers
	// (a leading + is OK)
	var validWorldPhoneChars = phoneNumberDelimiters + "+";
	// Minimum no of digits in an international phone no.
	var minDigitsInIPhoneNumber = 1;

	str = stripCharsInBag(str,validWorldPhoneChars);
	
	return (isValidPattern_Digits(str) && str.length >= minDigitsInIPhoneNumber);
}

function isValidPattern_Digits(str){
	var regEx = new RegExp("[^0-9]","ig");

	return !regEx.test(str);
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isRadioButtonSelected(strGroupName){
	var colButtons = document.getElementsByName(strGroupName);

	for(i = 0; i < colButtons.length; i++){
		if(colButtons[i].checked == true){
			return true;
		}
	}
	
	return false;
}

function getMultipleSelVal(ID) {
    var result = '';
    for (var i = 0; i < $(ID).length; i++) {
        if ($(ID).options[i].selected) {
            result += $(ID).options[i].value + ",";
        }
    }
    return result;
}
/*****************************************************************************/

/************************Show Validation Errors********************************/
function showValidationErrors(strErrors){
	$('divErrors').style.display = "block";
	$('divFailures').innerHTML = "<table>" + strErrors + "</table>";
}

function hideValidationErrors(){
	$('divErrors').style.display = "none";
	$('divFailures').innerHTML = "";
}
/**********************************************************************/



