
function jb_replace(string,rtext,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = rtext.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(rtext);
    if ((!i) && (rtext != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += jb_replace(string.substring(i+txtLength,strLength),rtext,by);
    return newstr;
}

function wopen(url,popupname,attributes) {
  win = window.open(url,popupname,attributes);
  win.focus();
}

//===============================DATE VALIDATION START
/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(yy,mm,dd){
	var daysInMonth = DaysArray(12)
	if (mm<1 || mm>12){
		//alert("Please enter a valid month")
		return false
	}
	if (dd<1 || dd>31 || (mm==2 && dd>daysInFebruary(yy)) || dd > daysInMonth[mm]){
		//alert("Please enter a valid day")
		return false
	}
	if (yy==0 || yy<minYear || yy>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
return true
}
//===============================DATE VALIDATION END

//===============================CALENDAR START

//udf_month_of_year,udf_day_of_week
if(typeof(udf_day_of_week)=='undefined' || udf_day_of_week.length!=7){
	var day_of_week = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
}else{
	var day_of_week = udf_day_of_week;
}
if(typeof(udf_month_of_year)=='undefined' || udf_month_of_year.length!=12){
	var month_of_year = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
}else{
	var month_of_year = udf_month_of_year;
}
if(typeof(udf_title_format)=='undefined' || udf_title_format==''){
	var title_format = 'month,  year';
}else{
	var title_format = udf_title_format;
}

//  DECLARE AND INITIALIZE VARIABLES
if(isDate(calyear,calmonth+1,calday)){
	var Calendar = new Date(calyear, calmonth, calday);
}else{
	var Calendar = new Date();
}
//var year = Calendar.getYear();	    // Returns year
var year = Calendar.getFullYear();	    // Returns year
var month = Calendar.getMonth();    // Returns month (0-11)
var today = Calendar.getDate();    // Returns day (1-31)
var weekday = Calendar.getDay();    // Returns day (1-31)

var DAYS_OF_WEEK = 7;    // "constant" for number of days in a week
var DAYS_OF_MONTH = 31;    // "constant" for number of days in a month
var cal;    // Used for printing

Calendar.setDate(1);    // Start the calendar day at '1'
Calendar.setMonth(month);    // Start the calendar month at now

/* VARIABLES FOR FORMATTING*/

var TR_start = '<tr class="blog_cal_tr">';
var TR_end = '</tr>';
var TD_start = '<td class="blog_cal_td_normal">';
var TD_end = '</td>';

/* BEGIN CODE FOR CALENDAR */

cmonth = month+1;
preyearmonth = (cmonth==1)?((year-1)+'12'):(year.toString()+(((cmonth-1)<10)?('0'+(cmonth-1)):(cmonth-1)));
nextyearmonth = (cmonth==12)?((year+1)+'01'):(year.toString()+(((cmonth+1)<10)?('0'+(cmonth+1)):(cmonth+1)));

cal_title = title_format.replace('month', month_of_year[month]);
cal_title = cal_title.replace('year', year);

cal = '<table class="blog_cal_table">' + TR_start;
cal += '<td class="blog_cal_th_arrow"><a href="'+cal_url+preyearmonth+'"><<</a>'+TD_end;
cal += '<td COLSPAN="5" class="blog_cal_th_title">';
cal += cal_title + TD_end;
cal += '<td class="blog_cal_th_arrow"><a href="'+cal_url+nextyearmonth+'">>></a>'+TD_end;
cal += TR_end + TR_start;

// LOOPS FOR EACH DAY OF WEEK
for(index=0; index < DAYS_OF_WEEK; index++)
{
	// BOLD TODAY'S DAY OF WEEK
	if(weekday == index)
		cal += '<td class="blog_cal_th_header">' + day_of_week[index] + TD_end;

	// PRINTS DAY
	else
		cal += '<td class="blog_cal_th_header">' + day_of_week[index] + TD_end;
}

cal += TD_end + TR_end;
cal += TR_start;

// FILL IN BLANK GAPS UNTIL TODAY'S DAY
for(index=0; index < Calendar.getDay(); index++)
cal += '<td class="blog_cal_td_blank">' + '  ' + TD_end;


// LOOPS FOR EACH DAY IN CALENDAR
for(index=0; index < DAYS_OF_MONTH; index++)
{
	if( Calendar.getDate() > index )
	{
	  week_day =Calendar.getDay();

	  if(week_day == 0)
	  cal += TR_start;

	  if(week_day != DAYS_OF_WEEK)
	  {
		  var day_data  = Calendar.getDate();
		  if(cd[day_data]==1){
		  	lcalmonth = ((calmonth+1)<10)?('0'+(calmonth+1)):(calmonth+1);
		  	lday_data = (day_data<10)?('0'+day_data):day_data;
				day_data = '<a href="'+cal_url+calyear+lcalmonth+lday_data+'"><u>'+day_data+'</u></a>';
				tTD_start = '<TD class="blog_cal_td_link">';
		  }else{
		  	tTD_start = TD_start;
			}

		  if( today==Calendar.getDate() )
		  	cal += '<TD class="blog_cal_td_today">' + day_data + TD_end;
		  else
		  	cal += tTD_start + day_data + TD_end;
	  }

	  if(week_day == DAYS_OF_WEEK)
	  cal += TR_end;
  }
  // INCREMENTS UNTIL END OF THE MONTH
  Calendar.setDate(Calendar.getDate()+1);

}// end for loop

cal += '</TD></TR></table>';
//===============================CALENDAR END


function jb_create_comment_form(postid){
	//var cf_output = document.getElementById('post_comment_'+postid);
	if(postid){
		var cf_str = post_common_form;
		cf_str = jb_replace(cf_str,'jbpostid',postid);
		//cf_str = jb_replace(cf_str,'this_human_check_img','<img src="'+eval('human_check_img_'+postid)+'" border="0"/>');
		document.write(cf_str);
		//cf_output.innerHTML = cf_str;
	}
}

function jb_comment_show_hide(postid){
	var new_status = (document.getElementById('post_comment_'+postid).style.display=='none')?'block':'none';
	document.getElementById('post_comment_'+postid).style.display = new_status;
}

function jb_switch_comment_form(ptype, postid){
	document.getElementById('mb'+postid).style.display='none';
	document.getElementById('ob'+postid).style.display='none';
	if(ptype){
		document.getElementById(ptype+'b'+postid).style.display='block';
	}
}