// Easy Events client side AJAX
// I know this could be reduced a lot...
function intval( mixed_var, base ) {
    var tmp;
    if (typeof base == "undefined") {
      base = 10;
    }
    if( typeof( mixed_var ) == 'string' ){
        tmp = parseInt(mixed_var*1);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if( typeof( mixed_var ) == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}

function ee_setMonth(id,year,month) {
	sel = $(id);
	str = year+'-'+month;
	for (i=0; i<sel.options.length; i++) {
		if (sel.options[i].value == str) {
			sel.selectedIndex = i;
      break;
		}
	}
}

var EasyEvents = {
    listDivId: '',
    calDivId: '',
    xhr0: window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0"),
    updateList:function(n,y,m,d,lp,gtdp){
        var xhro = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
        xhro.open('post',this.ajaxPageUrl,true);
        xhro.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhro.onreadystatechange = function()
        {
            if (xhro.readyState == 4 && xhro.status == 200)
            {
                document.getElementById(EasyEvents.listDivId).innerHTML = xhro.responseText;
            }
        }
        if ( xhro )
        {
            xhro.send('a=ul&y='+y+'&m='+m+'&d='+d+'&lp='+lp+'&gtdp='+gtdp+'&n='+n);

        }
        return false;
    },
    updateCalendar:function(n,y,m,d,pid,gtdp,sm){
        var xhro = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
        xhro.open('post',this.ajaxPageUrl,true);
        xhro.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhro.onreadystatechange = function()
        {
            if (xhro.readyState == 4 && xhro.status == 200)
            {
                document.getElementById(EasyEvents.calDivId).innerHTML = xhro.responseText;
            }
        }
        if ( xhro )
        {
            xhro.send('a=uc&y='+y+'&m='+m+'&d=0&pid='+pid+'&n='+n+'&gtdp='+gtdp+'&sm='+sm);

        }
        return false;
    },
    getDetails:function(n,eeid){
        var xhro = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
        xhro.open('post',this.ajaxPageUrl,true);
        xhro.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhro.onreadystatechange = function()
        {
            if (xhro.readyState == 4 && xhro.status == 200)
            {
                document.getElementById(EasyEvents.listDivId).innerHTML = xhro.responseText;
            }
        }
        if ( xhro )
        {
            xhro.send('n='+n+'&a=gd&i='+eeid);

        }
        return false;
    }
}