document.phpurl = "suppliersnewgen.php"
document.edbrd = "2px dashed #003399"
initb()

function initb(){
chkloginout();
}

function init(){
		
	document.skin  = document.getElementById("dv-tmpl")
	document.lnm = document.getElementById('dvdes');
	document.upld = document.getElementById("dv-upim")
	document.upld.ttl = document.getElementById("upl-ttl")
	document.btrw = document.getElementById("btn-row")
	document.byfm = document.getElementById("dv-buyfrm")
	//document.byfm.txt = document.getElementById("dv-txtfrm")
	document.hlp = document.getElementById("dv_edt_hlp_pop")
	
	mkhlpob(document.hlp)
	
	document.ssme = readCookie("admn")
	
	cksup = readCookie("supp")
	//alert("ssme\n" + document.ssme + "\ncksup\n " + cksup)///
	if(-1 == document.ssme){		
		document.admin = -1
	}
	ck = readCookie("payplret")
	if(ck){
		writeCookie ("payplret", "", -24)
		window.location = ck
	}
	qs = window.location.search.toString()
		//alert("sup ck is:" + cksup  + '\n qs length is: '+ qs.length  + '\nAdmn is' + document.ssme + '\ntest is' + (qs &&  qs.length > 2) + '\n' + (cksup < 1)  + '\n' + ( -1 != document.ssme))
	if(qs &&  (qs.length > 2) &&  (cksup < 1)  && (-1 != document.ssme)){
		//alert(document.location.search)
		if("albatross" != prompt("Please enter the password\nyou were given", "albatross")){
		//if("albatross" != prompt("Please enter the password\nyou were given")){ // for production
			if(confirm("Click OK to try again\nCancel to view suppliers normally")){
				init()
			}
			else{
				qs = ""
				window.location = "lady-golfer-suppliers.html"
			}
		}
	}
	else if( cksup > 0){
		document.admin = cksup
	}
	if(qs &&  (qs.length > 2) && (-1 == document.ssme)){
		 var sk = document.getElementById("dv-btn-cde-pck")
		document.cdepck = autograb(sk)		
		 mkcdepk(document.cdepck)
	}
	if(!document.catmp){
		//alert("getting cat")
		kzam("getcat", qs)
	}
	
	///kzam("knock", "select  * from supplier where 1~~" + qs)
}
function adminobj(n){
	
	var ky = document.getElementById("spkey")
	//alert(ky.innerHTML)
	if(ky.innerHTML == ''){
		///    remove second argument to nix default password
		tx = prompt("Welcome, Please login", "Casie")
		ky.innerHTML = ''
		kzam("knock", tx )
	}
	else{
		ky.innerHTML = ''
		document.admin = false
		setedt(false)
	}
}
function supbuy(){
	writeCookie("invdat", this.kid.byg, 2)
	writeCookie("payplret", window.location, 2)
	window.location = "inv.html"//
}

function logfrm(f){
	n = f.elements.length
	flog = ""
	for(i=0;i<n;i++){
		flog += f.elements[i].name + " is " + f.elements[i].value + "_\n_"
	}
	kzam("logit", escape(flog))
	return 1
}
function pgspc(fo){
	if(fo.typ == 'i'){
		fo.onsetv = "chkintpck(this)"
	}
	if(fo.fld == "supplier_eml"){
		//alert("setting e-mail hide")
		fo.shwed = true
	}
}

function chkintpck(fo){
	if(fo.dad.rwid == document.admin){
		ft = fo.fld.split("_")
		ckn = "temp_" + ft[1]
		ckvl = readCookie(ckn)
		if(ckvl){
			
			sid = ckvl.replace(/^(\d+).+/, "$1")
			src = ckvl.replace(/^\d+(.+)/, "$1")
			if(sid == document.admin){
			//alert(sid +'\n' + src)
				fo.pic.src = src
				fo.htm.style.display = "block"
			}
		}
	}
}
function sortkey(key){
	document.supdat = key
	writeCookie("supdat", key, 2)
	//alert("key is  " + key)
	document.admin = rsval(key,"supplier_id")
	document.supnme =  rsval(key,"supplier_nme")
	document.cde =  rsval(key,"supplier_cde")
	if(document.cdepck)document.cdepck.setv(document.cde);
	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
	}
	//mdif = sqldtefmt(invdte,"m dif")
	bybn = document.getElementById("dv-buybnri")
	bybn.parentNode.kid = bybn
	byst = document.getElementById("dv-buystdi")
	byst.parentNode.kid = byst
	if(document.cde == "std"){
		mdif = sqldtefmt(invdte,"m dif")
		bybn.innerHTML ="Upgrade listing for &pound;" + (mdif >5 ?  "12.50" : "25.00")
		bybn.byg = (mdif >5 ?  "hup12.50" : "fup25.00")
	}
	else if (document.cde == "upd"){
		bybn.innerHTML ="Deluxe Subscription (&pound;50)"
		bybn.byg = "bnr50" 
		byst.innerHTML ="Standard Subscription (&pound;25)"
		byst.byg = "std25" 		
	}
}
/*+ckvl*/

function nixit(){
	msg = "Cookies:\n" + document.cookie.replace(/(.{30})[^;]*;/g,'$1;\n') + "\nOK to log-out\nCancel to stay in"
	if(confirm(msg)){
		writeCookie("admn", "", -24)
		writeCookie("supp", "", -24)
		al = window.location.toString()
		
		al = al.replace(/\077.+/, "")
		//alert(al)alert(al)
		
		window.location = al
	}
}
//###### code picker button ############## may go general 


function mkcdepk(pk){
	for(var i=0 ; i < pk.clls.length ; i++){
		var cll = pk.clls[i]
		//sqwk("cell\n" + cll.id)
		if(cll.nme){
			cll.onclick = cdeclk
		}
	}
	pk.setv = pksetv
}

function cdeclk(){
	//sqwk("clicked\n" + this.nme)
	kzam("docde", this.nme + document.admin)
	//this.dad.setv(this.nme)
}
function duncde(vl){
	if(vl.length == 3){
		alert("Updated code ok")
		window.location = window.location.href
	}
	else{
		alert(vl.replace(/<br>/g, "\\n"))
	}
}
function pksetv(v){
	if(qs &&  (qs.length > 2) && (-1 == document.ssme)){
		for(var i=0 ; i < this.clls.length ; i++){
			cll = this.clls[i]
			if(cll.nme){
				cll.className = (v == cll.nme ? "cde-on" : "cde-off")
			}
		}
		this.sk.style.display =  "block" //: "none"
	}
	else{
		this.sk.style.display =  "none"
	}
}






