thCount = 0;
selectBtn = new Array();
selectBtn[0] = new Image();
selectBtn[0].src = "images/pt-select-0.jpg";
selectBtn[1] = new Image();
selectBtn[1].src = "images/pt-select-1.jpg";
sendBtn = new Array();
sendBtn[0] = new Image();
sendBtn[0].src = "images/pt-send-x.jpg";
sendBtn[1] = new Image();
sendBtn[1].src = "images/pt-send.jpg";
clearBtn = new Array();
clearBtn[0] = new Image();
clearBtn[0].src = "images/pt-clear-x.jpg";
clearBtn[1] = new Image();
clearBtn[1].src = "images/pt-clear.jpg";
responseText = "";
responseDiv = "";
responseTimer = 0;
sbInerval = 0;
newTop = 0;
function selectThis(n){
   if(thStat[n]==0 && thCount>=3){
      alert("Sorry, Maximum of 3 selections per session only.");
   } else {
      thStat[n]=(thStat[n]+1)%2;
      document.getElementById("select"+n).src = selectBtn[thStat[n]].src;
      if (thStat[n]){ thCount++; } else { thCount--; }
   }
   document.getElementById("sendBtn").src = (thCount>0)?sendBtn[1].src:sendBtn[0].src;
   document.getElementById("clearBtn").src = (thCount>0)?clearBtn[1].src:clearBtn[0].src;
   if(thCount==0){ hideSend(); }
}
function showSend(){
   if(thCount<1){
      alert("Please select at least 1 Thought to send.");
   } else {
      sObj = document.getElementById("sendLayer");
      document.getElementById("sendLayer").style.visibility = "visible";
   }
}
function moveSendBox(){
   var ns = navigator.appName=="Netscape";
   var docTop=!ns?document.documentElement.scrollTop:window.pageYOffset;
   var nTop=(thCount>0)?(docTop+2):185;
   nTop=(nTop<185)?185:nTop;
   var sObj = document.getElementById("menu-sendthought")
   var sTop = parseInt(sObj.style.top);
   dTop = (nTop-sTop)/6;
   newTop = (Math.abs(dTop)<1)?nTop:(sTop+dTop);
   sObj.style.top=""+(newTop)+"px";
}
function initSendBox(){
   sbInterval = setInterval("moveSendBox()", 40);
}
function clearSelect(){
   if(thCount>0){
      for(var i=0; i<thStat.length; i++){
	     thStat[i]=0;
         document.getElementById("select"+i).src = selectBtn[thStat[i]].src;
	  }
	  thCount=0;
   } else {
      alert("No thought selected.");
   }
   document.getElementById("sendBtn").src = sendBtn[0].src;
   document.getElementById("clearBtn").src = clearBtn[0].src;
   hideSend();
}
function hideSend(){
      document.getElementById("sendLayer").style.visibility = "hidden";
}
function clearSend(){
   fObj = document.getElementById("sendForm");
   fObj.toEmail.value="";
   fObj.toName.value="";
   fObj.fromEmail.value="";
   fObj.fromName.value="";
}
function submitThought(){
   fObj=document.getElementById("sendForm");
   te=fObj.toEmail.value;
   tn=fObj.toName.value;
   fe=fObj.fromEmail.value;
   fn=fObj.fromName.value;
   if(te.search(/@/)>0 && fe.search(/@/)>0 && tn.length>0 && fn.length>0){
      thList=catName;
      for(var i=0; i<thStat.length; i++){
         if(thStat[i]==1){
            thList+=","+i;
         }
      }
      sendPath="scripts/sendthought.php?toEmail=" + te + "&toName=" + tn + "&fromEmail=" + fe + "&fromName=" + fn + "&thList=" + thList;
      getData(sendPath, "sendResult");
      hideSend();
   } else {
      alert("Please make sure your entries are correct.");
   }
}
function sendMail(){
   fObj=document.getElementById("emailme");
   fe=fObj.email.value;
   fn=fObj.name.value;
   msg=fObj.message.value;
   if(fe.search(/@/)>0 && fn.length>0 && msg.length>0){
      sendPath="scripts/sendmail.php?fromEmail=" + fe + "&fromName=" + fn + "&message=" + msg;
	  getData(sendPath, "mailStatus");
   } else {
      alert("Please make sure your entries are correct.");
   }
}
function sendQuickMsg() {
	fObj=document.getElementById("quickmsg");
	fn=fObj.name.value;
	tmp=fObj.message.value;
	tmp=tmp.replace(/"/g, "<dq>");
	tmp=tmp.replace(/'/g, "<sq>");
	tmp=tmp.replace(/\n/g, " ");
	tmp=tmp.replace(/\r/g, " ");
	tmp=tmp.replace(/\x25/g, "<pp>");
	tmp=tmp.replace(/\x26/g, "<aa>");
	tmp=tmp.replace(/\x23/g, "<ch>");
	tmp=tmp.replace(/\x3A\x29\x29/g, "<lol>");
	tmp=tmp.replace(/\x3A\x29/g, "<sml>");
	tmp=tmp.replace(/\x3AD/g, "<grn>");
	tmp=tmp.replace(/\x3AP/g, "<raz>");
	tmp=tmp.replace(/\x3B\x29/g, "<wnk>");
	msg=tmp.replace(/\x3F/g, "<qm>");
	if(fn.search(/\W/)>-1){
		alert("Please use only alphanumeric characters for names.");
	} else {
		if(fn.length>0 && msg.length>0){
			var date=new Date();
			var dstr=""+date.getTime();
			sendPath='scripts/quickMsg.php?fName=' + fn + '&message=' + msg + '&fn=' + dstr;
			getData(sendPath, "quick");
			fObj.message.value="";
		} else {
			alert("Please make sure your entries are correct.");
		}
	}
}
function showQuickMsg(){
	setInterval("updateQuickMsg()", 2000);
}
function checkEnter(e){ 
	var characterCode;
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		sendQuickMsg(); //submit the form
		return false
	} else {
		return true
	}
}
function updateQuickMsg(){
	var date=new Date();
	var dstr=""+date.getTime();
	getData("scripts/showQuickMsg.php?fn="+dstr, "quick");
}
function getData(dataSource, divID) {
	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest) {
		XMLHttpRequestObject = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
		if (!XMLHttpRequestObject){
			XMLHttpRequestObject = new ActiveXObject("Msxml2.XMLHTTP");
		}
	}
	if(XMLHttpRequestObject) {
		var obj = document.getElementById(divID)
		try {
			XMLHttpRequestObject.open("GET", dataSource);
			XMLHttpRequestObject.onreadystatechange = function()
			{
				if (XMLHttpRequestObject.readyState == 4 &&
				XMLHttpRequestObject.status == 200) {
					obj.innerHTML=XMLHttpRequestObject.responseText;
					//obj.scrollTop=obj.scrollHeight;
				}
			}
			XMLHttpRequestObject.send(null);
		} catch(e) {
			alert(e);
		}
	}
}