// JavaScript Document

function getFlashMovieObject(movieName)
{
  if (window.document[movieName]) 
  {
    return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function StopFlashMovie()
{
	var flashMovie=getFlashMovieObject("flashsound");
	flashMovie.StopPlay();
}

function PlayFlashMovie()
{
	var flashMovie=getFlashMovieObject("flashsound");
	flashMovie.Play();
	//embed.nativeProperty.anotherNativeMethod();
}

function RewindFlashMovie()
{
	var flashMovie=getFlashMovieObject("flashsound");
	flashMovie.Rewind();
}

function execJS(t)

{

    var p1 = 0, p2 = 0, p3 = 0, p4 = 0;

    p1 = t.indexOf("<" + "script", 0);

    if(p1 == -1) return t;

    

    p2 = t.indexOf(">", p1 + 7) + 1;

    p3 = t.indexOf("<" + "/script>", p2);

    p4 = p3 + 9;

    

    var c = t.substring(p2, p3);

    var s = document.createElement("script");

    s.type = "text/javascript";

    s.text = c;

    document.getElementsByTagName("head")[0].appendChild(s);

    

    t = t.substring(0, p1) + t.substr(p4);

    return execJS(t);



}


var http2 = createRequestObject();

function handleResponse2() {
	if(http2.readyState == 4){
		var response = http2.responseText;
		var update = new Array();

		if(response.indexOf(']|[' != -1)) {
			update = response.split(']|[');
			document.getElementById(update[0]).style.display="block";
			outputupdate=execJS(update[1]);
			document.getElementById(update[0]).innerHTML = update[1];
			if (document.getElementById(update[0]+'minus')) document.getElementById(update[0]+'minus').style.display='block';
		}
	} else {
		isBusy = false;
	}
}

function handleResponse3() {
	if(http2.readyState == 4){
		var response = http2.responseText;
		var update = new Array();
		if(response.indexOf(']|[' != -1)) {
			update = response.split(']|[');
			document.getElementById(update[0]).style.border="1px solid #7F9DB9;";
			document.getElementById(update[0]).style.padding="2px 2px 3px 3px";
			if (update[1]==1) {
				document.getElementById(update[0]).style.background = '#bbffbb';
			} else {
				document.getElementById(update[0]).style.background = '#ffaaaa';
			}
			if (document.getElementById(update[0]+'minus')) document.getElementById(update[0]+'minus').style.display='block';
		} 
	} else {
		isBusy = false;
	}
}

function handleResponse4() {
	if(http2.readyState == 4){
		var response = http2.responseText;
		var update = new Array();
		if(response.indexOf(']|[' != -1)) {
			update = response.split(']|[');
		}
	} else {
		isBusy = false;
	}
}

function handleResponse5() {
	if(http2.readyState == 4){
		var response = http2.responseText;
		var update = new Array();

		if(response.indexOf(']|[' != -1)) {
			update = response.split(']|[');
			outputupdate=execJS(update[1]);
		}
	} else {
		isBusy = false;
	}
}

var isBusy ='';
function sndReq2(action,idoutput,operation) {
	if (isBusy == true)
	{
		http2.onreadystatechange = null;
		http2.abort();
	}
	if (operation!="useronline") document.getElementById(idoutput).innerHTML='<img style="padding:2px; padding-top:4px;" src="http://www.bloo.it/img/n_loader.gif" />';
	http2.open('get', '/include/ajax_php.inc.php?'+action+'&idoutput='+idoutput+'&operation='+operation);
	isBusy = true;
	if (operation=="checkform") {
		http2.onreadystatechange = handleResponse3;
	} else if (operation=="useronline") {
		http2.onreadystatechange = handleResponse4;
	} else {
		http2.onreadystatechange = handleResponse2;
	}
	http2.send(null);
}

function sndReq2b(action,idoutput,operation) {
	if (isBusy == true)
	{
		http2.onreadystatechange = null;
		http2.abort();
	}
	http2.open('get', '/include/ajax_php.inc.php?'+action+'&idoutput='+idoutput+'&operation='+operation);
	isBusy = true;
	if (operation=="checkform") {
		http2.onreadystatechange = handleResponse3;
	} else {
		http2.onreadystatechange = handleResponse2;
	}
	http2.send(null);
}

function sndReq3(action,idoutput,operation) {
	if (isBusy == true)
	{
		http2.onreadystatechange = null;
		http2.abort();
	}
	http2.open('get', '/include/ajax_php.inc.php?'+action+'&idoutput='+idoutput+'&operation='+operation);
	isBusy = true;
	http2.onreadystatechange = handleResponse5;
	http2.send(null);
}

function sndReqpost2(action,idoutput,operation,vars) {
	document.getElementById(idoutput).innerHTML='<img style="padding:2px; padding-top:4px;" src="http://www.bloo.it/img/n_loader.gif" />';
	http2.open('post', '/include/ajax_php.inc.php?'+action+'&idoutput='+idoutput+'&operation='+operation, true);
	var variabili=vars;
	http2.onreadystatechange = handleResponse2;
	http2.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http2.send(variabili);
}

function CheckFields(CtrlName,idc,oper,table,divout){
      var reqcell="";                  //string for required field's corresponding notification cell
      var msg="";                        //debug message
	  var altro="";
      var reqlist=document.getElementById(CtrlName).value.split(",");
	  //document.write(reqlist);
      for (var x in reqlist){
		  //document.write(reqlist[x]);
           // reqcell="Required_"+reqlist[x];
            msg+="&"+reqlist[x];
            msg+="="+document.getElementById(reqlist[x]).value;
      }
     //reqcell="CreationDate";
	 if (idc!='') {
	 	altro="&id="+idc;
	 }
	 msg=msg.replace(/\+/g,'#43#');
	 msg=unescape(msg);
	 if (divout==null) divout='form';
	 sndReqpost2('table='+table+altro,divout,oper,msg)
}
