// Common JavaScript

<!-- Preload Partner images
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_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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];}
}
//-->

<!--//SHOW HIDE CODE
function showhide(layer_ref){
	state = document.getElementById(layer_ref).style.display;
	if (state == 'none') {
			state = ''; 
	} else {
			state = 'none';
	}
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.display = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].display = state; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.display = state; 
	}
}
//-->

<!--//SWAP contents of a tag
function swap(me,main,alt) {
	me.innerHTML = (me.innerHTML == main) ? alt : main;
}
//-->

<!--//toggle list images
function toggle_li_image(layer_ref,ROOT){
	state = document.getElementById(layer_ref).className;
	if (state == 'li_class_down') {
			state = 'li_class_up'; 
	} else {
			state = 'li_class_down';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".className = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].className = state; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.className = state; 
	}
	/*
	state = document.getElementById(layer_ref).style.background;
	if (state == 'transparent url('+ROOT+'0-common/images/left_nav/li_down.gif) no-repeat scroll 0% 0%' || state == 'url('+ROOT+'0-common/images/left_nav/li_down.gif) no-repeat') {
			state = 'transparent url('+ROOT+'0-common/images/left_nav/li_up.gif) no-repeat scroll 0% 0%'; 
	} else {
			state = 'transparent url('+ROOT+'0-common/images/left_nav/li_down.gif) no-repeat scroll 0% 0%';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.background = state");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].background = state; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.background = state; 
	}
	*/
}
//-->

<!--//send menu status to php session data file
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
var http = createRequestObject();
function save_nav(section, ROOT) {
	
	if(initialstate[section] == 1){
		newstate = 0;
	} else {
		newstate = 1;
	}
	initialstate[section] = newstate;
	url = ROOT+'0-common/scripts/nav_session.php?'+section+'='+newstate;
    http.open('get', url);
    http.send(null);
}
//-->

<!--// Check Login for empty fields etc
function checklogin(){
	if(document.getElementById('login_username').value == '' || document.getElementById('login_username').value == 'username'){
		alert('Please enter a username');
		document.getElementById('login_username').focus();
		return false;
	} else if(document.getElementById('login_password').value == ''){
		alert('Please enter a password');
		document.getElementById('login_password').focus();
		return false;
	} else {
		return true;
	}
}
function checklogin2(){
	if(document.getElementById('pagelogin_username').value == '' || document.getElementById('pagelogin_username').value == 'username'){
		alert('Please enter a username');
		document.getElementById('pagelogin_username').focus();
		return false;
	} else if(document.getElementById('pagelogin_password').value == ''){
		alert('Please enter a password');
		document.getElementById('pagelogin_password').focus();
		return false;
	} else {
		return true;
	}
}
//-->


<!--// Toggle size of YouTube Video
function togglesize(object_id, embed_id){
	if(document.getElementById(object_id).width == '150'){
		size = 'small';
	} else if(document.getElementById(object_id).width == '300'){
		size = 'medium';
	} else if(document.getElementById(object_id).width == '600'){
		size = 'large';
	}
	
	if(size == 'small'){ width = 300; height = 250; }
	if(size == 'medium'){ width = 600; height = 500; }
	if(size == 'large'){ width = 150; height = 124; }
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + object_id + ".width = width");
		eval( "document.all." + object_id + ".height = height");
		eval( "document.all." + embed_id + ".width = width");
		eval( "document.all." + embed_id + ".height = height");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[object_id].width = width;
		document.layers[object_id].height = height;
		document.layers[embed_id].width = width;
		document.layers[embed_id].height = height; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(object_id);
		hza.width = width; 
		hza.height = height;
		hza2 = document.getElementById(embed_id);
		hza2.width = width; 
		hza2.height = height;
	}
}
//-->

<!--// Pop-up windows
var popUpWin=0;
function popup(URLStr, width, height){
  if(width == ''){
	  width = 700;
  }
  if(height == ''){
	  height = 600;
  }
  if(popUpWin){
    if(!popUpWin.closed){
		popUpWin.close();
	}
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+'px,height='+height+'px,left=100px, top=100px,screenX=100px,screenY=100px');
}
//-->


<!--// Image Resizing in popup
function toggleimgstretch(layer_ref){
	size = document.getElementById(layer_ref).style.width;
	if (size == 'auto') {
			size = '95%'; 
			windowwidth = 300;
			windowheight = 350;
			windowposx = 100;
			windowposy = 100;
	} else {
			size = 'auto';
			windowwidth = screen.width;
			windowheight = screen.height;
			windowposx = 0;
			windowposy = 0;
	}
	
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.width = size");
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].width = size; 
	}
	if (document.getElementById &&!document.all) {
		hza = document.getElementById(layer_ref);
		hza.style.width = size; 
	}
	self.resizeTo(windowwidth, windowheight);
	self.moveTo(windowposx, windowposy);
}
//-->


<!--// Adding form fields into slideshow edit
var counter = 0;
function newslideshowimage() {
	counter++;
	var newFields = document.getElementById('slideshow_img_fields_table').cloneNode(true);
	newFields.id = 'slideshow_img_fields_table'+counter; //used to be = ''
	newFields.style.display = 'table';
	var newField = newFields.childNodes;
	for (var i=0;i<newField.length;i++) {
		var theName = newField[i].name
		if (theName)
			newField[i].name = theName + counter;
	}
	var insertHere = document.getElementById('writeroot');
	insertHere.parentNode.insertBefore(newFields,insertHere);
}
//-->


<!--// Intro films etc on homepage
var short_intro = 1;
var full_intro = 0;
function change_intro($in) {
	if($in == "short_intro" && short_intro == 1){
		$('#short_intro').Pulsate(100,3);
		return false;
	}
	if($in == "full_intro" && full_intro == 1){
		$('#full_intro').Pulsate(100,3);
		return false;
	}
	if($in == "short_intro" && short_intro == 0){
		$('#full_intro').SlideOutLeft(500);
		setTimeout('$(\'#short_intro\').SlideInLeft(500)', 500);
		short_intro = 1;
		full_intro = 0;
		return false;
	}
	if($in == "full_intro" && full_intro == 0){
		$('#short_intro').SlideOutLeft(500);
		setTimeout('$(\'#full_intro\').SlideInLeft(500)', 500);
		short_intro = 0;
		full_intro = 1;
		return false;
	}
}
//-->


<!--// Basic / Advanced link on search page
function searchmode() {
	showhide('advanced_search');
	document.getElementById('case').checked = 0;
	document.getElementById('mode').selectedIndex = 0;
	swap(document.getElementById('advancedlink'),'Basic Search','Advanced Search');
}
//-->