// (C) 2008 by Petr Carda
function $isNull(value){if((value==null)||(value=='undefined'))return true;return false;}
function $element(id){var el=document.getElementById(id);if ($isNull(el))return null;return el;}
function $hide(id){var el=$element(id);if(!$isNull(el))el.style.display='none';}
function $show(id){var el=$element(id);if(!$isNull(el))el.style.display='';}
function $visible(id,visible){var el=$element(id);if($isNull(el))return(false);if(!$isNull(visible)){if((visible=='1')||(visible==true)||((''+visible).toUpperCase()=='TRUE')){$show(id);}else{$hide(id);}}return(el.style.display!='none');}
function $cssClass(id,cssclass){var el=$element(id);if($isNull(el))return'';if(!$isNull(cssclass))el.className=cssclass;return el.className;}
function $get(id){var el=$element(id);if($isNull(el))return ''; switch(el.tagName.toUpperCase()){
        case 'INPUT':{switch( (el.attributes['type']!=null)?el.attributes['type'].value.toUpperCase():''){case'PASSWORD':case'TEXT':case'HIDDEN':return(el.value);case'CHECKBOX':case'RADIO':return(el.checked)?true:false;defult:return('');}return('');}
        case 'SELECT':return(el.options.length<1)?'':el.options[(el.selectedIndex<0)?0:el.selectedIndex].value;
        default:return(el.innerHTML);
    }
}
function $set(id, value){var el=$element(id);if($isNull(el))return('');switch(el.tagName.toUpperCase()){
        case 'INPUT':{switch( (el.attributes['type']!=null)?el.attributes['type'].value.toUpperCase():''){case'PASSWORD':case'TEXT':case 'HIDDEN':el.value=value;return;case'CHECKBOX':case'RADIO':(el.checked=((value!=null)&&(value!='')&&((value==1)||(value=='1')||(value.toUpperCase()=='TRUE'))));defult:return;}}
        case 'SELECT':{for(var f=0;f<el.options.length;f++){if(el.options[f].value==value){el.selectedIndex=f;return;}}el.selectedIndex=(el.options.length>0)?0:-1;};return('');
        default:el.innerHTML=value;return;
    }
}
function $value(id,value){if(!$isNull(value))$set(id,value);return($get(id));}
if((typeof(HTMLElement)!="undefined")&&(!HTMLElement.prototype.insertAdjacentElement)){
	HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
		switch (where){
		case 'beforeBegin':this.parentNode.insertBefore(parsedNode,this);break;
		case 'afterBegin':this.insertBefore(parsedNode,this.firstChild);break;
		case 'beforeEnd':this.appendChild(parsedNode);break;
		case 'afterEnd':if (this.nextSibling)this.parentNode.insertBefore(parsedNode,this.nextSibling);else this.parentNode.appendChild(parsedNode);break;
	}}
	HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){var r = this.ownerDocument.createRange();r.setStartBefore(this);var parsedHTML = r.createContextualFragment(htmlStr);this.insertAdjacentElement(where,parsedHTML)}
	HTMLElement.prototype.insertAdjacentText=function(where,txtStr){var parsedText = document.createTextNode(txtStr);this.insertAdjacentElement(where,parsedText)}
}
function $html(id,html){var el=$element(id);if($isNull(el))return('');if(!$isNull(html)){el.innerHTML='';el.insertAdjacentHTML('beforeEnd',html);}return el.innerHTML;}
function $insertHTML(id,html){var el=$element(id);if(!$isNull(el))el.insertAdjacentHTML('beforeEnd',html);}
function $clearHTML(id){var el=$element(id);el.innerHTML='';}

function submit(element){if(!$isNull(element))element.submit();}
function submitFormById(formid){submit($element(formid));}
