
if(document.getElementById("perk_box")) {
	document.getElementById("perk_box").style.left= (findX(document.getElementById("openPopup"))-130)+"px"; 
	document.getElementById("perk_box").style.top = (findY(document.getElementById("openPopup"))+18)+"px";	
}	
function findX(obj){
	var x=0,y=0;
	while (obj!=null){
		x+=obj.offsetLeft-obj.scrollLeft;
		y+=obj.offsetTop-obj.scrollTop;
		obj=obj.offsetParent;
	}
	return x;
}
function findY(obj){
	var x=0,y=0;
	while (obj!=null){
		x+=obj.offsetLeft-obj.scrollLeft;
		y+=obj.offsetTop-obj.scrollTop;
		obj=obj.offsetParent;
	}
	return y;
}
function toggleBox() { 
	//perk = document.getElementById("perk_box");
		if($("perk_box").style.display=="block") 
			$("perk_box").style.display="none";
		else	
			$("perk_box").style.display="block";	
}

function setNotExpired(threadid) {
	if(confirm("Do you want to set the thread UNEXPIRED?")) {
		location.href="http://www.pricenetwork.ca/showthread.php?threadid="+threadid+"&unexp=1";
	}
}

function menuClicked(todo, threadid, userid) {
	//alert(todo+"---"+threadid);
	if(todo==1) 
		location.href="http://del.icio.us/post?url=http://www.pricenetwork.ca/showthread.php?threadid="+threadid;
	else if(todo==2) 
		location.href="http://digg.com/submit?phase=2&url=http://www.pricenetwork.ca/showthread.php?threadid="+threadid;
	else if(todo==4) {
		if(confirm("Do you want to add this thread to newsletter?")) {
			xmlhttpPost("http://www.pricenetwork.ca/showthread/controller.php?todo=add&threadid="+threadid,"test","test");
			alert("The thread has been added to newsletter.");
		}
	}	
	else if(todo==3) {
		if(userid==0) {
			alert("Please login first.");
			return;
		}
			xmlhttpPost("http://www.pricenetwork.ca/showthread/controller.php?todo=basket&threadid="+threadid,"test","OUTBOXNUMBER");
			alert("The thread has been added to your outbox.");		
	}	

	else if(todo==5) 
		location.href="http://www.pricenetwork.ca/newsletter.php";
									
	else if(todo==7) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=openclosethread&threadid="+threadid;
	else if(todo==8) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=move&threadid="+threadid;
	else if(todo==9) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=editthread&threadid="+threadid;
	else if(todo==10) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=deletethread&threadid="+threadid;
	else if(todo==11) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=merge&threadid="+threadid;
	else if(todo==12) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=split&threadid="+threadid;
	else if(todo==13) 
		location.href="http://www.pricenetwork.ca/forum/postings.php?action=stick&threadid="+threadid;	
	else if(todo==14)	
		location.href="http://www.pricenetwork.ca/forum/member2.php?s=&action=addsubscription&threadid="+threadid;
	else if(todo==15)	
		location.href="http://www.pricenetwork.ca/linx.php?tid="+threadid+"&autooff=1";
	return;				
}
function content(threadid) {
	obj=document.getElementById("thread_content");
	if(obj.style.display=="block") {
		obj.style.display="none";
		if(document.getElementById("wiki_"+threadid))
			document.getElementById("wiki_"+threadid).style.display="none";
		document.getElementById("contentButton").innerHTML="View Content";
		document.getElementById("first_post").style.backgroundColor="#efefef";
		if(document.getElementById("perk_box"))
		document.getElementById("perk_box").style.display="none";
	}
	else {
		obj.style.display="block";
		wikiRead(threadid);
		if(document.getElementById("wiki_"+threadid)) {
			document.getElementById("wiki_"+threadid).style.display="block";
			
		}			
		
		document.getElementById("contentButton").innerHTML="Hide Content";
		document.getElementById("first_post").style.backgroundColor="#ffffff";
		if(document.getElementById("perk_box"))
		document.getElementById("perk_box").style.display="block";
	}
}
function quickTip(userid,postid) {
	xmlhttpPost("http://www.pricenetwork.ca/showthread/controller.php?todo=tip&userid="+userid+"&postid="+postid,"test","tips_"+postid);
}
function xmlhttpPost(strURL,formID,dispID) {
	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		self.xmlHttpReq = new XMLHttpRequest();
		//self.xmlHttpReq.overrideMimeType("text/xml");
	}
	// IE
	else if (window.ActiveXObject) {
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	self.xmlHttpReq.open("POST", strURL, true);
	self.xmlHttpReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState == 4) {
			updatepage(self.xmlHttpReq.responseText,dispID);
		}
	}
	self.xmlHttpReq.send(getquerystring(formID));
}

function getquerystring(formID) {
	var qstr= "";
	obj = document.getElementById(formID);
	for(i=0;i<obj.length;i++) {
		qstr+=obj[i].name+"="+escape(obj[i].value)+"&";
	}
	return qstr;
}
function updatepage(str,dispID){
	document.getElementById(dispID).innerHTML = str;
}

// wiki

var controller="http://www.pricenetwork.ca/showthread/controller.php";
var currentThread=0;
function wikiWrite(threadid,login, posts) {
	currentThread = threadid;
	/*
	if($('wiki_'+threadid).style.display == 'block') {
		$('wiki_'+threadid).style.display = 'none';
		return;
	}*/	
	$('wiki_'+threadid).style.display = 'block';
	if(login==0) {
		alert('Please login first.');
		return;
	}
	if(posts<100) {
		alert('You need to have 100 posts.');
		return;		
	}
	$('wiki_'+threadid).innerHTML = 
			'<form name="form_'+threadid+'" id="form_'+threadid+'" onsubmit="return formAjax('+threadid+')">'+
			'<b></b><input type="hidden" name="threadid" value="'+threadid+'">'+
			'<textarea rows="6" cols="70" name="wiki_content" id="content_'+threadid+'" style="border:1px dashed #999;color:#666;font-size:9pt;padding:6px;background-color:#F6EBA3;" onclick="cleanTA('+threadid+');">'+
			'Write the reason why this is considered a great deal. Give examples of other offers or prices to verify this deal.'+
			'</textarea><br/>'+
			'<input type="submit" value="Submit" style="border:1px solid #666;font:size:7pt;color:#666">'+	
			'</form>';	
	$('content_'+threadid).focus();		

}
function cleanTA(threadid) {
	$('wiki_'+threadid).innerHTML = 
			'<form name="form_'+threadid+'" id="form_'+threadid+'" onsubmit="return formAjax('+threadid+')">'+
			'<b></b><input type="hidden" name="threadid" value="'+threadid+'">'+
			'<textarea rows="6" cols="70" name="wiki_content" id="content_'+threadid+'" style="border:1px dashed #999;color:#666;font-size:9pt;padding:6px;background-color:#F6EBA3;">'+
			'</textarea><br/>'+
			'<input type="submit" value="Submit" style="border:1px solid #666;font:size:7pt;color:#666">'+	
			'</form>';	
	$('content_'+threadid).focus();		
}

function formAjax(threadid) {
	currentThread = threadid;
	var myAjax = new Ajax.Request( 
									controller+"?todo=7", 
									{ 
										method: 'post', 
										parameters: Form.serialize('form_'+threadid), 
										onComplete: WikiDisplay 
									}
								);
	return false;								
}	

function WikiDisplay(originalRequest) {
	$('wiki_'+currentThread).innerHTML = originalRequest.responseText;
	if($('wiki_image_'+currentThread)) {
		
		if($('wiki_image_'+currentThread).src=="http://www.pricenetwork.ca/deals/icon_wwoff.gif") 
			$('wiki_image_'+currentThread).src="http://www.pricenetwork.ca/deals/icon_wwnew.gif";	
		else if($('wiki_image_'+currentThread).src=="http://www.pricenetwork.ca/deals/icon_wwnew.gif") 
			$('wiki_image_'+currentThread).src="http://www.pricenetwork.ca/deals/icon_wwedit.gif";
		else if($('wiki_image_'+currentThread).src=="http://www.pricenetwork.ca/deals/icon_ww.gif")
			$('wiki_image_'+currentThread).src="http://www.pricenetwork.ca/deals/icon_wwedit.gif";				
		$('wiki_image_'+currentThread).onclick = wikiRead2 ;
	}		
}

function WikiContent(originalRequest) {
	$('wiki_'+currentThread).innerHTML = originalRequest.responseText;
	$('wiki_'+currentThread).style.display="block";
}

function wikiRead2() {

	
	if($('wiki_'+currentThread).style.display=="block") {
		$('wiki_'+currentThread).style.display="none";
		return;
	}
	var myAjax = new Ajax.Request( 
									controller+"?todo=8", 
									{ 
										method: 'get', 
										parameters: "tid="+currentThread, 
										onComplete: WikiContent 
									}
								);	
}

function wikiRead(threadid) {

	currentThread = threadid;
	
	if($('wiki_'+threadid).style.display=="block") {
		$('wiki_'+threadid).style.display="none";
		return;
	}
	var myAjax = new Ajax.Request( 
									controller+"?todo=8", 
									{ 
										method: 'get', 
										parameters: "tid="+threadid, 
										onComplete: WikiContent 
									}
								);	
}
function wikiEdit(threadid) {

	currentThread = threadid;
	$('wiki_'+currentThread).style.display="block";
	var myAjax = new Ajax.Request( 
									controller+"?todo=9", 
									{ 
										method: 'get', 
										parameters: "tid="+currentThread, 
										onComplete: WikiContent 
									}
								);		
	
	
}