/*****************************************************************
 * Componente:  Chat AJAX
 * Autor:       Ivan Mattoni
 * Empresa:     MyDesign
 * Comentario:  Librerias Javascript
 ****************************************************************/


var Class_Chat_Prototype = function(){
	
	this.$ = function(id){
		return document.getElementById(id);
	},
	
	this.validate_options = {
		validate: function(){
			var error = new Array();
			var param = new Array();
			var value="";
			var strReturn="var Return={"
			var options = arguments[0];
			var equal=false;
			
			for( var i=1; i<=arguments.length-1; i++ ){
				param = arguments[i];
				
				for( option in options ){
					if( option==param[0] ) {
						equal=true;
						break;
					}else equal=false;				
				}
	
				if( equal ){					
					eval("valueOption = options."+option+";");					
					if( typeof(valueOption)!="string" && typeof(valueOption)!="numeric" ) break;
					
					if( param[2].toLowerCase()=="required" ){
						if( typeof(valueOption)!=typeof(param[1]) ) error.push(param[0]);
						else{
							strReturn += option + ": " + this.get_value(valueOption) + ",";
						}
					}
					else {
						if( typeof(valueOption)==typeof(param[1]) ) {
							strReturn += option + ": " + this.get_value(valueOption) + ",";
						}else{
							strReturn += option + ": " + this.get_value(param[1]) + ",";							
						}
					}
					
				}else{
					if( param[2].toLowerCase()=="required" ) error.push(param[0]);
					else{												
						strReturn += param[0] + ": " + this.get_value(param[1]) + ",";						
					}				
				}
			}//end for		
		
					
			if( error.length>0 ){
				var nameprop="";
				for( var i=0; i<=error.length-1; i++ ){
					nameprop += error[i]+"\n";
				}
				
				alert('ERROR COMPONENTE "Slider":\n'+				  
					  'Las siguientes opciones son obligatorias o el tipo de dato es incorrecto:\n'+nameprop);
				return;
			}
			eval(strReturn.substr(0,strReturn.length-1)+"}");
			
			for( option in options ){
				eval("var value = options."+option+";");
				eval("var option2 = Return."+option);
				
				if( !option2 ){
					eval("Return."+option+"=value;");
				}
			}
			
			return Return;
		},
		
		get_value: function(Value){
			if( typeof(Value)=="string" ) return "'"+Value+"'";
			else return Value;
		}, 
		
		get_count_prop: function(prop){
			var count=0;
			for( p in prop ){
				count++;	
			}
			return count;
		}
	}
	
	this.Ajax={
		XMLHttp: false,
		on_finalizer: function(){},
		resultText: '',
		resultXML: '',
		
		create_instance_ajax: function(){
			this.XMLHttp=false;
			
			if( window.XMLHttpRequest ){
				return new XMLHttpRequest();
			}
			else if( window.ActiveXObject ){
				var versiones = ["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
				
				for(var i=0;i<versiones.length;i++){
					try {
						XMLHttp = new ActiveXObject(versiones[i]);
						if( XMLHttp ){
							return XMLHttp;
							break;
						}
					} catch(e){}
				}
			}
		},
		
		changing_state_ajax: function(This){
			if( This.Ajax.XMLHttp.readyState==1 ){
				try{
					This.Ajax.XMLHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				}
				catch(e){}
			}
			
			if( This.Ajax.XMLHttp.readyState==4 ){
				if( This.Ajax.XMLHttp.status==200 ){
					This.Ajax.resultText = This.Ajax.XMLHttp.responseText;
					This.Ajax.resultXML = This.Ajax.XMLHttp.responseXML;
					This.Ajax.on_finalizer();
					
				}else{
					//alert("Error al recibir respuesta "+This.Ajax.XMLHttp.statusText);
				}
			}
		},
		
		execute: function(method, link, send, This){
			this.XMLHttp = this.create_instance_ajax();
			if( this.XMLHttp ){
				if( typeof(send)=="undefined" ) send=null;
				this.XMLHttp.onreadystatechange = function(){This.Ajax.changing_state_ajax(This)};
				this.XMLHttp.open(method, link, true);
				this.XMLHttp.send(send);
				return;
			}		
		}
	}
	
	this.trim = function(str){
		return 	str.replace(/^\s+|\s+$/g,"");
	},
	
	this.getTimer = function(){
		var Digital=new Date()
		var hours=Digital.getHours()
		var minutes=Digital.getMinutes()
		var seconds=Digital.getSeconds()
		
		var dn=" am"
		if (hours>12){
			dn=" pm"
			hours=hours-12
		}
		if (hours==0) hours=12
		if (minutes<=9) minutes="0"+minutes
		if (seconds<=9) seconds="0"+seconds
		
		return hours+":"+minutes+":"+seconds+dn;	
	}

	this.get_property_css = function(object, prop){
		if( document.defaultView && document.defaultView.getComputedStyle ) {
			return document.defaultView.getComputedStyle(object,'').getPropertyValue(prop);
		}else{
			if( object.currentStyle ){
				eval("var result = object.currentStyle."+prop);
				return result;
			}else return "";
		}
	}

	this.addEvent = function(target, eventName, handlerName){
		if( target.addEventListener )
		  target.addEventListener(eventName, handlerName, false);
		else if( target.attachEvent )
		  target.attachEvent("on" + eventName, handlerName);
		else
		  target["on" + eventName] = handlerName;
	}
	
	this.set_opacity = function(o, val){
		if( o.filters ) {  //For IE
			val = parseInt(val)*10;
			if( val>100 ) val=100;
			
			try {
				o.filters.item("DXImageTransform.Microsoft.Alpha").opacity = val;
			} catch (e) { 
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.				
				if( val==100 ) o.style.filter = '';
				else o.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity='+val+')';
			}
		} else {
			val = parseInt(val)*0.1;
			if( val >1 ) val=1;
			
			o.style.opacity = val;
			o.style.MozOpacity = val;  //This is for older Mozilla Browsers
		}			
	}
	
	this.get_size_window = function(){
		var x, y;
		if (self.innerHeight) { // MOS
			y = self.innerHeight + window.pageYOffset;
			x = self.innerWidth + window.pageXOffset;
		} else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict
			x = document.documentElement.clientWidth + document.documentElement.scrollLeft;
			y = document.documentElement.clientHeight + document.documentElement.scrollTop;
		} else if (document.body.clientHeight) { // IE quirks
			y = document.body.clientHeight + document.body.scrollTop;
			x = document.body.clientWidth + document.body.scrollLeft;
		}
		return {x: x, y: y};
	}
	
	this.remove_element = function(obj){
		if( obj ){
			nodePadre = obj.parentNode;
			nodePadre.removeChild(obj);
		}
	}

	
}