
// clears and replaces text in form input fields and textareas
// -----------------------------------------------------------------
function clearText(thefield) {
  if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 
function replaceText(thefield) {
  if (thefield.value=="") { thefield.value = thefield.defaultValue }
}



function createIframe (iframeSrc) 
{
	node = document.getElementById("iframediv");
	var iframe;
	if (document.createElement && (iframe = document.createElement('iframe'))) 
	{
		iframe.name = 'bnapics';
		iframe.id = 'bnapics';
        iframe.style.height = '82px'; 
        iframe.style.width = '455px'; 
		iframe.padding = '0px';  
		iframe.marginTop = '3px'; 
		iframe.frameBorder = '0';
		iframe.scrolling = "no";
		iframe.src = iframeSrc;
		if(document.getElementById('bnapics'))
		{
			document.getElementById('bnapics').src = iframeSrc;
		}
		else
		{
			node.appendChild(iframe);
		}
	}
}

function addLargeImage(thepic)
{
	node = document.getElementById("iframediv");
	var thediv;
	if (document.createElement && (thediv = document.createElement('div'))) 
	{
		mypar = document.createElement('p');
		myImage = new Image() ;
		myImage.src = thepic; 		
		thediv.name = 'largebnapic';
		thediv.style.padding='0px';
		thediv.style.margin='0px';
		myImage.style.margin='0px';
		thediv.style.textAlign='center';
		thediv.style.background="#fafafa";
		if(parent.document.getElementById("bnapics").style.width=='440px')
		{
			thediv.width='435px';
			thediv.maxWidth='435px';
			myImage.style.maxWidth = "430px";
			mypar.style.maxWidth = "430px";
			//parent.document.getElementById('largebnapic').maxWidth= 430;
		}	
		else
		{
			thediv.width='480px';
			myImage.style.maxWidth = "450px";
		}
		thediv.style.marginTop='5px';
		myImage.style.borderBottom="#ccc 1px solid";
		myImage.style.borderTop = "#ccc 1px solid";
		myImage.style.borderLeft = "#ccc 1px solid";
		myImage.style.borderRight = "#ccc 1px solid"; 
		myImage.style.padding = "3px 3px 3px 3px";
		if(document.all){
			 mypar.innerText = "Click Image to Close";
		} else{
			mypar.textContent = "Click Image to Close";
		}
		mypar.style.color = '#8b4f0b';
		mypar.style.fontSize = '12px';
		mypar.setAttribute('onmouseover', "this.style.cursor='pointer';"); 	
		thediv.id = 'largebnapic';
		thediv.setAttribute('onmouseover', "this.style.cursor='pointer';"); 
		thediv.setAttribute('onclick', 'document.getElementById("largebnapic").innerHTML = "";'); 	
		if(document.getElementById('largebnapic'))
		{
			document.getElementById('largebnapic').innerHTML = '';	
			document.getElementById('largebnapic').appendChild(myImage);
			document.getElementById('largebnapic').appendChild(mypar);
		}
		else
		{
			node.appendChild(thediv);
			document.getElementById('largebnapic').appendChild(myImage);
			document.getElementById('largebnapic').appendChild(mypar);
		}
	}

}

function checkcontact(fields)
{
    var email = document.getElementById('email').value;
    var phone = document.getElementById('phone').value;
	var msg;
	var success = false;
  
    if (email)//Checks for an email field
	{
	  var substremail = email.split("@")   
      if (substremail.length > 1)//makes sure the email address has an @ symbol   
      {   
          index = substremail[1].indexOf(".") 
		     
           if (index != -1)   //makes sure there is a dot (.) in the address
           { 
		    	success = true;
           }   
      } 
	}
	
	if (phone)//checks for a number field
	 {	 
	 	if (IsNumeric(phone)!=false)//checks for a non numeric value
		{			
			success = true;
		}
	}
	if(success == false)
	{
		msg  = "______________________________________________________\n\n"
		msg += "The form was not submitted because of the following error(s).\n";
		msg += "Please enter a valid email or phone number and re-submit.\n";
		msg += "______________________________________________________\n\n"
    	alert(msg);
    	return false; 		
	}
	else
	{
		return true;	
	}
}

function IsNumeric(sText)
{

	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 IsNumber = false;
			 }
		  }
	   return IsNumber;
}	
