var Nqcf = {
	application: 'site',
	theme: '',
	
	changeTheme: function(newtheme) {
		if (this.theme == newtheme) return;
	
		var re = new RegExp('^(/styles/)('+this.theme+')(/.*\.css)$',"i");
		sss = $$('link[rel=stylesheet]');
		sss.each(function(ss) {
			if (ss.getAttribute('href').match(re)) {
				ss.setAttribute('href', ss.getAttribute('href').replace(re, '$1'+newtheme+'$3'));
			}
		});
		this.theme = newtheme;
	},
	
	addScript: function(src) {	
		if ($$('script[src="'+src+'"]') == '') {
			var headID = document.getElementsByTagName("head")[0];         
			var newScript = document.createElement('script');
			newScript.type = 'text/javascript';
			newScript.src = src;
			headID.appendChild(newScript);
		}
	},
	
	addCss: function(href) {
		if ($$('link[href="'+href+'"]') == '') {
			var headID = document.getElementsByTagName("head")[0];         
			var cssNode = document.createElement('link');
			cssNode.type = 'text/css';
			cssNode.rel = 'stylesheet';
			cssNode.href = href;
			cssNode.media = 'screen';
			headID.appendChild(cssNode);
		}
	},
	addLink: function(href, name, hreflang, type, rel, rev, charset) {
		if ($$('link[href="'+href+'"]') == '') {
			var headID = document.getElementsByTagName("head")[0];         
			var cssNode = document.createElement('link');
			cssNode.type = type;
			cssNode.name = name;
			cssNode.rel = rel;
			cssNode.rev = rev;
			cssNode.href = href;
			cssNode.hreflang = hreflang;
			cssNode.charset = charset;
			cssNode.media = 'screen';
			headID.appendChild(cssNode);
		}
	},

	addMeta: function(name, httpequiv, content, lang) {
		var meta;
		
		if (httpequiv != null && httpequiv != "") {
			$$( 'meta' ).each(function(elt) {
				if (elt.getAttribute('http-equiv') == httpequiv)
					meta = elt;
			});
		} else if (name != null && name != "") { 
			meta = $$('meta[name="'+name+'"]');
		}
		
		if (typeof(meta) != "object") {
			var headID = document.getElementsByTagName("head")[0];         
			var metaNode = document.createElement('meta');
			if (name != "") metaNode.name = name;
			if (httpequiv != "") metaNode.httpEquiv = httpequiv;
			if (content != "") metaNode.content = content;
			if (lang != "") metaNode.lang = lang;
			headID.appendChild(metaNode);
		} else {
			// setAttribute dont't work for ie7 :-(
			if (httpequiv != "") meta.httpEquiv =  httpequiv;
			if (name != "") meta.name = name;
			if (content != "") meta.content = content;
			if (lang != "") meta.lang = lang;
		}
	},
	
	setTitle: function(title) {
		//document.getElementsByTagName('title')[0].innerHTML = title;
		if (title) {
			document.title = title;
			if ($('title')) $('title').innerHTML = title;
		}
	},
	
	setDescription: function(description) {
		if (description) {
			if ($('description')) $('description').innerHTML = description;
		}
	},
	
	setIcon: function(href) {
		//icon = $$('link[rel=shortcut icon]');
		//if(icon != '' && icon != null)
		//	icon.setAttribute('href', href);
	}
	
};

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++) {
        if(this[i] == p_val) {
            rowid = i;
            return i;
        }
    }
    return false;
};

Array.prototype.remove = function(p_val) {
    var i = 0, l = 0;
    for(i = 0; i < this.length; i++) {
        if(this[i] != p_val) { 
            this[l] = this[i];
            l++; 
        }
    }
    if (i>l) { this.pop(); }
    
    return true;
};

sleep = function(millis) {
    var notifier = new EventNotifier();
    setTimeout(notifier, millis);
    notifier.wait();
}

