function getAnchorPosition(anchorname){var useWindow=false;var coordinates=new Object();var x=0,y=0;var use_gebi=false, use_css=false, use_layers=false;if(document.getElementById){use_gebi=true;}else if(document.all){use_css=true;}else if(document.layers){use_layers=true;}if(use_gebi && document.all){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_gebi){var o=document.getElementById(anchorname);x=AnchorPosition_getPageOffsetLeft(o);y=AnchorPosition_getPageOffsetTop(o);}else if(use_css){x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);}else if(use_layers){var found=0;for(var i=0;i<document.anchors.length;i++){if(document.anchors[i].name==anchorname){found=1;break;}}if(found==0){coordinates.x=0;coordinates.y=0;return coordinates;}x=document.anchors[i].x;y=document.anchors[i].y;}else{coordinates.x=0;coordinates.y=0;return coordinates;}coordinates.x=x;coordinates.y=y;return coordinates;}
function getAnchorWindowPosition(anchorname){var coordinates=getAnchorPosition(anchorname);var x=0;var y=0;if(document.getElementById){if(isNaN(window.screenX)){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else{x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}}else if(document.all){x=coordinates.x-document.body.scrollLeft+window.screenLeft;y=coordinates.y-document.body.scrollTop+window.screenTop;}else if(document.layers){x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;}coordinates.x=x;coordinates.y=y;return coordinates;}
function AnchorPosition_getPageOffsetLeft(el){var ol=el.offsetLeft;while((el=el.offsetParent) != null){ol += el.offsetLeft;}return ol;}
function AnchorPosition_getWindowOffsetLeft(el){return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;}
function AnchorPosition_getPageOffsetTop(el){var ot=el.offsetTop;while((el=el.offsetParent) != null){ot += el.offsetTop;}return ot;}
function AnchorPosition_getWindowOffsetTop(el){return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;}

function getElementsByClassName(classname, node)  {    if(!node) node = document.getElementsByTagName("body")[0];    var a = [];    var re = new RegExp('\\b' + classname + '\\b');    var els = node.getElementsByTagName("*");    for(var i=0,j=els.length; i<j; i++)        if(re.test(els[i].className))a.push(els[i]);    return a;}

function clearField(element, value){
	if(element.value == value)
		element.value="";
}
var arImages = new Array();
var arText = new Array();
var currentImage = 0;
var grey_left;
var grey_right;
var orange_left;
var orange_right;
function preload_officeimages(){
	
	var im;
	for(var i=0; i<20; i++){
		im = new Image();
		im.src = "images/office/" + (i+1) + ".jpg";
		arImages[i] = im;
	}
	grey_left = new Image();
	grey_left.src = "images/lft_mv_icon_gray.gif";
	grey_right= new Image();
	grey_right.src = "images/rgt_mv_icon_gray.gif";
	orange_left= new Image();
	orange_left.src = "images/lft_mv_icon_orange.gif";
	orange_right= new Image();
	orange_right.src = "images/rgt_mv_icon_orange.gif";
	
	arText[0] = "Biscuit or iPod?";
	arText[1] = "Our floor: some people love it, others say, “so, ahem, what are you going to do about this floor?”";
	arText[2] = "We take our tea selection very seriously.";
	arText[3] = "We read books so that you don’t have to. Sometimes we even read the same book twice.";
	arText[4] = "Some of our computers are pink.";
	arText[5] = "We enjoy a variety of seating options.";
	arText[6] = "Gotcha!  We are still in the office, not in a forest.";
	arText[7] = "This ladder would come in handy if we had office bunk beds.";
	arText[8] = "Things to pack for work: tank top and parka.";
	arText[9] = "“Getting Sleep Done.” Someone’s gotta do it.";
	arText[10] = "In our office wall space is in high demand.";
	arText[11] = "Ridiculously yummy.  Also, ridiculously gone in a few minutes. (Yes, we bought them today.)";
	arText[12] = "One of these people is not like the others…";
	arText[13] = "Door knobs forever (I).";
	arText[14] = "Door knobs forever (II).";
	arText[15] = "We’re number 1! ...in local competitions.";
	arText[16] = "We accept cash, credit cards, or dark chocolate.";
	arText[17] = "Industrial lighting helps set the mood for wireframing.";
	arText[18] = "When computers become smarter than people, will they have feelings too?";
	arText[19] = "Who knew that red and blue would make great colors for a desk?";
	
	
	
}

function rolloverImages_old(sign){
	var elementLeftArrow  = document.getElementById('leftArrow');
	var elementRightArrow = document.getElementById('rightArrow');
	if(currentImage == 0 && sign < 0){
		return;
	}
	if(currentImage == 19 && sign > 0){
		return;
	}
	currentImage = currentImage + sign;
	if(currentImage > 19){
		currentImage = 0;
	}
	if(currentImage < 0){
		currentImage = 0;
	}
	document.getElementById('imgOffice').src = arImages[currentImage].src;
	document.getElementById('txtOffice').innerHTML = arText[currentImage];
	if(currentImage == 0){
		elementLeftArrow.src = grey_left.src;
	}else {
		elementLeftArrow.src = orange_left.src;
	}
	if(currentImage == 19){
		elementRightArrow.src = grey_right.src;
	}else {
		elementRightArrow.src = orange_right.src;
	}
	
	return;
	if(currentImage == 0){
		elementLeftArrow.src = grey_left.src;
		elementLeftArrow.onclick = null;
	}else{
		elementLeftArrow.src = orange_left.src;
		try {
			if (window.attachEvent) {
	      		elementLeftArrow.attachEvent("onclick",rolloverImages(-1));
	   		} 
	   		else if (window.addEventListener) {
	      		elementLeftArrow.addEventListener("onclick",rolloverImages(-1),false);
	   		}
		}catch (exception ){
		
		}
	}
	
	if(currentImage == 19){
		elementRightArrow.src = grey_right.src;
		elementRightArrow.onclick = null;
	}else{
		elementRightArrow.src = orange_right.src;
		try {
			if (window.attachEvent) {
	      		elementRightArrow.attachEvent("onclick",rolloverImages(1));
	   		} 
	   		else if (window.addEventListener) {
	      		elementRightArrow.addEventListener("onclick",rolloverImages(1),false);
	   		}
		}catch (exception ){
			alert(exception);
		}
	}
}
function rolloverImages(sign){
	currentImage = currentImage + sign;
	if(currentImage > 19){
		currentImage = 0;
	}
	if(currentImage < 0){
		currentImage = 19;
	}
	document.getElementById('imgOffice').src = arImages[currentImage].src;
	document.getElementById('txtOffice').innerHTML = arText[currentImage];
	return;
}

	var emailType = "";
	function postRequest(strURL, type)
	{
		var xmlHttp;
		if (window.XMLHttpRequest){
			 xmlHttp = new XMLHttpRequest();
		} else if (window.ActiveXObject){ 
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		xmlHttp.open('GET', strURL, true);
		xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		emailType = type;
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4)
			{
				updatepage(xmlHttp.responseText);
			}
		}
		xmlHttp.send(strURL);
	}
	
	function updatepage(str)
	{
		//document.getElementById("result").innerHTML = 	"<font color='red' size='5'>" + str + "</font>";
		if(emailType == 'ask'){
			document.getElementById('askMain').style.display = 'none';
			document.getElementById('askSuccess').style.display = 'block';
		}else {
			document.getElementById('notesMain').style.display = 'none';
			document.getElementById('notesSuccess').style.display = 'block';
		}
		emailType = "";
	}
	
	
	function sendEmail(type){
		var email;
		var body;
		var maxMsg = 200;
		if(type == 'ask'){
			email = document.getElementById('txtAsk');
			msg = document.getElementById('txtAreaAsk');
			document.getElementById('loadingImg1').style.display = 'block';
		}else {
			email = document.getElementById('txtNotes');
			msg = document.getElementById('txtAreaNotes');
			document.getElementById('loadingImg2').style.display = 'block';
		}
		if(!isEmail(Trim(email.value))){
			document.getElementById('loadingImg1').style.display = 'none';
			document.getElementById('loadingImg2').style.display = 'none';
			alert("Please enter a valid email address.");
			email.focus();
			return false;
		}
		if((Trim(msg.value)).length <= 0){
			document.getElementById('loadingImg1').style.display = 'none';
			document.getElementById('loadingImg2').style.display = 'none';
			alert("Please enter a message");
			msg.focus();
			return false;
		}
		if(!checkTextareaLength(msg, maxMsg, 'Your message')){
			return false;
		}

		var url= window.location.protocol + "//" + window.location.host + "/thinkdynamik/" +  "mailsend.php?email=" + email.value + "&message=" +msg.value + "&type=" + type;
		
		postRequest(url, type);		
		return true;
		
		
	}
	
	function isEmail(strValue){
	    var objRegExp = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
	    return objRegExp.test(strValue);
	}
	
	function Trim(strValue){
	    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
	    if (objRegExp.test(strValue)) {
	        //remove leading and trailing whitespace characters
	        strValue = strValue.replace(objRegExp, '$2');
	    }
	    return strValue;
	}	
	// Check the length of a textarea field and warn user if they've entered greater than a given number of characters.
	function checkTextareaLength(field, maxLength, fieldDesc){
	    if (field.value.length > maxLength) {
	        alert('Warning. "' + fieldDesc + '" can accept a maximum of ' + maxLength + ' characters. It currently contains ' + field.value.length + ' characters and must be revised before proceding.');
	        field.focus();
	        field.select();
	        return false;
	    }
	    return true;
	}

