/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
var xmlHttp2 = false;
var xmlHttp3 = false;

var gAllPosible=0; //Indica si pueden estar seleccionadas todas las clases. En tal caso cada cambio de grupo genera update
/*@cc_on @*/

//if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttp2 = new ActiveXObject("Msxml2.XMLHTTP");
  xmlHttp3 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
	xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
	xmlHttp2 = false;
	xmlHttp3 = false;
  }
}
//end@



if(typeof XMLHttpRequest != 'undefined'){ //Para versiones nuevas.
	if (!xmlHttp2) {
	  xmlHttp2 = new XMLHttpRequest();  
	}
	
	if (!xmlHttp) {
	  xmlHttp = new XMLHttpRequest();
	}
	if (!xmlHttp3) {
	  xmlHttp3 = new XMLHttpRequest();
	}

}
	
function gop(pCmd,pId){
	var url="../gophp.php?ajax=1&pCmd="+pCmd+"&pId="+pId;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlHttp.onreadystatechange = afterGop;
	xmlHttp.send(null);	
}

function afterGop(){
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    alert(response);
  }	
}

function getServClases(opt, owned, allposible) {
	grupo=document.getElementById('cboGrupo').value
	bol=0 
	if(allposible==1) gAllPosible=1;
	pOwned=""; if(owned==1) pOwned="&pOwned=1";
	pAllPosible=""; if(allposible==1) pAllPosible="&pAllPosible=1";
	var url = "../php/data/getClases.php?g=" + grupo + "&b=" + bol + pOwned + pAllPosible;
	
	xmlHttp.open("GET", url, true);
	  xmlHttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlHttp.onreadystatechange = updateAjaxClases;
	xmlHttp.send(null);
	
}



function updateAjaxClases() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("spanCboClase").innerHTML = response;
  }
  if(typeof(cboClaseChanged) != 'undefined' && gAllPosible==1) cboClaseChanged();
}

function getServAlus(opt) {
	grupo=document.getElementById('cboGrupo').value
	bol=0 
	var url = "../php/data/getAlus.php?g=" + grupo;
	
	xmlHttp2.open("GET", url, true);
	xmlHttp2.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlHttp2.onreadystatechange = updateAjaxAlus;
	xmlHttp2.send(null);
}

function updateAjaxAlus() {
  if (xmlHttp2.readyState == 4) {
    var response = xmlHttp2.responseText;
    document.getElementById("spanCboAlus").innerHTML = response;
  }
}


function getServConcs(opt) {
	grupo=document.getElementById('cboGrupo').value

	var url = "../php/data/getConcs.php?g=" + grupo;
	
	//xmlHttp2.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	$('#wait').show();
	
		
	xmlHttp2.open("GET", url, true);
	xmlHttp2.onreadystatechange = updateAjaxConcs;
	xmlHttp2.send(null);
}

function updateAjaxConcs() {
  if (xmlHttp2.readyState == 4) {
    var response = xmlHttp2.responseText;
    document.getElementById("spanCboConcs").innerHTML = response;
	
  }
  $('#wait').hide();
  $('#gobtn').removeAttr('disabled');
}

function getServMomentos(opt) {
	grupo=document.getElementById('cboGrupo').value
	var url = "../php/data/getMoms.php?g=" + grupo;
	
	$('#wait').show();
	//xmlHttp2.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlHttp3.open("GET", url, true);
	
	xmlHttp3.onreadystatechange = updateAjaxMoms;
	xmlHttp3.send(null);
}

function updateAjaxMoms() {
  if (xmlHttp3.readyState == 4) {
    var response = xmlHttp3.responseText;
    document.getElementById("spanCboMoms").innerHTML = response;
	
  }
  $('#wait').hide();
  $('#gobtn').removeAttr('disabled');
}



function loadTo(area, w){
	//var url = "../php/data/getClases.php?g=" + grupo + "&b=" + bol + pOwned;
	
	xmlHttp.open("GET", w, true);
	xmlHttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	xmlHttp.onreadystatechange = updateAjaxArea;
	xmlHttp.send(null);		
}
function updateAjaxArea() {
	ajaxArea=document.getElementById('ajaxArea');
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    ajaxArea.innerHTML = response;
  }
}


function exe(func, val1, val2, val3) { //Ejecutar un comando gophp en ajax

	if (func=='conf') var url = "../gophp.php?redir=none&pCmd=setConfig&pParam=" + val1 + "&pSec=" + val2 + "&pVal=" + val3;
	
	xmlHttp.open("GET", url, true);
	xmlHttp.setRequestHeader("Content-Type", "text/html;charset=iso-8859-1");
	//xmlHttp.onreadystatechange = updateAjaxClases;
	xmlHttp.send(null);
}

function openPopWindow(url, name, ynScroll){
	nW=300;nH=300; //Default
	if (name=='popEvents') {nW=500;nH=500;}
	if (name=='popSelTo') {nW=360;nH=540;}
	if (name=='popSelConcepts') {nW=360;nH=540;}
	if (name=='popSelClase') {nW=360;nH=520;}
	if (name=='popCake') {nW=450;nH=220;}
	if (name=='popUploadImg') {nW=300;nH=150;}
	if (name=='popPuntaje') {nW=550;nH=300;}
	if (name=='popInfoItem') {nW=650;nH=400;}
	
	sScroll=ynScroll ? 'yes' : 'no'

	// ## cambiado para que pueda redimensionar para Word, pero no lo hace (AR-060108)
	nw=window.open(url,name,'toolbar=no,location=no,scrollbars='+sScroll+' ,resizable=yes, width=' + nW + ', height=' + nH); 
	nw.focus(); 
	return false;
}

function initAll() {

    if (!document.all) document.all = ((document.getElementsByTagName("*").length > 0) ? document.getElementsByTagName("*") : null) 
	//document.all = (document.all) ? document.all : ((document.getElementsByTagName("*").length > 0) ? document.getElementsByTagName("*") : null)
}

function openPopSelTo(){
//##No jala por la parte dependiente de PHP
/*	tipoDest="P"
	cs=false
	<? if ($tipoUsuario=='P'):?>
	cs=true
	if (document.all.rbTipoDestA.checked) tipoDest="A"
	if (document.all.rbTipoDestP.checked) tipoDest="P"
	if (document.all.rbTipoDestT.checked) tipoDest="T"	
	<?endif;?>
	url='../common/popSelTo.php?ToType=' + tipoDest + '&pMode=CM'
	if (cs) url+='&pChooseScope=1'; else url+='&pChooseScope=0';
	if (tipoDest=="P") url+='&pFilterByGroup=0';
	
	nw=window.open(url,'popSelTo','toolbar=no,location=no,scrollbars=No,resizable=No'); nw.focus(); return false;
*/
}
function limitLen(ctl, maxLen){
	if (ctl.value.length>=maxLen){
		ctl.value=ctl.value.substr(0,maxLen)
		alert("Este campo está limitado a " + maxLen + " caracteres.")
		return false;
	}
	
}