
// Note this copy MOVED for revisions 03-30-10
// Making some mods here to get inline JS out of the documents.
// Be sure the bluehost (main pg) and swfobject libraries are loaded BEFORE loading this file.

preloadImages();

// Load just the navs.
function preloadImages() {
	if (document.images) {
		var bg					= new Image();
		var cubicles			= new Image();
		var office_furniture	= new Image();
		var about_us			= new Image();
		var our_process			= new Image();
		var green_office		= new Image();
		var blog				= new Image();
		var contact_us			= new Image();
		var imgObj = new Array (bg,cubicles,office_furniture,about_us,our_process,green_office,blog,contact_us);
		var imgs = new Array ('/images/DaSliva.jpg','/images/cubicles-nav.jpg','/images/office-furniture-nav.jpg','/images/about-us-nav.jpg','/images/our-process-nav.jpg','/images/green-office-nav.jpg','/images/blog-nav.jpg','/images/contact-us-nav.jpg');
		var imgName;
		for (i=0;i<imgs.length;i++) {
			imgName = imgs[i];
			imgObj[i].src=imgName;
		}
	}
}

// Uses SWFObject to load main page video, 03-30-10
// Be sure to include swfobject.js FIRST in source code.

window.onload=function() { 
	loadVideo(); 
	attachBehaviors();
};

function loadVideo() {

	var vids = {
		'main-video':		'\/about\/videos\/flv\/intro.flv',
		'promise-1-video':	'\/about\/videos\/flv\/ch3.flv',
		'process-1-video':	'\/about\/videos\/flv\/ch4.flv',
		'process-2-video':	'\/about\/videos\/flv\/ch6.flv'
	};
	var imgs = {
		'main-video':		'\/images\/main-video-intro.gif',
		'promise-1-video':	'\/about\/images\/promise-1-intro.gif',
		'process-1-video':	'\/about\/images\/process-1-intro.gif',
		'process-2-video':	'\/about\/images\/process-2-intro.gif'
	};
	
	for (key in vids) {
		if (document.getElementById(key)) {
			var w = (key=='main-video')?460:248;
			var h = (key=='main-video')?320:205;
			var sdvideo = new SWFObject('\/about\/videos\/player.swf', 'z-vid', w, h, '9', '#ffffff'); 
			sdvideo.addParam("wmode", "transparent");
			sdvideo.addParam("menu", "false");
			sdvideo.addVariable("file", vids[key]);
			sdvideo.addVariable("size", "false");
			sdvideo.addVariable("aplay", "false");
			sdvideo.addVariable("autorew", "false");
			// Only IE needs these two
			sdvideo.addVariable("width", w);
			sdvideo.addVariable("height", h);
			sdvideo.addVariable("image", imgs[key]);
			sdvideo.addVariable("title", "");
			sdvideo.write(key);
		}
	}
}

function attachBehaviors() {
	// To validate under strict, add new window behaviors to any links in this list.
	// flash-alt,bbb-link: all pages. catalog links and '-link' links: furniture page.
	// process-1-alt, process-2-alt: our process page. OnlineChatSoftware = velaro chat link
	var newWins = Array (
		'flash-alt','bbb-link',
		'catalog-index','catalog-desks','catalog-chairs','catalog-storage','catalog-conference',
		'catalog-lobby','catalog-link','green-office','promise-1-alt','OnlineChatSoftware','chatLink',
		'chairs','desks','files','conference','lobby','lease-app','lease-calc',
		'process-1-alt','process-2-alt','c2cert','leed-cert','leed-cert2');
	var minFields = Array ('cname','cphone','cemail');
	
	for (i=0;i<newWins.length;i++) {
		if (document.getElementById(newWins[i])) {
			document.getElementById(newWins[i]).onclick=function() { return newFullWin(this.href); }
		}
	}
	for (i=0;i<minFields.length;i++) {
		if (document.getElementById(minFields[i])) {
			document.getElementById(minFields[i]).onfocus=function() { clearText(this); }
			document.getElementById(minFields[i]).onblur=function() { replaceText(this); }
		}
	}
	if (document.getElementById('Mail_ActionPage_FormResponse')) {
		document.getElementById('Mail_ActionPage_FormResponse').onsubmit= function() { return validateSmallForm(this); }
	}
	if (document.getElementById('sellForm')) {
		document.getElementById('sellForm').onsubmit= function() { return validateSellForm(this); }
	}
	// For non-public promo only, may be removed if /catalog-request is removed
	if (document.getElementById('cat-request')) {
		document.getElementById('cat-request').onsubmit= function() { return validateCatRequest(this); }
	}
}

// the main page form is different than the mini's and contact form, but at this point only email is required for both
function validateSmallForm(form) {
	if (form.email) {
		var regex = /.*\@.*[.].*/;
		if (regex.test(form.email.value)) { return true; }
		else { 
			alert('Please enter a valid email address\n in the form account-name@example.com.');
			return false;
		}
	}
	return true;
}

// Opens a NEW full window with all tools, alternative to target which is invalid under strict.

function newFullWin(url) {
	var day = new Date();
	var id=day.getTime();
	var params = 'toolbar,location,status,menubar,scrollbars,resizable,width=900,height=600,top=0,left=0';
	open(url,id,params);
	return false;
}

function validateSellForm(form) {
	name = form.name.value;
	wname = form.wName.value;
	pNum = form.pNum.value;
	email = form.eMail.value;
	numCubs = form.numCubs.value;
	removaldead = form.removaldead.value;
	emailErr=0;
	
	if (name == "") { alert("Please enter your name"); return false; }
    if (wname == "") { alert("Please enter your Company's Name"); return false; }
	if (pNum == "") { alert("Please enter your phone number"); return false; }
	if (numCubs == "") { alert("Please enter the number of cubicles"); return false; }
	if (removaldead == "") { alert("Please enter the deadline for removal"); return false; }
	// Ugh. Fix this.
	if(-1 == email.indexOf("@")) {	emailErr=1; } 
    if(-1 != email.indexOf(",")) {	emailErr=1; }
    if(-1 != email.indexOf("#")) {	emailErr=1; }
    if(-1 != email.indexOf("!")) {	emailErr=1; }
    if(-1 != email.indexOf(" ")) {	emailErr=1; }
    if(email.length == (email.indexOf("@")+1) ) {	emailErr=1; }
    if(email.length == 0) {	emailErr=1; }
	if (emailErr==1) { alert('Please enter a complete email address in the form: yourname@yourdomain.com.'); return false; }
	return true;
}

// For non-public promo only, may be removed if /catalog-request is removed
function validateCatRequest(form) {
	var req = {
	'fname':	'first name',
	'lname':	'last name',
	'phone':	'contact phone',
	'email':	'email address',
	'address':	'mailing address',
	'city':		'city',
	'state':	'state',
	'zip':		'zip code'
	};
	var email='email'; // set to null if not required
	var msg = '';
	for (key in req) {
		if (document.getElementById(key)) {
			var type = document.getElementById(key).type;
			if (type=='select-one') { // state
				if (document.getElementById(key).selectedIndex==0) {
					msg += 'Please select your ' + req[key] + '.\n';
				}
			}
			else {
				if (document.getElementById(key).value=='') {
					msg += 'Please enter your ' + req[key] + '.\n';
				}
			}
		}
	}
	
	if ((msg=='') && (email!=null)) {
		var regex = /.*\@.*[.].*/;
		if (! regex.test(document.getElementById(email).value)) {
			msg += 'Please enter a valid ' + req[email] + '.\n';
		}
	}
	if (msg != '') { alert(msg); return false; }
	else { return true; }
}

// These two were loaded ABOVE the main page contact form. As of this mod,
// not sure if they apply to any other pages.
function check_cdfs(form) { return true; }
function doSubmit() {
	if (check_cdfs(document.survey)) {
		var day = newDate();
		var id=day.getTime();
		open('',id,'resizable,scrollbars,width=300,height=150');
		return true;
	}
	else { return false; }
}

// For mini forms which have no visible labels
function clearText(thefield) {  
	if (thefield.defaultValue==thefield.value) { thefield.value = ""; }
}
function replaceText(thefield) {
	if (thefield.value=="") { thefield.value = thefield.defaultValue; }
}
