var onload_vars = new Array();

function addLoadEvent(func)
{
	onload_vars[onload_vars.length] = func;
}

function triggerLoadEvents()
{
	for(var i = 0;i < onload_vars.length;i++)
	    eval(onload_vars[i]);
}

addLoadEvent('addwarning();');
addLoadEvent('startTimers();');
window.onload = triggerLoadEvents;

function startTimers()
{
	setInterval("runTimers()",1000);
}

function runTimers()
{
    var spans = document.getElementsByTagName("span");
    if (!spans) {
        return;
    }

    for (var x = 0; x != spans.length; x++)
    {
        if (spans[x].className == "time")
        {
        	var time = parseInt(spans[x].getAttribute("seconds"));
        	
        	if(spans[x].getAttribute("count") == "up")
        	{
        		time = time + 1;
        	}
        	else
        	{
        		time = time - 1;
        		
        		if(time < 1)
        		{
        			//spans[x].innerHTML = spans[x].getAttribute("complete_text");
        			spans[x].className = "timeComplete";
        		}
        	}
        	
            spans[x].setAttribute("seconds", time);
            spans[x].innerHTML =  getTimeInWords(time);
        }
    }
}

function getTimeInWords(iSeconds)
{
	if(iSeconds < 60)
		return iSeconds + " second" + (iSeconds != 1 ? "s" : "");
	
	if(Math.floor(iSeconds/60) < 60)	
		return Math.floor(iSeconds/60) + " minute" + (Math.floor(iSeconds/60) != 1 ? "s" : "");		
		
	if(Math.floor(iSeconds/3600) < 24)	
		return Math.floor(iSeconds/3600) + " hour" + (Math.floor(iSeconds/3600) != 1 ? "s" : "");	
		
	return Math.floor(iSeconds/86400) + " day" + (Math.floor(iSeconds/86400) != 1 ? "s" : "");		
}

//Edit the informaiton between the quotes below with the path to your image.
var imagePath = "images/tooltiparrow.gif";

function addwarning()
{
    var thealinks = document.getElementsByTagName("label");
    if (!thealinks) {
        return;
    }

    for (var x = 0; x != thealinks.length; x++) {

        if (thealinks[x].className == "addToolTip") {
            thealinks[x].setAttribute("tooltiptext", thealinks[x].title);
            thealinks[x].removeAttribute("title");
            thealinks[x].onmouseover = function gomouseover() {
                ddrivetip(this.getAttribute("tooltiptext"))
            };
            thealinks[x].onmouseout = function gomouseout() {
                hideddrivetip();
            };
        }
    }

    thealinks = document.getElementsByTagName("span");

    for (var x = 0; x != thealinks.length; x++) {

        if (thealinks[x].className == "addToolTip") {
            thealinks[x].setAttribute("tooltiptext", thealinks[x].title);
            thealinks[x].removeAttribute("title");
            thealinks[x].onmouseover = function gomouseover() {
                ddrivetip(this.getAttribute("tooltiptext"))
            };
            thealinks[x].onmouseout = function gomouseout() {
                hideddrivetip();
            };
        }
    }
    
    thealinks = document.getElementsByTagName("tr");

    for (var x = 0; x != thealinks.length; x++) {

        if (thealinks[x].className == "addToolTip") {
            thealinks[x].setAttribute("tooltiptext", thealinks[x].title);
            thealinks[x].removeAttribute("title");
            thealinks[x].onmouseover = function gomouseover() {
                ddrivetip(this.getAttribute("tooltiptext"))
            };
            thealinks[x].onmouseout = function gomouseout() {
                hideddrivetip();
            };
        }
    }
}

var offsetfromcursorX = -7; //Customize x offset of tooltip
var offsetfromcursorY = 23; //Customize y offset of tooltip
var offsetdivfrompointerX = 13; //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY = 13; //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).
document.write('<div id="theToolTip"></div>'); //write out tooltip DIV
document.write('<img id="ToolTipPointer" src="' + imagePath + '">'); //write out pointer image
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var enabletip = false;
if (ie || ns6) {
    var tipobj = document.all ? document.all["theToolTip"] : document.getElementById ? document.getElementById("theToolTip") : "";
}

var pointerobj = document.all ? document.all["ToolTipPointer"] : document.getElementById ? document.getElementById("ToolTipPointer") : "";

function ietruebody() {
    return (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function ddrivetip(thetext, thewidth, thecolor) {
    thewidth = 300;
    if (ns6 || ie) {
        if (typeof thewidth !== "undefined") {
            tipobj.style.width = thewidth + "px";
        }
        if (typeof thecolor !== "undefined" && thecolor !== "") {
            tipobj.style.backgroundColor = thecolor;
        }
        tipobj.innerHTML = thetext;
        enabletip = true;
        return false;
    }
}

function positiontip(e) {
    if (enabletip) {
        var nondefaultpos = false;
        var curX = (ns6) ? e.pageX : event.clientX + ietruebody().scrollLeft;
        var curY = (ns6) ? e.pageY : event.clientY + ietruebody().scrollTop;
        //Find out how close the mouse is to the corner of the window
        var winwidth = ie && !window.opera ? ietruebody().clientWidth : window.innerWidth - 20;
        var winheight = ie && !window.opera ? ietruebody().clientHeight : window.innerHeight - 20;

        var rightedge = ie && !window.opera ? winwidth - event.clientX - offsetfromcursorX : winwidth - e.clientX - offsetfromcursorX;
        var bottomedge = ie && !window.opera ? winheight - event.clientY - offsetfromcursorY : winheight - e.clientY - offsetfromcursorY;

        var leftedge = (offsetfromcursorX < 0) ? offsetfromcursorX * (-1) : -1000;

        //if the horizontal distance isn't enough to accomodate the width of the context menu
        if (rightedge < tipobj.offsetWidth) {
            //move the horizontal position of the menu to the left by it's width
            tipobj.style.left = curX - tipobj.offsetWidth + "px";
            nondefaultpos = true;
        }
        else if (curX < leftedge) {
            tipobj.style.left = "5px";
        }
        else {
            //position the horizontal position of the menu where the mouse is positioned
            tipobj.style.left = curX + offsetfromcursorX - offsetdivfrompointerX + "px";
            pointerobj.style.left = curX + offsetfromcursorX + "px";
        }

        //same concept with the vertical position
        if (bottomedge < tipobj.offsetHeight) {
            tipobj.style.top = curY - tipobj.offsetHeight - offsetfromcursorY + "px";
            nondefaultpos = true;
        }
        else {
            tipobj.style.top = curY + offsetfromcursorY + offsetdivfrompointerY + "px";
            pointerobj.style.top = curY + offsetfromcursorY + "px";
        }
        tipobj.style.visibility = "visible";
        if (!nondefaultpos) {
            pointerobj.style.visibility = "visible";
        }
        else {
            pointerobj.style.visibility = "hidden";
        }
    }
}

function hideddrivetip() {
    if (ns6 || ie) {
        enabletip = false;
        tipobj.style.visibility = "hidden";
        pointerobj.style.visibility = "hidden";
        tipobj.style.left = "-1000px";
        tipobj.style.backgroundColor = '';
        tipobj.style.width = '';
    }
}

document.onmousemove = positiontip;

var currentUser = null;
var currentIndex = 0;

function loadUsers()
{
	var listBox = document.getElementById('listBox');
	var newHtml = "";
	
	for(var x = 0; x < users.length; x++)
	{
		newHtml += "<option value='" + x + "'>"+users[x].username+"</option>";
	}
	
	listBox.innerHTML = newHtml;
	
	var listBox = document.getElementById('listBox');
	currentUser = users[0];
	currentIndex = 0;

	document.getElementById('listBox').value = currentIndex;

	printUser(currentUser);
}

function selectUser()
{
	var listBox = document.getElementById('listBox');
	currentUser = users[listBox.value];
	currentIndex = listBox.value;

	printUser(currentUser);
}

function printUser(oUser)
{
	document.getElementById('current_user_name').innerHTML = "@" + oUser.username;
	document.getElementById('current_user_image').src = oUser.image_url;
	document.getElementById('current_user_description').value = oUser.description;
	document.getElementById('current_user_url').value = oUser.url;
	document.getElementById('current_user_location').value = oUser.user_location;
	document.getElementById('current_user_real_name').value = oUser.real_name;
	
	document.getElementById('follow_button').onclick = function(){follow(oUser.id, oUser.username); skip();}
}

function skip()
{
	currentIndex++;
	
	document.getElementById('listBox').value = currentIndex;
	
	if(currentIndex >= users.length)
	{
		alert("You have followed all the current users, refresh the page for more!", "notice");
		return;
	}
	
	currentUser = users[currentIndex];

	printUser(currentUser)
}


function selectAll() {
    var aa = document.getElementById('inboxForm');
    var checked = document.getElementById('mainCheckBox').checked;
    for (var i = 0; i < aa.elements.length; i++) {
        aa.elements[i].checked = checked;
    }

}

function alphanumeric(alphane) {
    var numaric = alphane;
    for (var j = 0; j < numaric.length; j++) {
        var alphaa = numaric.charAt(j);
        var hh = alphaa.charCodeAt(0);
        if ((hh > 47 && hh < 58) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123)) {} else {
            return false;
        }
    }
    return true;
}

function capitalizeMe(obj) {
    val = obj;
    newVal = '';
    val = val.split(' ');
    for (var c = 0; c < val.length; c++) {
        newVal += val[c].substring(0, 1).toUpperCase() + val[c].substring(1, val[c].length) + ' ';
    }
    return newVal;
}

function urlencode(str) {
return escape(str).replace('+', '%2B').replace('%20', '+').replace('*', '%2A').replace('/', '%2F').replace('@', '%40');
}

function ajax(url) {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e) {
        // Internet Explorer
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Your browser does not support AJAX!");
                return false;
            }
        }
    }

    xmlHttp.onreadystatechange = function () {
        if (xmlHttp.readyState == 4)
        {
            eval(xmlHttp.responseText);
        }
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

function tweet(text)
{
	window.open("http://twitter.com/?status="+text);
	//ajax("tweet.php?status=" + urlencode(text));
}

function follow(id, name)
{
	ajax("follow.php?id=" + id + "&name=" + name);
}

function follow_vip()
{
	ajax("follow_vip.php");
	document.getElementById("follow_vip_button").disabled = true;
	document.getElementById("follow_vip_button").value = "Following All VIP Users...";
}

function changePoints(amt)
{
	document.getElementById("current_points").innerHTML = parseInt(document.getElementById("current_points").innerHTML) + amt;
	document.getElementById("total_points").innerHTML = parseInt(document.getElementById("total_points").innerHTML) + amt;
	Notifier.notifyChangePoints(amt);
}

function showBulletin()
{
	fade("<h2>Welcome to InfiniteAdds.com!</h2><br><center>Start earning some points by posting a tweet and getting your followers to sign up!<br>The more points you have, the more followers you get!<br><br>You can get points in a few different ways, for more info read the FAQ!<br><br><input value='Post' type='button' class='button' onclick='tweet(document.getElementById(\"post_text\").value);document.getElementById(\"light\").style.display=\"none\";document.getElementById(\"fade\").style.display=\"none\";'><input value='Skip' type='button' class='button' onclick='document.getElementById(\"light\").style.display=\"none\";document.getElementById(\"fade\").style.display=\"none\";'></center>");
}

function fade(text)
{
	document.getElementById('light').style.display='block';
	document.getElementById('fade').style.display='block';		
	document.getElementById('light').innerHTML="<table><tr><td width='200px'><img src='http://i19.photobucket.com/albums/b190/erb2011/friendtrain/notify.png' width='100px'></td><td>" + text + "</td></tr></table>";
}









var Notifier=new function(){
	// real alert function placeholder
	this._alert=null;
	// return Notifier object methods
	return {
		// m=message,c=classname
		notify:
			function(m,c){
				// we may consider adding frames support
				var w=this.main;
				// shortcut to document
				var d=this.main.document;
				// canvas, window width and window height
				var r=d.documentElement;
				var ww=w.innerWidth?w.innerWidth+w.pageXOffset:r.clientWidth+r.scrollLeft;
				var wh=w.innerHeight?w.innerHeight+w.pageYOffset:r.clientHeight+r.scrollTop;
				// create a block element
				var b=d.createElement('div');
				b.id='Message';
				b.className=c||'';
				
				var beforeElement = d.getElementById("sidenav");
				
				if(beforeElement == null)
					beforeElement = d.body;
				
				// insert block in to body
				b=beforeElement.insertBefore(b,beforeElement.firstChild);
				// write HTML fragment to it
				b.innerHTML=m;
				// save width/height before hiding
				var bw=b.offsetWidth;
				var bh=b.offsetHeight;
				// hide, move and then show
				b.style.display='none';
				//b.style.top=Math.random()*(wh-bh)+'px';// random y position
//				b.style.top=wh-bh+'px';// this is to place it to the bottom
				//b.style.left=Math.random()*(ww-bw)+'px';// random x position
//				b.style.left=ww-bw+'px';// this is to place it to the right
				b.style.display='block';
				// fadeout block if supported
				setFading(b,100,0,2000,function(){beforeElement.removeChild(b);});
			},
		// m=message,c=classname
		notifyChangePoints:
			function(m,c){
				// we may consider adding frames support
				var w=this.main;
				// shortcut to document
				var d=this.main.document;
				// canvas, window width and window height
				var r=d.documentElement;
				
				for(var l = 0; l < 2; l++)
				{
					// create a block element
					var b=d.createElement('span');
					b.className=c||'';
					
					var beforeElement = d.getElementById(l == 0 ? "current_points_mod" : "total_points_mod");
					
					if(beforeElement == null)
						beforeElement = d.body;
					
					// insert block in to body
					b=beforeElement.insertBefore(b,beforeElement.firstChild);
					// write HTML fragment to it
					b.innerHTML= ((m > 0) ? "+" : "") + m + " ";
					
					if(m > 0)
						b.style.color = "#00FF00";
					else
						b.style.color = "#FF0000";
					// fadeout block if supported
					setFading(b,100,0,2000,function(){beforeElement.removeChild(b);});
				}
			},
		// initialize Notifier object
		init:
			function(w,s){
				// save window
				this.main=w;
				this.classname=s||'';
				// if not set yet
				if(this._alert==null){
					// save old alert function
					this._alert=this.main.alert;
					// redefine alert function
					this.main.alert=function(m, s2)
					{
						if(s2 == '')
							s2 = s;
						Notifier.notify(m,s2);
					}
				}
			},
		// shutdown Notifier object
		shut:
			function(){
				// if redifine set
				if(this._alert!=null){
					// restore old alert function
					this.main.alert=this._alert;
					// unset placeholder
					this._alert=null;
				}
			}
	};
};

// apply a fading effect to an object
// by applying changes to its style
// @o = object style
// @b = begin opacity
// @e = end opacity
// @d = duration (millisec)
// @f = function (optional)
function setFading(o,b,e,d,f){
	var t=setInterval(
		function(){
			b=stepFX(b,e,2);
			setOpacity(o,b/100);
			if(b==e){
				if(t){clearInterval(t);t=null;}
				if(typeof f=='function'){f();}
			}
		},d/50
	);
}

// set opacity for element
// @e element
// @o opacity
function setOpacity(e,o){
	// for IE
	e.style.filter='alpha(opacity='+o*100+')';
	// for others
	e.style.opacity=o;
}

// increment/decrement value in steps
// checking for begin and end limits
//@b begin
//@e end
//@s step
function stepFX(b,e,s){
	return b>e?b-s>e?b-s:e:b<e?b+s<e?b+s:e:b;
}

var __alert=window.alert;

Notifier.init(window, 'notifier');











