//All scripts Copyright 2005 The Digital Practice unless noted. All Rights Reserved. Use without written consent
//prohibited. Limited license to use script granted to SimGlobal.
//For more information contact matej@thedigitalpractice.com

//General Script for opening new windows
newwin=new Object;
newwin.closed=true;
function windowOpener(title,body,width,height) {
	if(!newwin.closed) {
		newwin.close();
		}
	   height=parseInt(height)+10
	   newwin=window.open("","","scrollbars=0,status=0,resizable=0,width="+width+",height="+height);
	   newwin.document.write('<html>\n<head>\n<title>'+title+'</title>\n<style>\na { text-decoration: none; color: 666699; font-family: arial, sans-serif }\na:hover { text-decoration: underline; color: 666699 }\n</style>\n</head>\n');
	   newwin.document.write('<body bgcolor="#ffffff">\n<font face="arial" color="#000000">\n<center>\n');
	   newwin.document.write(body+'\n');
	   newwin.document.write('</font></center>\n</body>\n</html>');
}
//Figure out the date
function theDate() {
	the_month=new Array()
		the_month[0]="January"
		the_month[1]="February"
		the_month[2]="March"
		the_month[3]="April"
		the_month[4]="May"
		the_month[5]="June"
		the_month[6]="July"
		the_month[7]="August"
		the_month[8]="September"
		the_month[9]="October"
		the_month[10]="November"
		the_month[11]="December"
	right_now=new Date();
	year=right_now.getFullYear();
	var month=the_month[right_now.getMonth()];
	var the_date=right_now.getDate();
	var full_date=month+" "+the_date+", "+year;
	return full_date;
}
//Figure out the day of the year
function dayOfYear() {
	var next_year=year+1;
	var this_time=right_now.getTime();
	var ever_since=Date.parse("1 Jan "+year+" 00:00:00");
	var end_year=Date.parse("1 Jan "+next_year+" 00:00:00");
	var days_past=this_time - ever_since;
	var days_togo=end_year - this_time;
	var past= parseInt(days_past / 86400000);
	var tocome= parseInt(days_togo / 86400000);
	past=past+1;
	//The following chooses an ender for the day number
	   past=""+past+"";
	   var num_pos=past.length-1;
	   var check_end=past.charAt(num_pos);
	   var conf_end=past.substring(num_pos-1, num_pos+1);
	   var ender="<sup>th</sup>";
	   if (check_end==1 && conf_end != 11) {
	       ender="<sup>st</sup>";
	       }
	   else if (check_end==2 && conf_end !=12) {
	       ender="<sup>nd</sup>";
	       }
	   else if (check_end==3 && conf_end !=13) {
	       ender="<sup>rd</sup>";
	       }
	
	if (tocome==0) {
	var day_of_yr="Today is the "+past+ender+" day of the year, tomorrow starts "+next_year+".";
	}
	else {
	var day_of_yr="Today is the "+past+ender+" day of the year, with "+tocome+" days remaining in "+year+".";
	}
	return day_of_yr;
}

//Add to favorites script
var browsercheck="false";
var linewrite="";
if (navigator.appName == "Microsoft Internet Explorer") {
browsercheck="true";
}
if (browsercheck=="true") {
var linewrite="<a href=\"#\" onclick=\"addFavorites(); return false;\" class=\"drklnk\">Make SimGlobal.net a favorite!</a>";
}
function addFavorites() {
window.external.AddFavorite("http://www.simglobal.net/home.shtml","SimGlobal-The Sim World at your Fingertips");
}

//Translate SimGlobal Script
function translateGlobal(lang) {
	var url=window.location.href;
	var net=url.lastIndexOf('%2F');
	if (net==-1) {
		net=url.lastIndexOf('/');
		var page=url.substring(net+1, url.length);
	}
	else {
	var page=url.substring(net+3, url.length);
	}
	if(lang=="#translator") {
		window.location=lang;
	}
	else {
window.location="http://babelfish.altavista.com/babelfish/urltrurl?lp=en_"+lang+"&url=http%3A%2F%2Fwww.simglobal.net%2F"+page;
	}
}

//Checks contact page submissions for illegal submissions
function checkForm() {
	var name=document.contact.name.value;
	var email=document.contact.email.value;
	var text=document.contact.Text.value;
	var at=email.indexOf("@");
	var per=email.lastIndexOf(".");
	var bad_char="!#$%^&*()/:;,+[]{}\|";
	var err_str="";
	var chartst="";
	var is_illegal=false;
//Checks for illegal chars in email
	for (var loop=0; loop<bad_char.length; loop++) {
		chartst=bad_char.charAt(loop);
		if (email.indexOf(chartst)!=-1) is_illegal=true; 
		}
//Email Check Below
	if ((at==-1) || (at==0) || (per==-1) || (per==at+1) || (per==email.length-1) || (is_illegal)) {
		err_str += "Your E-Mail address is invalid. \n";
	        }
//Check to see if there is anything in the name an text fields
	if (name==" " || name=="") {
		err_str +="You have not entered a name. \n";
		}
//Check to see if there is anything in the text box
	if (text==" " || text=="") {
		err_str +="You have not entered any text to your e-mail. \n";
		}
	if (err_str=="") return true;
	else {
		err_str="The validator has found the following problem(s) with your submission: \n"+err_str;
		alert(err_str);
		return false;
		}
	}