function init(){
/*Creates the object that holds the error message table*/
 try{
    var oTableContainer=document.createElement("<div id='oTableContainer'>");
	var oTD=document.getElementById("errMessages");
	oTD.appendChild(oTableContainer);
	message=new makeObj('oTableContainer')
	//test=new makeObj('oSpan')
  }
  catch(e)
  {
    //Do nothing
  }
}

/*############################################################################
This script is made by bratta from www.bratta.com and can be used freely
as long as this msg is intact. Visit www.bratta.com for more great scripts.
############################################################################*/
	var n = (document.layers) ? 1:0;
	var ie = (document.all) ? 1:0;
	var vis=0;
/*The function for "making" the objects
######################################################################################*/
	function makeObj(obj){				
   	this.css=(n) ? eval('document.'+obj):eval(obj+'.style')		
		this.showIt=b_showIt;
		
		this.hideIt=b_hideIt;					
		return this
	}
/*The functions for showing and hiding
#####################################################################################*/
	function b_showIt(){
		{
			spnResult.style.display="none"
			this.css.display="inline"
		}
	}
	function b_hideIt(){
		
        this.css.display="none"
	}
//######################################################################################

/***********************************************************************************
Form validation code. Calls to seperate functions that evaluate individual
controls on the form. Returns '0' if form does not validate, '1' if form validates
Creates an error message in a string and calls 'hasTable' to begin constructing the 
error table 
************************************************************************************/
function validateContact(contactForm){

	var allValid;
  	var aErrMsg= new Array()
	var iArrayEle=0
	allValid = 1;
	var strErr=""
	var phoneLgnth=contactForm.txtPhone.value; /* + contactForm.txtEx.value + contactForm.txtNum.value;*/																														
	if (allValid==1){
	//check individual form items 
	checkFirstName=verifyNotEmpty(contactForm.txtFrstName.value);
		if (checkFirstName == 0) {
			allValid = 0;
			strErr+="Please enter your first name."
			}
	checkLastName=verifyNotEmpty(contactForm.txtLstName.value);
		if (checkLastName == 0) {
			allValid = 0;
			strErr+="Please enter your last name."
			}
	checkEmail=verifyEmail(contactForm.txtEmailAdd.value);
		if (checkEmail == 0) {
			allValid = 0;
			strErr+="Please enter a valid email address."
			}
	checkPhoneLgnth=verifyNotEmpty(contactForm.txtPhone.value);
		
		if (checkPhoneLgnth == 0) {
			allValid = 0;
			strErr+="Please enter a valid phone number."
			}
/*
		else{
		checkPhoneArea=verifyIsNum(contactForm.txtArea.value);
		if (checkPhoneArea == 0) {
			allValid = 0;
			strErr+="Please enter your correct 3-digit area code."
			}
	checkPhoneEx=verifyIsNum(contactForm.txtEx.value);
		if (checkPhoneEx == 0) {
			allValid = 0;
			strErr+="Please enter your correct 3-digit phone exchange."
			}
	checkPhoneNum=verifyIsNum(contactForm.txtNum.value);
		if (checkPhoneNum == 0) {
			allValid = 0;
			strErr+="Please enter the correct last 4-digits of your phone number."
			}
			
		
		}
	*/
		//if fields do not validate construct the error table
		if (allValid==0){                       
			
		hasTable(strErr)
		}
	else	
		//...otherwise submit the form
		{
		removeElement(contactForm.name);
		//document.infoForm.submit()
		getSubmit(contactForm);
		}
	}
}
	
/***********************************************************************************
Form validation code for "Tell a Friend" page. Calls to seperate functions that evaluate individual
controls on the form. Returns '0' if form does not validate, '1' if form validates
Creates an error message in a string and calls 'hasTable' to begin constructing the 
error table. Checks that the individual submitting the form has entered a valid name and email and
that there is at least one email address that has been submitted.
************************************************************************************/
function validateReferences(referenceForm){
	var allValid;
  	var aErrMsg= new Array()
	var iArrayEle=0
	allValid = 1;
	var strErr=""
	var refEmail=referenceForm.txtEmailAdd1.value + referenceForm.txtEmailAdd2.value + referenceForm.txtEmailAdd3.value+referenceForm.txtEmailAdd4.value+referenceForm.txtEmailAdd5.value+referenceForm.txtEmailAdd6.value;
	if (allValid==1){
	//check individual form items 
	checkSenderName=verifyNotEmpty(referenceForm.txtSenderName.value);
		if (checkSenderName == 0) {
			allValid = 0;
			strErr+="Please enter your first name."
			}
		checkEmail=verifyEmail(referenceForm.txtSenderEmail.value);
		if (checkEmail == 0) {
			allValid = 0;
			strErr+="Please enter a valid email address."
			}
		checkEmailExist=verifyNotEmpty(refEmail);
		if (checkEmailExist == 0) {
			allValid = 0;
			strErr+="Please enter at least one email besides your own."
			
			}
		checkEmail_1Exist=verifyNotEmpty(referenceForm.txtEmailAdd1.value);
		if (checkEmail_1Exist == 0) {
			}
			else{
	 			checkEmail_1=verifyEmail(referenceForm.txtEmailAdd1.value);
				if (checkEmail_1 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}
		checkEmail_2Exist=verifyNotEmpty(referenceForm.txtEmailAdd2.value);
		if (checkEmail_2Exist == 0) {
			}
			else{
	 			checkEmail_2=verifyEmail(referenceForm.txtEmailAdd2.value);
				if (checkEmail_2 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}
		checkEmail_3Exist=verifyNotEmpty(referenceForm.txtEmailAdd3.value);
		if (checkEmail_3Exist == 0) {
			}
			else{
	 			checkEmail_3=verifyEmail(referenceForm.txtEmailAdd3.value);
				if (checkEmail_3 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}
		checkEmail_4Exist=verifyNotEmpty(referenceForm.txtEmailAdd4.value);
		if (checkEmail_4Exist == 0) {
			}
			else{
	 			checkEmail_4=verifyEmail(referenceForm.txtEmailAdd4.value);
				if (checkEmail_4 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}
		checkEmail_5Exist=verifyNotEmpty(referenceForm.txtEmailAdd5.value);
		if (checkEmail_5Exist == 0) {
			}
			else{
	 			checkEmail_5=verifyEmail(referenceForm.txtEmailAdd5.value);
				if (checkEmail_5 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}
		checkEmail_6Exist=verifyNotEmpty(referenceForm.txtEmailAdd6.value);
		if (checkEmail_6Exist == 0) {
			}
			else{
	 			checkEmail_6=verifyEmail(referenceForm.txtEmailAdd6.value);
				if (checkEmail_6 == 0) {
					allValid = 0;
					strErr+="Please enter a valid email address."
				}
			}														
			//if fields do not validate construct the error table
			if (allValid==0){                       
			hasTable(strErr)
		}
	else	
		//...otherwise submit the form
		{
		removeElement(referenceForm.name);
		//document.referenceForm.action="stonemont/newsletters/newsletter_func.asp" //opens a new window with the updated chart
		//document.referenceForm.method="post"
		//document.referenceForm.target="_self"
		//document.referenceForm.submit()
		getSubmit(referenceForm)
		}
	}
}


/***********************************************************************************
Form validation code for "Sign up for Newsletter" page. Calls to seperate functions that evaluate individual
controls on the form. Returns '0' if form does not validate, '1' if form validates
Creates an error message in a string and calls 'hasTable' to begin constructing the 
error table. Checks that the individual submitting the form has entered a valid email.
************************************************************************************/
function validateNewsLetter(newsLetterForm){

	var allValid;
  	var aErrMsg= new Array()
	var iArrayEle=0
	allValid = 1;
	var strErr=""
	
	checkEmail=verifyEmail(newsLetterForm.txtEmailAdd.value);
	//var refEmail=newsLetterForm.txtEmailAdd.value
	if (allValid==1){
	//check individual form items 
	
		
		
		
		if (checkEmail == 0) {
			allValid = 0;
			strErr+="Please enter a valid email address."
			}
														
			//if fields do not validate construct the error table
			if (allValid==0){                       
			//alert("not a valid email")
			
		}
	else	
		//...otherwise submit the form
		{
		removeElement(newsLetterForm.name);
		
		document.newsLetterForm.action="stonemont/newsletters/newsletter_func.asp" //opens a new window with the updated chart
		document.newsLetterForm.method="post"
		document.newsLetterForm.target="_self"
		document.newsLetterForm.submit()
		
		
		//document.newsLetterForm.submit()
		}
	}
}
function unSubscribe(newsLetterForm){
	//newsLetterForm.txtSubscribeToggle.value="true"
	//validateNewsLetter(newsLetterForm)
	getHTMLPage2()
}
function subscribe(newsLetterForm){
	//newsLetterForm.txtSubscribeToggle.value="false"
	//validateNewsLetter(newsLetterForm)
	getHTMLPage2()
}
function references(referenceForm){
	referenceForm.txtSubscribeToggle.value="refer"
	//alert(referenceForm.txtSubscribeToggle.value)
	validateReferences(referenceForm)
	
}

function getSubmit(form){
	
	try{
		var frmName=form.name
		
		switch (frmName) {
			
			case "contactForm":{
				document.contactForm.action="/stonemont/downloads/contactstonemont.asp" 
				document.contactForm.method="post"
				document.contactForm.target="_self"
				document.contactForm.submit()
			}
			break;
			case "referenceForm":{
				//document.referenceForm.action="xServ.asp?source=menu2&xform=main.display&topics=WELCOME&topic=TellFriends&type=submit1" 
				document.referenceForm.action="/stonemont/newsletters/newsletter_func.asp" 
				//document.referenceForm.action="/stonemont/newsletters/newsletter_func.asp
				document.referenceForm.method="post"
				document.referenceForm.target="_self"
				document.referenceForm.submit()
			}
			break;
			case "newsletterForm":{
				var valTypeSubscribe=document.newsletterForm.valTypeSubscribe.value
					
				switch (valTypeSubscribe) {
					case "1":{
				
						document.newsletterForm.action="/stonemont/downloads/aggqcSubcribe.asp" 
						document.newsletterForm.method="post"
						document.newsletterForm.target="_self"
						document.newsletterForm.submit()
					}
					break;
					case "2":{
					
						document.newsletterForm.action="/stonemont/downloads/aggqcSubcribe.asp" 
						document.newsletterForm.method="post"
						document.newsletterForm.target="_self"
						document.newsletterForm.submit()
					}
					break;
				}
			}
			break;
			case "infoForm":{
		//alert(frmName)
				var valTypeDemo=document.infoForm.valTypeDemo.value
			//	alert (document.infoForm.optMethod.value)
				switch (document.infoForm.optMethod.value) {
					case "1":{
						document.infoForm.action="/stonemont/downloads/aggqcgetdemo.asp" 
						document.infoForm.method="post"
						document.infoForm.target="_self"
						document.infoForm.submit()
				}
				break;
					case "2":{
	//alert ("getSubmit")
						document.infoForm.action="/stonemont/downloads/aggqcgetdemo.asp" 
						document.infoForm.method="post"
						document.infoForm.target="_self"
						document.infoForm.submit()
				}
				break;
				default:{
				}
				break;
				}
			}
			break;
			default:{
			}
			break;
			}
		}
	catch(e){
		//do nothing. an error tends to be thrown here when the page is updated to quickly. Just ignore it.
	}
}

function getTypeDemo(infoForm){
	//document.infoForm.valTypeDemo.value=1 //download
	document.infoForm.valTypeDemo.value=2 //download
}
function getTypeDemo2(infoForm){
	document.infoForm.valTypeDemo.value=2 //mail cd
}

function getTypeSubscribe(newletterForm){
	newletterForm.valTypeSubscribe.value=1 //download
	
}
function getTypeSubscribe2(newletterForm){
	newletterForm.valTypeSubscribe.value=2
	
}

function validateForm(infoForm){
//	message.showIt2();
	var allValid;
  	var aErrMsg= new Array()
	var iArrayEle=0
	allValid = 1;
	var strErr=""
	var phoneLgnth=infoForm.txtPhone.value;
	/* + infoForm.txtEx.value + infoForm.txtNum.value;																		*/										//alert(infoForm.optMethod.value)	
	document.infoForm.optMethod.value=2
	if (allValid==1){
	//check individual form items 
	checkFirstName=verifyNotEmpty(infoForm.txtFrstName.value);
		if (checkFirstName == 0) {
			allValid = 0;
			strErr+="Please enter your first name."
			}
	checkLastName=verifyNotEmpty(infoForm.txtLstName.value);
		if (checkLastName == 0) {
			allValid = 0;
			strErr+="Please enter your last name."
			}
	checkCompany=verifyNotEmpty(infoForm.txtCompany.value);
		if (checkCompany == 0) {
			allValid = 0;
			strErr+="Please enter your company name."
			}
	checkAddress=verifyNotEmpty(infoForm.txtFrstAdd.value);
		if (checkAddress == 0) {
			allValid = 0;
			strErr+="Please enter your address."
			}
	checkCity=verifyNotEmpty(infoForm.txtCty.value);
		if (checkCity == 0) {
			allValid = 0;
			strErr+="Please enter your city."
			}
	checkState=verifyNotEmpty(infoForm.txtState.value);
		if (checkState == 0) {
			allValid = 0;
			strErr+="Please enter a state, providence, region."
			}
			
	checkCountry=verifyNotEmpty(infoForm.txtCountry.value);
		if (checkCountry == 0) {
			allValid = 0;
			strErr+="Please enter a country."
			}

	checkEmail=verifyEmail(infoForm.txtEmailAdd.value);
		if (checkEmail == 0) {
			allValid = 0;
			strErr+="Please enter a valid email address."
			}
			
	checkPhoneLgnth=verifyNotEmpty(phoneLgnth);
		//alert (phoneLgnth)
		if (checkPhoneLgnth == 0) {
			allValid = 0;
			strErr+="Please enter a phone number."
			}
/*		else{
		checkPhoneArea=verifyIsNum(infoForm.txtArea.value);
		if (checkPhoneArea == 0) {
			allValid = 0;
			strErr+="Please enter your correct 3-digit area code."
			}
	checkPhoneEx=verifyIsNum(infoForm.txtEx.value);
		if (checkPhoneEx == 0) {
			allValid = 0;
			strErr+="Please enter your correct 3-digit phone exchange."
			}
	checkPhoneNum=verifyIsNum(infoForm.txtNum.value);
		if (checkPhoneNum == 0) {
			allValid = 0;
			strErr+="Please enter the correct last 4-digits of your phone number."
			}
		
		}
*/
	
		//if fields do not validate construct the error table
		if (allValid==0){                       
			
		hasTable(strErr)
		}
	else	
		//...otherwise submit the form
		{
		removeElement(infoForm.name);
		getSubmit(infoForm);
		//document.infoForm.submit()
		}
	}
	
}


function validateForm2(newsletterForm){
//	message.showIt2();
	var allValid;
  	var aErrMsg= new Array()
	var iArrayEle=0
	allValid = 1;
	var strErr=""
	/*var phoneLgnth=newsletterForm.txtArea.value + newsletterForm.txtEx.value + newsletterForm.txtNum.value;*/																														
	if (allValid==1){
	//check individual form items 
	checkFirstName=verifyNotEmpty(newsletterForm.txtFrstName.value);
		if (checkFirstName == 0) {
			allValid = 0;
			strErr+="Please enter your first name."
			}
	checkLastName=verifyNotEmpty(newsletterForm.txtLstName.value);
		if (checkLastName == 0) {
			allValid = 0;
			strErr+="Please enter your last name."
			}
	checkCompany=verifyNotEmpty(newsletterForm.txtCompany.value);
		if (checkCompany == 0) {
			allValid = 0;
			strErr+="Please enter your company name."
			}
	checkAddress=verifyNotEmpty(newsletterForm.txtFrstAdd.value);
		if (checkAddress == 0) {
			allValid = 0;
			strErr+="Please enter your address."
			}
	checkCity=verifyNotEmpty(newsletterForm.txtCty.value);
		if (checkCity == 0) {
			allValid = 0;
			strErr+="Please enter your city."
			}
	checkState=verifyNotEmpty(newsletterForm.txtState.value);
		if (checkState == 0) {
			allValid = 0;
			strErr+="Please enter a region, state or providence."
			}
	checkCountry=verifyNotEmpty(newsletterForm.txtCountry.value);
		if (checkCountry == 0) {
			allValid = 0;
			strErr+="Please enter a country."
			}
	checkEmail=verifyEmail(newsletterForm.txtEmailAdd.value);
		if (checkEmail == 0) {
			allValid = 0;
			strErr+="Please enter a valid email address."
			}
	checkPhone=verifyNotEmpty(newsletterForm.txtPhone.value);
		if (checkCountry == 0) {
			allValid = 0;
			strErr+="Please enter a valid phone number."
			}
		
		
	
		//if fields do not validate construct the error table
		if (allValid==0){                       
		
		hasTable(strErr)
		}
	else	
		//...otherwise submit the form
		{
		//removeElement(newsletterForm.name);
		
		getSubmit(newsletterForm);
		//document.infoForm.submit()
		}
	}
	
}




/*Delete any existing error tables from previous submittal attempts if they exist
and construct a new table, or just construct a new table*/
function hasTable(data){
	var hasTable=oTableContainer.hasChildNodes()

	if (hasTable==true){
		removeElement();
		validateFail(data)
		}
		else{
		validateFail(data)
		}
}
function verifyNotEmpty(data) {
  
  var data_len;
  // Get the length of the string
  data_len = data.length;
 // Check that the length is greater than zero
  if (data_len > 0) {
    return 1;
  } 
  else {
    return 0;
  }
}
// ************************************************************************
// This is the validate email function. Take it verbatum ... dont try to 
// change it. It's a generic self contained modulat function. Use it as is
// and you'll do well.
// ************************************************************************
// Begin validEmail Function
function verifyEmail(data) {
	
	invalidChars = " /:,;"
	if (data == "") {		// The email field cannot be empty
				return 0;
	}
	for (i=0; i<invalidChars.length; i++) {	// Does it contain any invalid characters?
		badChar = invalidChars.charAt(i)
		if (data.indexOf(badChar,0) > -1) {
			return 0;
			}
	}
	atPos = data.indexOf("@",1)	// There must be one "@" symbol
	if (atPos == -1) {
		return 0;
	}
	if (data.indexOf("@",atPos+1) != -1) {	// ...and only one "@" symbol
		return 0;
		}
	periodPos = data.indexOf(".",atPos)
	if (periodPos == -1) {			// .... and at least one "." after the "@"
			return 0;
	}
	if (periodPos+3 > data.length)	{ // .. there must be at least 2 characters after the "."
		return 0;
	}
		return 1
} // End validEmail Function

function verifyLength(data) {
  var data_len;
  // Get the length of the string
  data_len = data.length;
 	
 // Check that the length is greater than zero
  if (data_len != 10) {
    return 0;
  } 
  else {
    return 1;
  }
}
// ************************************************************************
// This is the 'is it a number' function. Take it verbatum ... dont try to 
// change it. It's a generic self contained modulat function. Use it as is
// and you'll do well.
// ************************************************************************
// Begin isNum Function
function verifyIsNum(data) {		// Is this a number?
	if (data == "") {
		return 0;
	}
	for (i=0; i<data.length; i++) {
		
		if (data.charAt(i) < "0") {
				return 0;
		}
		if (data.charAt(i) > "9") {
			return 0;
			}
		}
	return 1;
}
// End isNum Function
/*************************************************************************
Constructs the error table
**************************************************************************/
function validateFail(data){
//Create the table elements
	var oTable = document.createElement("TABLE");
	var oTHead = document.createElement("THEAD");
	var oTBody0 = document.createElement("TBODY");
	var oTBody1 = document.createElement("TBODY");
	var oTFoot = document.createElement("TFOOT");
	var oCaption = document.createElement("CAPTION");
	var oRow, oCell,j;
	//The error string 'data' is parsed using the '.' character
	var strBreak="." 
	var iStrBreak=data.indexOf(strBreak)
		for (i=0;i<data.length;i++){
		//find the break
		   if(data.charAt(i)==strBreak){
		   	
			oRow = document.createElement("TR");
  			oTBody0.appendChild(oRow);
			oRow.setAttribute("className", "clsError")
			//Create an array from the error string, 'j' is the row
			var aErrMsg = new Array;
			//'i' marks the position of the '.' character
			//'j' is set to 'i' at the end of the function
			
			aErrMsg[j,0]=data.substring(j+1,i+1);
			
			
			{
    		oCell = document.createElement("TD");
			oCell.innerText = aErrMsg[j,0]
    		oCell.setAttribute("className", "clsError")
			oRow.appendChild(oCell);
			}
			j=i
	   	}
	}
// Insert the created elements into oTable.
oTable.appendChild(oTBody0);
oTable.setAttribute("id","tblError");
oTable.setAttribute("className","clsError");
// Create and insert rows and cells into the footer row.
oRow = document.createElement("TR");
oTFoot.appendChild(oRow);
oCell = document.createElement("TD");
oRow.appendChild(oCell);
// Insert the table into the document tree.
oTableContainer.appendChild(oTable);
//displays the message
message.showIt();
}
//Removes any existing error tables from previous submittals
function removeElement(form)
{
var formName=form
  try
  {
    var oChild=oTableContainer.children(0);	
    oTableContainer.removeChild(oChild);
  }
  catch(x)
  {
	if(formName=="infoForm"){
     document.infoForm.submit();
	
	}
	
	if(formName=="referenceForm"){
     document.referenceForm.submit();
	
	}
	if(formName=="newsletterForm"){
     document.referenceForm.submit();
	}
	
	else{
	 if(document.contactForm!=null){
	 document.contactForm.submit();
	 }
	}
  }
}
function jumpPage(newLoc) {
	newPage = newLoc.options[newLoc.selectedIndex].value
		if (newPage != "") {
			open(newPage,"_blank")
			
		}
}



/*
Contractible Headers Script- © Dynamic Drive (www.dynamicdrive.com)
For full source code, 100's more DHTML scripts, and TOS, 
Visit http://www.dynamicdrive.com
*/
var ns6=document.getElementById&&!document.all?1:0
var head="display:''"
var folder=''

function expandIt(obj){
var i;
var oIndex=obj.sourceIndex;
var oName=test.childNodes(1).nodeName

for(i=oIndex;i<=185;i++){
	
}

folder=ns6?obj.nextSibling.nextSibling.style:document.all[obj.sourceIndex+1].style
if (folder.display=="none")
folder.display=""
else
folder.display="none"

//folderPrevious=ns6?obj.previousSibling.previousSibling.style:document.all[obj.sourceIndex-1].style
//if (folderPrevious.display=="none")
//folderPrevious.display="none"
//else
//folderPrevious.display="none"
}

function getHTMLPage(url,prop,page, opener, status) {
//winStats='toolbar=no,location=no,directories=no,menubar=no,scrollbars=no,width=560,height=615'
var winStats=prop

	document.all.txtPosition.value=page
   var newWin=window.open(url,'windowName',winStats);
   var newPage=opener;
 //  var newPage='http://192.168.1.100/stonemont_root/xServ.asp?source=menu2&amp;xform=main.display&amp;topics=SUPPORT&amp;topic=stonemontForum'
  var checkLoad=status;
  if(checkLoad==0){
  //do nothing
  }
  else{
   open(newPage,"_self")
  }
  
}

function getHTMLPage2() {
	//newPage = newLoc.options[newLoc.selectedIndex].value
		var newPage='xServ.asp?source=menu2&xform=main.display&topics=WELCOME&topic=NewsLetter&type=initial'
		if (newPage != "") {
			open(newPage,"_self")
		
		}
}

