//sniffer
function Is() {
  var agent = navigator.userAgent.toLowerCase();
  var is_major = parseInt(navigator.appVersion);
  var is_minor = parseFloat(navigator.appVersion);
  this.ns = (agent.indexOf('mozilla')!=-1) && (agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1) && (is_major < 5) && (agent.indexOf('firefox')==-1);
  this.ie = (agent.indexOf("msie") != -1);
  this.dom = ((agent.indexOf('mozilla')!=-1) && (agent.indexOf('gecko') != -1) && (is_major >= 5)) || (agent.indexOf('firefox')!=-1);
}

var is = new Is();

//form styles
function formLight(formField){
	formField.style.backgroundColor='#D2BC8A';
}
function formFade(formField) {
	formField.style.backgroundColor='#FFFFFF';
}

//hover cell styles for drop downs
function changeColor(thisID, colorNum){
	thisID.style.backgroundColor=colorNum;
	//stupid netscape
	thisID.bgColor=colorNum;
}
//highlight form areas orange if there's an error
function alertLayer(divID, colorNum) {
	if(is.ie) {
		document.all[divID].style.backgroundColor = colorNum;
	} else if(is.ns) {
		//stupid netscape
		divID.bgColor=colorNum;
	} else {
		document.getElementById(divID).style.backgroundColor = colorNum;
	}
}

//popup
function popupPage(varPage,ht,wd){
	window.open(varPage,'popup', "height=" + ht + ",width=" + wd + ",left=100,top=100,scrollbars=yes,menubars=no,toolbars=no,resizable=yes");
}



//drop down menus
var loaded = 0;

function itBegins(){
        loaded = 1;		
}

function dropEm(ddnum){
	document.getElementById('dropdowna'+ddnum).style.visibility = 'visible';
	document.getElementById('dropdown'+ddnum).style.visibility = 'visible';
	document.getElementById('hideEm').style.visibility = 'visible';
}

function hideEmAll(){
	var i = 0;
	for (i=0;i<=3;i++) {
		document.getElementById('dropdowna'+i).style.visibility = 'hidden';
		document.getElementById('dropdown'+i).style.visibility = 'hidden';
		document.getElementById('hideEm').style.visibility = 'hidden';
	}
}



//portfolio
function changePage(whichNum) {
	if(maxPages > 1) {
		//hide current page
		document['btn'+currentPage].src = '/design/images/btn'+currentPage+'.gif';
		document.getElementById('port'+currentPage).style.visibility = 'hidden';
		//determine new page
		if(whichNum == 'back') {
			//move back
			if(pageType == "portfolio") {
				currentPage = (pageSection * 5)-4;
			}
			if(currentPage - 1 < 1) {
				currentPage = maxPages + 1;
			}
			currentPage = currentPage - 1;
		} else if(whichNum == 'next') {
			//move next
			if(pageType == "portfolio") {
				currentPage = pageSection * 5;
			}
			if(currentPage + 1 > maxPages) {
				currentPage = 0;
			}
			currentPage = currentPage + 1;
		} else {
			//move specific
			if(whichNum > maxPages) {
				currentPage = maxPages;
			} else if(whichNum < 1) {
				currentPage = 1;
			} else {
				currentPage = whichNum;
			}
		}
		//change section if appropriate
		if(pageSection == 1 && currentPage > 5) {
			document.getElementById('section'+pageSection).style.visibility = 'hidden';
			if(currentPage > 15) {
				pageSection = 4;
			} else if(currentPage > 10) {
				pageSection = 3;
			} else {
				pageSection = 2;
			}
		} else if(pageSection == 2 && (currentPage < 6 || currentPage > 10)){
			document.getElementById('section'+pageSection).style.visibility = 'hidden';
			if(currentPage > 15) {
				pageSection = 4;
			} else if(currentPage > 10) {
				pageSection = 3;
			} else {
				pageSection = 1;
			}
		} else if(pageSection == 3 && (currentPage < 11 || currentPage > 15)){
			document.getElementById('section'+pageSection).style.visibility = 'hidden';
			if(currentPage > 15) {
				pageSection = 4;
			} else if(currentPage > 5) {
				pageSection = 2;
			} else {
				pageSection = 1;
			}
		} else if(pageSection == 4 && currentPage < 16){
			document.getElementById('section'+pageSection).style.visibility = 'hidden';
			if(currentPage > 10) {
				pageSection = 3;
			} else if(currentPage > 5) {
				pageSection = 2;
			} else {
				pageSection = 1;
			}
		}
		//show new page
		document['btn'+currentPage].src = '/design/images/btn'+currentPage+'_over.gif';
		document.getElementById('section'+pageSection).style.visibility = 'visible';
		//alert("page=" + currentPage + "; section=" + pageSection);
	}
	document.getElementById('port'+currentPage).style.visibility = 'visible';
	if(pageType == "portfolio") {
		document.portfolio.src = "/design/port/" + whichPage + currentPage + ".jpg";
	}
}


//forms
var emailRE = /^\w+([-|\.]\w+)*@\w+([-|\.]\w+)*\.\w+(-*\w+)*$/;
var phoneRE = /^(((\+| \+ )?[0-9]{1,3}(-| )?\(?[0-9]{1,3}\)?(-| )?[0-9]{1,5})|(\(?[0-9]{2,6}\)?))(-| )?([0-9]{2,4})(-| )?([0-9]{4,5})(( \w{1,3}| \w{1,3} )[0-9]{1,5}){0,1}$/;
function validate(thisForm) {
	with(thisForm) {
		var contactType = 0;
		if (contact[1].checked == true) {
			contactType = 1;
			}
		if (contact[2].checked == true) {
			contactType = 2;
			}
		if (contact[0].checked == true || contact[1].checked == true || contact[2].checked == true) {
			if(!is.ns) alertLayer('prefcontact','#FFFFFF');
		}
		if (firstName.value == " " || firstName.value == "") {
			document.getElementById("doError").innerHTML = "Please enter your first name.";
			document.getElementById("doError").style.display = "block";
			firstName.focus();
			return false;
		} else if (lastName.value == " " || lastName.value == "") {
			document.getElementById("doError").innerHTML = "Please enter your last name.";
			document.getElementById("doError").style.display = "block";
			lastName.focus();
			return false;
		} else if (contact[0].checked == false && contact[1].checked == false && contact[2].checked == false) {
			document.getElementById("doError").innerHTML = "Please choose how you'd prefer us to contact you.";
			document.getElementById("doError").style.display = "block";
			if(!is.ns) alertLayer('prefcontact','#D2BC8A');
			return false;
		} else if (email.value == "" || !emailRE.test(email.value)) {
			document.getElementById("doError").innerHTML = "Please enter a valid email address.";
			document.getElementById("doError").style.display = "block";
			email.focus();
			return false;
		} else if (!phoneRE.test(phone.value) && phone.value != '') {
			document.getElementById("doError").innerHTML = "Please enter a valid phone number including area code.";
			document.getElementById("doError").style.display = "block";
			phoneArea.focus();
			return false;
		} else if (!phoneRE.test(fax.value) && fax.value != '') {
			document.getElementById("doError").innerHTML = "Please enter a valid fax number including area code.";
			document.getElementById("doError").style.display = "block";
			faxArea.focus();
			return false;
		} else if (comments.value.length < 5) {
			document.getElementById("doError").innerHTML = "Please type in your comment or project information.";
			document.getElementById("doError").style.display = "block";
			comments.focus();
			return false;
		} else if (verifycode.value.length < 5) {
			document.getElementById("doError").innerHTML = "Please enter the verify code.";
			document.getElementById("doError").style.display = "block";
			verifycode.focus();
			return false;
		} else if (verifycode.value != verifycheck.value) {
			document.getElementById("doError").innerHTML = "Please check that the verify code you entered is correct.";
			document.getElementById("doError").style.display = "block";
			verifycode.focus();
			return false;
		} else {
			document.getElementById("doError").style.display = "none";
			Submitted.value = "1";
			return true;
		}
	}
}
