/**
** site.scripts.php
** contains site-wide javascripts
**
** Written by Doug Hammond, for Develop.
**
** Jan 2007
**
*****************************************/
var c_fs_amount = 0;

//switch element colours (rollovers)
function RollOver(id,col) {
	//I DON'T THINK THIS FUNCTION IS USED ANY LONGER
	x = document.getElementById(id);
	x.style.backgroundColor = col;
	
	/*
	//maybe this jQuery would look nicer ?
	$('#'+id).animate({
		background-color: col
		}, 'slow');
	*/
}

//show/hide an element (hidden login form)
function ToggleVis(id) {
	if ($('#'+id).css("display")=='block') {
		$('#'+id).hide('normal');		//this is a jQuery command!
	} else {
		$('#'+id).show('normal',function(){
			
		});		
	}
}

//change the font size on specified tags (li,p,td,th)
//also remembers setting across page views
function FontSizeAdjust(amount) {
   c_fs_amount += parseInt(amount,10);
   var min=8;
   var max=18;
   //alert (c_fs_amount);
   //if (c_fs_amount<min) c_fs_amount = min;
   //if (c_fs_amount>max) c_fs_amount = max;
   var els = new Array("li","p","td","th");
   for(i=0;i<els.length;i++) {
	   p = document.getElementsByTagName(els[i]);
	   for(j=0;j<p.length;j++) {
		  if(p[j].style.fontSize) {
			 var s = parseInt(p[j].style.fontSize.replace("pt",""));
		  } else {
			 var s = 12;
		  }
		  s += amount;
		  if ((s>=min) && (s<=max)) p[j].style.fontSize = s+"pt";
	   }
   }
   
   createCookie("dev_font_size",c_fs_amount,365);
}

//cookie helper function
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//cookie helper function
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;
}
//cookie helper function
function eraseCookie(name) {
	createCookie(name,"",-1);
}

//restore the last font size when the page refreshes
function RestoreFontPref() {
	var fs = readCookie('dev_font_size');
	c_fs_amount = 0;

	if (fs) {
		//c_fs_amount = parseInt(fs,10);
		//alert(fs);
		return FontSizeAdjust(parseInt(fs,10));
	}
}

//confirm form actions
function confirmSubmit(msg) {
	var agree=confirm(msg);
	if (agree)
		return true ;
	else
		return false ;
}

//confirm link click
function confirmLink(msg,url) {
	var agree=confirm(msg);
	if (agree) location = url ;
}

//send form data on return  - also disable sumbit button
//to prevent sending data twice
function submitenter(frm,myfield,e) {
	var theform = document.frm;
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13)
	   {
	   myfield.form.submit();
	   theform.libutton.value='[Please Wait]';
	   theform.libutton.disabled=true;
	   return false;
	   }
	else
	   return true;
}

//called from file_chooser.php - updates form fiels with chosen file
function returnFile(file) {
	document.myFrm.link.value = document.myFrm.link.value  + file + "\n";
    //self.close();
	tb_remove();
    return false;	
}

//open a new window
function newWindow(file,window) {
    msgWindow=open(file,window,'resizable=no,width=800,height=400');
    if (msgWindow.opener == null) msgWindow.opener = self;
}

function AdminLinkHelp(refLink,helpobj) {
	var ho = document.getElementById(helpobj);
	ho.innerHTML = refLink.title;
}