
function define_endereco()
{
	var endereco_dados = document.getElementById('endereco_calendario').value;
	return endereco_dados;
}

function define_nr_data_pickers()
{
	var nr_data_pickers = document.getElementById('nr_data_pickers').value;
	return nr_data_pickers;
}

function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();
var pick_opcao = '';
var div_calendario = 'calspan';



function getCalendarioPick(action,id_input,id_div_calendario){
	pick_opcao = id_input;
	div_calendario = id_div_calendario;
	sndReq(action);
}


function sndReq(action)
{

	var endereco_dados = define_endereco();

	//alert('a: '+action+' e: '+endereco_dados);
	//IMPORTANTE
	//na variavel é necessáeio incluir o ? para podermos passar variaveis como opcao
	//se acresentamos variaveis no html, temos k colocar & no final da variaveis
	//para não quebrar a variaveis usadas nesta funcao

    http.open('get', endereco_dados+'data='+action+'&pick_opcao='+pick_opcao);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();
        document.getElementById(div_calendario).innerHTML = response;
    }
}

function pick(mydate,opcao) {
    show('');
    document.getElementById(opcao).value = mydate;
}

function pick_subscricoes(mydate,opcao) {

	var id_elemento = opcao.substring(30);
    var data_pagamento = opcao.substring(0,18);

	//alert('1. '+data_pagamento);

	show('');
    document.getElementById(opcao).value = mydate;


	//alert('2. '+data_pagamento);
	if(data_pagamento == 'subs_data_pagament' || data_pagamento == 'pag_data_pagamento' )
	{
		//não faz nada
		//alert('X');
	}
	else if('subs_data_inicio_periodicidade' == opcao)
	{
	    MakeXMLHTTPCall(); //em js.assinaturas.js
	}
	else
	{
		MakeXMLHTTPCall2(id_elemento); //em js.assinaturas.js
	}
}

function show(id_div_calendario)
{
    var nr_pickers = define_nr_data_pickers();

    for(var i = 1; i <= nr_pickers; i++)
    {
		if('calspan'+i == id_div_calendario)
        	document.getElementById('calspan'+i).style.visibility = "visible";
    	else
       		document.getElementById('calspan'+i).style.visibility = "hidden";
    }


}


