﻿function copyPrototype(descendant, parent) {
	var sConstructor = parent.toString();
	var aMatch = sConstructor.match( /\s*function (.*)\(/ );
	if ( aMatch != null ) { descendant.prototype[aMatch[1]] = parent; }
	for (var m in parent.prototype) {
		descendant.prototype[m] = parent.prototype[m];
	}
};

function god(id){
	this.id = id;
	this.elem = document.getElementById(this.id);
}

god.prototype.isEmpty = function (){
	var result;
	try{
		result = this.elem.value=='';
	}catch(e){
		try{
			result = this.elem.options.length==0;
		}catch(e){};
	};
	return result;
};

god.prototype.isNumeric = function(){
		var result;
		try{
			result = typeof(this.elem.value)=='numeric';
		}catch(e){};
		return result;		
	};
god.prototype.inRange = function(from, to){
		var result;
		try{
			result = this.isNumeric() && this.elem.value>=from && this.elem.value<=to;	
		}catch(e){};
		return result;
	};

god.prototype.isEmail = function(){
		var result;
		try{
			result = this.isEmpty && this.isMatch(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/);
		}catch(e){};
		return result;
	};
god.prototype.isMatch = function (regexp){
		var result;
		try{
			result = this.elem.value.match(regexp);
		}catch(e){};
		return result;
	};
	
god.prototype.isDifferent = function (){
		var result;
		try{
			if(typeof(this.elem.length) == 'undefined') {
				this.elem = this.elem.form[this.elem.id];
			}
			var checkedRadio;
			for(var i=0;i<this.elem.length;i++) {
					if(this.elem[i].checked) {
							checkedRadio = this.elem[i];
					}
			}
			result = checkedRadio.value == this.elem[0].value;			
			if(!result) {
				result = confirm("¿Está seguro que desea mover este prospect?");
			}
			//result = false;
		}catch(e){
		};
		return result;
	};	

god.prototype.onValidate = function(){
	//	alert('god::onValidate()');
		return true;
	};
god.prototype.onSubmit = function() {
		return this.onValidate();
	};

