
//REAL Agora Util class [STATIC METHODS]

    DataFloat.Agora.Util = function(){};

    
    DataFloat.Agora.Util.NewPop = function(Url, Width, Height, Name){
        Name    = DataFloat.Agora.Util.IsEmptyOrNull(Name) ? DataFloat.Agora.Util.NewGuid().replace(/-/g,"") :  Name;
        Width   = DataFloat.Agora.Util.IsEmptyOrNull(Width) ? 500 : Width;
        Height  = DataFloat.Agora.Util.IsEmptyOrNull(Height) ? 300 : Height;
        window.open(Url, Name, DataFloat.Agora.Util.StringFormat("height={1},width={0},scrollbars=no,menubar=no,toolbar=no,status=no,resizable=no", Width, Height));
    }
    
    
    DataFloat.Agora.Util.ValidateForm = function(FormId){
    
 	    var inputFields = $('#' + FormId + ' input').get();
	    for (var i = 0; i<inputFields.length; i++)
	    {
		    if (inputFields[i].id.indexOf('req')!=-1 && $.trim(inputFields[i].value)=='')
		    {
			    alert("Please fill in the required field.");
			    inputFields[i].focus();
			    return false;
		    }
	    }
	    return true;
    }
    
    DataFloat.Agora.Util.ValidateFormtitleval = function(FormId){
    
 	    var inputFields = $('#' + FormId + ' input').get();
	    for (var i = 0; i<inputFields.length; i++)
	    {
		    if (inputFields[i].id.indexOf('req')!=-1 && ($.trim(inputFields[i].value)==$.trim(inputFields[i].title)))
		    {
			    alert("Please fill in the required field.");
			    inputFields[i].focus();
			    return false;
		    }
	    }
	    return true;
    }
    
    /*
    $(document).ready(function(){
        $AgoraLog.WriteLog('[DataFloat.Agora.Util.Validation] - Initializing');
        $("#RegForm").submit( function() {
          alert('as');
        } );

        $AgoraLog.WriteLog('[DataFloat.Agora.Util.Validation] - Initializing');
        formsToValidate = $('.AgoraValidateForm');
        alert(formsToValidate);
        for (var i = 0; i<formsToValidate.length; i++){
            $AgoraLog.WriteLog('[DataFloat.Agora.Util.Validation] - ' + formsToValidate);
        
        
    });}*/
    
    DataFloat.Agora.Util.AutoClear = function(formElemet){
		    if (formElemet.title == formElemet.value){
				formElemet.value = '';
				return false;
			}
			
			if(formElemet.value == ''){
				formElemet.value = formElemet.title;
				return false;
			}
	}
	

    DataFloat.Agora.Util.DeleteCookie = function(name) {
	        DataFloat.Agora.Util.SetCookie(name, "", -1);
    }
	   
    DataFloat.Agora.Util.ReadCookie = function(name) {
	    var nameEQ = name + "=";
	    var ca = document.cookie.split(';');
	    for(var i=0;i < ca.length;i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
	    }
	    return null;
    }
        
	DataFloat.Agora.Util.SetCookie = function(name,value,days) {
	    if (days) {
		    var date = new Date();
		    date.setTime(date.getTime()+(days*24*60*60*1000));
		    var expires = "; expires="+date.toGMTString();
	    }
	    else var expires = "";
	    document.cookie = name+"="+escape(value)+expires+"; path=/";
    }
	
	DataFloat.Agora.Util.ReplaceAll = function(currentText, textOld, textNew){
	    var returnText = currentText; 
	    while(returnText.indexOf(textOld) != -1){
	        returnText = returnText.replace(textOld, textNew);
	    }
	    return returnText;
	}
	
	DataFloat.Agora.Util.removeQueryStringAttr = function(queryString,AttrName)
    {
        queryString = DataFloat.Agora.Util.ReplaceQueryString(queryString, AttrName, "");
		queryString = DataFloat.Agora.Util.ReplaceAll(queryString, "&"+AttrName+"=", "");
		return queryString;
    }    	
	
	DataFloat.Agora.Util.getYear = function()
	{
        var now = new Date();
        return now.getFullYear().toString();
	}
	
	DataFloat.Agora.Util.getMonth = function()
	{
        //Date
        var now = new Date();
        var Month = (now.getMonth()+1).toString();
        if (Month.length==1) Month = "0" + Month;
        return Month.toString();   	
	}
	
	DataFloat.Agora.Util.getDate = function()
	{
        //Date
        var now = new Date();
        var date = now.getDate();
        if (date<10) date = "0" + date;
        return date.toString();   	
	}
	
	
    
    DataFloat.Agora.Util.SerializeForm = function(formId){
        var params = $('#'+formId).fastSerialize();
        var fragment = $.param( params );
        return fragment;
    }
    
    
    DataFloat.Agora.Util.NewGuid = function(){
        var result, i, j;
            result = '';
            for(j=0; j<32; j++)
            {
                if( j == 8 || j == 12|| j == 16|| j == 20)
                    result = result + '-';
                i = Math.floor(Math.random()*16).toString(16).toUpperCase(); result = result + i;
            }
            return result;
    }
    
    DataFloat.Agora.Util.FormatNumber = function (num){
        num = num.toString().replace(/\$|\,/g,'');
        if(isNaN(num))
        num = "0";
        sign = (num == (num = Math.abs(num)));
        num = Math.floor(num*100+0.50000000001);
        cents = num%100;
        num = Math.floor(num/100).toString();
        if(cents<10)
        cents = "0" + cents;
        for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
        num = num.substring(0,num.length-(4*i+3))+','+
        num.substring(num.length-(4*i+3));
        return (((sign)?'':'-') + '$' + num);
    }
    
    

    DataFloat.Agora.Util.StringFormat = function( text )
    {
        if ( arguments.length <= 1 )
            return text;

        var tokenCount = arguments.length - 2;
        for( var token = 0; token <= tokenCount; token++ )
            text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ),
                                                    arguments[ token + 1 ] );
        return text;
    };
    
    DataFloat.Agora.Util.IsEmptyOrNull = function (text){
        if (text == '' || text == null || text == undefined)
            return true;
        else
            return false;
    };
    
    DataFloat.Agora.Util.ReplaceQueryString = function (Url, Key, Value) {
           var re = new RegExp(Key + "=.*?(&|$)","gi");
           if (Url.match(re))
               return Url.replace(re, Key + "=" + Value + '$1');
           else
               return Url + '&' + Key + "=" + Value;
        }
    
    
    DataFloat.Agora.Util.NewEvent = function (ctrl, Tipo)
    {
	    // Filtra navegadores conhecidos
	    var s = QualNavegador();

	    if ( s.length==0 )
		    return;

	    if ( s=="IE" && QualVersao()>6 )
		    return;
	    /* As linhas abaixo, foram comentadas para a função rodar no NS 7.0	
	    if ( s=="NE" && QualVersao()>4 )
		    return;
	    */
	    if (ctrl.onkeypress==null)
	    {
		    if (Tipo!=null)
			    Tipo.toUpperCase();
		    ctrl.Tipo=Tipo;
		    //InicializarIndices();
		    ctrl.onkeypress=ValidarTecla;
	    }
    }

    DataFloat.Agora.Util.GetParameter = function (QueryString , name)
    {
		name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
		var regexS = "[\\?&]"+name+"=([^&#]*)";  
		var regex = new RegExp( regexS );  
		var results = regex.exec( QueryString );  
		if( results == null )    
			return "";  
		else    
			return results[1];
    }


//THIS LIBRARY NEEDS TO BE CLEAN AND ORGANIZED
    //Class Declaration
    function __DataFloat__Agora__Util(){
    
        //Public Methods
        this.GenerateGuid = __Util__GenerateGuid;
        this.ReplaceQueryString = __Util__ReplaceQueryString;
        //Public Methods
        
        
        function __Util__GenerateGuid(){
            var result, i, j;
            result = '';
            for(j=0; j<32; j++)
            {
                if( j == 8 || j == 12|| j == 16|| j == 20)
                result = result + '-';
                i = Math.floor(Math.random()*16).toString(16).toUpperCase();
                result = result + i;
            }
            return result;
        }
        
        function __Util__ReplaceQueryString(Url, Key, Value) {
           var re = new RegExp(Key + "=.*?(&|$)","i");
           if (Url.match(re))
               return Url.replace(re, Key + "=" + Value + '$1');
           else
               return Url + '&' + Key + "=" + Value;
        }
    }
    //
    Array.prototype.remove = function(from, to) {
      var rest = this.slice((to || from) + 1 || this.length);
      this.length = from < 0 ? this.length + from : from;
      return this.push.apply(this, rest);
    };
    
    if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
		  i || (i = 0);
		  var length = this.length;
		  if (i < 0) i = length + i;
		  for (; i < length; i++)
		    if (this[i] === item) return i;
		  return -1;
		};
    
    String.IsEmptyOrNull = function (text){
        if (text == '' || text == null || text == undefined)
            return true;
        else
            return false;
    };
    
    
    

    
    
    //Explicit function
    String.format = function( text )
    {
        //check if there are two arguments in the arguments list
        if ( arguments.length <= 1 )
        {
            //if there are not 2 or more arguments there’s nothing to replace
            //just return the original text
            return text;
        }
        //decrement to move to the second argument in the array
        var tokenCount = arguments.length - 2;
        for( var token = 0; token <= tokenCount; token++ )
        {
            //iterate through the tokens and replace their placeholders from the original text in order
            text = text.replace( new RegExp( "\\{" + token + "\\}", "gi" ),
                                                    arguments[ token + 1 ] );
        }
        return text;
    };
    
    Number.Random = function(){
        return Math.round(1000*Math.random());
    }
    
    
    function UsabilityEnhancement(divName, state){
			if (state == 1){
				$("#" + divName).addClass("BoxEnhancement");
			}else{
				$("#" + divName).removeClass("BoxEnhancement");
			}
				
		}
    
    
    function serializeForm(formID)
    {
        var params = $('#'+formID).fastSerialize();
        var fragment = $.param( params );
        return fragment;
    }
    
    /* I have to re-code all those code */
    
    
    
    function isNumeric(pStr)
{
//	var aux = pStr;

//	var regex = /^[0-9]$/;
//	return regex.test(pStr);
	if (pStr.indexOf(".") > 0) return false;
	if (pStr.indexOf(",") > 0) return false;
	
	if (isNaN(pStr))
		return false;
	else
		return true;
		
}
//Fim da função responsável por verificar caracteres numéricos.

//Put Comma in numeric XXX,XXX,XXX
	function commafy(val){
		var pos;
		val = val.split(",").join(""); // remove existing commas if present.
		var dot=val.indexOf("."); // locate decmal
		if(dot<0)dot=val.length; // use end if no decimal
		var r="";
		for(pos=dot-3;pos>=1;pos-=3) // put commas in
		r=","+val.substr(pos,3)+r;
		r=val.substring(0,pos+3)+r; // put start of string on
		dot=val.indexOf("."); // check for decimal
		if(dot>0)r+=val.substring(dot);// put fraction part on
		return r;
	}

    

<!--
// Verificar qual navegador
function QualNavegador(){
	var u = navigator.userAgent.toLowerCase();
	var s = navigator.appName;	
	if(u.indexOf('safari')!= -1)
		return "SA";	
	if ( s == "Microsoft Internet Explorer" )
		return "IE";
	else if ( s == "Netscape" )
		return "NE";
	else
		return "";
}

// Verificar qual a versão do navegador
function QualVersao()
{
	var s = navigator.appVersion;
	if ( QualNavegador() == "IE" )
	{
		var i = s.search("MSIE");
		s=s.substring(i+5);
		i=s.search(";");
		return s.substring(0,i);
	}
	else if ( QualNavegador() == "NE" ){
		if(navigator.userAgent.indexOf('Netscape/7.0')!= -1)return "7.0";		
		if(navigator.userAgent.indexOf('Netscape/7.1')!= -1)return "7.1";
		return parseInt(s.substring(0,1));
	}
	else{
		return 0;}
}


function ValidarTecla (evnt)
{
	var tk;
    var c;
	var tkce;
	var ce;
	// Recebe a tecla pressionada
	tk = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    c=String.fromCharCode(tk);
	c=c.toUpperCase();

	tkce = ( (QualNavegador()=="IE") ? event.keyCode : evnt.which);
    ce=String.fromCharCode(tkce);
	ce=ce.toUpperCase();
	
	// Só aceita teclas alfanuméricas. Não aceita teclas de controle
    if ( tk < 32 )
		return true;
	if ( tk > 127 )
		return false;

	switch ( this.Tipo )
	{
	case "D":
		if ( c<"0" || c>"9" )
			return false;
		break;
	case "N":
		if ( (c<"0" || c>"9") && (c!=",") )
			return false;
		if ( (c==",") && ((this.value.search(",")>-1) || (this.value.length==0)) )
			return false;
		if ( (c==".") && (this.value.length==0) )
			return false;
		break;
	case "C":
		if ( c<"A" || c>"Z" )
			return false;
		break;
	case "CE":
		if ( tkce < 33 )
			return true;
		if ( tkce > 127 )
			return false;
		if ( ce<"A" || ce>"Z" )
			return false;
		break;
	case "ALERTLOGIN":
		if ((c<"0" || c>"9") || (c<"A" || c>"Z"))
		{
			return false;
		}
		break;
	case "ALERT":
		if ( c<"A" || c>"Z" )
		{
			return false;
		}
		break;
	case "ALERTSENHA":
		if ((c<"0" || c>"9") || (c<"A" || c>"Z"))
		{
			return false;
		}
		break;
	default:
		break;
	}

	//verifica se o tamanho do campo, coincide com o solicitado para saltar	
	// se for NS7.0, Safari não decrementa		
	if ((QualNavegador()=="NE" && QualVersao()=="7.0") || QualNavegador()=="SA")	
		this.Saltar=(this.value.length==this.Tam);	
	else
		this.Saltar=(this.value.length==this.Tam-1);	
		
		
	if ( ((QualNavegador()=="IE") && QualVersao()<5) || (QualNavegador()!="IE") )
		//SaltarCampo(this);

	return true;
}
// -->


shortcut = {
	'all_shortcuts':{},//All the shortcuts are stored in this array
	'add': function(shortcut_combination,callback,opt) {
		//Provide a set of default options
		var default_options = {
			'type':'keydown',
			'propagate':false,
			'disable_in_input':false,
			'target':document,
			'keycode':false
		}
		if(!opt) opt = default_options;
		else {
			for(var dfo in default_options) {
				if(typeof opt[dfo] == 'undefined') opt[dfo] = default_options[dfo];
			}
		}

		var ele = opt.target
		if(typeof opt.target == 'string') ele = document.getElementById(opt.target);
		var ths = this;
		shortcut_combination = shortcut_combination.toLowerCase();

		//The function to be called at keypress
		var func = function(e) {
			e = e || window.event;
			
			if(opt['disable_in_input']) { //Don't enable shortcut keys in Input, Textarea fields
				var element;
				if(e.target) element=e.target;
				else if(e.srcElement) element=e.srcElement;
				if(element.nodeType==3) element=element.parentNode;

				if(element.tagName == 'INPUT' || element.tagName == 'TEXTAREA') return;
			}
	
			//Find Which key is pressed
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			var character = String.fromCharCode(code).toLowerCase();
			
			if(code == 188) character=","; //If the user presses , when the type is onkeydown
			if(code == 190) character="."; //If the user presses , when the type is onkeydown
	
			var keys = shortcut_combination.split("+");
			//Key Pressed - counts the number of valid keypresses - if it is same as the number of keys, the shortcut function is invoked
			var kp = 0;
			
			//Work around for stupid Shift key bug created by using lowercase - as a result the shift+num combination was broken
			var shift_nums = {
				"`":"~",
				"1":"!",
				"2":"@",
				"3":"#",
				"4":"$",
				"5":"%",
				"6":"^",
				"7":"&",
				"8":"*",
				"9":"(",
				"0":")",
				"-":"_",
				"=":"+",
				";":":",
				"'":"\"",
				",":"<",
				".":">",
				"/":"?",
				"\\":"|"
			}
			//Special Keys - and their codes
			var special_keys = {
				'esc':27,
				'escape':27,
				'tab':9,
				'space':32,
				'return':13,
				'enter':13,
				'backspace':8,
	
				'scrolllock':145,
				'scroll_lock':145,
				'scroll':145,
				'capslock':20,
				'caps_lock':20,
				'caps':20,
				'numlock':144,
				'num_lock':144,
				'num':144,
				
				'pause':19,
				'break':19,
				
				'insert':45,
				'home':36,
				'delete':46,
				'end':35,
				
				'pageup':33,
				'page_up':33,
				'pu':33,
	
				'pagedown':34,
				'page_down':34,
				'pd':34,
	
				'left':37,
				'up':38,
				'right':39,
				'down':40,
	
				'f1':112,
				'f2':113,
				'f3':114,
				'f4':115,
				'f5':116,
				'f6':117,
				'f7':118,
				'f8':119,
				'f9':120,
				'f10':121,
				'f11':122,
				'f12':123
			}
	
			var modifiers = { 
				shift: { wanted:false, pressed:false},
				ctrl : { wanted:false, pressed:false},
				alt  : { wanted:false, pressed:false},
				meta : { wanted:false, pressed:false}	//Meta is Mac specific
			};
                        
			if(e.ctrlKey)	modifiers.ctrl.pressed = true;
			if(e.shiftKey)	modifiers.shift.pressed = true;
			if(e.altKey)	modifiers.alt.pressed = true;
			if(e.metaKey)   modifiers.meta.pressed = true;
                        
			for(var i=0; k=keys[i],i<keys.length; i++) {
				//Modifiers
				if(k == 'ctrl' || k == 'control') {
					kp++;
					modifiers.ctrl.wanted = true;

				} else if(k == 'shift') {
					kp++;
					modifiers.shift.wanted = true;

				} else if(k == 'alt') {
					kp++;
					modifiers.alt.wanted = true;
				} else if(k == 'meta') {
					kp++;
					modifiers.meta.wanted = true;
				} else if(k.length > 1) { //If it is a special key
					if(special_keys[k] == code) kp++;
					
				} else if(opt['keycode']) {
					if(opt['keycode'] == code) kp++;

				} else { //The special keys did not match
					if(character == k) kp++;
					else {
						if(shift_nums[character] && e.shiftKey) { //Stupid Shift key bug created by using lowercase
							character = shift_nums[character]; 
							if(character == k) kp++;
						}
					}
				}
			}

			if(kp == keys.length && 
						modifiers.ctrl.pressed == modifiers.ctrl.wanted &&
						modifiers.shift.pressed == modifiers.shift.wanted &&
						modifiers.alt.pressed == modifiers.alt.wanted &&
						modifiers.meta.pressed == modifiers.meta.wanted) {
				callback(e);
	
				if(!opt['propagate']) { //Stop the event
					//e.cancelBubble is supported by IE - this will kill the bubbling process.
					e.cancelBubble = true;
					e.returnValue = false;
	
					//e.stopPropagation works in Firefox.
					if (e.stopPropagation) {
						e.stopPropagation();
						e.preventDefault();
					}
					return false;
				}
			}
		}
		this.all_shortcuts[shortcut_combination] = {
			'callback':func, 
			'target':ele, 
			'event': opt['type']
		};
		//Attach the function with the event
		if(ele.addEventListener) ele.addEventListener(opt['type'], func, false);
		else if(ele.attachEvent) ele.attachEvent('on'+opt['type'], func);
		else ele['on'+opt['type']] = func;
	},

	//Remove the shortcut - just specify the shortcut and I will remove the binding
	'remove':function(shortcut_combination) {
		shortcut_combination = shortcut_combination.toLowerCase();
		var binding = this.all_shortcuts[shortcut_combination];
		delete(this.all_shortcuts[shortcut_combination])
		if(!binding) return;
		var type = binding['event'];
		var ele = binding['target'];
		var callback = binding['callback'];

		if(ele.detachEvent) ele.detachEvent('on'+type, callback);
		else if(ele.removeEventListener) ele.removeEventListener(type, callback, false);
		else ele['on'+type] = false;
	}
}

function AutoClear(formElemet){
		
		
			if (formElemet.title == formElemet.value){
				formElemet.value = '';
				return false;
				}
			
			if(formElemet.value == ''){
				formElemet.value = formElemet.title;
				return false;
				}

		
	}