// JavaScript Document

function clearValue(element) {
	if (element.id == 'cf-name' && element.value == 'name:') {
		element.value='';
	}else if (element.id == 'cf-email' && element.value == 'email:') {
		element.value='';
	}else if (element.id == 'cf-phone' && element.value == 'phone:') {
		element.value='';
	}else if (element.id == 'cf-message' && (element.value == 'message:' && element.innerHTML == 'message:')) {
		element.innerHTML='';
		element.value='';
	}else{
	}
}

function setValue(element) {
	if (element.id == 'cf-name' && element.value == '') {
		element.value='name:';
	}else if (element.id == 'cf-email' && element.value == '') {
		element.value='email:';
	}else if (element.id == 'cf-phone' && element.value == '') {
		element.value='phone:';
	}else if (element.id == 'cf-message' && (element.value == '' && element.innerHTML == '')) {
		element.value='message:';
		element.innerHTML='message:';
	}else{
	}
}

function checkForm(form) {
	var count = form.elements.length;
	var msg = '';

	for (i=0; i<count; i++) {
		element = form.elements[i];
		
		//name textfield
		if (element.id == 'cf-name' && (element.value == '' || element.value == 'name:')) {
			msg += 'Please Enter your Name<br />';
			element.style.backgroundColor = '#A80000';
			
		//email textfield
		}else if (element.id == 'cf-email' && (element.value == '' || element.value == 'email:')) {
			msg += 'Please Enter your Email Address<br />';
			element.style.backgroundColor = '#A80000';
		}else if (element.id == 'cf-email' && (element.value != '' && element.value != 'email:')) {
			if (!checkEmail(element.value)) {
				msg += 'Please Enter a <strong>Valid</strong> Email Address<br />';
				element.style.backgroundColor = '#A80000';
			}else{
				element.style.backgroundColor = '';
			}
			
		//phone textfield
		}else if (element.id == 'cf-phone' && (element.value == '' || element.value == 'phone:')) {
			msg += 'Please Enter your Phone Number<br />';
			element.style.backgroundColor = '#A80000';
		}else if (element.id == 'cf-phone' && (element.value != '' && element.value != 'phone:')) {
			if (!checkPhoneNum(element.value)) {
				msg += 'Please Enter a <strong>Valid</strong> Phone Number<br />';
				element.style.backgroundColor = '#A80000';
			}else{
				element.style.backgroundColor = '';
			}
		//message textarea
		}else if (element.id == 'cf-message' && ((element.value == '' || element.value == 'message:') && (element.innerHTML == '' || element.innerHTML == 'message:'))) {
			msg += 'Please Enter a Message<br />';
			element.style.backgroundColor = '#A80000';
		}else{
			if (element.type != 'submit') {
				element.style.backgroundColor = '';
			}
		}
	}
	if (msg != '') {
		document.getElementById('error').innerHTML = msg;
		return false;
	}else{
		document.getElementById('error').innerHTML = '';
		return true;
	}
}

//Checks for a valid email address
function checkEmail(email) {
	var regexp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z0-9])+$/;
	return regexp.test(email);
}

//Checks that value contains only numerical digits.
function checkForDigits(num) {
	var regexp = /^[\d .\(\)\+-]+$/;
	return regexp.test(num);
}

//Checks that value contains only numerical digits.
function checkPhoneNum(num) {
	var regexp = /^(\(\d+\))?([\+\d+])?([\d .-])+$/;
	return regexp.test(num);
}



/* Basic Web Functions */
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
	var i,x,a=document.MM_sr; 
	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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 MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; 
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; 
	if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function basicPopup(url,w,h,top,left) {
	self.name = "main";
	pagewindow = window.open(url,"page","width=" + w + ",height=" + h + ",top=" + top + ",left=" + left + ",toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
}

function resize(div1,div2,div3){
	//alert("resize"+div1+div2+div3);
	var frame1 = document.getElementById(div1); 
	var frame2 = document.getElementById(div2); 
	var frame3 = document.getElementById(div3); 
	var windowheight = pageHeight();
	var xxx = getPanelDir();

	if (xxx == "up") {
		frame1.style.height = windowheight - 290 + "px";
		frame2.style.height = windowheight - 290 + "px";
		frame3.style.height = windowheight - 290 + "px";
	} else if (xxx == "down") {
		frame1.style.height = windowheight - 456 + "px";
		frame2.style.height = windowheight - 456 + "px";
		frame3.style.height = windowheight - 456 + "px";
	} else {
		frame1.style.height = windowheight - 456 + "px";
		frame2.style.height = windowheight - 456 + "px";
		frame3.style.height = windowheight - 456 + "px";
	}
	init_dw_Scroll();
} 

function changeTitle (page) {
	html = '';
	if (page == "about") {
		html += '<div id="sub-menu">';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'about-multimedia.php\'); return false;">multimedia experience</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'about-swimming.php\'); return false;">swimming</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'about-other-interests.php\'); return false;">other interests</a>' + '\n';
		html += '</div>' + '\n';
	} else if (page == "resume") {
		html += '<div id="sub-menu">';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'resume-goals-skills.php\'); return false;">goals &amp; skills</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'resume-education.php\'); return false;">education</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'resume-employment.php\'); return false;">employment</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'resume-achievements.php\'); return false;">achievements</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'resume-referees.php\'); return false;">referees</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="resume-pdf.php" rel="width=800;" title="resume pdf" onclick="Shadowbox.open(this); return false;" >pdf</a>' + '\n';
		//html += '	<span class="bText3">+</span> <a href="" onclick="basicPopup(\'../media/docs/Stephen_Green_Resume.pdf\',800,600,100,100)" >pdf</a>' + '\n';
		html += '</div>' + '\n';
	} else if (page == "") {
		html += '<div id="sub-menu">';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'web-sites.php\'); return false;">sites</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'web-technologies.php\'); return false;">technologies</a>&nbsp;&nbsp;' + '\n';
		html += '</div>' + '\n';
	} else if (page == "") {
		html += '<div id="sub-menu">';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'flash-sites.php\'); return false;">sites</a>&nbsp;&nbsp;' + '\n';
		html += '	<span class="bText3">+</span> <a href="" onclick="get_content(\'flash-assignments.php\'); return false;">assignments</a>&nbsp;&nbsp;' + '\n';
		html += '</div>' + '\n';
	} else {
	}
	html += '<img src="../media/images/title-' + page + '.jpg" alt="' + page + '" title="' + page + '" class="titleImage" />';
	document.getElementById('title').innerHTML = html;
}
function pageHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myHeight;
}
function pageWidth() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
  return myWidth;
}
