//  http://www.brubakerconstruction.com javascript 
//  rotating image
var interval = 1000; // delay between rotating images (in seconds)
var random_display = 1; // 0 = no, 1 = yes
interval *= 1000;
 
var image_index = 0;
image_list = new Array();
image_list[image_index++] = new imageItem("images/photo-lg-01.jpg");
image_list[image_index++] = new imageItem("images/photo-lg-02.jpg");
image_list[image_index++] = new imageItem("images/photo-lg-03.jpg");
image_list[image_index++] = new imageItem("images/photo-lg-04.jpg");
image_list[image_index++] = new imageItem("images/photo-lg-05.jpg");
var number_of_image = image_list.length;
function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}
function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src);
}
function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}
function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
}
else {
image_index = (image_index+1) % number_of_image;
}
var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);
}
function rotateImage(place) {
var new_image = getNextImage();
document[place].src = new_image;
var recur_call = "rotateImage('"+place+"')";
setTimeout(recur_call, interval);
}
//  End      

function setDisplay(objId, sVisibility) {
    var obj = document.getElementById(objId);
    obj.style.display = sVisibility;
}
function newView(page) {    //opens a new window
    newWindow=window.open(page,'newView','toobar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=700,height=500,left=100,top=100')
    newWindow.focus
}

function newWindow1(page) {
         email = window.open(page,'email','scrollbars=no,location=no,toolbar=no,resizable=yes,status=no,width=330,height=390,top=150,left=300')

}

   function submitIt() {
            if (document.emailSend.name.value.length < 2) {
               alert("Please enter your name")
               document.emailSend.name.focus()
               document.emailSend.name.select()
               return false
            }
       //     if (!testPhone(document.emailSend.phone.value)) {
              // alert("Please enter a valid phone number")
        //       document.emailSend.phone.focus()
        //       document.emailSend.phone.select()
        //       return false
        //    }
            if (!emailCheck(document.emailSend.email.value)) {
               alert("Please enter a valid E-mail address")
               document.emailSend.email.focus()
               document.emailSend.email.select()
               return false
            }
            if (document.emailSend.Rank.checked) {
					if (document.emailSend.url.value.length < 5) {
				     alert("Please enter a valid URL for your ranking report.")
					  document.emailSend.url.focus()
					  document.emailSend.url.select()
					  return false
					}
				}            
            // required fields are OK, return true
				alert("Thank-you for your message. We will get back to you shortly.")
            return true
     }

/* Email Check Function *********************************************/
function emailCheck (emailStr) {
/* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */
var checkTLD=1;
/* The following is the list of known TLDs that an e-mail address must end with. */
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
/* The following pattern is used to check if the entered e-mail address fits the user@domain format.  It also is used to separate the username from the domain. */
var emailPat=/^(.+)@(.+)$/;
/* The following string represents the pattern for matching all special characters.  We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
/* The following string represents the range of characters allowed in a username or domainname.  It really states which chars aren't allowed.*/
var validChars="\[^\\s" + specialChars + "\]";
/* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")";
/* The following pattern applies for domains that are IP addresses, rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
/* The following string represents an atom (basically a series of non-special characters.) */
var atom=validChars + '+';
/* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")";
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
/* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
/* Finally, let's start trying to figure out if the supplied address is valid. */
/* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat);
if (matchArray==null) {
/* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */
alert("Email address seems incorrect (check @ and .'s)");
return false;
}
var user=matchArray[1];
var domain=matchArray[2];
// Start by checking that only basic ASCII characters are in the strings (0-127).
for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
alert("Ths email address username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
alert("Ths domain name for this email address contains invalid characters.");
return false;
   }
}
// See if "user" is valid 
if (user.match(userPat)==null) {
// user is not valid
alert("The email address username doesn't seem to be valid.");
return false;
}
/* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {
// this is an IP address
for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
alert("Destination IP email address is invalid!");
return false;
   }
}
return true;
}
// Domain is symbolic name.  Check if it's valid. 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("The email address domain name does not seem to be valid.");
return false;
   }
}
/* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */
if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("The email address must end in a well-known domain or two letter " + "country.");
return false;
}
// Make sure there's a host name preceding the domain.
if (len<2) {
alert("This email address is missing a hostname!");
return false;
}
// If we've gotten this far, everything's valid!
return true;
}
/* End Email Check Function *********************************************/

/* Phone Check Functions *********************************************************************************************/
var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value
if(p.length==3){
	//d10=p.indexOf('(')
	pp=p;
	d4=p.indexOf('(')
	d5=p.indexOf(')')
	if(d4==-1){
		pp="("+pp;
	}
	if(d5==-1){
		pp=pp+")";
	}
	//pp="("+pp+")";
	document.emailSend.phone.value="";
	document.emailSend.phone.value=pp;
}
if(p.length>3){
	d1=p.indexOf('(')
	d2=p.indexOf(')')
	if (d2==-1){
		l30=p.length;
		p30=p.substring(0,4);
		//alert(p30);
		p30=p30+")"
		p31=p.substring(4,l30);
		pp=p30+p31;
		//alert(p31);
		document.emailSend.phone.value="";
		document.emailSend.phone.value=pp;
	}
	}
if(p.length>5){
	p11=p.substring(d1+1,d2);
	if(p11.length>3){
	p12=p11;
	l12=p12.length;
	l15=p.length
	//l12=l12-3
	p13=p11.substring(0,3);
	p14=p11.substring(3,l12);
	p15=p.substring(d2+1,l15);
	document.emailSend.phone.value="";
	pp="("+p13+")"+p14+p15;
	document.emailSend.phone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
	l16=p.length;
	p16=p.substring(d2+1,l16);
	l17=p16.length;
	if(l17>3&&p16.indexOf('-')==-1){
		p17=p.substring(d2+1,d2+4);
		p18=p.substring(d2+4,l16);
		p19=p.substring(0,d2+1);
		//alert(p19);
	pp=p19+p17+"-"+p18;
	document.emailSend.phone.value="";
	document.emailSend.phone.value=pp;
	//obj1.value="";
	//obj1.value=pp;
	}
}
//}
setTimeout(ValidatePhone,1000)
}
function getIt(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
}
function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
}
}
/* End Phone Check Functions *****************************************************************************************/

