
varPagesave="";
var MailMime="";
var Mailmenu="<div class=Area id=Sidemenu><div class=title id=sidetitle>"+
"<li class='sidemenu'><a class=Menu href=''>Trash</a></li>"+
"</ul></div>";
var Newspanelsave="";
var c=16;
var obj;
var zoom;
var postfocused=0;



function firstFocus(el) {
	document.getElementById(el).focus();
}


function browseSetNewChanged(tableId,field) {
	el = tableId + '|VAR|newchanged';
	document.getElementById(el).value = '1';
	// add backslash to single quote and backslash
	//field.value = field.value.replace(/['\\]/g, "\\$&");
	//id = tableId + "|VAR|msg";
	//document.getElementById(id).innerHTML = field.value;
}



function browseFirstFocus(tableId,colname) {
	// five hidden elements come first
	el = tableId + '|VAR|firstfocus';
	colname = document.getElementById(el).value;
	el = tableId + "|" + colname;
	document.getElementById(el).focus();
}






function browseRefresh(tableId,dbtable,nameid) {
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
	if (request.readyState == 4 && request.status == 200) {
    	document.getElementById(tableId).innerHTML=request.responseText;
    	el = tableId + "|VAR|firstfocus" ;
    	colname = document.getElementById(el).value;
    	el = tableId + "|" + colname;
		document.getElementById(el).focus();
	}
}
url = '/db/browseServer.php';
colnames =   document.getElementById(tableId+'|VAR|colnames').value;
fields   =   document.getElementById(tableId+'|VAR|fields').value;
order    =   document.getElementById(tableId+'|VAR|order').value;
firstfocus = document.getElementById(tableId+'|VAR|firstfocus').value;
where   =    document.getElementById(tableId+'|VAR|where').value;
asc   =   	 document.getElementById(tableId+'|VAR|asc').value;
params = 'cmd=refresh';
params = params + '&tableid='    + tableId;
params = params + '&dbtable='    + dbtable;
params = params + '&colnames='   + colnames;
params = params + '&fields='     + escape(fields);
params = params + '&order='      + order;
params = params + '&firstfocus=' + firstfocus;
params = params + '&where=' 	 + where;
params = params + '&asc='        + asc;
request.open('GET', url+"?"+params, true);

//document.getElementById(tableId+'|VAR|msg').innerHTML = document.getElementById(tableId+'|VAR|colnames').value;
//document.getElementById(tableId+'|VAR|msg').innerHTML = params;

request.send(null);
}







function browseDelete(tableId,dbtable,recId) {
// send record delete request to server
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
	if (request.readyState == 4 && request.status == 200) {
    	browseRefresh(tableId,dbtable);
    	document.getElementById(tableId+'|VAR|msg').innerHTML=request.responseText;
	}
}
url = '/db/browseServer.php';
params = 'cmd=delete&dbtable='+dbtable+'&id='+recId;
request.open('GET', url+"?"+params, true);
request.send(null);
}






function browseEnter(event,tableId,dbtable,field)
{
// grab keypress to process returnkey before default form submit
// submit if return or tab
var keycode;
// fit field width to field content
field.size = field.value.length * 1.1 + 1;
// get keycode either from window event or which
if (window.event) keycode = window.event.keyCode;
else if (event) keycode = event.which;
else return true;
el = tableId + '|VAR|msg';
//document.getElementById(el).innerHTML="key="+keycode;
// key13=return key0=tab
if (keycode == 13 ) { 
	field.style.background="transparent";
	browseNewRecord(tableId,dbtable);
	return false; 
}
else return true;
}




function browseNewRecord(tableId,dbTable) {
// send new record from table to server
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
	if (request.readyState == 4 && request.status == 200) {
    	el = tableId + '|VAR|msg';
    	document.getElementById(el).innerHTML=request.responseText;
    	browseRefresh(tableId,dbTable);
	}
}
cmd = 'newRec';
url = '/db/browseServer.php';
el=tableId+"|VAR|colnames";
colnames = document.getElementById(el).value;
colarray = colnames.split(",");
i=1;
// column name list
cols = '';
while ( colarray[i] ) {
	if ( i > 1 ) cols = cols + ",";
	cols = cols + colarray[i++];
}
i=1;
// values list
vals = ''; 
colarray = colnames.split(",");
while ( colarray[i] ) {
	if ( i > 1 ) vals = vals + ",";
	colname = tableId + "|" + trim(colarray[i]);
	value = document.getElementById(colname).value;
	if( colname == tableId + '|date' ) vals = vals + "STR_TO_DATE('" + value + "','%M %d %Y')";
	else {
		// add backslash before quotes and backslashes
		value = value.replace(/['\\]/g, "\\$&");
		vals = vals + "'" + value + "'"; 
		}
	i++;
}
params = 'cmd='+cmd+ '&dbtable='+dbTable + '&cols=' + cols + '&vals=' + escape(vals);
// secure should be 1 not true
request.open('GET', url+"?"+params, 1);
request.send(null);
}





function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}







function browseField(myfield,e)
{
// grab keypress to process returnkey before default form submit
// submit if return or tab, first set submitflag
// get keycode either from window event or which
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;
//document.getElementById('browsemsg').innerHTML="key="+keycode;
if (keycode == 13 || keycode == 0) { 
	document.getElementById('browsemsg').innerHTML='key='+keycode;
	return false; 
}
else return true;
}




function browseSize(id,colname)
{
el=id+"|"+colname;
document.getElementById(el).size=document.getElementById(el).value.length * 1.1;
}





function browseUpdate(field,dbtable,recordId,colname) {
el=recordId+"|"+colname;
value = field.value;
//add backslash before single quotes and backslashes
// escape value to send &
value = value.replace(/['\\]/g, "\\$&");

if( colname == 'date' ) value = "STR_TO_DATE('" + value + "','%M %d %Y')";
//else value = escape(value);
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
	if (request.readyState == 4 && request.status == 200) {
    	document.getElementById(el).value=request.responseText;
    	document.getElementById(el).size=document.getElementById(el).value.length * 1.1;
    	//document.getElementById('browsemsg').innerHTML=request.responseText;
	}
}
cmd = 'update';
url = '/db/browseServer.php';
params = 'cmd='+cmd+ '&dbtable='+dbtable+'&id='+recordId+'&colname='+colname+'&value='+escape(value);
//params = encodeURIComponent(params);
//urlparams = url + params;
request.open('GET', url+"?"+params, true);
//request.open("POST", url, true);
//request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
//request.setRequestHeader("Content-length", params.length);
//request.setRequestHeader("Connection", "close");
//request.send(params);
request.send(null);
}





function setpostfocused() { 
	postfocused = 1; 
	document.getElementById('posttext').style.color="#000";
	}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function topicchange(){
	if( document.postform.posttopic.value != 'choose topic') document.postform.submit();
	else return false;
}

function postsubmit () {
	// don't submit if neverfocused or empty posttext
	trimmedtext = trim(document.postform.posttext.value);
	len = trimmedtext.length;
	if( postfocused==0 || (len == 0) || document.postform.posttopic.value=='choose topic' ) return false;
	// change postbutton value before submiting to confirm submit,
	// not just a page refresh or topic change
	document.getElementById('postbutton').value="posted";
	return true;
}


function postfocus() {
if( postfocused == 0) {
	document.getElementById('posttext').value="";
	document.getElementById('posttext').style.color="#000";
	postfocused=1;
	document.getElementById('postfocused').value="1";
	}
}


function windowshade(fname) {
document.getElementById('windowshade').style.display = "block";
document.getElementById('windowshade').style.background = "url("+fname+")";
document.getElementById('windowshade').style.backgroundRepeat = "no-repeat";
document.getElementById('windowshade').style.backgroundSize = "100%";
document.getElementById('windowshade').style.backgroundColor = "#fff";
//document.getElementById('windowshade').style.zindex = "8";
//document.getElementById('Page').style.display = 'none';
}



 
function displaydiv(div_id, flag) {
	var el = document.getElementById(div_id);
	if ( flag == 1 || document.URL == "http://burro.net/" ) {	el.style.display = 'inline';}
	else {el.style.display = 'none';}
}
  
function Appload(fname)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  request=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  request=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
request.onreadystatechange=function()
  {
  if (request.readyState==4 && request.status==200)
    {
    document.getElementById('App').innerHTML=request.responseText;
    }
  }
fullpathname="/app/"+fname+"/"+fname+".php"; 
request.open("GET",fullpathname,true);
request.send();
}



function background() {
	document.getElementById('body').style.background=" -moz-linear-gradient(left,  #fff,  #ffe)"; 
	
	menus = document.getElementsByClassName('submenu');
	i=0;  while ( menus[i] )  menus[i++].style.background=" -moz-linear-gradient(left,  #fff,  transparent)";

	buttons = document.getElementsByClassName('topbutton');
	i=0;  while ( buttons[i] )  buttons[i++].style.color="#00f"; 
	
	buttons = document.getElementsByClassName('subbutton');
	i=0;  while ( buttons[i] )  buttons[i++].style.color="#00f";
	
	document.getElementById('Personalbody').style.color="#00f";
	document.getElementById('Friendbody').style.color="#00f";
	
	links = document.getElementsByClassName('home');
	i=0;  while ( links[i] )  links[i++].style.color="#00f"; 
	
	logos = document.getElementsByClassName('menulogo');
	i=0;  while ( logos[i] )  logos[i++].style.color="#00f";
	
	document.getElementById('menuright').style.color="#00f"; 
	
}


function AppPhoto(fname)
{
Appbodyhome=gethtml('Appbody');
document.getElementById('Appbody').innerHTML="<div id='Albumpanel'>"+
"<div class='Paneltitle'>Photo Album</div> <div class='Panelbody'>"+
"<img class='photoalbum' src='"+fname+"'></div></div>";
}



function supports_video() {
  return !!document.createElement('video').canPlayType;
}
 
 
 
function setmovie(base) {
//if (Modernizr.video) {
	//alert('modernizer');
	document.getElementById('TVbody').innerHTML=""+
	"<video width='480' "+
  		"poster='http://burro.net/" + base + ".jpg' " +
  		"preload autoplay controls >" +
  		"<source src='http://burro.net/" + base + ".webm' type='video/webm'/>" +
  		"<source src='http://burro.net/" + base + ".mp4'  type='video/mp4' />" +
	"</video>";
	// ogv=chrome, firefox
	// webm=firefox
	// mp4=safari, chrome
	
	
  	
  	//"<source src='http://burro.net/" + base + ".ogv'  type='video/ogg' />" +
	//"<source src='http://burro.net/"+base+".webm type='video/webm' />"+
	//	"<source src='http://burro.net/"+base+".mp4' type='video/mp4'/>  "+
	//	"<source src='http://burro.net/"+base+".ogv' type='video/ogg'/>  "+
//}	
//else {		
	//alert('Isloaded');
//	stream = "http://tv.burro.net/movies/stream/" + base + ".mp4";
//	$f('TVbody').play(stream);	
	//$f("TVbody").onPause( function() { $f("TVbody").stopBuffering();  } );
	//$f("TVbody").onPlay( function() { $f("TVbody").startBuffering();  } );
//}
}//endsetmovie



function loadleft(fname)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  left=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  left=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
left.onreadystatechange=function()
  {
  if (left.readyState==4 && left.status==200)
    {
    document.getElementById('Appleft').innerHTML=left.responseText;
    }
  }
fullpathname="/"+fname+"/appleft.php"; 
left.open("GET",fullpathname,true);
left.send();
}



function loadbody(fname)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  body=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  body=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
body.onreadystatechange=function()
  {
  if (body.readyState==4 && body.status==200)
    {
    document.getElementById('Appbody').innerHTML=body.responseText;
    }
  }
  fullpathname="/"+fname+"/appbody.php";
  body.open("GET",fullpathname,true);
  body.send();
}

function loadiframe()
{
	document.getElementById('mail-iframe').contentWindow.document.value="x<br>x<br>x<br>x<br>x";
}



function getmailrequest(fname)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  mailrequest=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  left=new ActiveXObject("Microsoft.XMLHTTP");
  }
  
mailrequest.onreadystatechange=function()
  {
  if (mailrequest.readyState==4 && mailrequest.status==200)
    {   
    Mailbuf=mailrequest.responseText;
    //split Mailbuf on char31 boundary
    bufseparator=Mailbuf.indexOf("\x1f");
    Mailheaderbuf=Mailbuf.slice(0,bufseparator);
    Mailbodybuf=Mailbuf.slice(bufseparator);
    frames['mailmsg'].document.getElementById('mailmsgheader').innerHTML=Mailheaderbuf;
    frames['mailmsg'].document.getElementById('mailmsgbody').innerHTML=Mailbodybuf;
    }
  }
  mailrequest.open("GET",fname,true);
  mailrequest.send();
}



function gethtml(obj) {
	return document.getElementById(obj).innerHTML
}

function clearhtml(obj) {
	document.getElementById(obj).innerHTML=""
}

function Appclear(obj) {
	Appsave();
	document.getElementById('Appleft').innerHTML="";
	document.getElementById('Appbody').innerHTML="";
	document.getElementById('Appright').innerHTML="";
}



function Apploadmail(){
	document.getElementById('Appright').innerHTML="";
	document.getElementById('Appbody').innerHTML="";
	document.getElementById('Appleft').innerHTML="";
	loadbody('mail');
}

function Appsave(){
Appleftsave=gethtml('Appleft');
Appbodysave=gethtml('Appbody');
Apprightsave=gethtml('Appright');
}

function Appsavehome(){
Applefthome=gethtml('Appleft');  
Appbodyhome=gethtml('Appbody');
Apprighthome=gethtml('Appright');
}

function Apprestorehome(){
document.getElementById('Appleft').innerHTML=Applefthome; 
document.getElementById('Appbody').innerHTML=Appbodyhome;
document.getElementById('Appright').innerHTML=Apprighthome;
}

function Apprestore(){
document.getElementById('Appleft').innerHTML=Appleftsave;
document.getElementById('Appbody').innerHTML=Appbodysave;
document.getElementById('Appright').innerHTML=Apprightsave;
}



function Apploadhome(){
document.getElementById('Appleft').innerHTML=Applefthome;
//document.getElementById('Appbody').innerHTML=Appbodyhome;
//document.getElementById('Appright').innerHTML=Apprighthome;
}

function shownews() { 
	document.getElementById('Newspanelbody').style.display='inline'; 
	//document.getElementById('Newspanelbody').innerHTML=Newspanelsave;
}


function hidenews() { 
	//Newspanelsave=document.getElementById('Newspanelbody').innerHTML;
	//document.getElementById('Newspanelbody').innerHTML="";
	document.getElementById('Newspanelbody').style.display='none'; 
}	
 




function Pagecolor(color){
document.getElementById('Page').style.background=color;
}

function mailmsg(msgnum) {
//frame=document.getElementById('mailmsg');
//getElementById('mailmsgheader').innerHTML+="";
//getElementById('mailmsgbody').innerHTML="loading... "+msgnum;
document.getElementById('mainFrame').contentWindow.document.getElementById('screen').innerHTML ='';
url="https://burro.net/mail/mailbody.php?id="+msgnum;
getmailrequest(url);
}


function initzoom() {
   obj=document.getElementById('pic')
   obj.onmouseover=function() { zoooom(); }
   obj.onmouseout=function() {
   	 clearTimeout(zoom);
  	 c=16;
   	 obj.style.marginLeft=-c/2+'px';
   	 obj.style.marginTop=-3*c/8+'px';
   	 obj.style.width=c+'px';
   	 obj.style.height=3*c/4+'px';
  }
 }
 
function zoooom() {
   if(c>800) { return; } 
   obj.style.marginLeft=-c/2+'px';
   obj.style.marginTop=-3*c/8+'px';
   obj.style.width=c+'px';
   obj.style.height=3*c/4+'px';
   c+=4;
   zoom=setTimeout('zoooom()',25);
}

 
 
function mailget(){
//update select
}

var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function getthedate(){
	var mydate=new Date(), year=mydate.getYear();if (year < 1000) year+=1900;var day=mydate.getDay(), month=mydate.getMonth(), daym=mydate.getDate()
	if (daym<10) daym="0"+daym;var hours=mydate.getHours(), minutes=mydate.getMinutes(), seconds=mydate.getSeconds(), dn="am"
	if (hours>=12) dn="pm";
	if (hours>12) { hours=hours-12 };
	if (hours==0) hours=12;if (minutes<=9) minutes="0"+minutes
	if (seconds<=9) seconds="0"+seconds;
	/*var cdate=hours+":"+minutes+dn+" "+dayarray[day]+" "+montharray[month]+" "+daym;*/
	var cdate=hours+":"+minutes+dn+" "+dayarray[day]+" "+montharray[month]+" "+daym;
	if (document.all) document.all.menuright.innerHTML=cdate;
	else if (document.getElementById) document.getElementById("menuright").innerHTML=cdate;else document.write(cdate)
}
if (!document.all&&!document.getElementById) getthedate()
function goforit(){ if (document.all||document.getElementById); setInterval("getthedate()",10000) }


