﻿/**
*
*  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};
///////////////////Namespace utility used for organizing the entire uno framework... you can use it as well/////////
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 && uno.debug){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;}
};

Namespace.register("uno");
if (!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.replaceglobal = function(input,what,value){while (input.indexOf(what)>-1){input = input.replace(what,value);}return input;};
uno.clearchilds = function(elm){elm = $(elm);if (elm && elm.hasChildNodes && elm.removeChild){while (elm.hasChildNodes()){elm.removeChild(elm.firstChild);}}};
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);};
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.importdesc = function(desc){
    var olink = document.createElement('meta'); 
    olink.setAttribute("name","description");olink.setAttribute("content", desc);
    document.getElementsByTagName("head")[0].appendChild(olink)};

//NON PERMANENT IN THE FREMEWORK ALL BELOW
uno.donothing = function(){if(uno){return;}return;};
uno.htmlentities = function(str){
   return str.replace(/</g,"&lt;").replace(/>/g,"&gt;"); };//Eliminare dopo TODO.
   //TODO : controllare crossbrowserità del metodo value(alcuni fanno automaticamente un unentities)
   //var ta=document.createElement("textarea");
   // ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");   
   //return ta.value;};
uno.unhtmlentities = function(str){return str.replace(/&lt;/g,"<").replace(/&gt;/g,">");};
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);}
};