/**DHTML library from DHTMLCentral.com Thomas Brattli 2001 **/

//Browsercheck
function rightString(fullString, subString) {
   if (fullString.indexOf(subString) == -1) {
      return "";
   } else {
      return (fullString.substring(fullString.indexOf(subString)+subString.length, fullString.length));
   }
}

function lib_bwcheck(){ 
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
	this.opera5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
	this.opera6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
	this.opera7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
 
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0; 
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6||this.ie7
  this.mac=this.agent.indexOf("Mac")>-1
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	if(this.moz) this.ns6 = 1

	string1 = (rightString(navigator.userAgent, 'Netscape'));
	string2 = (rightString(string1, '/'));
	string3 = (parseInt(string2));
	this.ns6=(this.dom && string3 >= 6) ?1:0;
	this.ns7=(this.dom && string3 >= 7) ?1:0; 
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie7||this.ie6||this.ie5||this.ie4||this.ns7||this.ns6||this.ns4||this.opera5||this.opera6||this.opera7)
  return this
}
bw=new lib_bwcheck() //Browsercheck object

function lib_message(txt){
	//alert(txt); 
	//return false
}

function lib_obj(obj,nest){ 
  if(!bw.bw) return lib_message('This browser is not fully supported yet, for best results, browse with IE 6+')
  nest=(!nest) ? "":'document.'+nest+'.'
  this.evnt=bw.dom? document.getElementById(obj):
    bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;	
  if(!this.evnt) return lib_message('The layer does not exist ('+obj+')' 
    +'- \nThis is a Netscape 4 issue')
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt; 
  this.ref=bw.dom||bw.ie4?document:this.css.document;
  this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  this.w=this.evnt.offsetWidth||this.css.clip.width||
    this.ref.width||this.css.pixelWidth||0; 
  this.h=this.evnt.offsetHeight||this.css.clip.height||
    this.ref.height||this.css.pixelHeight||0
  this.c=0 //Clip values
  if((bw.dom || bw.ie4) && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1); 
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0; 
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0; 
  this.cl=this.css.clip.left||this.c[3]||0
  this.obj = obj + "Object"; eval(this.obj + "=this")
  return this
}

lib_obj.prototype.moveIt = function(x,y){
  this.x=x;this.y=y; this.css.left=x;this.css.top=y
}

lib_obj.prototype.moveBy = function(x,y){
  this.css.left=this.x+=x; this.css.top=this.y+=y
}

lib_obj.prototype.showIt = function(){this.css.visibility="visible"}

lib_obj.prototype.hideIt = function(){this.css.visibility="hidden"}

lib_obj.prototype.displayShowIt = function(){this.css.display=""}

lib_obj.prototype.displayHideIt = function(){this.css.display="none"}

lib_obj.prototype.showhideIt = function(){
	if (this.css.visibility == "hidden") {
	this.css.visibility="visible";
	}else{
	this.css.visibility="hidden";
	}
}

lib_obj.prototype.writeDispIt = function(){this.css.display =""}
lib_obj.prototype.writeNoneIt = function(){this.css.display ="none"}
lib_obj.prototype.dipslayIt = function(){this.css.display =""}


lib_obj.prototype.writeStuff = function(){
	if (this.css.display == "none") {
	this.css.display="";
	}else{
	this.css.display="none";
	}
}

lib_obj.prototype.switchStuff = function(first,second){
	if (image1.src == "http://www.sqlsentry.net/images/button_minus.gif") {
	//alert('none');
	image1.src="images/" + first
	}else if (image1.src == "http://www.sqlsentry.net/images/button_plus.gif"){
	//alert('blank');
	image1.src="images/" + second
	}
}

lib_obj.prototype.bg = function(color){ 
	if(bw.opera) this.css.background=color
	else if(bw.dom || bw.ie4) this.css.backgroundColor=color
	else if(bw.ns4) this.css.bgColor=color  
}

lib_obj.prototype.writeIt = function(text,startHTML,endHTML){
	if(bw.ns4){
    if(!startHTML){startHTML=""; endHTML=""}
	  this.ref.open("text/html"); 
    this.ref.write(startHTML+text+endHTML); 
    this.ref.close()
	}else this.evnt.innerHTML=text
}

lib_obj.prototype.clipTo = function(t,r,b,l,setwidth){ 
  this.ct=t; this.cr=r; this.cb=b; this.cl=l
  if(bw.ns4){
    this.css.clip.top=t;this.css.clip.right=r
    this.css.clip.bottom=b;this.css.clip.left=l
  }else{
    if(t<0)t=0;if(r<0)r=0;if(b<0)b=0;if(b<0)b=0
    this.css.clip="rect("+t+","+r+","+b+","+l+")";
    if(setwidth){this.css.pixelWidth=this.css.width=r; 
    this.css.pixelHeight=this.css.height=b}
  }
}

lib_obj.prototype.clipBy = function(t,r,b,l,setwidth){ 
  this.clipTo(this.ct+t,this.cr+r,this.cb+b,this.cl+l,setwidth)
}

lib_obj.prototype.clipIt = function(t,r,b,l,step,fn,wh){
  tstep=Math.max(Math.max(Math.abs((t-this.ct)/step),Math.abs((r-this.cr)/step)),
    Math.max(Math.abs((b-this.cb)/step),Math.abs((l-this.cl)/step)))
  if(!this.clipactive){
    this.clipactive=true; if(!wh) wh=0; if(!fn) fn=0
    this.clip(t,r,b,l,(t-this.ct)/tstep,(r-this.cr)/tstep,
      (b-this.cb)/tstep,(l-this.cl)/tstep,tstep,0, fn,wh)
  }
}
lib_obj.prototype.clip = function(t,r,b,l,ts,rs,bs,ls,tstep,astep,fn,wh){
  if(astep<tstep){
    if(wh) eval(wh); 
    astep++
    this.clipBy(ts,rs,bs,ls,1);
    setTimeout(this.obj+".clip("+t+","+r+","+b+","+l+","+ts+","+rs+","
      +bs+","+ls+","+tstep+","+astep+",'"+fn+"','"+wh+"')",50)
  }else{
    this.clipactive=false; this.clipTo(t,r,b,l,1);
    if(fn) eval(fn)
  }
}

lib_obj.prototype.slideIt = function(endx,endy,inc,speed,fn,wh){
  if(!this.slideactive){
    var distx = endx - this.x;
    var disty = endy - this.y
    var num = Math.sqrt(Math.pow(distx,2)+Math.pow(disty,2))/inc
    var dx = distx/num; var dy = disty/num
    this.slideactive = 1; 
    if(!wh) wh=0; if(!fn) fn=0
    this.slide(dx,dy,endx,endy,speed,fn,wh)
    }
}
lib_obj.prototype.slide = function(dx,dy,endx,endy,speed,fn,wh) {
  if(this.slideactive&&
  (Math.floor(Math.abs(dx))<Math.floor(Math.abs(endx-this.x))|| 
    Math.floor(Math.abs(dy))<Math.floor(Math.abs(endy-this.y)))){
    this.moveBy(dx,dy); 
    if(wh) eval(wh)
    setTimeout(this.obj+".slide("+dx+","+dy+","+endx+","+endy+","+speed+",'"
    +fn+"','"+wh+"')",speed)
  }else{
    this.slideactive = 0; 
    this.moveIt(endx,endy);
    if(fn) eval(fn)
  }
}


function lib_doc_size(){ 
  this.x=0;this.x2=bw.ie && document.body.offsetWidth-20||innerWidth||0;
  this.y=0;this.y2=bw.ie && document.body.offsetHeight-5||innerHeight||0;
  if(!this.x2||!this.y2) return message('Document has no width or height') 
  this.x50=this.x2/2;this.y50=this.y2/2;
  return this;
}

function Capitalize(txtVar) {
  MyText = trim(txtVar.value);
  txtVar.value = MyText.substr(0, 1).toUpperCase() + MyText.substr(1);
}

function CapitalizeAll(txtVar) {
  MyText = trim(txtVar.value);
  txtVar.value = MyText.substr(0).toUpperCase();
}

function CapitalizeEveryWord(txtVar) {
  MyText = trim(txtVar.value);
  var pattern = /(\w)(\w*)/; // a letter, and then one, none or more letters 
  var a = MyText.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2];

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    txtVar.value = a.join(' '); // join it back together
}

function CapitalizeEveryBloodyThing(txtVar) {
  MyText = trim(txtVar.value);
  var pattern = /([a-zA-Z_0-9\.\-\'\"\(\)\:\;\?\,\#\$\%\!\@\/])([a-zA-Z_0-9\.\-\'\"\(\)\:\;\?\,\#\$\%\!\@\/]*)/; // a letter, and then one, none or more letters 
  var a = MyText.split(/\s+/g); // split the sentence into an array of words

    for (i = 0 ; i < a.length ; i ++ ) {
        var parts = a[i].match(pattern); // just a temp variable to store the fragments in.

        var firstLetter = parts[1].toUpperCase();
        var restOfWord = parts[2];

        a[i] = firstLetter + restOfWord; // re-assign it back to the array and move on
    }
    
    txtVar.value = a.join(' '); // join it back together
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

// insert() is merely a convenience here
String.prototype.insert = function(chr, pos)
{
	return this.substring(0,pos) + chr + this.substring(pos);
}

// toCurrency will convert a number to a string in the form:
//	symbol + 1,234,567.89
//	where symbol is either "$" (default) or any other currency
//	symbol you supply as the argument
// 	examples given below for euro, pound and yen
Number.prototype.toCurrency = function(sym)
{
	var symbol = sym ? sym : "$";
	var num = Math.round(this * 100)/100;
	var parts = ("" + num).split(".");
	
	if(parts[1])
		while(parts[1].length < 2) 
			parts[1] += "0";
	else
		parts[1] = "00";
	
	var i = parts[0].length - 3;
	while(i > 0)
	{
		parts[0] = parts[0].insert(",", i);
		i -= 3;
	} 
	return symbol + parts.join(".");
}

function openPopUp(windowURL, windowName, windowWidth, windowHeight, scrollBar){
  var winHandle = window.open(windowURL,windowName,"toolbar=no,scrollbars="+scrollBar+",resizable=yes,width=" + windowWidth + ",height=" + windowHeight)
  return winHandle
  }
  
function winClose(){    // close all open pop-up windows   
  if(win1Open != null) win1Open.close() 
  if(win2Open != null) win2Open.close()
  if(win3Open != null) win3Open.close()
  if(win4Open != null) win4Open.close()
  if(win5Open != null) win5Open.close()
  if(win6Open != null) win6Open.close()
  if(win7Open != null) win7Open.close()

  }

