// JavaScript Document
var background = "#000000";
var weektext = "#FFFFFF";
var colordate = "#FFFFFF";
var colortime = "#FFFFFF";
var colorcountdown = "#FFFFFF";
var loginvars = new Array();
loginvars[0] = '0';

tabname = new Array();
tabname[0] = "Suggestions";
tabname[1] = "Colors";

function expandbox(box, w, h, cont){
	tabcontent = new Array();
	commvar = "&quot;comment&quot;";
	
	if(loginvars[0] == '1'){
	tabcontent[0] = "<div style='z-index:100; padding-left:5px; padding-right:5px;'>Welcome, "+loginvars[1]+"<input type='hidden' value='"+loginvars[1]+"' name='csname' id='csname'/><br/><textarea name='cstext' id='cstext' style='width:385px; height:100px;' onclick='textclear(this)' onKeyPress='checkenter(event, "+commvar+")'>Add your comment or suggestion here.</textarea><br/><input type='button' id='csbutton' value='Submit' style='border:1px solid #777777; background-color:#333333; color:#FFFFFF; font-size:18px;' onclick='loadXMLDoc()' onKeyPress='checkenter(event, "+commvar+")'/>";
	}
	else{
	tabcontent[0] = "<div style='z-index:100; padding-left:5px; padding-right:5px;'>Name: <input type='text' name='csname' id='csname' onKeyPress='checkenter(event, "+commvar+")'/><br/><textarea name='cstext' id='cstext' style='width:385px; height:100px;' onclick='textclear(this)' onKeyPress='checkenter(event, "+commvar+")'>Add your comment or suggestion here.</textarea><br/><input type='button' id='csbutton' value='Submit' style='border:1px solid #777777; background-color:#333333; color:#FFFFFF; font-size:18px;' onclick='loadXMLDoc()' onKeyPress='checkenter(event, "+commvar+")'/>";
	}
	
	tabcontent[1] = "<div style='z-index:100; position:relative; width:170px; height:170px; border:1px solid #000000; top:-8px; float:left;'>"+
	"<div class='colorsquare' id='000000' onclick='changecolor(this)' style='background-color:#000000;'></div>"+
	"<div class='colorsquare' id='333333' onclick='changecolor(this)' style='background-color:#333333;'></div>"+
	"<div class='colorsquare' id='666666' onclick='changecolor(this)' style='background-color:#666666;'></div>"+
	"<div class='colorsquare' id='999999' onclick='changecolor(this)' style='background-color:#999999;'></div>"+
	"<div class='colorsquare' id='FFFFFF' onclick='changecolor(this)' style='background-color:#FFFFFF;'></div>"+
	
	"<div class='colorsquare' id='FFFF00' onclick='changecolor(this)' style='background-color:#FFFF00;'></div>"+
	"<div class='colorsquare' id='FFCC00' onclick='changecolor(this)' style='background-color:#FFCC00;'></div>"+
	"<div class='colorsquare' id='FF9900' onclick='changecolor(this)' style='background-color:#FF9900;'></div>"+
	"<div class='colorsquare' id='FF6600' onclick='changecolor(this)' style='background-color:#FF6600;'></div>"+
	"<div class='colorsquare' id='CC3300' onclick='changecolor(this)' style='background-color:#CC3300;'></div>"+
	
	"<div class='colorsquare' id='00FF00' onclick='changecolor(this)' style='background-color:#00FF00;'></div>"+
	"<div class='colorsquare' id='00CC00' onclick='changecolor(this)' style='background-color:#00CC00;'></div>"+
	"<div class='colorsquare' id='339900' onclick='changecolor(this)' style='background-color:#339900;'></div>"+
	"<div class='colorsquare' id='006600' onclick='changecolor(this)' style='background-color:#006600;'></div>"+
	"<div class='colorsquare' id='003300' onclick='changecolor(this)' style='background-color:#003300;'></div>"+
	
	"<div class='colorsquare' id='0000FF' onclick='changecolor(this)' style='background-color:#0000FF;'></div>"+
	"<div class='colorsquare' id='000066' onclick='changecolor(this)' style='background-color:#000066;'></div>"+
	"<div class='colorsquare' id='003366' onclick='changecolor(this)' style='background-color:#003366;'></div>"+
	"<div class='colorsquare' id='3399FF' onclick='changecolor(this)' style='background-color:#3399FF;'></div>"+
	"<div class='colorsquare' id='33CCFF' onclick='changecolor(this)' style='background-color:#33CCFF;'></div>"+
	
	"<div class='colorsquare' id='FF0000' onclick='changecolor(this)' style='background-color:#FF0000;'></div>"+
	"<div class='colorsquare' id='CC0000' onclick='changecolor(this)' style='background-color:#CC0000;'></div>"+
	"<div class='colorsquare' id='990000' onclick='changecolor(this)' style='background-color:#990000;'></div>"+
	"<div class='colorsquare' id='660000' onclick='changecolor(this)' style='background-color:#660000;'></div>"+
	"<div class='colorsquare' id='330000' onclick='changecolor(this)' style='background-color:#330000;'></div>"+
	"</div>"+
	
	"<div style='z-index:100; position:relative; width:auto; height:172px; top:-8px; float:left;'>&nbsp;&gt;&nbsp;<br/><br/>&nbsp;&gt;&nbsp;<br/><br/>&nbsp;&gt;&nbsp;<br/><br/>&nbsp;&gt;&nbsp;<br/><br/>&nbsp;&gt;&nbsp;</div>"+
	
	"<div style='z-index:100; position:relative; width:170px; height:170px; border:1px solid #000000; top:-8px; float:left;'>"+
	"<div class='colorbox' id='background' style='background-color:"+background+";' onclick='getcolor(this)'>Background</div>"+
	"<div class='colorbox' id='weektext' style='background-color:"+weektext+"; color:#000000;' onclick='getcolor(this)'>Week Text</div>"+
	"<div class='colorbox' id='colordate' style='background-color:"+colordate+"; color:#000000;' onclick='getcolor(this)'>Date</div>"+
	"<div class='colorbox' id='colortime' style='background-color:"+colortime+"; color:#000000;' onclick='getcolor(this)'>Time</div>"+
	"<div class='colorbox' id='colorcountdown' style='background-color:"+colorcountdown+"; color:#000000;' onclick='getcolor(this)'>Countdown</div>"+
	"</div>";
	var hd;
	var wd;
	box.setAttribute("class", "quartercalcopen");
	box.setAttribute("className", "quartercalcopen");
	exh = setTimeout(function(){expandbox(box, w, h, cont)},25);
	if(box.offsetWidth < w){
	box.style.width=box.offsetWidth+10+"px";
	}
	else{
		wd=1;
		box.style.width=w+"px";
	}
	if(box.offsetHeight < h){
	box.style.height=box.offsetHeight+10+"px";	
	}
	else{
		hd=1;
		box.style.height=h+"px";
	}
	if(hd==1 && wd==1){
	clearTimeout(exh);
	box.innerHTML = "<div style='position:absolute; left:5px; top:3px;'>"+tabname[cont]+"</div><div style='position:absolute; right:2px; top:2px; cursor:pointer;' onclick='closebox(200, 30, "+cont+", "+w+", "+h+")'>close[X]</div><br/><br/>"+tabcontent[cont];
	box.onclick=function(){filler()};
	}
}

function filler(){
}

function closebox(w, h, cont, wf, hf){
	var hd;
	var wd;
	boxname = "tab"+cont;
	box = document.getElementById(boxname);
	box.innerHTML = tabname[cont];
	clh = setTimeout(function(){closebox(w, h, cont, wf, hf)},20);
	if(parseInt(box.style.width) > w){
	box.style.width=parseInt(box.style.width)-20+"px";
	}
	else{
		wd=1;
		box.style.width="";
	}
	if(parseInt(box.style.height) > h){
	box.style.height=parseInt(box.style.height)-20+"px";	
	}
	else{
		hd=1;
		box.style.height="";
	}
	if(hd==1 && wd==1){
	clearTimeout(clh);
	box.setAttribute("class", "quartercalc");
	box.setAttribute("className", "quartercalc");
	box.onclick=function(){expandbox(this, wf, hf, cont)};
	}
}

function textclear(txtbox){
txtbox.value = "";
txtbox.onclick = function(){filler()};
}

function loadXMLDoc()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	var csbutton;
	csbutton = document.getElementById('csbutton');
    csbutton.value = xmlhttp.responseText;
	csbutton.onclick=function(){this.value = 'Already Submitted'};
    }
  }
  
name = document.getElementById('csname').value;
text = document.getElementById('cstext').value;
url = "xmlwrite.php?n="+name+"&t="+text;

xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

var curbrick = 1;
var brickcolor;

function changecolor(brick){
	if(curbrick != 1){
		curbrick.style.border = "1px solid #000000";
	}
	brickcolor = "#"+brick.id;
	brick.style.border = "1px dashed #FFFFFF";
	curbrick = brick;
}

function getcolor(brick){
	brick.style.backgroundColor=brickcolor;
	 if(brickcolor == "#FFFFFF"){
		  brick.style.color="#000000";
	  }
	 if(brickcolor == "#000000"){
		  brick.style.color="#FFFFFF";
	  }
	ele = brick.id;
	switch(ele)
	{
	case 'background':
	  document.body.style.background=brickcolor;
	  background = brickcolor;
	  if(loginvars[0]=='1'){
		  savecolor('background', brickcolor);
		  loginvars[2] = brickcolor;
	  }
	  break;
	case 'weektext':
	  document.getElementById('week').style.color=brickcolor;
	  weektext = brickcolor;
	  if(loginvars[0]=='1'){
		  savecolor('weektext', brickcolor);
		  loginvars[3] = brickcolor;
	  }
	  break;
	case 'colordate':
	  document.getElementById('date').style.color=brickcolor;
	  colordate = brickcolor;
	  if(loginvars[0]=='1'){
		  savecolor('colordate', brickcolor);
		  loginvars[4] = brickcolor;
	  }
	  break;
	case 'colortime':
	  document.getElementById('time').style.color=brickcolor;
	  colortime = brickcolor;
	  if(loginvars[0]=='1'){
		  savecolor('colortime', brickcolor);
		  loginvars[5] = brickcolor;
	  }
	  break;
	case 'colorcountdown':
	  document.getElementById('timer').style.color=brickcolor;
	  colorcountdown = brickcolor;
	  if(loginvars[0]=='1'){
		  savecolor('colorcountdown', brickcolor);
		  loginvars[6] = brickcolor;
	  }
	  break;
	default:
	  
	}
}

function autocolor(){
	  document.body.style.background=background;
	  document.getElementById('week').style.color=weektext;
	  document.getElementById('date').style.color=colordate;
	  document.getElementById('time').style.color=colortime;
	  document.getElementById('timer').style.color=colorcountdown;
}

function savecolor(ele, c)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
	  
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    }
  }

c = c.replace("#", "");
url = "colorchange.php?ele="+ele+"&c="+c;

xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

var linkvars;

function loadlinks(logout)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
	topbartext = document.getElementById('topbartext');
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	linkvars=xmlhttp.responseText.split("|");
	if(parseInt(linkvars[0]) >= 1){
	recnum = parseInt(linkvars[0]);
	var linput = "";
	for(i=0;i<recnum;i++){
		var x;
		var vx;
		x=i+1;
		vx = x;
		if(x > 2){
			vx = x * 2;
			vx = vx + (x - 2);
		}
		else if(x == 2){
			vx = 4;
		}
	linput += "<a href='";
	linput += linkvars[vx+1];
	linput += "' ";
		if(parseInt(linkvars[vx+2])==1){
			linput += "target='_blank'";
		}
	linput += ">";
	linput += linkvars[vx];
	linput += "</a>";
		if(x == recnum){
		}else{
			linput += "&nbsp; | &nbsp;";
		}
	}
	if(logout != 0){
	linput += "<img src='plus.gif' class='plus' onclick='popuplink()' />";
	}
	topbartext.innerHTML = linput;
	}
	
    }
  }
  
url = "links.php";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function linkclear(lnum){
	linkurl = "linkurl" + lnum;
	document.getElementById(linkurl).value="";
	linkname = "linkname" + lnum;
	document.getElementById(linkname).value="";
}

function loadlinksbox(){
	recnum = parseInt(linkvars[0]);
	for(i=0;i<recnum;i++){
		var x;
		var vx;
		x=i+1;
		vx = x;
		if(x > 2){
			vx = x * 2;
			vx = vx + (x - 2);
		}
		else if(x == 2){
			vx = 4;
		}
	document.getElementById(("linkurl"+x)).value=linkvars[vx+1];
	document.getElementById(("linkname"+x)).value=linkvars[vx];
	}
}

function savelinks()
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
var savebutton = document.getElementById('linksave');
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
		savebutton.value = "saved";
		loadlinks();
    }
  }
linkn1 = document.getElementById('linkname1').value;
linku1 = document.getElementById('linkurl1').value;
linkn2 = document.getElementById('linkname2').value;
linku2 = document.getElementById('linkurl2').value;
linkn3 = document.getElementById('linkname3').value;
linku3 = document.getElementById('linkurl3').value;
linkn4 = document.getElementById('linkname4').value;
linku4 = document.getElementById('linkurl4').value;

url = "savelinks.php?n1="+linkn1+"&u1="+linku1+"&n2="+linkn2+"&u2="+linku2+"&n3="+linkn3+"&u3="+linku3+"&n4="+linkn4+"&u4="+linku4;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function resetsave(){
	var savebutton = document.getElementById('linksave');
	savebutton.value = "save";
}













