// JavaScript Document
$("document").ready(function (){
							  
	//color rows
	$("table.color tr:even").addClass("row2");
	
	//deletion check
	$("a.delete").click(function(){
		var href=$(this).attr("href");
		$.alerts.okButton="Yes";
		$.alerts.cancelButton="No";
		jConfirm("Are you sure you want to delete this record?", "Delete Record", function(r){
				if(r){
					window.location=href;
				}
		});
		return false;
	});
	
	$("a.blank").click(function(){
			window.open($(this).attr("href"));
			return false;
	});
	
	if($('input.dpicker').length>0){
		//DO NOT TOUCH THIS, YOU WILL BREAK THE ENTIRE BACKEND.
		Date.format = 'mm/dd/yyyy';
		$('input.dpicker').datePicker({startDate:'01/01/1996', clickInput: false});
	}
	
	$("textarea#story").keypress(function(e){
		var len=$(this).val().length;
		var left;
		len=parseInt(len);
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code!=8){
			if(len>=800){
				e.preventDefault();
			}
			left=800-(len+1);
		}else{
			left=800-(len-1);	
		}
		
		if(parseInt(left)>800){left=800;}
		
		$("span#max").text(""+left);	
	});
});


function imposeMaxLength(Object, MaxLen)
{
  return (Object.value.length <= MaxLen);
}

function addOption(sel_id, value, name){
	if(document.getElementById(sel_id)!=null){
		var opt=document.createElement("option");
		opt.text=name;
		opt.value=value;
		document.getElementById(sel_id).options.add(opt);
	}
}

function clearDropDown(sel_id){
	if(document.getElementById(sel_id)!=null){
		document.getElementById(sel_id).options.length=0;
	}	
}