var countdownTimer=new Object();var commentshowreply=new Object();function getElementsByClassName(classname){if(document.getElementsByTagName){var els=document.getElementsByTagName("*");var c=new RegExp('/b^|'+classname+'|$/b');elem=new Array();var n=0;for(var i=0;i<els.length;i++){if(els[i].className){if(c.test(els[i].className)){elem[n]=els[i];n++;}}}
return elem;}else{return false;}}
function getCookieVal(offset){var endstr=document.cookie.indexOf(";",offset);if(endstr==-1)
endstr=document.cookie.length;return unescape(document.cookie.substring(offset,endstr));}
function GetCookie(name){var arg=name+"=";var alen=arg.length;var clen=document.cookie.length;var i=0;while(i<clen){var j=i+alen;if(document.cookie.substring(i,j)==arg)
return getCookieVal(j);i=document.cookie.indexOf(" ",i)+1;if(i==0)break;}
return null;}
function SetCookie(name,value){var argv=SetCookie.arguments;var argc=SetCookie.arguments.length;var expires=(argc>2)?argv[2]:null;if(expires){var date=new Date();date.setTime(date.getTime()+(expires*24*60*60*1000));var expires="; expires="+date.toGMTString();}
var path=(argc>3)?argv[3]:null;var domain=(argc>4)?argv[4]:null;var secure=(argc>5)?argv[5]:false;document.cookie=name+"="+escape(value)+
((expires==null)?"":("; expires="+expires))+
((path==null)?"":("; path="+path))+
((domain==null)?"":("; domain="+domain))+
((secure==true)?"; secure":"");}
function startCountdown(element,secondsremaining,showreply){$(element).innerHTML=secondsremaining;commentshowreply[element]=showreply;if(!countdownTimer[element]){countdownTimer[element]=setInterval('updateCountdown(\''+element+'\')',1000);}}
function updateCountdown(element){if(element==null){clearInterval(countdownTimer[element]);countdownTimer[element]=null;}else{var target=$(element);if(target){current=parseInt(target.innerHTML);current--;if(current<=0){target.innerHTML=0;clearInterval(countdownTimer[element]);countdownTimer[element]=null;var id=element.replace(/countdown/,'');var newtarget=$('cbody'+id);var content=newtarget.innerHTML.replace(/^[\s\S]*Seconds\)<\/a>/i,'');content=content.replace(/\<a [^<]*\[reply\].*$/i,'');var newhtml='<div class="c-body-inside" id="cbody-inside-'+id+'">'+content;if(commentshowreply[element]){var replylink=newtarget.innerHTML.replace(/^[\s\S]*setupcreply\(/i,'setupcreply(');replylink=replylink.replace(/\)\)[\s\S]*$/mi,')');newhtml+='<a href="?creplyto='+id+'#creplyform" onclick="return('+replylink+')" class="c-reply">[reply]</a>';}
newhtml+='</div>';newtarget.innerHTML=newhtml;$('c'+id).className='c-normal';}else{target.innerHTML=current;}}}}
function initPreview(){setInterval('updateAll()',1000);}
function updateAll(){$('titlepreview').innerHTML=$('title').value;$('bodytextpreview').innerHTML=$('bodytext').value;charCounter($('title'),75,$('titleCounter'));charCounter($('bodytext'),350,$('bodytextCounter'));}
function charLimit(field,maxLength){var inputLength=field.value.length;if(inputLength>=maxLength){field.value=field.value.substring(0,maxLength);}}
function charCounter(field,maxLength,countTarget){var inputLength=field.value.length;if(inputLength>=maxLength){field.value=field.value.substring(0,maxLength);}
countTarget.innerHTML=maxLength-field.value.length;}
function charCounterPreview(field,maxLength,countTarget,previewTarget,emptyFlag){charCounter(field,maxLength,countTarget);if(emptyFlag&&field.value.length==0){previewTarget.innerHTML='&nbsp;';}else{previewTarget.innerHTML=field.value;}}
function updateTopicPreview(text,cleantext){var target=$('topicpreview');target.innerHTML=text;target.href='/'+cleantext;}
function unpopp(){poppDiv=$('poppDiv');if(poppDiv){poppDiv.parentNode.removeChild(poppDiv);poppDiv=false;}}
function popp(id,text){unpopp();$('enclosure'+id).innerHTML+='<div id="poppDiv" class="inline-warning"><div><p><strong>Make your vote count!</strong> To '+text+' stories, <a href="/login">login</a> or <a href="/register">join Digg</a> for free.</p><a href="javascript:unpopp()"><img src="/img/close.gif" class="close" width="22" height="22" alt="Close" /></a></div></div>';return(false);}
function poppd(id){return(popp(id,'digg'));}
function poppe(id){return(popp(id,'email'));}
function poppr(id){return(popp(id,'bury'));}
function poppb(id){return(popp(id,'blog'));}
function toggleDisclosureWidget(id){var div=document.getElementById(id);if(div.className=='slide-show'){div.className='slide-hide';}else{div.className='slide-show';}
return(false);}
function tdw(id){return(toggleDisclosureWidget(id));}
function toggleLogin(){unpopp();toggleDisclosureWidget('login-form');return(false);}
function toggleGmap(){unpopp();toggleDisclosureWidget('map_holder');return(false);}
function toggleGal(){unpopp();toggleDisclosureWidget('vnu_gal_holder');return(false);}
function toggleMstat(){unpopp();toggleDisclosureWidget('mstat_holder');return(false);}
function toggleMstatMain(){unpopp();toggleDisclosureWidget('mstat_main');return(false);}
function toggleAddStory(){toggleDisclosureWidget('story_holder');return(false);}
function toggleAddStoryComment(){toggleDisclosureWidget('storycomment_holder');return(false);}
function topsearch(){var all;if(all=$('search-all')){if(all.checked==true){$('search').action='/search';}
all.disabled=true;$('search-specific').disabled=true;}
$('top-submit').disabled=true;return true;}
function formHandler(){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;}
function openMiniguide()
{
	if(document.all||document.layers) window.open('/miniguides/miniguide.asp?city=<%=strVnuCity%>', 'homewin', 'width=640,height=600,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/miniguides/miniguide.asp?city=<%=strVnuCity%>','homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=640,height=600');
}
function checkFieldsAddStory() {
missinginfo = "";
if (document.general_support.name.value == "") {
missinginfo += "\n     -  Name";
}
if ((document.general_support.submit_by.value == "") ||
(document.general_support.submit_by.value.indexOf('@') == -1) ||
(document.general_support.submit_by.value.indexOf('.') == -1)) {
missinginfo += "\n     -  Email address";
}
if (document.general_support.venue.value == "") {
missinginfo += "\n     -  Venue Name";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
function checkFieldsAddStory()
{
	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

	if (document.general_support.headline.value == "") {
	missinginfo += "\n     -  Missing Headline";
	}
	if (document.general_support.story.value == "") {
	missinginfo += "\n     -  Missing Story";
	}
	if (document.general_support.ssex.value == "") {
	missinginfo += "\n     -  Missing Their Sex";
	}
	if ( (document.general_support.ssex.value != "M") && (document.general_support.ssex.value != "m") && (document.general_support.ssex.value != "F") && (document.general_support.ssex.value != "f") ){
	missinginfo += "\n     -  Incorrect Sex (M or F only)";
	}
	if (document.general_support.city.value == "") {
	missinginfo += "\n     -  Missing City";
	}
    if (document.general_support.valcode.value.toUpperCase() != document.general_support.vc.value.toUpperCase()) {
	missinginfo += "\n     -  Incorrect validation code";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}
function checkFieldsAddStoryComment()
{
	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

	if (document.general_support.comment.value == "") {
	missinginfo += "\n     -  Missing Comment";
	}
    if (document.general_support.valcode.value.toUpperCase() != document.general_support.vc.value.toUpperCase()) {
	missinginfo += "\n     -  Incorrect validation code";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}
function checkRegistrationFields()
{

	missinginfo = "";

	var emailFilter=/^.+@.+\..{2,3}$/;
    var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/

    if (document.general_support.email.value.match(illegalChars)) {
    	missinginfo += "\n     -  Invalid Email Address";
    }
    if (!(emailFilter.test(document.general_support.email.value))) {
    	missinginfo += "\n     -  Invalid Email Address";
    }

	if (document.general_support.username.value == "") {
	missinginfo += "\n     -  Missing Username";
	}
	if (document.general_support.pwd.value == "") {
	missinginfo += "\n     -  Missing Password";
	}
	if (document.general_support.cpwd.value == "") {
	missinginfo += "\n     -  Missing Password Confirm";
	}
	if (document.general_support.pwd.value != document.general_support.cpwd.value) {
	missinginfo += "\n     -  Passwords don't match";
	}
	if (document.general_support.sex.value == "") {
	missinginfo += "\n     -  Missing Sex";
	}
	if ( (document.general_support.sex.value != "M") && (document.general_support.sex.value != "m") && (document.general_support.sex.value != "F") && (document.general_support.sex.value != "f") ){
	missinginfo += "\n     -  Incorrect Sex (M or F only)";
	}
	if (document.general_support.city.value == "") {
	missinginfo += "\n     -  Missing City";
	}
	if (document.general_support.email.value == "") {
	missinginfo += "\n     -  Missing Email";
	}
    if ( ( (document.general_support.born.value < 1900 ) ||
    (document.general_support.born.value > 2000) ) && document.general_support.born.value != "") {
    missinginfo += "\n     -  Dodgy year of birth";
    }
    if (document.general_support.valcode.value.toUpperCase() != document.general_support.vc.value.toUpperCase()) {
	missinginfo += "\n     -  Incorrect validation code";
	}

	if (missinginfo != "") {
	missinginfo ="_____________________________\n" +
	"Sorry, please correct the following:\n" +
	missinginfo + "\n_____________________________" +
	"\nPlease re-enter and submit again!";
	alert(missinginfo);
	return false;
	}
	else return true;
}

function checkFields() {
missinginfo = "";
if (document.general_support.username.value == "") {
missinginfo += "\n     -  Missing username";
}
if (document.general_support.password.value == "") {
missinginfo += "\n     -  Missing password";
}
if (document.general_support.password_conf.value == "") {
missinginfo += "\n     -  Missing password confirmation";
}
if (document.general_support.password.value != document.general_support.password_conf.value) {
missinginfo += "\n     -  Passwords don't match";
}
if (document.general_support.firstname.value == "") {
missinginfo += "\n     -  Missing first name";
}
if (document.general_support.sex.value == "") {
missinginfo += "\n     -  Missing sex(!)";
}
if (document.general_support.city.value == "") {
missinginfo += "\n     -  Missing city(!)";
}
if ( ( (document.general_support.born.value < 1900 ) ||
(document.general_support.born.value > 2000) ) && document.general_support.born.value != "") {
missinginfo += "\n     -  Dodgy year of birth";
}
if ((document.general_support.email.value == "") ||
(document.general_support.email.value.indexOf('@') == -1) ||
(document.general_support.email.value.indexOf('.') == -1)) {
missinginfo += "\n     -  Email address";
}

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"Oops. The following problems were found:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}

function OnChangedUsername()
{
    if(document.general_support.username.value == "") {
        document.general_support.btnCheckAvailability.disabled = true;
    }
    else
    {
        document.general_support.btnCheckAvailability.disabled = false;
    }
}
function OnCheckAvailability()
{
    if(window.XMLHttpRequest)
    {
        oRequest = new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        oRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }

    oRequest.open("POST", "check_username.asp", true);
    oRequest.onreadystatechange = UpdateCheckAvailability;

    oRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oRequest.send("strCmd=availability&strUsername=" + document.general_support.username.value);
}

function UpdateCheckAvailability()
{
    if(oRequest.readyState == 4)
    {
        if(oRequest.status == 200)
        {
            document.getElementById("Available").innerHTML = oRequest.responseText;
        }
        else
        {
            document.getElementById("Available").innerHTML = "Asychronous Error";
        }
    }
}
function openPhoto(member,photo)
{
	if(document.all||document.layers) window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo, 'homewin', 'width=500,height=480,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=500,height=480');
}
function openPhotoWindow(member,photo)
{
	if(document.all||document.layers) window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo, 'homewin', 'width=500,height=460,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/view_photo.asp?name=' + member + '&photo=' + photo,'homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=500,height=460');
}
function openEditPhotoWindow()
{
	if(document.all||document.layers) window.open('/members/edit_photo.asp', 'homewin', 'width=480,height=380,top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,fullscreen=no,scrollbars=no,resizable=no,copyhistory=no,alwaysRaised=yes');
	else window.open('/members/edit_photo.asp','homewin','toolbar=no,status=no,fullscreen=no,scrollbars=no,resizable=no,width=480,height=380');
}
