// -----------------------------------------------------------------------------
// Browser Sniffer
// -----------------------------------------------------------------------------
// sniffer_version = "1.1"
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION *********************************************************
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
   is_major = parseInt(is_minor);
}              

var is_getElementById   = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

if ((navigator.vendor) && ((navigator.vendor=="Netscape6") || (navigator.vendor=="Netscape")) && (is_nav)) {
   is_major = parseInt(navigator.vendorSub);
   is_minor = parseFloat(navigator.vendorSub);
}

var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up 	= (is_nav && is_minor >= 4); 
var is_navonly	= (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav6up 	= (is_nav && is_minor >= 6);
var is_nav5up 	= (is_nav && is_minor >= 5);
var is_nav7up 	= (is_nav && is_minor >= 7);
var is_ie   	= ((iePos!=-1));
var is_ie4   	= (is_ie && is_major == 4);
var is_ie4up 	= (is_ie && is_minor >= 4);
var is_ie5up 	= (is_ie && is_minor >= 5);
var is_ie5_5  	= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6up 	= (is_ie && is_minor >= 6);

// *** PLATFORM *******************************************************************	
var is_win   		= ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 		= ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_winme 		= ((agt.indexOf("win 9x 4.90")!=-1));  
var is_win2k 		= ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1));
var is_winxp 		= ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1));
var is_winxp_sp2 	= ((is_winxp) && (agt.indexOf("sv1")!=-1));	//Currently only works in IE
var is_win98 		= ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt 		= ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 		= (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
var is_mac   		= (agt.indexOf("mac")!=-1);


// -----------------------------------------------------------------------------
// Image Rollover Functions
// -----------------------------------------------------------------------------
// old school
function rollOver(img_name, img_src)
{
	if (document.images)
	{
		document [img_name].src = img_src;
	}
}

// new DOM hotness
function imgSwap( imgID, imgURL )
{
	return document.getElementById( imgID ).src = imgURL;
}

// -----------------------------------------------------------------------------
// window popup functions
// -----------------------------------------------------------------------------
// General Purpose popUp Script
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindow (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var options="resizable="+_resizeable+",scrollbars="+_scrollbars+",width="+window_width+",height="+window_height+"";
	popupWin=window.open(window_url, window_name, options);
	return false;
}

// popup function places window into lower left corner.
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindowMarketing (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var top;
	var left;
	
	top = screen.height - window_height - 40;
	left = 0;
	
	if (top < 0) { top = 0; }
	
	var options="top=" + top +
							",left=" + left +
							",resizable=" + _resizeable +
							",scrollbars="+ _scrollbars +
							",width=" + window_width + 
							",height=" + window_height + "";
							
	popUpWinMarketing = window.open(window_url, window_name, options);
	return false;
}

// popup function places window into upper right corner.
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindowOrdering (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var top;
	var left;
	
	top = 0;
	left = screen.width - window_width - 10;

	if (left < 0) { left = 0; }

	var options="top=" + top +
							",left=" + left +
							",resizable=" + _resizeable +
							",scrollbars="+ _scrollbars +
							",width=" + window_width + 
							",height=" + window_height + "";
							
	popUpWinOrdering = window.open(window_url, window_name, options);
	return false;
}

// loads URL into window that oppened popup
// usage: openerLink('URL');
function openerLink(link_location)
{
	opener.location.href=link_location;
	return false;
}

// -----------------------------------------------------------------------------
// loopqual autotab functions
// -----------------------------------------------------------------------------
// checks if keycode is a number
function isNumericLQ()
{
	if (is_nav)
	{
		return;
	}
	else
	{
		get=event.keyCode;
		if((get>47&&get<58)||(get==8)||(get==9)) 
		{
			return true;
		}
		else
		{
			event.returnValue=false;
		}
	}
}

// automatically changes focus to linkItem once maxLength of hItem is reached
// DON'T USE ON NUMBER/LINE, AS THE RE-FOCUS TO THE GO BUTTON DOESN'T WORK!
function AutoTabLQ(hItem, maxLength, linkItem )
{	
	isNumericLQ();
	if (is_mac)
	{
		return;
	}
	else
	{
		if (is_ie)
		{
			var vKeyCode,oItem;
			oItem = eval(linkItem);	
			vKeyCode = window.event.keyCode
			if(vKeyCode==9 && window.event.shiftKey){ return; }
			switch(window.event.keyCode)
			{
				case 37 : return;
				case 39 : return;
				case 16 : return;
				case 46 : return;
			}
			if (window.event.keyCode != 9 )
			{
				if( typeof(oItem) == "object" )
				{					
					if(bAutotab && (String(oItem.value).length ==0) && (String(hItem.value).length == maxLength) && (window.event.keyCode != 8))
					{
						oItem.focus();
					}
				}
			}
		}
		bAutotab = true;
	}
}

// turns autotab on
bAutotab = true;

// turns autotab off
function stopAutoTabLQ()
{
	bAutotab = false;
}


// validates phone numbers
function validatePhoneNumber(area_code, exchange, last4)
{
	var area_code_string=area_code+"";
	var exchange_string=exchange+"";
	var last4_string=last4+"";
	
	var valid=1;
	
	if(area_code=="" || exchange=="" || last4=="")
	{
		valid=0;
	}
	else if(isNaN(area_code) || isNaN(exchange) || isNaN(last4))
	{
		valid=0;
	}
	else if(area_code_string.length!=3 || exchange_string.length!=3 || last4_string.length!=4)
	{
		valid=0;
	}
	
	return valid;
}

// validates area-code and local exchange (first 6 digits of a phone #)
function validateFirstSix(area_code, exchange)
{
	var area_code_string=area_code+"";
	var exchange_string=exchange+"";
	
	var valid=1;
	
	if(area_code=="" || exchange=="")
	{
		valid=0;
	}
	else if(isNaN(area_code) || isNaN(exchange))
	{
		valid=0;
	}
	else if(area_code_string.length!=3 || exchange_string.length!=3)
	{
		valid=0;
	}
	
	return valid;
}

// validates email addresses
// smallest email that validates as true: xx@xx.xx
function validateEmail(email_address)
{
	var valid=1
	
	if(email_address.indexOf('@') == -1 || email_address.indexOf('.') == -1)
	{
		valid=0;
	}
	
	if(valid==1)
	{
		var splitAt = email_address.split("@")
		var splitDot = splitAt[1].split(".")
		
		if(splitAt[0].length < 2 || splitDot[0].length < 2 || splitDot[1].length < 2)
		{
			valid=0;
		}
	}
	return valid;
}

// validates zip code for either a 5 digit or 9 digit zip (numbers only)
function validateZip(zip)
{
	var valid=0;
		
	var zip_string = zip + "";
	var zip_numbers="";
	
	//this loop goes through the zip and removes any non-digit characters
	for(var n=0; n<zip_string.length; n++)
	{
		if(!isNaN(zip_string.charAt(n)) && zip_string.charAt(n) != " ")
		{
			zip_numbers=zip_numbers +zip_string.charAt(n);
		}
	}
	
	if(zip_numbers.length==5 || zip_numbers.length==9)
	{
		valid=1;
	}
	
	return valid;
}

// validates that a field isn't empty
function isNotEmpty ( textfield )
{
	var valid = 0;
	if ( textfield.length != 0 )
	{
		valid = 1;
	}
	return valid;
}

// validates the REP ID format
function validateRepIDFormat( rep_id ){
	var valid = 1;

	first_character=rep_id.charAt(0); 
	second_character=rep_id.charAt(1); 
	third_character=rep_id.charAt(2); 
	fourth_character=rep_id.charAt(3); 
	fifth_character=rep_id.charAt(4); 
	sixth_character=rep_id.charAt(5);
	
	numeric=third_character+fourth_character+fifth_character+sixth_character;

	if(!isNaN(first_character) || !isNaN(second_character) || isNaN(numeric)){
		valid = 0;
	}

	return valid;
}	
////////////

function trim(str)
{
   if(str!=""){
	while (str.charAt(0)==" ")
		str = str.substring(1,str.length);

	while (str.charAt(str.length-1)==" ")
		str = str.substring(0,str.length-1);
   }

	return str;
}
