function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


function urlEncode (str) {
str = escape(str);
return str.replace(/[*+\/@]|%20/g,
function (s) {
switch (s) {
case "*": s = "%2A"; break;
case "+": s = "%2B"; break;
case "/": s = "%2F"; break;
case "@": s = "%40"; break;
case "%20": s = "+"; break;
}
return s;
}
);
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return unescape(strReturn);
}



function doRPC(url,callback){

// when using callback cvar specify details as follows
// doRPC('url.php',function(){ js_function();}) ;


  if(callback == undefined){
	var xmlhttp;
	if (window.XMLHttpRequest){
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  } else if (window.ActiveXObject){
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  } else {
	  alert("Your browser does not support XMLHTTP!");
	  }

	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
  } else {
		var ajaxIndex = dynamicContent_ajaxObjects.length;
                dynamicContent_ajaxObjects[ajaxIndex] = new sack();
                dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;
                dynamicContent_ajaxObjects[ajaxIndex].onCompletion = callback; 
                dynamicContent_ajaxObjects[ajaxIndex].runAJAX();
  }

}


function getMouseX(){
        x = document.getElementById('MouseX').value;
        return x;
}
function getMouseY(){
        y =  document.getElementById('MouseY').value
        return y;
}


function addLoadEvent2(func) {
   var oldonload = window.onload;
   if (typeof window.onload != 'function') {
       window.onload = func;
   }
   else {
       window.onload = function() {
           oldonload();
           func();
       }
   }
}

function findPosX(obj)
{
        obj = document.getElementById(obj);
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosY(obj)
{
                obj = document.getElementById(obj);
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function findPosXAlt(obj)
{
        //obj = document.getElementById(obj);
        var curleft = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curleft += obj.offsetLeft
                        obj = obj.offsetParent;
                }
        }
        else if (obj.x)
                curleft += obj.x;
        return curleft;
}

function findPosYAlt(obj)
{
         //obj = document.getElementById(obj);
        var curtop = 0;
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
                        curtop += obj.offsetTop
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
        return curtop;
}

function getWindowHeight(){
  var myHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientHeight ) ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
	return myHeight;
}

function getWindowWidth(){
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
  }
        return myWidth;
}


function getScreenCenterY() {
	var y = 0;
	 
	y = getScrollOffset()+(getInnerHeight()/2);
 
	return(y);
}
 
function getScreenCenterX() {
	return(document.body.clientWidth/2);
}
 
function getInnerHeight() {
var y;
if (self.innerHeight) // all except Explorer
{
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{a
y = document.body.clientHeight;
}
return(y);
}
 
function getScrollOffset() {
var y;
if (self.pageYOffset) // all except Explorer
{
y = self.pageYOffset;
}
else if (document.documentElement && 
document.documentElement.scrollTop)
// Explorer 6 Strict
{
y = document.documentElement.scrollTop;
}
else if (document.body) // all other Explorers
{
y = document.body.scrollTop;
}
return(y);
}

function doSearch(query){
	show_searching();

	if(query == undefined){
		q = document.getElementById('textbox-search-main').value;
	} else {
		q =query;
	}
	if(q == 'I\'m looking for...' || q == ''){
		setTimeout(doSearchError,2000);
	} else {
		var ss = function() { doSearchOK(q);}
		setTimeout(ss,2000);
	}

}

function doSearchError(){
                close_searching();
                show_alert('Please ensure you fill out the search form correctly.',0);
}

function doSearchOK(query){
	close_searching();


	if(query == undefined){
		q = document.getElementById('textbox-search-main').value;
	} else {
		q = query;
	}

        //create canvas that is dimmed out
        show_blankout();

        //create the alert
        w = 640;
        h = 480;
        uid = 'search-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
	mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);

        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');

	ajax_loadContentOpacity(uid,'/tools/search.php?query=' + urlEncode(q)) ;


}

function closeDoSearchOK(){
        mRemoveDiv('search-xaetad');
        close_blankout();	
}

function doSearchInBox(){

        q = document.getElementById('popup-search-query').value;
	document.getElementById('textbox-search-main').value = q; //reset top box search

        ajax_loadContentOpacity('search-box-results','/tools/search.php?justresults=1&query=' + urlEncode(q)) ;



}

function wait(msecs)
{
var start = new Date().getTime();
var cur = start
while(cur - start < msecs)
{
cur = new Date().getTime();
}
}


function std_ajaxbox(title,url){


        //create canvas that is dimmed out
        show_blankout();

        //create the alert
        w = 640;
        h = 480;
        uid = 'stdajaxbox-xaetad';
        mCreateDiv(uid);
        mDivBackgroundColor(uid,'#ffffff');
        mDivBorder(uid,'1','solid','#cccccc');
        mDivSize(uid,w,h);

        x = getScreenCenterX() - parseInt((w/2));
        y = getScreenCenterY() - parseInt((h/2));
        mDivPos(uid,y,x,'absolute');

	document.getElementById(uid).innerHTML='<div style="width:640px;height:480px;"><div style="float:left;width:640px"><div style="margin:10px;margin-bottom:4px;color:#666666;font-weight:bold;float:left;height:20px;">'+title+':</div><div style="margin:10px;margin-bottom:4px;float:right;height:20px;"><a href="javascript:close_stdajaxbox();"><img src="/gfx/close.gif" border="0" alt="close"></a></div><div style="width:620px;margin-left:10px;margin-right:10px;height:1px;background:#cccccc;float:left"></div><div id="stdajaxbox-xaetad-content" style="text-align:left;line-height:150%;float:left;width:620px;height:425px;margin:10px;overflow:auto"></div></div>';

        ajax_loadContentOpacity('stdajaxbox-xaetad-content',url) ;


}

function close_stdajaxbox(){
        mRemoveDiv('stdajaxbox-xaetad');
        close_blankout();
}




