/*----------------------------------------------------------------------------------------------------------*/
// htc FrameWork 3.0 - 2004-2008
//created by: Paulo Henrique
/*----------------------------------------------------------------------------------------------------------*/
/*DEFINIÇÕES*/
var isIE = (document.all)?true:false;
if(window.ActiveXObject && !window.XMLHttpRequest){window.XMLHttpRequest = function(){var msxmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');for(var i = 0; i < msxmls.length; i++){try{return new ActiveXObject(msxmls[i]);}catch(e){}}return null;};}
if(window.opera && !window.XMLHttpRequest){window.XMLHttpRequest = function(){this.readyState = 0;this.status = 0;this.statusText = '';this._headers = [];this._aborted = false;this._async = true;this._defaultCharset = 'ISO-8859-1';this._getCharset = function(){var charset = _defaultCharset;var contentType = this.getResponseHeader('Content-type').toUpperCase();val = contentType.indexOf('CHARSET=');if(val != -1){charset = contentType.substring(val);}val = charset.indexOf(';');if(val != -1){charset = charset.substring(0, val);}val = charset.indexOf(',');if(val != -1){charset = charset.substring(0, val);}return charset;};this.abort = function(){this._aborted = true;};this.getAllResponseHeaders = function(){return this.getAllResponseHeader('*');};this.getAllResponseHeader = function(header){var ret = '';for (var i = 0; i < this._headers.length; i++){if(header == '*' || this._headers[i].h == header){ret += this._headers[i].h + ': ' + this._headers[i].v + '\n';}}return ret;};this.getResponseHeader = function(header){var ret = getAllResponseHeader(header);var i = ret.indexOf('\n');if (i != -1) {ret = ret.substring(0, i);}return ret;};this.setRequestHeader = function(header, value){this._headers[this._headers.length] = {h:header, v:value};};this.open = function(method, url, async, user, password){this.method = method;this.url = url;this._async = true;this._aborted = false;this._headers = [];if (arguments.length >= 3){this._async = async;}if(arguments.length > 3){opera.postError('XMLHttpRequest.open() - user/password not supported');}this.readyState = 1;if(this.onreadystatechange){this.onreadystatechange();}};this.send = function(data){if(!navigator.javaEnabled()){alert("XMLHttpRequest.send() - Java must be installed and enabled.");return;}if(this._async){setTimeout(this._sendasync, 0, this, data);}else{this._sendsync(data);}};this._sendasync = function(req, data){if(!req._aborted){req._sendsync(data);};};this._sendsync = function(data){this.readyState = 2;if (this.onreadystatechange){this.onreadystatechange();}var url = new java.net.URL(new java.net.URL(window.location.href), this.url);var conn = url.openConnection();for(var i = 0; i < this._headers.length; i++){conn.setRequestProperty(this._headers[i].h, this._headers[i].v);}this._headers = [];if(this.method == 'POST'){conn.setDoOutput(true);var wr = new java.io.OutputStreamWriter(conn.getOutputStream(), this._getCharset());wr.write(data);wr.flush();wr.close();}
var gotContentEncoding = false;var gotContentLength = false;var gotContentType = false;var gotDate = false;var gotExpiration = false;var gotLastModified = false;for (var i = 0; ; i++){var hdrName = conn.getHeaderFieldKey(i);var hdrValue = conn.getHeaderField(i);if(hdrName == null && hdrValue == null){break;}if(hdrName != null){this._headers[this._headers.length] = {h:hdrName, v:hdrValue};switch (hdrName.toLowerCase()){case 'content-encoding':gotContentEncoding=true; break;case 'content-length':gotContentLength=true; break;case 'content-type':gotContentType=true; break;case 'date':gotDate=true; break;case 'expires':gotExpiration=true; break;case 'last-modified':gotLastModified=true; break;}}}var val;val = conn.getContentEncoding();if(val != null && !gotContentEncoding) this._headers[this._headers.length] = {h:'Content-encoding', v:val};val = conn.getContentLength();if(val != -1 && !gotContentLength) this._headers[this._headers.length] = {h:'Content-length', v:val};val = conn.getContentType();if(val != null && !gotContentType) this._headers[this._headers.length] = {h:'Content-type', v:val};val = conn.getDate();if(val != 0 && !gotDate) this._headers[this._headers.length] = {h:'Date', v:(new Date(val)).toUTCString()};val = conn.getExpiration();if(val != 0 && !gotExpiration) this._headers[this._headers.length] = {h:'Expires', v:(new Date(val)).toUTCString()};val = conn.getLastModified();if(val != 0 && !gotLastModified) this._headers[this._headers.length] = {h:'Last-modified', v:(new Date(val)).toUTCString()};var reqdata = '';var stream = conn.getInputStream();if(stream){var reader = new java.io.BufferedReader(new java.io.InputStreamReader(stream, this._getCharset()));var line;while((line = reader.readLine()) != null){if(this.readyState == 2){this.readyState = 3;if(this.onreadystatechange){this.onreadystatechange();}}reqdata += line + '\n';}reader.close();this.status = 200;this.statusText = 'OK';this.responseText = reqdata;this.readyState = 4;if(this.onreadystatechange){this.onreadystatechange();}if(this.onload){this.onload();}}else{this.status = 404;this.statusText = 'Not Found';this.responseText = '';this.readyState = 4;if(this.onreadystatechange){this.onreadystatechange();}if(this.onerror){this.onerror();}}};};}
if(!window.ActiveXObject && window.XMLHttpRequest){window.ActiveXObject = function(type){switch (type.toLowerCase()){case 'microsoft.xmlhttp':case 'msxml2.xmlhttp':case 'msxml2.xmlhttp.3.0':case 'msxml2.xmlhttp.4.0':case 'msxml2.xmlhttp.5.0':return new XMLHttpRequest();}return null;};}
/*getElementById*/
function _gel(a){return document.getElementById?document.getElementById(a):null;}
/*getElementsByName*/
function _geln(a){return document.getElementsByName?document.getElementsByName(a):null;}
/*getElementByTagName*/
function _geltn(a){if(a == "*" && document.all){return document.all;}return document.getElementsByTagName?document.getElementsByTagName(a):[];}
/*_gmv(a):getMovieFlash;a:flashInstanceName*/
function _gmv(a) {return (isIE)?window[a]:document[a];}
/*_ce(a):createElement;a:elementName*/
function _ce(a){return document.createElement(a);}
/*_geo():getStyleObject;c:htcCSSObject*/
function _gso(c,p){var o = null;if(isIE){o = document.createStyleSheet();if(c){try{if(typeof(c) == 'object'){for(style in c){o.addRule( ((p)?p+style:style), c[style]);}}else{for(var i=0;i<c.length;i++){o.addRule(c[i].name, c[i].style);}}}catch(e){alert('GSO:erro de estrutura do array');}}}else{o = document.createElement('style');o.type='text/css';	o.innerHTML = '';try{if(typeof(c) == 'object'){for(style in c){o.innerHTML += ((p)?p+style:style) +'{'+ c[style] +'}';}}else{for(var i=0;i<c.length;i++){o.innerHTML += c[i].name +'{'+ c[i].style +'}';}}}catch(e){alert('GSO:erro de estrutura do array - '+ e);}_geltn('body')[0].appendChild(o);}return o;}//get Style object
/*_ass(n,s,[o]):add Style Sheet;n:className,s:classDefinition,[o]:Object*/
function _ass(n,s,o){if(!o){alert('NO');o = _geltn('STYLE');if(o.length == 0){if(isIE){o = document.createStyleSheet();}else{o = document.createElement('style');o.type='text/css';	o.innerHTML = '';_geltn('body')[0].appendChild(o);}}else{o = o[0];}}try{if(isIE){o.addRule('.Teste', 'width:200px;');}else{o.innerHTML += n +'{'+ s +'}';}}catch(e){alert('ASS error:'+ e.message +'\nname:'+ n);}}
/*innerHTML*/
function _inHTML(a,b,c){
	if(typeof a == 'string'){
		if(_gel(a) != null){
			if(c){
				_gel(a).innerHTML += b;
			}else{
				_gel(a).innerHTML = b;	
			}
		}
	}else{
		if(a == null){
			alert(b);
		}
		if(c){
			a.innerHTML += b;
		}else{
			a.innerHTML = b;
		}
	}
}
/*p(x,y):ponto*/
function _p(x,y) { this.x = x; this.y = y;}$cmop = new _p(0,0);
/*move layer to mouse position*/
function _mlmp(o,oh,ov){var ob = ((typeof(o) == 'string')?_gel(o):o);if(o != null){ob.style.left = $cmop.x + oh;ob.style.top  = $cmop.y + ov;}}
/*move to object position*/
function _mtop(o,d,x,y){
	var p = new _p(0,0);if(!document.layers){var onWindows = navigator.platform ? navigator.platform == "Win32" : false;var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;var par = d;var lastOffset = 0;while(par){if( par.leftMargin && ! onWindows ) x += parseInt(par.leftMargin);if( (par.offsetLeft != lastOffset) && par.offsetLeft ) x += parseInt(par.offsetLeft);if( par.offsetLeft != 0 ) lastOffset = par.offsetLeft;par = macIE45 ? par.parentElement : par.offsetParent;}par = d;while(par){if( par.topMargin && !onWindows ) y += parseInt(par.topMargin);if( (par.offsetTop != lastOffset) && par.offsetTop ) y += parseInt(par.offsetTop);if( par.offsetTop != 0 ) lastOffset = par.offsetTop;par = macIE45 ? par.parentElement : par.offsetParent;}p.y = y;p.x = x;}
	if(o){
		o.style.left = p.x +'px';
		o.style.top  = p.y +'px';
	}
	return p;}
/*get mouse position*/
function _gml(e){if(_geltn('body').length > 0){if(!isIE){$cmop.x = e.pageX;$cmop.y = e.pageY;}else{$cmop.x = event.x + _geltn('body')[0].scrollLeft;$cmop.y = event.y + _geltn('body')[0].scrollTop;}return true;}else{return false;}}
document.onmousemove = _gml;
/*AJAX;{url:string,config:{ctrl:['object'],type:['xml','json','*default'],postContent:['*default','xml'],method:['*post','get'],params:['object','string'],args:'any',onStateChange:'function'}};{req:['object','xml','string'],obj:'object',args:'any',err:{code:'number',men:'string'}*/
function _get(url, config){if(!config){config={desc:null}}var result = null, error={code:0,men:''}, xmlcontent = ((config.obj)?config.obj:new XMLHttpRequest());if(!config.type){config.type='default'} if(typeof config.ctrl != 'object'){config.ctrl = null}	if(!config.postContent){config.postContent='default'} if(!config.method){config.method='post'} if(!config.params){config.params=''}	if(typeof config.params == 'object'){config.params=hf.json.url(config.params)} if(xmlcontent){xmlcontent.onreadystatechange = ((typeof config.onStateChange == 'function')?config.onStateChange({req:result,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null),err:error}):function(){if(xmlcontent.readyState == 3){if(typeof config.onLoading == 'function'){config.onLoading({req:xmlcontent.responseText,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null),err:error});}}else if(xmlcontent.readyState == 4){if(xmlcontent.status == 200 || xmlcontent.status == 304){switch(config.type){case 'xml':try{result = xmlcontent.responseXML;}catch(e){error.code=1;error.men=e;}break;case 'json':try{result = eval(unescape(xmlcontent.responseText));}catch(e){error.code=2;error.men=e;}break;default:result = unescape(xmlcontent.responseText);break;}if(typeof config.onLoad == 'function'){config.onLoad({req:result,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null),err:error});}}}else if(xmlcontent.readyState == 4 && (xmlcontent.status == 500 || xmlcontent.status == 404)){if(config.onError){config.onError({req:result,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null),err:error})}}});if(config.method == 'get'){xmlcontent.open('GET', url+((config.params!='')?'?'+config.params:''), true);xmlcontent.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8; ajaxGetRequest;');xmlcontent.send(null);}else{xmlcontent.open('POST', url, true);xmlcontent.setRequestHeader('Content-Type',((config.postContent == 'xml')?'text/xml':'application/x-www-form-urlencoded; charset=UTF-8; ajaxPostRequest;'));xmlcontent.send(config.params);}}else{if(config.onError){config.onError({req:result,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null),err:error})}} return {req:result,ctrl:config.ctrl,obj:xmlcontent,args:((config.args)?config.args:null)};}
/*panel(a,b,c,d,e,f,g,h,i,j,k,l):cria um panel flutuante;a:Tipo[frame,conteudo],b:titulo,c:opções[close,size,opction],d:conteudo ou url,e:largura,f:altura,g:verb[{url:'',click:'',title:'',label:''}],h:position[center,top,default],i:top margin,j:left margin,k:dragable,l:name*/
function _panel(a,b,c,d,e,f,g,h,i,j,k,l){
	return win_control.initWin(a,b,c,d,e,f,g,h,i,j,k,l);
}
/*coockies*/
function _rCK(name){var cookieValue='', search=name+"=";if(document.cookie.length > 0){offset = document.cookie.indexOf(search);if(offset!=-1){offset+=search.length;end=document.cookie.indexOf(";", offset);if (end == -1){end = document.cookie.length;}cookieValue = unescape(document.cookie.substring(offset, end))}}return cookieValue;}
function _wCK(name, value, hours){var expire='';if(hours!=null){expire = new Date((new Date()).getTime() + hours * 3600000);expire = "; expires=" + expire.toGMTString();}document.cookie = name + "=" + escape(value) + expire;}
/*auto skip*/
function _autoSkip(from,to,size){
	return _addEvent(from,'onkeyup',"(this.value.length >= "+ size +")?_gel('"+ to +"').focus():true;");
}
/*add event*/
function _addEvent(o,e,s){
	if(typeof o == 'string'){o = _gel(o)}
	var x = (o[e]) ? o[e].toString() : "";
	x = x.substring(x.indexOf("{")+1, x.lastIndexOf("}"));
	x = (x + s) + "\n";
	return o[e] = (!!window.Event) ? new Function(e, x) : new Function(x);	
}
/*get page properties*/
function _gpp(){
	 var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (_geltn('body')[0].scrollHeight > _geltn('body')[0].offsetHeight){ // all but Explorer Mac
		xScroll = _geltn('body')[0].scrollWidth;
		yScroll = _geltn('body')[0].scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = _geltn('body')[0].offsetWidth;
		yScroll = _geltn('body')[0].offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = _geltn('body')[0].clientWidth;
		windowHeight = _geltn('body')[0].clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}


/*htc Format*/
var hf = {
	numeric:function(a,c){
		if(isNaN(a)){return a}
		if(typeof(c) != 'object'){return a}
		if(c.decimalPlaces){a = parseFloat(a).toFixed(c.decimalPlaces)}
		if(c.useThousandSeparator){
			var n=-1, t='', ti=parseInt(a).toString();
			var d='.', s = ((c.thousandSeparator)?c.thousandSeparator:',');
			for(var i=ti.length;i>=0;i--){
				t = (((n%3) == 0 && n>0)?s:'') + t;
				t = ti.substring(i,i+1) + t;
				n++;
			}
			if(c.decimalSeparator){
				a = a.replace('.',c.decimalSeparator);
				d = c.decimalSeparator;
			}
			a = ((a.indexOf(d)==-1)?t:t+a.substring(a.indexOf(d),a.length));
		}
		if(c.decimalSeparator && !c.useThousandSeparator){a = a.replace('.',c.decimalSeparator)}
		if(c.currencyChar){a = c.currencyChar +''+ a}
		if(c.charAfter){a += ''+ c.charAfter}
		if(c.charBefore){a = c.charBefore +''+ a}
		
		return a;
	},
	text:function(a,c,i,f,rui,ruf){
		if(!i){i='['}
		if(!f){f=']'}
		if(!rui){rui='#'}
		if(!ruf){ruf='#'}

		var rem = a, campo = '';
		while((rem.indexOf(i) != -1) && (rem.indexOf(f) != -1)){
			campo = rem.substring(rem.indexOf(i)+1,rem.indexOf(f))
			if(c[campo] != undefined){
				rem = rem.replace(i+ campo +f,c[campo]);
			}else{
				rem = rem.replace(i+ campo +f,rui+campo+ruf);
			}
		}
		return rem;
	},
	date:function(a,c){ //
		return a;
	},
	string:{
		size:function(a,t,c,before){
			while(a.length < t){
				if(before){
					a += ''+ c;
				}else{
					a = c +''+ a;
				}
			}
			return a;
		},
		trim:function(s){
			var ts = '', p = false, u = 0, c = '';
			for (i = 0; i < s.length; i++){
				c = s.charAt(i);
				if(c == ' '){
					if(p){ts = ts + c}
				}else{
					ts = ts + c;u = i;p = true;
				}
			}	
			if(c == ' '){
				ts = ts.substring(0,(u-1));
			}
			return ts;
		},
		onlyNumbers:function(str){
			var txt = '';
			for(var i = 0;i < str.length;i++){
				var c = str.charAt(i);
				if( (c >= '0') && (c <= '9') ){
					txt = txt + '' + c;
				}
			}
			return txt;
		}		
	},
	json:{
		url:function(a){
			var ret = '', comma = '';
			if(typeof a == 'object'){
				for(b in a){
					ret += comma + b +'='+ escape(a[b]);
					comma = '&';
				}
			}
			return ret;
		},
		string:function(a,c){
			var ret = '', comma = '';
			if(typeof a == 'object'){
				for(b in a){
					ret += comma + ((c != undefined)?c:'') + b + ((typeof a[b] == 'object')?'={\n\t'+hf.json.string(a[b],((c != undefined)?c:'')+'\t')+ ((c != undefined)?c:'')+'\n}':'='+a[b]);
					comma = '\n';
				}
			}
			return ret;
		},
		toString:function(a){
			var ret = '{', comma = '', c, scomma = '';
			if(typeof a == 'object'){
				for(b in a){
					if(typeof a[b] == 'object'){
						if(a[b].length != undefined){
							ret += comma + b +':[';
								c = a[b];
								scomma = '';
								for(var i=0;i<c.length;i++){
									ret += scomma + hf.json.toString(c[i]);
									scomma = ',';
								}
							ret += ']';
						}else{
							ret += comma + b +':'+ hf.json.toString(a[b]);
						}
					}else if(typeof a[b] == 'function'){
						var f = a[b].toString();
						while(f.indexOf('\r\n') >= 0){
							f = f.replace('\r\n','');
						}
						while(f.indexOf('\n') >= 0){
							f = f.replace('\n','');
						}
						while(f.indexOf('\t') >= 0){
							f = f.replace('\t','');
						}
						ret += comma + b +':'+ f;
					}else{
						if(isNaN(a[b])){
							ret += comma + b +':\''+ escape(a[b].toString()) +'\'';
						}else{
							ret += comma + b +':'+ escape(a[b].toString()) +'';
						}
					}
					comma = ',';
				}
			}
			return ret + '}';
		}
	}
}

/*htc Context Menu Control*/
var cmc = {
	m:[],
	createAndGet:function(el,op,css){
		var d = _ce('div');
		d.className = css;
		d.style.display = 'none';
		d.identification = 'contextmenu';
		this.buildOptions(d,op);
		el['oncontextmenu'] = this._doCM;
		return d;
	},
	buildOptions:function(a,b){
		for(var i=0;i<b.length;i++){
			var c = _ce('div');
			c.className = b[i].classOut;
			c.title 	= b[i].alt;
			if(b[i].icon){
				var icon = _ce('div');
				var text = _ce('div');
				icon.className	= b[i].classIcon;
				icon.innerHTML 	= '<img src="'+ b[i].icon +'"/>';
				
				icon.className	= b[i].classIconText;
				text.innerHTML 	= b[i].text;
				
				c.appendChild(icon);
				c.appendChild(text);
			}else{
				c.style.width	= (b[i].textWidth + 5) + 'px';
				c.className = b[i].classOut;
				c.innerHTML = b[i].text;
			}
			var cmd = 'a.onclick = function(){'+ b[i].click +'}';
			eval(cmd);
			a.appendChild(c);
		}
	},
	create:function(el,op,css){
		if(typeof(el) == 'object' && typeof(op) == 'object'){
			try{
				var d = _ce('INPUT');
				d.type = 'text';
				//d.innerHTML = 'TESTE CONTEXT';
				//d.style.position = 'absolute';
				el.appendChild(d);
				//el.contextmenu = d;
				el['oncontextmenu'] = function(){
					//this.contextmenu.style.disply = 'block';
					return false;
				}
			}catch(e){
				status = 'cmc - '+ e;
			}
		}else{
			status = 'cmc - todos os elementos devem ser objetos';
		}
	},
	_doCM:function(e){
		if(isIE){e = event};
		var o = ((isIE)?e.srcElement:e.target);
		var txt = '';
		var flag = false;
		for(a in o){
			if(a == 'getElementById'){flag=true;}
			if(flag){
				txt += a +':'+ o[a] +'\n';
			}
		}
		//alert(txt);
		for(var i=0;i<this.childNodes.length;i++){
			if(this.childNodes[i].identification){
				if(this.childNodes[i].identification == 'contextmenu'){
					this.childNodes[i].style.display = 'block';
				}
			}
		}
		
		return false;
	}
}

/*********************************************************************************/
function _gopos(a){var p = {x:0,y:0};if (!document.layers){var onWindows = navigator.platform ? navigator.platform == "Win32" : false;var macIE45 = document.all && !onWindows && getExplorerVersion() == 4.5;var par = a, l = {x:0,y:0};while(par){if( par.leftMargin && ! onWindows ) p.x += parseInt(par.leftMargin);if( ((par.offsetLeft != l.x) && par.offsetLeft) ) p.x += parseInt(par.offsetLeft); if( par.offsetLeft != 0 ) l.x = par.offsetLeft;par = macIE45 ? par.parentElement : par.offsetParent;}var par = a;while(par){if( par.topMargin && ! onWindows )	p.y += parseInt(par.topMargin);if( ((par.offsetTop != l.x) && par.offsetTop) )	p.y += parseInt(par.offsetTop);	if( par.offsetTop != 0 ) l.y = par.offsetTop; par = macIE45 ? par.parentElement : par.offsetParent;}}else if(a.x && a.y){p.x += a.x;p.y += a.y;}return p;}


var drag_control={obj:null,lastMouseX:0,lastMouseY:0,
	start:function(a){
		obj = a;
		var a = drag_control.fixE(a), b = obj.parentNode;
		drag_control.lastMouseX = a.clientX;
		drag_control.lastMouseY = a.clientY;
		var p = _gopos(b);
		b.style.top = p.y + 'px';
		b.style.left = p.x + 'px';
		document.onmouseup	 = drag_control.end;
		document.onmousemove = drag_control.drag;
		document.onselectstart = function(){return false}
		return false
	},
	drag:function(a){
		var a = drag_control.fixE(a), b = obj.parentNode;
		if(a.which == 0){return drag_control.end()}
		var c = a.clientY, d = a.clientX;
		(!drag_control.lastMouseX)?drag_control.lastMouseX = d:null;
		(!drag_control.lastMouseY)?drag_control.lastMouseY = c:null;
		if(drag_control.lastMouseX == d && drag_control.lastMouseY == c){return false}
		var e = parseInt(b.style.top), f = parseInt(b.style.left),g,h;
		g = f + d - drag_control.lastMouseX;
		h = e + c - drag_control.lastMouseY;
		b.style.left 	= g + 'px';
		b.style.top		= h + 'px';
		drag_control.lastMouseX = d;
		drag_control.lastMouseY = c;
		return false
	},
	end:function(){var b = obj.parentNode;document.onmouseup = null;document.onmousemove = null;document.onselectstart = null;},
	fixE:function(a){if(typeof a == "undefined")a = window.event;if(typeof a.layerX == "undefined")a.layerX = a.offsetX;if(typeof a.layerY == "undefined")a.layerY = a.offsetY;if(typeof a.which == "undefined")a.which = a.button;return a}
};



var win_control = {
	cont:0,
	wins:new Array(),
	initWin:function(tipo,titulo,config,conteudo,largura,altura,options,position,distancia_left,distancia_top,dragable,window_name){
		a = tipo;		// (frame,conteudo)
		b = titulo;
		c = config;		//(close, size e/ou option)
		d = conteudo;	// ou url
		e = largura;
		f = altura;
		g = options;	// [{url:'',click:'',title:'',label:''},...]
		h = position;	// (center, top, default)
		i = distancia_left;
		j = distancia_top;
		k = dragable;	//true/false 
		l = window_name;
		
		if(!a){return false}
		if(!b){b='&nbsp;'}
		if(!e){e=200}
		if(!f){f=200}
		if(!h){h='top'}

		var win=document.createElement("DIV"), header=document.createElement("DIV"), content=document.createElement("DIV");
		win.className 	  = "htcPanel";
		header.className  = "htcPanelHeader";
		content.className = "htcPanelContent";

		if(_gel(l)){
			if(a=='frame'){
				_gel(l).childNodes[1].childNodes[0].src=d;
				_gel(l).childNodes[1].childNodes[0].height=(f);
			}
			_gel(l).style.display = 'block';
			return;
		}else{
			(l)?win.id=l:win.id = 'HPNL'+win_control.cont++;
			win.style.width=(a!='frame')?(e)+'px':(e+15)+'px';
		}
		
		if(h == 'center'){
			var sw=screen.width, sh=screen.height,dif=100;
			if(document.all){
				var st = _geltn('body')[0].scrollTop;
				win.style.left = ((sw/2)-(e/2))+'px';
				win.style.top = ((st+((sh/2)-(f/2)-dif))<0) ? (st+((sh/2)-(f/2)))+'px' : (st+((sh/2)-(f/2)-dif))+'px';
			}else{
				win.style.left = ((sw/2)-(e/2))+'px';
				win.style.top = (((sh/2)-(f/2)-dif)<0)?((sh/2)-(f/2))+'px':((sh/2)-(f/2)-dif)+'px';
			}
		}else{
			win.style.top = ((i)?i+'px':'5px');
			win.style.left = ((j)?j+'px':'5px');
		}
		win.style.zIndex = 150 + win_control.cont;
		win.appendChild(header);
		win.appendChild(content);
		win.close = function(){
			this.closing = true;
			if(this.onBeforeClose){this.onBeforeClose(this)}
			if(this.closing){
				this.style.display = 'none';
				win_control.enableWin();
			}
			if(this.onClose){this.onClose(this)}
		};
		win.show = function(){
			this.showing = true;
			if(this.onBeforeShow){this.onBeforeShow(this)}
			if(this.showing){
				this.style.display = 'block';
				win_control.disableWin();
			}
			if(this.onShow){this.onShow(this)}
		};
		
		var title=document.createElement("DIV"), option=document.createElement("DIV");
		title.className = 'htcPanelTitle';
		title.innerHTML = b;

		option.className = 'htcPanelOptions';
		if(c){
			c = c.split(',');
			for(var i = 0;i < c.length;i++){
				switch(c[i]){
					case 'size':
						option.innerHTML += '<div class="htcPanelButton"><a href="javascript:void(0);" onclick="win_control.sizeWin(\''+ win.id +'\')">_</a></div>';
						break;
					case 'close':
						option.innerHTML += '<div class="htcPanelButton"><a href="javascript:void(0);" onclick="win_control.closeWin(\''+ win.id +'\')">X</a></div>';
						break;
					case 'option':
						if(g)
							option.innerHTML += '<div class="htcPanelButton"><a href="javascript:void(0);" onclick="win_control.optionWin(this,\''+ win.id +'\')">V</a></div>';
						break;
				}
			}
		}
		content.id	= "cnt"+ win.id;
		(a!='frame')?content.innerHTML=d:content.innerHTML='<iframe id="frame'+ win.id +'" style="width:99.9%;" height="'+ (f) +'" src="'+ d +'" scrolling="auto" frameborder="0" marginheight="0" marginwidth="0" allowtransparency="no"></iframe>';
		
		content.style.height = (f) + 'px';

		header.appendChild(title);
		header.appendChild(option);
		if(k){
			header.onmousedown = function(){
				if(_gel(this.parentNode.id+'_MNU')!=null){_gel(this.parentNode.id+'_MNU').style.display='none'};
				drag_control.start(this)
			}
		}

		this.wins.push({win:win,opt:g})
		this.makeDisable();
				
		_geltn('BODY')[0].appendChild(win);
		
		return win;
	},
	makeDisable:function(){
		if(!this.dp){
			this.dp = _ce('DIV');
			this.dp.id = 'htcAllDisabled';
			var ps = _gpp();
			this.dp.style.height = ps[1] + 'px';
			this.dp.style.width = ps[0] + 'px';
			_geltn('DIV')[0].appendChild(this.dp);
		}
	},
	disableWin:function(){
		if(isIE){
			for(var i= 0;i<document.frames.length;i++){
				var e = document.frames[i].document.getElementsByTagName('SELECT');
				for(var j=0;j<e.length;j++){e[j].style.visibility='hidden'};
			}
			var e = _geltn('SELECT');
			for(var i=0;i<e.length;i++){e[i].style.visibility='hidden'};
		}
		var ps = _gpp();
		if(this.dp == undefined){
			this.makeDisable();
		}
		this.dp.style.height = ps[1] + 'px';
		this.dp.style.width = ps[0] + 'px';
		this.dp.style.display = 'block';
	},
	enableWin:function(){
		if(isIE){
			for(var i= 0;i<document.frames.length;i++){
				var e = document.frames[i].document.getElementsByTagName('SELECT');
				for(var j=0;j<e.length;j++){e[j].style.visibility='visible'};
			}
			var e = _geltn('SELECT');
			for(var i=0;i<e.length;i++){e[i].style.visibility='visible'};
		}
		if(this.dp == undefined){
			this.makeDisable();
		}
		this.dp.style.display = 'none';
	},
	closeWin:function(obj){
		if(obj != 'all'){
			_gel(obj).style.display = 'none';
			var f = true;
			for(var i=0;i<win_control.wins.length;i++){if(_gel(win_control.wins[i].win.id).style.display != 'none'){f = false}}
			if(f){this.enableWin()}
		}else{
			for(var i=0;i<win_control.wins.length;i++){_gel(win_control.wins[i].win.id).style.display = 'none'}
		}
	},
	openWin:function(obj){
		if(obj != 'all'){
			_gel(obj).style.display = '';
			var f = true;
			for(var i=0;i<win_control.wins.length;i++){if(_gel(win_control.wins[i].win.id).style.display != ''){f = false}}
			if(f){this.enableWin()}
		}else{
			for(var i=0;i<win_control.wins.length;i++){_gel(win_control.wins[i].win.id).style.display = ''}
		}
	},	
	sizeWin:function(obj){
		if(_gel(obj).childNodes[1].style.display == 'none')
			_gel(obj).childNodes[1].style.display = 'block';
		else
			_gel(obj).childNodes[1].style.display = 'none';
	},
	resizeWin:function(obj,w,h,center){
		var win = _gel(obj);
		if(win != null){
			win.style.width = w +'px';
			win.style.height = h +'px';
			if(center){
				var sw=screen.width, sh=screen.height,dif=150,e=w,f=h;
				if(document.all){
					var st = _geltn('body')[0].scrollTop;
					win.style.left = ((sw/2)-(h/2))+'px';
					win.style.top = ((st+((sh/2)-(w/2)-dif))<0) ? (st+((sh/2)-(w/2)))+'px' : (st+((sh/2)-(w/2)-dif))+'px';
				}else{
					win.style.left = ((sw/2)-(h/2))+'px';
					win.style.top = (((sh/2)-(w/2)-dif)<0)?((sh/2)-(w/2))+'px':((sh/2)-(w/2)-dif)+'px';
				}
			}
		}
	},
	optionWin:function(btn,obj){
		if(win_control.wins.length == 0){return false}
		var opt = null,title,click,url;
		for(var i=0;i<win_control.wins.length;i++){if(win_control.wins[i].win.id==obj&&win_control.wins[i].opt){opt=win_control.wins[i].opt}}
		if(opt != null){
			if(_gel(obj+'_MNU') != null){
				var menu=_gel(obj+'_MNU'), p=_gopos(btn);
				menu.style.left = p.x + 'px';
				menu.style.top = p.y + 'px';
				menu.style.display = 'block';
			}else{
				var menu=document.createElement("DIV")
				menu.id=obj+'_MNU'
				menu.className='htcPanelMenu';
				var content='<table>'
				for(var i=0;i<opt.length;i++){
					(opt[i].url)?url=opt[i].url:url='javascript:void(0);';
					(opt[i].click)?click='onclick="'+ opt[i].click +'"':click='';
					(opt[i].title)?title='title="'+ opt[i].title +'"':title='';
					content+='<tr><td class="htcPanelMenuItem"><a href="'+ url +'" '+ click +' '+ title +'>'+ opt[i].label +'</a></td></tr>';
				}
				menu.innerHTML=content+'</table>';
				var p = _gopos(btn);
				menu.style.left = (p.x) + 'px';
				menu.style.top = (p.y) + 'px';
				menu.style.zIndex = _gel(obj).style.zIndex + 200;
				menu.onmouseout = function(){
					this.tmr = setTimeout('_gel(\''+ this.id +'\').style.display =\'none\'',1000);
				}
				menu.onmouseover = function(){
					clearTimeout(this.tmr);
				}
				_geltn('body')[0].appendChild(menu);
			}
		}
	}
};

/*================================================================================================*/

var layoutc = {
	lays:[],
	create:function(n){
		var l = {id:n,html:'',object:null,url:'',params:''};
		l.getFromFile = this._getFromFile;
		l.transform = this._transform;
		l.onLayoutLoaded = this._layload;
		l.onLoad = null;
		l.get = _get;
		
		this.lays.push(l);
		return l;
	},
	_getFromFile:function(f,p,pr){
		this.url = f;
		this.params = pr;
		this.get(this.url, {ctrl:this, method:((p)?'post':'get'), params:this.params, onLoad:this.onLayoutLoaded, onError:function(a){alert(a.obj.responseText)}});
	},
	_layload:function(o){
		o.ctrl.html = o.req;
		if(o.ctrl.object){
			o.ctrl.transform();	
		}else if(typeof o.ctrl.onLoad == 'function'){
			o.ctrl.onLoad();
		}
	},
	_transform:function(){
		if(typeof this.object == 'object'){
			this.html = hf.text(this.html,this.object);
			if(typeof this.onLoad == 'function'){
				this.onLoad();
			}
		}else{
			alert('layout \''+ this.id +'\' object error');
		}
	}
};

//================================================================================================================
var htcTipoAviso = {warn:0,alert:1,confirm:2,success:3};
var htcIconAviso = {warn:'pictures/icon/ic_warn.gif',alert:'pictures/icon/ic_alert.gif',confirm:'pictures/icon/ic_confirm.gif',success:'pictures/icon/ic_success.gif'};
var htcAviso = {
	tmr:null,
	fadeIn:true,
	fadeOut:true,
	fadeStep:10,
	fadeInterval:50,
	autoHideTime:5000,
	autoHide:true,
	mensagem:'',
	target:null,
	objeto:document.createElement('DIV'),
	tipo:htcTipoAviso.warn,
	icon:null,
	show_icon:true,
	sim_label:null,
	nao_label:null,
	sim_action:null,
	nao_action:null,
	show:function(men, type, target, icon, sim_label, nao_label, sim_action, nao_action){
		this.close();
		this.mensagem = men;
		this.tipo = type;
		this.target = target;
		if(icon){
			this.show_icon = true;
			this.icon = icon;
		}else{
			this.show_icon = false;
		}
		
		this.sim_label = sim_label;
		this.nao_label = nao_label;
		this.sim_action = sim_action;
		this.nao_action = nao_action;
		
		//validação
		this.buildAviso();
	},
	buildAviso:function(){
		var txt = '';
		
		if(this.icon)
			txt += '<table><tr><td><img src="'+ this.icon +'"></td><td>';
		
		txt += '<strong>';
		txt += this.mensagem + ' ';

		this.objeto.style.textAlign = 'center';
		
		switch(this.tipo){
			case 0://warn
				txt += '</strong>';
				this.objeto.style.borderWidth = '1px';
				this.objeto.style.borderStyle = 'solid';
				this.objeto.style.borderColor = '#CC0000';
				this.objeto.style.backgroundColor = '#F4DDE0';
				break;
			case 1://alert
				txt += '</strong>';
				this.objeto.style.borderWidth = '1px';
				this.objeto.style.borderStyle = 'solid';
				this.objeto.style.borderColor = '#FFCC00';
				this.objeto.style.backgroundColor = '#F7F5DF';
				break;
			case 2://confirm
				txt += '<a href="javascript:void(0);" onclick="'+ ((this.sim_action)?this.sim_action+',':'') +'htcAviso.close();" style="color:#CC0000;">'+ this.sim_label +'</a>';
				txt += ' | ';
				txt += '<a href="javascript:void(0);" onclick="'+ ((this.nao_action)?this.nao_action+',':'') +'htcAviso.close();" style="color:#CC0000;">'+ this.nao_label +'</a>';
				txt += '</strong>';
				this.objeto.style.borderWidth = '1px';
				this.objeto.style.borderStyle = 'solid';
				this.objeto.style.borderColor = '#CC0000';
				this.objeto.style.backgroundColor = '#F4DDE0';
				break;
			case 3://success
				txt += '</strong>';
				this.objeto.style.borderWidth = '1px';
				this.objeto.style.borderStyle = 'solid';
				this.objeto.style.borderColor = '#009999';
				this.objeto.style.backgroundColor = '#DFF5D8';
				break;
		}
		
		if(this.icon)
			txt += '</td></tr></table>';

		this.objeto.innerHTML = txt;

		if(this.fadeOut)
			this.fadeout(0);
			
		this.target.appendChild(this.objeto);
		this.target.style.display = '';

		if(this.tmr)
			clearTimeout(this.tmr);
			
		if(this.autoHide)
			this.tmr = setTimeout( ((this.fadeIn)?'htcAviso.fadein(100)':'htcAviso.close()') ,this.autoHideTime);
		
	},
	fadeout:function(i){
		if(i >= 100){
			(IE)?this.target.style.filter = 'Alpha(Opacity=100)':this.target.style.opacity = 100;
		}else{
			(IE)?this.target.style.filter = 'Alpha(Opacity='+ i +')':this.target.style.opacity = ((i>0)?(i/100):0);
			setTimeout('htcAviso.fadeout('+ (i+this.fadeStep) +')',this.fadeInterval);
		}
	},
	fadein:function(i){
		if(!this.fadeIn)
			this.close();
	
		if(i <= 0){
			(IE)?this.target.style.filter = 'Alpha(Opacity=0)':this.target.style.opacity = 0;
			this.close();
		}else{
			(IE)?this.target.style.filter = 'Alpha(Opacity='+ i +')':this.target.style.opacity = (i/100);
			setTimeout('htcAviso.fadein('+ (i-this.fadeStep) +')',this.fadeInterval);
		}
	},
	close:function(){
		if(this.target){
			this.target.innerHTML = '';
			this.target.style.display = 'none';
		}
	}
};

//==============================================================================================================

var cmbc = {
	cmb:[],
	create:function(config){
		var c = {desc:null};
		for(a in _cmbc){
			c[a] = _cmbc[a];
		}
		for(a in config){
			c[a] = config[a];
		}
		this.cmb.push(c);
		return c;
	}
};

var _cmbc = {
	target:null,
	selected:null,
	waitMessage:false,
	waitMessageText:'aguarde...',
	url:'/lib/inc_geral.asp',
	json:null,
	onError:null,
	onLoad:null,
	fillCombo:function(){
		if(this.checkCombo()){
			if(this.cleanBefore){this.cleanCombo();}
			if(this.json){
				if(this.json[0].erro){
					this.cleanCombo();
					this.addOptionCombo(this.json[0].men,0,0);
					if(this.onError){this.onError(this.target,this);}
					return false;
				}else{
					for(var i = 1;i < this.json.length;i++){
						this.addOptionCombo(this.json[i].label,this.json[i].value);
					}
					if(this.remLoading){this.remOptionCombo(0);}
					if(this.onLoad){this.onLoad(this.target,this);}
					return true;
				}
			}
		}
		return null;
	},
	cleanCombo:function(target){
		if(target){
			for(var i = target.options.length;i >= 0;i--){
				target.remove(i);
			}
			return true;			
		}else{
			if(this.checkCombo()){
				for(var i = this.target.options.length;i >= 0;i--){
					this.target.remove(i);
				}
				return true;
			}
		}
		return null;
	},
	addOptionCombo:function(men,valor,ix,forecolor,bgcolor){
		var elem = document.createElement('OPTION');
		elem.text = men;
		elem.value = valor;
		if(forecolor){elem.style.color = forecolor;}
		if(bgcolor){elem.style.backgroundColor = bgcolor;}
		try{
			if(ix){
				this.target.add(elem,ix);
			}else{
				this.target.add(elem);
			}
		}catch(e){
			try{
				this.target.add(elem,null);
			}catch(e1){
				status = 'cmbCtrl - Erro(1)';
			}
		}
	},
	remOptionCombo:function(ix){
		this.target.remove(ix);
	},
	checkCombo:function(){
		if(this.target){
			if(this.target.tagName == 'SELECT'){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	},
	load:function(a){
		if(a){
			a.ctrl.json = a.req;
			a.ctrl.fillCombo();
		}else{
			if(this.waitMessage){
				this.cleanCombo();
				this.addOptionCombo(this.waitMessageText,0);
				this.cleanBefore = true;
			}
			_get(this.url, {ctrl:this, type:'json', method:'post', params:'acao='+ ((this.acao == undefined)?'1':this.acao) +'&cmb=true&cod='+ this.cod + ((this.params)?'&params='+this.params:'') + ((this.tipo)?'&tipo='+this.tipo:'') + ((this.lingua)?'&lng='+this.lingua:''), onLoad:this.load});
		}
	}
};

//==============================================================================================================
//validador
//==============================================================================================================
var fvct = {none:0,email:1,notnull:2,numeric:3,decimal:4,date:5,hora:6,range:7,cpf:8,cnpj:9,datefract:11,creditcard:12};
var fvcft = {unknow:0,input:1,combo:2,combomulti:3,textarea:4,radio:5,checkbox:6,file:7,button:8};
var fvc = {
	form:[],
	create:function(config){
		var fv = config;
		fv.ix = this.form.length;
		fv.itens = [];
		fv.autoType = true;
		fv.men = '';
		fv.params = '';
		fv.add = this._add;
		fv.valid = this._valid;
		fv.search = this._find;
		fv.getParams = this._getForm;
		fv.hl = this._highlightLabel;
		fv.hf = this._highlightField;
		fv.fieldClassErro = '';
		fv.fieldClassOK = '';
		fv.labelClassErro = '';
		fv.labelClassOK = '';
		fv.comboNullValue = 0;
		
		fv.hint = _ce('DIV');
		fv.hint.className = config.hintClass;
		fv.hint.id = 'fvHint'+this.form.length;
		_geltn('BODY')[0].appendChild(fv.hint);
		
		this.form.push(fv);
		return fv;
	},
	_add:function(c){
		if(c.type >= 0 && c.type <= 10){
			if(typeof c.field == 'string'){c.field = _geln(c.field)[0]}
			switch(c.field.tagName.toLowerCase()){
				case 'input':
					switch(c.field.type.toLowerCase()){
						case 'text':
						case 'password':
						case 'file':
						case 'hidden':
							c.ftype = fvcft.input;
							break;
						case 'radio':
							c.ftype = fvcft.radio;
							if(this.autoType){
								c.type  = fvct.notnull;
							}
							break;
						case 'checkbox':
							c.ftype = fvcft.checkbox;
							if(this.autoType){
								c.type = fvct.range;
							}
							break;
						case 'button':
						case 'submit':
						case 'reset':
						case 'image':
							c.ftype = fvcft.button;
							break;
						default:
							c.ftype = fvcft.unknow;
							break;
					}
					break;
				case 'textarea':
					c.ftype = fvcft.textarea;
					break;
				case 'select':
					if(c.field.multiple){
						c.ftype = fvcft.combomulti;
						if(this.autoType){
							c.type  = fvct.range;
						}
					}else{
						c.ftype = fvcft.combo;
						if(this.autoType){
							c.type  = fvct.notnull;
						}
					}
					break;
				default:
					c.ftype = fvcft.unknow;
					break;
			}
			
			if(c.ftype != fvcft.unknow){
				c.ctrl = this;
				if(c.hint != undefined){
					c.field.title = c.hint;
					_addEvent(c.field,'onfocus',"fvc.ctrlHint(this,"+ this.ix +",'block');");
					_addEvent(c.field,'onblur',"fvc.ctrlHint(this,"+ this.ix +",'none');");
				}
			}
			if(!this.search(c.field,true)){
				this.itens.push(c);
			}
		}else{
			this.itens.push(c);
		}
	},
	_find:function(f,a){
		for(var i=0;i<this.itens.length;i++){
			if(this.itens[i].type >= 0 && this.itens[i].type <= 10){
				if(this.itens[i].field.name == f.name){
					return (a) ? this.itens[i] : true ;
				}
			}
		}
		return (a) ? null : false ;
	},
	_valid:function(){
		var ok = true, f = null, conc = '&';
		this.men = '';
		this.params = 'formID='+ escape(this.id);
		for(var i=0;i<this.itens.length;i++){
			f = this.itens[i];
			ignore = false;
			if(typeof f.onValidating == 'function'){
				ignore = !f.onValidating(f);
			}
			if(!ignore){
				switch(f.type){
					case fvct.email:
						if(fvc.isEMail(f.field.value) || (f.onlyIsNotNull && hf.string.trim(f.field.value).length == 0)){
							if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
							if(this.fieldHighlight){this.hf(f.field,true)}
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){((f.label)?this.hl(f.label,false,true):this.hl(f.field,false,false))}
							if(this.fieldHighlight){this.hf(f.field,false)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						break;
					case fvct.notnull:
						var flag = false;
						switch(f.ftype){
							case fvcft.radio:
							case fvcft.checkbox:
								var fld = _geln(f.field.name);
								for(var j=0;j<fld.length;j++){
									if(fld[j].checked){
										flag=true;
										this.params += conc + ((f.pname)?f.pname:f.field.name) +'='+ escape(fld[j].value);
									}
								}
								break;
							case fvcft.combo:
								valor = ((isNaN(f.field.value))?f.field.value:parseInt(f.field.value));
								flag = ((valor != this.comboNullValue)?true:false);
								this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
								break;
							default:
								flag = ((hf.string.trim(f.field.value).length > 0)?true:false);
								flag = ((f.maxSize)?(hf.string.trim(f.field.value).length <= f.maxSize):flag);
								flag = ((f.minSize)?(hf.string.trim(f.field.value).length >= f.minSize):flag);
								this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);								
								break;
						}
	
						if(this.labelHighlight){((f.label)?this.hl(f.label,flag,true):this.hl(f.field,flag,false))}
						if(this.fieldHighlight && f.ftype != fvcft.radio){this.hf(f.field,flag)}
						ok = ((ok && flag)?true:false);
						break;
					case fvct.numeric:
					case fvct.decimal:
						if( ( !isNaN(hf.string.trim(f.field.value)) && hf.string.trim(f.field.value).length > 0 ) || (f.onlyIsNotNull && hf.string.trim(f.field.value).length == 0) ){
							if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
							if(this.fieldHighlight){this.hf(f.field,true)}
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){((f.label)?this.hl(f.label,false,true):this.hl(f.field,false,false))}
							if(this.fieldHighlight){this.hf(f.field,false)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						break;
					case fvct.date:
						if(fvc.isDate(f.field.value) || (f.onlyIsNotNull && hf.string.trim(f.field.value).length == 0)){
							if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
							if(this.fieldHighlight){this.hf(f.field,true)}
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){((f.label)?this.hl(f.label,false,true):this.hl(f.field,false,false))}
							if(this.fieldHighlight){this.hf(f.field,false)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						break;
					case fvct.range:
						//TODO
						break;
					case fvct.cpf:
						if(fvc.isCPF(f.field.value) || (f.onlyIsNotNull && hf.string.trim(f.field.value).length == 0)){
							if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
							if(this.fieldHighlight){this.hf(f.field,true)}
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){((f.label)?this.hl(f.label,false,true):this.hl(f.field,false,false))}
							if(this.fieldHighlight){this.hf(f.field,false)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						break;
					case fvct.cnpj:
						if(fvc.isCNPJ(f.field.value) || (f.onlyIsNotNull && hf.string.trim(f.field.value).length == 0)){
							if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
							if(this.fieldHighlight){this.hf(f.field,true)}						
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){((f.label)?this.hl(f.label,false,true):this.hl(f.field,false,false))}
							if(this.fieldHighlight){this.hf(f.field,false)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						break;
					case fvct.datefract:
						var data = '', datac = '';
						if(f.day != undefined && f.month != undefined && f.year != undefined && f.hour != undefined && f.minute != undefined){
							datac = hf.string.trim(f.day.value) +''+ hf.string.trim(f.month.value) +''+ hf.string.trim(f.year.value) +''+ hf.string.trim(f.hour.value) +''+ hf.string.trim(f.minute.value);
							data = hf.string.size(f.day.value,2,'0',true) +'/'+ hf.string.size(f.month.value,2,'0',true) +'/'+ hf.string.size(f.year.value,4,'0',true)+' '+((f.hour.value.length==0 || isNaN(f.hour.value))?'24':hf.string.size(f.hour.value,2,'0',true)) +':'+ ((f.minute.value.length==0 || isNaN(f.minute.value))?'60':hf.string.size(f.minute.value,2,'0',true));
						}else if(f.day != undefined && f.month != undefined && f.year != undefined){
							datac = hf.string.trim(f.day.value) +''+ hf.string.trim(f.month.value) +''+ hf.string.trim(f.year.value);
							data = hf.string.size(f.day.value,2,'0',true) +'/'+ hf.string.size(f.month.value,2,'0',true) +'/'+ hf.string.size(f.year.value,4,'0',true)+' 00:00';
						}else if(f.hour != undefined && f.minute != undefined){
							datac = hf.string.trim(f.hour.value) +''+ hf.string.trim(f.minute.value);
							data = '01/01/2009 '+((f.hour.value.length==0 || isNaN(f.hour.value))?'24':hf.string.size(f.hour.value,2,'0',true)) +':'+ ((f.minute.value.length==0 || isNaN(f.minute.value))?'60':hf.string.size(f.minute.value,2,'0',true));
						}
						if(fvc.isDate(data) || (f.onlyIsNotNull && datac.length == 0)){
							if(this.labelHighlight){this.hl(f.label,true,true)}
							ok = ((ok)?true:false);
						}else{
							if(this.labelHighlight){this.hl(f.label,false,true)}
							ok = false;
						}
						this.params += conc + ((f.pname)?f.pname:'data') +'='+ escape(data);
						break;
					case fvct.creditcard:
						this.params += '&cc_tipo='+f.tipo;
						this.params += '&cc_nome='+escape(f.nome);
						this.params += '&cc_numero='+f.numero;
						if(f.cod_ilegivel){
							this.params += '&cc_codigo=ILEGIVEL';
							f.cod = null;
						}else{
							this.params += '&cc_codigo='+f.cod;
						}
						this.params += '&cc_val_mes='+f.mes;
						this.params += '&cc_val_ano='+f.ano;
						this.ccMen = fvc.isCC(f.tipo,f.nome,f.numero,f.cod,f.ano,f.mes);
						ok = ((this.ccMen == 'ok')?true:false);
						break;
					case fvct.none:
						switch(f.ftype){
							case fvcft.radio:
							case fvcft.checkbox:
								var fld = _geln(f.field.name);
								for(var j=0;j<fld.length;j++){
									if(fld[j].checked){
										this.params += conc + ((f.pname)?f.pname:f.field.name) +'='+ escape(fld[j].value);
									}
								}
								break;
							case fvcft.combomulti:
								for(var j=0;j<f.field.options.length;j++){
									if(f.field.options[j].selected){
										this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.options[j].value);
									}
								}
								break;
							default:
								this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
						}
						break;
				}
			}else{
				if(this.labelHighlight){((f.label)?this.hl(f.label,true,true):this.hl(f.field,true,false))}
				if(this.fieldHighlight){this.hf(f.field,true)}						
				ok = ((ok)?true:false);
				if(f.ftype == fvcft.input || f.ftype == fvcft.combo || f.ftype == fvcft.textarea || f.ftype == fvcft.file || f.ftype == fvcft.button){
					this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(f.field.value);
				}else if(f.ftype == fvcft.radio || f.ftype == fvcft.checkbox){
					var fld = _geln(f.field.id);
					for(var j=0;j<fld.length;j++){
						if(fld[j].checked){
							flag=true;
							this.params += conc + ((f.pname)?f.pname:f.field.id) +'='+ escape(fld[j].value);
						}
					}
				}
			}
		}
		return ok;
	},
	_highlightField:function(o,b){
		if(o != undefined){
			o.className = ((b)?this.fieldClassOK:this.fieldClassERROR);
		}
	},
	_highlightLabel:function(o,b,l){
		if(l){
			o.className = ((b)?this.labelClassOK:this.labelClassERROR);
		}else{
			var id, node = o.parentNode;
			for(var c=0;c<3;c++){
				if(node.tagName == 'TD'){
					node = node.parentNode.childNodes[((isIE)?0:1)];
					c = 3;
				}else{
					node = node.parentNode;
				}
			}
			if(node.tagName == 'TD'){node.className = ((b)?this.labelClassOK:this.labelClassERROR)}
		}
	},
	isDate:function(s){

		var ret = true, lfev = 0;
		var d = s.substring(0,2);
		var m = s.substring(3,5);
		var a = s.substring(6,10);
		
		if(isNaN(d)){return false};
		if(isNaN(m)){return false};
		if(isNaN(a)){return false};
		
		var reh = /(([0-1][0-9])|(2[0-3])):[0-5][0-9]/;
		ret = reh.test(s.substring(11,16));
		
		d = Math.abs(d);
		m = Math.abs(m);
		a = Math.abs(a);
		
		if(ret){
			lfev = (((a%4) == 0 && (a%100) != 0 || (a%400) == 0)?29:28);

			switch(m){
				case 1:
				case 3:
				case 5:
				case 7:
				case 8:
				case 10:
				case 12: //31 dias
					ret = ((d > 31)?false:true);
					break;
				case 4:
				case 6:
				case 9:
				case 11: //30 dias
					ret = ((d > 30)?false:true);
					break;
				case 2: // fevereiro
					ret = ((d > lfev)?false:true);
					break;
				default :
					ret = false;
					break;
			}

		}
		
		return ret;
	},
	isEMail:function(s){
		s = hf.string.trim(s);
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		return filter.test(s);
	},
	isCPF:function(s){
		var i, txt = hf.string.onlyNumbers(s);
		var c = txt.substr(0,9), dv = txt.substr(9,2);
		var d1 = 0;
		for (i = 0; i < 9; i++){
			d1 += c.charAt(i)*(10-i);
		}
		if (d1 == 0) return false;
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){
			return false;
		}
		d1 *= 2;
		for (i = 0; i < 9; i++){
			d1 += c.charAt(i)*(11-i);
		}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1){
			return false;
		}
		return true;
	},
	isCNPJ:function(s){
		var i, txt = hf.string.onlyNumbers(s);
		if (txt.length > 14) {
			if (txt.substr(0,1) == 0){
				var c = txt.substr(1,12);
				var dv = txt.substr(13,2);
			}
			else{
				var c = txt.substr(0,12);
				var dv = txt.substr(12,2);
			}
		}
		else{
			var c = txt.substr(0,12);
			var dv = txt.substr(12,2);
		}
		var d1 = 0;
		if (txt.length < 14) {
			return false;
		}
		for (i = 0; i < 12; i++){
			d1 += c.charAt(11-i)*(2+(i % 8));
		}
		if (d1 == 0) return false;
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(0) != d1){
			return false;
		}
		d1 *= 2;
		for (i = 0; i < 12; i++){
			d1 += c.charAt(11-i)*(2+((i+1) % 8));
		}
		d1 = 11 - (d1 % 11);
		if (d1 > 9) d1 = 0;
		if (dv.charAt(1) != d1){
			return false;
		}
		return true;
	},
	isCC:function(tipo,nome,numero,cod,ano,mes){
		var allnumber = '',card1,card2,card3,card4,hoje = new Date(),anofull = 0;
		card1 = numero.substring(0,4);
		card2 = numero.substring(4,8);
		card3 = numero.substring(8,12);
		card4 = numero.substring(12,numero.length);			
		allnumber = card1 + '' +  card2 + '' +  card3 + '' +  card4;
		if(ano.substring(0,1) == '0'){ano = ano.substring(1,2)}
		if(mes.substring(0,1) == '0'){mes = mes.substring(1,2)}
		anofull = 2000 + parseInt(ano);
		if(hf.string.trim(nome).length == 0){return 'nome não preenchido';}
		if(isNaN(numero) || numero.length == 0){return 'numero não preenchido';}
		if(isNaN(hf.string.trim(ano)) || isNaN(hf.string.trim(mes)) || hf.string.trim(ano) == 0 || hf.string.trim(mes) == 0 ){return 'validade não preenchida';}
		if(cod != null){ if( !( (hf.string.trim(cod).length == 3 && tipo == 1|2|4) || (hf.string.trim(cod).length == 4 && tipo == 3) ) ){return 'código de segurança (inválido)';} }
		if(anofull < hoje.getFullYear()){
			return 'cartão expirado';
		}else if(parseInt(mes) < (hoje.getMonth()+1) && anofull <= hoje.getFullYear()){
			return 'cartão expirado';
		}
		

		if(tipo >= 1 && tipo <= 4){

			if(!fvc.isMod10(allnumber)){return 'numero inválido'};
			
			switch(tipo){
				case 1://Visa
					if(allnumber.length >= 13 && allnumber.length <= 16){
						ini = parseInt(card1)/1000;
						if( !(parseInt(ini) == 4) ){return 'numero inválido'};
					}else{
						return 'numero inválido';				
					}				
					break;
				case 2://Master
					if(allnumber.length == 16){
						ini = parseInt(card1)/100;
						if( !(parseInt(ini) >= 51 && parseInt(ini) <= 55) ){return 'numero inválido'};
					}else{
						return 'numero inválido';		
					}
					break;
				case 3://Amex
					if(allnumber.length == 15){
						ini = parseInt(card1)/100;
						if( !(parseInt(ini) == 34 || parseInt(ini) == 37) ){return 'numero inválido'};
					}else{
						return 'numero inválido';
					}				
					break;
				case 4://Diners
					if(allnumber.length == 14){
						ini = parseInt(card1)/10;
						ini2 = parseInt(card1)/100;	
						if( !( (parseInt(ini) >= 300 && parseInt(ini) <= 308) || parseInt(ini2) == 38 || parseInt(ini2) == 36 ) ){return 'numero inválido'};
					}else{
						return 'numero inválido';
					}								
					break;				
			}
		}
		return 'ok';
	},
	isMod10:function(valor){
		var ar = new Array( valor.length );
		var i = 0,sum = 0;
		
		for(i=0;i<valor.length;++i){
			ar[i] = parseInt(valor.charAt(i));
		}
		for(i=ar.length-2;i>=0;i-=2){
			ar[i] *= 2;
			if(ar[i] > 9) ar[i]-=9;
		}
		for(i=0;i<ar.length;++i){
			sum += ar[i];
		}
		return (((sum%10)==0)?true:false);
	},
	_getForm:function(a){
		if(a){
			this.valid();
		}
		return this.params;
	},
	ctrlHint:function(o,i,a){
		_inHTML(fvc.form[i].hint,((a=='none')?'&nbsp;':o.title));
		_mtop(fvc.form[i].hint,o,0,o.offsetHeight);
		fvc.form[i].hint.style.display = a;
	}
};

/*===========================================*/
