var favarray = new Array();
var current_tab = false;
var favcookie;
var emailclick = false;
var new_poll = false;

function set_bwb_email(){

	if (emailclick)
	return true;

if (document.getElementById("chk_agree2").value == 0) { 
	alert("You have to accept the Privacy Policy to proceed");
	document.getElementById("wbw_email_error").style.display = 'none';
	return true;
}


	emailclick = true;
	xmlhttp2 = new getXMLHTTP();
	xmlhttp2.onreadystatechange = function( ){


		if ( xmlhttp2.readyState == 4 ) {
			setEmailClick();
			document.getElementById("wbw_email_error").style.display = 'none';

			switch(xmlhttp2.responseText){
				case "SET":
				document.getElementById("wbw_email_div").innerHTML = "<div style='margin-top:4px;padding:5px;display:block;border:1px solid #fc85c5;width:282px;'><b>Thank you for registering!</b><br />We have already sent your first weekly email.<br /> Please check your spamfilter if you did not receive the email.</div>";
				//document.getElementById("wbw_email_div").display = 'none';
				break;

				case "COOKIE":
				alert('You\'ve already setup your week by week email.');
				break;

				case "NOWEEK":
				document.getElementById("wbw_email_error").style.display = 'block';
				document.getElementById("wbw_email_error").innerHTML = "Attention! Form was not filled out correctly<div style='overflow:hidden;height:7px;'></div>You've entered an incorrect due date.";
				break;

				case "NOEMAIL":
				//document.getElementById("wbw_email_div").innerHTML = "<div style='margin-top:4px;padding:5px;display:block;border:1px solid #fc85c5;width:282px;'><b>Thank you for registering!</b><br />We have already sent your first weekly email.<br /> Please check your spamfilter if you did not<br />receive the email.</div>";
				document.getElementById("wbw_email_error").style.display = 'block';
				document.getElementById("wbw_email_error").innerHTML = "Attention! Form was not filled out correctly<div style='overflow:hidden;height:7px;'></div>Your email address is not correct.";
				break;

				default:
				document.getElementById("wbw_email_error").style.display = 'block';
				document.getElementById("wbw_email_error").innerHTML = "Attention! Form was not filled out correctly<div style='overflow:hidden;height:7px;'></div>Please make sure you filled in everything properly";
				break;


			}
		}
	}
	xmlhttp2.open( "GET", "/ajax/set_wbw_email.php?email=" + document.wbw_email_form.dd_email.value + "&day=" + document.wbw_email_form.dd_day.value + "&month=" + document.wbw_email_form.dd_month.value + "&year=" + document.wbw_email_form.dd_year.value, true );
	xmlhttp2.send(null);

}


function setEmailClick(){
	emailclick = false;
}



function rndtime(){ return Math.floor(Math.random() * 100000) }

function checkLoggedIn() {
	return document.cookie.indexOf('bnw_logged_in=1') != -1;
}

function headerBlockCheckLogin() {
	try {
		if ( checkLoggedIn() ) {
			document.getElementById('login').style.display = 'none';
			document.getElementById('logout').style.display = 'block';
		}
	} catch(e) {
		alert(e.message);
	}
}

function footerBlockCheckLogin() {
	try {
		if ( checkLoggedIn() ) {
			var links = document.getElementById('footer_links').getElementsByTagName('A');
			for ( var i = 0; i < links.length; i++ ) {
				if ( links[i].className == 'login' )
				links[i].style.display = 'none';
				else if ( links[i].className == 'logout' )
				links[i].style.display = 'inline';
			}
		}
	} catch(e) {
		alert(e.message);
	}
}

function getForm(nobj) {
	while(nobj.nodeName != 'FORM'){
		nobj = nobj.parentNode;
	}
	return nobj;
}

function frmKeyPress(obj,e) {
	if (document.all) {
		var evnt = window.event;
		x=evnt.keyCode;
	}else{
		x=e.keyCode;
	}
	if (x == 13) {
		obj.submit();
	}
}

function frmSubmit(obj) {
	frmObj = getForm(obj);
	frmObj.submit();
}

function frmReset(obj) {
	frmObj = getForm(obj);



	if (document.getElementById("mselect_box2")){
		document.getElementById("mselect_box2").innerHTML = '';
		document.getElementById("s_origins").value = '';
	}

	if (document.getElementById("mselect_cbox2")){
		document.getElementById("mselect_cbox2").innerHTML = '';
		document.getElementById("s_categories").value = '';
	}


	frmObj.reset();

	inp = frmObj.getElementsByTagName("input");
	for(i=0;i<inp.length;i++){
		if (inp[i].getAttribute("type") == 'select'){
			inp[i].selectedIndex = 0;
		}
		if (inp[i].value == '' || inp[i].value== 'Select'){
			//inp[i].disabled = true;
		}
	}

}

function frmAction(obj,action) {
	frmObj = getForm(obj);
	frmObj.action = action;
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function getXMLHTTP() {
	var xmlhttp;
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {
			xmlhttp = false;
		}
	}

	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}




var fl_prev_id = false;
var fl_prev_subforums = false;

function forumLinksClick(id, type, subforums) {
	if ( type == 'main' && subforums.length > 0 ) {
		if ( fl_prev_id == id ) {
			forumLinksCollapse(id, subforums);
		} else {
			if ( fl_prev_id )
			forumLinksCollapse(fl_prev_id, fl_prev_subforums);
			forumLinksExpand(id, subforums);
		}
	} else {
		document.location.href = '/forum/forum' + id + '.html';
	}
}



clr = '#d74995';
clr2 = '#FFFFFF';

function cal_hover(obj){
	if (obj.style.backgroundColor != clr){
		obj.setAttribute('oldbg',obj.style.backgroundColor);
		obj.style.backgroundColor = clr;
		obj.style.cursor = 'hand';
		link = obj.childNodes[0];
		link.style.color = clr2;
	}else{
		obj.setAttribute('selected','true');
	}
}


function cal_out(obj){

	if(!obj.getAttribute('selected')){
		obj.style.backgroundColor = obj.getAttribute('oldbg');
		link = obj.childNodes[0];
		link.style.color = clr;

	}
}

function cal_onclick(obj){
	link = obj.childNodes[0];
	self.location.href = link.href;
}


function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function submitCuteKid(){
	document.getElementById('next_abuse').style.display = 'none';	
	//document.getElementById('cute-kid-form').style.display = '';	
	document.getElementById('frame_box').style.display = '';	
    document.getElementById('abuse_popup1').style.display='none';
    if (document.getElementById('cute_kid_btn1') != null) { document.getElementById('cute_kid_btn1').style.display='none'; }
    if (document.getElementById('cute_kid_btn2') != null) { document.getElementById('cute_kid_btn2').style.display='none'; }
}

function closeCuteKid(){
	document.getElementById('next_abuse').style.display = '';	
	//document.getElementById('cute-kid-form').style.display = 'none';	
	document.getElementById('frame_box').style.display = 'none';	
    if (document.getElementById('cute_kid_btn1') != null) { document.getElementById('cute_kid_btn1').style.display=''; }
    if (document.getElementById('cute_kid_btn2') != null) { document.getElementById('cute_kid_btn2').style.display=''; }
}

function submissionPollEnd() {
    document.getElementById('thanks_note').style.display='none';
}

function showAbusePopup(t) {
    document.getElementById('abuse_popup1').style.display='block';
    if (new_poll) {
        document.getElementById('abuse_popup1').style.top='463px';
    } else {
        document.getElementById('abuse_popup1').style.top='458px';
    }
    frames['frame_box'].document.getElementById('cute-kid-gender').style.visibility='hidden';
}

function postAbusePopup() {
    if (document.getElementById('abuse_popup_reason').options[document.getElementById('abuse_popup_reason').selectedIndex].value == '_') {
        alert('Please select a reason for this report');
        return false;        
    }
    xmlhttp_abuse = new getXMLHTTP();
	xmlhttp_abuse.onreadystatechange = function( ){

        if ( xmlhttp_abuse.readyState == 4 ) {
            document.getElementById('abuse_popup1').style.display='none';
            frames['frame_box'].document.getElementById('cute-kid-gender').style.visibility='visible';
            alert('Thank you for bringing this to our attention.');
    	}
    	
    }
    xmlhttp_abuse.open( "GET", "/ajax/send_abuse_email.php?photo_id=" + abuse_photo_id + "&reason=" + escape(document.getElementById('abuse_popup_reason').options[document.getElementById('abuse_popup_reason').selectedIndex].value) + "&comment=" + escape(document.getElementById('abuse_popup_comment').value), true );
    xmlhttp_abuse.send(null);
}