function checkall(cb)
{
	var cbaname = cb.name;
	var checked = cb.checked;
	
	allcb = document.getElementsByName(cbaname.substring(1, cbaname.length));
	
	for(i=0;i<allcb.length; i++)
	{
		allcb[i].checked = checked;
	}
}

function ptr(oddEven, counter_name, triggereddate, highlow, peaktrough, buyselllimit, troughpeak, cutloss, symbol, temp_market_id)
{	
	out = '';
	if(oddEven==1)
		out +="<tr class=orangeevenrow  valign=\"top\" >";
	else
		out +="<tr class=orangeoddrow valign=\"top\" >";
	
	out += "<td class='orangetablecell' align='left'>"+counter_name+"</td>";
	out += "<td class='orangetablecell' align='left'>"+symbol+"</td>";
	out += "<td class='orangetablecell'>"+triggereddate+"&nbsp;</td>";
	out += "<td class='orangetablecell' align='right'>"+highlow+"</td>";
	out += "<td class='orangetablecell' align='right'>"+peaktrough+"</td>";
	out += "<td class='orangetablecell' align='right'>"+buyselllimit+"</td>";
	out += "<td class='orangetablecell' align='right'>"+troughpeak+"</td>";
	out += "<td class='orangetablecell' align='right'>"+cutloss+"</td>";
	
	out += "<td class=\"orangetablecell\" align='center'><a href=\"javascript:openPopUp1('chart.jsp?load="+symbol+"&market="+temp_market_id+"','charts')\" ><img src=\"images/view.gif\" width=\"11\" height=\"11\" border=\"0\"/></a></td></tr>"

document.write(out);
}

function watchlistSelectAllDel(){
	
	var ckset = document.getElementsByName('deletestock');
	
	try{
	
		for(i=0; i< ckset.length; i++){
		
			if(ckset[i]!=null && !ckset[i].checked){
			
				ckset[i].checked = true;
			}
			
			else if(ckset[i]!=null && ckset[i].checked){
			
				ckset[i].checked = false;
			}
		}
		
	}catch(e){
		alert(e.message);
	}
}

function shareWatchlist(mid, wid, state){
	var url="watchlist.jsp";
	url=url+"?market_id="+mid;
	url+= "&act="+state;
	url+= "&wid="+wid;
	url=url+"&sid="+Math.random();
	
	window.location=url;
	
}



function searchCounter(mid, key, divid){
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	var url ="composeT-post.jsp?market_id="+mid;
	url += "&ch="+key;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=function showRes(){
		document.getElementById(divid).innerHTML=xmlhttp.responseText;
	};
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	document.getElementById(divid).innerHTML='<img src="images/ajax-loader.gif />';
	
}


function changeTPostPublicState(id){
	
	tpostAct(id, 'public');
}

function tpostAct(id, act){

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	var url ="tPostList.jsp?act="+act;
	url += "&id="+id;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=function showRes(){
		if (xmlhttp.readyState==4)
		  {
			if(xmlhttp.responseText.length>4){alert(xmlhttp.responseText);}
		  }
	};
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);

	return true;
}

function deleteTPost(id){
	
	go=confirm('Confirm delete T-Post with ID: '+id);
	if(go==false){
		return false;
	}
	return tpostAct(id, 'del');
}

function addToWatchlist(){
	//alert(selectedCounter);
	cb = (document.getElementsByName('wids'));
	for(i=0; i< cb.length; i++){
		if(cb[i].checked){
			
			$.post("watchlist.jsp", {  
				wid: cb[i].value, 
				market_id: market_id, 
				act: 'add',
				addstock: selectedCounter
			} );
			
			cb[i].checked=false;
		}
	}
	
	$('#watchlistdialog').dialog('close');
	
}


function doselect(postid, code, mid ,chart_src){
	selectedCounter=code;
	/*ele = document.getElementsByName("tcounter");alert(ele.length);  
	for(i=0; i<ele.length; i++){
		atag = ele[i];
		atag.className='t-post_stock';
	} */
	
	$("td[name=tcounter]").each(function(idx) { 
		($('#tcounter_'+(idx+1)).attr('class','t-post_stock'));  
	});
	//document.getElementById('tstock_'+postid).className='t-post-select';
	$('#tcounter_'+postid).attr('class', 't-post-select');
	$("#tpostchartimages").attr('src','tPostImages/'+chart_src);
	$('#chartappletlink').attr('href',"javascript:openPopUp1('chart.jsp?load="+code+"&market="+mid+"','charts')");
}

function loadWatchlist(){
	$.post( 'getWatchlist.jsp', { market_id: market_id , loginname:loginname} ,
		      function( data ) {
		          $( "#watchlistdialog" ).html(data);
		      }
		    );
}


function loadPreviousMsg(msgid){
	$.post( 'todayFocus.jsp', { msgid: msgid, act: 'getMsg',gtlt:'p' } ,
		      function( data ) {
		        $("#kmsgtd").html(data);
		      }
		    );
}

function loadNextMsg(msgid){
	$.post( 'todayFocus.jsp', { msgid: msgid, act: 'getMsg' ,gtlt:'n'} ,
		      function( data ) {
		        $("#kmsgtd").html(data);
		      }
		    );
}


function delKMsg(kmsgid){
	$.post( 'postNewMsg.jsp', { kmsgid: kmsgid, act: 'deleteKmsg' });
}


