// JavaScript Document

var d = document;
var n = navigator;
var scren = screen;

var path_directory;
var path_cd;

var iexplorer = n.appName == 'Microsoft Internet Explorer';
var opera = n.appName.indexOf('Opera') == 0 ? true : false;
var firefox = !iexplorer && !opera ? true : false;

function get_request(src){ var src;
	var oScript = document.createElement("script");
	oScript.src = src+"&rand="+(Math.random()*1.64)+"";
	document.body.appendChild(oScript);
}

function get_nodo( element ){

	if( !d.getElementById(element) ){ return false;}return d.getElementById(element);
	
}

function get_nodname( element ){
	
	if( !d.getElementsByName(element) ){ return false;} return d.getElementsByName(element);
	
}

function get_tagname( element ){
		
	if( !d.getElementsByTagName(element) ){ return false; } return d.getElementsByTagName(element);
}

function get_position( layer ){
	
	var layer = typeof( layer )	 == 'object' ? layer : get_nodo(layer);
	position = {Left: layer.offsetLeft, Top: layer.offsetTop};
	return position;
}

//; no es lo mismo display que visibility;
function get_display(layer, action){
	var layer = typeof(layer) == 'object' ? layer : get_nodo(layer);
	layer.style.display = action == true ? 'block' : 'none';
}

function get_visible(layer, action){
	var layer = typeof(layer) == 'object' ? layer : get_nodo(layer);
	layer.style.visibility = action == true ? 'visible' : 'hidden';
}

function get_AbreDiv(element, M, h, x){
	
	if( x == M ){  return;  }else{ x++; }
	var elemento = get_nodo(element);
	var margin = parseInt(elemento.style.height);
	var px = h/M;
	
	margin+=px;
	elemento.style.height = margin + 'px';
	setTimeout("get_AbreDiv('"+ element +"',"+ M +","+ h +","+ x +");", 70);
}

function get_CloseDiv(element, M, h, x){
	
	if( x == M ){ get_visible(element, false); return; }else{ x++; }
	var elemento = get_nodo(element);
	var margin = parseInt(elemento.style.height);
	var px = h/M;
	margin-=px;
	
	elemento.style.height = margin + 'px';
	setTimeout("get_CloseDiv('"+ element +"',"+ M +","+ h +","+ x +");", 70);

}

function Scroll(action,div){
	
	var ly = d.getElementById(div);
	var pixeles = 2;
	var newScroll = action == true ? ly.scrollTop+pixeles : ly.scrollTop-pixeles;
	ly.scrollTop = newScroll;
	timer = setTimeout("Scroll("+action	+",'"+div+"');",10);
}

function get_link(url){
	d.location = url;	
}

function get_newWindow(url, target){
		
	window.open(url, 'tarjet=' + target);
}

function openPopUp(wt, ht, url, name, scrol){
	
	var w_origi = scren.availWidth;
	var h_origi = scren.availHeight;
	
	var w = wt ? wt : w_origi;
	var h = ht ? ht : h_origi;
	var t = parseInt(w_origi / 3);
	var l = parseInt(h_origi / 2);
	
	props = "menubar=no,toolbars=no,scrollbars="+ scrol +",resizable=no,width="+ w +",height="+ h +",top="+ t +",left="+ l;
	eval(window.open(url, name, props));
}


function CountChars(limit, textarea, e, id_1, id_2){

	var key = ( w.event ) ?  e.keyCode : e.which;
	var asc = textarea.length;
	var desc = ( limit - asc );
	
	if( asc <= limit ){
		get_nodo(id_1).innerHTML = asc;
		get_nodo(id_2).innerHTML = desc;
		return true;
	}
	else { if( key != 8 ){ return false } };
		
}


function get_writen(id, msg){
	
	var element = typeof(id) == 'object' ? msg : get_nodo(id);
	typeElement = element.tagName.toLowerCase();

	if( typeElement == 'input' || typeElement == 'select' || typeElement == 'textarea' )
	{
		get_nodo(id).value = msg;
	}
	else get_nodo(id).innerHTML = msg;
}

function get_return_value(id){
	
	var element = typeof(id) == 'object' ? id : get_nodo(id);
	typeElement = element.tagName.toLowerCase();
	
	if( typeElement == 'input' || typeElement == 'select' || typeElement == 'textarea' ){
		return element.value;
	}
	else return element.innerHTML;
}

function get_return_checked(id){
	return get_nodo(id).checked;
}

// solo numeros
function AcptNum( e ){
	
	var key = ( window.event ) ?  e.keyCode : e.which;
	
	if( key != 46 && key != 0 && key != 8 && key != 13 && ( key < 48 || key > 57 ) )
	{
		return false;
	}
	else return true;
}


function _dontChar( e ){
	var key = ( window.event ) ?  e.keyCode : e.which;
	
	if( key )
	{
		return false;
	}
}

function get_focus(element){
	get_nodo(element).focus();
	//get_nodo(element).select();
}

function _newContador(div, y){
	get_nodo(div).value = '';
	get_nodo(div).value = y;
}


function get_calendar(id, calendar){
	
	var Pose =  get_position(id);
	var x = Pose.Left;
	var y = Pose.Top;
	var calendari = get_nodo(calendar);
	
	get_display(calendar, true);
	calendari.style.top = (y) + 'px';
	calendari.style.left = (x + 20) + 'px';
}

// generate cookies whith n name.
function setcookie(nameCookie, valor, expira, path){ 

	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expira);
	d.cookie = nameCookie+"="+escape(valor)+((expira==null) ? "" : ";expires="+exdate.toGMTString()+";path="+path); 
}

function get_submit(idForm){
	
	get_nodo(idForm).submit();
}

function wprint(){
	window.print();
}

function email_validation(idElement){

	var regular_exp_email = RegExp(/^[_a-zA-Z0-9_]+(\.[_a-zA-Z0-9-]+)*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]*$/);
	
	return get_return_value(idElement).match(regular_exp_email);

}