// Display pop-up to confirm deletion
function ConfirmDelete(u){
	if(confirm("Are you sure you want to delete this record?")) 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;
}

// 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){
	var w=window.open(wu,"","width="+ww+",height="+wh+",status=no");
	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) document.images[n+"Img"].src=document.images[n+"Img"].src.replace(s1,s2);
}

// 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);

}