var XmlHttp;
var flag_val =new Array();
var fl_t = 0;
function del_topic(iid){
   if(confirm("Do you really want to delete this topic ?\nClick OK to continue or click Cancel to stay in this page.")){
		var url = '/ajax_controller';
		var prm = 'provider=delete_forum_topic&iid='+iid;
		XmlHttp = $GX();
		keepfocus = 0;
		XmlHttp.onreadystatechange=function ShowResponse() {
				if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete") {
		 		var searchresult = eval('(' + XmlHttp.responseText+ ')')
		   		if(searchresult.success == 1) {		   			 
		   			 $("#div_"+searchresult.idd).fadeOut("slow");	
		 	  	}else {	
		 	  		if(searchresult.success == 2){
		 	  			alert("Oops.. you can not remove a topic which has at least one comment posted on it by someone.If you still wants to remove it, then please contact support@teezen.com and we will do the needful.");
		 	  		}else{
		 	  			alert("Sorry!! try after some time");  
		 	  		}
		 	  	}
			}
			}
		XmlHttp.open("POST",url,true);
		$Header(XmlHttp,prm);
	}else{
		return;
	}	
}

function add_comment_topic(id,btn_path,pg_url,fl){
	$GE(id).src=website_name+'image/ajaxloader_add_friend.gif';
	var comm=$GE('comment').value;	
    if(comm.length > 1000){alert('characters limit is max.1000');$GE(id).src = btn_path;return;}	
    var al_msg = 'You need to login to your account to perform this action.\nClick ok to continue or cancel to stay in this page.';	 
	var url = '/ajax_controller';
    var prm = 'provider=auth';    
    XmlHttp = $GX();
    XmlHttp.onreadystatechange = function dummy() {
	       if (XmlHttp.readyState == 4 || XmlHttp.readyState == 'complete') {
	            var authresult = eval('(' + XmlHttp.responseText + ')')
	            if (authresult.success == 0) {  	            	
	            	if(confirm(al_msg)){             
	                  window.location.href=pg_url;           
	            	}else{
	            		$GE(id).src = btn_path;
	            		return;
	            	}
	            } else {	
	            	if(fl == 'btn'){      
	            	    if(comm.length == 0){
	            	    	alert('Enter comment');
	            	    	$GE(id).src = btn_path;return;
	            	    }else{      	 
			              document.add_comm.submit(); 
	            	    }
	            	}else{
	            		$GE(id).src = btn_path;
	            		return;
	            	}
	            }
	       } 
	   }
    XmlHttp.open('POST', url, true); 
    $Header(XmlHttp, prm); 
}

function rem_comment(sid){
	if(confirm(confirmation_msg_fordel)){
	var url = '/ajax_controller';
	var prm = 'provider=delete_forum_comment&iid='+sid;
	XmlHttp = $GX();
	keepfocus = 0;
	XmlHttp.onreadystatechange=function ShowResponse() {
			if (XmlHttp.readyState == 4 || XmlHttp.readyState == "complete") {
		 		var searchresult = eval('(' + XmlHttp.responseText+ ')')
		   		if(searchresult.success == 0) {
		   			 alert("Sorry!! try after some time");  	
		 	  	}else {	
		 	  		$("#comm_"+searchresult.idd).fadeOut("slow");  		 	  			
		 	  	}
			}
		}
	XmlHttp.open("POST",url,true);
	$Header(XmlHttp,prm);
	}else{
		return;
	}	
}
function update_comment(sid,uurl){		
	var org_val = $GE('comment_text'+sid).value;
	if(flag_val['val'] != undefined){		
		$BF('comm_text_'+flag_val['id'],flag_val['val']);
	}
	flag_val['id'] = sid;
	flag_val['val'] = org_val;	
	org_val = escape(org_val);	
	if(org_val != undefined && org_val.length > 0){		
		var txt = "<form id='add_comment' name='add_comment' method='POST' action='"+uurl+"#comwall'><input type='hidden' id='comm_up' name='comm_up' value='"+sid+"_yes' /><textarea class='text_comm' onblur='$GE(\"txt_final"+sid+"\").value=this.value;' name='up_comm_"+sid+"' id='up_comm_"+sid+"'>"+unescape(org_val)+"</textarea><br />";
		txt=txt+"<img style='cursor:pointer;' onclick=\"set_def("+sid+",'"+org_val+"');\" border='0' align='Cancel' src='/image/cancel_grey.gif' title='Cancel'/>&nbsp;&nbsp;<img style='margin-top:20px;cursor:pointer;' border='0px' onclick='final_update("+sid+");' alt='Update' title='Update'  src='"+website_name+"image/update.gif'  /><input id='txt_final"+sid+"' name='txt_final"+sid+"' type='hidden' value='"+org_val+"'/></form>";
		$GE('comm_text_'+sid).style.height='150px';
		$GESD('comm_text_'+sid,'none');
		$BF('comm_text_'+sid,txt);
		$("#comm_text_"+sid).fadeIn("slow");		
	}else{
		return;
	}
}
function set_def(sid,txt){	
	$GESD('comm_text_'+sid,'none');
	$GE('comm_text_'+sid).style.height='auto';
	$BF('comm_text_'+sid,unescape(txt));
	$("#comm_text_"+sid).fadeIn("slow");
}
function final_update(sid){
	var dt = $GE('txt_final'+sid).value;
	if(dt != undefined && dt.length > 0){
	   $GE('comm_text_'+sid).style.height='auto';   	
	   document.add_comment.submit();	  
	}else{
		alert("Enter comment");
		return;
	}
}
function set_block_code(sc_id,uname){
	var comm = $GE('comment_text'+sc_id).value;	
	comm = escape(comm);
	var text ="<blockquote><cite>"+uname+" said :</cite>"+comm+"</blockquote> ";
	if(text.length < 5000 ){
		var len = 5000 - text.length;
		cnt_chr('comment','wordCnt',len);
		$GE('comment').value=unescape(text);
		$GE('parent_id').value=sc_id;
//		window.scrollTo(0,document.body.clientHeight);
	}else{
		alert("Sorry !!, Comment lenth exceed character limit.");
		$GE('comment').value='';
	}
}
function con_firm(urr){
	if(confirm("You need to login to your account to perform this action.\nClick ok to continue or click cancel to stay in this page.")){
		window.location.href=website_name+'login/r-'+urr;
	}else{
		return;
	}
}