// get cookie value by cookie name
function GetCookieValue(name)
{
	var allcookies = document.cookie;
	var value = "";
	var pos = allcookies.indexOf(name+"=");
	if (pos != -1) 
	{
		var start = pos + name.length+1;
		var end = allcookies.indexOf(";", start);
		if (end == -1) 
		{
			end = allcookies.length;
		}	
		value = allcookies.substring(start, end);
		value = unescape(value);			
	}
	return value;		
}

// set REDIRECTURL hidden field value
function SetRedirectURL() 
{
	var RedirectStr=""
  
	if (location.search) 
	{
		RedirectStr=location.search.substring(1,255);
	}		
	document.login.REDIRECTURL.value=RedirectStr;	
}

// on the pageload check page access and redirect to the login page if necessery 
function CheckPageAccess()
{
	
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf("/") + 1);
	var doredirect = false;
	switch (sPage)
	{
		case "mbr_locator.shtml" : 
			doredirect = true;
			sPage = "../../"+sPage;
			break;
		case "awt_mainlogin_loggedon.shtml" :
			sPage = "../../"+sPage;
			doredirect = true;
			break;
		case "company_locator1.shtml" :
			sPage = "../../"+sPage;
			doredirect = true;
			break;	
	}
	if (doredirect)
	{
		var memberid = CUSTOMERCD;
		var ismember = ISMEMBERFLG;
		if ((memberid == "") || (ismember!="Y")) 
		{	
			//location.href = "awt_mainlogin1.shtml?"+sPage;
			alert("You must logon to our Member's Only site");	
			location.href="https://www.awt.org/awt_mainlogin.shtml";
		}
	}
}

//to check cookie and redirect to Path if user has already logged in
function ResetLogin(Path) 
{
	document.login.CUSTOMERCD.value = CUSTOMERCD;
	if (document.login.CUSTOMERCD.value != "") 
	{
		location.href = Path;
	}
	document.login.WEBUSERID.focus();
}

//to show/hide links depend on cookie value
function displayLinks()
{
//	var value=GetCookieValue("skillcdlst");
	var value=GetCookieValue("primarycontact");
	var pos = value.indexOf("PC");
	if (pos != -1) 
	{
		var txt='<p><a href="../../cgi-bin/organizationdll.dll/Info">Organization Profile Update</a></p><p><a href="../../cgi-bin/duespayment.dll/updateinfo">Renew Your Membership</a></p>';
		var obj=document.getElementById("insert");
		insert.insertAdjacentHTML("afterEnd",txt);
	}
}




function RunSearch() {
     if ( (isBegindate()) )
     document.form1.submit();
	  return true;
}   


function isBegindate() {
 	
	var myselect = document.form0.selectdate.selectedIndex;
        var today = new Date();
	year = today.getYear();
	if (year < 2000)    
	year = year + 1900; 
    switch (myselect) {
	case 0:        
 	  document.form1.SESSIONBEGDATE.value = "";
          break;
        case 1:
	   var tbegdate = ( (today.getMonth() + 1) + "/" + (today.getDate()) + "/" + year );
           var tenddate = ( (today.getMonth() + 2) + "/" + (today.getDate()) + "/" + year );
	   document.form1.SESSIONBEGDATE.value = "BETWEEN '" + tbegdate+"' AND '"+tenddate+"'";
           break;
        case 2:
	   var tbegdate = ( (today.getMonth() + 1) + "/" + (today.getDate()) + "/" + year );
           var tenddate = ( (today.getMonth() + 4) + "/" + (today.getDate()) + "/" + year );
	   document.form1.SESSIONBEGDATE.value = "BETWEEN '" + tbegdate+"' AND '"+tenddate+"'";
           break;
        case 3:
	   var tbegdate = ( (today.getMonth() + 1) + "/" + (today.getDate()) + "/" + year );
           var tenddate = ( (today.getMonth() + 1) + "/" + (today.getDate()) + "/" + (year+1));
	   document.form1.SESSIONBEGDATE.value = "BETWEEN '" + tbegdate+"' AND '"+tenddate+"'";
           break;
        default: 
           var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
 	   var tbegdate = ( myselect-3 + "/" + 01 + "/" + year );
           var tenddate = ( myselect-3 + "/" + MonthDays[ myselect-4] + "/" + year);
	   document.form1.SESSIONBEGDATE.value = "BETWEEN '" + tbegdate+"' AND '"+tenddate+"'";
         
	}
      

       if (document.form1.SESSIONBEGDATE.value == "")
	{
 	   var tbegdate = ( (today.getMonth()+1) + "/" + (today.getDate()-1) + "/" + year );
           document.form1.SESSIONBEGDATE.value="BETWEEN '" + tbegdate+"' AND '01/01/2040'";
	}

      return true;
}


function EventRegister(eventstatus, eventcd) { 
   if (eventstatus<2){ 

    if (eventstatus==1){ 
   	alert('This event is full. If you would like to be placed on a waiting list please select OK to complete the registration form.')
      }

	var allcookies = document.cookie;
	var value = CUSTOMERCD;
	/*var pos = allcookies.indexOf("memberid=");
		if (pos != -1) {
			var start = pos + 9;
			var end = allcookies.indexOf(";", start);
			if (end == -1) end = allcookies.length;
			value = allcookies.substring(start, end);
			value = unescape(value);
		}*/

	if (value != "") 
	{
	   location = '../../cgi-bin/Registerdll.dll/RegistrationForm?sessionaltcd='+eventcd+'&FUNFILTER=RBN&WLN='+eventcd+'_nav.htm';
	}
    else 
	{
		location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=%2Fcvwebtest_elfa%2Fcgi-bin%2FRegisterdll.dll%2FRegistrationForm%3Fsessionaltcd%3D'+eventcd+'%26FUNFILTER%3DRBN%26WLN%3D'+eventcd+'_nav.htm';
		//location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=';
	} 

      }


   else {
     alert('Online Registration is Closed.'); 
     }
}

function EventMultiRegister(eventstatus, eventcd) 
{ 
  if (eventstatus<2)
  { 
	  if (eventstatus==1)
	  
	  { 
   		alert('This event is full. If you would like to be placed on a waiting list please select OK to complete the registration form.')
      }
		 var allcookies = document.cookie;
		 var value = CUSTOMERCD;
		 /*var pos = allcookies.indexOf("memberid=");
		  if (pos != -1) 
		  {
		   var start = pos + 9;
		   var end = allcookies.indexOf(";", start);
		   if (end == -1) end = allcookies.length;
		   value = allcookies.substring(start, end);
		   value = unescape(value);
		  }*/
		if (value != "") 
		{
			location='../../cgi-bin/Registerdll.dll/RegistrationForm?sessionaltcd='+eventcd+'&FUNFILTER=EN&MULTIREG=Y&ONLYOPTIONS=Y&RESPONSEPAGE=MultiRegForm.htm&WLN='+eventcd+'_nav.htm';
		}
		else 
		{
			location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=%2Fcvwebtest_elfa%2Fcgi-bin%2FRegisterdll.dll%2FRegistrationForm%3Fsessionaltcd%3D'+eventcd+'%26FUNFILTER%3DEN%26MULTIREG%3DY%26ONLYOPTIONS%3DY%26RESPONSEPAGE%3DMultiRegForm.htm%26WLN%3D'+eventcd+'_nav.htm';
			//location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=';
		} 
	} 
	else 
	{
		alert('Online Registration is Closed.'); 
    }	
}

function ReviseResume() 
{ 
  	 var allcookies = document.cookie;
	 var value = CUSTOMERCD;
	 /*var pos = allcookies.indexOf("memberid=");
	  if (pos != -1) 
	  {
	   var start = pos + 9;
	   var end = allcookies.indexOf(";", start);
	   if (end == -1) end = allcookies.length;
	   value = allcookies.substring(start, end);
	   value = unescape(value);
	  }*/
 
	 if (value != "") 
	 {
    	location='cgi-bin/memberdll.dll/Info?WRP=mainloginwelcome.htm';
	 }
     else 
	 {
	   location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=%2Fcvwebtest_elfa%2Fcgi-bin%2Fmemberdll.dll%2FInfo%3FWRP%3Dmainloginwelcome.htm';
	   //location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=';
	 } 
	
}

function PlaceAd() 
{ 
  	 var allcookies = document.cookie;
	 var value = CUSTOMERCD;
	 /*var pos = allcookies.indexOf("memberid=");
	  if (pos != -1) 
	  {
	   var start = pos + 9;
	   var end = allcookies.indexOf(";", start);
	   if (end == -1) end = allcookies.length;
	   value = allcookies.substring(start, end);
	   value = unescape(value);
	  }*/
 
	 if (value != "") 
	 {
    	location='cgi-bin/jobboard.dll/Info';
	 }
     else 
	 {
	   location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=%2Fcvwebtest_elfa%2Fcgi-bin%2Fjobboard.dll%2FInfo';
	   //location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=';
	 } 
	
}

function printpage() {
	window.print();  
}


function mailpage()
{
	mail_str = "mailto:?subject=BICSI Send to a friend -- " + document.title;
	mail_str += "&body= This is a link to an item on the BICSI Website:" + "&nbsp;&nbsp;"+ location.href;
	location.href = mail_str;
}

function RunLogin() 
{
	var RedirectStr=""
  
	if (location.search) 
	{
		RedirectStr=location.search.substring(1,255);
	}		
	document.login.REDIRECTURL.value=RedirectStr;
	document.login.submit()
}

function Redirect() {

var allcookies = document.cookie;
var value = "";
var pos = allcookies.indexOf("REDIRECTURL=");
	if (pos != -1) {
		var start = pos+12;
		var end = allcookies.indexOf(";", start);
		if (end == -1) end = allcookies.length;
		value = allcookies.substring(start, end);
		value = unescape(value);
	}

        if (value != "") {
	  location.href = value;
	  }
}

/*
function formValidate() {
     if ( (isFirstname()) && (isCity()) && (isState()) && (isEmail()) && (isSkills()) && (isResume()) )
     document.order.submit();
	  return true;
} 
*/


function isFirstname() {
var str = document.order.FIRSTNAME.value;
   // Return false if First Name field is blank.
   if (document.order.FIRSTNAME.value == "") 
      {
      alert("\nThe First Name field is blank.\n\nPlease enter your first name.")
      document.order.FIRSTNAME.focus();
      return false; 
      }
      
   // Return false if characters are not a-z, A-Z.
   for (var i = 0; i < str.length; i++) 
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
         {
         alert("\nThe First Name field only accepts letters.\n\nPlease re-enter.");
         document.order.FIRSTNAME.select();
         document.order.FIRSTNAME.focus();
         return false;
         }
       else  {
          return true;
      }	     
   }       
}

// Checks the City field.
function isCity()  {
   // Return false if City field is blank.
   if (document.order.CITY.value == "") 
      {
       alert("\nThe City field is blank.\n\nPlease enter your City.")
       document.order.CITY.focus();
       return false; 
      }
   else  {
      return true;
 		  }	     
}

// Checks the State field.
function isState()
   {
	var mystate=document.order.STATECD.selectedIndex;
	if (mystate==0) {
	alert("\nYou must select your State from the dropdown box.");
	document.order.STATECD.focus();
   	return false; 
      }
   	else  {
      return true;
 		  }	     
}

function isEmail()
   {
   // Return false if E-mail field is blank.
   if (document.order.EMAIL.value == "") 
      {
      alert("\nThe Email Address field is blank.\n\nPlease enter your Email Address.")
      document.order.EMAIL.focus();
      return false; 
      }
   // Return false if E-mail field does not contain a '@' and '.' .
   if (document.order.EMAIL.value.indexOf ('@',0) == -1 || 
       document.order.EMAIL.value.indexOf ('.',0) == -1)
      {
      alert("\nThe Email Address field must contain a \"@\" and a \".\" \n\nPlease re-enter your Email Address.")
      document.order.EMAIL.select();
      document.order.EMAIL.focus();
      return false;
      }
   else  {
      return true;
 		  }	     
}

function isDegree()
   {
	var mydegree=document.order.EDUCATIONDEGREE.selectedIndex;
	if (mydegree==0) {
	alert("\nYou must select your Degree from the dropdown box.");
	document.order.EDUCATIONDEGREE.focus();
   	return false; 
      }
   	else  {
      return true;
 		  }	     
}

function isSkills()
   {
	var myskills=document.order.JOBREQUIREDSKILLSLST.selectedIndex;
	if (myskills==0) {
	alert("\nYou must select your Skills from the dropdown box.");
	document.order.JOBREQUIREDSKILLSLST.focus();
   	return false; 
      }
   	else  {
      return true;
 		  }	     
}

function isResume()  {
   if (document.order.RESUMETEXT.value == "") 
      {
       alert("\nThe Resume field is blank.\n\nPlease enter your resume.")
       document.order.RESUMETEXT.focus();
       return false; 
      }
   else  {
      return true;
 		  }	  
}








function OrgformValidate() 
{
	if ( (isComapnyname()) && (isAddress()) && (isCity()) && (isZip()) 
		&& (isCountry()) && (formatAllPhoneNum()) && (isEmail()) && (isPrimaryContact()) && (isNote())
		&& (isCardtype()) && (cardConfirm()) 
		&& (isExpmonth()) && (isExpyear()) && (isExpdate()) && (isCategory()) && (isSubnamechkbox()) 
		&& (isSubitems()) && (isJoindate()) && (GetContactNames()) )
  	   document.order.submit();
	   return true;
}

function GetContactNames()
{
	document.order.CONTACTNAME.value = document.order.FNAME.value+" "+document.order.LNAME.value;
	document.order.ALTCONTACTNAME.value = document.order.FALTNAME.value+" "+document.order.LALTNAME.value;
	document.order.UDEF2TXT.value = document.order.FPRESNAME.value+" "+document.order.LPRESNAME.value;
	return true;
}

function isComapnyname() 
{
	var str = document.order.ORGNAME.value;
	if (document.order.ORGNAME.value == "") 
	      {
		      alert("\nThe Company Name field is blank.\n\nPlease enter your Company name.")
		      document.order.ORGNAME.focus();
		      return false; 
	      }
      
	else  
	      {
		       return true;
	      }	     
}


function isPrimaryContact() 
{
	var str = document.order.PRIMARYCONTACT.value;
	if (document.order.PRIMARYCONTACT.value == "") 
	      {
		      alert("\nThe Primary contact field is blank.\n\nPlease enter your Primary Contact.")
		      document.order.CONTACTNAME.focus();
		      return false; 
	      }
      
		   // Return false if characters are not a-z, A-Z.
	for (var i = 0; i < str.length; i++) 
	      {
		      var ch = str.substring(i, i + 1);
		      if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
      		         {
			         alert("\nThe Primary Contact field only accepts letters.\n\nPlease re-enter.");
				 document.order.CONTACTNAME.select();
				 document.order.CONTACTNAME.focus();
			         return false;
		         }
		       else  
			 {
			         return true;
		         }	     
	     }       
}


function isAddress()
{
   if (document.order.ADDRESS1.value == "") 
	{
	  alert("\nThe primary Address field is blank.\n\nPlease enter your Address.")
	  document.order.ADDRESS1.focus();
	  return false; 
	 }
      else  
	{
	 return true;
 	}	
}


function isNote()
{
   if (document.order.HTMLNOTE.value == "") 
	{
	  alert("\nThe Mission field is blank.\n\nPlease enter the Mission Statement.")
	  document.order.HTMLNOTE.focus();
	  return false; 
	 }
      else  
	{
	 return true;
 	}	
}

function isPrimaryContact()
{
   if ((document.order.FNAME.value == ""))
	{
	  alert("\nThe primary Contact Name field is blank.\n\nPlease enter the Primary Contact Name.")
	  document.order.FNAME.focus();
	  return false; 
	 }
      else  
	{
	    if ((document.order.LNAME.value == ""))
	    {
		  alert("\nThe primary Contact Last Name field is blank.\n\nPlease enter the Primary Contact Last Name.")
		  document.order.LNAME.focus();
		  return false; 
	    }
	    else  
	    {
		 	return true;
 	    }	

 	}	
}



// Checks the zip field.
function isZip()
{
	var str = document.order.ZIP.value;
	// Return false if Zip field is blank.
   
	if (document.order.ZIP.value == "") 
	    {
		    alert("\nThe primary Zip field is blank.\n\nPlease enter your Zip.");
		    document.order.ZIP.focus();
		    return false;
	    }
	
	// Return false if characters are not '0-9', 'a-z', 'A-Z', '-'. 
	for (var i = 0; i < str.length; i++) 
	    {
		 var ch = str.substring(i, i + 1);
		 if ((ch < "0" || "9" < ch) && (ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch != '-'))
		    {
			    alert("\nThe primary Zip field accepts only numbers and letters. \n\nPlease re-enter your Zip.");
			    document.order.ZIP.select();
			    document.order.ZIP.focus();
			    return false;
		    }
    		return true;
	    }    
}


// Checks the State field.
function isCountry()
   {
	var mystate=document.order.STATECD.selectedIndex;
	var mycountry=document.order.COUNTRY.selectedIndex;
	if ((mystate==0) && (mycountry==0)){
	alert("\nYou must select your Country from the dropdown box.");
	document.order.COUNTRY.focus();
   	return false; 
      }
   	else  {
      return true;
 		  }	     
}


function formatAllPhoneNum()
{
	if (document.order.HOMEPHONE.value == "") 
	    {
		    alert("\nThe Phone Number field is blank.\n\nPlease enter your phone number.");
		    document.order.HOMEPHONE.focus();
		    return false;
	    }
	if (document.order.WORKPHONE.value == "") 
	    {
		    alert("\nThe Phone Number field is blank.\n\nPlease enter your phone number.");
		    document.order.WORKPHONE.focus();
		    return false;
	    }
	var tmpnum = document.order.HOMEPHONE.value;
	document.order.HOMEPHONE.value = formatPhoneNum(tmpnum);
	var tmpnum = document.order.WORKPHONE.value;
	document.order.WORKPHONE.value = formatPhoneNum(tmpnum);
	tmpnum = document.order.FAXPHONE.value;
	document.order.FAXPHONE.value = formatPhoneNum(tmpnum);
	return true;

}


// JavaScript Document
function formatPhoneNum(inputStr)
{
	if (inputStr != "")
		{ 
        	    var phoneNum = filterChars(inputStr);
	            phoneNum = addFormat(phoneNum);       
		    return phoneNum;
		}
	else 
		{
		      return "";
	        }
}

function filterChars(phoneNumStr)
{
            var validchars = "0123456789";
            var letter;
            var strA;
            var strB;
            i = 0;
            while (i <= phoneNumStr.length)
            {
                        letter = phoneNumStr.charAt(i).toLowerCase();
                        if (validchars.indexOf(letter) < 0)
                        {
                                    //remove char @ index i
                                    strA = phoneNumStr.substring(0, i);
                                    strB = phoneNumStr.substring(i+1, phoneNumStr.length);
                                    phoneNumStr = strA + strB;
                        }
                        else
                        {
                                    i++;
                        }
            }
            return phoneNumStr;      
}

function addFormat(inputStr)
{
            // Add Slash
            if (inputStr != "")
	    {	
		    var strA = inputStr.substring(0, 3);
        	    var strB = inputStr.substring(3, inputStr.length);
	            phoneNumStr = strA +"-";
        	    phoneNumStr = phoneNumStr + strB;
	            // Add Hyphen
        	    strA = phoneNumStr.substring(0, 7);
	            strB = phoneNumStr.substring(7, phoneNumStr.length);
        	    phoneNumStr = strA + "-";
	            phoneNumStr = phoneNumStr + strB;
        	    return phoneNumStr;
	     }
	     else
	     {		
		 return "";     
	     }	
}


// Make sure a Card Type is selected.
function isCardtype()
	{
	var count = 0;
	for (var i = 0; i <= 2; i++)
		{
		if (document.order.PAYMENTTYPECD[i].checked==true)
			{
			count = count + 1;
			}
		}
		
	 if (count==0)
		{
			alert("\nYou must choose a Card Type.")
			document.order.PAYMENTTYPECD[0].focus();
			return false;
		}
		else
		{
		  return true;
		}	
	}	
       
//This script was written by yosarian@cyberramp.net
//I made some minor changes 
function verify_ccard(inNumber, type)
{// returns 0 if valid, positive number if invalid.
        total = 1*0;
        tmp = 1*0;

        number = "";

        // make sure there are only numbers in the string...
        for(i = 0; i < inNumber.length; i++)
        {
		if(inNumber.charAt(i) >= "0" && inNumber.charAt(i) <= "9")
                {
                        number = number + inNumber.charAt(i);
                }
        }

        if(number.length < 13) return 10; // too short for anything

        first = "" + number.charAt(0);
        second = "" + number.charAt(1);
        third = "" + number.charAt(2);
        firstTwo = first + second;
        firstFour = firstTwo + third + number.charAt(3);

        if(type == "MC")
        {
                if(first != "5" || second < "1" || second > "5")
                        return 11;// invalid Mastercard prefix
                if(number.length != 16)
                        return 21;
        }
        else if(type == "VISA")
        {
                if(first != "4")
                        return 12;// invalid Visa prefix
                if(number.length != 13 && number.length != 16)
                        return 22;
        }
        else if(type == "AMEX")
        {
                if(first != "3" || (second != "4" && second != "7"))
                        return 13;// invalid American Express Prefix
                if(number.length != 15) 
                        return 23;
        }

        // now check the credit card suffix and length vs. the type

    
         // do the check sum
        for(loc = number.length - 2; loc >= 0; loc -= 2)
        {
                total += 1 * number.charAt(loc +1);
                tmp = number.charAt(loc) * 2;
		if(tmp > 9) total += 1;
		total += tmp%10;
        }
	if(number.length % 2 > 0)
	total += 1 * number.charAt(0);


        return (total % 10);
}


function cardConfirm()
{
	for (var i = 0; i <= 2; i++)
		{
		if (document.order.PAYMENTTYPECD[i].checked==true)
		var cardtype = document.order.PAYMENTTYPECD[i].value;
			{
			}
		}
        if((reason = verify_ccard(document.order.PAYMENTREFNUM.value, cardtype)) == 0)
        {
			 return true;
        }
        else
        {
                alert("Card Number Invalid.");
                document.order.PAYMENTREFNUM.focus();
                return false;
        }
}

function isExpmonth()
{
	var mymonth=document.order.expiremonth.selectedIndex;
	if (mymonth==0) 
		{
			alert("\nYou must select Expiration month from the dropdown box.");
			document.order.expiremonth.focus();
		   	return false; 
		}
	else  
		{
		      return true;
 		}	     
}

function isExpyear() {
   var str = document.order.expireyear.value;
     // Return false if Exp. Date year is blank.
   
   if (document.order.expireyear.value == "") {
         alert("\nThe Exp. Date year is required.");
         document.order.expireyear.focus();
         return false;
   }
   // Return false if characters are not any of the following. 
		var ch = document.order.expireyear.value;
		if ( (ch != "05") && (ch != "06") && (ch != "07") && (ch != "08") && (ch != "09") && (ch != "10") && (ch != "11") && (ch != "12") ) {
         alert("\nPlease enter the correct expiration year.");
         document.order.expireyear.select();
         document.order.expireyear.focus();
         return false;
      }
    		return true;
}

function isExpdate() {
	var month = document.order.expiremonth.value;
	var year = document.order.expireyear.value;
	var expiredate;
	expiredate = month + "/" + year;
	document.order.PAYMENTREFEXPDATE.value = expiredate;
	return true;
}

function isCategory()
{
	var sub="";
	for (var i = 0; i <= 3; i++)
	{
		if (document.order.SUBSCRIPTIONNAME[i].checked==true)
		{
			sub = sub + document.order.SUBSCRIPTIONNAME[i].value;
		}
		document.order.category.value=sub;
	}
	return true;
}	

function isSubnamechkbox() {
	var sub="";
	for (var i=0; i<order.length; i++) {
 		if ((document.order.elements[i].type == "checkbox") && (document.order.elements[i].checked==true) 
 			&& (document.order.elements[i].name!="NOSELLFLG")) {
			sub = sub + document.order.elements[i].value + ",";
		}
	document.order.subname.value
	}
	var result=sub.lastIndexOf(',');
	var newresult=sub.substring(0,result);
 	document.order.subname.value=newresult;	
	//alert(document.order.subname.value);
	return true;
}

function isSubitems() {
	document.order.SUBITEMS.value=document.order.category.value + "," + document.order.subname.value;
	//alert(document.order.SUBITEMS.value);
	return true;
}


function isJoindate() {
   	var today = new Date();
	year = today.getYear();
	if (year < 2000)    
	year = year + 1900; 
	var tdate = ( (today.getMonth() + 1) + "/" + today.getDate() + "/" + year );
	document.order.JOINDATE.value = tdate;
	return true;
}

// Checks the Last Name field.
function isLastname()
   {
var str = document.order.LASTNAME.value;
   // Return false if Last Name field is blank.
   if (document.order.LASTNAME.value == "" || document.order.LASTNAME.value == " ") 
      {
      alert("\nThe Last Name field is blank.\n\nPlease enter your last name.")
      document.order.LASTNAME.focus();
      return false; 
      }

   // Return false if characters are not a-z, A-Z.
   for (var i = 0; i < str.length; i++) 
      {
      var ch = str.substring(i, i + 1);
      if ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) 
         {
         alert("\nThe Last Name field only accepts letters.\n\nPlease re-enter.");
         document.order.LASTNAME.select();
         document.order.LASTNAME.focus();
         return false;
         }
   else  {
      return true;
 		  }	     
      }       
   }

function isPrefix()
   {
	var mysel=document.order.PREFIX.selectedIndex;
	if (mysel==0) {
	alert("\nYou must select Prefix from the dropdown box.");
	document.order.PREFIX.focus();
   	return false; 
      }
   	else  {
      return true;
 		  }	     
}

function isPhone() {
   var str = document.order.WORKPHONE.value;
     // Return false if Daytime Phone Number field is blank.
   
   if (document.order.WORKPHONE.value == "" || document.order.WORKPHONE.value == " ") {
         alert("\nThe Work Phone Number is required.");
         document.order.WORKPHONE.focus();
         return false;
   }
   // Return false if characters are not '0-9', '-', '(', ')'. 
   for (var i = 0; i < str.length; i++) {
      var ch = str.substring(i, i + 1);
      if ((ch < "0" || "9" < ch) && (ch != '-') && (ch != '(') && (ch != ')')) {
         alert("\nDaytime Phone Number is invalid.");
         document.order.WORKPHONE.select();
         document.order.WORKPHONE.focus();
         return false;
      }
    		return true;
   }         
}

//checks the user name field
function isWebuser()
{
	var userStr = document.order.WEBUSERID.value;
	
	if (document.order.WEBUSERID.value=="")
		{
		alert("\nThe Username field is blank.\n\nPlease enter your Username")
		document.order.WEBUSERID.focus();
		return false;
		}
	if ((userStr.length < 6) || (userStr.length >10))
		{
		alert("\nThe Usernamen field has to be between 6 and 10 characters in length.\n\nPlease re-enter Username")
		document.order.WEBUSERID.focus();
		document.order.WEBUSERID.select();
		return false;
		}
	return true;
}

//checks the password.	
function isPsd()
	{
   var pscheck = document.order.WEBUSERID.value;
   var test  = document.order.WEBUSERPASSWORD.value;
   var newtest = test.substring(0,3);
 	
 	if (document.order.WEBUSERPASSWORD.value=="")
 	{
 	alert("\The Password field is blank.\n\nPlease enter your Passord")
 	document.order.WEBUSERPASSWORD.focus();
 	return false;
 	}
	
	if ((test.length < 6) || (test.length >10))
		{
		alert("\nThe Password field has to be between 6 and 10 characters in length.\n\nPlease re-enter Password")
		document.order.WEBUSERPASSWORD.focus();
		document.order.WEBUSERPASSWORD.select();
		return false;
		}

  	
     var ch = pscheck.substring(0, 3);
      if (ch == newtest ) 
         {
         alert("\nThe Password cannot start  with the same 4 characters as your User Name. \n\nPlease re-enter new Password.")
         document.order.WEBUSERPASSWORD.select();
         document.order.WEBUSERPASSWORD.focus();
         return false;
         }
        else {
         return true;
         }
 		
 }

 //checks for confirm
function isConfirm()
{
  var confirmpsd1 = document.order.WEBUSERPASSWORD.value;
  var confirmpsd2 = document.order.WEBPASSWORD2.value;
  if (document.order.WEBPASSWORD2.value == "") 
      {
       alert("\nThe Confirm field is blank.\n\nPlease enter your Confirm password")
       document.order.WEBPASSWORD2.focus();
       return false; 
      }
  if (confirmpsd2 != confirmpsd1)
  		{
  		alert("\nPlease retype your password")
  		document.order.WEBPASSWORD2.focus();
  		document.order.WEBPASSWORD2.select();
  		return false;
  		}
   else  {
      return true;
 		  }	     
}


function isSendemail() {
	if (document.order.internalmail.checked==true) {
	document.order.NOCALLFLG.value = "N";
	document.order.JOURNALFLG.value = "Y";
	}	
	else {
		document.order.NOCALLFLG.value = "Y";
		document.order.JOURNALFLG.value = "N";
	}
	if (document.order.thirdpartymail.checked==true) {
	document.order.NOSELLFLG.value = "N";
	}	
	else {
		document.order.NOSELLFLG.value = "Y";
		
	}return true;
}


// Prompt user before emptying shopping cart.
// NEILTAG 5/31/07
function emptyCartConfirmation() {
	var answer = confirm("Empty your cart?")
	if (answer){
		window.location = "ResetCart";
	}
}


// Search for organization name.
// NEILTAG 6/4/07
function RunOrgSearch() {	
	var tmpsearch = document.abc.ORGNAME.value;
	if (tmpsearch.length < 2) {
		alert('Please enter the first two characters (or more) of the organization name');
		document.abc.ORGNAME.focus();
		return false;
	} else {
		tmpsearch = encodeURIComponent(tmpsearch);
		tmpsearch = tmpsearch + '~';   
		window.open("../../cgi-bin/organizationdll.dll/List?ORGNAME="+tmpsearch+"&SORT=ORGNAME&WMT=none&WHP=OrganizationHeader.htm&WBP=OrganizationAddForm.htm","","fullscreen=no,location=yes,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480")
		return true;
	}
}   

function CreateOrg() {	
	
		window.open("../../cgi-bin/memberdll.dll/OpenPage?WRP=NewOrganizationProfile.htm&WPH=none&WLN=none&WPF=none","","fullscreen=no,location=yes,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=640,height=480")

}   




function EditUser()
{	
	window.open("../../cgi-bin/memberdll.dll/Info?CUSTOMERCD=<#CUSTOMERCD>&WRP=Customer_Update.htm&WPH=none&WLN=none&WPF=none","","fullscreen=no,location=yes,toolbar=no,menubar=yes,scrollbars=yes,resizable=yes,width=750,height=750")
}  

function ShoppingCartCheckOut() 
{ 
  	 //var allcookies = document.cookie;
	 var value = CUSTOMERCD;
	 /*var pos = allcookies.indexOf("memberid=");
	  if (pos != -1) 
	  {
	   var start = pos + 9;
	   var end = allcookies.indexOf(";", start);
	   if (end == -1) end = allcookies.length;
	   value = allcookies.substring(start, end);
	   value = unescape(value);
	  }*/
 
	 if (value != "") 
	 {
    		location='../../cgi-bin/msascartlist.dll/Orderconfirm';
	 }
       
	 else 
	  {
	   	location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=%2Fcvwebtest_elfa%2Fcgi-bin%2Fmsascartlist.dll%2FOrderconfirm';
		//location.href = 'http://www.elfaonline.org/index.cfm?fa=login&ReturnUrl=';
	  } 
	 
   
}

//LUCAS taken from CVWebRequired.js
//takes parameters in a hash (params) and submits as a post instead of get
function createPOST(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    var newForm = document.createElement("form");
    newForm.setAttribute("method", method);
    newForm.setAttribute("action", path);

    for(var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        newForm.appendChild(hiddenField);
    }

	document.body.appendChild(newForm);    
    newForm.submit();
}

