var UEL;
if (!UEL) { UEL = new Object(); }
//..................................................................................:UEL.class_Search
UEL.class_Search = function () {
    this.Datasources = new Array(
    'all','news','staff','lls',
    'postgraduate','undergraduate',
    'cite','ava','hab','ssmcs','business','psychology','law','education','combined','gradschool','connect','ftsrc','risingeast');
    this.Initialise();
}

//..................................................................................:Field
//properties
UEL.class_Search.prototype.isInitialised = false;
UEL.class_Search.prototype.hasBeenUsed = false;
UEL.class_Search.prototype.Field = null;
UEL.class_Search.prototype.Form = null;
UEL.class_Search.prototype.DefaultText = '';
UEL.class_Search.prototype.Datasources = null;
UEL.class_Search.prototype.Datafields = null;
UEL.class_Search.prototype.Options_Region = null;

//..................................................................................:Initialise
UEL.class_Search.prototype.Initialise = function () {
    //
    try {
        var Current = null;
        if (!this.isInitialised){
	    var _F = new Array();
	    for (var i in this.Datasources){
		var e = document.getElementById('searcher.'+this.Datasources[i]+'_uel.active');
		if (e != null) {
		    e.onclick = function(){UEL.Search.set_Source(this);}
                    e.descriptor = document.getElementById('search_Descriptor_'+this.Datasources[i]+'');
		    _F.push(e);
                    if (e.checked === true) Current = e;
		}
	    }
            if (_F.length > 0) {
                this.Datafields = _F;
                this.isInitialised = true;
            }
        }
        this.set_Source(Current);
		window.onload = function () {
			UEL.Search.setField('REQ');
		}
    } catch (exc) {
    }    
}
//..................................................................................:Initialise
UEL.class_Search.prototype.showOptions = function () {
    if (!this.Options_Region) {
        this.Options_Region = document.getElementById('seach_Options_Section');
        this.Options_Region.isVisible = false;//this.Options_Region.style.display != 'none';
    }
    this.Options_Region.isVisible = !this.Options_Region.isVisible;
    if (this.Options_Region.isVisible){
        this.Options_Region.style.display = 'block';
    }else{
        this.Options_Region.style.display = 'none';
    }

}
//..................................................................................:normalise
UEL.class_Search.prototype.normalise = function (txt) {
	var V = txt.toLowerCase().split(' ');
	for (var i=V.length-1; i >= 0; i--) {
		if (!V[i]) {
			V.splice(i,1);
		}
	}
	return V.join(' ');
}
//..................................................................................:setField
UEL.class_Search.prototype.setField = function (txtName) {
    this.Field = document.getElementById(txtName);
    if (this.Field) {
        this.DefaultText = 'Search here';
		var V = this.normalise(this.Field.value);
		if (V == '' || V == this.normalise(this.DefaultText)) {
			this.Field.value = this.DefaultText;
		}
        this.Field.onfocus = function() { return UEL.Search.onFocus();	}
        this.Field.onblur = function() { return UEL.Search.onBlur();	}
		this.Field.className = 'Default'; 
		this.hasBeenUsed = false;
    }
    this.Form = document.getElementById('search');
	if (!this.Form) this.Form = document.getElementById('form_Search');
	if (this.Form) {
        this.Form.onsubmit = function() { return UEL.Search.onSubmit();	}
	}
}
//..................................................................................:onFocus
UEL.class_Search.prototype.onFocus = function () {
	if (!this.hasBeenUsed) {
		if (this.Field.value == this.DefaultText) {	
			this.Field.value = ''; 	
		}
		this.Field.className = 'Active'; 
		this.hasBeenUsed = true;
	}
}
//..................................................................................:onBlur
UEL.class_Search.prototype.onBlur = function () {
    if (this.Field.value == '') {	
		//this.Field.value = this.DefaultText; 
	}
}
//..................................................................................:onFocus
UEL.class_Search.prototype.onSubmit = function () {
	var V = this.normalise(this.Field.value);
    return (V != this.normalise(this.DefaultText) && V != '');
}
//..................................................................................:setField
UEL.class_Search.prototype.set_Source = function ($src) {
    if ($src){
        //clear all other datasources
        for(var i in this.Datafields){
            if ($src != this.Datafields[i]){
                this.Datafields[i].checked = false;
                this.Datafields[i].descriptor.parentNode.className = '';
            } else {
                //multiple clicks on the same datasource
                this.Datafields[i].checked = true;
            }
        }
        //display label
        if ($src.descriptor != null){
            document.getElementById('search_Scope_Text').innerHTML = $src.descriptor.innerHTML;
            $src.descriptor.parentNode.className = 'current';
        }
    
    }
}
UEL.class_Search.prototype.setSource = function ($src) {
    for(var i in this.Datasources){
        var e = document.getElementById('searcher.'+this.Datasources[i]+'_uel.active');
        if ($src !=this.Datasources[i] && e){
            e.checked = false;
        }
    }
    e = document.getElementById($src);
    if (e){
        e.checked = true;
    }
}

//..................................................................................:AsURL
if (!UEL.Search) { UEL.Search = new UEL.class_Search(); }


