var $doneSettind_gExclusiveSearchDefaultValues = "false";    
var $doneSettinghiddenBoxDivID = "false";
var $defaultURLstring="includes/ajax/_search.php?";
var fadedtextcolour = "#aba8a8";
var fulltextcolour  = "#000";
//var fulltextcolourclass = "";
//var fadedtextcolourclass="";
//////////////////////////////////////////////////////////////////
if(typeof console === "undefined") {console = {log:function(){}};}
function reloadPage($button){
    location.reload(true);
	$button.disabled = "disabled";
}    
$autosuggest_html /*--*/ = '<label for="testinput" id="lbl_textbox1">Name/Type/Location</label><input style="width: 200px;display:block" type="text" id="textbox1" value="" />&nbsp;&nbsp;<label for="testinput" id="lbl_textbox2" >Name/Type/Location</label><input style="width: 200px;display:block" type="text" id="textbox2" value="" /> &nbsp;&nbsp; <label for="testinput" id="lbl_textbox3" >Name/Type/Location     </label>	    <input style="width: 200px" type="text" id="textbox3" value=""/> &nbsp;&nbsp;<input type="submit" value="Search" /><input type="button" name="reset<?=md5(time())?>" id="reset" value="Clear" onclick="javascript:reloadPage(this);"  /><small style="float:right" style="display:block">Hidden ID Field:     <input type="text" id="testid" value="" style="font-size: 10px; width: 20px;" disabled="disabled" /></small>';
$autosuggest_hiddenforms= "<small style='float:right' style='display:block' >compid:<input type='text' id='compid' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right' >busyid:<input type='text' id='busyid' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right'>locaid:<input type='text' id='locaid' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right'  >headid:<input type='text' id='headid' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right' style='display:block' >comp_box:<input type='text' id='comp_box' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right'  >busy_box:<input type='text' id='busy_box' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small><small style='float:right' style='display:block' >loca_box:<input type='text' id='loca_box' value='' style='font-size: 10px; width: 100px;' disabled='disabled'  /></small> ";
function init_autosuggest($hiddenBoxDivID){d_gE($hiddenBoxDivID).innerHTML = $autosuggest_html + $autosuggest_hiddenforms;}
var d_cObj = "";
function d_gE($e){return document.getElementById($e);}
function setAutoSuggesField(fldid,option,serverOptions) {
    $hiddenBoxDivID = "autoSuggestHiddenbox";
    if ($doneSettinghiddenBoxDivID!=true){$doneSettinghiddenBoxDivID =true;init_autosuggest($hiddenBoxDivID);}
    var as_json = new dck.AutoSuggest(fldid, option,serverOptions);
}
if(typeof(dck)=="undefined")_d= dck = {};
if(typeof(_d.Autosuggest)=="undefined") _d.Autosuggest = {};
else alert("Autosuggest is already set!");

_d.AutoSuggest = function(id,param,serverOptions){
	if(!d_gE) return 0;
	this.fld=_d.DOM.d_gE(id);
	if(!this.fld) return 0;
	this.sInp ="";
	this.nInpC=0;
	this.aSug =[];
	this.iHigh=0;
	this.oP = param ? param : {};
	var k, def = {minchars:0, meth:"get", varname:"input", className:"autosuggest", timeout:1000000000, delay:350, offsety:-5, shownoresults: true, noresults: "No results!", maxheight: 250, cache: true, maxentries: 25};
	for(k in def){if(typeof(this.oP[k])!= typeof(def[k])) this.oP[k]=def[k];}
	
    if(typeof this.oP.serverOptions === "undefined")this.oP.serverOptions = "";
	this.extra = serverOptions ? serverOptions : {};
	for(c in this.extra){this.oP.serverOptions = this.oP.serverOptions + "&" + c + "="  + this.extra[c];}
    if(typeof this.oP.script=== "undefined")this.oP.script = "";
	if(this.oP.script =="" )this.oP.script =$defaultURLstring;
    if(typeof this.oP.linked=== "undefined")this.oP.linked = "";
	if(this.oP.linked =="" )this.oP.linked ="true";
	
    if(this.oP.fldtype!=""  && typeof this.oP.dtxt != "undefined"){
        setExclusiveSearchDefaultValues();
	    if(this.oP.fldtype=="location"){if(this.oP.fldlbl=="") this.oP.fldlbl="lbl_textbox3";setExclusiveSearchField(id,"loca_box",this.oP.fldlbl);}
	    if(this.oP.fldtype=="type")    {if(this.oP.fldlbl=="") this.oP.fldlbl="lbl_textbox2";setExclusiveSearchField(id,"busy_box",this.oP.fldlbl);}
	    if(this.oP.fldtype=="name")    {if(this.oP.fldlbl=="") fldlbl="lbl_textbox1";        setExclusiveSearchField(id,"comp_box",this.oP.fldlbl);}
    }
    
    if(this.oP.dtxt_dstyle!=""  && typeof this.oP.dtxt_dstyle != "undefined"){fadedtextcolourclass = this.oP.dtxt_dstyle;}
    else {fadedtextcolourclass="b"}
    
    if(this.oP.dtxt_astyle!=""  && typeof this.oP.dtxt_astyle != "undefined"){fulltextcolourclass = this.oP.dtxt_astyle;}
    else {fulltextcolourclass="a"}
    
    if(this.oP.dtxt!="" && typeof this.oP.dtxt != "undefined"){
            if(d_gE(this.fld.id).value == "") {
                d_gE(this.fld.id).value = this.oP.dtxt;
                if (this.oP.dtxt_dstyle!="" && typeof this.oP.dtxt_dstyle != "undefined" ) d_gE(this.fld.id).setAttribute("class",this.oP.dtxt_dstyle);
                else d_gE(this.fld.id).style.color = fadedtextcolour;
            }
    }
    
	var p = this;
	this.fld.onkeypress=function(ev){return p.onKeyPress(ev); };
	this.fld.onkeyup   =function(ev){return p.onKeyUp(ev);    };
    this.fld.onclick   =function(ev){return p.onClick(ev);    };
    this.fld.onblur    =function(ev){return p.onBlur(ev);     };
    this.fld.trigger   =function(ev){return p.autoTrigger(ev);};	
	this.fld.setAttribute("autocomplete","off"); 
};

_d.AutoSuggest.prototype.onClick=function(ev){
    if(this.oP.dtxt!="" && typeof this.oP.dtxt != "undefined"){
        if(d_gE(this.fld.id).value == this.oP.dtxt) d_gE(this.fld.id).value = "";
        if (this.oP.dtxt_astyle!="" && typeof this.oP.dtxt_astyle != "undefined" ) d_gE(this.fld.id).setAttribute("class",this.oP.dtxt_astyle);
        else d_gE(this.fld.id).style.color = fulltextcolour;
    }
    
    this.getSuggestions(this.fld.value);
	var bubble = 1;
	return bubble;
}; 
_d.AutoSuggest.prototype.onBlur = function(ev) {
    if (d_cObj!=''){
        try     {d_cObj.clearSuggestions();}
        catch(e){}
    }
    
    if(this.oP.dtxt!="" && typeof this.oP.dtxt != "undefined"){
        if(d_gE(this.fld.id).value == "" || d_gE(this.fld.id).value == this.oP.dtxt) {
            d_gE(this.fld.id).value = this.oP.dtxt;
            if (this.oP.dtxt_dstyle!="" && typeof this.oP.dtxt_dstyle != "undefined") d_gE(this.fld.id).setAttribute("class",this.oP.dtxt_dstyle);
            else d_gE(this.fld.id).style.color = fadedtextcolour;
        }
        else{
            if (this.oP.dtxt_astyle!="" && typeof this.oP.dtxt_astyle != "undefined" ) {d_gE(this.fld.id).setAttribute("class",this.oP.dtxt_astyle);}
            else {d_gE(this.fld.id).style.color = fulltextcolour;}
        }
    }
    
    
};
_d.AutoSuggest.prototype.onKeyPress = function(ev){
	var key = (window.event) ? window.event.keyCode : ev.keyCode;
//	var RETURN = 13;
//	var TAB    = 9;
	var ESC    = 27;
	var bubble = 1;
	switch(key)	{
//		case RETURN:
//			this.setHighlightedValue();
//			bubble = false;
//			break;
//		case TAB:
//			this.setHighlightedValue();
//			bubble = false;
//			break;
		case ESC:
			this.clearSuggestions();
			break;
	}
	return bubble;
};
_d.AutoSuggest.prototype.onKeyUp = function(ev){
	var key      = (window.event) ? window.event.keyCode : ev.keyCode;
	var TAB      = 9;
	var ARRUP    = 38;
	var ARRDN    = 40;
	var DEL      = 46;
	var BACKSPACE= 8;
	var bubble   = 1;
	switch(key)	{
		case ARRUP:
			this.changeHighlight(key);
			bubble = false;
			break;
		case ARRDN:
			this.changeHighlight(key);
			bubble = false;
			break;
		case BACKSPACE:
			this.clearsetfileds(this.fld.value);
			bubble = false;
			break;
		case DEL:
			this.clearsetfileds(this.fld.value);
			bubble = false;
			break;	
		case TAB:
		    break;					
		default:
			this.getSuggestions(this.fld.value);
	}
	return bubble;
};

_d.AutoSuggest.prototype.clearsetfileds = function (val){
    $type = this.oP.fldtype;
    if ($type=="name")    {d_gE('compid').value  ="";/* d_gE('comp_box').value = ""*/;}
    if ($type=="location"){d_gE('locaid').value  ="";/* d_gE('loca_box').value = ""*/;}
    if ($type=="type")    {d_gE('busyid').value="";/* d_gE('busyid').value   = ""*/;}
}

_d.AutoSuggest.prototype.autoTrigger = function (ev){
    this.getSuggestions(this.fld.value,"autoTrigger");    
	var bubble = 1;
	return bubble;
}
_d.AutoSuggest.prototype.getSuggestions = function (val,triggerMethod){
    if (d_gE("compid").value =='' &&  d_gE("locaid").value=='' && d_gE("busyid").value =='' && val == this.sInp) return false;
    if (d_cObj!=''){
        try{d_cObj.clearSuggestions();}
        catch(e){}
    }
    d_cObj = this;
	_d.DOM.remE(this.idAs);
	this.sInp = val;
	if (val.length < this.oP.minchars){
		this.aSug = [];
		this.nInpC = val.length;
		return false;
	}
	
	var ol = this.nInpC; 
	this.nInpC = val.length ? val.length : 0;
	
	if (ol == val.length && val.legnth==0) return 0;
	
	this.oP.cache = false; 
	var l = this.aSug.length;
	if (this.nInpC > ol && l && l<this.oP.maxentries && this.oP.cache){
		var arr = [];
		for (var i=0;i<l;i++){
			if (this.aSug[i].value.substr(0,val.length).toLowerCase() == val.toLowerCase())	arr.push( this.aSug[i]);
		}
		this.aSug = arr;
		this.createList(this.aSug);
		return false;
	}
	else {  
	    var pointer = this;
	    var input   = this.sInp;
	    clearTimeout(this.ajID);
	    setOtherFields(this.fld.id,this.oP.linked);
	    this.ajID   = setTimeout(function(){pointer.doAjaxRequest(input,triggerMethod)},this.oP.delay);
	}
	return false;
};
function setOtherFields($currentfield,$linkedsearch){
    $comp    = d_gE("compid").value;
    $location= d_gE("locaid").value;
    $type    = d_gE("busyid").value;
    $Rn_comp ="false"; $Rn_busy="false";$Rn_loca="false";
    if(d_gE('comp_box').value=="")$Rn_comp="true";
    if(d_gE('busy_box').value=="")$Rn_busy="true";
    if(d_gE('loca_box').value=="")$Rn_loca="true";
    $exclusiveSearch ="";
    if($Rn_comp!="true" && $Rn_busy!="true" && $Rn_loca!="true"){
        if(d_gE('comp_box').value==$currentfield)$exclusiveSearch="comp";
        if(d_gE('busy_box').value==$currentfield)$exclusiveSearch="busy";
        if(d_gE('loca_box').value==$currentfield)$exclusiveSearch="loca";
    }
    if  ($linkedsearch=="false") $otherFields="&exclusiveSearch="+ $exclusiveSearch;
    else /*-------------------*/ $otherFields="comp_id="+$comp+"&locality_id="+$location+"&bustype_id="+$type+"&exclusiveSearch="+ $exclusiveSearch;
}
_d.AutoSuggest.prototype.doAjaxRequest = function(input,triggerMethod){
	if (input != this.fld.value) return false;
	var pointer = this;
	if (!this.oP.animationOff) this.fld.setAttribute("class", "searchboxAnimation");
	if (typeof(this.oP.script) == "function") var url=this.oP.script(encodeURIComponent(this.sInp));
	else /*--------------------------------*/ var url=this.oP.script+$otherFields+"&keyword="+encodeURIComponent(this.sInp)+"&"+this.oP.serverOptions;
    if (!url) return false;
    var meth  = this.oP.meth;
    var input = this.sInp;
    var onSuccessFunc= function(req)   {pointer.setSuggestions(req,input,triggerMethod)};
    var onErrorFunc  = function(status){this.fld.setAttribute("class","suggestTextActive");alert("AJAX error: "+status);};
    var myAjax = new _d.Ajax();
    myAjax.makeRequest( url, meth, onSuccessFunc, onErrorFunc );
};
_d.AutoSuggest.prototype.setSuggestions = function (req, input, triggerMethod){
	if (input != this.fld.value) return false;
	this.fld.setAttribute("class", "suggestTextActive");
	this.aSug = [];
	var x;
	if(x=="xPos"){ 
		var jsondata = eval('(' + req.responseText + ')');
		for (var i=0;i<jsondata.results.length;i++)	{
			this.aSug.push({'id':jsondata.results[i].id,'value':jsondata.results[i].value,'info':jsondata.results[i].info, 'display':jsondata.results[i].display });
		}
	}
	else{
	    response = req.responseText.split("\n");
	    $resultType ="";
	    if(response[0] != ''){
		    response.pop();
		    if(response.length > 0) {
		        for (var i=0;i<response.length;i++)
		        {
		            thisResult = response[i].split(",");
		           if (thisResult[1]){
		                thisResult[1] = thisResult[1].split("=");
			            this.aSug.push({'id':thisResult[1][1],'value':thisResult[2],'info':thisResult[0],'resultType':$resultType,'ics':thisResult[1][2], 'display':thisResult[3], 'returnField':thisResult[4]});
			        }
			       else if (response[i].length>1) {
			                this.aSug.push({'id':'--','value':response[i],'info':''}); 
						    $resultType = response[i];               
			       }
		        }
		    }
	    }
	}
	this.idAs = "as_"+this.fld.id;
	this.createList(this.aSug, triggerMethod );
};
_d.AutoSuggest.prototype.createList = function(arr,triggerMethod){
	var pointer = this;
	_d.DOM.remE(this.idAs);
	this.killTimeout();
	if (arr.length == 0 && !this.oP.shownoresults) return false;
	var div    =_d.DOM.cE("div",{id:this.idAs, className:this.oP.className});	
	var hcorner=_d.DOM.cE("div",{className:"as_corner"});
	var hbar   =_d.DOM.cE("div",{className:"as_dar"});
	var header =_d.DOM.cE("div",{className:"as_header"});
	header.appendChild(hcorner);
	header.appendChild(hbar);
	div.appendChild(header);
	var ul=_d.DOM.cE("ul",{id:"as_ul"});
	var number_of_results = 0;
    var result_type  = "";
    var result_type2 = "";
	for (var i=0;i<arr.length;i++) {
		var val = arr[i].value;
        var thisResultType = arr[i].resultType;
		var output=''; 
        var display = arr[i].display;
        if((typeof display != 'undefined' || typeof display != 'null') && arr[i].id != '--') {
           output = display;
         } else {
           output=val; 
         }
        
		var parts = this.sInp.split(' ');
		for (var part in parts) {
			var word = parts[part].charAt(0).toUpperCase() + parts[part].substr(1);
			var regExp = new RegExp("\\b"+word,"gi")
			if(word != '')output = output.replace(regExp,"<em><strong>"+word+"</strong></em>");
		}
      var error = 0;
		if (arr[i].id =='--'){
            if (val=="ERROR:insufficient search criteria(2)") {
                val = "keep typing to refine search";       var span 		= _d.DOM.cE("span", {}, val, true);    error = 1;
            } 
            else if (val=="ERROR:no matches"){
                val = "Sorry, no matches in this category"; var span 		= _d.DOM.cE("span", {}, val, true);    error = 1;
            }         
            else if (val.length >1 ) { 
                result_type2= result_type;  result_type  = val;
                //if   (val=="Locations") var span=_d.DOM.cE("span",{},"<em>"  +  "</em>", true);
                //else /*--------------*/ var span=_d.DOM.cE("span",{},"<em>"+val+"</em>", true);
                // RCT: enabling "Locations" to be displayed.
                var span=_d.DOM.cE("span",{},"<em>"+val+"</em>", true);
            }
		}
        else {
            var span 		= _d.DOM.cE("span", {}, output, true);
            number_of_results = number_of_results + 1;
        }

		if (arr[i].info != "") {}
		else if (arr[i].info == ""){
		    var br   =_d.DOM.cE("br",   {});
		    var small=_d.DOM.cE("small",{}, "---------------------------------------------------");                  
		}
		var a  =_d.DOM.cE("a",   { href:"#"});   
		var tl =_d.DOM.cE("span",{className:"tl"}, " ");
		var tr =_d.DOM.cE("span",{className:"tr"}, " ");
        var br2=_d.DOM.cE("br",  {});
	    a.appendChild(tl); 
	    a.appendChild(tr);
	    if (arr[i].id =='--' && error==0) { /*a.appendChild(br2);*/ }
	    a.appendChild(span);
		a.name          = i+1;
		if (arr[i].id !='--'){				
		    a.onclick       = function () { pointer.setHighlightedValue(); return false; };
		    a.onmouseover   = function () { pointer.setHighlight(this.name); };
    		var li = _d.DOM.cE(  "li", {}, a  );
		    ul.appendChild( li );
		}
		else{
    		var li = _d.DOM.cE(  "li", {className:"titlelink"}, a  );
		    ul.appendChild( li );
		}
	}
	if (arr.length == 0 && this.oP.shownoresults){
		var li = _d.DOM.cE(  "li", {className:"as_warning"}, this.oP.noresults);
		ul.appendChild( li );
	}
	div.appendChild( ul );
	var fcorner = _d.DOM.cE("div",{className:"as_corner"});
	var fbar    = _d.DOM.cE("div",{className:"as_dar"});
	var footer  = _d.DOM.cE("div",{className:"as_footer"});
	footer.appendChild(fcorner);
	footer.appendChild(fbar);
	div.appendChild(footer);
	var pos         = _d.DOM.getPos(this.fld);
	//div.style.left 	= pos.x + "px";
	div.style.top 	= (pos.y + this.fld.offsetHeight + this.oP.offsety ) + "px";
    
	div.onmouseover = function(){pointer.killTimeout()  };
	div.onmouseout 	= function(){pointer.resetTimeout() };
	if (triggerMethod==undefined) { var triggerMethod = "Trigger unknown"; }
	if ((number_of_results==1 && triggerMethod == "autoTrigger") ||  (number_of_results==2 && result_type2!='' && triggerMethod == "autoTrigger")){
        this.fld.value = arr[i-1].value;
        postSelectFunction(arr[i-1].id, result_type ,this.fld.id, arr[i-1].ics);
        this.clearSuggestions();
        return false;
	}
	if (number_of_results>0 && triggerMethod != "autoTrigger")document.getElementsByTagName("body")[0].appendChild(div);

    // This is the positioning of the div.
    if(div.offsetWidth < this.fld.offsetWidth) div.style.width = this.fld.offsetWidth + "px";
    div.style.left  = (pos.x+this.fld.offsetWidth-div.offsetWidth) + "px";
	this.iHigh  = 0;
	var pointer = this;
};

_d.AutoSuggest.prototype.changeHighlight = function(key){	
	var list = _d.DOM.d_gE("as_ul");
	if (!list)	return false;
	var n;
    if (this.iHigh == 0) {this.iHigh = this.iHigh; } 
	if (key == 40)  	n = this.iHigh+1;
	else if (key == 38)	n = this.iHigh-1;
	if (n > list.childNodes.length)	n = list.childNodes.length;
	if (n < 2) n = 2; 
	this.setHighlight(n);
};
_d.AutoSuggest.prototype.setHighlight = function(n){
	var list = _d.DOM.d_gE("as_ul");
	if (!list)	return false;
	if (this.iHigh > 0)	this.clearHighlight();
	this.iHigh = Number(n);
	list.childNodes[this.iHigh-1].className = "as_highlight";
	this.killTimeout();
};
_d.AutoSuggest.prototype.clearHighlight = function(){
	var list = _d.DOM.d_gE("as_ul");
	if (!list) return false;
	if (this.iHigh > 0)	{
		list.childNodes[this.iHigh-1].className = "";
		this.iHigh = 0;
	}
};
_d.AutoSuggest.prototype.setHighlightedValue = function (){
	if (this.iHigh){
		this.sInp = this.fld.value = this.aSug[ this.iHigh-1 ].value;
		this.fld.focus();
		if (this.fld.selectionStart) this.fld.setSelectionRange(this.sInp.length, this.sInp.length);
		this.clearSuggestions();
	    postSelectFunction(this.aSug[this.iHigh-1 ].id, this.aSug[this.iHigh-1 ].resultType, this.aSug[this.iHigh-1 ].returnField,this.fld.id, this.oP.fldrturn,this.oP.postJsCMD); 
	}
};
function postSelectFunction($id,$type, $optionReturnField,$fieldID,$fldrturn,$postJsCMD){
    if     (typeof $fldrturn === "undefined"){}
    else if($fldrturn!="") /*-------------*/ {d_gE($fldrturn).value = $id;}
    
    if(typeof $optionReturnField !== "undefined") {
        d_gE($optionReturnField).value = $id;
    }
   
    if($type=="Names")     {d_gE('compid').value = $id; d_gE('comp_box').value=$fieldID; }
    if($type=="Locations")     {d_gE('locaid').value = $id; d_gE('loca_box').value=$fieldID; }
    if($type=="Types"){d_gE('busyid').value = $id; d_gE('busy_box').value=$fieldID; }

    if(typeof $postJsCMD === "undefined") {}
    else if($postJsCMD!="") /*---------*/ {eval($postJsCMD);}
}

function setExclusiveSearchDefaultValues(){
    if ($doneSettind_gExclusiveSearchDefaultValues !=true){
        d_gE('lbl_textbox1').innerHTML = "Name";
        d_gE('lbl_textbox2').innerHTML = "Type";
        d_gE('lbl_textbox3').innerHTML = "Location";
        d_gE('comp_box').value = "textbox1";
        d_gE('busy_box').value = "textbox2";
        d_gE('loca_box').value = "textbox3";
        $doneSettind_gExclusiveSearchDefaultValues  = true;
    }
}

function setExclusiveSearchField($searchflds,$boxes,$lbls){
    d_gE($boxes).value = $searchflds;
}
function setExclusiveSearch($searchflds,$boxes,$lbls) {
    d_gE('lbl_textbox1').innerHTML = "Name";
    d_gE('lbl_textbox2').innerHTML = "Type";
    d_gE('lbl_textbox3').innerHTML = "Location";
    d_gE('comp_box').value = "textbox1";
    d_gE('busy_box').value = "textbox2";
    d_gE('loca_box').value = "textbox3";
    if (!$searchflds==''){for(var i in $searchflds){d_gE($boxes[i]).value = $searchflds[i];}}
}

function checkAutoFillOptions() {
    if (d_gE('textbox2').value =='')      d_gE('textbox2').trigger();
    else if (d_gE('textbox3').value =='') d_gE('textbox3').trigger();
    else if (d_gE('textbox1').value =='') d_gE('textbox1').trigger();
    return false;
}
_d.AutoSuggest.prototype.killTimeout  = function(){ clearTimeout(this.toID); };
_d.AutoSuggest.prototype.resetTimeout = function(){	clearTimeout(this.toID); var pointer = this; };

_d.AutoSuggest.prototype.clearSuggestions = function (){
	this.killTimeout();
	var ele = _d.DOM.d_gE(this.idAs);
	var pointer = this;
	if (ele){
		var fade = new _d.Fader(ele,1,0,250,function () { _d.DOM.remE(pointer.idAs) });
	}
};
if (typeof(_d.Ajax) == "undefined")	_d.Ajax = {};
_d.Ajax = function (){
	this.req = {};
	this.isIE = false;
};
_d.Ajax.prototype.makeRequest = function (url, meth, onComp, onErr){
	if (meth != "POST")	meth = "GET";
	this.onComplete = onComp;
	this.onError = onErr;
	var pointer = this;
	if (window.XMLHttpRequest){
		this.req = new XMLHttpRequest();
		this.req.onreadystatechange = function () { pointer.processReqChange() };
		this.req.open("GET", url, true); //
		this.req.send(null);
	}
	else if (window.ActiveXObject) {
		this.req = new ActiveXObject("Microsoft.XMLHTTP");
		if (this.req){
			this.req.onreadystatechange = function () { pointer.processReqChange() };
			this.req.open(meth, url, true);
			this.req.send();
		}
	}
};

_d.Ajax.prototype.processReqChange = function(){
	if (this.req.readyState == 4) {
		if (this.req.status == 200) this.onComplete( this.req );
        else /*------------------*/ this.onError( this.req.status );
	}
};
if (typeof(_d.DOM) == "undefined")	_d.DOM = {};
_d.DOM.cE = function ( type, attr, cont, html ){
	var ne = document.createElement( type );
	if (!ne) return 0;
	for (var a in attr) ne[a] = attr[a];
	var t = typeof(cont);
	if     (t=="string" && !html)ne.appendChild(document.createTextNode(cont));
	else if(t=="string" &&  html)ne.innerHTML = cont;
	else if(t=="object") /*---*/ ne.appendChild( cont );
	return ne;
};
_d.DOM.d_gE = function(e){
	var t=typeof(e);
	if /**/ (t=="undefined") return 0;
	else if (t=="string"){
		var re = d_gE( e );
		if(!re)return 0;
		else if(typeof(re.appendChild) != "undefined" ) return re;
		else return 0;
	}
	else if(typeof(e.appendChild) != "undefined") return e;
	else /*------------------------------------*/ return 0;
};
_d.DOM.remE = function(ele){
	var e = this.d_gE(ele);
	if (!e) /*-------------------------*/ return 0;
	else if (e.parentNode.removeChild(e)) return true;
	else /*----------------------------*/ return 0;
};
_d.DOM.getPos = function(e){
	var e = this.d_gE(e);
	var obj = e;
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)	curleft += obj.x;
	var obj = e;
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)	curtop += obj.y;
	return {x:curleft, y:curtop};
};
if (typeof(_d.Fader) == "undefined") _d.Fader = {};
_d.Fader = function (ele, from, to, fadetime, callback){	
	if (!ele) return 0;
	this.e     = ele;
	this.from  = from;
	this.to    = to;
	this.cb    = callback;
	this.nDur  = fadetime;
	this.nInt  = 50;
	this.nTime = 0;
	var p      = this;
	this.nID   = setInterval(function() { p._fade() }, this.nInt);
};
_d.Fader.prototype._fade = function(){
	this.nTime += this.nInt;
	var ieop = Math.round( this._tween(this.nTime, this.from, this.to, this.nDur) * 100 );
	var op = ieop / 100;
	if (this.e.filters) {
		try /*-*/ {this.e.filters.item("DXImageTransform.Microsoft.Alpha").opacity = ieop;           } 
        catch (e) {this.e.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+ieop+')';}
	}
	else this.e.style.opacity = op;
	
	if (this.nTime == this.nDur) {
		clearInterval( this.nID );
		if (this.cb != undefined) this.cb();
	}
};
_d.Fader.prototype._tween = function(t,b,c,d){
	return b + ( (c-b) * (t/d) );
};
