var uagent = navigator.userAgent.toLowerCase();
var illegalChars = /[\W_]/; // allow only letters and numbers
var nospaces = /^\s+|\s+$/g; //remove all spaces
var onlynumbers = /[\(\)\.\-\ a-z]/g; //only numbers
function openportfolio(ptype) {
	//eval("page" + id + " = window.open('portfolio.php?ptype="+ptype+"', 'pop_" + ptype + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=410');");
	w=600;
	h=410;
	var wleft = (screen.width - w) / 2;
	var wtop = (screen.height - h) / 2;
	var url = "portfolio29f9.html?ptype="+ptype;
	var name = "pop_" + ptype;
	/*if (window.showModalDialog) {
		var win = window.showModalDialog(url,name,
				"dialogWidth:"+w+"px,dialogHeight:"+h+"px,"+
				"width="+w+",height="+h+","+
				"left="+wleft+",top="+wtop+","+
				"location=no,menubar=no,"+
				"modal=yes,dialog=yes,"+
				"status=no,toolbar=no,scrollbars=no,resizable=no");
	}
	else {*/
		var win = window.open(url,name,'width=' + w + ', height=' + h + ', ' +
				'left=' + wleft + ', top=' + wtop + ', ' +
				'location=no, menubar=no, ' +
				'modal=yes,dialog=yes,' +
				'status=no, toolbar=no, scrollbars=no, resizable=no');
		win.resizeTo(w, h);
	//}
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
var themain;
var theportfolio;
function showportfolio() {
	themain = document.getElementById("container");
	//if (uagent.indexOf("safari") == -1) setopacity(themain,0);
	themain.style.visibility = "hidden";
	themain.style.display = "none";
	//var wleft = (window.width - 600) / 2;
	//var wtop = (window.height - 410) / 2;
	theportfolio = document.getElementById("portfolio");
	/*if (uagent.indexOf("safari") == -1) for (var i=7;i<=10;i++) {
		setopacity(theportfolio,0);
		for (var i=7;i<=10;i++) {
			if (i == 8) {
				setTimeout('theportfolio.style.visibility = "visible"',(i));
				setTimeout('theportfolio.style.display = "block"',(i));
			}
			setTimeout('setopacity(theportfolio,'+(i*10)+')',(30*i));
		}
	}*/
	theportfolio.style.visibility = "visible";
	theportfolio.style.display = "block";
	//theportfolio.offsetX = themain.offsetX;
	//theportfolio.style.left = wleft+"px";
	//theportfolio.style.top = wtop+"px";
}
function hideportfolio() {
	themain = document.getElementById("container");
	//if (uagent.indexOf("safari") == -1) setopacity(themain,100);
	themain.style.visibility = "visible";
	themain.style.display = "block";
	theportfolio = document.getElementById("portfolio");
	theportfolio.style.visibility = "hidden";
	theportfolio.style.display = "none";
}
function validateemail (email) {
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(email))) { 
	   alert("'"+email+"' is an Invalid Email Address");
	   return false;
	}
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
	if (email.match(illegalChars) && error == "") {
	   alert("'"+email+"' Contains Illegal Characters");
	   return false;
	}
	else {
		return true;
	}
}
function validatecontact() {
	thename = document.getElementById("name").value;
	thephone = document.getElementById("phone1").value+document.getElementById("phone2").value+document.getElementById("phone3").value;
	theemail = document.getElementById("email").value;
	theemail2 = document.getElementById("email2").value;
	themessage = document.getElementById("message").value;
	
	var message = "";
	
	if (thename.replace(nospaces, "") == "") {
		alert("You Must Include Your Name.");
		return false;
	}
	if (thephone.replace(nospaces, "") == "") {
		alert("You Must Include Your Phone Number.");
		return false;
	}
	if (!validateemail(theemail)) {
		return false;
	}
	if (theemail != theemail2) {
		alert("You Must Confirm Your Email Address.");
		return false;
	}
	if (themessage.replace(nospaces, "") == "") {
		alert("You Must Include A Message.");
		return false;
	}
	return true;
}
function setopacity(theelement,value) {
	if (uagent.indexOf("msie") != -1) theelement.style.filter = 'alpha(opacity=' + (value==100?210:value) + ')'; //internet explorer
	else theelement.style.opacity = value/100; //everything else
}