var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
var isFire = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;

function parentForm(childObj) {
    var testObj = childObj.parentNode;
    while(testObj.nodeName.toLowerCase() != 'form') {
        testObj = testObj.parentNode;
    }
	return testObj;
}
var cfxFilter = function(){
	this.sanitize= function(value,type){
		switch (type){
			case 'urlKey':
			if(typeof(value) != 'string')return false;
			    return value.toLowerCase().replace(' ', '-').replace(/[^0-9 a-z_.-]/, '');
				break;
			case 'Number':
			    return value.replace(/[^0-9]/, '');
				break;
			case 'trim':
			    return value.replace(/^\s+/g,'').replace(/\s+$/g,'');
				break;	
			default:
				return value;
		}	
	}
	this.validate= function(value,type){
		switch (type){
			case 'urlKey':
			if(typeof(value) != 'string')return false;
				value.match(/[0-9a-z_.-]/);
			    return (value.length)?true:false;
				break;
			default:
				return value;
		}	
	}
}
var cfxAjax = function(options) {
	
	var param=new Object();
	var xmlhttp=false;
	
	this.response='text';
	this.progress={position:0,totalSize:1,total:0};
	this.method='GET';
	this.setRequestHeader={name:"Content-Type", value:"application/x-www-form-urlencoded"};
	this.init=function(){
		if(typeof(XMLHttpRequest) != 'undefined'){
			try{
			  xmlhttp = new XMLHttpRequest();
			}catch(e){ }
		}else{
			try{
				xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
				}catch(e){
		  		xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
			}
		}
	   return xmlhttp;
	}
	this.addParam=function(options){
		if(typeof(options)=='object'){
			for ( name in options){
				param[name] = options[name];
			}
		}else{ 
			alert('addParam::( ERROR: No object())');
		}
	}
	this.send=function(link){
		var temThis=this;
		xmlhttp.open(this.method, link, true);
		if(this.setRequestHeader){
			xmlhttp.setRequestHeader('User-Agent', 'AJAX');
		}
		if(this.method=='POST'){
			var values=null
			for ( name in param){
				if(values){
					values=name+'='+param[name]
				}else{
					values='&'+name+'='+param[name]
				}
			}
			xmlhttp.send(values);
		}else{
			xmlhttp.send(null);
		}
		
       xmlhttp.onreadystatechange=function(){temThis.onreadystatechange()};
	   
	}
	this.onreadystatechange=function(){
		if(xmlhttp.readyState==4){ 
				switch (this.response){
					case 'text':
						this.oncomplete(xmlhttp.responseText);
					break;
					case 'xml':
						this.oncomplete(xmlhttp.responseXML);
					break;
					case 'body':
						this.oncomplete(xmlhttp.responseBody);
					break;
					case 'ajaxObject':
						this.oncomplete(eval(xmlhttp.responseText));
					break;
				   default:
					this.oncomplete(xmlhttp);
				}
		}
		
		this.progress.position=xmlhttp.readyState;
		this.progress.totalSize=4;
		this.progress.total=(xmlhttp.readyState/4)*1;
		this.onprogress(this.progress);
		
	};
	this.oncomplete=function(v){};
	this.onprogress=function(e){};
	this.init();
}
var alpha_array = new Array(':','a','b','c','d','e','f','g','h','i','j','k','l','m','n','ñ','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','/','?','&','=','.',',','-','_');
	
function urlDe(e){
	var e = e.split(',');
  	var s = '' ;
	for(n in e){
		var f = alpha_array[e[n]];
		s+=(f)?f:'';
	}
	return s;
}
function urlEn(e){
	var s='';
	e= e.split('');
	for(n in e){
		for (var i=0; i<alpha_array.length;i++){
			if(alpha_array[i]==e[n]){
				s+=i+",";
				break;
			}
		}
	}
	return s
}
