// JavaScript Document

function copyDataN1(){
var name1 = document.phoneContact.namePhone.value;
document.emailContact.nameEmail.value = name1;
}
function copyDataN2(){
var name2 = document.emailContact.nameEmail.value;
document.phoneContact.namePhone.value = name2;
}
function copyDataP1(){
var phone1 = document.phoneContact.phoneNum.value;
document.emailContact.phoneNumEmail.value = phone1;
}
function copyDataP2(){
var phone2 = document.emailContact.phoneNumEmail.value;
document.emailContact.phoneNumEmail.value = phone2;
}
function copyDataD1(){
var desc1 = document.phoneContact.callTopic.value;
document.emailContact.emailTopic.value = desc1;
}
function copyDataD2(){
var desc2 = document.emailContact.emailTopic.value;
document.phoneContact.callTopic.value = desc2;
}
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
} 
function checkEmail(emailFld){
	var email = trim(emailFld.value);
	
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	if(!emailFilter.test(email)){
		emailFld.style.border = '1px solid Red';
		emailFld.focus();
		alert("Please enter a valid email address");
	}else if(emailFld.value.match(illegalChars)){
		emailFld.style.border = '1px solid Red';
		emailFld.focus();
		alert("Please enter a valid email address");
	}else{
		emailFld.style.border = '1px solid #666666';
		if(document.emailContact.emailAddress1.value == document.emailContact.emailAddress2.value){
		document.phoneContact.phoneEmail.value = document.emailContact.emailAddress2.value;
		}
	}
}

function checkPhone(phoneFld){
	var stripped = phoneFld.value.replace(/[\(\)\.\-\ ]/g, '');
	
	if (isNaN(parseInt(stripped))) {
        phoneFld.style.border = '1px solid Red';
		alert("This phone number contains illegal characters");
    } else if (!(stripped.length == 10)) {
		phoneFld.style.border = '1px solid Red';
        alert("Your phone number is the wrong length. Make sure to included your area code");

    } 
}

function sendPhone(){
	var name = trim(document.phoneContact.namePhone.value);
	var stripped = document.phoneContact.phoneNum.value.replace(/[\(\)\.\-\ ]/g, '');
	var error = 0;
	
	// check name
	if(name == ""){
		document.phoneContact.namePhone.style.border = '1px solid Red';
		document.phoneContact.namePhone.focus();
		error = 1;
		alert("Please enter your name");
	}else {
		document.phoneContact.namePhone.style.border = '1px solid #666666';
	}
	
	//check phone
	if(error == 0){
		//alert ("stripped - "+stripped+" parseint - "+parseInt(stripped)+" isNaN - "+isNaN(stripped));
		//alert("stripped - "+stripped+" ("+substr(stripped,1, 3)+")"+substr(stripped, 3, 3)+"-"+substr(stripped, 6,4));
		if (document.phoneContact.phoneNum.value == ""){
			document.phoneContact.phoneNum.style.border = '1px solid Red';
			document.phoneContact.phoneNum.focus();
			error = 1;
        	alert("Please enter your phone number");
		}else if (isNaN(stripped)) {
        	document.phoneContact.phoneNum.style.border = '1px solid Red';
			document.phoneContact.phoneNum.focus();
			error = 1;
			alert("This phone number contains illegal characters");
		}else if (!(stripped.length == 10)) {
			document.phoneContact.phoneNum.style.border = '1px solid Red';
			document.phoneContact.phoneNum.focus();
			error = 1;
        	alert("Your phone number is the wrong length. Make sure to included your area code");
    	}else {
			document.phoneContact.phoneNum.style.border = '1px solid #666666';
			
		}
	}
	
	// check topic
	if(error == 0){
		if(document.phoneContact.callTopic.value == ""){
			document.phoneContact.callTopic.style.border = '1px solid Red';
			document.phoneContact.callTopic.focus();
			error = 1;
			alert("Please let me know how I can help you");
		}else {
			document.phoneContact.callTopic.style.border = '1px solid #666666';
		}
	}
	
	
	if(error == 0){
	// submit	
		//alert("submited - error:"+error);
		document.phoneContact.submit();
	}
	
}

function sendEmail(){
	var email1 = trim(document.emailContact.emailAddress1.value);
	var email2 = trim(document.emailContact.emailAddress2.value);
	var name = trim(document.emailContact.nameEmail.value);
	var error = 0;
	
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	
	// check name
	if(name == ""){
		document.emailContact.nameEmail.style.border = '1px solid Red';
		document.emailContact.nameEmail.focus();
		error = 1;
		alert("Please enter your name");
	}else {
		document.emailContact.nameEmail.style.border = '1px solid #666666';
	}
	
	// check email
	if (error == 0){
		if(email1 == ""){
			document.emailContact.emailAddress1.style.border = '1px solid Red';
			document.emailContact.emailAddress1.focus();
			error = 1;
			alert("Please enter your email address");
		}else if(email2 == ""){
			document.emailContact.emailAddress2.style.border = '1px solid Red';
			document.emailContact.emailAddress2.focus();
			error = 1;
			alert("Please confirm your email address");
		}else if(!emailFilter.test(email1)){
			document.emailContact.emailAddress1.style.border = '1px solid Red';
			document.emailContact.emailAddress1.focus();
			error = 1;
			alert("Please enter a valid email address");
		}else if(!emailFilter.test(email2)){
			document.emailContact.emailAddress2.style.border = '1px solid Red';
			document.emailContact.emailAddress2.focus();
			error = 1;
			alert("Please enter a valid email address");
		}else if(email1.match(illegalChars)){
			document.emailContact.emailAddress1.style.border = '1px solid Red';
			document.emailContact.emailAddress1.focus();
			error =1;
			alert("Please enter a valid email address");
		}else if(email2.match(illegalChars)){
			document.emailContact.emailAddress2.style.border = '1px solid Red';
			document.emailContact.emailAddress2.focus();
			error =1;
			alert("Please enter a valid email address");
		}else if(email1 != email2){
			document.emailContact.emailAddress1.style.border = '1px solid Red';
			document.emailContact.emailAddress2.style.border = '1px solid Red';
			document.emailContact.emailAddress1.focus();
			error = 1;
			alert("Your email addresses do not match");
		}else {
			document.emailContact.emailAddress1.style.border = '1px solid #666666';
			document.emailContact.emailAddress2.style.border = '1px solid #666666';
		}
	}
	
	if(error == 0){
		if(document.emailContact.emailTopic.value == ""){
			document.emailContact.emailTopic.style.border = '1px solid Red';
			document.emailContact.emailTopic.focus();
			error = 1;
			alert("Please let me know how I can help you");
		}else {
			document.emailContact.emailTopic.style.border = '1px solid #666666';
		}
	}
	
	if(error == 0){
	// submit	
	//alert("submited");
	document.emailContact.submit();
	}
}




function LoademUp(){
fluidLayers('main','200','200','auto','auto',0,0,0,0); 
fluidLayers('left-sidebar','0','200','auto','auto',0,0,0,0);
fluidLayers('right-sidebar','750','200','auto','auto',0,0,0,0);
fluidLayers('blog-header','0','0','auto','200',0,0,0,0);
fluidLayers('header-text','420','0','480','200',0,0,0,0);
fluidLayers('header-jesse-info','15','195','870','15',0,0,0,0);
fluidLayers('top-bar','0','198','auto','12',0,0,0,0);
fluidLayers('header-car','0','0','458','200',0,0,0,0);
Flashover();
}


// layer name, left, top, width, height (these are numbers or the word 'auto')
// then, left margin, right margin, top margin, bottom margin
function fluidLayers(el,lp,tp,wp,hp,lm,rm,tm,bm) { 
	var x,g,d,sw,sh,xx,yy,ww,hh,pa='',t="','",u=",";
	var ns4 = (document.layers) ? true:false ;
	var ie4 = (document.all) ? true:false;
	var ng5 = (document.getElementById) ? true:false; 
	if((g=MM_findObj(el))==null){return;}
	if((parseInt(navigator.appVersion)>4 || navigator.userAgent.indexOf("MSIE")>-1)&& !window.opera){pa="px";}
	var tS="fluidLayers('"+el+t+lp+t+tp+t+wp+t+hp+"',"+lm+u+rm+u+tm+u+bm+")";
	if(window.innerWidth) {sw= window.innerWidth;sh = window.innerHeight;
	}else if(document.body) {sw=document.body.clientWidth;sh=document.body.clientHeight;
    if(document.body.offsetWidth == sw && document.documentElement && document.documentElement.clientWidth) {
	 sw=document.documentElement.clientWidth;}
    if(document.body.offsetHeight == sh && document.documentElement && document.documentElement.clientHeight) {
     sh=document.documentElement.clientHeight;}}
	if(!g.fluid) {g.fluid=true;g.fluidw=0;g.fluidh=0;}
	if(sw==g.fluidw && sh==g.fluidh) {setTimeout(tS,750);return;}
	d=(document.layers)?g:g.style;
	if(wp=='auto') {if(lp=='auto'){ww=sw-lm-rm;}else{ww=sw-lp-rm;}}else{ww=wp;}
	if(hp=='auto') {if(tp=='auto'){hh=sh-tm-bm;}else{hh=sh-tp-bm;}}else{hh=hp;}
	if(lp=='auto') {if(wp=='auto'){xx=lm;}else{xx=sw-wp-rm;}}else{xx=lp;}
	if(tp=='auto') {if(hp=='auto'){yy=tm;}else{yy=sh-tp-bm;}}else{yy=tp;}
	
	var ls_ww = 150;
	var rs_ww = 200;
	
	if(sw>=1000){
		
	var ls_xx = 15;
	
	var m_ww = (sw-ls_xx-ls_ww-rs_ww-65);
	if(m_ww>=800){
	m_ww=800;	
	}
	var m_xx = ((sw/2)-(m_ww/2));
	if(m_xx<='150'){
	m_xx=150;	
	}
	ls_xx = (m_xx-15-ls_ww);
	if(ls_xx<=15){
	ls_xx = 15;	
	}
	var rs_xx=m_ww+m_xx+15;
	if(rs_xx>=(sw-rs_ww-15)){
	rs_xx = (sw-rs_ww-15);	
	}
	}else{
	var ls_xx = 15;
	var m_ww = 617;
	var m_xx = 182.5;
	var rs_xx = 799;
	}
	
	
	if(el == 'left-sidebar'){
	ww=ls_ww;
	xx=ls_xx;
	}
	if(el == 'main'){
	ww=m_ww;
	xx=m_xx;
	}
	if(el == 'right-sidebar'){
	ww=rs_ww;
	xx=rs_xx;
	hh=1500;
	}
	
	if(el == 'header-text'){
	if(sw>=1000){
		xx=.42308*sw+39.23;
	}
	}
	if(el == 'header-jesse-info'){
		if(sw>=1000){
	ww = .3846*sw+554;
	hh = .00641*sw+8.23;
	yy = -.002564*sw+198.31;
	xx = (sw/2)-(ww/2);
	vv = 12;
	document.getElementById('header-jesse-info').style.fontSize = vv+'px';
		}else{
	ww = 900.14;
	hh = 14;
	yy = 196;
	xx = 1;
	vv = 12;
	document.getElementById('header-jesse-info').style.fontSize = vv+'px';	
		}
	}
	if(el == 'top-bar'){
	if(sw>=1000){
	ww=sw;
	}else{
	ww=1000;	
	}
	}
	if(el == 'blog-header'){
	if(sw>1000){
	//ww=sw-14;	
	}else{
	ww=1000;	
	}
	
	}
	
	d.left=xx+pa;d.top=yy+pa;
	if(document.layers){g.clip.height=hh;g.clip.width=ww;
	}else if(window.opera){g.style.pixelHeight=hh;g.style.pixelWidth=ww;
	}else{d.width=ww+pa;d.height=hh+pa;}
	g.fluidw=sw;g.fluidh=sh;
	setTimeout(tS,750);
}

function MM_reloadPage(init) {  //Updated by PVII. Reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) history.go(0);
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function Flashover(){
//theObjects = document.getElementsByTagName("object");
//for (var i = 0; i < theObjects.length; i++) {
//theObjects[i].outerHTML = theObjects[i].outerHTML;
//}

n=navigator.userAgent;
w=n.indexOf("MSIE");
if((w>0)&&(parseInt(n.charAt(w+5))>5)){
T=["object","embed","applet"];
for(j=0;j<2;j++){
E=document.getElementsByTagName(T[j]);
for(i=0;i<E.length;i++){
P=E[i].parentNode;
H=P.innerHTML;
P.removeChild(E[i]);
P.innerHTML=H;
}}}
}


