// JavaScript Document

function member(memcount){
	alert(memcount);
var memcount=memcount;
var total;
var memamount=25;
total= memcount * memamount ;
document.member.memgrandtotal.value = total;
}

function memberprice(memvalue){
var memvalue=memvalue;
var total=document.frm_event.noofmembers.value * memvalue ;
document.frm_event.memgrandtotal.value = total;
}

function nonmemberprice(nonmemvalue){
var nonmemvalue=nonmemvalue;
var nmtotal=document.frm_event.noofnonmembers.value * nonmemvalue ;
document.frm_event.nonmemgrandtotal.value = nmtotal;
}


//UserLogin Validation
function userlogin_validate(){
	if (document.userlogin.username.value == "") 
		{
				alert ("Please Enter the User name.");
				document.userlogin.username.focus();
				return false;
		}
	if (document.userlogin.password.value == "") 
		{
				alert ("Please Enter the Password.");
				document.userlogin.password.focus();
				return false;
		}
}
//Event register Validation
function event_validate(){
	if (document.frm_event.name.value == "") 
		{
				alert ("Please Enter the Name.");
				document.frm_event.name.focus();
				return false;
		}
	if (document.frm_event.title.value == "") 
		{
				alert ("Please Choose Title.");
				document.frm_event.title.focus();
				return false;
		}
	if (document.frm_event.organization.value == "") 
		{
				alert ("Please Enter the Organization.");
				document.frm_event.organization.focus();
				return false;
		}
		if (!validateEmail(document.frm_event.email.value,1,1)) 
		{
				document.frm_event.email.focus();
				return false;
		}
	if (document.frm_event.street.value == "") 
		{
				alert ("Please Enter the Street Address.");
				document.frm_event.street.focus();
				return false;
		}
	if (document.frm_event.city.value == "") 
		{
				alert ("Please Enter City.");
				document.frm_event.city.focus();
				return false;
		}
	if (document.frm_event.state.value == "") 
		{
				alert ("Please Enter State.");
				document.frm_event.state.focus();
				return false;
		}
	if (document.frm_event.zipcode.value == "") 
		{
				alert ("Please Enter Zipcode.");
				document.frm_event.state.focus();
				return false;
		}
	if (document.frm_event.telephone.value == "") 
		{
				alert ("Please Enter Telephone Number.");
				document.frm_event.telephone.focus();
				return false;
		}
		phone = document.frm_event.telephone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number");
			phone.value="";
			phone.focus();
			return false;
			}

	if (document.frm_event.guest1.value == "") 
		{
				alert ("Please Enter the Guest Name.");
				document.frm_event.guest1.focus();
				return false;
		}
	if (document.frm_event.noofmembers.value == "") 
		{
				alert ("Please Enter HPRMS Members.");
				document.frm_event.noofmembers.focus();
				return false;
		}
	if (document.frm_event.noofnonmembers.value == "") 
		{
				alert ("Please Enter HPRMS Non-Members.");
				document.frm_event.noofnonmembers.focus();
				return false;
		}
}
//Become a member Validation
function becomemember_validate(){
	if (document.bmember.uname.value == "") 
		{
				alert ("Please Enter the User name.");
				document.bmember.uname.focus();
				return false;
		}
	if (document.bmember.pass.value == "") 
		{
				alert ("Please Enter the Password.");
				document.bmember.pass.focus();
				return false;
		}
	if (document.bmember.name.value == "") 
		{
				alert ("Please Enter the First Name.");
				document.bmember.name.focus();
				return false;
		}
	if (document.bmember.lastname.value == "") 
		{
				alert ("Please Enter the Last Name.");
				document.bmember.lastname.focus();
				return false;
		}
	if (document.bmember.title.value == "") 
		{
				alert ("Please Enter the Title.");
				document.bmember.title.focus();
				return false;
		}
	if (document.bmember.organization.value == "") 
		{
				alert ("Please Enter the Organization.");
				document.bmember.organization.focus();
				return false;
		}
		if (!validateEmail(document.bmember.email.value,1,1)) 
		{
				document.bmember.email.focus();
				return false;
		}
	if (document.bmember.address1.value == "") 
		{
				alert ("Please Enter the Address1.");
				document.bmember.address1.focus();
				return false;
		}
	/*if (document.bmember.street.value == "") 
		{
				alert ("Please Enter the Address2.");
				document.bmember.street.focus();
				return false;
		}*/
	if (document.bmember.city.value == "") 
		{
				alert ("Please Enter the City.");
				document.bmember.city.focus();
				return false;
		}
	if (document.bmember.state.value == "") 
		{
				alert ("Please Enter the State.");
				document.bmember.state.focus();
				return false;
		}
	if (document.bmember.zipcode.value == "") 
		{
				alert ("Please Enter the Zipcode.");
				document.bmember.zipcode.focus();
				return false;
		}
	/*if (document.bmember.street.value == "") 
		{
				alert ("Please Enter the Organization.");
				document.bmember.street.focus();
				return false;
		}*/
	if (document.bmember.telephone.value == "") 
		{
				alert ("Please Enter the Telephone.");
				document.bmember.telephone.focus();
				return false;
		}
		phone = document.bmember.telephone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number");
			phone.value="";
			phone.focus();
			return false;
			}
}
//Article Validate
function article_validate(){
	if (document.frm_article.txttitle.value == "") 
		{
				alert ("Please Enter the Title.");
				document.frm_article.txttitle.focus();
				return false;
		}
}
//Search Article Validate
function searcharticle_validate(){
	if (document.frm_search.Search.value == "") 
		{
				alert ("Please Enter the Search String.");
				document.frm_search.Search.focus();
				return false;
		}
}
//Contact us validattion
function contactus_validate(){
	if (document.contact.txtName.value == "") 
		{
				alert ("Please Enter the Name.");
				document.contact.txtName.focus();
				return false;
		}
	if (document.contact.txtTitle.value == "") 
		{
				alert ("Please Enter the title.");
				document.contact.txtTitle.focus();
				return false;
		}
	if (document.contact.txtOrganization.value == "") 
		{
				alert ("Please Enter the Organization.");
				document.contact.txtOrganization.focus();
				return false;
		}
	if (!validateEmail(document.contact.txtEmail.value,1,1)) 
		{
				document.contact.txtEmail.focus();
				return false;
		}
	if (document.contact.txtAddress1.value == "") 
		{
				alert ("Please Enter the Street Address1.");
				document.contact.txtAddress1.focus();
				return false;
		}
	if (document.contact.txtCity.value == "") 
		{
				alert ("Please Enter the City.");
				document.contact.txtCity.focus();
				return false;
		}
	if (document.contact.txtState.value == "") 
		{
				alert ("Please Enter the State.");
				document.contact.txtState.focus();
				return false;
		}
	if (document.contact.txtState.value == "") 
		{
				alert ("Please Enter the State.");
				document.contact.txtState.focus();
				return false;
		}
	if (document.contact.txtZip.value == "") 
		{
				alert ("Please Enter the Zipcode.");
				document.contact.txtZip.focus();
				return false;
		}
	if (document.contact.txtPhone.value == "") 
		{
				alert ("Please Enter the Phone Number.");
				document.contact.txtPhone.focus();
				return false;
		}
		phone = document.contact.txtPhone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number");
			phone.value="";
			phone.focus();
			return false;
			}
}


//Job Bank validation
function job_validate(){
	if (document.frm_job.txtname.value == "") 
		{
				alert ("Please Enter the Name.");
				document.frm_job.txtname.focus();
				return false;
		}
	if (document.frm_job.txtjobtitle.value == "") 
		{
				alert ("Please Enter Jobtitle");
				document.frm_job.txtjobtitle.focus();
				return false;
		}
	if (document.frm_job.txtcompany.value == "") 
		{
				alert ("Please Enter Company Name");
				document.frm_job.txtcompany.focus();
				return false;
		}
}
//Search Member byname Validate
function searchmemname_validate(){
	if (document.frm_memsearch.Search.value == "") 
		{
				alert ("Please Enter the Search String.");
				document.frm_memsearch.Search.focus();
				return false;
		}
}
//Forgotpassword validation
function forgotpass_validate(){
	if (!validateEmail(document.forgotpass.femail.value,1,1)) 
		{
				document.forgotpass.femail.focus();
				return false;
		}
}
//Search Member bycompany Validate
function searchmemcompany_validate(){
	if (document.frmmemcom_search.Search.value == "") 
		{
				alert ("Please Enter the Search String.");
				document.frmmemcom_search.Search.focus();
				return false;
		}
}

//Email Validation Script
function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

 //Function phone validation Script
// 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 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 checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

