var chatwindow;
var stinglength,stingindex,mySting;
var monthnames3=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
// ========= FORM FIELD VALIDATION S=========
function isURL(url){
	//DOESN'T REQUIRE HTTP OR WWW
	var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
	if(RegExp.test(url)){
			return true;
	}else{
			return false;
	}
}

function isEmail(invalue){
	invalue=unescape(invalue);
		return (invalue.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1);
}

// ==========================================

function checkContribution(){
	var result=true;
	var sel=document.getElementById('contributionType').selectedIndex;
	switch (document.getElementById('contributionType')[sel].value){
		case '0':
			alert('You must select a contribution category');
			result=false;
			break;
		case 'url':
			if(document.getElementById('url').value.length==0){
				alert('Missing web site URL');
				document.getElementById('url').focus();
				result=false;
			}
			else{
				if(isURL(document.getElementById('url').value)==false){
					alert('Invalid web site URL');
					document.getElementById('url').focus();
					result=false;
				}
			}
			break;

		case 'blog':
			if(document.getElementById('blog').value.length==0){
				alert('Missing blog URL');
				document.getElementById('blog').focus();
				result=false;
			}
			else{
				if(isURL(document.getElementById('blog').value)==false){
					alert('Invalid blog URL');
					document.getElementById('blog').focus();
					result=false;
				}
			}
			break;
		case 'story':
			if(document.getElementById('story').value.length==0){
				alert('No text entered');
				document.getElementById('story').focus();
				result=false;
			}
			break;
		case 'feedback':
			if(document.getElementById('feedback').value.length==0){
				alert('You havenot entered a comment');
				document.getElementById('feedback').focus();
				result=false;
			}
			break;
		default:
			result=false;
	}
	return result;
}

function openChat(){
	chatwindow=window.open('/chatwindow.asp','chatwindow','width=450,height=550,scrollbars=yes,resizable=yes');
	if(chatwindow!=null){chatwindow.focus()};
}

function openForum(){
	forumwindow=window.open('/forum/','forum','width=1000,height=750,scrollbars=yes,resizable=yes');
	if(forumwindow!=null){forumwindow.focus()};
}

function getChatUsersLoop(){
	getChatUsers();
	setTimeout("getChatUsersLoop()",60000);
}

function selectContribution(selection){
	var u=document.getElementById('div_url');
	var b=document.getElementById('div_blog');
	var s=document.getElementById('div_story');
	var f=document.getElementById('div_feedback');
	var x=document.getElementById('submitContribution');
	u.style.display='none';
	b.style.display='none';
	s.style.display='none';
	f.style.display='none';
	x.style.display='none';
	if(selection!='0'){
		document.getElementById('div_'+selection).style.display='';
		x.style.display='';
	}
}

function getUserTZ(){
	var today=new Date();
	return today.getTimezoneOffset();
}

function showSignUp(){
	document.getElementById('divSignUp').style.display='';
	document.getElementById('divPasswordRetrieve').style.display='none';
}

function showPwRetrieve(){
	document.getElementById('divSignUp').style.display='none';
	document.getElementById('divPasswordRetrieve').style.display='';
}

function checkSignIn(){

}

function checkSignUp(){

}

function checkPwRetrieve(){

}

function updatedate(){
	var now=new Date()
	var nowstring=formatDate(now,'d MMM yyyy HH:mm');
	document.getElementById('date').innerHTML=nowstring;
	setTimeout("updatedate()",60000);
}

function checkPasswords(){
	var jsignupbutton=document.getElementById('signupButton');
	var pwdHasError=false;
	pwdWarning=document.getElementById('badpwd');
	pw1=document.getElementById('newuserpassword');
	pw2=document.getElementById('newuserpassword2');
	if(pw1.value!=pw2.value){
		pwdWarning.innerHTML='passwords do not match';
		pwdHasError=true;
		pw2.focus();
	}
	if(pw1.value.replace(/ /g,'').length==0){
		pwdWarning.innerHTML='no password';
		pwdHasError=true;
		pw1.focus();
	}
	if(pwdHasError==true){
		pwdWarning.style.display='';
		jsignupbutton.disabled=true;
	}
	else{
		pwdWarning.style.display='none';
		jsignupbutton.disabled=false;
	}
}

function checkEmailsMatch(){
	var jsignupbutton=document.getElementById('signupButton');
	var emailHasError=false;
	emWarning=document.getElementById('bademail');
	em1=document.getElementById('newuseremail');
	em2=document.getElementById('newuseremail2');
	if(isEmail(em1.value)==false){
		emWarning.innerHTML='invalid email address';
		emailHasError=true;
		em1.focus();
	}
	if(em1.value!=em2.value){
		emWarning.innerHTML='emails do not match';
		emailHasError=true;
		em2.focus();
	}
	if(emailHasError==true){
		emWarning.style.display='';
		emWarning.innerHTML='invalid email address';
		jsignupbutton.disabled=true;
	}
	else{
		emWarning.style.display='none';
		jsignupbutton.disabled=false;
	}
}

function fixNick(nick){
	var rep = '';
	nick.value = nick.value.replace(/ /g, rep);
}

function showroles(control){
	var controlID=control.id;
	var target;
	targetID='div'+controlID+'status';
	switch(controlID){
		case 'kh':
			target=document.getElementById(targetID);
			control.checked?target.style.display='':target.style.display='none';
			break;
		case 'lg':
			target1=document.getElementById(targetID+'1');
			target2=document.getElementById(targetID+'2');
			target3=document.getElementById(targetID+'3');
			control.checked?target1.style.display='':target1.style.display='none';
			control.checked?target2.style.display='':target2.style.display='none';
			control.checked?target3.style.display='':target3.style.display='none';
			break;
	}
}

function makeDate(){
	var jday=document.getElementById('ddob')[document.getElementById('ddob').selectedIndex].value;
	var jmonth=document.getElementById('mdob')[document.getElementById('mdob').selectedIndex].value;
	var jyear=document.getElementById('ydob')[document.getElementById('ydob').selectedIndex].value;
	if(jday*jmonth.length*jyear==0){
	}
	else{
		check=new Date(jday + ' ' + jmonth + ' ' + jyear);
		if(monthnames3[check.getMonth()]!=jmonth){
			alert('invalid date');

		}
		else{
			document.getElementById('dob').value=jday + ' ' + jmonth + ' ' + jyear;
		}
	}
}

function checkthis(incontrol,intype){
	markError(incontrol,false);
	switch (intype){
		case 'email address':
			if(incontrol.value.length==0){
				alert('Missing ' + intype);
				markError(incontrol,true);
				incontrol.focus();
			}
			else{
				if(isEmail(incontrol.value)==false){
					alert('Invalid email address');
					markError(incontrol,true);
					incontrol.focus();
				}
			}
			break;
		case 'prdays':
			if(isNaN(incontrol.value)==true || incontrol.value.length==0){
				alert('You must enter a number or enter 0 for indefinite lockup');
					markError(incontrol,true);
					incontrol.focus();
			}
			break;
		case 'prkhnick':
			if(incontrol.value.replace(' ','').length>0){
				getkhguid(incontrol);
			}
			break;
	}
}

function checkprofileedit(){
	var sp=document.getElementById('showprogress');
	if(sp.checked==true){

	}
}

function doBingoNick(incontrol){
	var jnick=incontrol.value;
	var placeholder='[name/nick]';
	if(jnick=='' || jnick==placeholder){
		incontrol.value=placeholder;
	}
	else{
		checkBingoNick(jnick);
	}
}

function showSting(insting){
		stingIndex=0;
		stinglength=insting.length;
		mySting=insting;
		scrollSting();
}

function scrollSting(){
	stingIndex=stingIndex+1;
	stinger=document.getElementById('sting');
	if(stingIndex>mySting.length){
		ret=setTimeout("jsGetSting()",5000);
	}
	else{
		if(mySting.charAt(stingIndex)=='<'){
			while(mySting.charAt(stingIndex)!='>'){
				stingIndex=stingIndex+1;
			}
		}
		partial=mySting.slice(0,stingIndex);
		stinger.innerHTML='<strong>&ldquo;</strong>'+partial+'<strong>&rdquo;</strong>';
		ret=setTimeout("scrollSting()",50);
	}
}

function showHideProgressConfig(inchecked){
	target=document.getElementById('divprogressconfig');
	switch (inchecked){
		case true:
			target.style.display='block';
			break;
		case false:
			target.style.display='none';
			break;
	}
}

function markError(incontrol,bool){
	var pink="#fccfac";
	var white='#ffffff';
	switch (bool){
		case true:
			incontrol.style.backgroundColor=pink;
			break;
		case false:
			incontrol.style.backgroundColor=white;
			break;
	}
}

function showMiniProfile(nick){
	var ret=window.open('/profiles/miniprofile.asp?id='+nick,nick,'width=550,height=550,scrollbars=yes,resizable=no');
	if(ret!=null){ret.focus()};
}
