//*************************************************************
function CancelUpdate() {
	top.location.href = 'viewmembers.asp';
}

//*************************************************************
function CancelProfileUpdate() {
	top.location.href = 'viewprofiles.asp';
}


//*************************************************************
function DeleteMember(ItemNum) {
 if (Confirm()) {
	top.location.href = "deletemember.asp?ItemNum=" + ItemNum;
	}
}

//*************************************************************
function DeleteProfile(ItemNum) {
 if (Confirm()) {
	top.location.href = "deleteprofile.asp?ItemNum=" + ItemNum;
	}
}


//*************************************************************
function Confirm() {
if (confirm("You are about to permanently delete this record."))
	 { return (true)}
	else
	 { return (false) }
}


//*************************************************************
function readcookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		// if cookie exists
		if (offset != -1) { 
			offset += search.length;
			// set index of beginning of value
			end = document.cookie.indexOf(";", offset);
			// set index of end of cookie value
			if (end == -1) end = document.cookie.length;
			returnvalue=unescape(document.cookie.substring(offset, end));
				//alert(returnvalue);
			
		}
		if (returnvalue == '0Uneed12') // user is logged on
			{ toggleMemNav("nav2",1);
			  showhidelogon(0); // show logoff member link
			  return returnvalue;
			}
	}
	toggleMemNav("nav2",0);
	showhidelogon(1); // show member logon link
	return returnvalue;
}

//*************************************************************
function toggleMemNav(szDivID, iState) // 1 visible, 0 hidden
{ 
	var d2;

    if(document.layers)	   //NN4+
    { alert('detected NN4+');
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+ // DOM-compliant browsers
    {
		//alert('detected DOM compliant=' + iState + 'szDivID=' + szDivID);
	 d2=document.getElementById(szDivID);

	 d2.style.display= iState ? "block" : "none";

     //   var obj = document.getElementById(szDivID);
      //  obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}

//*************************************************************
function showhidelogon(showval) {
var d2;

if (showval == 1) // show logon
 { 
	d2=document.getElementById('logon');
	d2.style.display = "block";

	d2=document.getElementById('logoff');
	d2.style.display = "none";
 }
else  // show logout
 { 
	d2=document.getElementById('logoff');
	d2.style.display = "block";

	d2=document.getElementById('logon');
	d2.style.display = "none";
  }
}

//*************************************************************
function removeSpaces(string) {

	// remove all spaces from a string
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];

	return tstring;
}

//*************************************************************
function removeHTTP(string) {

	// remove the occurance of HTTP from a string
	var tstring = "";
	string = '' + string;
	splitstring = string.split("http://");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];

	return tstring;
}

//*************************************************************
function getDateStr(){
    var today = new Date()
	var daystr = today.getDate();
	var yearstr = today.getYear();
	if (yearstr < 1900)  { yearstr = yearstr + 1900 }
	var monthstr = today.getMonth() + 1;
	todayStr = monthstr + "/" + daystr + "/" + yearstr;
	return todayStr
}

//*************************************************************
function setDate() {
  document.Form1.since.value = getDateStr();
}

//*************************************************************
function admincheck()  {
// confirm that the user should have admin priviledges
 if (document.Form1.admin.checked == true)
 {
   if ( confirm("Are you sure you wish to make this user an administrator of the Members Area??") == true ) 
	 { 
		document.Form1.admin.checked = true
	  } 
		else document.Form1.admin.checked = false;
 }
}

//*************************************************************
function createCookie(name,value,days) { 
if (days > 0) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	}
else 
	var expires = "";

document.cookie = name+"="+value+expires+"; path=/cnbpa";
document.cookie = name+"="+value+expires+"; path=/";
}
//*************************************************************
/*
function GetCookie(name)
{ var cname = name + "=";
  var dc = document.cookie;             
  if (dc.length > 0) 
  { begin = dc.indexOf(cname);       
    if (begin != -1) 
    { begin += cname.length;       
      end = dc.indexOf(";", begin);
      if (end == -1) end = dc.length;
      return unescape(dc.substring(begin, end));
    } 
  }
  return null;
}


function DelCookie (name,path,domain) 
{ if (getCookie(name)) 
  { document.cookie = name + "=" +
    ((path == null) ? "" : "; path=" + path) +
    ((domain == null) ? "" : "; domain=" + domain) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
*/

//*************************************************************
function Validator_addmember()
//validate submited form informaton when a new user is created.
{
  if ((removeSpaces(document.Form1.username.value) == "") || (document.Form1.username.value.length < 6) || (document.Form1.username.value.length > 10))
  {
    alert("The \"User ID\" field must be between 6 - 10 characters.");
    document.Form1.username.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.password.value) == "")
  {
    alert("The \"Password\" field can not be empty.");
    document.Form1.password.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.password.value.length) < 6)
  {
    alert("The \"Password\" must have 6 or more characters.");
    document.Form1.password.focus();
    return (false);
  }

	if (removeSpaces(document.Form1.last.value) == "")
  {
    alert("The \"Last Name\" field can not be empty.");
    document.Form1.last.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.since.value) == "")
  {
    alert("The \"Member Since\" field can not be empty.");
    document.Form1.since.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.expire.value) == "")
  {
    alert("The \"Member Expire\" date field can not be empty.");
    document.Form1.expire.focus();
    return (false);
  }

  if (document.Form1.desc.value.length > 255)
  {
    alert("Please enter at most 255 characters in the \"Description\" field.");
    document.Form1.jobdesc.focus();
    return (false);
  }

	document.Form1.accountnum.disabled = false;

	//made it here so the form looks ok for submission
	return (true);
}

//*************************************************************
function Validator_modifyuser()
//validate submited form informaton when an existing user is modified.
{
 
  if (removeSpaces(document.Form1.password.value) == "")
  {
    alert("The \"Password\" field can not be empty.");
    document.Form1.password.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.password.value.length) < 6)
  {
    alert("The \"Password\" must have 6 or more characters.");
    document.Form1.password.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.last.value) == "")
  {
    alert("The \"Last Name\" field can not be empty.");
    document.Form1.last.focus();
    return (false);
  }

  if (document.Form1.desc.value.length > 255)
  {
    alert("Please enter at most 255 characters in the \"Description\" field.");
    document.Form1.desc.focus();
    return (false);
  }

  if (removeSpaces(document.Form1.since.value) == "")
  {
    alert("The \"Member Since\" field can not be empty.");
    document.Form1.since.focus();
    return (false);
  }
  
    if (removeSpaces(document.Form1.expire.value) == "")
  {
    alert("The \"Member Expire\" date field can not be empty.");
    document.Form1.expire.focus();
    return (false);
  }


   
  //made it here so the form looks ok for submission

    // enable the form field so that we can use it
	document.Form1.username.disabled=false;
	document.Form1.accountnum.disabled = false;
  
   return (true);
}

//*************************************************************
function Validator_addprofile()
//validate submited form informaton when a new profile is created.
{




	if (removeSpaces(document.Form1.name.value) == "") {
		alert("The \"Name\" field can not be empty.");
		document.Form1.name.focus();
		return (false);
	}

	if ((removeSpaces(document.Form1.industry.value) == "") && (removeSpaces(document.Form1.industry2.value) == "")) {
		alert("At least one Industry field must be filled in.");
		document.Form1.industry.focus();
		return (false);
	}


	if (document.Form1.desc.value.length > 255) {
		alert("Please enter at most 255 characters in the \"Description\" field.");
		document.Form1.desc.focus();
		return (false);
	}


	//made it here so the form looks ok for submission  
	return (true);
}


//*************************************************************
function Validator_modifyprofile(){
//validate submited form informaton when an existing profile is modified.

//	alert("need to test form fields here.");

return (true);
}

//*************************************************************
function validate_pwd(id, pass1, pass2) {
// called from pwdchange.asp
// validate new password

if ( pass1.length <= 5  ) {
	alert("The new password must be between 6 and 10 characters.");
	resetnewpasswordfields();
	return false;
}

if (pass1.indexOf(" ") != -1) {
	alert("Password fields can not have spaces or blanks.");

	return false;
}

if ( pass1 != pass2) {
	alert("New password does not match validation password.");
	resetnewpasswordfields();
	return false;
}

var pwdstr = pass1.toLowerCase();
var idstr = id.toLowerCase();

if ( pwdstr == idstr ) {
	alert("The password can not be the same as your user id.")
	resetnewpasswordfields();
	return false;
}

document.form1.actionx.value = "validate_login";
document.form1.submit();
return true;
}

function resetnewpasswordfields() {
document.form1.passwordn.value = "";
document.form1.passwordv.value = "";
document.form1.passwordn.focus();
}

//*************************************************************
// append the % sign to the search string
// called from: azmembers.asp
function azmembersearch(nameStr1,formname) {
	formname.nameStr2.value = nameStr1 + "%";
	formname.submit();
}

//*************************************************************
// open a new window for selecting the industry codes for a profile
// called from: addprofiles.asp, modifyprofiles.asp
function IndustrySelect(ind_num,current_ind) {

	if (current_ind=="") { current_ind="00";}
	window.open('indpicker.asp?ind_num=' + ind_num + '&current_ind=' + current_ind,'IndustryPicker','width=300,height=150,menubar=no,toolbar=no');
}

//*************************************************************
// open a new window for selecting the membership association to a profile
// called from: addprofiles.asp, modifyprofiles.asp
function AssSelect() {

//	switch(AccountType) {
//		case "2":  // Personal
//		case "3":
//			Accnt = '1';
//			break;
//		case "1":  // Corporate
//		case "4":
//			Accnt = '2';
//			break;
//		default: // network only - set to 1 because network only members are not corporate
//			Accnt = '1';
//		}

//	URLstr = "asspicker.asp?AccountType=" + Accnt;
	URLstr = "asspicker.asp";
	window.open(URLstr,'AssociationPicker','width=300,height=150,menubar=no,toolbar=no');
}

//*************************************************************
// set values for profile association
// called from: asspicker.asp
function UpdateForm(code,codename){
	opener.document.forms[0].assname.value = codename;
	opener.document.forms[0].accountnum.value = code;
}

//*************************************************************
// set values for profile association
// called from: asspicker.asp
function EnableCorpFieldsDELETEME(lvl){
	if (lvl=='2') { 
		document.Form1.http.disabled = false;
		document.Form1.logo.disabled = false;
	} else  {
		document.Form1.http.disabled = true;
		document.Form1.logo.disabled = true;
	}
}


//*************************************************************
// Enable/Disable Company dropdown box for personal/corporate memberships

function EnableCorpAssociation(){
var d2;
	d2=document.getElementById('accountrel');

	switch(document.Form1.corplevel.value) {
		case "3":  // Personal
				 d2.style.display = "none";
				 break;
		case "5":  // network
				 d2.style.display = "block";
				 break;
		default: // for all other cases, show the corporate selection
			d2.style.display = "block";
		}

}

