/*
Auto center window script- Eric King (http://redrival.com/eak/index.shtml)
Permission granted to Dynamic Drive to feature script in archive
For full source, usage terms, and 100's more DHTML scripts, visit http://dynamicdrive.com
*/

var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
win = window.open(mypage,myname,settings)
}

var ANewWindow = null; 
function openAWindow(theURL,winName,w,h,scroll) { //v2.0
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
if (!ANewWindow || ANewWindow.closed) {
ANewWindow = window.open(theURL,winName,settings);
} else {
ANewWindow.location = theURL;
ANewWindow.focus();
}
}


function reTargetLinks () { 
for (var i=0; i<=(document.links.length-1); i++) document.links[i].target = 'new'; 
}


function showMoreComments(entryID, entryLink, htmlObj) {
extTextDivID = ('extText' + (entryID));
extLinkDivID = ('extLink' + (entryID));
if( document.getElementById ) {
if( document.getElementById(extTextDivID).style.display ) {
if( entryLink != 0 ) {
document.getElementById(extTextDivID).style.display = "block";
document.getElementById(extLinkDivID).style.display = "none";
htmlObj.blur();
} else {
document.getElementById(extTextDivID).style.display = "none";
document.getElementById(extLinkDivID).style.display = "block";
}
} else {
location.href = entryLink;
return true;
}
} else {
location.href = entryLink;
return true;
}
}


function showMoreEntry(entryID, entryLink, htmlObj) {
extTextDivID = ('extText' + (entryID));
extLinkDivID = ('extLink' + (entryID));
if( document.getElementById ) {
if( document.getElementById(extTextDivID).style.display ) {
if( entryLink != 0 ) {
document.getElementById(extTextDivID).style.display = "block";
document.getElementById(extLinkDivID).style.display = "none";
htmlObj.blur();
} else {
document.getElementById(extTextDivID).style.display = "none";
document.getElementById(extLinkDivID).style.display = "block";
}
} else {
location.href = entryLink;
return true;
}
} else {
location.href = entryLink;
return true;
}
}

function deCode() {
   function entities(e) {
      f=e.value;t='';
      for (i=0;i<f.length;i++) {
         if (f.charCodeAt(i)==60) {t+='&lt;';} else if (f.charCodeAt(i)==62) {t+='&gt;';} else if (f.charCodeAt(i)==123) {t+='&#123;';} else if (f.charCodeAt(i)==125) {t+='&#125;';} else if (f.charCodeAt(i)==34) {t+='&quot;';} else {
            t += f.charAt(i);
         }
      } 
      e.value=t;
   }
   l=document.getElementsByTagName('textarea');
   for (j=0;j<l.length;j++) {entities(l[j])}
   l=document.getElementsByTagName('input');
   for (j=0;j<l.length;j++) {
      if (l[j].type=='text')entities(l[j])
   }
}

function replaceQuote(aField) {
  if (document.getSelection) {
    var str = document.getSelection();
  } else if (document.selection && document.selection.createRange) {
    var str = document.selection.createRange().text;
  } else {
    alert("Sorry, your browser cannot use the highlight text functinality.  You can copy and paste the quote into the popup box.");
  }

  if (str == null || str == "") {
     var str = prompt ("Enter text you'd like to quote.  In the future, you can highlight text on the page and click the <quote> button for automatic quote insertion.  Click Cancel to exit this prompt.","")
  } 
   if (str != null && str != "") {
     str = "<blockquote>\"" + str + "\"</blockquote>"
     eval("document.comment_form." + aField + ".value = str;");
   }
}

var original = Array();
var ajax=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
 try {
  ajax = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   ajax = false;
  }
 }
@end @*/
if (!ajax && typeof XMLHttpRequest!='undefined') {
	ajax = new XMLHttpRequest();
}

function editEntry(serverPage, objID) {
	var element = document.getElementById(objID);
	original[objID] = element.innerHTML;
	ajax.open('GET', serverPage);
	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1:
				element.innerHTML = "Loading.";
				break;
			case 2:
				element.innerHTML += " .";
				break;
			case 3:
				element.innerHTML += " .";
				break;
			case 4:
				if (ajax.status==200) {
					element.innerHTML = ajax.responseText;
				}
				break;
		}
  	}
	ajax.send(null);
}

function cancelEntry(objID)
{
	var element = document.getElementById(objID);
	element.innerHTML = original[objID];		
}

function saveEntry(serverPage, objID, form, save)
{
	var element = document.getElementById(objID);
	var queryStr = formData2QueryString(form);
	if (save==false) { queryStr += '&preview=Preview'; }
	ajax.open('POST', serverPage, true);
	ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	ajax.onreadystatechange = function() {
		switch(ajax.readyState) {
			case 1:
				element.innerHTML = "Processing.";
				break;
			case 2:
				element.innerHTML += " .";
				break;
			case 3:
				element.innerHTML += " .";
				break;
			case 4:
				if (ajax.status==200) {
					element.innerHTML = ajax.responseText;
					if (save==true) {window.location.reload(false);} 
				}
				break;
		}
	}
	ajax.send(queryStr);
}

/*
---------------------------------------------------------------------------

 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program (see the file COPYING); if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA  02111-1307, USA
 
 The following code is copyright 2003 by Matthew Eernisse
 Modified by Yvonne L
 
---------------------------------------------------------------------------	
*/ 

function formData2QueryString(docForm)
{
	var strSubmitContent = '';
	var formElem;
	var strLastElemName = '';
	
	for (i = 0; i < docForm.elements.length; i++) {
		
		formElem = docForm.elements[i];
		switch (formElem.type) {
			// Text fields, hidden form elements
			case 'text':
			case 'hidden':
			case 'password':
			case 'textarea':
			case 'image':
			case 'select-one':
				strSubmitContent += formElem.name + '=' + encodeURIComponent(formElem.value) + '&';
				break;				
			case 'select-multiple':
				for (count = 0; count < formElem.length; count++) {
					if ( formElem[count].selected ) {
						strSubmitContent += formElem.name + '=' + encodeURIComponent(formElem[count].value) + '&';
					}
				}
				break;								
			// Radio buttons
			case 'radio':
				if (formElem.checked) {
					strSubmitContent += formElem.name + '=' + encodeURIComponent(formElem.value) + '&';
				}
				break;				
			// Checkboxes
			case 'checkbox':
				if (formElem.checked) {
					// Continuing multiple, same-name checkboxes
					if (formElem.name == strLastElemName) {
						// Strip of end ampersand if there is one
						if (strSubmitContent.lastIndexOf('&') == strSubmitContent.length-1) {
							strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
						}
						// Append value as comma-delimited string
						strSubmitContent += ',' + encodeURIComponent(formElem.value);
					}
					else {
						strSubmitContent += formElem.name + '=' + encodeURIComponent(formElem.value);
					}
					strSubmitContent += '&';
				}
				break;
		}
		strLastElemName = formElem.name;
	}
	
	// Remove trailing separator
	strSubmitContent = strSubmitContent.substr(0, strSubmitContent.length - 1);
	return strSubmitContent;
}