/*
_________________________________________________________

Specific javascript functions for the thewriter.co.uk v3
_________________________________________________________

*/

var formatted_date;
SetFormattedDate();

function SetFormattedDate() {
	var today = new Date();
	var day = today.getDay();
	var date = today.getDate();
	var month = today.getMonth() + 1 ;
	var year = '';
	if ( day == 1 ) { day = 'Mon' }
	else if ( day == 2 ){ day = 'Tue'}
	else if ( day == 3 ){ day = 'Wed'}
	else if ( day == 4 ){ day = 'Thur'}
	else if ( day == 5 ){ day = 'Fri'}
	else if ( day == 6 ){ day = 'Sat'}
	else if ( day == 7 ){ day = 'Sun'}
	else { day = 'Day ?'}
	if ( month == 1 ) { month = 'January' }
	else if ( month == 2 ){ month = 'February'}
	else if ( month == 3 ){ month = 'March'}
	else if ( month == 4 ){ month = 'April'}
	else if ( month == 5 ){ month = 'May'}
	else if ( month == 6 ){ month = 'June'}
	else if ( month == 7 ){ month = 'July'}
	else if ( month == 8 ){ month = 'August'}
	else if ( month == 9 ){ month = 'September'}
	else if ( month == 10 ){ month = 'October'}
	else if ( month == 11 ){ month = 'November'}
	else if ( month == 12 ){ month = 'December'}
	else { month = 'Month ?'}
	if ( today.getFullYear() ) { year = today.getFullYear();  }
	formatted_date = new String ( day + ', ' + date + ' ' + month + ' ' + year);
}

function BrowserType()
{
	if ((navigator.appVersion.indexOf("Mac")!=-1)
			&& (navigator.userAgent.indexOf("MSIE")!=-1)
			&& (parseInt(navigator.appVersion)==3))
		this.ie3Mac = true;
	else {
		// Comparisons are easier in lowercase
		var agt=navigator.userAgent.toLowerCase();

		// On IE5, these return 4, so use.ie5up to detect IE5.
		this.major = parseInt(navigator.appVersion);
		this.minor = parseFloat(navigator.appVersion);
		this.opera = (agt.indexOf("opera") != -1);

		this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
					&& (agt.indexOf('compatible') == -1) && (! this.opera)
					&& (agt.indexOf('webtv')==-1));
		this.nav2 = (this.nav && (this.major == 2));
		this.nav3 = (this.nav && (this.major == 3));
		this.nav4 = (this.nav && (this.major == 4));
		this.nav4up = (this.nav && (this.major >= 4));
		this.navonly = (this.nav && ((agt.indexOf(";nav") != -1) ||
							  (agt.indexOf("; nav") != -1)));
		this.nav5 = (this.nav && (this.major == 5));
		this.nav5up = (this.nav && (this.major >= 5));
		this.nav6up = (this.nav && (agt.indexOf("gecko") != -1));

		this.ie   = ((agt.indexOf("msie") != -1)  && (! this.opera));
		this.ie3  = (this.ie && (this.major < 4));
		this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")==-1) && (agt.indexOf("msie 6")==-1));
		this.ie4up = (this.ie  && (this.major >= 4));
		this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")!=-1));
		this.ie6  = (this.ie && (this.major == 4) && (agt.indexOf("msie 6")!=-1));
		this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
	}
}
// Link the appropriate style sheet into the document:
var isBrowser = new BrowserType();

/*
-------------------------
images rollover functions
-------------------------
*/	
	
function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImage(layer,imgName,imgObj) {
	if (document.images) {
		//window.alert('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
		if (document.layers && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
		else document.images[imgName].src = eval(imgObj+".src")
	}
}

/*---------------------------------
Submit a form on a layer functions
---------------------------------*/	
function submitform()
	{
	if (ns4) document.layers['divform'].document.frm.submit();
	else if (ie4) document.frm.submit();
	}
	
/*
-------------------------
Misc functions
-------------------------
*/	
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
