/*------------------------------------------------------------------------
# CW2 Bump Me Plugin for Wordpress from customweb2.com  
# ------------------------------------------------------------------------
# Copyright (C) 2009 Netaxis IT Solutions Private Ltd. All Rights Reserved.
# Author: Netaxis IT Solutions Private Ltd
# Website:  http://www.customweb2.com 
-------------------------------------------------------------------------*/

/* A script to update the bump */

var xmlHttp
var currentobj
var initialof
var bumpobj
var aftervotetext

//Useful for compatibility
function function_exists( function_name ) 
{
    if (typeof function_name == 'string')
	{
        return (typeof window[function_name] == 'function');
    }
	else
	{
        return (function_name instanceof Function);
    }
}

//Javascript Function for JavaScript to communicate with Server-side scripts
function cw2_AJAXrequest(scriptURL) 
{
	xmlHttp=cw2GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	} 
	xmlHttp.onreadystatechange=cw2bumpChanged;
	xmlHttp.open("GET",scriptURL,true);
	xmlHttp.send(null);
}

function cw2GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function cw2bumpChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		var bumpno = xmlHttp.responseText;
		
		currentobj_obj = document.getElementById(currentobj);
		bumpobj_obj = document.getElementById(bumpobj);
		bumpwidgetobj_obj = currentobj_obj.parentNode;
		bumpbuttonobj_obj = bumpobj_obj.parentNode;

		currentobj_obj.innerHTML = parseInt(bumpno)+parseInt(initialof);
		bumpobj_obj.innerHTML = aftervotetext;
	}
}

function bump(obj, votelinkobj, aftervote, postID ,userID, baseURL,initial,time) 
{
	currentobj = obj;
	initialof=initial;
	bumpobj = votelinkobj;
	gpostid = postID;
	aftervotetext = aftervote;
	var scripturl = baseURL+"/cw2bumpmeinterface.php?tid=total&uid="+userID+"&pid="+postID+"&time="+time+"&auth="+Math.random();
	cw2_AJAXrequest(scripturl);
}

