// JavaScript Document

function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

function switchImage(imgName, onOff, previousRule, nextRule) {
    imgDir = "/images/nav/";
    if (document.images) {
        if (onOff == "on") {
            document.images[imgName].src = imgDir + imgName + "_on.gif";
            if (previousRule) {
                document.getElementById("rule" + previousRule).className="ruleon";
            }
            if (nextRule) {
                document.getElementById("rule" + nextRule).className="ruleon";
            }
        } else {
            document.images[imgName].src = imgDir + imgName + "_off.gif";
            if (previousRule) {
                document.getElementById("rule" + previousRule).className="rule";
            }
            if (nextRule) {
                document.getElementById("rule" + nextRule).className="rule";
            }
        }
    }
}

function testQuote() {
    ssArray = [[],[10,11,12,13,14]];
    thisArray = eval('ss' + 'Array');


    alert (thisArray[1][0]);
}

function writeQuote(section, shortQuote) {
    if(section == "coleman_associates") section = 'ca';
    else if (section == "about_redesign") section = 'ar';
    else if (section == "how_to_start") section = 'hts';
    else if (section == "techniques") section = 't';
    else if (section == "team_culture") section = 'tc';
    else if (section == "success_stories") section = 'ss';
    else if (section == "more_resources") section = 'a'; // more resources and articles are sharing quotes
    else if (section == "articles" || section == "root") section = 'a';

    // first array for each section is short quotes, second is all quotes.
    // NOTE!  we are not expecting this function to be called from these sections:
    // - about redesign

    aArray = [[],[5,7,8,9]];
    ssArray = [[15,16,17,20],[10,11,12,13,14,15,16,17,18,20]];
    htsArray = [[21,23,24,25,26],[21,23,24,25,26]];
    tcArray = [[28,29],[27,28,29,30]];
    tArray = [[34,38,39],[31,32,33,34,35,36,37,38,39]];
    caArray = [[6,17],[1,2,3,4,5,6,7,8,9,17]];

    thisArray = eval(section + 'Array');
    
    imgRef = '<img src="/images/quote_';
    if(shortQuote) {
        imgRef += thisArray[0][Math.floor(Math.random() * thisArray[0].length)];
    } else {
        imgRef += thisArray[1][Math.floor(Math.random() * thisArray[1].length)];
    }
    imgRef += ('_' + section);
    imgRef += '.gif" class="quoteimage"';
    imgRef += (shortQuote ? ' style="margin-bottom: 0" />' : ' />');

    document.write(imgRef);
} 


//Advanced Email Check credit-
//By JavaScript Kit (http://www.javascriptkit.com)
//Over 200+ free scripts here!
// altered by Ben Di Maggio 5/13/05 (http://www.tokyoben.net)

function validateForm(form){
    var noGoodMsg = "";
	var badToAddrs = "";
    var testresults = true;
    var to=form.toaddr.value;
    var from=form.fromaddr.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

	if(to.indexOf(",") != -1) {
		to = to.replace(/\s/g, "");
		toArray = to.split(",");
	} else toArray = new Array (to);

	for (i in toArray) {
		if(!filter.test(toArray[i])) {
			testresults = false;
			badToAddrs += (badToAddrs == "" ? '"'+toArray[i]+'"' : ' and "'+toArray[i] + '"');
		}
	}
	if(!testresults) noGoodMsg = "The address[es] " + badToAddrs + " in the \"Recipient's Email\" field seem to be invalid. Please check it/them and click \"Send\" again.\n";

    if(!filter.test(from)) {
		testresults = false;
		noGoodMsg += "The \"Your Email\" field seems to contain an invalid address. Please check it and click \"Send\" again.\n";
	}

	if(!testresults) alert(noGoodMsg);
    return (testresults);
}

function validateEnewsForm(form){
    var testresults = true;
    var to=form.Email.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if(!filter.test(to)) {
		testresults = false;
		alert("The address you submitted seems to be invalid. Please check it and click \"Submit\" again.\n");
	} else form.Mode.value='update';
	return(testresults);
}

$(document).ready(function() {
 $('.pull_quote_left').corner('15px');
 $('.pull_quote_right').corner('15px');
});

