function newForm(act,mth,wnd){
	var frm = document.createElement("FORM");
	document.body.appendChild(frm);
	frm.action = act;
	frm.method = mth;
	if (typeof(wnd)!='undefined') { frm.target = wnd;} 
	return frm;
}

function newInput(id,value){
	var element = document.createElement("input");
	element.type="hidden";
	element.name=id;
	element.value = value;
	return element;
}

function chkLen(obj,len,info) {
	if (obj.value.length>len) {obj.value=obj.value.substring(0,len-1);} 
	if (document.getElementById(info)) { document.getElementById(info).innerHTML=obj.value.length;} 
}

function tagsShowHide(visible,tags) {
  visible = (visible?"block":"none");
  for (tag in tags) {if (document.getElementsByName(tags[tag])[0]) {document.getElementsByName(tags[tag])[0].parentNode.style.display=visible; } }
}

function popDiv(tp,w,h) { // tp 0 => DIV msgBox, tp 1 => IFRAME , tp 2 => DIV 

	if (document.getElementById('backDv')) { 
		document.getElementById('backDv').style.display='block';
		oBackDv=document.getElementById('backDv');
	} else { 
		var oBackDv = document.createElement('div');
		oBackDv.id='backDv';
		oBackDv.style.cssText='position:absolute;top:0px;left:0px;width:'+(document.body.clientWidth)+'px;height:'+(document.body.clientHeight)+'px;background-color:#000000;opacity:0.2;filter:alpha(opacity=20);z-index:98;overflow:hidden;';
		/*window.parent.*/ document.body.appendChild(oBackDv);
	}	
	if (!/^[0-9\.]*(%|px| )$/.test(w)) {w='90%';}
	if (!/^[0-9\.]*(%|px| )$/.test(h)) {h='90%';}
	if (/^[0-9]*%$/.test(w)) {l=Math.round((100-parseFloat(w))/2)+'%';} else {l=((oBackDv.clientWidth-parseInt(w))/2)+'px';}
	if (/^[0-9]*%$/.test(h)) {t=Math.round((100-parseFloat(h))/2)+'%';} else {t=((oBackDv.clientHeight-parseInt(h))/2)+'px';}

	if (document.getElementById('frontDv')) {
		document.getElementById('frontDv').style.display='block';
		oFrontDv=document.getElementById('frontDv');
		oFrontDv.style.top=t; oFrontDv.style.left=l; oFrontDv.style.width=w; oFrontDv.style.height=h;
	} else {
		var oFrontDv = document.createElement('div');	
		oFrontDv.id='frontDv';
		oFrontDv.style.cssText='font: 11px/11px arial;color:#FFFFFF;position:absolute;text-align:justify;z-index:99;background-color:transparent;overflow:hidden;top:'+t+';left:'+l+';width:'+w+';height:'+h;
		/*window.parent.*/ document.body.appendChild(oFrontDv);	
	}	

	var cssText='width:100%;height:100%;border:0px none;background-color:transparent;z-index:100; border:1px solid transparent;display:block;';
	//var cssText='width:'+w+';height:'+h+';border:0px none;background-color:transparent;z-index:100; border:1px solid transparent;';
	if (tp==1) {
		if (document.getElementById('popIfrm')) {
			document.getElementById('popIfrm').style.display='block';
		} else {
			if (oFrontDv.outerHTML) {
				oFrontDv.innerHTML+='<iframe id="popIfrm" name="popIfrm" frameborder="0px" AllowTransparency style="'+cssText+'"></iframe>';
				oTag=oFrontDv.childNodes[1];
			} else {
				var oTag=document.createElement('IFRAME');
				oTag.id='popIfrm';oTag.name='popIfrm';oTag.frameBorder='0px';oTag.style.cssText=cssText;
				oFrontDv.appendChild(oTag);
			}
		}
	} else {
		if (document.getElementById('popDiv')) {
//			document.getElementById('popDiv').style.display='block';
//			document.getElementById('popDiv').style.backgroundColor='transparent';
			document.getElementById('popDiv').style.cssText=cssText;
			oTag=document.getElementById('popDiv');
		} else {
			oFrontDv.innerHTML = '<a id="_close" href="javascript:void(0);" onclick="dropPopDiv();" style="position:absolute;top:12px;right:12px;z-index:150;">cerrar</a>';
			var oTag = document.createElement('div');	
			oTag.id='popDiv';oTag.name='popDiv';oTag.style.cssText=cssText;
			oFrontDv.appendChild(oTag);
//			if (tp==0) {
//				oTag.innerHTML = '<div id="_title" style="font-size:15px;font-weight:bold;margin-top:15px;margin-left:15px;margin-right:70px;margin-bottom:15px;"></div>';
//				oTag.innerHTML+= '<div style="background: url(img/sepMsg.png) no-repeat center;height:4px;"></div>';
//				oTag.innerHTML+= '<div id="_text" style="margin-top:16px;margin-left:20px;margin-right:20px;margin-bottom:10px;"></div>';
//			}		
		}
	}

	var oJs = document.createElement('script');
	oJs.type = 'text/javascript';
	oJs.src = 'js/lib.js';
	/*window.parent.*/document.getElementsByTagName('head')[0].appendChild(oJs);
	return oTag;
}

function dropPopDiv() {
	if (document.getElementById('backDv')) {document.getElementById('backDv').style.display='none';}
	if (document.getElementById('frontDv')) {document.getElementById('frontDv').style.display='none';}
	//if (document.getElementById('popIfrm')) {document.getElementById('popIfrm').style.display='none';}
	if (document.getElementById('popDiv')) {document.getElementById('popDiv').style.display='none';}
	if (window.parent.document.getElementById('backDv')) {window.parent.document.getElementById('backDv').style.display='none';}
	if (window.parent.document.getElementById('frontDv')) {window.parent.document.getElementById('frontDv').style.display='none';}
	if (window.parent.document.getElementById('popIfrm')) {window.parent.document.getElementById('popIfrm').style.display='none';window.parent.document.getElementById('popIfrm').src='';}
	//if (window.parent.document.getElementById('popDiv')) {window.parent.document.getElementById('popDiv').style.display='none';}

}

function requestUrl(url){
	requestUrlWnd(url,'');
}

function requestUrlWnd(url,wnd) {
	if (wnd=='') {wnd='popupWnd';}
	window.open(url,wnd,"width=1024,height=768,left=0,top=0,screenX=0,screenY=0,scrollbars=yes, location=no");
}

function requestUrlIfrm(url) {
	var oTag=popDiv(1,'80%','80%');
	window.open(url,oTag.name);
}
			
function numCheckeds(chks) {
	var num=0;
	for (chk in chks) {if (document.getElementById(chks[chk]).checked) {num++;}}
	return num;
}

function xajaxCall() {
	var _xajax = new Xajax();
	var back_xajaxRequestUri=xajaxRequestUri;
	xajaxRequestUri=_site+arguments[0];
	var args = new Array();
	for (var i=2;i<arguments.length;i++) {args[i-2]=arguments[i];}
	_xajax.call(arguments[1],args,1);
	xajaxRequestUri=back_xajaxRequestUri;	
}
