//####################################################################
//#
//#  Copyright 2009 - David Colarusso 
//#  eMail: dac33@cornell.edu  Web: http://www.davidcolarusso.com
//#
//#  This file is part of communityCOUNTS 
//#  Available at http://www.communitycounts.com
//#
//#   communityCOUNTS is free software: you can redistribute it and/or modify
//#   it under the terms of the GNU Lesser General Public License as published by
//#   the Free Software Foundation, either version 3 of the License, or
//#   (at your option) any later version.
//#
//#   communityCOUNTS 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 Lesser General Public License for more details.
//#
//#   You should have received a copy of the GNU Lesser General Public License
//#   along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
//#
//###################################################################

// also included 

/*************************************************************
* NLB Background Color Fader v1.0
* Author: Justin Barlow - www.netlobo.com
*
* Description:
* The Background Color Fader allows you to gradually fade the
* background of any HTML element.
*
* Usage:
* Call the Background Color Fader as follows:
*   NLBfadeBg( elementId, startBgColor, endBgColor, fadeTime );
*
* Description of Parameters
*   elementId - The id of the element you wish to fade the
*             background of.
*   startBgColor - The background color you wish to start the
*             fade from.
*   endBgColor - The background color you want to fade to.
*   fadeTime - The duration of the fade in milliseconds.
*************************************************************/

var nlbFade_hextable = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ]; // used for RGB to Hex and Hex to RGB conversions
var nlbFade_elemTable = new Array( ); // global array to keep track of faded elements
var nlbFade_t = new Array( ); // global array to keep track of fading timers
function NLBfadeBg( elementId, startBgColor, endBgColor, fadeTime )
{
	var timeBetweenSteps = Math.round( Math.max( fadeTime / 300, 30 ) );
	var nlbFade_elemTableId = nlbFade_elemTable.indexOf( elementId );
	if( nlbFade_elemTableId > -1 )
	{
		for( var i = 0; i < nlbFade_t[nlbFade_elemTableId].length; i++ )
			clearTimeout( nlbFade_t[nlbFade_elemTableId][i] );
	}
	else
	{
		nlbFade_elemTable.push( elementId );
		nlbFade_elemTableId = nlbFade_elemTable.indexOf( elementId );
	}
	var startBgColorRGB = hexToRGB( startBgColor );
	var endBgColorRGB = hexToRGB( endBgColor );
	var diffRGB = new Array( );
	for( var i = 0; i < 3; i++ )
		diffRGB[i] = endBgColorRGB[i] - startBgColorRGB[i];
	var steps = Math.ceil( fadeTime / timeBetweenSteps );
	var nlbFade_s = new Array( );
	for( var i = 1; i <= steps; i++ )
	{
		var changes = new Array( );
		for( var j = 0; j < diffRGB.length; j++ )
			changes[j] = startBgColorRGB[j] + Math.round( ( diffRGB[j] / steps ) * i );
		if( i == steps )
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+endBgColor+'";', timeBetweenSteps*(i-1) );
		else
			nlbFade_s[i - 1] = setTimeout( 'document.getElementById("'+elementId+'").style.backgroundColor = "'+RGBToHex( changes )+'";', timeBetweenSteps*(i-1) );
	}
	nlbFade_t[nlbFade_elemTableId] = nlbFade_s;
}
function hexToRGB( hexVal )
{
	hexVal = hexVal.toUpperCase( );
	if( hexVal.substring( 0, 1 ) == '#' )
		hexVal = hexVal.substring( 1 );
	var hexArray = new Array( );
	var rgbArray = new Array( );
	hexArray[0] = hexVal.substring( 0, 2 );
	hexArray[1] = hexVal.substring( 2, 4 );
	hexArray[2] = hexVal.substring( 4, 6 );
	for( var k = 0; k < hexArray.length; k++ )
	{
		var num = hexArray[k];
		var res = 0;
		var j = 0;
		for( var i = num.length - 1; i >= 0; i-- )
			res += parseInt( nlbFade_hextable.indexOf( num.charAt( i ) ) ) * Math.pow( 16, j++ );
		rgbArray[k] = res;
	}
	return rgbArray;
}
function RGBToHex( rgbArray )
{
	var retval = new Array( );
	for( var j = 0; j < rgbArray.length; j++ )
	{
		var result = new Array( );
		var val = rgbArray[j];
		var i = 0;
		while( val > 16 )
		{
			result[i++] = val%16;
			val = Math.floor( val/16 );
		}
		result[i++] = val%16;
		var out = '';
		for( var k = result.length - 1; k >= 0; k-- )
			out += nlbFade_hextable[result[k]];
		retval[j] = padLeft( out, '0', 2 );
	}
	out = '#';
	for( var i = 0; i < retval.length; i++ )
		out += retval[i];
	return out;
}
if (!Array.prototype.indexOf) {
	Array.prototype.indexOf = function( val, fromIndex ) {
		if( typeof( fromIndex ) != 'number' ) fromIndex = 0;
		for( var index = fromIndex, len = this.length; index < len; index++ )
			if( this[index] == val ) return index;
		return -1;
	}
}
function padLeft( string, character, paddedWidth )
{
	if( string.length >= paddedWidth )
		return string;
	else
	{
		while( string.length < paddedWidth )
			string = character + string;
	}
	return string;
}

/*************************************************************

*************************************************************/


addthis_brand = "CommunityCounts";

function keeploggedin() {

// sec * 1000

setTimeout("alert('Due to inactivity, you are about to be logged out. To prevent this, save your changes or reload this page.');",3300000);

}

function comingsoon() {

alert ("This feature is coming soon.");

}

//--------------

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

//--------------------------------------------------------------

function deletforum() {

var answer = confirm ('Are you sure you want to delet your forum? This can NOT be undone.');

var whereto = "../removeforum/";

if (answer){
document.location.href = whereto;
} 


}

//--------------------------------------------------------------

function botcheck(id,linked,vote,cap) {

if (0 == 0) {

var answer = confirm ('To maintain the integrity of votes, we occasionally ask users to do something that a computer program would find really hard. This is such a time.\n\nClick \"OK\" to perform such a task or click \"CANCEL\" to have your vote ignored.\n\nNote: If clicking \"OK\" dosen\'t open a new window, you\'ll need to disable your pop-up blocker and try again. ');

if (answer){

captcha_win = window.open('http://www.communitycounts.com/ondeck/tools/vote.cgi?id='+ escape(id)+'&linked='+ escape(linked)+'&vote='+ escape(vote)+'&cap='+ escape(cap), 'captcha_win','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=400,height=285'); 
captcha_win.focus();
return true;


} else {
document.FORM.tab.value = document.FORM.from.value;
if (document.FORM.from.value == "2") {
document.FORM.preamb.value = document.FORM.preambfrom.value;
document.FORM.resettext.value='0';
}
}


} else {

document.FORM.submit();

}

}

//--------------------------------------------------------------

function jump() {

if (document.FORM.from.value == "2") {
var oEditor = FCKeditorAPI.GetInstance('FCKeditorbody') ;

if ( oEditor.IsDirty() && document.FORM.saving.value != "1") {
document.FORM.saved.value = '0';
}
}

if (document.FORM.saved.value == 0) {

var answer = confirm ('Are you sure you to do this without saving changes? Any unsaved edits will be lost. \n\nNote: If you have included your own HTML edits you may be reciving this message even if you have saved your work. Simply click \"OK.\"');

if (answer){
document.FORM.submit();
} else {
document.FORM.tab.value = document.FORM.from.value;
if (document.FORM.from.value == "2") {
document.FORM.preamb.value = document.FORM.preambfrom.value;
document.FORM.resettext.value='0';
}
}


} else {

document.FORM.submit();

}

}

function linkhere(whereto) {

if (document.FORM.from.value == "2") {
var oEditor = FCKeditorAPI.GetInstance('FCKeditorbody') ;
if ( oEditor.IsDirty() && document.FORM.saving.value != "1") {
document.FORM.saved.value = '0';
}
}

if (document.FORM.saved.value == 0) {

var answer = confirm ('Are you sure you to do this without saving changes? Any unsaved edits will be lost. \n\nNote: If you have included your own HTML edits you may be reciving this message even if you have saved your work. Simply click \"OK.\"');

if (answer){
document.location.href = whereto;
} else {
document.FORM.tab.value = document.FORM.from.value;
if (document.FORM.from.value == "2") {
document.FORM.preamb.value = document.FORM.preambfrom.value;
document.FORM.resettext.value='0';
}
}

} else {

document.location.href = whereto;

}

}

//###################################



function xmlhttpListAdd(strURL,emadd,mod,ccounts,id) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageThree(self.xmlHttpReq.responseText,emadd,mod,ccounts,id);
        }
    }
    self.xmlHttpReq.send(getquerystringThree(emadd,mod,ccounts,id));
}


function getquerystringThree(emadd,mod,ccounts,id) { 
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    var vote = emadd;
    qstr = 'id=' + escape(id) + '&addtolist=' + escape(emadd) + '&addmod=' + escape(mod) + '&addcounts=' + escape(ccounts);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageThree(str,emadd,mod,ccounts,id){
	var countbox = "mailinglist";
    document.getElementById('mailinglist').innerHTML = str;
}

//############################

function xmlhttpPost(strURL,id,sig,divid,vote) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepage(self.xmlHttpReq.responseText,divid);
        }
    }
    self.xmlHttpReq.send(getquerystring(id,sig,vote));
}

function getquerystring(id,sig,vote) {
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    qstr = 'id=' + escape(id) + '&linked=' + escape(sig) + '&vote=' + escape(vote);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str,divid){
	var countbox = divid;
    document.getElementById(countbox).innerHTML = str;
}


//############################
//  self advancing stuff
//############################

function xmlhttpPostSelf(strURL,id,sig,divid,vote,type,next,sort) {
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageSelf(self.xmlHttpReq.responseText,id,type,next,sort);
        }
    }
    self.xmlHttpReq.send(getquerystring(id,sig,vote));
}

function getquerystring(id,sig,vote) {
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    qstr = 'id=' + escape(id) + '&linked=' + escape(sig) + '&vote=' + escape(vote);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageSelf(str,id,type,next,sort){
  var selfnext = 'http://www.communitycounts.com/forum/embed.cgi?id=' + escape(id) + '&type=' + escape(type) + '&next=' + escape(next) + '&sort=' + escape(sort);
  document.location.href = selfnext;
}

//############################



function xmlhttpClass(strURL,divid,linked,db,code,respondent,vidurl) {
    var xmlHttpReq = false;
    var self = this;
 	var divid = divid.toString();
 	// Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageClass(self.xmlHttpReq.responseText,divid);
        }
    }
    self.xmlHttpReq.send(getquerystringClass(divid,linked,db,code,respondent,vidurl));
}

function getquerystringClass(divid,linked,db,code,respondent,vidurl) {
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    qstr = 'id=' + escape(db) + '&linked=' + escape(linked) + '&class=' + escape(code) + '&respondent=' + escape(respondent) + '&vidurl=' + escape(vidurl);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageClass(str,divid){
	var countbox = divid;
    document.getElementById(countbox).innerHTML = str;
}


//############################

function xmlhttpAdd(strURL,vidurl,divid,db,challenge,response,user,website,local,runtime) {
    var xmlHttpReq = false;
    var self = this;
 	var divid = divid.toString();
 	// Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepageadd(self.xmlHttpReq.responseText,divid);
        }
    }
    self.xmlHttpReq.send(getquerystringadd(vidurl,db,divid,challenge,response,user,website,local,runtime));
}

function getquerystringadd(vidurl,db,divid,challenge,response,user,website,local,runtime) {
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    qstr = 'id=' + escape(db) + '&vidurl=' + escape(vidurl) + '&recaptcha_challenge_field=' + escape(challenge) + '&recaptcha_response_field=' + escape(response) + '&user=' + escape(user) + '&website=' + escape(website) + '&local=' + escape(local) + '&runtime=' + escape(runtime);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepageadd(str,divid){
	var countbox = divid;
    document.getElementById(countbox).innerHTML = str;
}


//############################

function xmlhttpUpdate(strURL,sig,divid,db,user) {
    var xmlHttpReq = false;
    var self = this;
 	var divid = divid.toString();
 	// Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updatepagetoo(self.xmlHttpReq.responseText,divid);
        }
    }
    self.xmlHttpReq.send(getquerystringtoo(sig,db,user,divid));
}

function getquerystringtoo(sig,db,user,divid) {
    //var form     = document.forms['ajf'];
    //var vote = form.vote.value;
    var vote = sig;
    qstr = 'id=' + escape(db) + '&linked=' + escape(sig) + '&respondent=' + escape(user) + '&embed=1&faceto=1';  // NOTE: no '?' before querystring
    return qstr;
}

function updatepagetoo(str,divid){
	var countbox = divid;
    document.getElementById(countbox).innerHTML = str;
}


//############################


function shoh(id) { 
    
    if (document.getElementById) { // DOM3 = IE5, NS6
        if (document.getElementById(id).style.display == "none"){
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';         
        }   
    } else { 
        if (document.layers) {  
            if (document.id.display == "none"){
                document.id.display = 'block';
            } else {
                document.id.display = 'none';
            }
        } else {
            if (document.all.id.style.visibility == "none"){
                document.all.id.style.display = 'block';
            } else {
                document.all.id.style.display = 'none';
            }
        }
    }
}



//show funtion
function show(id) { 
    
    if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById(id).style.display = 'block';
    } else { 
        if (document.layers) {  
                document.id.display = 'block';
        } else {
                document.all.id.style.display = 'block';
        }
    }
}

//hide funtion
function hide(id) { 
    if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById(id).style.display = 'none';         
    } else { 
        if (document.layers) {  
                document.id.display = 'none';
        } else {
                document.all.id.style.display = 'none';
        }
    }
}

function hidestuff(id) { 
    if (document.getElementById) { // DOM3 = IE5, NS6
            document.getElementById(id).style.display = 'none';         
    } else { 
        if (document.layers) {  
                document.id.display = 'none';
        } else {
                document.all.id.style.display = 'none';
        }
    }
}

















