/*
	Virticle Corp Prebuilt Base JavaScript Code
	Version 1.0 - Updated 2006-02-24 by Greg Leuch
	http://www.virticle.com
*/



// Set to the site path (w/o ending slash)
urlPath = "http://www.archangel.com/wp-content/themes/archangel";



// -----------------------------------------------------------------------------
// Flash Vars
// Major version of Flash required
var requiredMajorVersion = 8;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------





/*
	Cross-browser compatible method of getting a element by Id
	Call - changeElement("elementName");
*/
function changeElement(areaElement) {
	return ((document.getElementById) ? document.getElementById(areaElement) : eval("document.all."+areaElement));
}


/*
	function to display the current year, for copyright messages, etc.
*/
function displayYear() {
	var time = new Date();
	var year = time.getYear();
	if(year<2000){
		year = (year-100)+2000;
	}
	document.write(year);
}


/*
	Code to check for browser
	This works well for stylesheets formatted for specific browsers
	or other browser specific elements.
*/

var browser = "";
var version = "";
var entrance = "";
var cond = "";

if (browser == ""){
	if (navigator.appName.indexOf("Microsoft") != -1) browser = "IE";
	else if (navigator.appName.indexOf("Netscape") != -1) browser = "Netscape";
	else browser = "IE";
}
if (version == ""){
	version= navigator.appVersion;
	paren = version.indexOf("(");
	whole_version = navigator.appVersion.substring(0,paren-1);
	version = parseInt(whole_version);
}

/* Code to output stylesheet (if neeeded) */
function getStylesheets() {
	if (browser == 'IE' && version >= 4) {
		document.write('<'+'link type="text/css" rel="stylesheet" href="'+urlPath+'/site/css/screen-ie.css" />');
	} else {
		document.write('<'+'link type="text/css" rel="stylesheet" href="'+urlPath+'/site/css/screen-other.css" />');
	}
}


/*
	Image swap code
	Preload images (must have <body onload="preloadImages()"> set)
	Best to preload images by specifying in preloadImages()
	Call to change images: changeImages(src, link, [src, link...]);
	Saves current effect into variable to "unload" when action is
	undone (i.e. mouseout).
*/

var oldArgs = "";
var preloadFlag = true;

function preloadImages() {
	if (document.images) {
		image = newImage(urlPath+"");
		preloadFlag = true;
	}
}

function changeImages() {
	oldArgs = new Array;
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			oldArgs[i] = changeImages.arguments[i];
			oldArgs[i+1] = document[changeImages.arguments[i]].src;
			document[changeImages.arguments[i]].src = urlPath+changeImages.arguments[i+1];
		}
	}
}

function undoChangeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<oldArgs.length; i+=2) {
			document[oldArgs[i]].src = oldArgs[i+1];
		}
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}



/* 
	sIFR Font Code
*/

if(typeof sIFR == "function"){
	sIFR.replaceElement("h1", named({
		sFlashSrc: urlPath+"/site/type/--font-name--.swf", 
		sColor: "#------", 
		sLinkColor: "#------",
		sHoverColor: "#------",
		sBgColor: "#FFFFFF"
	}));
};




/* 
	Code for form submission checks....  
	checkform() is the function called by the script.
	checkvalue() checks the value of a simple input field
	checkselect() checks the value of a select field
	checkemailaddress() checks the validity of an email address
*/

function checkform (form) {
	if (!checkvalue(form.Name, 'Please enter your name.')) return false;
	if (!checkvalue(form.Address1, 'Please enter your address.')) return false;
	if (!checkselect(form.Country, 'Please select your country.')) return false;
	if (getselected(form.Country) == "United States") {
		if (!checkselect(form.State, 'Please select your state.')) return false;
	} else if (getselected(form.Country) == "Canada") {
		if (!checkselect(form.Province, 'Please select your province/territory.')) return false;
	} else {
		if (!checkvalue(form.State_Province, 'Please enter your state or province.')) return false;
	}
	if (!checkvalue(form.City, 'Please enter your city.')) return false;
	if (!checkvalue(form.ZipCode, 'Please enter your zip code or other identifying mailing location.')) return false;
	if (!checkvalue(form.Phone, 'Please enter your daytime phone number.')) return false;
	if (!checkemailaddress(form.vCONTROL_from, 'Please enter an email address in the correct format (name@domain.com).')) return false;
	if (!checkselect(form.PreferredContactMethod, 'Please select how you prefer to be contacted.')) return false;
	if (!checkselect(form.JoinMailingList, 'Please select whether you would like to be added to our mailing list.')) return false;
	if (!checkvalue(form.Feedback, 'Please enter your questions, feedback or comments.')) return false;
	
	return true;
}

function checkEvalForm(form) {
	if(!checkvalue(form.prodEvaluated, 'Please enter the name of the product you are evaluating.')) return false;
	if(!checkvalue(form.name, 'Please enter your name.')) return false;
	if(!checkvalue(form.company, 'Please enter the name of your company.')) return false;
	if(!checkemailaddress(form.vCONTROL_from, 'Please enter your email address in the correct format (name@domain.com).')) return false;
	if(!checkvalue(form.comments, 'Please enter additional detail about the product so we can provide more targeted service.')) return false;
	
	return true;
}

function changeStates(country) {
	if (country.value == "United States") {
		x = '<label for="State">State <span class="highlight">*</span></label><select name="State" id="State" size="1"><option value="">Please Select... </option><option value="AL">Alabama</option><option value="AK">Alaska</option><option value="AZ">Arizona</option><option value="AR">Arkansas</option><option value="CA">California</option><option value="CO">Colorado</option><option value="CT">Connecticut</option><option value="DE">Delaware</option><option value="DC">Dist of Columbia</option><option value="FL">Florida</option><option value="GA">Georgia</option><option value="HI">Hawaii</option><option value="ID">Idaho</option><option value="IL">Illinois</option><option value="IN">Indiana</option><option value="IA">Iowa</option><option value="KS">Kansas</option><option value="KY">Kentucky</option><option value="LA">Louisiana</option><option value="ME">Maine</option><option value="MD">Maryland</option><option value="MA">Massachusetts</option><option value="MI">Michigan</option><option value="MN">Minnesota</option><option value="MS">Mississippi</option><option value="MO">Missouri</option><option value="MT">Montana</option><option value="NE">Nebraska</option><option value="NV">Nevada</option><option value="NH">New Hampshire</option><option value="NJ">New Jersey</option><option value="NM">New Mexico</option><option value="NY">New York</option><option value="NC">North Carolina</option><option value="ND">North Dakota</option><option value="OH">Ohio</option><option value="OK">Oklahoma</option><option value="OR">Oregon</option><option value="PA">Pennsylvania</option><option value="RI">Rhode Island</option><option value="SC">South Carolina</option><option value="SD">South Dakota</option><option value="TN">Tennessee</option><option value="TX">Texas</option><option value="UT">Utah</option><option value="VT">Vermont</option><option value="VA">Virginia</option><option value="WA">Washington</option><option value="WV">West Virginia</option><option value="WI">Wisconsin</option><option value="WY">Wyoming</option></select>';
		y = "State";
	} else if (country.value == "Canada") {
		x = '<label for="Province">Province <span class="highlight">*</span></label><select name="Province" id="Province" size="1"><option value="">Please Select...</option><option value="Alberta">Alberta</option><option value="British Columbia">British Columbia</option><option value="Manitoba">Manitoba</option><option value="New Brunswick">New Brunswick</option><option value="Newfoundland and Labrador">Newfoundland and Labrador</option><option value="Northwest Territories">Northwest Territories</option><option value="Nova Scotia">Nova Scotia</option><option value="Nunavut">Nunavut</option><option value="Ontario">Ontario</option><option value="Prince Edward Island">Prince Edward Island</option><option value="Quebec">Quebec</option><option value="Saskatchewan">Saskatchewan</option><option value="Yukon">Yukon</option></select>';
		y = "Province";
	} else {
		x = '<label for="State_Province">State/Province <span class="highlight">*</span></label><input type="text" name="State_Province" id="State_Province" />';
		y = "State_Province";
	}

	changeElement("states_sel").innerHTML = '';
	changeElement("states_sel").innerHTML = x;
	//changeElement(y).focus();
}

function checkvalue(formfield, message) {
	if (formfield.value == "") {
		alert (message);
		formfield.focus();
		return false;
	}
	return true;
}

function checkselect(formfield, message) {
	// Checks if return option value is not defined or is "na"
	if (formfield.options[formfield.selectedIndex].value == "" || formfield.options[formfield.selectedIndex].value == "na") {
		alert (message);
		formfield.focus();
		return false;
	}
	return true;
}

function getselected(formfield) {
	return formfield.options[formfield.selectedIndex].value;
}

function checkemailaddress(formfield, message) {
	var str = formfield.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (str == "") {
		alert(message);
		formfield.focus();
		return false;
	} else if (!str.match(re)) {
		alert(message);
		formfield.focus();
		return false;
	} else {
		return true;
	}
}


// For Flash

var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      		var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
      		versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
            flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
      	} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		
		flashVer = -1;
	}
	return flashVer;
} 
// If called with no parameters this function returns a floating point value 
// which should be the version of the Flash Player or 0.0 
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) 
{
 	reqVer = parseFloat(reqMajorVer + "." + reqRevision);
   	// loop backwards through the versions until we find the newest version	
	for (i=25;i>0;i--) {	
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);		
		}
		if (versionStr == -1 ) { 
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray         = versionStr.split(" ");
				tempString        = tempArray[1];
				versionArray      = tempString .split(",");				
			} else {
				versionArray      = versionStr.split(".");
			}
			versionMajor      = versionArray[0];
			versionMinor      = versionArray[1];
			versionRevision   = versionArray[2];
			
			versionString     = versionMajor + "." + versionRevision;   // 7.0r24 == 7.24
			versionNum        = parseFloat(versionString);
        	// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );	
			}
		}
	}	
	return (reqVer ? false : 0.0);
}



function loadFlashHeader(swfsrc) {
	var hasRightVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
	if(hasRightVersion) {  // if we've detected an acceptable version
		var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'width="773" height="405"'
			+ 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">\n'
			+ '<param name="movie" value="'+urlPath+'/site/flash/'+swfsrc+'?setdelay=10000" />\n<param name="quality" value="high" />\n<param name="bgcolor" value="#c9c3b7" />'
			+ '<embed src="'+urlPath+'/site/flash/'+swfsrc+'?setdelay=10000" quality="high" bgcolor="#c9c3b7" '
			+ 'width="773" height="405" name="header" align="middle"'
			+ 'play="true"'
			+ 'loop="false"'
			+ 'quality="high"'
			+ 'allowScriptAccess="sameDomain"'
			+ 'type="application/x-shockwave-flash"'
			+ 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
			+ '<\/embed>\n'
			+ '<\/object>';
		document.write(oeTags);   // embed the flash movie
	} else {  // flash is too old or we can't detect the plugin
		var alternateContent = '<table cellpadding="0" cellspacing="0" border="0"><tr><td colspan="2"><a href="'+urlPath+'/index.html"><img src="'+urlPath+'/site/images/noflash_logo.jpg" alt="Archangel Systems Inc." title="Archangel Systems Inc." width="773" height="91" border="0" /></a></td></tr><tr><td width="162"><a href="'+urlPath+'/about"><img src="'+urlPath+'/site/images/noflash_nav01.jpg" alt="About" title="About" width="162" height="27" border="0" /></a><br /><a href="'+urlPath+'/products"><img src="'+urlPath+'/site/images/noflash_nav02.jpg" alt="Products" title="Products" width="162" height="26" border="0" /></a><br /><a href="'+urlPath+'/services"><img src="'+urlPath+'/site/images/noflash_nav03.jpg" alt="Services" title="Services" width="162" height="26" border="0" /></a><br /><a href="'+urlPath+'/innovations"><img src="'+urlPath+'/site/images/noflash_nav04.jpg" alt="Innovations" title="Innovations" width="162" height="26" border="0" /></a><br /><a href="'+urlPath+'/clients"><img src="'+urlPath+'/site/images/noflash_nav05.jpg" alt="Clients" title="Clients" width="162" height="26" border="0" /></a><br /><a href="'+urlPath+'/support"><img src="'+urlPath+'/site/images/noflash_nav06.jpg" alt="Support" title="Support" width="162" height="26" border="0" /></a><br /><a href="'+urlPath+'/media"><img src="'+urlPath+'/site/images/noflash_nav07.jpg" alt="Media" title="Media" width="162" height="26" border="0" /></a><br /></td><td width="611"><a href="http://www.macromedia.com/go/getflash/" target="_blank"><img src="'+urlPath+'/site/images/noflash_click.jpg" border="0" title="You need  Macromedia Flash Player 8 to view this site properly. Click here to download."/></a></td></tr><tr><td colspan="2"><img src="'+urlPath+'/site/images/noflash_bottom.jpg" alt="Archangel Systems Inc." title="Archangel Systems Inc." width="773" height="131" border="0" /></td></tr></table>';
		document.write(alternateContent);  // insert non-flash content
	}
}