/*
+---------------------------------------------------------------+
|	1st Winnersh Scout Group.
|	/ipg.js
|   Javascript support functions
|   Based on the code developed for the
|   ipg website (also ©Steve Graham)
|	©Steve Graham 2006-2009
|
|	steve.graham@matata1.myvnc.com
|
+---------------------------------------------------------------+
*/
// Image swap functions
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function findElement(n,ly) {
	if (browserVers < 4) return document[n];
	var curDoc = ly ? ly.document : document;
	var elem = curDoc[n];
	if (!elem) {
		for (var i=0;i<curDoc.layers.length;i++) {
			elem = findElement(n,curDoc.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}

function changeImages() {
	if (document.images && (preloadFlag == true))  {
		var img;
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			img = null;
			if (document.layers) {
				img = findElement(changeImages.arguments[i],0);
			}
			else {
				img = document.images[changeImages.arguments[i]];
			}
			if (img) {
				img.src = changeImages.arguments[i+1];
			}
		}
	}
}
// -->



// Image pop up functions
var sf_newWin = null;
function popUp(strURL, strType, strWidth, strHeight) {
 if (sf_newWin != null && !sf_newWin.closed) {
 sf_newWin.close();
 }
 var strOptions="";
 if (strType=="console") {
   strOptions="resizable=yes,height="+strHeight+",width="+strWidth;
 }    
 if (strType=="fixed") {
   strOptions="resizable=no,status,height="+strHeight+",width="+strWidth;
 }
 if (strType=="fixedScroll") {
   strOptions="resizable=no,scrollbars,height="+strHeight+",width="+strWidth;
 }
 if (strType=="scroll") {
   strOptions="scrollbars,resizable=yes,height="+strHeight+",width="+strWidth;
 }
 sf_newWin = window.open(strURL, 'sf_newWin', strOptions);
 sf_newWin.focus();
}


var sf_imgWin = null;
function viewPic(img)
{ 	
	if (sf_imgWin != null && !sf_imgWin.closed) {
		sf_imgWin.close();
	}
    picfile = new Image(); 
    picfile.src =(img);
    fileCheck(img);
} 

function fileCheck(img)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img);
        sf_imgWin.focus();
    }
    else 
    {
        funzione="fileCheck('"+img+"')";
        intervallo=setTimeout(funzione,50); 
    }
} 

function makeWindow(img)
{ 	
    ht = picfile.height + 18;
    wd = picfile.width + 18; 

    var args= "height=" + ht + ",innerHeight=" + ht;
    args += ",width=" + wd + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 1.2; 
        var ycen = (avht - ht) / 6;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=yes"; 	
    }
    sf_imgWin = window.open(img, '', args);
	return sf_imgWin;
}

function copyToClip(text) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text);
  }else{
    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

    var copytext=text;

    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
    if (!str) return false;
    str.data = copytext;
    var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
    if (!trans) return false;
    trans.addDataFlavor("text/unicode");
    trans.setTransferData("text/unicode",str,copytext.length * 2);
    var clipid = Components.interfaces.nsIClipboard;
    var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
    if (!clip) return false;
    clip.setData(trans,null,clipid.kGlobalClipboard);
    alert('" ' + text +' "' + " stored to clipboard. You can now paste where required");
  }
}

//var preloadFlag = false;
//function preloadImages() {
//	if (document.images) {
//<?php //This code reads the preload images from an array set on individual pages
//	if (count($sf_pl_imgs)>0) {
//		$i=1;
//		while (count($sf_pl_imgs)>=($i+1)) {
//			echo "		".$sf_pl_imgs[$i]." = newImage(\"".$sf_pl_imgs[($i+1)]."\");
//";
//			$i=$i+2;
//	 	}
//	}
//?>
//	  preloadFlag = true;
//	}
//}

// tinyMCE image support functions works with wesAdminUpLoadImg.php

var lastSet=0;
function hiliteImg(imgNode,imgSet){
  if(document.getElementById("ulImgForm")!=null){
    lastSet=document.forms['ulImgForm'].elements['lastImgSet'].value;
  }
  var s=imgSet;
  if (document.images)  {
//    alert(document.images.length);
    for (var i=0; i<document.images.length; i+=1) {
//      alert(document.images[i]);
       if (document.images[i].parentNode.className=='selected'){
       document.images[i].parentNode.className='';
       }
    }

  }
  if(document.getElementById('ulImgForm')!=null){
    if(document.forms['ulImgForm'].elements['isImgSet'].checked==true && document.forms['ulImgForm'].elements['newImgSet'][1].checked){

      if(s>0){
        document.forms['ulImgForm'].elements['imgSet'].value=s;
        lastSet=s;
      } else {
        document.forms['ulImgForm'].elements['imgSet'].value="";
        lastSet=0;
      }

    }
  }
  imgNode.parentNode.className='selected';
}
function updateSet(nextSet){
  var isSet = document.forms['ulImgForm'].elements['isImgSet'];
  var setID = document.forms['ulImgForm'].elements['imgSet'];
  var isNewSet = document.forms['ulImgForm'].elements['newImgSet'][0];
  var lastSet=document.forms['ulImgForm'].elements['lastImgSet'].value;
   if(isSet.checked==true){
     setID.disabled=false;
     if(isNewSet.checked){
        setID.value=nextSet ;
     } else {
       if(lastSet>0){
        setID.value=lastSet;
       } else {
         setID.value="";
       }
          alert("The 'image set ID' defaults to the last one used, change it by clicking an alternative set in the gallery, below.");
   }
   } else {
     setID.disabled=true;
     setID.value="";
   }
}


/*
function delSelectedImg() {
  var imgName = "";

  if (document.images)  {
//    alert(document.images.length);
    var i;
    for (var i=0; i<document.images.length; i+=1) {
       if (document.images[i].parentNode.className=='selected'){
         //get the name of the selected image
         with (document.images[i].src){
           //local files use \ and remote / so must test
           if (lastIndexOf("/")==0){
              imgName=substr(lastIndexOf("\\")+1);
           } else {
             imgName=substr(lastIndexOf("/")+1);
           }
         }
       }
    }
  }
  if (imgName==""){
    alert("You have not selected an image!");
  } else {
    if (confirm("Do you wish to delete the image " + imgName +"?")){
//        alert(location.pathname+"?act=del&field=src&img="+imgName);
      location.href=location.pathname+"?act=del&field=src&img="+imgName;
    }
  }
}
*/
function delSelectedImg() {
  var imgName = "";
  var thumbName="";
  var spanID="";

  if (document.images)  {
//    alert(document.images.length);
    var i;
    for (var i=0; i<document.images.length; i+=1) {
       if (document.images[i].parentNode.className=='selected'){
         //get the name of the selected thumbnail
         thumbName=document.images[i].name;
         spanID=thumbName.replace("img","span");
       }
    }
  }
  if (thumbName==""){
    alert("You have not selected an image!");
  } else {
    imgName=document.getElementById(spanID).innerHTML;
//    alert(thumbName+spanID+imgName);

    if (confirm("Do you wish to delete the image " + imgName +"?")){
//        alert(location.pathname+"?act=del&field=src&img="+imgName);
      location.href=location.pathname+"?act=del&field=src&img="+imgName;
    }
  }
}
/*
+---------------------------------------------------------------+
|	Ajax code
|
|
+---------------------------------------------------------------+
*/

//Browser Support Code
// Trim white space string function
String.prototype.trim = function(){
  return this.replace(/^\s+/,'').replace(/\s+$/,'');
}

// Ajax request
function ajaxObj(){
  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!");
    }
    return xmlhttp;
}

// the tblRow object
// ++++++++++++++++++++++++++++++++++++
function tblRow(row){
//  var tbl=document.getElementById('artTable').rows;
  this._row=row;
  this.pageId=_artArray[row];

  this.revBut=document.getElementById("rev"+row);
  this.editBut=document.getElementById("edit"+row);
  this.suspBut=document.getElementById("suspend"+row);
  this.delBut=document.getElementById("del"+row);

  this.statCell=document.getElementById("stat"+row);
  this.lockCell=document.getElementById("lock"+row);
  this.lockByCell=document.getElementById("lockBy"+row);

  this.getStat=getStat;
  this.getLock=getLock;
  this.getLockBy=getLockBy;

  this.setStat=setStat;
  this.setLock=setLock;
  this.setLockBy=setLockBy;

  this.setRevBut=setRevBut;
  this.setEditBut=setEditBut;
  this.setSuspBut=setSuspBut;
  this.setDelBut=setDelBut;
}

// tblRow() object method functions
function getStat(){
  return parseInt(this.statCell.innerHTML);
}
function getLock(){
  return this.lockCell.innerHTML.trim();
}
function getLockBy(){
  return parseInt(this.lockByCell.innerHTML);
}

function setStat(val){
   this.statCell.innerHTML=val;
}
function setLock(bool){
  var str;
  if(bool==1){
    str="yes";
  } else {
    str="no";
  }
  this.lockCell.innerHTML=str;
}
function setLockBy(val){
  this.lockByCell.innerHTML=val;
}
// ++++++++++++++++++++++++++++++++++++

// ++++++++++++++++++++++++++++++++++++
// Button action functions
function doRev(pageId){
  if(pageId>=0){
    location.href="wesAdminRev.php?sec=" + _sec + "&page=" + _page + "&act=rev&id=" + pageId;
  } else if(pageId==-1) {
    alert("This article is locked by "+nLockWho+" and cannot be reviewed or edited until that user has unlocked it.\n\nIf you know that it is not currently being edited and you have administrative priviledge then you can force it into an unlocked state.");
  } else{
    alert("This article is marked ready for review and release, however you do not have the authority to carry this out. Please contact your nominated reviewer and request that he review and release your article.");
  }
}

function doEdit(pageId,stat){
  location.href="wesAdminEditor.php?sec=" + _sec + "&page=" + _page + "&act=edit&id=" + pageId + "&stat=" + stat;
}

function doLocked(stat,lock){
  if(lock=="no"){
    if(stat==0){
      alert("This article has been released and is available to be viewed on the site. If you wish to edit it now you must first mark it for revision using the button with the \"?\". \n\nNB this will prevent it from being viewed on the site until it has been reviewed and re-released by your nominated reviewer.");
    } else {
      alert("This article has been marked for review pending release. If you wish to edit it now you must first mark it for revision using the button with the \"?\".");
    }
  } else {
    alert("This article is locked by "+nLockWho+" and cannot be edited until that user has unlocked it.\n\nIf you know that it is not currently being edited and you have administrative priviledge then you can force it into an unlocked state, if you do not have adminstrative priviledge then you can request your nominated reviewer to do so.");
  }
}

function doSuspend(row){
  if(row>0){
    markSuspend(row)
  } else {
    row=-row;
    var r = new tblRow(row);
    if(r.getLock()=="yes" && r.getLockBy()!=_userId){
      if(_userCl<2){
        alert("This article is locked by "+nLockWho+".\n\nIf you are sure that it is not being edited, you can force the article to an unlocked state and then mark it for revision.");
      } else {
        alert("This article is locked by "+nLockWho+", you cannot mark it for suspension until it has been unlocked. You can request an administrator to force the article into an unlocked state.");
      }
    } else {
      alert("This article is already suspended for revision.");
    }
  }
}

function doDelete(row){
  if(row>0){
    markDelete(row);
  } else {
    row=-row;
    var r = new tblRow(row);
    if(r.getStat()==3){
      if(r.getLock()=="no"){
        alert("This article is already marked for deletion, to change this use the 'mark for revision' button, but please note that the article will need to be released by an administrator before it can be viewed by visitors to the site.");
      } else {
        if(_userCl<=1) {
          alert("This article is locked by "+nLockWho+".\n\nYou cannot change it's deletion status until it has been unlocked. As an administrator you have the authority to force this article to an unlocked state.");
        } else {
          alert("This article is locked by "+nLockWho+".\n\nTo change it's deletion status you must first get it unlocked. You can also request your nomintated reviewer to force your article into an unlocked state.");
        }
      }
    } else if(r.getStat()<2 && _userCl==2 && (r.getLock()=="no" || r.getLockBy()==_userId)){
      alert("You have released this article and you cannot delete it. If you wish to delete this article you must first mark it for revision, which will stop it being viewed on the web site. You can then mark it for deletion and request an administrator to run the delete articles routine.\n\nIf you change your mind, the article wil need to be reviewed by an administrator and re-released before it will be available to site visitors again!");
    } else {
      alert("This article is locked by "+nLockWho+".\n\nTo change it's deletion status you must first get it unlocked. You can also request your nomintated reviewer to force your article into an unlocked state.");
    }
  }
}


// ++++++++++++++++++++++++++++++++++++

// +++++++++++++++++++++++++++++++++++++++
// Button ajax controls, called by Button action functions

// Ajax code - Force article to an unlocked state (only accessed by an administrator)
// take the place of the edit button when article is locked and user is an administrator.
function forceUnlock(row){
  var r=new tblRow(row)
  var oldName=r.editBut.className;
  r.editBut.className="progSpinner";
  var doIt = confirm("Unlock this article?\n\nIf this article is being edited by "+nLockWho+", any changes they have made since the last save will be lost!");
   if(doIt){
     var targetFile="wesAdminAjaxForceUnlock.php?&pageId=" + r.pageId;
     var aO=ajaxObj();
     ajaxForceUnlock(aO,r);
     aO.open("GET",targetFile,true);
     aO.send(null);
   } else {
     r.editBut.className=oldName;
   }
}

function ajaxForceUnlock(aO,r){
  aO.onreadystatechange = function(){
    if(aO.readyState == 4){
      var response=aO.responseText;
      if(response!="Error"){
        r.setLock(0); // lock column, "0" indicates that the article is not locked
        r.setLockBy(0); // zero indicates the null user.
        r.setEditBut("admin");
        r.setSuspBut("on");
        if(r.getStat()!=3){
          r.setDelBut("on");
        } else {
          r.setDelBut("off");
        }
         alert("This article has been unlocked. It was previously locked by "+response+", you may wish to advise them that you have taken control of it!");
      } else {
         alert("An unknown error has occurred, and the article has not been unlocked!");
      }
    }
  }
}

// Ajax code - set article to revision (The suspend button)
function markSuspend(row){
  var r = new tblRow(row);
  var oldName=r.suspBut.className;
  r.suspBut.className="progSpinner";
//  if(getRow(r)){
     var doIt = confirm("Are you sure you want to mark this article for revision?\n\nIf you do, it will have to be reviewed by an administrator\nand released before it can be viewed on the site again!");
     if(doIt){
       var aO=ajaxObj();
       var targetFile="wesAdminAjaxMarkRev.php?&pageId=" + r.pageId+"&whoLock="+r.getLockBy();
       ajaxMarkRev(aO,r);
       aO.open("GET",targetFile,true);
       aO.send(null);
     } else {
             r.suspBut.className=oldName;
     }
//  }
}

function ajaxMarkRev(aO,r){
  aO.onreadystatechange = function(){
    if(aO.readyState == 4){
      var response=aO.responseText;
      if(response=="Updated"){
        r.setStat("2"); // status column, status 2 == marked for revision
        r.setRevBut("off");
        r.setSuspBut("dis");

        if(_userCl<2){
            r.setEditBut("admin");
        } else {
          r.setEditBut("user");
        }

        r.setDelBut("on");
      } else {
        alert("An unknown error has occurred and the article has not been marked for revision! Please use the browser refresh button to refresh the aricle table. Returned response was:- "+response);
      }
    }
  }
}

// Ajax code - mark article for deletion
function markDelete(row){
  var r = new tblRow(row);
  var oldName=r.delBut.className;
  r.delBut.className="progSpinner";
  var doIt = confirm("Are you sure you want to mark this article for deletion?\n\nIf you do, it cannot be undeleted without being reviewed\nby an administrator and re-released!");
  if(doIt){
     var targetFile="wesAdminAjaxMarkDel.php?&pageId=" + r.pageId;
     var aO=ajaxObj();
     ajaxMarkDel(aO,r);
     aO.open("GET",targetFile,true);
     aO.send(null);
  } else {
    r.delBut.className=oldName;
  }
}

function ajaxMarkDel(aO,r){
  aO.onreadystatechange = function(){
    if(aO.readyState == 4){
      var response=aO.responseText;
      if(response!="error"){
        r.setStat("3"); // status column, status 3 == marked for deletion

        r.setDelBut("off");
        r.setSuspBut("on");
        r.setEditBut("lock");
        document.getElementById("delSelected").disabled=false;
        document.getElementById("delSelected").className="delete";
        if(response!=""){
          alert("You marked this article for deletion but it is currently locked for editing by "+response+", you may wish to advise them!");
        }
      } else {
        alert("An error occurred and the article has not been marked for deletion!");
      }
    }
  }
}



// ++++++++++++++++++++++++++++++++++++
// Row update function - Update the row when user hovers mouse on row for > 1 second.
function mouseOut(row){
  mouseOver[row]=1;
}
function checkRow(row){
  mouseOver[row]=0;
    setTimeout("makeUpdate("+row+")",1000);
}
function makeUpdate(row) {
  if(mouseOver[row]==0){
    var r=new tblRow(row);
    var result;
    var targetFile="wesAdminAjaxGetRow.php?pageId=" + r.pageId + "&cStat=" + r.getStat() + "&cLockBy=" + r.getLockBy() + "&userId=" + _userId + "&noLock=1";
       var aO=ajaxObj();
       aO.open("GET",targetFile,true);
       aO.send(null);
       aO.onreadystatechange = function(){
         if(aO.readyState == 4){
          var response=aO.responseText;
          var lockState="no";
          if(response!="error"){
            var update=response.split(",");
            if(update[4]=="0"){ // update[4] is false (0) if the either the status or userlock has changed since page load
              var x=updateRow(r,update);
            }
          }
        }
     }
  }
}

function updateRow(r,update){
  var result=true;
  var admin = false;
  if(_userCl<=1){
    admin=true;
  }
  if(r.getLock()=="no"){
    cLock=0;
  } else {
    cLock=1;
  }
  var nStat = parseInt(update[0]);
  var nLock = update[1];
  var nLockBy = parseInt(update[2]);
  nLockWho = update[3];

  r.statCell.innerHTML=nStat;
  if(nLock==1){
    r.lockCell.innerHTML="yes";
  } else {
    r.lockCell.innerHTML="no";
  }
  r.lockByCell.innerHTML=nLockBy;

//  if(r.getStat() != nStat || cLock != nLock || r.getLockBy() != nLockBy){
    switch (nStat) {
      case 0: // Article is locked
// Review Button
    r.setRevBut("off");

// admin edit button
        if(admin){
          if(nLock==0 || _userId==nLockBy){
            r.setEditBut("admin");     // locked by this user, who has admin status

          } else {
            r.setEditBut("unlock");    // Locked by another user but this user has admin status

          }
// user edit button
        } else {
          r.setEditBut("lock");        // Locked by another user and this user does not have admin status
        }
// Suspend button

        if(nLock==1 && _userId!=nLockBy && !admin){
          r.setSuspBut("lockU");

        } else if(nLock==1 && _userId!=nLockBy && admin){
          r.setSuspBut("lockA");
        } else {
          r.setSuspBut("on");
        }
// Delete button
        if(admin){
          if(r.getLock()=="no" || r.getLockBy()==_userId){
            r.setDelBut("on");
          } else if(r.getLock()=="yes") {
           r.setDelBut("lock");
          }
        } else if(r.getLock()=="yes" && r.getLockBy()!=_userId) {
          r.setDelBut("lock");
        } else {
          r.setDelBut("off");
        }
      break;
     case 1:
// Review button
        if(admin){
          if(r.getLock()=="no" || r.getLockBy()==_userId ){
            r.setRevBut("admin");
          } else if(r.getLock()=="yes") {
            r.setRevBut("lock");
          } else {
            r.setRevBut("off");
          }
        } else   {
          r.setRevBut("user")
        }
// Edit button
// admin edit button
        if(admin){
          if(nLock==0 || _userId==nLockBy){
            r.setEditBut("admin");

          } else {
            r.setEditBut("unlock");
          }
// user edit button
        } else {
          r.setEditBut("lock");
        }

// Suspend button
        if(nLock==1 && _userId!=nLockBy && !admin){
          r.setSuspBut("lockU");

        } else if(nLock==1 && _userId!=nLockBy && admin){
          r.setSuspBut("lockA");
        } else {
          r.setSuspBut("on");
        }
// Delete button
        if(r.getLock()=="no" || r.getLockBy()==_userId){
          if(_userCl<2){
            r.setDelBut("on");
          } else {
            r.setDelBut("off");
          }
        } else {
         r.setDelBut("lock");
        }

      break;
      case 2:
// Review Button
    r.setRevBut("off");
// Edit button
          if(r.getLock()=="no" || _userId==r.getLockBy()){
            if(admin){
              r.setEditBut("admin");
            } else {
              r.setEditBut("user");
            }
          } else if(admin) {
            r.setEditBut("unlock");
          } else {
            r.setEditBut("lock");
          }
// Suspend button
    r.setSuspBut("dis");
// Delete button
        if(r.getLock()=="no" || r.getLockBy()==_userId){
          r.setDelBut("on");
        } else {
         r.setDelBut("lock");
        }
      break;
      case 3:
// Review Button
    r.setRevBut("off");
// Edit button
        if(admin && r.getLock()=="yes"){
          r.setEditBut("unlock");
        } else {
          r.setEditBut("lock");
        }
// Suspend button
        if(nLock==1 && _userId!=nLockBy && !admin){
          r.setSuspBut("lockU");

        } else if(nLock==1 && _userId!=nLockBy && admin){
          r.setSuspBut("lockA");
        } else {
          r.setSuspBut("on");
        }
// Delete Button
    r.setDelBut("off");
      break;
      default:

    }
    result=true;
//  }

  return result;
}
// +++++++++++++++++++++++++++++++++++++++
// End of Ajax code
// +++++++++++++++++++++++++++++++++++++++


// +++++++++++++++++++++++++++++++++++++++
/* The custom alert box code */
/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Steve Chipman | http://slayeroffice.com/ */

// constants to define the title of the alert and button text.
var ALERT_TITLE = "Oops!";
var ALERT_BUTTON1_TEXT = "Cancel";
var ALERT_BUTTON2_TEXT = "OK";

// over-ride the alert method only if this a newer browser.
// Older browser will see standard alerts
/*
if(document.getElementById) {
  window.alert = function(txt) {
    createCustomAlert(txt);
  }
}
*/
function myAlert(txt){
  createCustomAlert(txt);
}

function createCustomAlert(txt) {
  // shortcut reference to the document object
  d = document;

  // if the modalContainer object already exists in the DOM, bail out.
  if(d.getElementById("modalContainer")) return;

  // create the modalContainer div as a child of the BODY element
  mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
  mObj.id = "modalContainer";
   // make sure its as tall as it needs to be to overlay all the content on the page
  mObj.style.height = document.documentElement.scrollHeight + "px";

  // create the DIV that will be the alert
  alertObj = mObj.appendChild(d.createElement("div"));
  alertObj.id = "alertBox";
  // MSIE doesnt treat position:fixed correctly, so this compensates for positioning the alert
  if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
  // center the alert box
  alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";

  // create an H1 element as the title bar
  h1 = alertObj.appendChild(d.createElement("h1"));
  h1.appendChild(d.createTextNode(ALERT_TITLE));

  // create a paragraph element to contain the txt argument
  msg = alertObj.appendChild(d.createElement("p"));
  msg.innerHTML = txt;

  // create an anchor element to use as the cancel button.
  btn1 = alertObj.appendChild(d.createElement("a"));
  btn1.id = "cancelBtn";
  btn1.appendChild(d.createTextNode(ALERT_BUTTON1_TEXT));
  btn1.href = "#";
  // set up the onclick event to remove the alert when the anchor is clicked
  btn1.onclick = function() { removeCustomAlert();return false; }

  // create an anchor element to use as the ok button.
  btn2 = alertObj.appendChild(d.createElement("a"));
  btn2.id = "okBtn";
  btn2.appendChild(d.createTextNode(ALERT_BUTTON2_TEXT));
  btn2.href = "#";
  // set up the onclick event to remove the alert when the anchor is clicked
  btn2.onclick = function() { removeCustomAlert();return true; }
}

// removes the custom alert from the DOM
  function removeCustomAlert() {
  document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));
}
// +++++++++++++++++++++++++++++++++++++++

