function confirmdelete(){
	if (!confirm("Are you sure you want to delete this article?")){
		return false;
	}
}

function confirmprofiledelete(){
	if (!confirm("Are you sure you want to delete your profile?")){
		return false;
	}
}


function updateCommentCount(){
	var num=parseInt(document.getElementById('commentcount').innerHTML);
		if (num=='0'){
			document.getElementById('nocommentsyet').style.display='none';
		}
	document.getElementById('commentcount').innerHTML=num+1;
	document.getElementById('commentbox').value='';
	document.getElementById('commentboxcount').innerHTML="0";
}



function checkpassword(){
	el=document.getElementById('password');
	el2=document.getElementById('password2');
	if ((el.value!=null || el.value!='' || el.value.length>0 
		|| el2.value!=null || el2.value!='' || el2.value.length>0) 
		&& el.value!=el2.value){
		msg='Your supplied password do not match.\n';
		alert(msg);
		return false;
	}
	return true
}


function checkarticle(el){
//el.disabled=true;
	var fail=0;
	var strip=(tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,"");
	var numwords = strip.split(' ').length;
	var msg="";
	if (numwords<250){
		msg+='Articles must be at least 250 words long.\n';
		fail=1;
	}
	if (numwords>5000){
		msg+='Articles cannot be greater than 5000 words long.\n';
		fail=1;
	}

	el=document.getElementById('title');
	if (el.value==null || el.value=='' || el.value.length<1){
		msg+='You must enter a title.\n';
		fail=1;
	}

	el=document.getElementById('categoryid');
	if (el.selectedIndex==0 ){
		msg+='You must select a category.\n';
		fail=1;
	}

	el=document.getElementById('shortdesc');
	if (el.value==null || el.value=='' || el.value.length<1){
		msg+='You must enter a short description.\n';
		fail=1;
	}

	el=document.getElementById('tags');
	if (el.value==null || el.value=='' || el.value.length<1){
		msg+='You must enter some tags.\n';
		fail=1;
	}

	el=document.getElementById('license');
	if (el.selectedIndex==0 ){
		msg+='You must select a license.\n';
		fail=1;
	}

	el=document.getElementById('published');
	if (el.selectedIndex==0 ){
		msg+='You must select a publication status.\n';
		fail=1;
	}

	el=document.getElementById('ownership');
	if (!el.checked){
		msg+='You must indicate ownership of the article.\n';
		fail=1;
	}

	if(fail==1){
		alert(msg);
		return false;
	}

	//title
	//categoryid
	//shortdesc
	//articletext

	//photo
	//difficulty

	//articletime
	//tags
	//license
	//published
	//ownership

	return true;
}

function toggleDisplay(id){
	var el=document.getElementById(id);
	if (el.style.display=='none' || el.style.display==''){
		el.style.display='block'
	}else{
		el.style.display='none'
	}
}

function imposeMaxLength(Event, Object, MaxLen) {         
	//document.getElementById('commentboxcount').innerHTML=Object.value.length;
	return (Object.value.length <= MaxLen-1)||(Event.keyCode == 8 ||Event.keyCode==46||(Event.keyCode>=35&&Event.keyCode<=40)) 
} 

function warnMaxLength(Object, MaxLen, DivID)
{
	// textarea length limit and warning
	if (Object.value.length >= MaxLen){
		document.getElementById(DivID).innerHTML=" <span class=\"alertmsg\">Maximum length reached!</span> - "+ Object.value.length;
		//Object.style.backgroundColor="#f99";
		//Object.style.backgroundColor="#fff";
	}
	else
	{
		document.getElementById(DivID).innerHTML=Object.value.length;
		//Object.style.backgroundColor="#fff";

	}
}




var voted=0;
function castvote(url,novotemsg){
	// DISPLAYS MESSAGE OR CALLS AJAX FUNCTION WHEN VOTE IS MADE.
	if (voted==0 && url!='' && novotemsg==''){
		addToQueue('','articlescore',url); 
		voted=1;
		var el=document.getElementById('upbutton');
		el.style.backgroundColor='#dddddd';
		el.style.borderColor='#aaaaaa';
		var el=document.getElementById('downbutton');
		el.style.backgroundColor='#dddddd';
		el.style.borderColor='#aaaaaa';
		document.getElementById('articleactionmsg').innerHTML='Your vote has been recorded.';

	}else if (novotemsg!=''){
		document.getElementById('articleactionmsg').innerHTML=novotemsg;
	}else{
		document.getElementById('articleactionmsg').innerHTML='You can only vote once per article.';
	}
	return false;
}






