// JScript source code
// Functions that will be used by suppliers

function WhereFromWhat()
{
	var affVBC = false;
	var affTO = false;
	var affDL = false;
	var affPQ = false;
	
	document.FrontPage_Form1.Location[0].checked=false;
	document.FrontPage_Form1.Location[1].checked=false;
	document.FrontPage_Form1.Location[2].checked=false;
	document.FrontPage_Form1.Location[3].checked=false;
		
	trvbc.style.display='none';
	trto.style.display='none';
	trpq.style.display='none';
	trdl.style.display='none';
	
	//-----
	switch(document.FrontPage_Form1.Program1.value.toLowerCase())
	{
		case "mec" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=true;
				break;
			}		
				case "abt" :
			{
				affVBC=true;
				affTO=false;
				affDL=false;
				affPQ=false;
				break;
			}
		case "det" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}
		case "dbm" :
			{
				affVBC=false;
				affTO=false;
				affDL=true;
				affPQ=false;
				break;
			}

		case "tnl" :
			{
				affVBC=false;
				affTO=false;
				affDL=false;
				affPQ=true;
				break;
			}


		case "fos" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}
		case "abe" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=true;
				break;
			}
		case "sac" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}
		case "prt" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}

		case "0" :
			{
				affVBC=true;
				affTO=true;
				affDL=true;
				affPQ=true;
				break;
			}

		case "sls" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}

		case "ast" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=true;
				break;
			}


		case "bmg" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;	
						affPQ=false;
				break;
			}
			
			case "abm" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;	
				affPQ=false;
				break;
			}
			
		case "tss" :
			{
				affVBC=true;
				affTO=false;
				affDL=false;
							affPQ=false;
				break;
			}

			case "dce" :
			{
				affVBC=false;
				affTO=false;
				affDL=true;
				affPQ=false;
				break;
			}

			case "tnl" :
			{
				affVBC=false;
				affTO=false;
				affDL=false;
				affPQ=true;
				break;
			}

		case "dat" :
			{
				affVBC=false;
				affTO=false;
				affDL=true;
				affPQ=false;
				break;
			}		

		case "bat" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=true;
				break;
			}

		case "mbe" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=true;
				break;
			}

		case "cfc" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}

		case "ac1" :
			{
				affVBC=true;
				affTO=true;
				affDL=false;
				affPQ=false;
				break;
			}

		case "rpt" :
			{
				affVBC=true;
				affTO=false;
				affDL=false;
				affPQ=false;
				break;
			}

		case "pbt" :
			{
				affVBC=true;
				affTO=false;
				affDL=false;
				affPQ=false;
				break;
			}
	}//end switch

	
	if(affVBC)
	{
		trvbc.style.display='';
	}
	else
	{
		trvbc.style.display='none';
	}
	if(affTO)
	{
		trto.style.display='';
	}
	else
	{
		trto.style.display='none';
	}
	
	if(affPQ)
	{
		trpq.style.display='';
	}
	else
	{
		trpq.style.display='none';
	}
	if(affDL)
	{
		trdl.style.display='';
	}
	else
	{
		trdl.style.display='none';
	}
}//end WhereFromWhat() 



//-------------------------------------------
function FrontPage_Form1_Validator(theForm)
{

  if (theForm.Name.value == "")
  {
    alert("Please enter a value for the \"First and Last Names\" field.");
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Name.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"First and Last Names\" field.");
    theForm.Name.focus();
    return (false);
  }

   if (theForm.LName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    theForm.LName.focus();
    return (false);
  }

  if (theForm.LName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Last Name\" field.");
    theForm.LName.focus();
    return (false);
  }
  
  if (theForm.City.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.City.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.Prov.selectedIndex == 0)
  {
    alert("The first \"State - Province\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Prov.focus();
    return (false);
  }
	
  if (theForm.Prov.value == "0")
  {
    alert("Your selection in the Prov./State is not valid. Please choose one of the other options");
    theForm.Prov.focus();
    return (false);
  }
	
  if (theForm.Country.selectedIndex < 0)
  {
    alert("Please select one of the \"Country\" options.");
    theForm.Country.focus();
    return (false);
  }

  if (theForm.Country.selectedIndex == 0)
  {
    alert("The first \"Country\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Country.focus();
    return (false);
  }

  if (theForm.Tel.value == "")
  {
    alert("Please enter a value for the \"Phone\" field.");
    theForm.Tel.focus();
    return (false);
  }

  if (theForm.Tel.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Phone\" field.");
    theForm.Tel.focus();
    return (false);
  }
  
  if (theForm.Areacode.value.length > 3)
  {
    alert("Please enter only a 3 digit area code in the \"Area Code\" field.");
    theForm.Areacode.focus();
    return (false);
  }
  
  if (theForm.Email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }
  
   if (theForm.Email.value.length < 5)
  {
    alert("Please enter at least 5 characters in the \"Email Address\" field.");
    theForm.Email.focus();
    return (false);
  }
  
  
  
     if(theForm.Email.value.indexOf("@")<0 || theForm.Email.value.indexOf(".")<0)
  {
	alert("Invalid email address - Please try again");
	theForm.Email.focus();
    return (false);
  }
  
  var chOK="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz???????????????????????????????????0123456789-_@.";
  var Email = theForm.Email.value;
  var ctrlEmail = true;
  var i=0;
  var ch;
  
  while(ctrlEmail==true && i<Email.length)
  {
	ch=Email.charAt(i);
	if(chOK.indexOf(ch)<0)
	{
		ctrlEmail=false;
	}
	i++;
  }
  
  if (!ctrlEmail)
  {
    alert("Invalid Email address - Please try again");
    theForm.Email.focus();
    return (false);
  }

  if (theForm.Program1.selectedIndex < 0)
  {
    alert("Please select one of the \"Program1\" options.");
    theForm.Program1.focus();
    return (false);
  }

  if (theForm.Program1.selectedIndex == 0)
  {
    alert("The first \"Program1\" option is not a valid selection.  Please choose one of the other options.");
    theForm.Program1.focus();
    return (false);
  }
	
  if(document.FrontPage_Form1.Program1.value=="0")
	{
		alert("Please select a program.");
		theForm.Program1.focus();
		return (false);
	}
	
	//**alan writes here 'location; test
	
	var opt0=document.FrontPage_Form1.Location[0].checked;
  var opt1=document.FrontPage_Form1.Location[1].checked;
  var opt2=document.FrontPage_Form1.Location[2].checked;
  var opt3=document.FrontPage_Form1.Location[3].checked;
	
	if(opt0==false && opt1==false && opt2==false && opt3==false)
	{
		alert("Please select a study location.");
		if(trvbc.style.display=='')
		{
			theForm.Location[0].focus();
		}
		else
		{
			if(trto.style.display=='')
			{
				theForm.Location[1].focus();
			}
			
			else
		{
			if(trpq.style.display=='')
			{
				theForm.Location[2].focus();
			}
			
			else
		{
				if(trdl.style.display=='')
			{
					theForm.Location[3].focus();
				}
			}
		}	
		}
		return (false);
	}	

	
	//**alan writes here 'location; test
	
		
   if (theForm.StartDate.selectedIndex < 0)
  {
    alert("Please select one of the \"Start date\" options.");
    theForm.StartDate.focus();
    return (false);
  }

  if (theForm.StartDate.selectedIndex == 0)
  {
    alert("The first \"Start date\" option is not a valid selection.  Please choose one of the other options.");
    theForm.StartDate.focus();
    return (false);
  }

  if (theForm.StartYear.selectedIndex < 0)
  {
    alert("Please select one of the \"Start Year\" options.");
    theForm.StartYear.focus();
    return (false);
  }

  if (theForm.StartYear.selectedIndex == 0)
  {
    alert("The first \"Start Year\" option is not a valid selection.  Please choose one of the other options.");
    theForm.StartYear.focus();
    return (false);
  }

  if (theForm.TimeToContact.selectedIndex < 0)
  {
    alert("Please select one of the \"Best time to contact you\" options.");
    theForm.TimeToContact.focus();
    return (false);
  }

  if (theForm.TimeToContact.selectedIndex == 0)
  {
    alert("The first \"Best time to contact you\" option is not a valid selection.  Please choose one of the other options.");
    theForm.TimeToContact.focus();
    return (false);
  }


//** '  var radioSelected = false;
//** '  for (i = 0;  i < theForm.Source.length;  i++)
//** '  {
//** '    if (theForm.Source[i].checked)
//** '        radioSelected = true;
//** '  }
 //** ' if (!radioSelected)
//** '  {
 //** '   alert("Please select one of the \"Where did you learn about ATC?\" options.");
//** '    return (false);
//** '  }
  
  //-------------------

    var iChars = "@#$%^&*()+=-[]\\\;/{}|\":<>\\'\\";
        for (var i = 0; i < theForm.comments.value.length; i++) {
                if (iChars.indexOf(theForm.comments.value.charAt(i)) != -1) {
                alert ("The box has special characters. \nThese are not allowed.\n");
				 theForm.comments.focus();
                return false;
        }
                }
  
  return (true);
}//end FrontPage_Form1_Validator(theForm)




//----------------------------------------------------
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

//----------------------------------------------------
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//----------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

//------------------------------------------------------
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
