/*
	Javascript for SkellyForCongress.com
	Created: 01/24/2008
	Author: Stephen Rushing, eSiteful
*/

var ns4, op5, op6, agt, mac, ie, mac_ie;



function registerEmail(){
	
	theInput = document.getElementById('siteHeaderEmail');

	if(theInput.value!='' && theInput.value != 'email'){
		window.location='http://oi.vresp.com/?fid=5e30df79dd&email_address='+theInput.value;
	}else{
		alert("Please enter a valid e-mail address.");	
	}
	
}

function navHighlight(){

	theNav = document.getElementById('siteNav');
	theLinks = theNav.getElementsByTagName('a');
	theArrow = document.getElementById('siteNavArrow');
	matchFound = false;
	
	//Detect browser
	sniffBrowsers();
	
	currentUrl = document.location.href;
	
	for(i=0;i<theLinks.length;i++){
		//alert(cleanUrl(theLinks[i].href) + " : " +cleanUrl(currentUrl));
		cleanNavLink = cleanUrl(theLinks[i].href);
		cleanCurrentUrl = cleanUrl(currentUrl);
		
		if(cleanNavLink==cleanCurrentUrl || cleanCurrentUrl.indexOf(cleanNavLink)>-1){
			activeLink = theLinks[i];
			
			matchFound=true;
			
			if(i==theLinks.length-1){
				theArrow.src='/common/images/nav-special-arrow.gif';	
			}
		}
	}
	
	//activeLink = theLinks[1];
	
	//IF MATCHING NAV LINK IS FOUND
	if(matchFound){
		theArrow.style.display="block";
		activeLink.className = "active";		
		activeLinkX = findPos(activeLink)[0];
		activeLinkWidth = findWidth(activeLink);
		
		theArrowX = activeLinkX + (activeLinkWidth/2)-14;
		
		theArrow.style.left = theArrowX+'px';
		
	
			theArrow.style.top=113+'px';
			
		
	}
	//alert(findPos(theLinks[0]));
}

//cleans a url for better comparison
function cleanUrl(theLink){
	if(theLink.indexOf('http:')>-1){
		theLink	= theLink.substr(theLink.indexOf('http:')+5, theLink.length);
	}
	if(theLink.indexOf('index.htm')>-1){
		theLink	= theLink.substr(0,theLink.indexOf('index.htm'));
	}
	if(theLink[theLink.length-1]=='/'){
		theLink = theLink.substr(0, theLink.length-1);	
	}
	
	return theLink;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function findWidth(obj) {
		
		if (op5) {
			xPos = obj.style.pixelWidth;
		} else {
			xPos = obj.offsetWidth;
		}
		return xPos;
	
}

function sniffBrowsers() {
	ns4 = document.layers;
	op5 = (navigator.userAgent.indexOf("Opera 5")!=-1) 
		||(navigator.userAgent.indexOf("Opera/5")!=-1);
	op6 = (navigator.userAgent.indexOf("Opera 6")!=-1) 
		||(navigator.userAgent.indexOf("Opera/6")!=-1);
	agt=navigator.userAgent.toLowerCase();
	mac = (agt.indexOf("mac")!=-1);
	ie = (agt.indexOf("msie") != -1); 
	mac_ie = mac && ie;
	
}


function validateForm(formFields, formLabels, formName){
	alertMsg = "The following fields are not acceptable:\n\n";
	valid = true;
	for(i=0;i<formFields.length;i++){
		currentField = document.getElementById(formFields[i]);
		
		if(currentField){
			if(currentField.type=='text' && currentField.value==''){
				alertMsg+="   "+formLabels[i]+"\n";
				valid = false;
			}
		}
	}
	if(!valid){
		alert(alertMsg+"\n\n ");
	}else{
		
		document.getElementById(formName).submit();
	}
}