window.onerror = function( _message, _url, _line ) {
	var Val = "";
	Val += "&Msg=" + urlEncode( _message );
	Val += "&Line=" + _line;
	Val += "&URL=" + urlEncode( _url );
	Val += "&QS=" + urlEncode( location.search );
	Val += "&Location=" + urlEncode( location.pathname );
	Val += "&Referer=" + urlEncode( document.location.href );
	Val += "&HTTPRef=" + urlEncode( document.referrer );
	Val += "&Browser=" + urlEncode( navigator.userAgent + " : " + navigator.appName + " : " + navigator.appVersion );
	if( window.XMLHttpRequest )
		this.req = new XMLHttpRequest();
	else if( window.ActiveXObject )
		this.req = new ActiveXObject( "Microsoft.XMLHTTP" );
	else
		return;
	this.req.open( "POST", "/jslog.php", true );
	// this.req.setRequestHeader("content-type", "text/plain");
	this.req.setRequestHeader( "Content-type", "application/x-www-form-urlencoded" );
	this.req.setRequestHeader( "Content-length", Val.length );
	this.req.setRequestHeader( "Connection", "close" );
	this.req.send( Val );
}

if (top.location != location) {
	top.location.href = document.location.href;
}

function urlEncode( clearString ) {
	var output = '';
	var x = 0;
	clearString = clearString.toString();
	var regex = /(^[a-zA-Z0-9_.]*)/;
	while( x < clearString.length ) {
		var match = regex.exec( clearString.substr( x ) );
		if( match != null && match.length > 1 && match[ 1 ] != '' ) {
			output += match[ 1 ];
			x += match[ 1 ].length;
		} else {
			if( clearString[ x ] == ' ' )
				output += '+';
			else {
				var charCode = clearString.charCodeAt( x );
				var hexVal = charCode.toString( 16 );
				output += '%' + ( hexVal.length < 2 ? '0' : '' )
						+ hexVal.toUpperCase();
			}
			x++;
		}
	}
	return output;
}

d = document;
n = navigator;
w = window;

function addToBookmarks() {
	clientBrowser = n.userAgent.toLowerCase();
	if( d.layers || n.product == 'Gecko' ) { //Netscape 4, Gecko engine (Mozilla, Netscape 6+, etc)
		alert( 'Press Ctrl+D to Bookmark Us!' );
	} else if( d.getElementById || d.all
			|| ( clientBrowser.indexOf( 'msie' ) + 1 ) && w.ActiveXObject ) { //Internet Explorer 5+, Internet Explorer 4, Pocket Internet Explorer
		w.external.AddFavorite( "http://www.vivid.com",
				"Welcome to the all new Vivid.com!" );
	} else { //Unknown Browser
		alert( 'Don\'t forget to Bookmark Us in your Browser!' );
	}
}

navImages = [ '/images/nav_btn_aff_home_over.jpg',
		'/images/nav_btn_aff_girls_over.jpg',
		'/images/nav_btn_aff_videos_over.jpg',
		'/images/nav_btn_aff_news_over.jpg',
		'/images/nav_btn_aff_members_over.jpg',
		'/images/nav_btn_search_over.jpg',
		'/images/nav_btn_aff_access_over.jpg' ];

w.onload = function() {
	preload( navImages );
}

function preload( imgArray ) {
	imgObj = new Image();
	for( i = 0; i < imgArray.length; i++ ) {
		imgObj.src = imgArray[ i ];
	}
}

function year() {
	date = new Date().getYear();
	d.write( ( date < 1000 ) ? date + 1900 : date );
}

function bioLength( which ) {
	d.getElementById( 'bio' ).className = ( which == 0 ) ? 'bio_open'
			: 'bio_closed';
	d.getElementById( 'biolink' ).innerHTML = ( which == 0 ) ? '<a class="bio" href="#" onclick="bioLength(1);return false;">Show less bio &#9650;</a>'
			: '<a class="bio" href="#" onclick="bioLength(0);return false;">Show more bio &#9660;</a>';
}

function movieinfoLength( which ) {
	d.getElementById( 'movieinfo' ).className = ( which == 0 ) ? 'movieinfo_open'
			: 'movieinfo_closed';
	d.getElementById( 'biolink' ).innerHTML = ( which == 0 ) ? '<a class="bio" href="#" onclick="movieinfoLength(1);return false;">Show less info &#9650;</a>'
			: '<a class="bio" href="#" onclick="movieinfoLength(0);return false;">Show more info &#9660;</a>';
}

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;
}

if( !readCookie( 'nats' ) ) {

	var natsFound	= false;
	var natsVal		= "";
	var qv	= new Array();
	var p	= window.location.search.substring( 1 ).split( "&" );

	for( var i = 0; i < p.length && !natsFound; i++ ) {
		var pos = p[ i ].indexOf( "=" );
		if( pos > 0 ) {
			var pn = p[ i ].substring( 0, pos );
			var pv = p[ i ].substring( pos + 1 );
			switch( pn ) {
				case "nats":
					natsVal		= pv;
					natsFound	= true;
				break;
			}
		}
	}

	$.get(
		"/inline.warning.php?nats=" + natsVal + "&referrer=" + escape( document.referrer ),
		function( data ) {
			$( document.body ).append( data );
			$( "#warningDisplay > .blocker:first" ).height( $( document ).height() );
		}
	);

}


$(document).ready(function() {
	$("[onLeftEmpty]").focus(function(){
		if($(this).val()==$(this).attr("onLeftEmpty")) $(this).val("");
	}).blur(function(){
		if($(this).val()=="") $(this).val($(this).attr("onLeftEmpty"));
	}).blur();
});