// JavaScript Document
sChars=/[a-z0-9_]+/i;

function disableSubmit(me){
	me.cmdSubmit.disabled=true;	
}
function clearReply(){
	document.frmReplyPost.txtMessage.value="";	
}
function checkBadWord(me){
  sBadWords="northeastern.ncc.abbe.pasaol.proprietor.porn.shit.intercourse.moron.idiot.embicile.suck.fuck.blowjob.blowjob.masturbat.palpal.pal-pal.peste.pisti.atay.inatay.kanahan.karaho.pakloon.buang.kayat.iyot.gerger.jerjer.ger-ger.jer-jer.yabag.buli.oten.boto.bilat.penis.vagina.bol-bol.bolbol.gitmaw";
  arBadWords=sBadWords.split(".");
  for(ctr=0;ctr<arBadWords.length;ctr++){
   if(me.search(arBadWords[ctr])!=-1)
    return arBadWords[ctr];
  }
  return "wala";
}
function resetCreate(){
	document.frmCreatePost.cboCategory.selectedIndex=0;
	document.frmCreatePost.txtTitle.value = "";
	document.frmCreatePost.txtMessage.value = "";
}
function showError(){
	document.getElementById('pErrorHeader').style.visibility = 'visible';
	document.getElementById('pError').innerHTML = spError;
	goThere("#theTop");
}
function isEmailValid(email){
	sFormat = /^[a-z0-9_]+@[a-z0-9\-]+\.[a-z0-9\-\.]+$/i;
	a = email.match(sFormat);
	if(a!=null)
		return true;
		return false;
}
function isUserPassValid(me){
	sFormat=/^[a-z0-9_ ñ]+$/i;
	a=me.match(sFormat);
	if(a!=null)
		return true;
		return false;
}
	

function goThere(place){
 if (String(place).substring(0,2) == "aj")
     place = String(place).substring(2);
     document.location.href=place;
}
function viewSelect(catIndex){
	document.location.href="viewpost.asp?catIndex=" + (catIndex+1) + "&nostart=1";	
}
function checkAccept(me){
    sAcceptValue = me.value;
	if(sAcceptValue=='yes')
		document.frmReg.cmdSubmit.disabled=false;
	else
		document.frmReg.cmdSubmit.disabled=true;
}
function validateSearch(me){
	me.txtCatIndex.value = me.cboCategory.selectedIndex + 1;
}
function validateCreatePrivate(){
	sToUserName=document.frmCreatePrivate.txtToUserName.value;
	sTitle=document.frmCreatePrivate.txtTitle.value;
	sMessage=document.frmCreatePrivate.txtMessage.value;
	spError="";
	if((sToUserName.length==0)||(sToUserName.match(sChars)==null))
		spError=spError + "&raquo;&nbsp;To Username required<br>";	
	if((sTitle.length==0)||(sTitle.match(sChars)==null))
		spError=spError + "&raquo;&nbsp;Empty title<br>";
	else if(sTitle.length<=4){
		spError=spError + "&raquo;&nbsp;Title is too short<br>";	
	}
	if((sMessage.length==0)||(sMessage.match(sChars)==null))		
		spError=spError + "&raquo;&nbsp;Empty message<br>";
	else if(sMessage.length<=20)
		spError=spError + "&raquo;&nbsp;Message is too short<br>";
	if(checkBadWord(sTitle)!="wala")
		spError=spError + "&raquo;&nbsp;Cannot accept title containing word like <b>"+ checkBadWord(sTitle) + "</b><br>";
	if(checkBadWord(sMessage)!="wala")
		spError=spError + "&raquo;&nbsp;Cannot accept title containing word like <b>"+ checkBadWord(sMessage) + "</b><br>";	
	if(spError.length!=0){
		showError();
		return false;
	}
	document.frmCreatePrivate.cmdSubmit.disabled=true;
	return true;
}
function validateCreate(){
	sTitle=document.frmCreatePost.txtTitle.value;
	sMessage=document.frmCreatePost.txtMessage.value;
	sCategory=document.frmCreatePost.cboCategory.options[document.frmCreatePost.cboCategory.selectedIndex].text;
	sCategoryIndex=document.frmCreatePost.cboCategory.selectedIndex;
	
	spError="";
	if(sCategoryIndex==0)
		spError=spError + "&raquo;&nbsp;Category required<br>";	
	if((sTitle.length==0)||(sTitle.match(sChars)==null))
		spError=spError + "&raquo;&nbsp;Empty title<br>";
	else if(sTitle.length<=4){
		spError=spError + "&raquo;&nbsp;Title is too short<br>";	
	}
	if((sMessage.length==0)||(sMessage.match(sChars)==null))
		spError=spError + "&raquo;&nbsp;Empty message<br>";
	else if(sMessage.length<=20)
		spError=spError + "&raquo;&nbsp;Message is too short<br>";
	if(checkBadWord(sTitle)!="wala")
		spError=spError + "&raquo;&nbsp;Cannot accept title containing word like <b>"+ checkBadWord(sTitle) + "</b><br>";
	if(checkBadWord(sMessage)!="wala")
		spError=spError + "&raquo;&nbsp;Cannot accept title containing word like <b>"+ checkBadWord(sMessage) + "</b><br>";	
	if(spError.length!=0){
		showError();
		return false;
	}
	document.frmCreatePost.txtCategoryIndex.value=sCategoryIndex;
	document.frmCreatePost.cmdSubmit.disabled=true;
	return true;
}

function validateReg(){
	sUsername = document.frmReg.txtUserName.value;
	sFname = document.frmReg.txtFName.value;
	sLname = document.frmReg.txtLName.value;
	sGender=document.frmReg.cboGender.options[document.frmReg.cboGender.selectedIndex].text;
	sContactNo = document.frmReg.txtContactNo.value;
	sEmail = document.frmReg.txtEmail.value;
	sPassword = document.frmReg.txtPassword.value;
	sCPassword = document.frmReg.txtCPassword.value;
	spError="";
	if(checkBadWord(sUsername)!="wala")
		spError=spError + "&raquo;&nbsp;Username cannot be accepted. It's either reserved or contains bad words.<b></b><br>";			
	if((sUsername.length==0)||(sUsername.match(sChars)==null))
			spError=spError + "&raquo;&nbsp;Username required<br>";
	else if(isUserPassValid(sUsername)==false)
			spError=spError + "&raquo;&nbsp;Username can only be Aa-Zz,0-9<br>";
	if((sFname.length==0)||(sFname.match(sChars)==null))
			spError=spError + "&raquo;&nbsp;First Name required<br>";
	else if(isUserPassValid(sFname)==false)
			spError=spError + "&raquo;&nbsp;Cannot accept First name<br>";				
	if((sLname.length==0)||(sLname.match(sChars)==null))
			spError=spError + "&raquo;&nbsp;Last Name required<br>";
	else if(isUserPassValid(sLname)==false)
			spError=spError + "&raquo;&nbsp;Cannot accept Last name<br>";			
	if((sEmail.length==0)||(sEmail.match(sChars)==null))
			spError=spError + "&raquo;&nbsp;Email required<br>";
	else if(isEmailValid(sEmail)==false)
			spError=spError + "&raquo;&nbsp;Invalid Email<br>"			
	if((sPassword.length==0)||(sPassword.match(sChars)==null))
			spError=spError + "&raquo;&nbsp;Password required<br>";
	else if(isUserPassValid(sPassword)==false)
			spError=spError + "&raquo;&nbsp;Password can only be Aa-Zz,0-9<br>";
	if(sPassword!=sCPassword)
			spError=spError + "&raquo;&nbsp;Password don't match<br>";
	if((sUsername.length<=3)&&(sUsername.length!=0))
			spError=spError + "&raquo;&nbsp;Username must greater than 3 characters<br>";	
	if((sPassword.length<=4)&&(sPassword.length!=0))
			spError=spError + "&raquo;&nbsp;Password must greater than 4 characters<br>";	
	if(spError.length!=0){
			showError();
			return false;	
	}
	if(sContactNo=='')
		document.frmReg.txtContactNo.value='NONE';	
		return true;
}