// Open links in external window for XHTML 1.0 Strict compliancy
// To make a link open in external window add the "rel" attribute to the <a> tag
// and set its value to "external" example:
//     <a href="http://www.google.com" rel="external">Google</a>
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	var areas = document.getElementsByTagName("area");
	var forms = document.getElementsByTagName("form");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
	for (var x=0; x<areas.length; x++) {
		var area = areas[x];
		if (area.getAttribute("href") &&
		area.getAttribute("rel") == "external")
		area.target = "_blank";
	}
	for (var y=0; y<forms.length; y++) {
		var form = forms[y];
		if (form.getAttribute("rel") == "external")
		form.target = "_blank";
	}
}
// Image rollover - for use please make sure image names follow the following name scheme:
// Idle Image:  image_i.gif
// Hover Image: image_o.gif
// File extension and anything before the _i. does not matter so long as it is consistent between
// the two states (e.g. "image_i.gif" and "hoverimage_o.gif" does not work)
// Usage:
// <img src="image_i.gif" alt="" onmouseover="rollOver(this)" onmouseout="rollOut(this)" />
var oldImage = "";
function rollOver(oImg) {
	oldImage = oImg.src;
	var newImage = oldImage.replace("_i.","_o.");
	oImg.src = newImage;
}
function rollOut(oImg) {
	oImg.src = oldImage;
}
function clickDown(oImg) {
	oldImage = oImg.src.replace("_o.","_i.");
	var newImage = oldImage.replace("_i.","_d.");
	oImg.src = newImage;
}
function clickUp(oImg) {
	oImg.src = oldImage;
}
function tabBoxs() {
	if (!document.getElementsByTagName) return;
	if(document.getElementById("dtTabs")) {
		var tabBoxs = document.getElementById("dtTabs");
		var anchors = tabBoxs.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var thisAnchor = anchors[i];
			if (thisAnchor.getAttribute("rel") == "tabBox") {
				// IE kills the CSS roll overs if the href attribute is removed so
				// we are forced to use the javascript call in the href as an http call - 
				// which is annoying because of the stupid click noise IE makes from
				// using this method.
				/*
				if(!document.all) {
					thisAnchor.removeAttribute("href");
					thisAnchor.onclick = function() {
						toggleInfo(this.id);
					}
				} else {
					thisAnchor.href = "javascript:toggleInfo('"+thisAnchor.id+"');";
				}*/
				thisAnchor.setAttribute("onfocus","this.blur();");
				var closeLink = document.createElement("a");
					thisAnchor.parentNode.parentNode.getElementsByTagName("div")[0].appendChild(closeLink);
					closeLink.setAttribute("onfocur","this.blur();");
					closeLink.className = "closeLink";
					closeLink.setAttribute("class","closeLink");
					closeLink.onclick = function() {
						new Fx.Style(this.parentNode,'opacity',{duration:300}).start(1,0);
					}
			}
		}
		
		var bGo = function() {
			new Fx.Style('infoStrategize','opacity',{duration:750,onComplete:function(){
							new Fx.Style('infoDevelop','opacity',{duration:750,onComplete:function(){
										new Fx.Style('infoMarket','opacity',{duration:750}).custom(0,1);
										}}).custom(0,1);
							}}).custom(0,1);
			clearInterval(bInt);
		}
		var bInt = setInterval(bGo,1000);
	}
}
function toggleInfo(elem) {
	var infoName = elem.replace("dt","info");
	new Effect.toggle(infoName,'appear',{duration:0.3});
}
function toggleProposal() {
	new Effect.toggle(document.getElementById('proposalList'),'blind',{duration:0.3});
}
function startup() {
	//List functions to be run on startup here:
	externalLinks();
	tabBoxs();
}
var oldonload = window.onload;
if (typeof window.onload != 'function') {
	window.onload = startup;
} else {
	window.onload = function() {
		oldonload();
		startup();
	}
}
function showtwo(theid,moveMe) {
	var sContent = document.getElementById(theid);
	var sLink = document.getElementById("more" + theid);
	
	if(moveMe && moveMe == true) {
		var sideNav = document.getElementById("sideNavNews");
		
		sideNav.style.position = "fixed";
		sideNav.style.top = "30px";
	}		
	
	if (sContent.style.display == 'none') {
		new Effect.toggle(sContent,'blind',{duration:0.3});
        sLink.firstChild.src = "images/bullet_minus.gif";
	} else {
		new Effect.toggle(sContent,'blind',{duration:0.3});
        sLink.firstChild.src = "images/bullet_plus.gif";
	}
}
function validateTextField(element){
	if(document.getElementById(element).value=="") {
		alert('Please fill up all required fields');
		document.getElementById(element).focus();
		return false;
	} else {
		return true;
	}
}
	
function valedateSelectList(element){
	if(document.getElementById(element).selectedIndex==0) {
		document.getElementById(element).focus();
		return false;
	} else {
		return true;	
	}
}	
function proccessRFPForm(){
	if (validateTextField('Company')){
		if (validateTextField('Name')){
			if (validateTextField('Phone')){
				if (validateTextField('E-mail')){
					if (validateTextField('Address')){
						if (validateTextField('Industry')){
							if (validateTextField('Employees')){
								if (validateTextField('Anual_Revenue')){
									if (validateTextField('Offices_and_Locations')){
										if (valedateSelectList('Design_Budget')){
											if (valedateSelectList('Marketing_Budget')){
												document.forms[0].submit();
											} else {
												alert('Please select a marketing budget.')
											}
										} else {
											alert('Please select a design budget.')
										}										
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
// Replace input field with default value on blur if nothing was entered
// Usage: <input type="text" value="Default Value" onfocus="clearText(this)" onblur="replaceText(this)" />
function clearPhone(thefield,onOff) {
	if(onOff == 'off') {
		if (thefield.defaultValue==thefield.value) {
			thefield.value = "";
			thefield.style.color = '#000000';
		}
	} else {
		if (thefield.value=="") {
			thefield.value = thefield.defaultValue;
			thefield.style.color = '#AAAAAA';
		}
	}
}
