function gotoNext(hwnd)
	local page,position,a,b,c,position2
	local title, url = GetDocInfo(hwnd)
        	local position=string.find(url,"page=")
	local position2=string.find(url,"start=")
	local position3=string.find(url,"pagenumber=")
       	if(position) then
			a=string.sub(url,1,position+4)
			c=string.sub(url,position+7)
			d=string.sub(url,position+6,position+6)
			if d<='9' and d>='0' then
				b=string.sub(url,position+5,position+6)
			else
				b=string.sub(url,position+5,position+5)
				c=string.sub(url,position+6)
			end
			b=b+1
			a=a .. b .. c
                        	open(a)
		    elseif (position2) then
			a=string.sub(url,1,position2+5)
			c=string.sub(url,position2+8)
			b=string.sub(url,position2+6,position2+7)
			b=b+10
			a=a .. b .. c	
			NavigateTo(a, OPEN_NORMAL)
		    elseif (position3) then
			a=string.sub(url,1,position3+10)
			c=string.sub(url,position3+13)
			d=string.sub(url,position3+12,position3+12)
			if d<='9' and d>='0' then
				b=string.sub(url,position3+11,position3+12)
			else
				b=string.sub(url,position3+11,position3+11)
				c=string.sub(url,position3+12)
			end
			b=b+1
			a=a .. b .. c
                        NavigateTo(a, OPEN_NORMAL)
		    elseif  (string.find(url,"www.google.com")) then
			a=url.."&start=10"
			NavigateTo(a, OPEN_NORMAL)
		    elseif  (string.find(url,"xitek.com")) then
			a=url.."&pagenumber=2"
			NavigateTo(a, OPEN_NORMAL)
		    else			
			url=url .. "&page=2"
			NavigateTo(url, OPEN_NORMAL)

       	end
end

function gotoPrevious(hwnd)
	local page,position,a,b,c
	local title, url = GetDocInfo(hwnd)
        position=string.find(url,"page=")
	position2=string.find(url,"start=")
	local position3=string.find(url,"pagenumber=")
       	if(position) then
			a=string.sub(url,1,position+4)
			c=string.sub(url,position+6)
			b=string.sub(url,position+5,position+5)
			b=b-1
			a=a .. b .. c
                        NavigateTo(a, OPEN, hwnd)
		    elseif (position2) then
			a=string.sub(url,1,position2+5)
			c=string.sub(url,position2+8)
			b=string.sub(url,position2+6,position2+7)
			b=b-10
			a=a .. b .. c	
			NavigateTo(a, OPEN, hwnd)
		    elseif (position3) then
			a=string.sub(url,1,position3+10)
			c=string.sub(url,position3+13)
			d=string.sub(url,position3+12,position3+12)
			if d<='9' and d>='0' then
				b=string.sub(url,position3+11,position3+12)
			else
				b=string.sub(url,position3+11,position3+11)
				c=string.sub(url,position3+12)
			end
			b=b-1
			a=a .. b .. c
                        NavigateTo(a, OPEN, hwnd)
		    else			
			url=url .. "&page=2"
			NavigateTo(url, OPEN, hwnd)

       	end
end

function xiteksort(hwnd)
	local title,url=GetDocInfo(hwnd)
	if (string.find(url,"xitek.com")) then
		-- local pos=string.find(url,"showthread")
		NavigateTo(string.gsub(url,"showthread","sorthread"),OPEN,hwnd)
	end
end