
// Must have jQuery 1.4.2 included...
// Must have clientdetails.js included...

var clientDetails = null;

$( document ).ready( function() {
	
	targetReplacer();
	stripeTables();
	
	clientDetails = new ClientDetails( true );
	
});
		

function LOG( s ) {
	console.innerHTML += "<p> | " + s + " | </p>";
}

function targetReplacer() {
 if (!document.getElementsByTagName) return;
 var anchorTags = document.getElementsByTagName("a");
  for (var i=0; i<anchorTags.length; i++) {
   var anchor = anchorTags[i];
   if (anchor.getAttribute("href") &&
	   anchor.getAttribute("rel") == "blank")
	 anchor.target = "_blank";
 }
}

function makeClickable( element, url ) {

	var elem = document.getElementById( element );
	elem.onclick = function() { window.location = url; }
	
}

function show_em_addr( nm, dm, ex, ky ) {

	var keyId = document.getElementById( nm+ky );
	keyId.setAttribute("href", "m"+"ai"+"l"+"t"+"o"+":"+nm+"@"+dm+"."+ex);
	keyId.appendChild( document.createTextNode( nm+"@"+dm+"."+ex ) );
	
	var imgId = document.getElementById( ky );
	imgId.style.visibility = "hidden";

}

function stripeTables() {

	if( !document.getElementsByTagName ) return false;
	var tableElems = document.getElementsByTagName( "table" )
	for( var i = 0; i < tableElems.length; i++ ) {
	
		var odd = false;
		var rows = tableElems[ i ].getElementsByTagName( "tr" );
		for( var j = 0; j < rows.length; j++ ) {
			
			if( rows[ j ].className != "highlight" ) {
				
				if( odd == true ) {
					addClass( rows[ j ], "odd" );
					odd = false;	
				} else {
					odd = true;
				}
				
			}
			
		}
		
	}
	
}

function clearFieldOnFocus( field ) {
	
	var formField;

	if( typeof field == "string" ) {
	
		if( document.getElementById( field ) ) {
	
			formField = document.getElementById( field );
			
		} else { return }
	
	}
	
	if( formField.value ) { formField.onfocus = function() { formField.value = ""; } }

}

function addClass( element, value ) {
	
	if( !element.className ) {
		
		element.className = value;
		
	} else {
		
		newClassName = element.className;
		newClassName += " ";
		newClassName += value;
		element.className = newClassName;
		
	}
	
}

function getWinWidth() {
	
	if( window.innerWidth ) return window.innerWidth;
	else if( document.documentElement ) return document.documentElement.offsetWidth;
	else if( document.body.clientWidth ) return document.body.clientWidth;
	
	else return 0;

}

function getWinHeight() {
	
	if( window.innerHeight ) return window.innerHeight;
	else if( document.documentElement ) return document.documentElement.offsetHeight;
	else if( document.body.clientHeight ) return document.body.clientHeight;
	
	else return 0;
	
}

function getWinPosLeft() { return (document.all)?window.screenLeft:window.screenX; }
function getWinPosTop() { return (document.all)?window.screenTop:window.screenY; }

function winOpen( url, name, w, h ) {

	w += 32;
	h += 96;
	var win = window.open( url,
								   name,
								  'width=' + w + ', height=' + h + ', ' +
								  'location=no, menubar=no, ' +
								  'status=no, toolbar=no, scrollbars=yes, resizable=no' );
	
	xPos = ( getWinWidth()/2 ) + getWinPosLeft() - ( w/2 );
	win.resizeTo(w, h);
	win.moveTo( xPos, 50 );
	win.focus();
	
}

function createCookie( name, value, days ) {
	
	if (days) {
	
		var date = new Date();
		date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
		var expires = "; expires=" + date.toGMTString();
		
	} else {
	
		var expires = "";
		
	}
	
	document.cookie = name + "=" + value + expires + "; path=/";
	
}

function readCookie( name ) {

	var nameEQ = name + "=";
	var ca = document.cookie.split( ';' );
	
	for( var i = 0; i < ca.length; i++ ) {
	
		var c = ca[ i ];
		while( c.charAt( 0 ) == ' ' ) {
		
			c = c.substring( 1, c.length );
			
		}
		
		if ( c.indexOf( nameEQ ) == 0 ) return c.substring( nameEQ.length, c.length );
	}
	
	return null;
	
}

function eraseCookie( name ) {

	createCookie( name, "", -1 );
	
}

function getCurrentTime() {
	
	var d = new Date();
	return d.getTime();
	
}

function addEventHandler( node, evt, func, capt ) {
	
	if( typeof( window.event ) != "undefined" ) {
		
		node.attachEvent( "on" + evt, func );
		
	} else {
		
		node.addEventListener( evt, func, capt );
		
	}
	
}

function getEventTarget( e ) {
	
	if( window.event != null ) {
		
		return window.event.srcElement;
		
	} else {
		
		return e.target;
		
	}
	
}










