// Positions the footer at the bottom of the page
var OriginalFooterY=0;
function PositionFooter(){
	
	// This function uses functions found in inc/dynapi.js
	
	// Get reference to footer layer
	var fd=gE("FooterDiv");
	
	// Set original footer y-coordinate
	// OR move footer to original y-coordinate (allow correct positioning after resize)
	if(OriginalFooterY==0){
		OriginalFooterY=gY(fd);
	}else{
		sY(fd,OriginalFooterY);
	}
	
	// Find bottom y-coordinate
	var b=docH()-gH(fd);

	// If footer is above the bottom co-ordinate then resposition the footer bar
	if(gY(fd)<b) sY(fd,b);
	
	// Reveal footer
	sE(fd);

}

// Show search tips
function ShowSearchTips(){

	var strSearchHints=""+
		"Try the following to filter your documents more effectively:	\n" +
		"\n"+
		"\"exact phrase\"\n"+
		"Type your keywords in quotations to view records \n"+
		"only containing that exact phrase.\n"+
		"\n"+		
		"word1 OR word2\n"+
		"Type OR between your keywords if records should \n"+
		"be displayed containing either of the words.\n"+
		"\n"+
		"word1 AND word2\n"+
		"Type AND between your keywords if records should \n"+
		"be displayed containing all of your keywords\n"+
		"\n"+
		"Combinations\n"+
		"You can combine these search patterns for greater \n"+
		"search control – eg type \"exact phrase\" OR word1";
	alert(strSearchHints);
	
}

// Display pop-up to confirm deletion
function ConfirmDelete(u){
	ConfirmAction("Are you sure you want to delete this record?",u);
}

// Display pop-up to confirm action
function ConfirmAction(t,u){
	if(confirm(t)) location.href=u;
}

// Checks for a valid email address by string format
function ValidEmail(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1)return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;
}

// Check extension of file
function ValidExtension(Extensions,Filename){
	
	// Ignore if extension of filename is not provided
	if(Extensions=="" || Filename=="") return false;

	// Create an array of the valid extensions
	var ArrExtensions=Extensions.toString().split(",");

	// Get the extension of the supplied file
	var ArrFilename=Filename.toString().split(".");
	var SuppliedExtension=ArrFilename[ArrFilename.length-1];
	
	// Check that the extension of the supplied filename is valid
	for(var i=0;i<ArrExtensions.length;i++){
		
		// Extension is valid
		if(ArrExtensions[i].toLowerCase()==SuppliedExtension.toLowerCase()) return true;		
		
	}
	
	// Extension not valid
	return false;	
	
}

// Send an HTTP request to the server
function MakeHTTPRequest(url,fn){

	// Declare request variable
	var req;

	// Support for native object
	if(window.XMLHttpRequest){
		
		req=new XMLHttpRequest();
        req.onreadystatechange=fn;
        req.open("GET",url,true);
        req.send(null);

	// Windows/IE ActiveX object
	}else if(window.ActiveXObject){
		
		req=new ActiveXObject("Microsoft.XMLHTTP");		
        if(req){
            req.onreadystatechange=fn;
            req.open("GET",url,true);
            req.send();
        }
		
    }
	
	// return request object
	return req;
	
}

function ProcessReqChange(){
	
    // only if req shows "complete"
    if(req.readyState==4){
		
        // only if "OK"
        if(req.status==200){
			
			// Response text
			var response  = req.responseXML.documentElement;
			
        }else{
			
			// Error
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
			
        }
		
    }
	
}

// Open and center pop-up window
function OpenWindow(wu,ww,wh,wn){
	if(wn==null) wn="";
	var w=window.open(wu,wn,"width="+ww+",height="+wh);
	var x=(screen.availWidth-ww)/2;
	var y=(screen.availHeight-wh)/2;
	w.moveTo(x,y);
	w.focus();
}

// Image swap
function SwapImage(n,s){
	var On="._on.";
	var Off="._off.";
	var s1=s? Off: On;
	var s2=s? On: Off;
	if(document.images){
		
		var NewSrc=document.images[n+"Img"].src.replace(s1,s2);
		NewSrc=NewSrc.replace(AbsoluteImagePath,RelativeImagePath);
		document.images[n+"Img"].src=NewSrc;
		
	}
}


// Rollover on news listing
function hilite(o){
	o.origColor=o.style.backgroundColor;
	o.style.backgroundColor="#C2D3D4";
}
function lolite(o){
	o.style.backgroundColor=o.origColor;
}