﻿/**
*
*  uno.js 
*  by Hideki Yamamoto eu-gsm[+393453332248]
*  Version Alpha 0.0.3.0
*  This file is part of the uno project.
*  The user must agree with the terms specified in
*
*  ©Hideki Yamamoto, all rights reserved.
*
*  Licence       : Http://www.unodot.net/framework/current/uno.licence.txt
*  Documentation : Http://www.unodot.net/framework/current/uno.js.usage.txt
*  History       : Http://www.unodot.net/framework/current/uno.js.history.txt
*
**/
///////////////////////////////////////////////////////////////////////////////////////////////
//                            BROWSER RECOGNITION                                            //
var isIE	= document.all;
var isIE7	= isIE && window.XMLHttpRequest && window.ActiveXObject;
var isIE6	= isIE && document.implementation;var isgteIE6= isIE7 || isIE6;
var isIE5	= isIE && window.print && !isgteIE6;var isIEDOM2= isIE5 || isgteIE6;
var isIE4	= isIE && !isIEDOM2 && navigator.cookieEnabled;
var isIE3	= isIE && !isIE4 && !isIEDOM2;var isNS	= navigator.mimeTypes && !isIE;
var isNS3	= isNS && !navigator.language;var isNS4	= document.layers;
var isNS6	= document.getElementById && !isIE;
var isNS7	= isNS6;var isNS71	= document.designMode;
var isNSDOM2= isNS6;var isDOM2	= isIEDOM2 || isNSDOM2;
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;var is_opera = navigator.userAgent.toLowerCase().indexOf("opera") != -1;var is_firefox = navigator.userAgent.toLowerCase().indexOf("firefox") != -1;var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') != -1;
//////////////////////////////////////////////////////////////////////////////////////////////
//                                       COMMON CODE                                        //
function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
//////////////////////////////////////////////////////////////////////////////////////////////
//                                  NAMESPACES MANAGEMENT                                   //
var Namespace = {
register : function(_name){var chk = false;var cob = "";var spc = _name.split(".");for(var i = 0; i<spc.length; i++){if(cob!=""){cob+=".";}cob+=spc[i];chk = this.exists(cob);if(!chk){this.create(cob);}}if(chk){alert("Namespace: " + _name + " is already defined.");}},
create : function(_Src){eval("window." + _Src + " = new Object();");},
exists : function(_Src){eval("var NE = false; try{if(" + _Src + "){NE = true;}else{NE = false;}}catch(err){NE=false;}");return NE;}};
//////////////////////////////////////////////////////////////////////////////////////////////
//                                  UNO NAMESPACE BASICS                                    //
Namespace.register("uno");uno = {};uno.debug=false;uno.uniqueidcount = 0;
uno.getuqid = function(){uno.uniqueidcount += 1;return 'uno_uqid_' + uno.uniqueidcount;};
uno.throwerror = function (message){var err=new Error();err.message=message;throw err;};
uno.donothing = function(){if(uno){return;}return;};
//////////////////////////////////////////////////////////////////////////////////////////////
//                                    STRING UTILITIES                                      //
uno.htmlentities = function(str){return str.replace(/</g,"&lt;").replace(/>/g,"&gt;");};
uno.unhtmlentities = function(str){return str.replace(/&lt;/g,"<").replace(/&gt;/g,">");};
uno.replaceglobal = function(input,what,value){while (input.indexOf(what)>-1){input = input.replace(what,value);}return input;};
uno.stringends = function(value,match){var cx = 0;if (match==''){return true;}for(var c = value.length - match.length; c < value.length; c++){if(value.charAt(c)!=match.charAt(cx)){return false;}cx = cx + 1;}return true;};
uno.stringstarts = function(value,match){for(var c = 0; c < match.length; c++){if(value.charAt(c)!=match.charAt(c)){return false;}}return true;};
uno.firstupper=function(value){return value.charAt(0).toUpperCase()+value.slice(1);};
//////////////////////////////////////////////////////////////////////////////////////////////
//                                PAGE DOCUMENT MANAGEMENT                                  //
uno.querystring = function(key){var deft_="";key = key.replace(/[\[]/,'\\\[').replace(/[\]]/,'\\\]');var regex = new RegExp('[\\?&]'+key+'=([^&#]*)');var qs = regex.exec(window.location.href);if(qs == null){return deft_;}else{return qs[1];}};
uno.importcss = function(css_url){var olink = document.createElement('link');olink.href = css_url;olink.rel = 'stylesheet';olink.type = 'text/css';document.getElementsByTagName('head')[0].appendChild(olink)};
uno.importscript = function(script_url){var olink = document.createElement('script');olink.setAttribute('type','text/javascript');olink.setAttribute('src', script_url);document.getElementsByTagName('head')[0].appendChild(olink)};
uno.importwebicon = function(icon_url){var olink = document.createElement('link');olink.href = icon_url;olink.rel = 'SHORTCUT ICON';document.getElementsByTagName('head')[0].appendChild(olink)};
uno.setitle = function(title){document.title = title;};
uno.openbrowser = function(url){var thewindow = window.open(url,"save_listing","width=800,height=600,resizable=no,scrollbars=no,menubar=no,status=no,toolbar=no");};
//////////////////////////////////////////////////////////////////////////////////////////////
//                                   COOKIES MANAGEMENT                                     //
Namespace.register("uno.cookie");uno.cookie = {};
uno.cookie.create = function(name,value,days){var expires = '';
	if (days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));expires = '; expires='+date.toGMTString();}
	document.cookie=name+"="+value+expires+"; path=/";};
uno.cookie.read = function(name) {
	var c;var nameEQ=name+"=";var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++){c=ca[i];
		while (c.charAt(0)==' ') c=c.substring(1,c.length);
		if (c.indexOf(nameEQ)==0) return c.substring(nameEQ.length,c.length);
	}return null;};
uno.cookie.erase=function(name){uno.cookie.create(name,"",-1);};
/////////////////////////////////////////////////////////////////////////////////////////////
//                          CROSSBROWSER DHTML & EVENTS MANAGEMENT                         //
uno.clearchilds = function(elm){elm = $(elm);if (elm && elm.hasChildNodes && elm.removeChild){while (elm.hasChildNodes()){elm.removeChild(elm.firstChild);}}};
uno.include = function(url){if (!uno.xml){alert('uno.include function requires uno.xml.js');}
    else{var doc = uno.xml.syncload(url);document.write(uno.xml.nodexml(doc));}};
uno.update = function(target,url){if (!uno.xml){alert('uno.update function requires uno.xml.js');}
    else{var doc = uno.xml.syncload(url);
         var tgt = $(target);uno.clearchilds(tgt);
         tgt.innerHTML = uno.xml.nodexml(doc);}};
uno.addevent = function(elm, evtype, handler,usecapture){
	if (!elm.eventHandlers) elm.eventHandlers = [];
	if (!elm.eventHandlers[evtype]){
        elm.eventHandlers[evtype] = [];
		if (elm['on' + evtype]){elm.eventHandlers[evtype].push(elm['on' + evtype]);}
		elm['on' + evtype] = uno._handlevent;
	}elm.eventHandlers[evtype].push(handler);};
uno.removevent = function(elm, evtype, handler){var handlers = elm.eventHandlers[evtype];for (var i in handlers) if (handlers[i] == handler) delete handlers[i];};
uno._fixEvent = function(e){e.preventDefault = uno._preventDefault;e.stopPropagation = uno._stopPropagation;return event;};
uno._preventDefault = function() {this.returnValue = false;};
uno._stopPropagation = function() {this.cancelBubble = true;};
uno._handlevent = function(e){var returnValue = true;
	if (!e) e = uno._fixEvent(event);var handlers = this.eventHandlers[e.type]
	for (var i in handlers){this.$$handleEvent = handlers[i];returnValue = !((returnValue && this.$$handleEvent(e)) === false);}
	return returnValue;};
////////////////////////////////////////////////////////////////////////////////////////////



//NON PERMANENT IN THE FREMEWORK ALL BELOW
uno.evalscripts = function(elm) {
    elm = $(elm);
    var scripts = elm.getElementsByTagName('script');
    var code;
    var serrs = new Array;
    for (var i = 0; i < scripts.length; i++) {
        code = scripts[i].innerHTML ? scripts[i].innerHTML :
	    		scripts[i].text ? scripts[i].text :
		    	scripts[i].textContent;
        try { eval(code); } catch (ex) {
            var idx = serrs.length;
            serrs[idx] = ex;
    }   }
    var errcount = serrs.length;
    if (errcount > 0){
        var temp = '';
        for(var e = 0; e < errcount; e++){
            temp = temp + '\n ERROR' + (e+1);
            temp = temp + ': ' + serrs[e].message;
        }uno.throwerror(temp);}};

