
// basic functions
var currentThread = 0;
var bold_subcat_id = '';
var bold_store_id = '';
function init() {
	 
	if(currentHotOnly==0) {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;<B>All</B>";
	} else if (currentHotOnly==1) {
		$('hottest').innerHTML="<B>Hot&nbsp;Only</B>&nbsp;|&nbsp;All";
	} else {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;All";
	}
	
	if($('sort_'+currentSortBy)) 	 $('sort_'+currentSortBy).style.fontWeight = 'bold';
	if($('user_'+currentUserID)) 	 $('user_'+currentUserID).style.fontWeight = 'bold';
	if($('exp_'+currentExpired)) 	 $('exp_'+currentExpired).style.fontWeight = 'bold';
	if($('star_'+currentStarred)) 	 $('star_'+currentStarred).style.fontWeight = 'bold';
	if($('last_'+currentResultFrom)) 	 $('last_'+currentResultFrom).style.fontWeight = 'bold';
	

	pars = 'todo=1';  // cat images
	var myAjax1 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setCatImage });
	
	refresh_page();
	
}

function getPars(todo) {
	
	/*
	v = vendorid
	c = catID
	e = expired [ 0=yes ; 1= no ]
	star = starred [ 1 = star only, 2 = non-star, 0 = all] ]
	p = Page Number
	l = result for last 30 days, 60 days, 90 days, 120 days, a for all
	pp = items per page, default 30
	s = sort [ mr=mostRecent; pv=pageViews; re=replies; ra=ratings; ]
	u = userid
	*/
	return  	'todo='+todo+
				'&c='+currentCatId+
				'&d='+currentForumId+
				'&t='+currentTagId+
				'&v='+currentVendorId+
				'&l='+currentProId+
				'&pp='+currentItemsPP+
				'&p='+currentPageNum+
				'&e='+currentExpired+
				'&star='+currentStarred+
				'&r='+currentResultFrom+
				'&s='+currentSortBy+
				'&h='+currentHotOnly+
				'&g='+currentGroup+
				'&u='+currentUserID;
				//'&vp='+currentVendorPage; 
				//
}

function refresh_page(but) {
	$('processing').style.display = "block"; 
	
	pars = getPars(4);
	var myAjax4 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setDealData });	

	pars = getPars(5);
	var myAjax5 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setPaging });	

	if(but!=3) {
		pars = getPars(3)+"&d=&";
		var myAjax3 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setSubCats });		
	}
	
	pars = getPars(10);
	var myAjax10 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setTags });
	
	if(but!=2) {
		pars = getPars(2)+"&v=";
		var myAjax2 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setStores });
	}	
	pars = getPars(6);
	var myAjax6 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setLocation });	

	
}

function setCurrentCatId(cid) {
	currentCatId = cid;
	setCookie2('cat_id',cid)
}





/* ------- Display Ajax Response

----------------------*/


function setStores(originalRequest) {
	$('deals_filter_stores').innerHTML = originalRequest.responseText;
	
	bold_store_id='vendor_'+currentVendorId;
	
	if(bold_store_id=='') {bold_store_id='vendor_0';}
	
	if(bold_store_id!='vendor_0') {
		if($(bold_store_id)) {$(bold_store_id).style.fontWeight='bold';}
		$('vendor_0').style.fontWeight='normal';
	}
	else {
		$('vendor_0').style.fontWeight='bold';
	}
}

function toggle_hot(tid) { 
	
	if ($('hoticon_'+tid).src=='http://'+window.location.hostname+'/forum/images/icons/hoticon2.gif') {
		$('hoticon_'+tid).src = '../forum/images/icons/hoticon2_gray.gif';
		// set iconid=0
		var myAjax = new Ajax.Request( controller+"?todo=11", { method: 'post', parameters: 'tid='+tid, onComplete: null }	);
		//alert('set iconid=0...'+tid);
		
	} else if($('hoticon_'+tid).src=='http://'+window.location.hostname+'/forum/images/icons/hoticon2_gray.gif') {
		$('hoticon_'+tid).src = '../forum/images/icons/hoticon2.gif';
		// set iconid=15
		var myAjax = new Ajax.Request( controller+"?todo=11", { method: 'post', parameters: 'tid='+tid, onComplete: null }	);
		//alert('set iconid=15...'+tid);
	} else {
		//alert($('hoticon_'+tid).src);
		$('hoticon_'+tid).src = '../forum/images/icons/icon1.gif';
	}
}

function toggle_starred(tid) { 
	
	if ($('starredicon_'+tid).src=='http://'+window.location.hostname+'/images/icon_starred_on.gif') {
		$('starredicon_'+tid).src = '../images/icon_starred_off.gif';
		var myAjax = new Ajax.Request( controller+"?todo=12", { method: 'post', parameters: 'tid='+tid, onComplete: null }	);
		
	} else if($('starredicon_'+tid).src=='http://'+window.location.hostname+'/images/icon_starred_off.gif') {
		$('starredicon_'+tid).src = '../images/icon_starred_on.gif';
		var myAjax = new Ajax.Request( controller+"?todo=12", { method: 'post', parameters: 'tid='+tid, onComplete: null }	);
	} else {
		$('starredicon_'+tid).src = '../images/icon_starred_off.gif';
	}
}


function setSubCats(originalRequest) {
	$('subcats').innerHTML = originalRequest.responseText;
	if(currentForumId>0) {bold_subcat_id='subcat_'+currentForumId;};
	if(bold_subcat_id!='subcat_0') {
		$(bold_subcat_id).style.fontWeight='bold';
		$('subcat_0').style.fontWeight='normal';		
	}
	else {
		$('subcat_0').style.fontWeight='bold';
	}	
}
function setTags(originalRequest) {
	$('tags').innerHTML = originalRequest.responseText;
}
function setDealData(originalRequest) {
	$('deals_data').innerHTML = originalRequest.responseText;
	$('processing').style.display = "none";
	//location.href = "#anchor_top";
}

function setPaging(originalRequest) {
	$('paging').innerHTML = originalRequest.responseText;
	$('paging2').innerHTML = originalRequest.responseText;
}

function setLocation(originalRequest) {
	$('deals_filter_loc').innerHTML = originalRequest.responseText;
}



/* -------Events Handler

----------------------*/

// category events

function catMouseOut(cid) {
	if(currentCatId!=cid)
		$('cat_image_'+cid).src = 'images/deals/sm/b_'+cid+'.gif';
		$('cat_text_'+cid).style.backgroundColor = '#fff'; // LIGHT current cat text
		$('cat_text_'+currentCatId).style.color = '#000'; // LIGHT current cat text
}

function catMouseOver(cid) {
	if(currentCatId!=cid)
		$('cat_image_'+cid).src = 'images/deals/sm/b_'+cid+'.gif';
		$('cat_text_'+cid).style.backgroundColor = '#29aeff'; // LIGHT current cat text
			
}
function setCatImage(originalRequest) {
	$('deals_cat').innerHTML = originalRequest.responseText;
	$('cat_image_'+currentCatId).src = 'images/deals/sm/b_'+currentCatId+'.gif'; // LIGHT current cat image 
	$('cat_text_'+currentCatId).style.color = '#000'; // LIGHT current cat text
	$('cat_text_'+currentCatId).style.fontWeight = 'bold'; // bold it!
}
function catClicked(cid) {

	if(currentCatId==cid) return '';

	if($('vendor_0'))
		$('vendor_0').style.fontWeight = 'bold';
	if($('vendor_'+currentVendorId))
		$('vendor_'+currentVendorId).style.fontWeight = 'normal';
	currentVendorId = 0;
	setCookie2('vendor_id',0);
	
	$('cat_image_'+currentCatId).src = 'images/deals/sm/b_'+currentCatId+'.gif'; // dark current cat image 
	$('cat_text_'+currentCatId).style.color = '#666'; // dark current cat text
	$('cat_text_'+currentCatId).style.fontWeight = 'normal'; // normal it!
	
	setCurrentCatId(cid);
	
	$('cat_image_'+currentCatId).src = 'images/deals/sm/b_'+currentCatId+'.gif'; // LIGHT clicked cat image 
	$('cat_text_'+currentCatId).style.color = '#000'; // LIGHT clicked cat text	
	$('cat_text_'+currentCatId).style.fontWeight = 'bold'; // bold it!
	
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);
	
	currentTagId = 0;
	setCookie2('tag_id',0);
	
	
	
	refresh_page()	;
		
}

//Sub-catgeory Click Events

function subCatClicked(sid, obj) {
	if(sid==currentForumId) return '';
	oldForumId = currentForumId;					
	
	currentForumId =  sid;	
	setCookie2('forum_id',sid);
	
	if($('vendor_0'))
		$('vendor_0').style.fontWeight = 'bold';
	if($('vendor_'+currentVendorId))
		$('vendor_'+currentVendorId).style.fontWeight = 'normal';
	currentVendorId = 0;
	setCookie2('vendor_id',0);
	
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);		
	if($('subcat_0')) 
		$('subcat_0').style.fontWeight='normal';
	if($(bold_subcat_id))
		$(bold_subcat_id).style.fontWeight='normal';
	obj.style.fontWeight='bold';
	bold_subcat_id = obj.id;
	if(bold_subcat_id=='subcat_0')
		refresh_page();
	else
		refresh_page(3);			
}
function TagClicked(which) {
	
	if(currentTagId == which) return;
	
	currentTagId = which;
	setCookie2('tag_id',which);

	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);	

	refresh_page();
}

//user click event
function userFilterClicked(userid) {
	if(userid==currentUserID) return;
	if($('user_'+userid))
		$('user_'+userid).style.fontWeight = 'bold';
	if($('user_'+currentUserID))
		$('user_'+currentUserID).style.fontWeight = 'normal';	
	currentUserID = userid;	
	setCookie2('user_id',userid);		
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);
	refresh_page()	;
}

// Vendor Click Events
function vendorClicked(vid, obj) {
	if(vid==currentVendorId) return;
	
	if($('vendor_'+vid))
		$('vendor_'+vid).style.fontWeight = 'bold';
	if($('vendor_'+currentVendorId))
		$('vendor_'+currentVendorId).style.fontWeight = 'normal';
		
	currentVendorId = vid;	
	setCookie2('vendor_id',vid);
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);	

	if($('vendor_0')) 
		$('vendor_0').style.fontWeight='normal';
	if($(bold_store_id))
		$(bold_store_id).style.fontWeight='normal';
	obj.style.fontWeight='bold';
	bold_store_id = obj.id;	
	if(bold_store_id=='vendor_0')
		refresh_page();
	else
		refresh_page(2);
}
function pagePre(pre,next,total) {
	if(pre<0) pre=total;
	if(pre>total) pre=0;
	pars = getPars(2)+'&vp='+pre+'&v=&';
	var getVendors = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setStores });		
}
function pageNext(pre,next,total) {
	if(next<0) next=total;
	if(next>total) next=0;
	pars = getPars(2)+'&vp='+next+'&v=&';
	var getVendors = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setStores });	
}

// Paging clicked
function pagerClicked(pageNum) {
	
	currentPageNum = pageNum;
	setCookie2('page_number',pageNum);
	$('processing').style.display = "block"; 
	//if (pageNum!=1) {
		//$('fc_box').style.display = "none"; 
	//} else if (pageNum==1) {
		//$('fc_box').style.display = "block"; 
	//}
	
	pars = getPars(5);
	var myAjax5 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setPaging });		
	
	pars = getPars(4);
	var myAjax4 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setDealData });		
	
}

// sort by clicked 
function sortByClicked(sortby) {
	if(currentSortBy == sortby) return;
	
	currentSortBy = sortby;
	setCookie2('sort_by',sortby);
	
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);
	$('processing').style.display = "block"; 
	pars = getPars(5);
	var myAjax5 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setPaging });		
	
	pars = getPars(4);
	var myAjax4 = new Ajax.Request( controller, { method: 'get', parameters: pars, onComplete: setDealData });		
}

//
function hottestClicked(){
	if(currentHotOnly==1) {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;<B>All</B>";
		//$('sortby').options[0].selected = true;
		HotOnlyClicked2(0);
	}	
	else if(currentHotOnly==0) {
		$('hottest').innerHTML="<B>Hot&nbsp;Only</B>&nbsp;|&nbsp;All";
		//$('sortby').options[4].selected = true;
		HotOnlyClicked2(1);		
	} else {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;All";
		HotOnlyClicked2(0);
	}
}

function sortByClicked2(sortby) {
	if(currentSortBy == sortby) return;
	if($('sort_'+currentSortBy))
		$('sort_'+currentSortBy).style.fontWeight = 'normal';		
	currentSortBy = sortby;
	setCookie2('sort_by',sortby);
	if($('sort_'+currentSortBy))	
		$('sort_'+currentSortBy).style.fontWeight = 'bold';		
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);
	//if(currentSortBy==3) {
	//	$('hottest').innerHTML="Hottest&nbsp;|&nbsp;<B>Recent</B>";
	//} else if (currentSortBy==0) {
	//	$('hottest').innerHTML="<B>Hottest</B>&nbsp;|&nbsp;Recent";
	//} else {
	//	$('hottest').innerHTML="Hottest&nbsp;|&nbsp;Recent";
	//}
	refresh_page()	;	
}

function HotOnlyClicked2(hotonly) {
	if(currentHotOnly == hotonly) return;
	//if($('sort_'+currentSortBy))
	//	$('sort_'+currentSortBy).style.fontWeight = 'normal';		
	currentHotOnly = hotonly;
	setCookie2('hot_only',hotonly);
	//if($('sort_'+currentSortBy))	
	//	$('sort_'+currentSortBy).style.fontWeight = 'bold';		
	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	//setCookie2('hot_only',1);
	
	if(currentHotOnly==0) {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;<B>All</B>";
	} else if (currentHotOnly==1) {
		$('hottest').innerHTML="<B>Hot&nbsp;Only</B>&nbsp;|&nbsp;All";
	} else {
		$('hottest').innerHTML="Hot&nbsp;Only&nbsp;|&nbsp;All";
	}
	refresh_page()	;	
}

function expiredClicked(which) {
	
	if(currentExpired==which) return '';

	if($('exp_'+currentExpired))
		$('exp_'+currentExpired).style.fontWeight = 'normal';
		
	currentExpired = which;
	setCookie2('expired',which);
	
	if($('exp_'+currentExpired))	
		$('exp_'+currentExpired).style.fontWeight = 'bold';	

	currentPageNum = 1;
	setCookie2('page_number',1);
	refresh_page();
	
}

function starredClicked(which) {
	
	if(currentStarred==which) return '';

	if($('star_'+currentStarred))
		$('star_'+currentStarred).style.fontWeight = 'normal';
		
	currentStarred = which;
	setCookie2('starred',which);
	
	if($('star_'+currentStarred))	
		$('star_'+currentStarred).style.fontWeight = 'bold';	

	currentPageNum = 1;
	setCookie2('page_number',1);	
		
	refresh_page()	;
	
}

function resultfromClicked(which) {

	if(currentResultFrom==which) return '';

	if($('last_'+currentResultFrom))
		$('last_'+currentResultFrom).style.fontWeight = 'normal';
	currentResultFrom = which;
	setCookie2('result_from',which);
	
	if($('last_'+currentResultFrom))	
		$('last_'+currentResultFrom).style.fontWeight = 'bold';	

	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);	
		
	refresh_page()	;
}
function locationClicked(which) {
	
	if(currentProId == which) return;
	
	currentProId = which;
	setCookie2('province_id',which);

	currentPageNum = 1;
	//$('fc_box').style.display = "block"; 
	setCookie2('page_number',1);	

	refresh_page()	;	
}

/* -------General Functions

----------------------*/

function getCookie(c_name) {
	if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1; 
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    } 
	  }
	return "";
}

function linkto() {
	$('page_link').href = 'http://'+window.location.hostname+'/'+deal_home+'?'+getPars(99);
}

function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function setCookie2(name1, value1) {
	// get cookies first from unserialized "cookie_deals" and save as variable
	var cookie_array = unserialize(getCookie('cookie_deals'));
	// change array value of the specific setting to change
	cookie_array[name1] = value1;
	
	// serialize variable and save back as "cookie_deals"
	setCookie('cookie_deals',serialize(cookie_array),'90');
}

function serialize (txt) {
	switch (typeof(txt)) {
		case 'string':
			return 's:'+txt.length+':"'+txt+'";';
		case 'number':
			if (txt>=0 && String(txt).indexOf('.') == -1 && txt < 65536)
				return 'i:'+txt+';';
			return 'd:'+txt+';';
		case 'boolean':
			return 'b:'+( (txt)?'1':'0' )+';';
		case 'object':
			var i=0,k,ret='';
			for (k in txt) {
				//alert(k+"("+typeof(txt[k])+") = "+txt[k]);
				if (typeof(txt[k]) == "function")
					continue;					
				if (!isNaN(k))
					k = Number(k);
				ret += serialize(k)+serialize(txt[k]);
				i++;
			}
			return 'a:'+i+':{'+ret+'}';
		default:
			return 'N;';
			alert('var undefined: '+typeof(txt));return undefined;
	}
}

function unserialize(txt){
	var level=0,arrlen=new Array(),del=0,final=new Array(),key=new Array(),save=txt;
	while(1) {
		switch(txt.substr(0,1)) {
		case 'N':
			del = 2;
			ret = null;
		break;
		case 'b':
			del = txt.indexOf(';')+1;
			ret = (txt.substring(2,del-1) == '1')?true:false;
		break;
		case 'i':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 'd':
			del = txt.indexOf(';')+1;
			ret = Number(txt.substring(2,del-1));
		break;
		case 's':
			del = txt.substr(2,txt.substr(2).indexOf(':'));
			ret = txt.substr( 1+txt.indexOf('"'),del);
			del = txt.indexOf('"')+ 1 + ret.length + 2;
		break;
		case 'a':
			del = txt.indexOf(':{')+2;
			ret = new Array();
			arrlen[level+1] = Number(txt.substring(txt.indexOf(':')+1, del-2))*2;
		break;
		case 'O':
			txt = txt.substr(2);
			var tmp = txt.indexOf(':"')+2;
			var nlen = Number(txt.substring(0, txt.indexOf(':')));
			name = txt.substring(tmp, tmp+nlen );
			//alert(name);
			txt = txt.substring(tmp+nlen+2);
			del = txt.indexOf(':{')+2;
			ret = new Object();
			arrlen[level+1] = Number(txt.substring(0, del-2))*2;
		break;
		case '}':
			txt = txt.substr(1);
			if(arrlen[level] != 0){alert('var missed : '+save); return undefined;};
			//alert(arrlen[level]);
			level--;
		continue;
		default:
			if(level==0) return final;
			alert('syntax invalid(1) : '+save+"\nat\n"+txt+"level is at "+level);
			return undefined;
		}
		if(arrlen[level]%2 == 0){
			if(typeof(ret) == 'object'){alert('array index object no accepted : '+save);return undefined;}
			if(ret == undefined){alert('syntax invalid(2) : '+save);return undefined;}
			key[level] = ret;
		} else {
			var ev = '';
			for(var i=1;i<=level;i++){
				if(typeof(key[i]) == 'number'){
					ev += '['+key[i]+']';
				}else{
					ev += '["'+key[i]+'"]';
				}
			}
			eval('final'+ev+'= ret;');
		}
		arrlen[level]--;//alert(arrlen[level]-1);
		if (typeof(ret) == 'object')
			level++;
		txt = txt.substr(del);
		continue;
	}
}

// toggle the filters
function toggle(theid) {
	if($(theid).style.display!="none")
		$(theid).style.display="none";
	else 
		$(theid).style.display="block";
}

function toggle_filter(imageid,filterid) {
	toggle(filterid);	
	if($(imageid).src.indexOf("opened.gif")!=-1) 	
		$(imageid).src="usercp/closed.gif";	
	else 
		$(imageid).src="usercp/opened.gif";	
}

// wiki why

function wikiWrite(threadid,mouseEvent,login,posts) {
	
	$clickable = WikiOpen_Onclick(mouseEvent);
	if ($clickable=='1') {
		return;
	}
	
	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;" onclick="cleanTA('+threadid+');">'+
			'Write a summary for this deal!  Explain why this is a great deal.  Provide updates.'+
			'</textarea><br/>'+
			'<input type="submit" value="Submit" style="border:1px solid #666;font:size:7pt;color:#666">'+	
			'</form>';	
	$('content_'+threadid).focus();		

}

function WikiOpen_Onclick(mouseEvent) {
	// START - removes popup on clicking on link to thread
	var elementID;
	//if event doesn't exist,
	//use window.event
	if(!mouseEvent)
		mouseEvent = window.event;

	// get the id of the element that was clicked (firefox)
	if(mouseEvent.target)
		elementID = mouseEvent.target.id;
	// get the id of the element that was clicked (IE)
	else if(mouseEvent.srcElement)
		elementID = mouseEvent.srcElement.id;

	// perform the desired action UNLESS these
	// elements are clicked
	var noActionIDs = new Array();
	noActionIDs[0] = "thread";
	noActionIDs[1] = "form";
	noActionIDs[2] = "wikisubmit";
	noActionIDs[3] = "content";

	for(var i = 0; i < noActionIDs.length; i++) {
		if(elementID.indexOf(noActionIDs[i])>=0)
		return '1';
	}
	// END - removes popup on clicking on link to thread
	return '2';
}


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;">'+
			'</textarea><br/>'+
			'<input id="wikisubmit" 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) {
	
	inner = originalRequest.responseText.replace(/\\"/g,'"');
	inner = inner.replace(/\\'/g,"'");
	$('wiki_'+currentThread).innerHTML = inner;
	if($('wiki_image_'+currentThread)) {
		
		if($('wiki_image_'+currentThread).src=="http://"+window.location.hostname+"/deals/icon_wwoff.gif") 
			$('wiki_image_'+currentThread).src="deals/icon_wwnew.gif";	
		else if($('wiki_image_'+currentThread).src=="http://"+window.location.hostname+"/deals/icon_wwnew.gif") 
			$('wiki_image_'+currentThread).src="deals/icon_wwedit.gif";
		else if($('wiki_image_'+currentThread).src=="http://"+window.location.hostname+"/deals/icon_ww.gif")
			$('wiki_image_'+currentThread).src="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,mouseEvent,login,posts) {

	$clickable = WikiOpen_Onclick(mouseEvent);
	if ($clickable=='1') {
		return;
	}

	if(!isNaN(threadid)) 
		currentThread = threadid;
	
	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 wikiEdit(threadid) {

	currentThread = threadid;
	$('wiki_'+currentThread).style.display="block";
	var myAjax = new Ajax.Request( 
									controller+"?todo=9", 
									{ 
										method: 'get', 
										parameters: "tid="+currentThread, 
										onComplete: WikiContent 
									}
								);		
	
	
}
