var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	 xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest()
{
  var xmlHttp=null;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

var mnmxmlhttp = Array ();
var xvotesString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function vote (user, id, htmlid, md5, value, type)
{
  	if (xmlhttp) {
  	if (type == "links")
		  url = "http://www.ttiqq.com/vote.php";
		else
		  url = "http://www.ttiqq.com/rvote.php";
		var mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.ttiqq.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
     			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
          target1 = document.getElementById ('xvotes-' + htmlid);
     			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
    						changemnmvalues (htmlid, value, true);    					} else {
 if (xvotesString[htmlid].substring (1, 6) == "ERROR") {     						alert(xvotesString[htmlid]);  } else {    						changemnmvalues (htmlid, value, false); }     					}
    				}
    			}
    		}
    	}
	}
}

function unvote (user, id, htmlid, md5, value, type)
{
  	if (xmlhttp)
    {
      if (type == "links")
		    url = "http://www.ttiqq.com/vote.php";
		  else
		    url = "http://www.ttiqq.com/rvote.php";
		var mycontent = "unvote=true&id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.ttiqq.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");    
				  target1 = document.getElementById ('xvotes-' + htmlid);
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						 xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
							changemnmunvotevalues (htmlid, value, true);						} else {
              changemnmunvotevalues (htmlid, value, false);    				}
    				}
    			}
    		}
    	}
	}
}

function cvote (user, id, htmlid, md5, value)
{
	if (xmlhttp) {
		url = "http://www.ttiqq.com/cvote.php";
		mycontent = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value;
		anonymous_vote = false;
        if (anonymous_vote == false && user == '0') {
            window.location="http://www.ttiqq.com/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
    			mnmxmlhttp[htmlid].send (mycontent);
    			errormatch = new RegExp ("^ERROR:");
    			target1 = document.getElementById ('cvote-' + htmlid);
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			//target1.style.background = '#c00';
    			target1.style.backgroundColor = '#FFFFFF';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (xvotesString[htmlid].match (errormatch)) {
    						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
    						// myclearTimeout(row);
    						// resetrowfull(row);
    						changecvotevalues (htmlid, true);
    					} else {
							target1 = document.getElementById ('ratebuttons-' + id);
							target1.style.display = "none";
							target2 = document.getElementById ('ratetext-' + id);
							target2.innerHTML = "Thank you for rating this comment.";
							changecvotevalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}

function changemnmunvotevalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvoting-' + id);
	target3 = document.getElementById ('xunvoting-' + id);
	if (error) {
		if (value > 0) 
    { 
      target2.style.display = '';
      target3.style.display = 'none'; 
    }
		else if (value < 0) 
    { 
      target3.style.display = '';
      target2.style.display = 'none';
    }
		return false;
	}
	if (b.length <= 5) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
		if (value > 0) 
    { 
      target2.style.display = '';
      target3.style.display = 'none'; 
    }
	}
	return false;
}

function changemnmvalues (id, value, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('xvotes-' + id);
	target2 = document.getElementById ('xvoting-' + id);
	target22 = document.getElementById ('xunvoting-' + id);
	target3 = document.getElementById ('xreport-' + id);
	target4 = document.getElementById ('xnews-' + id);
	if (error) {
		if (value > 0) { target2.innerHTML = "<span>TTuqq</span> "; }
		else if (value < 0) { target2.innerHTML = "<span>Buried</span> "; }
		return false;
	}
	if (b.length <= 5) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
		if (value > 0) { 
      target2.style.display = 'none';
      target22.style.display = '';
    }
		else if (value < 0 ) 
    { 
      new Effect.Fade(target3);
      target2.innerHTML = "<span>Buried</span> ";
			new Effect.Opacity(target4, {duration:0.8, from:1.0, to:0.3}); }
	}
	return false;
}

function changecvotevalues (id, error)
{
	split = new RegExp ("~--~");
	b = xvotesString[id].split (split);
	//alert(id);
	target1 = document.getElementById ('cvote-' + id);
	//target2 = document.getElementById ('mnmlink-' + id);
	if (error) {
	//	target2.innerHTML = "<span>vote cast</span>";
		return false;
	}
	if (b.length <= 3) {
		target1.innerHTML = b[0];
		target1.style.backgroundColor = mnmPrevColor[id];
	//	target2.innerHTML = "<span>vote cast</span>";
	}
	return false;
}

function checkCheck(clickType, submitButton, captchaText)
{
  if (clickType.checked)
  {
    if (captchaText.value.length > 0)
    {
      submitButton.disabled = false;
    }
    else
      {submitButton.disabled = true;}
  }
  else
  {
    submitButton.disabled = true;
  }
}

function enablebutton (button, target)
{
	var string = target.value;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}

function checkfield (type, form, field)
{
	url = 'http://www.ttiqq.com/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);
	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
			if (responsestring == 1) {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:black">"' + field.value + 
						'": ' + "OK" + '</span>';
			} else {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:red">"' + field.value + '": ' +
				responsestring + '</span>';
				form.submit.disabled = 'disabled';
			}
		}
	}
  //  xmlhttp.setRequestHeader('Accept','message/x-formresult');
  checkitxmlhttp.send (null);
  return false;
}

function emailto (original_id, htmlid, instpath, address_count)
{
	email_message = document.getElementById('email_message' + htmlid).value;
	email_address = document.getElementById('email_address_1_' + htmlid).value;
	if (address_count > 1){ 
		for ($i = 2; $i <= address_count; $i++) {
			if(document.getElementById('email_address_' + $i + '_' + htmlid).value != "") {
				email_address = email_address + ', ' + document.getElementById('email_address_' + $i + '_' + htmlid).value;
			}
		}
	}
	
	if (xmlhttp) {
		url = "http://www.ttiqq.com/recommend.php";
		mycontent = "email_address=" + escape(email_address) + "&email_to_submit=submit&email_message=" + escape(email_message) + "&original_id=" + original_id + "&backup=0";
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Sending, please wait....";
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];

					}
				}
			}
		}
	}
}

function show_recommend(htmlid, linkid, instpath)
{
	var emailtodisplay=document.getElementById('emailto-' + htmlid).style.display ? '' : 'none';
	document.getElementById('emailto-' + htmlid).style.display = emailtodisplay;
	if (xmlhttp) {
		url = "http://www.ttiqq.com/recommend.php";
		mycontent = "draw=small&htmlid=" + htmlid + "&linkid=" + linkid;
		target2 = document.getElementById ('emailto-' + htmlid);
		target2.innerHTML = "<br>Loading, please wait....";
		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[htmlid].open ("POST", url, true);
			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type','application/x-www-form-urlencoded');
			mnmxmlhttp[htmlid].send (mycontent);
			errormatch = new RegExp ("^ERROR:");
			target1 = document.getElementById ('emailto-' + htmlid);
			mnmxmlhttp[htmlid].onreadystatechange = function () {
				if (mnmxmlhttp[htmlid].readyState == 4) {
					xvotesString[htmlid] = mnmxmlhttp[htmlid].responseText;
					if (xvotesString[htmlid].match (errormatch)) {
						xvotesString[htmlid] = xvotesString[htmlid].substring (6, xvotesString[htmlid].length);
						target2 = document.getElementById ('emailto-' + htmlid);
						target2.innerHTML = xvotesString[htmlid];
					} else {
						target2 = document.getElementById ('emailto-' + htmlid);
						 target2.innerHTML = xvotesString[htmlid];
					}
				}
			}
		}
	}
}

function stateChanged() 
{ 
  if (xmlHttp.readyState==4)
  { 
    document.getElementById("topContentBox").innerHTML=xmlHttp.responseText;
  }
}

function topBox(topType,category)
{
	xmlHttp=myXMLHttpRequest();
  if (xmlHttp==null)
    {
      alert ("Your browser does not support AJAX!");
      return;
    }
  if (topType == "tags")
  {
    var url="http://www.ttiqq.com/top-tags.php";
    document.getElementById("top1").innerHTML="<a href=\"javascript:topBox(\'published\',\'"+category+"\')\" class=\"navbut1\">Published</a>";
    document.getElementById("top2").innerHTML="<a href=\"javascript:topBox(\'upcoming\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-91px;\">Upcoming</a>";
    document.getElementById("top3").innerHTML="<a href=\"javascript:topBox(\'requests\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-182px;\">Requests</a>";
    document.getElementById("top4").innerHTML="<a href=\"javascript:topBox(\'tags\,\'"+category+"\'')\" class=\"navbut2\" style=\"position: relative; left:-273px;\">Tags</a>";
  } 
  else if (topType == "published")
  {
    var url="http://www.ttiqq.com/top-posts.php?pageType=published&category="+category;
    document.getElementById("top1").innerHTML="<a href=\"javascript:topBox(\'published\',\'"+category+"\')\" class=\"navbut2\">Published</a>";
    document.getElementById("top2").innerHTML="<a href=\"javascript:topBox(\'upcoming\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-91px;\">Upcoming</a>";
    document.getElementById("top3").innerHTML="<a href=\"javascript:topBox(\'requests\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-182px;\">Requests</a>";
    document.getElementById("top4").innerHTML="<a href=\"javascript:topBox(\'tags\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-273px;\">Tags</a>";
    
  }
  else if (topType == "upcoming")
  {
    var url="http://www.ttiqq.com/top-posts.php?pageType=upcoming&category="+category;
    document.getElementById("top1").innerHTML="<a href=\"javascript:topBox(\'published\',\'"+category+"\')\" class=\"navbut1\">Published</a>";
    document.getElementById("top2").innerHTML="<a href=\"javascript:topBox(\'upcoming\',\'"+category+"\')\" class=\"navbut2\" style=\"position: relative; left:-91px;\">Upcoming</a>";
    document.getElementById("top3").innerHTML="<a href=\"javascript:topBox(\'requests\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-182px;\">Requests</a>";
    document.getElementById("top4").innerHTML="<a href=\"javascript:topBox(\'tags\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-273px;\">Tags</a>";
  }
  else
  { 
    var url="http://www.ttiqq.com/top-requests.php?category="+category;
    document.getElementById("top1").innerHTML="<a href=\"javascript:topBox(\'published\',\'"+category+"\')\" class=\"navbut1\">Published</a>";
    document.getElementById("top2").innerHTML="<a href=\"javascript:topBox(\'upcoming\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-91px;\">Upcoming</a>";
    document.getElementById("top3").innerHTML="<a href=\"javascript:topBox(\'requests\',\'"+category+"\')\" class=\"navbut2\" style=\"position: relative; left:-182px;\">Requests</a>";
    document.getElementById("top4").innerHTML="<a href=\"javascript:topBox(\'tags\',\'"+category+"\')\" class=\"navbut1\" style=\"position: relative; left:-273px;\">Tags</a>";
  }
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

/***********************************************************************************************

Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com

Get this and other scripts at www.dhtmlgoodies.com

You can use this script freely as long as this copyright message is kept intact.

***********************************************************************************************/
var menuAlignment = 'left';	// Align menu to the left or right?	
var topMenuSpacer = 15; // Horizontal space(pixels) between the main menu items	
var activateSubOnClick = false; // if true-> Show sub menu items on click, if false, show submenu items onmouseover
var leftAlignSubItems = true; 	// left align sub items t

var activeMenuItem = false;	// Don't change this option. It should initially be false
var activeTabIndex = 0;	// Index of initial active tab	(0 = first tab) - If the value below is set to true, it will override this one.
var rememberActiveTabByCookie = true;	// Set it to true if you want to be able to save active tab as cookie

var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
var navigatorVersion = navigator.appVersion.replace(/.*?MSIE ([0-9]\.[0-9]).*/g,'$1')/1;
	
/*
These cookie functions are downloaded from 
http://www.mach5.com/support/analyzer/manual/html/General/CookiesJavaScript.htm
*/	
function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 
// This function has been slightly modified
function Set_Cookie(name,value,expires,path,domain,secure) { 
	expires = expires * 60*60*24*1000;
	var today = new Date();
	var expires_date = new Date( today.getTime() + (expires) );
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires_date.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
}	

function showHide()
{
	if(activeMenuItem){
		activeMenuItem.className = 'inactiveMenuItem'; 	
		var theId = activeMenuItem.id.replace(/[^0-9]/g,'');
		document.getElementById('submenu_'+theId).style.display='none';
		var img = activeMenuItem.getElementsByTagName('IMG');
		if(img.length>0)img[0].style.display='none';			
	}

	var img = this.getElementsByTagName('IMG');
	if(img.length>0)img[0].style.display='inline';
			
	activeMenuItem = this;		
	this.className = 'activeMenuItem';
	var theId = this.id.replace(/[^0-9]/g,'');
	document.getElementById('submenu_'+theId).style.display='block';
	

			
	if(rememberActiveTabByCookie){
		Set_Cookie('dhtmlgoodies_tab_menu_tabIndex','index: ' + (theId-1),100);
	}
}

function initMenu()
{
	var mainMenuObj = document.getElementById('mainMenu');
	var menuItems = mainMenuObj.getElementsByTagName('A');
	if(document.all){
		mainMenuObj.style.visibility = 'hidden';
		document.getElementById('submenu').style.visibility='hidden';
	}		
	if(rememberActiveTabByCookie){
		var cookieValue = Get_Cookie('dhtmlgoodies_tab_menu_tabIndex') + '';
		cookieValue = cookieValue.replace(/[^0-9]/g,'');
		if(cookieValue.length>0 && cookieValue<menuItems.length){
			activeTabIndex = cookieValue/1;
		}			
	}
	
	var currentLeftPos = 15;
	for(var no=0;no<menuItems.length;no++){			
		if(activateSubOnClick)menuItems[no].onclick = showHide; else menuItems[no].onmouseover = showHide;
		menuItems[no].id = 'mainMenuItem' + (no+1);
		if(menuAlignment=='left')
			menuItems[no].style.left = currentLeftPos + 'px';
		else
			menuItems[no].style.right = currentLeftPos + 'px';
			
		currentLeftPos = currentLeftPos + menuItems[no].offsetWidth + topMenuSpacer; 
		
		var img = menuItems[no].getElementsByTagName('IMG');
		if(img.length>0){
			img[0].style.display='none';
			if(MSIE && !Opera){
				img[0].style.bottom = '-1px';
				img[0].style.right = '-1px';
			}
		}
					
		if(no==activeTabIndex){
			menuItems[no].className='activeMenuItem';
			activeMenuItem = menuItems[no];
			var img = activeMenuItem.getElementsByTagName('IMG');
			if(img.length>0)img[0].style.display='inline';	
						
		}else menuItems[no].className='inactiveMenuItem';
		if(!document.all)menuItems[no].style.bottom = '-1px';
		if(MSIE && navigatorVersion < 6)menuItems[no].style.bottom = '-2px';
		

	}		
	
	var mainMenuLinks = mainMenuObj.getElementsByTagName('A');
	
	var subCounter = 1;
	var parentWidth = mainMenuObj.offsetWidth;
	while(document.getElementById('submenu_' + subCounter)){
		var subItem = document.getElementById('submenu_' + subCounter);
		
		if(leftAlignSubItems){
			// No action
		}else{							
			var leftPos = mainMenuLinks[subCounter-1].offsetLeft;
			document.getElementById('submenu_'+subCounter).style.paddingLeft =  leftPos + 'px';
			subItem.style.position ='absolute';
			if(subItem.offsetWidth > parentWidth){
				leftPos = leftPos - Math.max(0,subItem.offsetWidth-parentWidth); 	
			}
			subItem.style.paddingLeft =  leftPos + 'px';
			subItem.style.position ='static';
				
			
		}
		if(subCounter==(activeTabIndex+1)){
			subItem.style.display='block';
		}else{
			subItem.style.display='none';
		}
		
		subCounter++;
	}
	if(document.all){
		mainMenuObj.style.visibility = 'visible';
		document.getElementById('submenu').style.visibility='visible';
	}		
	document.getElementById('submenu').style.display='block';
}