function appendOption(obj,optdata){

	var qu;
	for (k in optdata){
		var opt=document.createElement('option');
		var qu=optdata[k];
		opt.text=qu['name'];
		opt.value=qu['id'];
		try  {
	  		obj.add(opt,null); // standards compliant
	  	}catch(ex){
	  		obj.add(opt); // IE only
	  	}
	}
}

function lengthcheck(id,buddyid,imin,imax,msg){

	var obj = document.getElementById(id);
	if(buddyid!='') var bud = document.getElementById(buddyid);

	if(obj){
		var leng=obj.value.length;

		if (leng>=imax){
			obj.value=obj.value.substring(0,imax);
			if(bud)bud.value=0 + msg;
		}else{
			if(bud)bud.value=(imax-leng) +''+ msg;
		}
	}
}

function removeAllOptions(obj){
	var qu;
	var obs=Array();
	var nn=0;
	for ($nn=obj.length;$nn>=0;$nn--){

		obj.remove($nn);
	}
}

function checkit(){
	alert('checked it');
}


var targetSelectID='';
function getnewcat(obj,site){
	removeAllOptions(obj);
	sendSmartRequest('/index.php?ajax&cmd=newcat&',xmlSendSmartHandler);
}

function selectOption(ndx,id){
	obj=document.getElementById(id);
	if(obj){
		obj.options.selectedIndex=ndx;
	}
}
function repopEditbox(msg,id){
	obj=document.getElementById(id);
	if(obj){
	 obj.value=msg;
	}
}
function repopSelect(){
	sel=document.getElementById(targetSelectID);
	if(sel){
		removeAllOptions(sel);
		appendOption(sel,json);
	}
}
function getSelectedValue(obj){
	var ndx=obj.options.selectedIndex;
	return obj.options[ndx].value;
}
function getSubCats(id,obj){
	targetSelectID=id;
	sendSmartRequest('/index.php?ajax&cmd=newcat&catid='+getSelectedValue(obj)+'&',xmlSendSmartHandler);
}

function addlinxtocart(lid,pri){
	sendSmartRequest('/index.php?ajax=1&cmd=addlinx&id='+pri+lid+'&',xmlSendSmartHandler);
	var obj=document.getElementById('incartimg'+lid);
	obj.style.display='inline';

	var obj=document.getElementById('add2cart'+lid);
	obj.style.display='none';
}

function removelinxfromcart(lid,pri){
	sendSmartRequest('/index.php?ajax=1&cmd=removelinx&id='+pri+lid+'&',xmlSendSmartHandler);

	var obj=document.getElementById('incartimg'+lid);
	if (obj)obj.style.display='none';

	var obj=document.getElementById('add2cart'+lid);
	if (obj)obj.style.display='inline';
}

function repopLinkCart(cont){
	var obj=document.getElementById('thelinkcartbox');
	obj.innerHTML=cont;
}

function clearLinkCart(cont){
	var obj=document.getElementById('thelinkcartbox');
	obj.innerHTML='';
}

function toggleSubmitButton(dis,id){
	var obj=document.getElementById(id);
	if (dis.checked==true){
		obj.style.display='inline';
	}else{
		obj.style.display='none';
	}
}


/*

'<label class="text" id="label_descr" for="'.$pri.'descr">Short description of your site'.$_reqIndicator.'</label>'.
'<textarea class="mceNoEditor" name="'.$pri.'descr" id="'.$pri.'descr" onkeydown="lengthcheck(\''.$pri.'descr\',\''.$pri.'descr_buddy\',0,250,\' characters remain\');" />'.(soil($listing['descr'])!=''?soil($listing['descr']):'').'</textarea>
<br class="crhr" />
<label class="text" id="label_descr" for="'.$pri.'descr">&nbsp;</label>
<input type="text" value="250 characters remain" id="'.$pri.'descr_buddy" class="buddy" readonly="readonly" /><br class="crhr" />'.

*/