<!--

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//ROLLOVER SCRIPTS
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

//EXTERNAL LINKS TARGET BLANK
function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") &&  anchor.className == "external") 
	 anchor.target = "_blank"; 
 } 
}

//POP UP WINDOW SCRIPT
var popWin = null;	 
function pop(file,width,height) {
	if (file.substring(0,4) == "http") {
		thispage = file;
	} else {
		thispage = baseURL+file;
	}
	popWin = window.open(thispage,
	 'popWin',
	 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=' + width + ',height=' + height );
	popWin.focus();
	return;
}

//TELL A FRIEND
function tell_a_friend(title,url) {
	if (!title) {
		title = document.title;
	}
	if (!url) {
		url = document.URL;
	}
	var tell_url = 'http://dev2.capstrat.com/clients/stewart/tellafriend.php?title=' + title + "&link=" + url;
	//alert(url);
	pop(tell_url, '475', '400');
}

//VALIDATION SCRIPT
function submitForm(myForm) {
	if ( !check_required(myForm) ) { 
		return false;
	}
	return true;
}

function check_required(myForm) {
	var requiredFields = myForm._required.value.split("|");
	var errorString = '';
	for (var i=0; i<requiredFields.length; i++) {
		var parts = requiredFields[i].split(",");
		var field = parts[0];
		var title = parts[1];
		var requiredType = parts[2];
		var myElement = myForm[field];
		var isNull = false;
		/*
		TYPES check for
			text				//the presence of any text
			text-email		//valid email address format
			text-int			//number
			text-phone		//valid phone: numbers()+-.
			radio				//radio
			checkbox			//checkbox
			select-single	//
			select-multi	//
		*/
		//validating: confirm that text is a string
		if (requiredType == "text") {
			//alert(myElement.name);
			if ((myElement.value == null || myElement.value.search(/\w/) == -1) && errorString.indexOf(title) == -1) {
				isNull = true;
			}
		//validating: confirm that text is a valid email format
		} else if (requiredType == "text-email") {
			//alert(myElement.name);
			var str = myElement.value;
			var at="@";
			var dot=".";
			var lstr=str.length;
			if ((myElement.value == null || myElement.value.search(/\w/) == -1) && errorString.indexOf(title) == -1) {
				isNull = true;
			}					
			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
				isNull = true;
			}
			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
				 isNull = true;
			}
		//validating: confirm that text is an integer
		} else if (requiredType == "text-int") {
			var str = myElement.value;
			if (isNaN(str) || str == "") {
				isNull = true;
			}	
		//validating: confirm that text is a valid email format
		} else if (requiredType == "text-phone") {
		
		//validating: confirm that text is a radio button or check box is selected
		} else if (requiredType == "radio" || requiredType == "checkbox") {
			var buttonCount = myElement.length;
			//alert(myElement[0].name);
			isNull = true;
			for (j = 0; j < buttonCount; j++) {
				if (myElement[j].checked) {
					isNull = false;
				}
			}
		//validating: confirm that a option is selected
		} else if (requiredType == "select-single" || requiredType == "select-multiple") {
			//alert(myElement.options[myElement.selectedIndex].value);
			if ((myElement.options[myElement.selectedIndex].value == null || myElement.options[myElement.selectedIndex].value == '') && errorString.indexOf(title) == -1) {
				isNull = true;
			}
		}
		
		//alert(field+' is invalid: '+isNull);
		//SET ERROR
		if (isNull) {
			errorString += title + ", ";
			if (document.getElementById('label_'+field)) { 
				document.getElementById('label_'+field).className="formlabelerror";
			}
			myElement.className="formfielderror";
		} else {
			if (document.getElementById('label_'+field)) {
				document.getElementById('label_'+field).className="formlabelvalid";
			}
			myElement.className="formfieldvalid";
		}

	}
	if (errorString != '') {
		errorString = errorString.slice(0,errorString.length-2);
		window.alert("Please fill in the following required fields before submitting this form:\n\n"+errorString)
		return false;
	}
	else {
		return true;
	}
}

//-->