// Copyright 2005 by strip-him.com owner.

function standard_onload () {
	default_age_form();
	check_if_member();
	default_navigation();
}

var cookie_regexp = /AllSetToReturnTo=(\w+)/g;

function get_cookie () {
   var match = cookie_regexp.exec(document.cookie);
   if (!match) match = cookie_regexp.exec(document.cookie); // work around odd Firefox 1.5 behavior
   return match && match[1];
}

function get_return_cookie () {
	var cookie = get_cookie ();
	if (cookie == "NeedForm" || cookie == "NoScene") {return null} else {return cookie};
}

function set_cookie (new_content) {
       // appends to other cookies -- see http://developer.mozilla.org/en/docs/DOM:document.cookie
	document.cookie = "AllSetToReturnTo=" + new_content + "; path=/"; 
}

function submit_age_form(form) {
	var ok = good_to_go();
	set_cookie (ok?  this_scene() || "NoScene" : "NeedForm");
	if (good_to_go()) unhighlight_age_form(); 
}

function default_age_form () {
	var form = find_age_form();
	var cookie = get_cookie ();
	var check_all = (cookie && cookie != "NeedForm");
	if (form) {
		form.elements['over18'].checked = check_all;
		form.elements['legal'].checked = check_all;
		form.elements['accepted'].checked = check_all;
 	   }
}

function default_navigation () {
	var P = document.getElementById('partially');
	var T = document.getElementById('totally');
	if (P) P.checked = !paid();
	if (T) T.checked = paid();
}

var month_names = ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

var remember_notices_directory = '../../notices/';

function insert_age_form (notices_directory) {
	if (!notices_directory) notices_directory = '../../notices/';
	remember_notices_directory = notices_directory;
//        if (referred_internally ())  {
//	document.writeln ('<div class="age-form">When you entered this site, you stated that you are an adult, and you agreed to our <a href="'
//						 + notices_directory + 'terms.html">Terms of Service</a>.</div>');
//	} else {
	document.write ('<form id="age_form" class="age-form" onsubmit="submit_age_form(this); if (event.preventDefault) event.preventDefault(); return false;">');
	document.write('<input type="checkbox" name="over18" onchange="submit_age_form(this.form)">I declare that I am at least <b>18</b> years old.');
	document.write('<br>');
	document.write('<input type="checkbox" name="legal" onchange="submit_age_form(this.form)">I declare that there is <b>no law</b> against these materials being presented to me <b>where I am</b>.');
	document.write('<br>');
	document.write('<input type="checkbox" name="accepted" onchange="submit_age_form(this.form)"> I hereby agree to the <a href="' + notices_directory + 'terms.html">Terms of Service</a>.');
	document.write ('</form>');
//	}
}

function declared_over_18 () {
	var f = find_age_form();
	return f && f.elements['over18'].checked
}

function declared_legal () {
	var f = find_age_form();
	return f && f.elements['legal'].checked
}

function agreed_on_form () {
	var f = find_age_form();
	return f && f.elements['accepted'].checked
}

function good_to_go () {
	return (declared_over_18 () && declared_legal () && agreed_on_form());
}

function referred_internally () {
	return String(document.location).match(/\/\w+\//)  // not top-level
			&&
		(document.referrer.match(/http:\/\/strip\-him\.com/)
				|| document.referrer.match(/http:\/\/www\.strip\-him\.com/)
				)
			&&
		!document.referrer.match(/goto/)
			&&
		!document.referrer.match(/notices/)
			&&
		!document.referrer.match(/just-signed-in/);
}

function find_age_form () {
	return document.getElementById('age_form');
}

function highlight_age_form () {
    if (find_age_form())
	find_age_form().style.backgroundColor = "yellow";
}

function unhighlight_age_form () {
    if (find_age_form())
	find_age_form().style.backgroundColor = null;
}

var last_refusal; // avoid repeated calls from mouse-move

function refuse () {
	if (last_refusal && new Date () - last_refusal < 1000)
	  return false;
	last_refusal = new Date();
	highlight_age_form();
	if (!declared_over_18())
	  { if (!confirm("If you are an adult and would like to view this site, please check the box.  Otherwise, press Cancel."))
		location =  remember_notices_directory +  'adults-only.html'  }
	else if (!declared_legal())
	  { alert('Sorry, but this site is not meant to be viewed where it would violate your local laws.') }
	else if (!agreed_on_form())
	  { alert('You must agree to the Terms of Service before proceeding.') }
	else
	  { alert('Something went wrong in checking your age statement and Terms of Service agreement.') }
}

function check_age () {
	// check_age() && action_if_okay...
	if (good_to_go ()) {return true}
	else {refuse(); return false}
}

function insert_heading () {
      var targ = ""; // does not work in IE with referer/.htaccess
      if (navigator.userAgent.match(/gecko/i)) targ = ' target="_top"';
	document.write('<table cellspacing=20><tr>');
	document.write('<td><div class="header">')
	document.write('<a href="../" ' + targ + '><img src="../../art/logo.gif" class="logo" title="Pick another guy to strip" alt="strip-him.com"></a>');
	document.write('</div>');
	document.write('<div class="navigation">')
	document.write('<input type=radio id=partially onclick="goto_free_page()">PARTIALLY')
	document.write('<input type=radio id=totally onclick="join()">TOTALLY')
	document.write('<a href="../" ' + targ + '><img src="../../art/home.jpg" title="Pick another guy to strip" alt="(home)"></a>');
	document.write('<img src="../../art/email.jpg" onclick="email_a_bookmark()" title="Email a bookmark to a friend"  style="cursor:pointer">');
	document.write('</div><td>');
	insert_age_form();
	document.write('</table>');
}

function insert_footer  (notices_directory) {
	if (!notices_directory) notices_directory = remember_notices_directory;
	document.write('<div class="footer">');
	document.write('<a href="' + notices_directory + 'copyright.html">&#169; 2005</a> | ');
	document.write('<a href="' + notices_directory + 'adults-only.html">Adults only!</a> |');
	document.write('<a href="' + notices_directory + 'sec2257.html">&#167;2257</a> |');
	document.write('<a href="' + notices_directory + 'terms.html">Terms of Service</a> |');
	document.write('<a href="' + notices_directory + 'faq.html">FAQ</a> |');
	document.write('<a href="' + notices_directory + 'browser-requirements.html">Browser Requirements</a> |');
	document.write('<a href="' + notices_directory + 'privacy.html">Privacy</a> |');
	document.write('<a href="' + notices_directory + 'contact.html">Contact Us</a>');
	if (location.protocol == 'http:') insert_counter();
	document.write('</div>');
}

function paid () {
	return (!!String(location).match(/\/content\//)) || (!!String(location).match(/\/protect\//));
}

var delay_before_payment_message = 3000;

function trying_to_go_beyond_free_limits () {
	if (paid()) {return false}
	else {
		setTimeout("notify_about_payment()", delay_before_payment_message);
		return true;
	}}		

function notify_about_payment () {
	var message_node = document.getElementById('join');
	if (!message_node)
	  {alert_about_payment()}
	else {message_node.className = "join-hilighted"; window.scroll(0,0);}
}

function check_if_member () {
	var message_node = document.getElementById('join');
	if (message_node) {
	  if (paid()) {message_node.style.visibility = "hidden";}
	  else {message_node.className = "join";}
	}
}

var already_did_alert_about_payment = false;

function alert_about_payment () {
   if (!already_did_alert_about_payment)
	  alert("To go any further than this, you'll have to become a member.");
  already_did_alert_about_payment = true;
}

function this_scene () {
	var match = String(location).match(/.*\/(\w*\d\d\d)/);
        if (!match) {return null} else {return match[1]};
}

function join () {
	if (paid()) return false;
	var scene = this_scene();
	if (good_to_go()) set_cookie (scene);
	location = "http://strip-him.com/ugas-signup.html?ref=" + scene;
}

function goto_free_page () {
    if (paid()) location = free_page();
}

function free_page () {
	return String(location).replace(/content\//, "free/");
}

function email_a_bookmark () {
	var s =  "mailto:Fill_in_address_of_your_adult_friend_here@domain.name.etc";
	s += '?subject=' + escape('Check out this site:  strip-him.com');
	s += '&body=' + escape('(Type your personal message here.)\n\n'
				                        + '   ' + free_page() + '\n\n________________\nstrip-him.com is intended strictly for adults.');
        location = s;
}


function insert_counter () {
  // Disabled 10/6/06 since their web site has been down a week or two and I don't think it's been maintained for years.
}

function DISABLED_insert_counter () {
// from avscounter.com
var data, p;
var agt=navigator.userAgent.toLowerCase();
var img=escape("./buttons/b1.jpg");
// document.cookie='__support_check=1';
p='http';
if((location.href.substr(0,6)=='https:')||(location.href.substr(0,6)=='HTTPS:')) {p='https';} data = '&agt=' + escape(agt) + '&img=' + img + '&r=' + escape(document.referrer) + '&aN=' + escape(navigator.appName) + '&lg=' + escape(navigator.systemLanguage) + '&OS=' + escape(navigator.platform) + '&aV=' + escape(navigator.appVersion) + '&url=' + location.href;
if(navigator.appVersion.substring(0,1)>'3') {data = data + '&cd=' + screen.colorDepth + '&p=' + escape(screen.width+ 'x'+screen.height) + '&je=' + navigator.javaEnabled();};
document.write('<a href="http://www.avscounter.com/redir/index.php?a=2923472">');
document.write('<img width=40 height=20 align=right border=0 hspace=0 '+'vspace=0 src="http://www.avscounter.com/counter.php?a=2923472' + data + '"> </a>');
}
