//////////////////////////////
// start file
//
// JavaScript Tools
//
//
//////////////////////////////
// onclick="back()" 
function back(){history.go(-1)}
//////////////////////////////
// checkemail(email)
var testresults
function checkemail(emailtocheck){
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
 if (regex.test(emailtocheck)) {
    testresults=true
	}
 else {
    alert("Please input a valid email address ("+emailtocheck+") such as trinogamy@email.com!")
    testresults=false
	}
 return (testresults)
}
//////////////////////////////
// C frm check
function checkItC() {
var userName = document.theform.name.value;
var userEmail = document.theform.replyemail.value;
var userPurpose = document.theform.purpose.value;
var userSubject = document.theform.subject.value;
var userMessage = document.theform.message.value;

if(userName.length == 0 || userEmail.length == 0 || userPurpose.length == 0 || userSubject.length == 0 || userMessage.length == 0){
alert("Please enter the required information and try again.");
document.theform.name.focus();
return false
}else{
document.theform.action="email.php"
document.theform.method="POST";
document.theform.submit();
   } 
} 
//////////////////////////////
// r frm check
function checkItR() {
var userName = document.theRecommend.realname.value;
var userEmail = document.theRecommend.realemail.value;
var userPurpose = document.theRecommend.recipient1.value;
var userSubject = document.theRecommend.recipient2.value;
var userMessage = document.theRecommend.message.value;

if(userName.length == 0 || userEmail.length == 0 || userPurpose.length == 0 || userSubject.length == 0 || userMessage.length == 0){
alert("Please enter the required information and try again.");
document.theRecommend.realname.focus();
return false
}else{
document.theRecommend.action="<?php echo $PHP_SELF?>"
document.theRecommend.method="POST";
document.theRecommend.submit();
   } 
} 
//////////////////////////////
// se frm check
function checkItSE() {
var qe = document.theSearch.q.value; 

if(qe.length == 0){
alert("Please enter the required information and try again.");
document.theSearch.q.focus();
return false
}else{ 
document.theSearch.action="http://www.google.com/custom"
document.theSearch.method="GET";
document.theSearch.submit();
   } 
} 
//////////////////////////////
// su frm check
function checkItS() {
var name = document.theSubscribe.name.value;
var email = document.theSubscribe.email.value; 

if(name.length == 0 || email.length == 0){
alert("Please enter the required information and try again.");
document.theSubscribe.name.focus();
return false
}else{
document.theSubscribe.action="http://www.trinogamy.org/php/newsletter/register.php"
document.theSubscribe.method="POST";
document.theSubscribe.submit();
   } 
} 
//////////////////////////////
// su2 frm check
function checkItSU() {
var name = document.theSubscriber.name.value;
var email = document.theSubscriber.email.value; 

if(name.length == 0 || email.length == 0){
alert("Please enter the required information and try again.");
document.theSubscriber.name.focus();
return false
}else{
document.theSubscriber.action="php/newsletter/register.php"
document.theSubscriber.method="POST";
document.theSubscriber.submit();
   } 
}  
//////////////////////////////
// unsub frm check
function checkItDl() {
var file = document.theDownloader.file.value;
var name = document.theDownloader.name.value; 
var email = document.theDownloader.email.value; 

if(file.length == 0 || name.length == 0 || email.length == 0){
alert("Please enter the required information and try again.");
document.theDownloader.name.focus();
return false
}else{
document.theDownloader.action="http://www.trinogamy.org/php/download/download.php"
document.theDownloader.method="POST";
document.theDownloader.submit();
   } 
} 
//////////////////////////////
// unsub frm check
function checkItuS() {
var name = document.theunSubscribe.name.value;
var email = document.theunSubscribe.email.value; 

if(name.length == 0 || email.length == 0 ){
alert("Please enter the required information and try again.");
document.theunSubscribe.name.focus();
return false
}else{
document.theunSubscribe.action="php/newsletter/unsubscribe.php"
document.theunSubscribe.method="POST";
document.theunSubscribe.submit();
   } 
} 
//////////////////////////////
// unsub contact frm check
function checkItuSc() {
var fullname = document.theunSubscribecontact.fullname.value;
var fullemail = document.theunSubscribecontact.fullemail.value; 
var fullmessage = document.theunSubscribecontact.fullmessage.value; 

if(fullname.length == 0 || fullemail.length == 0 || fullmessage.length == 0){
alert("Please enter the required information and try again.");
document.theunSubscribecontact.fullname.focus();
return false
}else{
document.theunSubscribecontact.action="php/newsletter/contact.php"
document.theunSubscribecontact.method="POST";
document.theunSubscribecontact.submit();
   } 
} 
//////////////////////////////
// submit frm check
function checkItSUB() {
var submitwebsite = document.theSubmiter.submitwebsite.value;
var submitemail = document.theSubmiter.submitemail.value; 

if(submitwebsite.length == 0 || submitemail.length == 0){
alert("Please enter the required information and try again.");
document.theSubmiter.submitwebsite.focus();
return false
}else{
document.theSubmiter.action="php/submit/submit.php"
document.theSubmiter.method="POST";
document.theSubmiter.submit();
   } 
} 
//////////////////////////////
// submit frm check
function checkItE() {
var subname = document.theEditor.subname.value;
var subemail = document.theEditor.subemail.value; 
var subusername = document.theEditor.subusername.value;
var subpassword = document.theEditor.subpassword.value; 

if(subname.length == 0 || subemail.length == 0 || subusername.length == 0 || subpassword.length == 0 ){
alert("Please enter the required information and try again.");
document.theEditor.subname.focus();
return false
}else{
document.theEditor.action="php/editor/editor.php"
document.theEditor.method="POST";
document.theEditor.submit();
   } 
} 
//////////////////////////////
//  frm check
function checkItCO() {
var fullemail = document.theContacter.fullemail.value;
var fullname = document.theContacter.fullname.value; 
var fullmessage = document.theContacter.fullmessage.value; 

if(fullemail.length == 0 || fullname.length == 0 || fullmessage.length == 0 ){
alert("Please enter the required information and try again.");
document.theContacter.fullname.focus();
return false
}else{
document.theContacter.action="php/contact/contact.php"
document.theContacter.method="POST";
document.theContacter.submit();
   } 
} 
//////////////////////////////
// Add to favorites
function addToFavorites() { 
	var url = location.href; 
	var title = document.title;
  	if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  		window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  }
   else if (window.external) {
		var urlAddress = location.href; 
		var pageName = document.title;
		window.external.AddFavorite(urlAddress,pageName) ;
  }
  else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  } 
    alert("Press CTRL-D or CTRL-T to bookmark"); 
} 
//////////////////////////////
// Change Language
function setLanguage(target) {
		var currentURL=location.href;
		var endT=currentURL.lastIndexOf('.');
		var startT=currentURL.lastIndexOf('_')+1;
		var setURL=currentURL.substr(0,startT)+target+currentURL.substr(endT);
		//var trace="setURL + "+setURL;
		//alert(trace);
		location.href=setURL;
}
//////////////////////////////
// Spam free mailto for addresses inside tri.int link to "javascript:sendTriMail('test');"
function sendTriMail(user) {
		var mailString=user+'@trinogamy.org';
		var mailString=mailString+'?subject=Message from Trinogamy';
		location.href('mailto:'+mailString);
}
// Spam free mailto link to "javascript:sendMail('info','trinogamy.org');"
function sendMail(user,domain) {
		var mailString=user+'@'+domain;
		var mailString = mailString+'?subject=Message from Trinogamy';
		location.href('mailto:'+mailString);
}
//////////////////////////////
// displays randomly one image from a list of images
// Advanced Random Images Start
// Copyright 2001-2006 All rights reserved, by Paul Davis - www.kaosweaver.com
function randomImage() {
  var j,d="",l="",m="",p="",q="",z="",KW_ARI= new Array()
  KW_ARI[KW_ARI.length]='/ads/random/134x45_01.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_02.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_03.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_04.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_05.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_06.jpg';
  
  KW_ARI[KW_ARI.length]='/ads/random/balloons.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/barley02.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/island.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/polution.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/sealpup.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/ship_1.jpg';
  
  KW_ARI[KW_ARI.length]='/ads/random/134x45_07.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_08.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_09.jpg';
  KW_ARI[KW_ARI.length]='/ads/random/134x45_10.jpg';
    
  j=parseInt(Math.random()*KW_ARI.length);
  j=(isNaN(j))?0:j;
    document.write("<img src='"+KW_ARI[j]+"' height='45'>");
}
// Advanced Random Images End
//////////////////////////////
// last modified
function lastMod() {
	var x = new Date (document.lastModified);
	Modif = new Date(x.toGMTString());
	Year = takeYear(Modif);
	Month = Modif.getMonth();
	Day = Modif.getDate();
	Mod = (Date.UTC(Year,Month,Day,0,0,0))/86400000;
	x = new Date();
	today = new Date(x.toGMTString());
	Year2 = takeYear(today);
	Month2 = today.getMonth();
	Day2 = today.getDate();
	now = (Date.UTC(Year2,Month2,Day2,0,0,0))/86400000;
	daysago = now - Mod;
	if (daysago < 0) return '';
	unit = 'days';
	if (daysago > 730) 	{
		daysago = Math.floor(daysago/365);
		unit = 'years';
	}
	else if (daysago > 60) {
		daysago = Math.floor(daysago/30);
		unit = 'months';
	}
	else if (daysago > 14) {
		daysago = Math.floor(daysago/7);
		unit = 'weeks'
	}
	var towrite = 'Page last changed ';
	if (daysago == 0) towrite += 'today';
	else if (daysago == 1) towrite += 'yesterday';
	else towrite += daysago + ' ' + unit + ' ago';
	return towrite;
}
function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}
//////////////////////////////
// end file
//////////////////////////////
