/*************************************************************************************
 Copyright © 2006-2010 by Walerian "Cobra" Walawski - http://walerian.info/
 Feel free to use code below however you'd like, but please keep this comment intact.
*************************************************************************************/

// StatCounter
var sc_project=4308160;
var sc_invisible=1;
var sc_partition=54;
var sc_click_stat=1;
var sc_security="24aeb652";

// Let's make document.getElementById shorter ;-) (by-id)
function bid(name)
{
	return document.getElementById(name);
}

// <body> onload
function bodyStart()
{
	antySpam();
	captchaAnimation();
}
window.onload = bodyStart;

// Safe (anty-spam) e-mail
function antySpam()
{
	if(bid('mail'))
	{
		bid('mail').innerHTML='\
		<a href="mailto:contact'+'@'+''+'simplest-image-hosting.net">contact'+''+'@'+'simplest-image-hosting.net</a>';
	}
}

// Captcha animation
function captchaAnimation()
{
	if(bid('captcha'))
	{
		setInterval("bid('captcha').src='captcha.jpg?'+new Date();",1000);
	}
}

// Upload
function upload()
{
	document.title='[Upload in progress] '+document.title;
	bid('uploadBox').style.visibility='hidden';
	bid('uploadBox').style.height='0px';
	bid('uploadBox').style.margin='0px';
	bid('uploadState').innerHTML='<div class="wait"><b>'+bid('fileName').value+'</b> upload in progress, please wait...</div>';
	bid('uploadForm').submit();
}

// TOS switch
function tosSwitch(link)
{
	if(link.getAttribute('href')=='#showFullTos')
	{
		bid('TOS-long').style.display='block';
		link.setAttribute('href','#hideFullTos');
		link.innerHTML='Hide full version...';
	}
	else
	{
		bid('TOS-long').style.display='none';
		link.setAttribute('href','#showFullTos');
		link.innerHTML='Full version...';
	}
}

// Firefox extension bar
function firefoxExtensionBar(action)
{
	// Firefox?
	if(navigator.userAgent.indexOf('Firefox')!=-1)
	{
		// Hide bar (or just renew cookie to make it perm.)
		if(action=='hide'||getCookie('firefoxExtensionBar')=='hide')
		{
			if(bid('firefoxExtensionBar'))
			{
				bid('firefoxExtensionBar').style.display='none';
			}
			setCookie('firefoxExtensionBar','hide');
		}
		
		// Show bar
		else
		{
			document.write('<div id="firefoxExtensionBar" style="color:#000000;font-size:14px;text-align:left;background:url(firefox-16x16.png) no-repeat 10px 5px #FFFBBB;border-bottom:1px solid #D6CA14;padding:5px 5px 5px 32px;margin:0 0 5px 0;">Using Firefox? Then we have something special for you! Upload images fast and easy with <a href="https://addons.mozilla.org/en-US/firefox/addon/13669/" style="color:#000000;font-size:14px;">our extension...</a> <input type="button" value="Hide" onclick="firefoxExtensionBar(\'hide\');" style="display:block;float:right;margin:-3px 0 0 0;"></div>');
		}
	}
}

// Cookies
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 cdate=new Date();
	cdate.setTime(cdate.getTime()+1000*60*60*24*30);
	document.cookie=name+'='+escape(value)+";expires="+cdate.toGMTString();
}
