function getAjax(dataSource, id) {

	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (XMLHttpRequestObject) {
		XMLHttpRequestObject.open("GET", dataSource);

		XMLHttpRequestObject.onreadystatechange = function () {
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {

				if (id != '') {
					document.getElementById(id).innerHTML = XMLHttpRequestObject.responseText;
				} else {
					if (XMLHttpRequestObject.responseText) {
						alert(XMLHttpRequestObject.responseText);
					}
				}
			}
		}
		XMLHttpRequestObject.send(null);
	}
}

function nuevoAjax() { 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function build_order(obj, id, order, max, pid) {

	var html;

	obj.onclick = new function() {}
	
	html	 = '<select name="order" onchange="set_order(this,\''+id+'\', \''+pid+'\')">';

	for (i=1; i<=max; i++) {
		if (i == order) {
			html	+= '<option value="'+i+'" selected>'+i+'</option>';
		} else {
			html	+= '<option value="'+i+'">'+i+'</option>';
		}
	}
	
	html	+= '</select>';
	
	return html;
}

function set_order(obj, id, pid) {
	location.href = 'index.php?pid='+pid+'&order='+id+'&stack='+obj.options[obj.selectedIndex].value;
}

function confDel(action, msg) {
	var answer = confirm(msg)
	if (answer){
		window.location = action;
	}	
}

function confPrinc(action, msg) {
	var answer = confirm(msg)
	if (answer){
		window.location = action;
	} else {
		window.parent.location.reload()
	}
}

function popup(url, name, w, h, scrollBar) {

	var loc_top = screen.height/2-h/2-50;
	if (!loc_top) loc_top = 250;

	var loc_left = screen.width/2-w/2;
	if (!loc_left) loc_left = 450;

	window.open(url, name, 'width='+w+',height='+h+',left='+loc_left+',top='+loc_top+',scrollbars='+scrollBar+',resizable=no,status=no');
}

function refreshparent(url) {
	window.opener.location.href = url;
	if (window.opener.progressWindow) {
		window.opener.progressWindow.close()
	}
	window.close();
}

function submitBtn(btn) {
	document.disp.task.value = btn;
	document.disp.submit()	
}

function guardar_filtro(action) {
	var answer = window.prompt("Escriba el Nombre para el Filtro")
	if (answer != '' && answer != null) {
		window.location = action + "&filtro_name=" + escape(answer);
	}
}

function select_filtro(action) {
	var id = document.getElementById('id_filtro').value;
	if(id!=''){
		url = action + "&id_filtro=" + id;
		window.location = url;
	}
}

function filtro(action) {
	var id = document.getElementById('id_filtro').value;
	if(id!=''){
		url = action + "&id_filtro=" + id;
		window.location = url;
	}
}

function show_prov(id){
	if(id==13){
		document.getElementById('prov').style.display="block";
	} else {
		document.getElementById('prov').style.display="none";
	}
}

function close_footalert() {
	document.getElementById('footalert').style.display = 'none';
}

var nav4 = window.Event ? true : false;
function is_Date(evt){
	// NOTE:
	// Backspace = 8
	// Enter = 13
	// '0' = 48
	// '9' = 57 
	// '-' = 45 
	var key = nav4 ? evt.which : evt.keyCode;
	return (key == 13 || (key >= 48 && key <= 57) || key == 0 || key == 45 || key == 47 || key == 8);
}

var nav4 = window.Event ? true : false;
function is_Number(evt){
	// NOTE:
	// Backspace = 8
	// Enter = 13
	// '0' = 48
	// '9' = 57 
	// '-' = 45 
	var key = nav4 ? evt.which : evt.keyCode;
	return (key == 13 || (key >= 48 && key <= 57) || key == 0 || key == 45 || key == 8);
}

function buscar(pid) {
	// Redirect
	if(window.event && window.event.keyCode == 13)
		window.location = "index.php?pid="+pid+"&kw="+document.getElementById('search').value;
	else
		window.location = "index.php?pid="+pid+"&kw="+document.getElementById('search').value;
}

var nav4 = window.Event ? true : false;
function key_Buscar(evt,pid){
	// NOTE:
	// Backspace = 8
	// Enter = 13
	// '0' = 48
	// '9' = 57 
	// '-' = 45 
	var key = nav4 ? evt.which : evt.keyCode;
	if (key == 13){
		buscar(pid);
	}
}
