
var LoginTimeoutId = 0;
var ClearLoginTimeoutId = 0;
var SendpassTimeoutId=0;
var ClearSendpassTimeoutId=0;


	



//jquery file upload
function upload()
{
	jQuery('#uploadify').uploadifyUpload();
}


var temp_hits;
var temp_size;
function upload_finished(msg)
{
	 
	var ary=msg.split("^");

	if (ary[0] == 'error')
	{
		alert(ary[1]);
	}else{


if (document.getElementById( 'attachment' )!=null)
{

		var tmp=document.getElementById( 'attachment' ).innerHTML ;
		if (tmp !="")
		{

			if (ary[3]=="public")
			{
			document.getElementById( 'attachment' ).innerHTML =tmp+"<div id=\""+ary[1]+"\"><br/>"+ary[2]+"&nbsp;&nbsp;  <a title=\"All users can view and download Click to change permission\" id=\"perm_"+ary[1]+"\" href=\"javascript:toggle_dl_perm('"+ary[1]+"')\"><img id=\"p_"+ary[1]+"\" src=\"http://www.tgipmt.com/forum/images/user.png\" alt=\"download permission\" border=\"0\"></a>  <a  title=\"Click to delete file\" href=\"javascript:del_attach('"+ary[1]+"')\"><img src=\"http://www.tgipmt.com/email/email_resource/common/clear.png\" alt=\"delete\" border=\"0\"></a></div>";
			
			}else{

			document.getElementById( 'attachment' ).innerHTML =tmp+"<div id=\""+ary[1]+"\"><br/>"+ary[2]+"&nbsp;&nbsp;  <a title=\"Only members can view and download Click to change permission\" id=\"perm_"+ary[1]+"\" href=\"javascript:toggle_dl_perm('"+ary[1]+"')\"><img id=\"p_"+ary[1]+"\" src=\"http://www.tgipmt.com/forum/images/user_accept.png\" alt=\"download permission\" border=\"0\"></a>  <a  title=\"Click to delete file\" href=\"javascript:del_attach('"+ary[1]+"')\"><img src=\"http://www.tgipmt.com/email/email_resource/common/clear.png\" alt=\"delete\" border=\"0\"></a></div>";

			}
		
		}else{

			if (ary[3]=="public")
			{
			document.getElementById( 'attachment' ).innerHTML ="<div id=\""+ary[1]+"\"><br/>"+ary[2]+"&nbsp;&nbsp;  <a title=\"All users can view and download Click to change permission\" id=\"perm_"+ary[1]+"\" href=\"javascript:toggle_dl_perm('"+ary[1]+"')\"><img id=\"p_"+ary[1]+"\" src=\"http://www.tgipmt.com/forum/images/user.png\" alt=\"download permission\" border=\"0\"></a>  <a title=\"Click to delete file\" href=\"javascript:del_attach('"+ary[1]+"')\"><img src=\"http://www.tgipmt.com/email/email_resource/common/clear.png\" alt=\"delete\" border=\"0\"></a></div>";
			
			}else{

			document.getElementById( 'attachment' ).innerHTML ="<div id=\""+ary[1]+"\"><br/>"+ary[2]+"&nbsp;&nbsp;  <a title=\"Only members can view and download Click to change permission\" id=\"perm_"+ary[1]+"\" href=\"javascript:toggle_dl_perm('"+ary[1]+"')\"><img id=\"p_"+ary[1]+"\" src=\"http://www.tgipmt.com/forum/images/user_accept.png\" alt=\"download permission\" border=\"0\"></a>  <a title=\"Click to delete file\" href=\"javascript:del_attach('"+ary[1]+"')\"><img src=\"http://www.tgipmt.com/email/email_resource/common/clear.png\" alt=\"delete\" border=\"0\"></a></div>";

			}
		}


		var tmp2=document.getElementById( 'attach' ).value ;
		if (tmp2 !="")
		{
			document.getElementById( 'attach' ).value =tmp2+"^"+ary[1];
		}else{
			document.getElementById( 'attach' ).value =ary[1];
		}

		
	
		var tmpx=document.getElementById( 'attach_perm' ).value ;
		if (tmpx !="")
		{
			document.getElementById( 'attach' ).value =tmp2+"^"+ary[1];
		}else{
			document.getElementById( 'attach' ).value =ary[1];
		}

		
	
		var tmpx=document.getElementById( 'attach_perm' ).value ;
		if (tmpx !="")
		{

			if (document.getElementById( "p_"+ary[1] ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			document.getElementById( 'attach_perm' ).value =tmpx+"^public";
			}else{
			document.getElementById( 'attach_perm' ).value =tmpx+"^register";
			}

		}else{
			if (document.getElementById( "p_"+ary[1] ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			document.getElementById( 'attach_perm' ).value ="public";
			}else{
			document.getElementById( 'attach_perm' ).value ="register";
			}
		}

		var tmp_hits=document.getElementById( 'attach_hits' ).value ;
		if (ary[4]=="undefined"||ary[4]=="" || ary[4]==null)
		{
			ary[4]=0;
		}

		 
		if (tmp_hits !="")
		{
		document.getElementById( 'attach_hits' ).value =tmp_hits+"^"+ary[1]+"$"+ary[4];

		}else{

		document.getElementById( 'attach_hits' ).value =ary[1]+"$"+ary[4];

		}

		var tmp_size=document.getElementById( 'attach_size' ).value ;
		if (ary[5]=="undefined"||ary[5]=="" || ary[5]==null)
		{
			ary[5]="0 bytes";
		}

		 
		if (tmp_size !="")
		{
		document.getElementById( 'attach_size' ).value =tmp_size+"^"+ary[1]+"$"+ary[5];

		}else{

		document.getElementById( 'attach_size' ).value =ary[1]+"$"+ary[5];

		}

	temp_hits=document.getElementById( 'attach_hits' ).value;
	temp_size=document.getElementById( 'attach_size' ).value;


	setcookie( "attach",document.getElementById( 'attach' ).value,10);
	setcookie ("perm",document.getElementById( 'attach_perm' ).value,10);
	setcookie ("attachment",document.getElementById( 'attachment' ).innerHTML,10);

	setcookie ("hits",document.getElementById( 'attach_hits' ).value,10);
	 setcookie ("size",document.getElementById( 'attach_size' ).value,10);

	}
	}
}

function del_attach(id)
{
 
	var parent=	document.getElementById(id).parentNode
	var d1=document.getElementById(id); 
	parent.removeChild(d1); 
	var tmpx="";
	var childNodeArray = document.getElementById('attachment').childNodes;
	var tmpz;
	var tmp_hits="";
	var tmp_size="";
	
	var ary=temp_hits.split("^");
	var arx=temp_size.split("^");

	var j=0;
	var k=0;
	for (i=0;i< childNodeArray.length;i++)
	{
		for (j=0;j< ary.length;j++)
		{
		var arz=ary[j].split("$");

		if ( childNodeArray[i].id==arz[0])
		{
			 
		if (tmp_hits=="")
		{
			tmp_hits=ary[j];
		}else{
			tmp_hits=tmp_hits+"^"+ary[j];
		}
		}

		}
		
		for (k=0;j< arx.length;k++)
		{
		var arz=arx[k].split("$");

		if ( childNodeArray[i].id==arz[0])
		{
			 
		if (tmp_size=="")
		{
			tmp_size=arx[k];
		}else{
			tmp_size=tmp_size+"^"+arx[k];
		}
		}

		}




		if (tmpx!="")
		{
			tmpx=tmpx+"^"+childNodeArray[i].id;

			if (document.getElementById( "p_"+childNodeArray[i].id ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			tmpz =tmpz+"^public";
			}else{
			tmpz =tmpz+"^register";
			}
			
			
		}else{
			tmpx=childNodeArray[i].id;
			if (document.getElementById( "p_"+childNodeArray[i].id ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			tmpz ="public";
			}else{
			tmpz ="register";
			}
			
		}
	}

	document.getElementById( 'attach' ).value=tmpx;
	document.getElementById( 'attach_perm' ).value =tmpz;
	document.getElementById( 'attach_hits' ).value =tmp_hits;
	document.getElementById( 'attach_size' ).value =tmp_size;



	setcookie( "attach",document.getElementById( 'attach' ).value,10);
	setcookie ("perm",document.getElementById( 'attach_perm' ).value,10);
	setcookie ("attachment",document.getElementById( 'attachment' ).innerHTML,10);
	setcookie ("hits",document.getElementById( 'attach_hits' ).value,10);
	setcookie ("size",document.getElementById( 'attach_size' ).value,10);
	
}


function getDirPath(URL) {
    var result = unescape(URL.substring(0,(URL.lastIndexOf("/")) + 1))

    return "http://www.tgipmt.com/forum/";
}


function toggle_dl_perm(id)
{

	 


if (document.getElementById( "p_"+id ).src ==getDirPath(window.location.href)+"images/user.png")
{
	document.getElementById("p_"+id ).src =getDirPath(window.location.href)+"images/user_accept.png";
	document.getElementById( "perm_"+id ).title="Only members can view and download Click to change permission";
}else{

	document.getElementById( "p_"+id ).src =getDirPath(window.location.href)+"images/user.png";
	document.getElementById( "perm_"+id ).title="All users can view and download Click to change permission";
}
var childNodeArray = document.getElementById('attachment').childNodes;
var tmpz="";
	for (i=0;i< childNodeArray.length;i++)
	{

		if (tmpz!="")
		{
			if (document.getElementById( "p_"+childNodeArray[i].id ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			tmpz =tmpz+"^public";
			}else{
			tmpz =tmpz+"^register";
			}

			
		}else{
			
			if (document.getElementById( "p_"+childNodeArray[i].id ).src ==getDirPath(window.location.href)+"images/user.png")
			{
			tmpz ="public";
			}else{
			tmpz ="register";
			}
			
		}
	}

	
	document.getElementById( 'attach_perm' ).value =tmpz;
	setcookie( "attach",document.getElementById( 'attach' ).value,10);
	setcookie ("perm",document.getElementById( 'attach_perm' ).value,10);
	setcookie ("attachment",document.getElementById( 'attachment' ).innerHTML,10);

}


function toggle_dl_perm2(id)
{

	


if (document.getElementById( id ).firstChild.data =="Public Download")
{
	document.getElementById( id ).firstChild.data ="Registered Download";
}else{

	document.getElementById( id ).firstChild.data ="Public Download";
}
var childNodeArray = document.getElementById('attachment').childNodes;
var tmpz="";
	for (i=0;i< childNodeArray.length;i++)
	{

		if (tmpz!="")
		{
			
			tmpz =tmpz+"^"+document.getElementById( 'perm_'+childNodeArray[i].id ).firstChild.data;
			
		}else{
			
			tmpz =document.getElementById( 'perm_'+childNodeArray[i].id ).firstChild.data;
			
		}
	}

	
	document.getElementById( 'attach_perm' ).value =tmpz;

}





function AddAttachment(att)
{

	if (att!="")
	{
		var ary=att.split("|");

		for (i=0;i< ary.length;i++)
		{
			
			upload_finished(ary[i]);
		}

	}
}

function trimstr(sString) 
{ 
while (sString.substring(0,1) == ' ') 
{ 
sString = sString.substring(1, sString.length); 
} 
while (sString.substring(sString.length-1, sString.length) == ' ') 
{ 
sString = sString.substring(0,sString.length-1); 
} 
return sString; 
} 





function previewPost1()
{
jQuery("#preview_section").hide();
	myEditor.saveHTML();
 
    //The var html will now have the contents of the textarea
    var html = myEditor.get('element').value;
alert((html.length))


var data="mode=preview&msg="+ html;

jQuery.post("/forum/forum_helper.php", data, prevCallback, "text");



	 	
		



}

function prevCallback(html)
                { 
		
		jQuery("#preview_body").html(html);
		jQuery("#preview_subject").html(document.frm_msg.title.value);
		document.getElementById('Preview_msg').scrollIntoView(true); 
	 
		jQuery("#preview_section").show(1000);

				}


function  previewPost()
{

myEditor.saveHTML();
var html = myEditor.get('element').value;

jQuery.ajax({
  type: 'POST',
  url: "/forum/forum_helper.php",
  data: { msg: html, mode: 'preview' },
  success: prevCallback,
  dataType: "text"
});


  }

















function CheckSubmit()
{
jQuery("#msg_post_error_container").hide();
var mode=document.frm_msg.mode.value;

if (document.frm_msg.user!=null)
{

if (trimstr(document.frm_msg.user.value) == ''   ) {
		
	window.location.hash="Preview_msg";
	jQuery("#msg_post_error").html("please specify name");
	jQuery("#msg_post_error_container").show(1000);

	return false;
}

if (document.frm_msg.user.value.length < 3)
{
	
	
	window.location.hash="Preview_msg";
	jQuery("#msg_post_error").html("Name is  too short");
	jQuery("#msg_post_error_container").show(1000);
	return false;
	

}
}


if (trimstr(document.frm_msg.title.value) == '') {
	
	if (mode=="add_reply" || mode=="edit_post"  || mode=="edit_reply" )
	{
	jQuery("#msg_post_error").html("Please specify title");

	}else if (mode=="add_topic") {
	jQuery("#msg_post_error").html("Please specify topic");

	}

	jQuery("#msg_post_error_container").show(1000);
		
	document.getElementById('msg_post_error_container').scrollIntoView(true); 
	
	return false;
}

if (document.frm_msg.title.value.length < 5)
{
	
	if (mode=="add_reply" || mode=="edit_post"  || mode=="edit_reply" )
	{
	jQuery("#msg_post_error").html("Title too short");

	}else if (mode=="add_topic" ){
	jQuery("#msg_post_error").html("Topic too short");

	}

		
	
	jQuery("#msg_post_error_container").show(1000);
		document.getElementById('msg_post_error_container').scrollIntoView(true); 

	return false;

}


 //Put the HTML back into the text area
    myEditor.saveHTML();
 
    //The var html will now have the contents of the textarea
    var html = myEditor.get('element').value;


	var content = html//tinyMCE.get('msg').getContent().replace(/<[^>]*>/g, ""); 
	 	
		jQuery("#msg").val(html);
		

	if ( (content=="") || (content==null) ) 
	{

		
		jQuery("#msg_post_error").html("please specify message");
		 	
	
	jQuery("#msg_post_error_container").show(1000);
		document.getElementById('msg_post_error_container').scrollIntoView(true); 

        
        return false; 
	}


if (content.length < 5)
{
	
	
		jQuery("#msg_post_error").html("Message too short");
		
	
	jQuery("#msg_post_error_container").show(1000);
		document.getElementById('msg_post_error_container').scrollIntoView(true); 

	return false;

}


deletecookie( "attach");
deletecookie ("perm");
deletecookie ("hits");
deletecookie ("size");
deletecookie ("attachment");

document.forms['frm_msg'].submit();

}

function ClearText()
{

//tinyMCE.get('msg').setContent('');
// CKEDITOR.instances.msg.setData( '' )

}

function jumpToAnchor(anc) 
{
	window.location = String(window.location).replace(/\#.*$/, "") + "#"+anc;
}




window.onload = function () {

setAttach();	

};		

function setAttach()
{
if(document.getElementById( 'cookieid' )!=null){

var att=getcookie("attach");


if (att!=null && att!="")
	{
	document.getElementById( 'attach' ).value=att;

	}
var perm=getcookie("perm");

if (perm!=null && perm!="")
	{
	document.getElementById( 'attach_perm' ).value=perm;

	}

var hits=getcookie("hits");

if (hits!=null && hits!="")
	{
	document.getElementById( 'attach_hits' ).value=hits;

	}
var size=getcookie("size");

if (size!=null && size!="")
	{
	document.getElementById( 'attach_size' ).value=size;

	}

var attachment=getcookie("attachment");

if (attachment!=null && attachment!="")
	{
	document.getElementById( 'attachment' ).innerHTML=attachment;

	}


	}

}






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.toUTCString());
}


function deletecookie(c_name)
{
var exdate=new Date();
exdate.setDate(exdate.getDate());
document.cookie=c_name+ "=" + ";expires="+exdate.toUTCString();
}


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 toggle_subscribe(user_id,topic_id,path)
{

var query="";


 var req = Inint_AJAX();
  req.open( "POST" , path+"forum_helper.php" , true );
  req.onreadystatechange = function()
  {
    if ( req.readyState == 4 )
    {
     if ( req.status == 200 )
     {

		
		if (req.responseText =='ok')
		{
		
		
		 hideTooltip();
		 if (document.getElementById( 'tg_subscr' ).title=="Click to unsubscribe this topic")
		{
			document.getElementById( 'tg_subscr' ).title="Click to subscribe this topic";
			document.getElementById( 'tg_subscr' ).innerHTML = "Subscribe this topic";
			document.getElementById( 'subscr_info' ).innerHTML ="unsubscribed";
		}else if (document.getElementById( 'tg_subscr' ).title=='Click to subscribe this topic')
		{
			document.getElementById( 'tg_subscr' ).title="Click to unsubscribe this topic";
			document.getElementById( 'tg_subscr' ).innerHTML = "Unsubscribe";
		document.getElementById( 'subscr_info' ).innerHTML ="Subscribed";
		
		}
		}
		
     };
    };
  };
  


if (document.getElementById( 'tg_subscr' ).title=="Click to unsubscribe this topic")
{
query="mode=subscribe&user_id="+user_id+"&topic_id="+topic_id+"&subscribe=0";
}else if (document.getElementById( 'tg_subscr' ).title=='Click to subscribe this topic')
{
query="mode=subscribe&user_id="+user_id+"&topic_id="+topic_id+"&subscribe=1";
}

req.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
  req.send( query );




}

jQuery(document).ready(function() {


jQuery(".field").mousedown(function(){

//clearTimeout ( LoginTimeoutId );
//clearTimeout ( ClearLoginTimeoutId );
	
});	
});	
		








