
if(document.all){ browserType='IE';}
else if(document.getElementById){ browserType='FF';}

var zVal='';	// global variable to hold existing value of an element.


function DivSetHight(fe1, fe2) {
	obj1 = document.getElementById(fe1);
	h1 = obj1.offsetHeight;


	obj2 = document.getElementById(fe2);
	h2 = obj2.offsetHeight;


	if(browserType =='FF'){ h1=h1-2; h2=h2-2; }
	 
	if (h1>h2){
	 obj2.style.height=h1+'px';
	}else{
	 obj1.style.height=h2+'px';
	}
}

function togDiv( iv, status,from ) {
	//alert(iv + '  --  '  + from );
	if (!(document.getElementById(iv))){
		//alert( 'togDiv -  ERROR  --  ' + iv + '  --  '  + from );
	}else{
	   obj=document.getElementById(iv);x='';if(status==0){x=0;}else if(status==1){x=1;}else if (status==2){if(obj.style.display=='none'){x=1;}else{x=0;}}if(x==1){obj.style.display='block';}else if(x==0){obj.style.display='none';}
		// Set status 0 off, 1 on, 2 on/off	
	}
}

function togDivAry(ary,status){
	for( var i = 0; i< ary.length; i++ ){
		togDiv(ary[i],status);
	}
}


function numberFormat(nStr){
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1))
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  return x1 + x2;
}



function fmatCur0(num,symbol){

	if(num==undefined || num=='undefined'){
		return;
	}

	num = num.toString().replace('-','');

	num = num.toString().replace(/\$/,'');
	var i = parseFloat(num);
	if(symbol==undefined){symbol='';}
	if(isNaN(i)){i=0.00;}
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;

	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }

	s = numberFormat(s);

	s = minus + s;
	return s;
}


function fmatInt(num){num=num.toString().replace(/\$|\,/g,'').replace('.','').trimEnds();if(isNaN(num))num="";return( num );}
function fmatDec(num){num=num.toString().replace(/\$|\,/g,'');num = num.replace('-','');if(isNaN(num)){	num="0";}cents=Math.floor((num*1000+0.5)%1000);num = Math.floor((num*1000+0.5)/1000).toString();if(cents < 10)cents="00"+cents;else if(cents < 100)cents="0"+cents;for(var i = 0; i < Math.floor((num.length-(1+i))/3); i++){num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));} if(num+'.'+cents!='0.000')return(num+'.'+cents);else return '';}



function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}




function getId(e){
	return document.getElementById(e);
}

function setValAry(ary,v) {
	for(var i = 0; i < ary.length; i++) {
		setVal(ary[i],v);
	}
}

function setVal(e,v) {
	if(document.getElementById(e)){
		document.getElementById(e).value= v;
	} else {
		//alert(e + ' is not an element.');
	}
}




function stripSpaces(str){
	str = str.replace(/ /g,'');
	return str;
}


function setChecked(e,tf){ 

	if(getElement(e)){
		document.getElementById(e).checked=tf;
	}
}



function setRadio(f,e,v){

	var RadioObj = eval('document.'+f+'.'+e);

	var radioLength = RadioObj.length;

	for(var i = 0; i < radioLength; i++) {
		RadioObj[i].checked = false;
		if(RadioObj[i].value == v.toString()) {
			RadioObj[i].checked = true;
		}
	}
}


function setInHtml(e,v) {
		if(getElement(e)){
			document.getElementById(e).innerHTML= v;
		}else{
//			alert( e );
		}
}


function getInHtml(e) {
//alert(e);
//		if(getElement(e)){
			return document.getElementById(e).innerHTML;
//		}
}




function getUniqueId(){
    	var newDate = new Date();
	return newDate.getTime();
}



function maxQtyMsg(){
	alert('Max qty allowed is 32,767');
}

function maxDollarMsg(){
	alert('Max dollar allowed is 214,748.00');
}

function invalidInvoiceTotal(){
	alert('Your invoice exceeds our maximum dollar amount allowed on a single invoice.\nYou will need to do this one by hand.\nVery sorry!');
}


/******  Set style attributes   BEGIN  ***** */

function setBG(e,bg) {

	if(getElement(e)){
		document.getElementById(e).style.backgroundColor=bg;
	}
}



function setBG1() {


// alert( GLB_LASTDIVON + ' -- ' + GLB_CUR_DIV );


	document.getElementById(GLB_LASTDIVON).style.backgroundColor='transparent';
	document.getElementById(GLB_CUR_DIV).style.backgroundColor=DIV_HIGHLIGHT;
	
}



function setClass(e,f){
 	var z='';	
	if(f==1){
		z='selected';
	}else{
		z='off';
	document.getElementById(e).className=z;
	}
}


function setDisabled(e){
	document.getElementById(e).disabled=true;
}

function setEnabled(e){
	document.getElementById(e).disabled=false;
}


function setBorder(e, borderval ){
	document.getElementById(e).style.border = borderval; 
}

function setColor(e,co) {
	document.getElementById(e).style.color=co;
}

function setVis(e,offOn){

	var v = "visible";
	if(offOn==0){
	   v = "hidden";
	}

	document.getElementById(e).style.visibility=v;
}



function setBGI(e,bgi) {
	var url = 'url('+bgi+')';
	document.getElementById(e).style.backgroundImage=url;
}



function setZ(iv,z) {
	document.getElementById(iv).style.zIndex=z;
}

/******  Set style attributes  END  ***** */



function getHeight(e){
	return document.getElementById(e).offsetHeight;
}




function getZ(e) {
	return document.getElementById(e).style.zIndex;
}



function setAllChecked(id,num,chk){
	for(var i=0; i<=num;i++){
		//setChecked(id+i,chk);
		el = id+i;
		document.getElementById(el).checked=chk;
	}
}


function setAllCheckedAry(id,num,chk){
	var elid = document.getElementsByName(id);
	for(var i=0; i<=num;i++){
		if(elid[i])
		elid[i].checked=chk;
	}
}






function setInGroupChecked(elname,start,num,onOff){
	var stopNum = start+num
	for(i=start;i<stopNum;i++){
		setChecked(elname+i,onOff);
	}
}

function retOpp1or0(e){

	if( getVal(e) == 1){
		return 0;
	}else{
		return 1;
	}
}






function inputBox( id, value, maxchar, cssclass, ondblclick, onclick, onkeyup, onblur, onfocus, tabindex ){

	if(!(value)){		value = ''; }
	if(ondblclick != undefined && ondblclick!=''){ 	ondblclick 	= ' onDblclick="'+ondblclick+'"'; 	}else {ondblclick='';}
	if(onclick!= undefined &&  onclick!=''){	  	onclick 		= ' onClick="'+onclick+'"'; 		}else{onclick='';}
	if(onkeyup != undefined && onkeyup!=''){		onkeyup 		= ' onkeyup="'+onkeyup+'"'; 		}else{onkeyup='';}
	if(onblur != undefined && onblur!=''){			onblur 		= ' onblur="'+onblur+'"'; 		}else{onblur='';}
	if(onfocus != undefined && onfocus!=''){		onfocus 		= ' onfocus="'+onfocus+'"'; 		}else{onfocus='';}
		
	return '<input type="text" id="'+id+'" maxlength="'+maxchar+'" value="'+value+'" class="'+cssclass+'"'+ondblclick+onclick+onkeyup+onblur+onfocus+'>';

}



 

function myReplace(sOrgVal,sSearchVal,sReplaceVal)
{
   var sVal;
   try
   {
      sVal = new String(sOrgVal);
      if (sVal.length < 1) { return sVal; }
      var sRegExp = eval("/" + sSearchVal + "/g");
      sVal = sVal.replace(sRegExp,sReplaceVal);
   }
   catch (exception)  { }
   return sVal;

 }
 
 

function getVal(e) { 
	var el = document.getElementById(e);
	if(el){
		return el.value;
	}
}


function createWindow(fe){
var theStr=getVal(fe);
if(theStr.trimEnds().length==0)return false;
var winName = window.open("about:blank","winName");
winName.document.write(theStr);
winname.document.close();
}



function getRadioVal(fn,fe){

	var el = eval('document.'+fn+'.'+fe);

	for(var i = 0; i < el.length; i++) {
		if(el[i].checked) {
			return el[i].value;
		}
	}
}

function getChecked(e){

	if(document.getElementById(e).checked)
		return 1;
	else 
		return 0;
}


function setFocus(e) {
	if(getElement(e)){
		document.getElementById(e).focus();
	}
}

function setSRC(e,val){
	if(getElement(e)){
		document.getElementById(e).src = val;
	}
}



function getSRC(e){
	if(getElement(e))
	return document.getElementById(e).src;
}


function getFileNameInURL(e){
	return e.substring( e.lastIndexOf('/')+1 );
}

function getDisplayState(e){
	var obj = document.getElementById(e);

	return obj.style.display;
}


function swapDivs(numrows, close, open){
	for(i=0;i<numrows;i++){
		togDiv(close+i,0);
		togDiv(open+i,1);
	}
}



function setMouseXY(e){

	var posx = 0;
	var posy = 0;
	if (!e) e = window.event;

	if ( e.pageX || e.pageY ) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else
	if ( e['clientX'] || e['clientY'] )	{

		posx = e.clientX + document.body.scrollLeft	+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop	+ document.documentElement.scrollTop;

	}
	
	
	GBL_MOUSE_X = posx;
	GBL_MOUSE_Y = posy;
	
	  // dev
	 //setVal('mouseX', posx );
	 //setVal('mouseY', posy );
}





function textCounter(field, countfield, maxlimit) {

	if (field.value.length > maxlimit) 

		field.value = field.value.substring(0, maxlimit);

	else 
		countfield.value = maxlimit - field.value.length;
 }


function selectOption(fe,valtoselect) {

	if(!getElement(fe) || valtoselect==undefined || valtoselect=='undefined'){
		return;
	}



    var optlist = document.getElementById(fe); 
    var valFound = 0;
     for (j = 0; j < optlist.options.length; j++){  

			if( isNaN(valtoselect) ){ 

					if( valtoselect.toLowerCase()==optlist.options[j].value.toLowerCase()  ){
						optlist.options[j].selected=true; 
						valFound = 1;
						break; 
					}	
			} else {

				if( valtoselect==optlist.options[j].value ){
					optlist.options[j].selected=true; 
					valFound = 1;
					break; 
				}
			}
	 
     }
     
     
	if(valFound==0){     

		return 'notfound';
	}     
     
  } 


function selectAddOption(fe, txtadd, valadd ) {
    var optlist = document.getElementById(fe); 
	var totalOps = optlist.options.length;
    for (var j = 0; j < totalOps; j++){  
		if (txtadd.toLowerCase()==optlist.options[j].text.toLowerCase()) {
				return false; 
		}
	}
	optlist.options[totalOps] = new Option(txtadd,valadd);
} 




function selectRemoveOption(fe, val2remove ) {
    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (val2remove==optlist.options[j].value){  
		optlist.options[j]=null; 
		break; 
	   } 
     }
  } 
function selectChangeTxtOption(fe, listvalue, newtext ) {
    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (listvalue==optlist.options[j].value){  
		optlist.options[j].text=newtext; 
		break; 
	   } 
     }
  } 
function selectGetTxt(fe,val) {

    var optlist = document.getElementById(fe); 
     for (var j = 0; j < optlist.options.length; j++){  
	if (val==optlist.options[j].value){  
	   return optlist.options[j].text;
	   } 
     }
  } 
function selectGetSelectedTxt(fe) {
    var optlist = document.getElementById(fe); 
    
	for(var i=0; i< optlist.options.length; i++) {
		if(optlist.options[i].selected==true){
			return optlist.options[i].text;
		}
	}
}



function selectIsSameTxtInList(e,newTxt){
    var optlist = document.getElementById(e); 
	for(var i=0; i< optlist.options.length; i++) {
		if ( newTxt==optlist.options[i].text && optlist.options[i].selected==false ){  
			return 1;
		}
	}
			return 0;
}




Array.prototype.find = function(searchStr) {
  var returnArray = false;
  for (i=0; i<this.length; i++) {
    if (typeof(searchStr) == 'function') {
      if (searchStr.test(this[i])) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    } else {
      if (this[i]===searchStr) {
        if (!returnArray) { returnArray = [] }
        returnArray.push(i);
      }
    }
  }
  return returnArray;
}

 
 
function inArray(a){              
  var o = {};
  for(var i=0;i<=a.length;i++){
    o[a[i]]='';
  }
  return o;
}


String.prototype.trimDblSpaces = function () { // remove double spaces
	return this.replace(/\s+/g," ");
}



String.prototype.trimEnds = function () { // trim white-space off both ends of object string
	return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
 

String.prototype.enc = function () { // convert ampersand
//	return this.replace(/&/g,'%26');

	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = this;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;

}



function html_entity_decode(str) {
  var dec = str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return dec;
}



function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function checkVersion()
{
  var msg = "You're not using Internet Explorer.";
  var ver = getInternetExplorerVersion();

  if ( ver > -1 )
  {
    if ( ver >= 8.0 ) 
      msg = "You're using a recent copy of Internet Explorer."
    else
      msg = "You should upgrade your copy of Internet Explorer.";
  }
  alert( msg );
}







var dateFormat = function () {
	var	token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,
		timezone = /\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,
		timezoneClip = /[^-+\dA-Z]/g,
		pad = function (val, len) {
			val = String(val);
			len = len || 2;
			while (val.length < len) val = "0" + val;
			return val;
		};

	// Regexes and supporting functions are cached through closure
	return function (date, mask, utc) {
		var dF = dateFormat;

		// You can't provide utc if you skip other args (use the "UTC:" mask prefix)
		if (arguments.length == 1 && Object.prototype.toString.call(date) == "[object String]" && !/\d/.test(date)) {
			mask = date;
			date = undefined;
		}

		// Passing date through Date applies Date.parse, if necessary
		date = date ? new Date(date) : new Date;
		if (isNaN(date)) throw SyntaxError("invalid date");

		mask = String(dF.masks[mask] || mask || dF.masks["default"]);

		// Allow setting the utc argument via the mask
		if (mask.slice(0, 4) == "UTC:") {
			mask = mask.slice(4);
			utc = true;
		}

		var	_ = utc ? "getUTC" : "get",
			d = date[_ + "Date"](),
			D = date[_ + "Day"](),
			m = date[_ + "Month"](),
			y = date[_ + "FullYear"](),
			H = date[_ + "Hours"](),
			M = date[_ + "Minutes"](),
			s = date[_ + "Seconds"](),
			L = date[_ + "Milliseconds"](),
			o = utc ? 0 : date.getTimezoneOffset(),
			flags = {
				d:    d,
				dd:   pad(d),
				ddd:  dF.i18n.dayNames[D],
				dddd: dF.i18n.dayNames[D + 7],
				m:    m + 1,
				mm:   pad(m + 1),
				mmm:  dF.i18n.monthNames[m],
				mmmm: dF.i18n.monthNames[m + 12],
				yy:   String(y).slice(2),
				yyyy: y,
				h:    H % 12 || 12,
				hh:   pad(H % 12 || 12),
				H:    H,
				HH:   pad(H),
				M:    M,
				MM:   pad(M),
				s:    s,
				ss:   pad(s),
				l:    pad(L, 3),
				L:    pad(L > 99 ? Math.round(L / 10) : L),
				t:    H < 12 ? "a"  : "p",
				tt:   H < 12 ? "am" : "pm",
				T:    H < 12 ? "A"  : "P",
				TT:   H < 12 ? "AM" : "PM",
				Z:    utc ? "UTC" : (String(date).match(timezone) || [""]).pop().replace(timezoneClip, ""),
				o:    (o > 0 ? "-" : "+") + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4),
				S:    ["th", "st", "nd", "rd"][d % 10 > 3 ? 0 : (d % 100 - d % 10 != 10) * d % 10]
			};

		return mask.replace(token, function ($0) {
			return $0 in flags ? flags[$0] : $0.slice(1, $0.length - 1);
		});
	};
}();

// Some common format strings
dateFormat.masks = {
	"default":      "ddd mmm dd yyyy HH:MM:ss",
	shortDate:      "m/d/yy",
	mediumDate:     "mmm d, yyyy",
	longDate:       "mmmm d, yyyy",
	fullDate:       "dddd, mmmm d, yyyy",
	shortTime:      "h:MM TT",
	mediumTime:     "h:MM:ss TT",
	longTime:       "h:MM:ss TT Z",
	isoDate:        "yyyy-mm-dd",
	isoTime:        "HH:MM:ss",
	isoDateTime:    "yyyy-mm-dd'T'HH:MM:ss",
	isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
};

// Internationalization strings
dateFormat.i18n = {
	dayNames: [
		"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	],
	monthNames: [
		"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
		"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
	]
};

// For convenience...
Date.prototype.format = function (mask, utc) {
	return dateFormat(this, mask, utc);
};




















function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}



function trimEnds2(str){
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');

}
 



String.prototype.revString = function() {
    var s = "";
    var i = this.length;
    while (i>0) {
        s += this.substring(i-1,i);
        i--;
    }
    return s;
}





function setLastMouse(){
	GBL_KEY_OR_MOUSE='mouse'; 
}


function keypress(e){

	var keycode;

	if (window.event){
		keycode = window.event.keyCode;
	} else if (e) { 
	 	keycode = e.which;
	}

	GLB_KEY_BEFORE_LAST = GLB_LASTKEY_PRESSED;
	GLB_LASTKEY_PRESSED = keycode;
	GBL_KEY_OR_MOUSE = 'key';


}




function stripCC(e) { 

 	var retval = e.replace(/[^0-9-]/g, ''); 
	retval = retval.replace(/--/g, '');
			

   	return retval; 
}


function stripAlpha(e) { 

 	var retval = e.replace(/[^0-9]/g, ''); 
   	return retval; 
}
 

function stripNonAlpha(e) { 

 	var retval = e.replace(/[0-9-]/g, ''); 
   	return retval; 
}


// Get elementById
function getElement(obj){
var theObj;

	if(document.all) {			// If IE
	  if(typeof obj=="string"){
	  	return document.all(obj);
	    } 
	  else {
	   	return obj;
	    }
	 }

	if(document.getElementById) {  		// Everything Else
	  if(typeof obj=="string") {
	  	return document.getElementById(obj);
	    } 
	  else {
	  	return obj;
	   }
	 }
	 
   return null;
}



function fmatComma(nStr)
{
	nStr += '';
	var x = nStr.split('.');
	var x1 = x[0];
	var x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}










function setCaretPosition(Id, caretPos) {

    var elem = getElement(Id);
    var cpos = elem.value.length;
    
    
    if(caretPos==0) // start
      cpos = 0;
    
    
//alert( cpos    );
    

    if(elem != null) { 
        if(elem.createTextRange) {
            var range = elem.createTextRange();
            range.move('character', cpos);
            range.select();
        }
        else {
            if(elem.selectionStart) {
                elem.focus();
                elem.setSelectionRange(cpos, cpos);
            }
            else
                elem.focus();
        }
    }
}





function findPos(id) {

	var obj = document.getElementById(id);

	var curleft = curtop = 0;

	if (obj.offsetParent) {

	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
	} 
	while (obj = obj.offsetParent);
	}

	return [curleft,curtop];
}



function getXY(id, getTopRight) {

	var XAX = 0;
	var YAX = 0;
	var obj = document.getElementById(id);
	var objcopy = document.getElementById(id);

	if(obj.offsetParent){
		while(obj.offsetParent)	{
			XAX += obj.offsetLeft;
			YAX += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if(obj.x) {
		XAX += obj.x;
		YAX += obj.y;
	}

	var xy = [XAX, YAX];
	
	return xy;

}

 



function moveDiv( id, x, y) {

	var obj = getElement(id);

	obj.style.position = "absolute";
	obj.style.left = x + 'px';
	obj.style.top = y + 'px';	
}






function getNextDiv(){
//	var tds = document.getElementById("cat_5969").nextSibling;
//	alert( document.getElementById(tds)  );
}







function addNewDiv( parentdiv, newdivid, innerhtml, nodelevel, marginleft, height, width, position, border, bgcolor, cssclassname, cbtag_clear, cbtag_height ){

		var divTag 	= document.createElement("div");
		var cbTag 	= document.createElement("div");
		var parentTag 	= document.getElementById(parentdiv);


		var parentOfParent = document.getElementById(parentTag.parentNode.id);

		divTag.id = newdivid;

 		divTag.style.height = height;
 		divTag.style.width = width;
 		divTag.style.position = position;
 		divTag.style.border = border;		//"1px green solid"

 		divTag.style.marginLeft = marginleft;

		divTag.className = cssclassname;		
		divTag.innerHTML  = innerhtml;


		cbTag.style.clear = cbtag_clear;
 		cbTag.style.height = cbtag_height;
 		
	
		parentOfParent.insertBefore(divTag, parentTag.nextSibling);

		parentOfParent.insertBefore(cbTag, parentTag.nextSibling);


		GBL_NEWNODES.push(newdivid);		// add to array of new divs



}



function addChildInDiv(parentdiv, newdiv, inhtml, marginTop){

	var x = document.createElement('div');
	x.setAttribute('id',newdiv);
	x.style.marginTop = marginTop+'px';
	x.innerHTML=inhtml;
	document.getElementById(parentdiv).appendChild(x);

}





function  increment(e){		// increment numbergroup in element 

	var curNum	= getVal(e);

	if(curNum=='')
	  curNum = '0';

	
	
	var zeros = '', count=0;
	var theString = curNum.replace(/[^0-9]/g,'~AH~');
	var strAry = theString.split('~AH~');
	var strAry = strAry.reverse();

	for(i=0;i<strAry.length;i++){
		if(Number(strAry[i])>=0){
			var theNum = strAry[i];
			break;
		}
	}


	var curNum = curNum.replace( theNum, '~~~InvNum~~~' );
	
	for(i=0;i<theNum.length;i++){
		if(theNum.charAt(i)=='0'){
			count++;
			var zeros = zeros + '0';
		}else{
			break;
		}
	}

	var newNum = Number(theNum) + 1;
	var newNum  = zeros + newNum.toString();

	if( theNum.length < newNum.length && count > 0 )
	var newNum = newNum.substring(1,newNum.length);
	var newVal = curNum.replace( '~~~InvNum~~~', newNum );


	setVal(e,newVal); 
}


function  decrement(e){		// decrement numbergroup in element 

	var curNum	= getVal(e);
	
	if(curNum=='')
	  curNum = '0';

	if(curNum==0)
	  return

	var zeros = '', count=0;
	var theString = curNum.replace(/[^0-9]/g,'~AH~');
	var strAry = theString.split('~AH~');
	var strAry = strAry.reverse();

	for(i=0;i<strAry.length;i++){
		if(Number(strAry[i])>=0){
			var theNum = strAry[i];
			break;
		}
	}


	var curNum = curNum.replace( theNum, '~~~InvNum~~~' );
	
	for(i=0;i<theNum.length;i++){
		if(theNum.charAt(i)=='0'){
			count++;
			var zeros = zeros + '0';
		}else{
			break;
		}
	}

	var newNum = Number(theNum) - 1;
	var newNum  = zeros + newNum.toString();

	if( theNum.length < newNum.length && count > 0 )
	var newNum = newNum.substring(1,newNum.length);
	var newVal = curNum.replace( '~~~InvNum~~~', newNum );

	setVal(e,newVal); 
}



function recordMsg(e,t){
    togDiv(e,1);
    setZ(e,1000);
    setTimeout("togDiv('"+e+"',0)",t);
}






String.prototype.reverse = function(){
splitext = this.split("");
revertext = splitext.reverse();
reversed = revertext.join("");
return reversed;
}






function countDown(displayElement, cdownFrom){

	setInHtml(displayElement,cdownFrom);
	cdownFrom = cdownFrom-1;

	if(cdownFrom>0){
		var cd = "countDown('" + displayElement + "', " + cdownFrom + ")";
		setTimeout(cd, 1000);
	}


}




function startdrag(t, e) {  
    if (e.preventDefault) e.preventDefault(); //line for IE compatibility  
    e.cancelBubble = true;  
    window.document.onmousemoveOld = window.document.onmousemove;  
    window.document.onmouseupOld = window.document.onmouseup;  
    window.document.onmousemove=dodrag;  
    window.document.onmouseup=stopdrag;  
    window.document.draged = t;  
    t.dragX = e.clientX;  
    t.dragY = e.clientY;  
    return false;  
}  
//move the DIV  
function dodrag(e) {  
      
    if (!e) e = event; //line for IE compatibility  
    t = window.document.draged;  
    t.style.left = (t.offsetLeft + e.clientX - t.dragX)+"px";  
    t.style.top = (t.offsetTop + e.clientY - t.dragY)+"px";  
    t.dragX = e.clientX;  
    t.dragY = e.clientY;  
    return false;  
}  
//restore event-handlers  
function stopdrag() {  
   window.document.onmousemove=window.document.onmousemoveOld;  
   window.document.onmouseup=window.document.onmouseupOld;  
}  





function pause(milliseconds) {
	var dt = new Date();
	while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}





function fade(TimeToFade, eid)
{
  var element = document.getElementById(eid);
  if(element == null)
    return;
   
  if(element.FadeState == null)
  {
    if(element.style.opacity == null 
        || element.style.opacity == '' 
        || element.style.opacity == '1')
    {
      element.FadeState = 2;
    }
    else
    {
      element.FadeState = -2;
    }
  }
    
  if(element.FadeState == 1 || element.FadeState == -1)
  {
    element.FadeState = element.FadeState == 1 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
  }
  else
  {
    element.FadeState = element.FadeState == 2 ? -1 : 1;
    element.FadeTimeLeft = TimeToFade;
    setTimeout("   animateFade(" + new Date().getTime() + ",'" + eid + "'," + TimeToFade + ")", 33);
  }  
}


function animateFade(lastTick, eid, TimeToFade)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
  
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = ' 
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
  
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}



//#############################   

function RZ_preventEvent(e) {
	var ev = e || window.event;
	if (ev.preventDefault) ev.preventDefault();
	else ev.returnValue = false;
	if (ev.stopPropagation)
		ev.stopPropagation();
	return false;
}

function RZ_getStyle(x, styleProp) {
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}
function RZ_getWidth(x) {
	if (x.currentStyle)
		var y = x.clientWidth - parseInt(x.currentStyle["paddingLeft"]) - parseInt(x.currentStyle["paddingRight"]);
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue("width");
	return y || 0;
}
function setCookie (name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}
function getCookie(name) {
	var cookie = " " + document.cookie;
	var search = " " + name + "=";
	var setStr = null;
	var offset = 0;
	var end = 0;
	if (cookie.length > 0) {
		offset = cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = cookie.indexOf(";", offset)
			if (end == -1) {
				end = cookie.length;
			}
			setStr = unescape(cookie.substring(offset, end));
		}
	}
	return(setStr);
}
function RZ_ColumnResize(table) {
	if (table.tagName != 'TABLE') return;
	this.id = table.id;
	var self = this;
	var dragColumns  = table.rows[0].cells; // first row columns, used for changing of width
	if (!dragColumns) return; // return if no table exists or no one row exists
	var dragColumnNo; // current dragging column
	var dragX;        // last event X mouse coordinate
	var saveOnmouseup;   // save document onmouseup event handler
	var saveOnmousemove; // save document onmousemove event handler
	var saveBodyCursor;  // save body cursor property
	this.changeColumnWidth = function(no, w) {
		if (!dragColumns) return false;
		if (no < 0) return false;
		if (dragColumns.length < no) return false;
		if (parseInt(dragColumns[no].style.width) <= -w) return false;
		if (dragColumns[no+1] && parseInt(dragColumns[no+1].style.width) <= w) return false;
		dragColumns[no].style.width = parseInt(dragColumns[no].style.width) + w +'px';
		if (dragColumns[no+1])
			dragColumns[no+1].style.width = parseInt(dragColumns[no+1].style.width) - w + 'px';
		return true;
	}
	this.columnDrag = function(e) {  
		var e = e || window.event;
		var X = e.clientX || e.pageX;
		if (!self.changeColumnWidth(dragColumnNo, X-dragX)) {
			self.stopColumnDrag(e);
		}
		dragX = X;
		RZ_preventEvent(e);
		return false;
	}
	this.stopColumnDrag = function(e) {
		var e = e || window.event;
		if (!dragColumns) return;
		document.onmouseup  = saveOnmouseup;
		document.onmousemove = saveOnmousemove;
		document.body.style.cursor = saveBodyCursor;
		var colWidth = '';
		var separator = '';
		for (var i=0; i<dragColumns.length; i++) {
			colWidth += separator + parseInt( RZ_getWidth(dragColumns[i]) );
			separator = '+';
		}
		var expire = new Date();
		expire.setDate(expire.getDate() + 365); // year
		document.cookie = self.id + '-width=' + colWidth +
			'; expires=' + expire.toGMTString();

		RZ_preventEvent(e);
	}
	this.startColumnDrag = function(e) {
		var e = e || window.event;
		dragColumnNo = (e.target || e.srcElement).parentNode.parentNode.cellIndex;
		dragX = e.clientX || e.pageX;
		var colWidth = new Array();
		for (var i=0; i<dragColumns.length; i++)
			colWidth[i] = parseInt( RZ_getWidth(dragColumns[i]) );
		for (var i=0; i<dragColumns.length; i++) {
			dragColumns[i].width = ""; // for sure
			dragColumns[i].style.width = colWidth[i] + "px";
		}

		saveOnmouseup       = document.onmouseup;
		document.onmouseup  = self.stopColumnDrag;

		saveBodyCursor             = document.body.style.cursor;
		document.body.style.cursor = 'w-resize';

		// fire!
		saveOnmousemove      = document.onmousemove;
		document.onmousemove = self.columnDrag;

		RZ_preventEvent(e);
	}
	for (var i=0; i<dragColumns.length; i++) {
		dragColumns[i].innerHTML = "<div style='position:relative;height:100%;width:100%'>"+
			"<div style='"+
			"position:absolute;height:100%;width:5px;margin-right:-5px;"+
			"left:100%;top:0px;cursor:w-resize;z-index:10;'>"+
			"</div>"+
			dragColumns[i].innerHTML+
			"</div>";
			// BUGBUG: calculate real border width instead of 5px!!!
			dragColumns[i].firstChild.firstChild.onmousedown = this.startColumnDrag;
		}
}

var resizableTables = new Array();
function RZ_ResizableColumns() {

	var tables = document.getElementsByTagName('table');
	for (var i=0; tables.item(i); i++) {
		if (tables[i].className.match(/RZ_resizable/)) {
			// generate id
			if (!tables[i].id) tables[i].id = 'table'+(i+1);
			// make table resizable
			resizableTables[resizableTables.length] = new RZ_ColumnResize(tables[i]);
		}
	}
}

// ################################################################
