/*
	common.js
	started: June 23, 2003
	author:  Justin Cook
*/

var ie5	  = ( document.getElementById && document.all ); 
var moz	  = ( document.getElementById &&! document.all );
var opera = ( navigator.userAgent.indexOf( 'Opera' ) != -1 );
if ( opera ) ie5 = false;

function checkForm( f ) { //June 23, 2003
// loops through each element in the specified form ( f ), and if element is suffixed by '_required', 
// function checks if there is valid data. 
// If all is well submit form otherwise alert user which elements need to be filled.
	var strMessage = 'Please fix the following:\n\n';
	var objTemp; 
	var strName = ''
	var boolIsValid = true;
	var boolRadioChecked = false;
	for ( var i = 0; i < f.elements.length; i++ ) {
		objTemp = f.elements[i];
		strName = objTemp.name
			//alert(strName)
		if ( strName.substr( strName.length - 9 ) == '_required' ) {
		// first see if it's required
		
			//if required, parse the name
			strName = strName.replace( /data_/, '' );
			strName = strName.replace( /_required/, '' );
			strName = strName.replace( /_/g, ' ' );
			strName = strName.toLowerCase();
			
			if ( objTemp.value == '' ) {
				boolIsValid = false;
				strMessage += strName + ' is empty\n';
			} else if ( objTemp.type == 'radio' ) {
				if ( objTemp.checked ) { boolRadioChecked = true; }
				if ( f.elements[i + 1].name != objTemp.name ) { //must be on a new one
					if ( !boolRadioChecked ) { 
						boolIsValid = false; 
						strMessage += strName + ' is required; please check one\n';
					}
					boolRadioChecked = false;
				}
			}
			
			if ( strName.indexOf( 'first name' ) != -1 && objTemp.value == 'First' ) {
				boolIsValid = false;
				strMessage += strName + ' is invalid\n';
			} else if ( strName.indexOf( 'last name' ) != -1 && objTemp.value == 'Last' ) {
				boolIsValid = false;
				strMessage += strName + ' is invalid\n';
			} else if ( strName.indexOf( 'email' ) != -1 && ( objTemp.value.indexOf( '@' ) == -1 || objTemp.value.indexOf( '.' ) == -1 ) ) {
				boolIsValid = false;
				strMessage += strName + ' is invalid\n';
			} else if ( strName == 'verify password' && ( objTemp.value != f.data_password_required.value ) ) {
				boolIsValid = false;
				strMessage += 'Passwords do not match!\n';
			}
		}
	}
	if ( boolIsValid ) {
		return true;
	 } else {
	 	alert( strMessage );
		return false;
	}
}

// common dreamweaver behaviours
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_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_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_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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];}
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	// hotwire, send to fader
	fader( args[0], args[2] );
	return;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	//obj.visibility=v; 
	}
}

function mm_showhidelayers2() { //v6.0
  var i,p,v,obj,args=mm_showhidelayers2.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function moveObject( obj, e ) {
	var tempX = 0;
	var tempY = 0;
	obj = MM_findObj(obj).style;
	if (document.all) {
		tempX = event.clientX + document.body.scrollLeft;
		tempY = event.clientY + document.body.scrollTop;
	} else {
		tempX = e.pageX;
		tempY = e.pageY;
	}
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}
	obj.top  = tempY + 'px';
	obj.left = tempX + 'px';
}

function getObject( obj ) {
	var strObj
	if ( document.all ) {
		strObj = document.all.item( obj );
	} else if ( document.getElementById ) {
		strObj = document.getElementById( obj );
	}
	return strObj;
}

// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie( name, value, expires, path, domain, secure ) {
	var curCookie = name + '=' + escape( value ) +
					( ( expires ) ? '; expires=' + expires.toGMTString() : '' ) +
					( ( path ) ? '; path=' + path : '' ) +
					( ( domain ) ? '; domain=' + domain : '' ) +
					( ( secure ) ? '; secure' : '' );
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie( name ) {
	var dc = document.cookie;
	var strPrefix = name + '=';
	var intStart = dc.indexOf( '; ' + strPrefix );
	if ( intStart == -1 ) { intStart = dc.indexOf( strPrefix ); }
	if ( intStart == -1 ) {
		return null;
	} else {
		//intStart += 2;
		var intEnd = document.cookie.indexOf( ';', intStart );
		if ( intEnd == -1 ) { intEnd = dc.length; }
		//alert( intEnd )
		return unescape( dc.substring( intStart + strPrefix.length, intEnd ) );
	}
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) {
		document.cookie = name + '=' + 
						( ( path ) ? '; path=' + path : ''  ) +
						( ( domain ) ? '; domain=' + domain : '' ) +
						'; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate( date ) {
  var base = new Date( 0 );
  var skew = base.getTime();
  if ( skew > 0 )
    date.setTime( date.getTime() - skew );
}


// hides or displays the printable/non-printable elements of the page
function printFriendly( dir ) {
	var strDisplay, strDisplay2
	var arList = new Array();
	arList = [ 'searchArea', 'tier1Row', 'tier2Row', 'shadowRow', 'leftColumn' ]
	if ( dir == 'on' ) {
		strDisplay  = 'none';
		strDisplay2 = 'inline';
	} else {
		strDisplay  = 'inline';
		strDisplay2 = 'none';
		if ( navigator.userAgent.indexOf('IE') == -1 || navigator.userAgent.indexOf('Opera') > -1 ) { 
			//location.reload() 
		} 
	}
	getObject( 'printFriendlyOn' ).style.display  = strDisplay2
	getObject( 'printFriendlyOff' ).style.display = strDisplay
	//alert( navigator.userAgent )
	for ( var i = 0; i < arList.length; i++ ) {
		if ( getObject( arList[ i ] ) != null ) { 
			getObject( arList[ i ] ).style.display = strDisplay
		}
	}
}

var objInUse = ''
var dirInUse = ''
function fader( objID, dir ) {
	if ( dirInUse != '' && dirInUse != dir ) {
		clearTimeout( goIn ); 
		dirInUse = '';
	}
	if ( objInUse != '' && objInUse != objID ) {
		MM_findObj( objInUse ).style.visibility = 'hidden';
		MM_findObj( objInUse ).style.display = 'none';
		objInUse = '';
	}
	
	var obj = MM_findObj( objID );
	
	if ( ie5 || moz ) {
		obj.style.visibility = 'visible';
		obj.style.display = 'block';
		var fade_index;
		dirInUse = dir;
		objInUse = objID;
		
		if( ie5 ) {
			fade_index = obj.filters.alpha.opacity;
		}
		if( moz ) {
			fade_index = obj.style.MozOpacity * 100;
		}
		
		fade_index  = dir == 'show' ? fade_index + 5 : fade_index - 5;
		index_limit = dir == 'show' ? 100 : 0;
		
		if( ie5 ) {
			obj.filters.alpha.opacity = fade_index;
		}
		if( moz ) {
			obj.style.MozOpacity = fade_index / 100; 
		}
		goIn = setTimeout( 'fader( \'' + objID + '\', \'' + dir + '\' )', 20 );
		if( ( dir == 'show' && fade_index >= index_limit ) || ( dir == 'hide' && fade_index <= index_limit ) ) { //reached limit
			dirInUse = '';
			objInUse = '';
			clearTimeout( goIn );
			if ( dir == 'hide' ) obj.style.display = 'none';
		}
	} else {
		var strVis = dir == 'show' ? 'visible' : 'hidden';
		var strDid = dir == 'show' ? 'block' : 'none';
		obj.style.visibility = strVis;
		obj.style.display = strDis;
	}
}
function s_co() {
//get rid of js error
}
function s_gs() {
//get rid of js error
}