//
/*
This page for generic text and image objects with their  handling*/
//alert('got generic')
///  gather divs & co into field groups from containing div
//alert("in generic")

function grabElements(skin){	
	els = skin.getElementsByTagName("*")
	skin.flds = Array()
	var fry = skin.flds
	for(oi=0;oi<els.length;oi++){
		if(els[oi].id && els[oi].id.indexOf("_") > 0){
			obts = els[oi].id.split("_")
			ofld = obts[1] + '_' + obts[2]
			var fobj =  kgetv(fry, ofld, true)
			fobj[1].fld =ofld
			fobj[1].dad = skin
			if((!obts[3]  || obts[3]>0) && obts[0] == "dv"){//grab htm showing div
			
				fobj[1].htm = els[oi]
				fobj[1].htm.dad = fobj[1]
				fobj[1].htm.fnm = ofld
			}
			else if(obts[0] == "lnm"){// grab the commentator
				//alert("got lnm")
				skin.lnm = els[oi]
				skin.lnm.dad = skin
			}

			else if(obts[1] == "btn"){// a pseudo field keep away from data
				fobj[1].btn = els[oi]
				fobj[1].btn.dad = fobj[1]
				//alert("boo" + fobj[1].fld)
			}
			else if(obts[0] == "btn"){// a pseudo field keep away from data
				fobj[1].htm = els[oi]
				fobj[1].htm.dad = fobj[1]
				fobj[1].htm.trg = obts[2]
			}
			else if(obts[0] == "dv"){///  grab edit showing div
				fobj[1].edt  = els[oi]
				fobj[1].edt.dad = fobj[1]
			}
			else if(obts[0] == "img"){/// as tag
				fobj[1].pic  = els[oi]
				fobj[1].pic.dad = fobj[1]
			}
			else if(obts[0] == "txt"){
				fobj[1].tx  = els[oi]
				fobj[1].tx.dad = fobj[1]
				fobj[1].tx.fld =ofld
			}
			else if(obts[0] == "ddl"){
				fobj[1].ddl = els[oi]
				fobj[1].ddl.dad = fobj[1]
			}
			else if(obts[0] == "com"){// comment, essentially a sub text-field to an image object
				fobj[1].com = els[oi]
				fobj[1].com.dad = fobj[1]
			}
			else if(obts[0] == "off"){// the off icon for a flip button
				//alert("got off icon")//
				fobj[1].off = els[oi]
				fobj[1].off.dad = fobj[1]
			}
			
			else{
				if(!(fobj[1].elms && fobj[1].elms[0])){// may be useful
					fobj[1].elms = Array(els[oi])
				}
				else{
					fobj[1].elms[fobj[1].elms.length] = els[oi]
				}
			}
		}
	}	
	return 1
}
function autograb(dadv){
	obj = new Object()
	obj.sk = dadv
	obj.clls = Array()
	var kdvs = dadv.getElementsByTagName("div")
	
	for(var i = 0 ; i < kdvs.length ; i++){
		if(kdvs[i].id){
			prp =   kdvs[i].id.substr(( kdvs[i].id.lastIndexOf("-") +1),6)
			//sqwk("boo\n" +  prp)
			obj.clls[i] =  kdvs[i]
			 kdvs[i].dad = obj
			 kdvs[i].nme = prp
		}
	}
	return obj
}
///  initialize text, image objects etc.
function initobjs(skin){
	//document.lnm.innerHTML += "<br>Init objects<br>"
			//if(skin.id == "btn-row"){alert("in init btnrw")}
	
	if(skin.flds && skin.flds[0][1]){
		var fry = skin.flds
		for(var i=0;i<fry.length;i++){
			var bts = fry[i][0].split("_")
			//fdnm = bts[1] + '_' + bts[2]
			var fdob = fry[i][1]
			if(fdob.htm && fdob.tx && fdob.edt){
				mktxob(fdob)
				//document.lnm.innerHTML += "Text object " + fdob.fld+ "<br>"
			}			
			if(fdob.htm && fdob.pic && fdob.edt){
				mkimob(fdob)
				//document.lnm.innerHTML += "<br>Image object " + fdob.fld
			}			
			if(fdob.off  && fdob.htm && fdob.edt){//
				mkicob(fdob)
				document.lnm.innerHTML += "<br>Icon object " + fdob.fld
			}
			
			if(fdob.htm &&  bts[0] == "upl"){
				//alert("in init upl\n" + bts[1])////
				mkupld(fdob)
				document.lnm.innerHTML += "<br>upload object " + fdob.fld
			}
		
			if(fdob.htm &&  bts[1] == "bdt"){
				//alert("off to init ed btn")//
				mkedbtn(fdob)
				document.lnm.innerHTML += "<br>upload object " + fdob.fld
			}
			else if(fdob.htm &&  bts[0] == "btn"){
				//alert(" in mkbtn")
				mkbtn(fdob)
				document.lnm.innerHTML += "<br>btn object object " + fdob.fld
				
			}
			
				
		}		
	}
	else{
		//alert("no fields on " + skin.id)
	}
}

//###########################################
//###########            text object         #################
function mktxob(fdob){
	fdob.typ = "t"
	fdob.setv = txsetv
	fdob.setedt = txsetedt
	if (fdob.fld == "supplier_bnt") fdob.shwed = true; 
	//fdob.goedt = txgoedt
	fdob.tx.auto = true // default auto update onblur
	if(pgspc.constructor){pgspc(fdob)}  // opportunity to customize on the page's own js file
}
function txsetv(rstr){
	
	var vl = rsval(rstr, this.fld)
	this.htm.innerHTML = vl ? vl : "N/G"
	this.tx.value = vl ? vl : "N/G"
	this.htm.style.display = vl && !this.shwed ? "block" : "none"
	this.edt.style.display = "none"
	//document.lnm.innerHTML += "<br> val :" + vl.substr(0,20)
	if (this.fld == "supplier_bnt") { this.dad.bannerurl = vl; }
	if(this.onsetv){eval(this.onsetv)}
}

function txsetedt(bl){
	if(this.shwed ){
		this.htm.style.display = bl ?  "block" : "none"
	}
	this.htm.style.border = bl ? document.edbrd : "none"
	//this.htm.style.display =  (vl || bl) ? "block" : "none"
	nixlnk(this.htm, bl)
	this.htm.onclick = txgoedt
	if(this.onsetedt){eval(this.onsetedt)}
}
 function txgoedt(bl){
	//alert(this.id)
	var tx = this.dad.tx
	var edt = this.dad.edt
	mkactv(tx)
	if(tx){
		//alert(this.innerHTML)
		txvl = txtohtm(this.innerHTML, false)
		tx.value = txvl
		this.style.display = "none"
		edt.style.display = "block"
		tx.dty = txvl  //dirty, ie. store original value to check if altered
		tx.onblur = txonblur
		tx.focus()
	}
	else{
		alert("no tx for " + this.id)
		
			
	}
	if(this.ongoedt){eval(this.ongoedt)}
	
}

function txonblur (){
	if((this.dty != this.value) && this.auto){
		//alert("blurrin\n" + document.ssme + "\n rwid " + this.dad.dad.rwid)//
		if(document.ssme*1 < 0 || (this.dad.dad &&  this.dad.dad.cde != "upd")){
			fnm = this.dad.fld
			dbid = this.dad.dad.rwid		
			if (fnm.indexOf("_bnt") > 0) {
			arg = fnm + '~c~' + this.value + '~c~' + dbid;
			}
			else { arg = fnm + '~c~' + txtohtm(this.value, true) + '~c~' + dbid; }
			if(this.dty.indexOf("@") == -1 &&  this.value.indexOf("@") > 0 && fnm.indexOf("_eml") > 0 && document.ssme*1 <0){
				if(confirm("New e-mail address eh?\n'spose we'd better tell them?")){
					arg +=  '~c~newsup.txt'
				}
			}
			kzam("doupdt", arg)
		}
		else{
			this.dad.htm.innerHTML  = this.value
			this.dad.edt .style.display = "none"
			this.dad.htm.style.display = "block"
			alert("Local edit only\nNOT saved to the Web")
		}
	}
	else{
		this.dad.edt .style.display = "none"
		this.dad.htm.style.display = "block"
	}
}
//###########            end text obj       #################



//###########################################
//###########            image object         #################
function mkimob(fdob){
	fdob.typ = "i"
	fdob.setv =imsetv
	fdob.setedt = imsetedt
	fdob.goedt = imgoedt
	if(pgspc.constructor){pgspc(fdob) }  // opportunity to customize on the page's own js file
}
function imsetv(rstr){
	vl = rsval(rstr, this.fld)
		//if(bts[2] == "pc1"){alert(this.id + '\n' + vl)}
	//alert(this.fld)
	if(vl && vl.indexOf(":IM:") + 1 && this. com){
		///alert("got com ob")
		var b = vl.split(":IM:")
		vl = b[0]
		 this.dad.com.innerHTML = b[1]
	}
	
	this.pic.src = vl ? vl : ""
	this.htm.style.display = vl ? "block" : "none"   ///// default hide div if no image	
	if(this.onsetv){eval(this.onsetv)}
}
function imsetedt(bl){
	this.htm.style.display = "block"
	this.htm.style.border = bl ? document.edbrd : ''
	nixlnk(this.htm, bl)
	this.htm.onclick = imgoedt
	if(this.onsetedt){eval(this.onsetedt)}	
}
function imgoedt(){
	//alert("imgo id\n" + this.id + '\n' + this.dad.pic.src + '\n'  + this.dad.dad.rwid)
	this.dad.edt.style.border = "2px solid #009933"
	this.dad.edt.style.display = "block"
	this.style.display = "block"
	//this.dad.edt.innerHTML = "Click to Pick"
	if(this.dad.com){
		//this.dad.tx.value = txtohtm(this.dad.com,false)
		txgoed.call(this)
	//alert("boo -")
	}
	if(document.actv && document.actv.onblur){
		document.actv.blur()
	}
	document.actv = this
		whwd = " and img_fld = '"+  this.dad.fld +"'"

	//alert(this.dad.dad.cmpid)

	arg = "where 1" + (whwd ?  whwd : "") 
	//alert(arg)
	kzam("getims",  arg)  ////////////   ##  returns to   mkimpck	
}

function mkimpck(str){
	var ht = document.actv
	var ed = ht.dad.edt
	ed.style.zIndex = "50"
	var cols = 3
	//alert(str.replace(/:R:/g, '\n'))
	if (ed && str && ht){
		ed.datry = str.indexOf(":R:") + 1 ? str.split(":R:") : Array(str)
		tot = ed.datry.length
		ed.style.border = "2px solid #009933"
		ed.style.width ="340px"
		vardvttl = mkel(ed,'div')
		//vardvttl.className = "property-name-sr"  ///////#### in style-properties.css
		vardvttl.innerHTML = "Wizzy-dizzy piccy picker<br><span style='font-size:.4em;'>Click here to close</span>"
		vardvttl.edt = ed 
		vardvttl.onclick = function(){
				this.edt.style.display = "none"
				this.edt.innerHTML = ""						
					}
		for(var i =0 ; i< tot ; i++){
			if(!(i%cols)){
				var rw = mkel(ed,'div')
				var sf = mkel(rw,'div')
				sf.style.clear = "both"
				rw.sf = sf
				rw.style.margin = "5px 5px 5px 5px"
				ed.rw = rw
			}
			url = rsval(ed.datry[i],"img_url")
			id =  rsval(ed.datry[i],"img_id")
			var exo = mkdblcell(ed.rw)
			exo.style.margin = "5px 5px 5px 5px"
			var im = mkel(exo.endo, 'img')
			im.style.height = "50px"
			im.style.width = "auto"
			im.src =url
			exo.endo.htm = ht
			exo.endo.url = url
			exo.endo.onclick = picclk
		}
		//alert("In impck\n" + str +'\n'+ ht.id +'\n'+ ed.id)
	}
	
}
function picclk(){	//alert("got it \n" + this.htm.dad.pic.src + '\n' + this.url + '\n' + document.actv.id)//
	if(document.actv && document.actv != this.htm){
		 if(document.actv.quit){
			document.actv.quit()
		}
		else if( document.actv.onblur){
			 document.actv.blur()
		}		
		else{
			alert("Trouble setting that value for \n" + document.actv.id)
		}
	}
	document.actv = this.htm.dad.pic
	if( this.url != this.ov){
		bs = this.htm.id.split("_")
		//alert("Pickin' \n" + bs[1] + '_' + bs[2] + '~c~' + this.val  + '~c~' + bs[3] )
		imvl = this.url.replace ( /^.+?_basca-active./, "")
		//alert("im val " + imvl)
		cmvl = ( this.htm.dad.com ? ':IM:' + txtohtm(this.htm.dad.tx.value, true) : "" )
		//alert("cm val " + cmvl)
		
		arg = bs[1] + '_' + bs[2] + '~c~' + imvl  + cmvl + '~c~' + bs[3]
	//alert(arg)////
		kzam("cmupd",  arg)
	}
	this.htm.dad.edt.style.display = "none"
	this.htm.dad.edt.innerHTML = ""
	
	return false
}

//###########            end image obj       #################

//###########################################
//###########         on/off   icon object         #################
function mkicob(fdob){
	var htm = fdob.htm
	var edt = fdob.edt 
	var off = fdob.off
	if(htm && edt && off){
		fdob.typ = "c"
		fdob.setv =icsetv
		fdob.setedt = icsetedt
		fdob.goedt = icgoedt
		fdob.onseted = "this.iconst()"
		fdob.iconst = iconset
		//
	}
	else{
		alert(htm.id +  '\n' +  edt.id +  '\n' +  off.id)
	}
}
function icsetv(rstr){	
	vl = rsval(rstr, this.fld)
	//alert("val icon" + vl)
	this.vl = vl
	this.off.style.display = (vl  ==1 ? "block" : "none")
	this.htm.style.display = (vl  ==1 ? "none" : "block")
	this.dad.style.display = ((vl  ==1) && (document.admin != -1) ? "none" : "block")
	if(this.onsetv){eval(this.onsetv)}
	
}
function icsetedt(bl){
	this.edt.style.display = bl ? "block" : "none"
	this.edt.onclick = icgoedt	
	if(this.onseted){eval(this.onseted)}
}
function iconset(){
	var hde = this.off	
	vl = (hde.style.display == "none" ? 1  : 0)
	//alert ("onset\n" + document.admin + '\n' + vl)
	this.dad.style.display = ( (this.vl  ==1) && (document.admin != -1) ? "none" : "block")	
}
function icgoedt(){
	var shw = this.dad.htm
	var hde = this.dad.off
	//shw.style.display = (shw.style.display == "none") ?  "block"  : "none"
	//hde.style.display = (hde.style.display == "none") ?  "block"  : "none"
	vl = (hde.style.display == "none" ? 1  : 0)
	fnm = this.dad.fld
	dbid = this.dad.dad.rwid
	arg = fnm + '~c~' + vl + '~c~' + dbid 
	mkactv(this)
	kzam("doupdt", arg)
	//alert(this.id)alert(arg)
}
//###########            end icon obj       #################

//###########################################
//############     upload object             ###############
function mkupld(fdob){
		//alert("got upload")//
		fdob.setedt =  uplsetedt
		fdob.htm.onclick = function (){
					cde =  (this.dad.dad.cde ?  this.dad.dad.cde : document.cde)
					//alert(this.dad.dad.rwid + '\n' + this.trg +  '\n' + cde)
					var upmg = document.upld
					if(upmg.style.display != 'block' || this.trg != upmg.trg){
						upmg.style.display = 'block'
					  upmg.trg = this.trg
					  upmg.style.zIndex = 10
						upmg.ttl.innerHTML = this.dad.ttl
						var f = document.pat
						f.hidcmpid.value =  this.dad.supl//this.id.substr(11,4)
						f.hidrelpth.value =  this.dad.pth
						document.curcmpid = this.dad.supl;						
						document.curcmpfld = this.trg;
						f.hidfld.value = this.trg
						//f.filupm.focus()
						}
					else{
						upmg.style.display = 'none'
					}
					//alert("you clicked sir")
				}
			
}

function dodelimg() {

			arg = 'supplier_'+document.curcmpfld + '~c~~c~' + document.curcmpid ;
			kzam("doupdt", arg);

}
function uplsetedt(bl){
	cde =  (this.dad.cde ?  this.dad.cde : document.cde)
	//alert(this.htm.style.display )
	if(cde == "bnr" || 0 > document.ssme){
		this.ttl = "Browse to the " + (this.htm.trg =="lgo" ? "logo" : "banner") + " you wish to upload<br>"
		this.ttl += "Large pictures will take a long time to upload<br>and may send the page awry<br>"
		this.ttl += "This will be saved to the Web"
		this.pth = "supplier-images"	
		this.supl = this.dad.rwid	
	}
	else if(cde == "upd"){
		this.ttl = "Browse to the " + (this.htm.trg =="lgo" ? "logo" : "banner") + " you wish to upload<br>"
		this.ttl += "Large pictures will take a long time to upload<br>and may send the page awry<br>"
		this.ttl += "This is for personal viewing only, so wont be saved to the Web"
		this.pth = "supplier-temp"
		this.supl = 0
	}
	else if(cde == "std"){
		this.ttl = "Browse to the " + (this.htm.trg =="lgo" ? "logo" : "banner") + " you wish to upload<br>"
		this.ttl += "Large pictures will take a long time to upload<br>and may send the page awry<br>"
		if(this.htm.trg =="lgo"){
			this.ttl += "This will be saved to the Web"
			this.pth = "supplier-images"	
			this.supl = this.dad.rwid
		}
		if(this.htm.trg == "bnr"){
			this.ttl += "This is for personal viewing only, so wont be saved to the Web"
			this.pth = "supplier-temp"	
			this.supl = 0		
		}
	}

	this.htm.style.display = (bl ? 'block' : "none" )
}

//############     end upload object             ###############

///############## edit button ob#####################
function mkedbtn(fo){
	//alert( "making " + fo.fld)//
	
	fo.dad.setedt =  shwedt
	fo.dad.edbn = fo.htm
	fo.htm.cln = fo.dad
	fo.htm.onclick = edbtnclk	
	
}
function  edbtnclk(){
	if(!(window.location.search)){
		window.location = window.location + "?sdgf345dfhb" + this.cln.rwid
	}
	if(document.edcln && document.edcln != this.cln){
		edbtnclk.call(document.edcln.edbn)
	}
	document.doed = (this.innerHTML == "Click to make changes" ? true : false)
	this.innerHTML = (document.doed ? "Click to view changes" : "Click to make changes")
	clsetedt.call(this.cln, document.doed)
	document.edcln = document.doed ? this.cln : null
	document.catedt.setedt(document.doed)
	return 1
}
 function shwedt(bl){
	//alert("in show\n" )
	
	if(document.admin == -1 || document.admin == this.rwid){
		//alert(this.hlp.id)
		//this.hlp.style.display = (bl ?  "block" : "none")
			//alert("clone set edit for rwid :" + this.rwid  + "\ndoc admin :" + document.admin)
		this.edbn.style.display = (bl ?  "block" : "none")
		
	}
}
///############## end edit button ob#####################
//################   help thingy    ######################
function mkhlpob(fo){
	//fo.vis.pup = fo
	//fo.dad.hlp = fo.visalert(fo.fld)
	

	fo.setv = hlpsetv
	var kids = fo.childNodes
	for(var i=0;i<kids.length;i++){
		if(kids[i].id == "dv-buystd"){fo.bstd = kids[i];fo.bstd.dad = fo}
		if(kids[i].id == "dv-buybnr"){fo.bbnr = kids[i];fo.bbnr.dad = fo}
	}
}
function hlpsetv(){
	if(document.cde){
		cde = document.cde
		//alert(cde)
		this.cde = cde
		this.style.display = "block"
		var lv = this.childNodes[0]
		c = 0
		while(lv.id != "dv-" + cde && c<10){lv = lv.nextSibling;c++}
		
		lv.style.display = "block"
		if(cde != "bnr"){
			this.bbnr.style.display =  "block"// : "none" ? 
			this.bbnr.onclick = supbuy  //local page
			this.bstd.onclick = supbuy
			if(cde != "std"){
				this.bstd.style.display =  "block"
				this.bstd.onclick = supbuy
			}
			else{
				this.bstd.style.display =  "none"
			}
		}
		else{
			this.bbnr.style.display =  "none"
		}
	}
}

//################   end help thingy    ######################
//###########################################
//############     button object             ###############
function mkbtn(fdob){
	//alert(fdob.htm.id)
	fdob.setedt = btnedt
	fdob.htm.onclick = gebtnclk
	if(fdob.dad && fdob.dad.rwid > 0){
		fdob.htm.id += '_' + fdob.dad.rwid
	}
	document.lnm.innerHTML += "<br> made button :" +fdob.htm.id
}
function btnedt(bl){
	this.htm.style.display = bl ? "block" : "none"
}
function gebtnclk(){
	if(this.id.indexOf("_new-") > 1){
		tab = this.id.substring(11,20)
		//alert(tab)
		document.newsup = true
		kzam("mknew", tab)
	}
	else if(this.id.indexOf("_del-") > 1){
		tab = this.id.substring(11,20)
		if(confirm("Now I'm quite serious\nThis will excoriate event number " + tab)){
			kzam("nixit", tab)
		}
		//
		
	}	
	else{
		alert("you clicked " + this.id)
	}
}
//############     end button object             ###############


//############     gen button object             ###############
function mkgenbtn(fo){
	if("btn_cde-pck" == fo.fld){//// use to sent to local js, if good enough ipromote to general
		sqwk("boo")
		mkcdepk(fo)
	}
}



//############     end gen button object             ###############


///############# category  object  ########################
function initcat(catdat){
	var tmp = document.getElementById("dv-ct-tmp")
	//alert("got cat dat\n" + catdat)
	if(tmp && tmp.parentNode && !document.catmp){
		document.catmp = tmp
		document.catmp.dat = catdat
		var dadv = tmp.parentNode
		dadv.dad = ""
		dadv.dad.kids = Array()
		dadv.sbcts = Array("cat_dad:V:-1:F:cat_nme:V:Main:F:cat_id:V:0")
		document.catmain = new mkctob(dadv , 0)
		document.catmain.txi.innerHTML = "Main"
		document.catmain.catid = 0
		document.catmain.txi.style.display = "none"
		document.catmain.im.style.display = "none"
		var ctedt = document.getElementById("dv-cat-edt")
		ctedt.ico = document.getElementById("dv-cat-ico")
		ctedt.ico.hlp = document.getElementById("dv-cat-hlp")
		ctedt.ico.onmouseout = cticout
		ctedt.ico.onmouseover = function (){
									this.hlp.style.display =  "block" 
									self.setTimeout("cticout()", 15000)
								}
		ctedt.setedt = catsetedt
		document.catedt = ctedt
		catclk.call(document.catmain.txi)
		////document.catmain.catid = 0
	}
	else{
		//alert("no tmp man")
	}
	
}


function catsetedt(bl){
	
	if (bl && document.edcln){
	//alert("in cat set edit \n" + bl + '\nid:' + document.edcln.id)
		this.style.display = "block"// ? 
		this.ico.style.display = "block"
		if(bl){
			kzam("getedcat", document.edcln.rwid)
		}
		else{
			document.catmain.oncycl("")
		}
	}
	else{
		this.style.display =  "none"
		this.ico.style.display = "none"
	}
}
function gotedcat(str, lnm){
	//sqwk("gotedcat says:\n" + str)////t
	document.catmain.dat = str// string cats already
	document.catmain.oncycl(str)
	if(lnm){alert("got edit category\n" + lnm)}
}
function catcyc(str){
	//sqwk("catid and sup id\n" + this.catid + '\n' + document.admin)
	if(str != "" || (-1 == document.ssme)){
		tst = "_cat:V:" + this.catid  + ":F:"
		this.chk.style.display = (this.catid && document.admin > 1 ? "block" : "none")
		this.chk.className = (str.indexOf(tst) != -1? "catgot" : "catnot")
		this.chk.onclick = catchkclk
	}
	else{
		this.chk.style.display =  "none"
	}
	if(this.kids.length > 0){
		for(var i=0;i<this.kids.length;i++){
			this.kids[i].oncycl(str)
		}			
	}
	//alert("kids l :" + this.kids.length)
}
function cticout(){
	document.catedt.ico.hlp.style.display =  "none"
}
function catclk(){	
	//alert("cat click\n" + this.dad.sbcts ?  this.dad.sbcts.length : "no subcats")////
	if(this.dad.im.className == "cat-pls"){
		if(this.dad.sbcts && this.dad.sbcts.length >0){		
			var sbcats = this.dad.sbcts
			msgc = "" //"boo\n" + reg + "\n" + sbcats.length
			if(sbcats && sbcats.length){
				
				for(i=0;i< sbcats.length;i++){
					var nmry = sbcats[i].match(/:cat_nme:V:([^:]+):F:cat_id:V:([0-9]+)/)
					var newb = new mkctob(this.dad.txo,nmry[2])
					//alert(nmry[1])
					newb.txi.innerHTML = nmry[1]
					//newb.catid = nmry[2]
					//msgc += (nmry) ? "\nAnd \n" + nmry[1] + " (" + nmry[2] + ")" : "\noops\n" + sbcats[i]
				}	
				if(document.catmain.dat && document.doed){
					this.dad.oncycl(document.catmain.dat)
				}
			}
			this.dad.im.className = "cat-mns"
		}
	}
	else{
		if(this.dad.sbcts && this.dad.sbcts.length >0){
			while(this.dad.sf != this.dad.txo.lastChild){
				var foo =  this.dad.txo.removeChild(this.dad.txo.lastChild)
				this.dad.im.className = "cat-pls"
			}
			this.kids = Array()
		}
	}
	
		/*ql ="select * from aml_supplier, aml_SuppCat where spc_sup = supplier_id and spc_cat = "  + this.dad.catid  + "  ORDER BY supplier_cde, RAND()"
		//ql =( document.admin > 0 ? "select *, ABS(supplier_id -  "  +  document.admin + ") as ord from aml_supplier, aml_SuppCat where spc_sup = supplier_id and spc_cat = "  + this.dad.catid  + "  ORDER BY ord" : ql)
		ql =( document.admin > 0 ? "select * from aml_supplier where supplier_id = "  + document.admin: ql)if(!(document.paige && document.admin)){}*/
	if( document.admin > 0){
		document.catedt.style.display = "block"// ? 
		document.catedt.ico.style.display = "block"
		ql = "select * from aml_supplier where supplier_id = "  + document.admin
	}
	else{
		document.catedt.style.display = "none"
		document.catedt.ico.style.display =  "none"
		ql ="select * from aml_supplier, aml_SuppCat where spc_sup = supplier_id and spc_cat = "  + this.dad.catid  + "  ORDER BY supplier_cde, RAND()"
	}
	//alert(ql)		document.edcln && document.edcln.rwid > 0 && 
	
	kzam("knock", ql)//

}
function catchkclk(){
///alert("ready to edit"+ '\n id:' +  document.edcln.rwid  + "\ndoc ad:" + document.admin  + "\ncat dat:" + document.catmain.dat)//> 0
		if( (document.edcln.rwid> 0 && document.edcln.cde !="upd")  || document.admin < 0){
			dat = document.catmain.dat
			//alert(dat +'\n' + this.dad.catid)
			if(dat.indexOf("V:" + this.dad.catid + ":F") > 0){
				if(confirm("You Are in this category\n OK will REMOVE you\n")){
					arg = document.edcln.rwid + "XX-" +  this.dad.catid
					//alert("todo kzam the db\n" + arg)
					kzam("docatedt", arg)///page php
				}
			}
			else{
				//alert(this.catdad)
				m = dat.match(/_dad:V:0/g)
				if(m && m.length > 1 && this.catdad == 0){
					alert("Sorry only 2 entries allowed for the main categories")
				}
				else{
					if(confirm("You are Not in this category\n OK will ADD you")){
						arg = document.edcln.rwid + "XX" +  this.dad.catid
						//alert("todo kzam the db\n" + arg)
						kzam("docatedt", arg)///page php
					}
				}
			}
		}
		else{
			alert("Please purchase to change your categories")
		}
}
function mkctob(dad, ctid){
	
	var tmp = document.catmp
	var nd = tmp.cloneNode(true)
	var tm =  dad.appendChild (nd)
	var dvs = tm.getElementsByTagName("div")
	for(var i=0;i<dvs.length;i++){
		if(dvs[i].id == "dv-ct-im"){
			tm.im = dvs[i]
			dvs[i].onclick = catclk
		}
		else if(dvs[i].id == "dv-ct-txi"){
			tm.txi = dvs[i]
			dvs[i].onclick = catclk
		}
		else if(dvs[i].id == "dv-ct-txo"){
			tm.txo = dvs[i]
			//dvs[i].onclick = catclk
		}
		else if(dvs[i].id == "dv-ct-chk"){
			tm.chk = dvs[i] ///   must be no gaps between tags not even html formatting
			//dvs[i].onclick = catclk
		}
		else if(dvs[i].id == "effinfloatschk"){
			tm.sf = dvs[i] ///   must be no gaps between tags not even html formatting
			//dvs[i].onclick = catclk
		}
		dvs[i].dad = tm
	}
	tm.catid =  ctid
	tm.oncycl = catcyc
	tm.kids = Array()
	if(dad.dad.kids){
		var l = dad.dad.kids.length
		dad.dad.kids[l] = tm
		tm.ind = l
		tm.chk.catdad=dad.dad.catid
	}
	else{
		//alert("no kids")
	}
	tm.style.display =  "block" 
	catdat = document.catmp.dat
	if(catdat){
		reg = new RegExp("cat_dad:V:" +ctid + ":F:cat_nme:V:([^:]+):F:cat_id:V:([0-9]+)", "g")
		var subcats = catdat.match(reg)
		if(subcats && subcats.length > 0){
			tm.im.className = "cat-pls"
			tm.sbcts = subcats
			//alert("set subcats\n" + ctid)
		}
		else{
			tm.im.className = "cat-mns"
			tm.sbcts = ""
			//alert(" not  set subcats\n" + ctid)
		}
		
		msgc = "" //"boo\n" + reg + "\n" + sbcats.length
		/*for(i=0;i< sbcats.length;i++){
			nmry = sbcats[i].match(/:cat_nme:V:([^:]+):F:cat_id:V:([0-9]+)/)
			var newb = new mkctob(this.dad.txo)
			
			newb.txi.innerHTML = nmry[1]
			newb.catid = nmry[2]
			msgc += (nmry) ? "\nAnd \n" + nmry[1] + " (" + nmry[2] + ")" : "\noops\n" + sbcats[i]
		}		*/
		//alert(msgc)// && nmry[1]
	}
	return tm
	//if(dad){alert(" in mkcat")}else{alert("no dad man")}///////////////
}
function gotcat(catdat, key){
	//alert("key is\n" + key)//
	sortkey(key)/// on local js
	/*document.supdat = key
	writeCookie("supdat", key, 2)
	document.admin = rsval(key,"supplier_id")
	document.cde =  rsval(key,"supplier_cde")
	document.supnme =  rsval(key,"supplier_nme")
	invdte = rsval(key,"supplier_dte")
	tildte = sqldtefmt(invdte,"m +1Y")
	document.till = tildte
	if(document.till.length>0){
		document.getElementById("sp-tilbnr").innerHTML = " till " + document.till
		document.getElementById("sp-tilstd").innerHTML = " till " + document.till
	}*/
	document.hlp.setv()
	initcat(catdat)
	//alert("got cat \n" + catdat)
}
///#############  end tree object  ########################
/// set events

///  event set value,   page opening, dat incoming

///  event set edit, user logged in, shows all editable areas
function setedt(bl){ /// Cycle clones 
	for(var i=0;i<document.paige.clns.length;i++){
		document.lnm.innerHTML += "<br><br>Set edit Row id:" + document.paige.clns[i].rwid
		document.paige.clns[i].setedt(bl)
	}
	if(document.btrw){
		if(!(document.btrw.flds)){					
			grabElements(document.btrw)
			//if(document.btrw.flds){alert("buttons man")}
			initobjs(document.btrw)
			document.btrw.setedt = clsetedt
			document.lnm.innerHTML += "<br><br>Set edit button Row " 
		}
		
		document.btrw.setedt(bl)
	}
}
///  event go edit, user clicks editable div so display edit bits

///  user finishes making a choice, onblur for keyboard, onclick/onchange for mouse events. Object should handle update 




///  row object
function mkcln(dat){
	var sk = document.skin
	var cln = sk.cloneNode(true)
	var cl = sk.parentNode.appendChild(cln)
	if(isNaN(dat)){
		cl.rwid = rsval(dat,"\\w+_id")
		cl.rwdat = dat
	}
	else{
		cl.dadix = dat
	}
	cl.style.display = "block"
	cl.dadry = document.clns
	cl.setv = clsetv
	cl.setedt = clsetedt
	grabElements(cl)
	initobjs(cl)
	//document.lnm.innerHTML += "<br><br>Row id:" + cl.rwid
	return cl
}

///  cycle fields, calling events, hang row specific data (_id..)
function clsetv(dat){
	if( dat && dat != 0){
		fry = this.flds
		this.rwdat = (dat && dat.length > 0) ? dat : this.rwdat
		this.rwid = (dat && dat.length > 0) ? rsval(dat,"\\w+_id") : this.rwid
		document.lnm.innerHTML += "<br><br>clset id :" + this.rwid
		//document.lnm.innerHTML += "<br>setting field ".constructor
		if (fry && fry[0] && this.rwdat){
			this.style.display = "block"
			for(var i=0;i<fry.length;i++){			
				if(fry[i][1].setv){
					document.lnm.innerHTML += "<br>set field " + fry[i][0]//
					fry[i][1].setv(this.rwdat)
				}
				else{
					document.lnm.innerHTML += "<br>no field set " + fry[i][0]
				}
			}		
		}
	}
	else{
		this.style.display = "none"
		//alert(dat)
		document.lnm.innerHTML += "<br>No fields, man, row " + this.rwid
	}
}
function clsetedt(bl){
	if(document.admin == -1 || document.admin == this.rwid){
		fry = this.flds
		//alert("clone set edit for rwid :" + this.rwid  + "\ndoc admin :" + document.admin)
		document.lnm.innerHTML += "<br>set edit for rwid :" + this.rwid
		//document.lnm.innerHTML += "<br>setting field "
		if (fry && fry[0]){
			for(var i=0;i<fry.length;i++){			
				if(fry[i][1].setedt){
					//document.lnm.innerHTML += "<br>set field " + fry[i][0]
					fry[i][1].setedt(bl)
				}
				else{
					document.lnm.innerHTML += "<br>no edit set " + fry[i][0]
				}
			}		
		}
		else{
			document.lnm.innerHTML += "<br>No fields, man, row " + this.rwid
		}
	}
}
///  table object
function gotdat(str,msg){
	//alert("got supplier data\n" + str.replace(/:R:/g, "\n\n"))
	if(!document.paige){
		//alert("new jimmy")
		document.paige = new jimmy()
	}
	document.paige.setv(str)
	//if(!document.paige.pgno){
	//}
	ckadm = readCookie("admn")
	if(msg){
		if(msg.indexOf("O") > 0){
			supid = msg.replace(/\D/g, '')
			//alert("Login for id\n" + supid)//
			document.admin = supid			
			writeCookie ("supp", supid, 2 )
			setedt(true)			
		}
		else{
			alert(msg)
		}		
	}
	else if(ckadm == -1){
		//alert("attemptin' " + ckadm)	
			//document.admin = -1		
			setedt(true)
	}/**/
	if(!document.catmp){
		kzam("getcat", 0)
	}
	/*datry = (str.indexOf(":R:")  + 1) ? str.split(":R:")  : Array(str)
	numrw = datry.length
	document.lnm.innerHTML += "<br><br>got data rows:" + numrw
	if(document.clns){
		while(document.clns[0]){
			var cl = document.clns.pop()
			var foo = cl.parentNode.removeChild(cl)
		}
	}
	document.clns = Array()
	for(var i=0;i<datry.length;i++){
		document.clns[i] = mkcln(datry[i])
		document.clns[i].setv()
	}
	if(document.admin == -1){setedt(true)}*/
}

///  if repeatable template required, clone multiple rows, pass on events
  
 function jimmy(){
	//  page size, ie items per page
	this.pgsz = 5
	//insert cookie stuff here
	if(!this.clns){
		this.clns = Array()
		for(var i=0;i<this.pgsz;i++){
			this.clns[i] = mkcln(i)			
		}
	}
	//alert("got clones")
	
	this.setv = pgsetv
	this.pgbtns = Array()
	var jimdv = document.getElementById("dv-jimmy")
	jimdv.sf = mkel(jimdv, "div")
	jimdv.sf.style.clear = "both"
	jimdv.dad = this
	this.jimdv = jimdv
	this.bpgbtns = Array()
	var jimbdv = document.getElementById("dv-jimmyb")
	jimbdv.sf = mkel(jimbdv, "div")
	jimbdv.sf.style.clear = "both"
	jimbdv.dad = this
	this.jimdv.bro = jimbdv
}  
   
function btnclk(){	
	ix = this.idx
	if(!(document.admin > 0)){
		this.jim.turn(ix)
	}
	//alert(this.jim.pgsz +'\n' + )
}
function turnpg(idx){
	//alert("from" + this.pgno + "\nto" + idx)
	if(this.pgno != idx){
		if(isNaN(idx)){
			nw =  eval("1*this.pgno " + idx +  " 1")
			if(nw*(this.lst  - nw + 1) == 0){
				alert("Ok, so do we go round the corner\nor disable arrows??")
				return 0
			}
			else{
				idx =nw
			}
			
		}
		if(this.pgno){
				this.pgbtns[this.pgno].endo.className ="slct"
				this.bpgbtns[this.pgno].endo.className ="slct"
				
		}
		this.pgbtns[idx].endo.className = "crnt"
		this.bpgbtns[idx].endo.className = "crnt"
		this.pgno = idx
		//alert("turn pag index" + idx)//
		from = (idx-1)*this.pgsz
		for(var i = 0; i < this.pgsz; i++){
			dat = (this.datry[from + i] ? this.datry[from + i] : 0)
			//if(dat ==0 ){alert("got un " + i)}
			this.clns[i].setv(dat)
			if(document.admin == -1){
				this.clns[i].setedt(true)
			}
		}
	}	
}
 function pgsetv(str){
	this.datry = (str.indexOf(":R:")  + 1) ? str.split(":R:")  : Array(str)
	this.numrw = this.datry.length
	btndat = Array("&lt;&lt;")
	lstpg = Math.ceil(this.numrw/this.pgsz)
	//alert(this.datry.length + '\n' + lstpg)//
	
		for(var  i = 1;i < lstpg +1;i++){
			btndat[i] = i
		}
		this.lst = lstpg
		btndat[i] = "&gt;&gt;"
		this.btndat = btndat
		//alert(btndat.join("__"))//
		
		for(var i = 0; i < btndat.length ; i++){
			if(!this.pgbtns[i]){
				this.pgbtns[i] = mkdblcell(this.jimdv)
				this.pgbtns[i].style.display = (this.lst > 1?  "block" : "none")
			}
			if(!this.bpgbtns[i]){
				this.bpgbtns[i] = mkdblcell(this.jimdv.bro)
				this.bpgbtns[i].style.display = (this.lst > 1?  "block" : "none")
				
			}
			var binbtn =  this.bpgbtns[i].endo
			var inbtn = this.pgbtns[i].endo
			inbtn.innerHTML = btndat[i]
			inbtn.className = ( i*(btndat.length - i - 1) )?  "slct" : "rrws"
			inbtn.onclick = btnclk
			inbtn.jim = this
			inbtn.idx = (i == ( btndat.length -1)) ? '+' : i ? i : '-'	
			binbtn.innerHTML = btndat[i]
			binbtn.className = ( i*(btndat.length - i - 1) )?  "slct" : "rrws"
			binbtn.onclick = btnclk
			binbtn.jim = this
			binbtn.idx = (i == ( btndat.length -1)) ? '+' : i ? i : '-'	
			binbtn.bro = inbtn
			inbtn.bro = binbtn
		}
		for(; i < this.pgbtns.length ; i++){
			this.pgbtns[i].endo.style.display =  "none"
			this.pgbtns[i].endo.onclick = null
			this.bpgbtns[i].endo.style.display =  "none"
			this.bpgbtns[i].endo.onclick = null
		}
	
	
	this.turn = turnpg
	this.pgno = 0
	this.turn(1)
	//if(!this.pgno){this.pgbtns[1].endo.click()}
}   
////   login stuff

function gentimber(str){
	var ky = document.getElementById("spkey")
	bt = str.split(":O:")
	document.admin = bt[0]
	//alert("doc admin set in gentim to " + document.admin )////
	writeCookie("admn", -1, 2)
	ky.innerHTML = ''
	//alert("ok, in")
	setedt(true)
}
////  utilities

function kgetv(hsh, k, mk){//// hash, key, make new(bool)
	l = hsh.length
	for(kvi=0;kvi<l;kvi++){
		if(hsh[kvi][0] && hsh[kvi][0] == k){
			return hsh[kvi]
		}
	}
	if(mk){
		var ob = new Object()
		hsh[l] = Array(k,ob)
		return hsh[l]
	}
	return false
}

var xmlhttp=false;    //  ###############    The  MAGIC object ;)
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
document.magic = true


/////////////////////    The Main Man
function doreq (url){
	if (!xmlhttp) {
		  alert("No magic in this browser, sorry")
		  return (0);
	}
	else{
		c = 0
		resp = ""//		
	 
		xmlhttp.open("POST",url ,true);
		
		 xmlhttp.onreadystatechange = kzamback
		 //t = new Date()
	 	 //alert("doreq (kzam) says\n" + url)	
		 xmlhttp.send(null)
		 return(1);
	}
}
function kzamback() {
				 var t = new Date()
			 
			  if (xmlhttp.readyState==4) {
				 ////////////////////////////     could be used to stop multiple requests  
					//  alert(document.grd +'\n' + xmlhttp.readyState + ' @ ' + t.getTime())
					 // document.grd = ""
				///////////////////////     *********  important debug line  ************** 
					 //alert("doreq return\n" + xmlhttp.responseText)	    //
					  
					  ///**************
					   //document.getElementById("dvlynam").innerHTML = xmlhttp.responseText
					   var resp = xmlhttp.responseText
					  /* if(document.magic && document.magic.substr(0,5) == 'doreq'){
						alert("waiting\n" + document.magic )//
					       	eval(document.magic)
					   }*/
					   document.magic = true
					   fnclf = resp.split(":A:")
					   fncla = resp.match(/ALT:([^\|]+)/)
					   
					   if(fnclf && fnclf[1] && fnclf[2]){
							foo = fnclf.shift()
							fnc = fnclf.shift()
							js = fnc + "(\"" + fnclf.join('\", \"') + "\")"
							//alert(js)
							eval(js)
							return 0
					   }
					   else if(fncla && fncla[1]){
					   	if (fncla[1] = 'Image removed') {
					   		alert("Image removed");
					   		//window.location.reload();
					   	}
					   	else {
							eval("alert(\"" + fncla[1].replace(/<br>/g,"\\n") + "\")")
							return 0
						}
					   }
					   else{
						 if (resp == "issess();" || resp == "notsess();") { eval(resp); }
						 else {
						 if(confirm(resp)){
						 eval(resp)
						 }
						 }
					}
				   
			  }
			  else{
				 //document.grd += '\n' + xmlhttp.readyState + ' @ ' + t.getTime()
//
			  }
		 }

function kzam(fnc, arg){
		if(document.edcln){
			cde = rsval(document.edcln.rwdat, "supplier_cde")
		}
		if(fnc == "doupdt" && cde == "upd" && document.admin > 0 && document.ssme != -1){
			m = arg.split("~c~")
			msg = "Not saved to web,\nonly locally"
			ret = ":F:" + m[0]  + ":V:" + m[1] + ":F:"
			retcmupd(msg,ret)
			//alert("paydirt\n" + ret)
		}
		else{
			grl = document.phpurl + "?fnc=" + fnc + "&arg=" + escape(arg)
			//alert(grl)
			if(document.magic){
			document.magic = false
				doreq (grl)
			}
			else{
				document.magic = "doreq (\"" + grl + "\")"
			}
		}
		return 1
}
function rsval (rstr, fld){
	var reg = RegExp("(F:|R:|^)" + fld + ":V:(.*?)(:F:|:DV:|:R:|$)")
	mvl = rstr ? rstr.match(reg) : ''
	return (mvl && mvl[2] ? mvl[2] : '')
}


function nullfunc(){
	return 1
}

function nixlnk(dv, bl){
	str = dv.innerHTML
	if(bl){
		str= str.replace(/<\/*a[^>]*>/g,"")/**/
		//alert(str)
		dv.innerHTML = str
	}
	else{
		
	}
	
	return 1
}
function dogosupplier(crnt) {
	//alert(crnt.dad.dad.bannerurl.indexOf('ttp'));
	if (crnt.dad.dad.bannerurl.indexOf('ttp') > 0) {
		//window.location.href=crnt.dad.dad.bannerurl;
		window.open(crnt.dad.dad.bannerurl, "supplier");
	}
	else if (crnt.dad.dad.bannerurl.indexOf('ww.') > 0) {
		//window.location.href=crnt.dad.dad.bannerurl;
		window.open("http://"+crnt.dad.dad.bannerurl, "supplier");
	}	
	//else alert(crnt.dad.dad.bannerurl);

}

function txtohtm(str, bl){
	str = unescape(str)
	//alert(str)
	if(bl){
		str = str.replace(/\015\012|\012/g, "<br>")
		str = str.replace(/\243/g, "&pound;")
		rege = /([^\s'"]+?@[^\s'"]+?\056[^\s'"]+)/g
		str = str.replace(rege, "<a href='mailto:$1 class='blue-link'>$1</a>")
		regw = /(www\056[^\s'"]+)/g
		str = str.replace(regw,  "<a href='http://$1' class='blue-link' target='_blank'>$1</a>")
		/*str = str.replace(/\243/g, "&pound;")*/
		
	}
	else{
		str = str.replace(/<br>/g, "\n")
		str = str.replace(/&pound;/g, String.fromCharCode(163))
		//str = str.replace(/<a h[^>]+?>(www\056[^\s'"]+?\w\w)<.a>/gi, "$1")//
		str = str.replace(/<\/*a[^>]*>/gi, "")//
		/*str = str.replace(/&pound;/g, String.fromCharCode(163))
		str = str.replace(/&pound;/g, String.fromCharCode(163))
		str = str.replace(/&pound;/g, String.fromCharCode(163))*/
	}
	//alert(str)
	return str
}
function dodes(){
	//alert('boo');
	var d=document.getElementById('dvdes');
	d.style.display=(d.style.display=='none')?'block':'none';
}
function mkactv(el){
	if(document.actv){
		document.actv.blur()
		//alert("active element:" + document.actv.id)
	}
	document.actv = el
}
function retcmupd(msg, val){
	
	//alert(msg + '\n' +  val + '\n' + document.actv.id)
	if(document.actv && val){
		//alert(document.actv.dad.setv ? "setv set" + val : "no setv")
		document.actv.dad.setv(val)
		
	}
	if(document.actv.dad.dad.lnm){
		document.actv.dad.dad.lnm.innerHTML = msg
		document.actv.dad.dad.lnm.style.display = "block"
		self.setTimeout('fadit()', 5000)
	}
	else{
		//alert("not able to save \n" + document.actv.dad.dad.rwid + '\n' + msg)
	}
	//+ "\n" + val
}
function fadit(dvid){
	if(dvid){
		//alert(dvid)
		var dvd =document.getElementById(dvid)
		dvd.innerHTML = "" 
		dvd.style.display = "none"
		
	}
	else{
		document.actv.dad.dad.lnm.innerHTML = "" 
		document.actv.dad.dad.lnm.style.display = "none"	
	}	

	//document.actv = 0
}

function mkel(dad,tag,sf){
	var nd = document.createElement(tag)
	if(sf && sf.style){
		var el = dad.insertBefore(nd, sf)
	}
	else{
		var el = dad.appendChild (nd)
	}
	return el
}
function mkdblcell(dad){
	var exo = mkel(dad, 'div',  dad.sf)
	exo.style.styleFloat= "left"
	exo.style.cssFloat= "left"
	var endo = mkel(exo,"div")
	endo.rxo = exo
	exo.endo = endo
	endo.rwdv = dad
	exo.rwdv = dad
	return exo
}
function upval(){
	//alert(frm.rdowdh[0].checked  + '\n' +   frm.rdowdh[0].value  + '\n' + frm.rdowdh[1].value)
	//alert(frm.hidcmpid.value + '\n' + fld)////
	var frm = document.pat
	rel = frm.hidrelpth.value
	fld = frm.hidfld.value
	if(fld.length*rel.length > 0 ){   ////0 &&
		msg = ''
		for(el in frm){
			msg += '\n' + el.value
		}
		
		
		//alert(frm.filupm.name + '\n ' + msg)
		frm.submit()
	}
	else{
		//alert("Ain't submitting\nfld : " + fld + '\npath: ' + rel)
	}
}

// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
    //sqwk(document.cookie)
}

// Example:
// alert( readCookie("myCookie") );
function readCookie(name){
  var cookieValue = "";
  var serch = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(serch);
    if (offset != -1)
    { 
      offset += serch.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}
function sqldtefmt(str,fmt){
	//alert("in date format\n" + str + '\n' + fmt)//
	m = str.match(/(\d{4})-(\d{1,2})-(\d{1,2})/)
	var mry = Array("", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
	//alert("in date format\n" + m[0] + '\n' + m[1] + '\n' + m[2] + '\n' +  m[3])
	if(m && m[3]){
		if(fmt == "m +1Y"){
			ou =m[3]*1  + '/' +m[2]*1  + '/' + (m[1] *1 +1)
			//alert("date format out\n" + ou)
		}
		if (fmt == "d m y"){
			ou =m[3]*1 + ' ' +  mry[m[2]*1]  + ' ' + (m[1] *1)
			//alert("got out\n" + ou)
		}
		if(fmt == "m dif"){
			n = new Date()
			y= n.getFullYear() *1
			mt = n.getMonth()*1  +1
			ou = (y - m[1]*1) *12 + mt  -  1*m[2]
			//alert(m[1]*1 + '\n' + y + '\n' + (y - m[1]*1) *12 + '\n' +1*m[2]  + '\n' + mt + '\nout is :' + ou)
			
		}
		return ou
	}
	else{
		return ''
	}
}
//sqldtefmt(,  "d m y")


function sqwk(msg){
	var usr =(sqwk && sqwk.caller ? sqwk.caller.toString() : "no caller{")// ""
	cal = usr ? usr.substr(0,usr.indexOf("{")) : "Page code"
	if(0){
		alert( 'Now in : ' + cal + '\n' + msg)	
	}
	else{
		//Todo, kzam msg to server for a logfile while in production
	}
}

			/*else if(obts[2] == "hlp"){// a pseudo field keep away from data 
				/*if(obts[3] == "vis"){
					fobj[1].vis = els[oi]
					fobj[1].vis.dad = fobj[1]
				}
				if(obts[3] == "pop"){
					fobj[1].popup = els[oi]
					fobj[1].popup.dad = fobj[1]
					//alert("gotpop")
				}
			}*/
	/*if(fdob.popup){
				//alert("off to init help stuff")//
				mkhlpob(fdob)
				document.lnm.innerHTML += "<br>upload object " + fdob.fld
			}*/


/*htmvl = txtohtm(this.htm.innerHTML, true)
		this.htm.innerHTML = htmvl
		this.htm.style.display = "block"
		this.tx.style.display = "none"*/	


	/*if(this.dad.pic && this.dad.pic.width){
	}
	else{
		alert("No image width man!\n" +  this.dad.pic.id)
	}*/

	/*fo.vis.onmouseover = function (){
							this.pup.style.display = "block"			
						}
	fo.vis.onmouseout = function (){
							this.pup.style.display = "none"			
						}*/