function initPage()
{
	var inputs = document.getElementsByTagName("input");
	for (var i=0; i<inputs.length; i++)
	{
		if (inputs[i].type == "text" && (inputs[i].name == "email" || inputs[i].name == "search" || inputs[i].name == "s" || inputs[i].name == "wpsb_email"))
		{
			var form = getAncestor(inputs[i], "form");
			if (form)
				form.onsubmit = handleSubmit;

			inputs[i].onfocus = function () {
					if ((this.value == "Enter email address") || (this.value == "Enter search term(s) here..."))
						this.value = "";
				}
			inputs[i].onblur = function () {
					if (this.value == "" && (this.name == "email" || this.name == "wpsb_email")) this.value = "Enter email address";
					if (this.value == "" && (this.name == "search" || this.name == "s") ) this.value = "Enter search term(s) here...";
				}	
		}
	}
}

function handleSubmit()
{
	var re = new RegExp('^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$');
	

    var element = this.elements["email"];
	if (element)
	{
		if (element.value == "")
		{
			alert("Email address is empty!");
			return false;
		}
		else
			return element.value.match(re)
				|| (alert("You have entered incorrect email address!"), false);
	}
	return true;
}

function getAncestor(element, tagName)
{
	var node = element;
	while (node.parentNode && (!node.tagName ||
			(node.tagName.toUpperCase() != tagName.toUpperCase())))
		node = node.parentNode;
	return node;
}

function initAccordion() {
		var _box = $('accordion');
		if (_box) {
			var _scookie = false;
		//Cookie.remove(_scookie);
			if (Cookie.get("slide"))
			{
				_scookie = Cookie.get("slide").split(",");
			}
			var accordion = new SlideDropDown(_box.getElements('h3'),_box.getElements('h3'),_box.getElements('div.slider'), {
			alwaysHide: true,
			opacity: false,
			cookie: _scookie,
			initialize: function() {
				Cookie.remove(_scookie);
				Cookie.set("slide", this.serialize(), {duration: 1});
			},
			onActive: function(toggler, element){
				toggler.className = toggler.className.replace("close", "");
			},
		onBackground: function(toggler, element){
			
			if (toggler.className.indexOf("close") == -1)
			{
				toggler.className += " close";
			}
		},
		onComplete: function() {
			Cookie.remove(_scookie);
			Cookie.set("slide", this.serialize(), {duration: 1});
		}
	}, _box);
	}
}

function initSummary() {
	var _box = $('content');
	if (_box) {
	var acc = new SlideDropDown(_box.getElements('div.summary div.head a'), _box.getElements('div.summary div.head a'), _box.getElements('div.summary div.summary-slide'), {
			alwaysHide: true,
			opacity: false,
			cookie: false,
			onActive: function(toggler, element) {
				toggler.innerHTML = "minimize";
				if (toggler.className.indexOf("close") == -1)
				{
					toggler.className += " close";
				}
			},
			onBackground: function(toggler, element){
				toggler.className = toggler.className.replace("close", "");
				toggler.innerHTML = "maximize";
			}
		}, _box);
	}
}

if (window.addEventListener) {
	window.addEventListener("load", initPage, false);
	window.addEventListener("load", initAccordion, false);
	window.addEventListener("load", initSummary, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initPage);
	window.attachEvent("onload", initAccordion);
	window.attachEvent("onload", initSummary);
}

window.addEvent('load', initAccordion);
if (window.addEventListener) {
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initPage);
}






window.addEvent('domready', function(){
  var cook = Cookie.get("safe");
  if( cook ==  "sfw" ){
    $('sfw').addClass('active');
    $$('#content img').setStyle('display', 'none'); 
    $$('#content embed').setStyle('display', 'none'); 
    $$('#ad_banner a img').setStyle('display', 'block'); 
    $$('.bookmark img').setStyle('display', 'block'); 
 //   $$('img.noBorder').setStyle('display', 'block'); 
   $$('img.captcha').setStyle('display', 'block'); 
  }else{
    $('nsfw').addClass('active');
    $$('#content img').setStyle('display', 'block'); 
    $$('#content embed').setStyle('display', 'block'); 
}



});

function sfw(){
   $('sfw').addClass('active');
   $('nsfw').removeClass('active');
   Cookie.set('safe', 'sfw', {duration: 30}); 

   $$('#content img').setStyle('display', 'none'); ; 
   $$('#content embed').setStyle('display', 'none'); 
   $$('#ad_banner img').setStyle('display', 'block'); 
   $$('.bookmark img').setStyle('display', 'block'); 
  // $$('img.noBorder').setStyle('display', 'block'); 
   $$('img.captcha').setStyle('display', 'block'); 

}

function nsfw(){
   $('nsfw').addClass('active');
   $('sfw').removeClass('active');
   Cookie.set('safe', 'nsfw', {duration: 30}); 

   $$('#content img').setStyle('display', 'block'); 
   $$('#content embed').setStyle('display', 'block'); 


}


