//
// controls for handpost options
//
    var HANDPOST_user_id = -1;
    var HANDPOST_id = -1;
    var HANDPOST_actionindex = -1;
    var HANDPOST_fmt=1;
	var HANDPOST_div_id = "wt";
	var HANDPOST_tabView=null;
    
    function HANDPOST_setIDs($hand_id, $user_id, $actionindex)
    {
        HANDPOST_user_id = $user_id;
        HANDPOST_id = $hand_id;
        HANDPOST_actionindex = $actionindex;
		//HANDPOST_div_id = $div_id;
        
        HANDPOST_setButtons();
    }
    
	function HANDPOST_updateAllHH()
	{
		//, timeout: 25000
        var callback = { success:cb_responseSuccess, failure:cb_responseFailure }
        var tableform = document.getElementById("pgform");
        
        
        var oprof = document.getElementById("chkprofile");
        var opgsaved = document.getElementById("chkpgsettings");
        
        if(oprof && oprof.checked && !(opgsaved && opgsaved.checked))
        {
            if(!tableform.username.value)
            {
                alert("PostgreSQL username not set."); oprof.checked=false; return;
            }
            else if (!tableform.dbname.value)
            {
                alert("PostgreSQL database name not set."); oprof.checked=false; return;
            }
            else if (!tableform.port.value)
            {
                alert("PostgreSQL port not set."); oprof.checked=false; return;
            }
            else if (!tableform.password.value)
            {
                alert("PostgreSQL password not set."); oprof.checked=false; return;
            }
        }
    
        o = document.getElementById("status_div");
        if (o) o.style.visibility="visible";
	    
	    var postData = "updateALL=1&hand_id="+HANDPOST_id+"&user_id="+HANDPOST_user_id; 
	    var formObject = document.getElementById("pgform");
	    if (formObject)
            YAHOO.util.Connect.setForm(formObject);
            
	    var transaction = YAHOO.util.Connect.asyncRequest('POST', "p_handpost.php", callback, postData);
		//TABS_select('wt');
	}

	function HANDPOST_updateStyle()
	{
		//, timeout: 25000
        var callback = { success:cb_responseSuccess, failure:cb_responseFailure }
		var param = '';
        
        o = document.getElementById("status_div");
        if (o) o.style.visibility="visible";
		
		o = document.getElementById("r_card_mini");
		if (o.checked)
			param = "&deck=1";

		o = document.getElementById("r_card_1");
		if (o.checked)
			param = "&deck=5";

		o = document.getElementById("r_card_6");
		if (o.checked)
			param = "&deck=6";
	    
	    var postData = "applystyle=1&hand_id="+HANDPOST_id+"&user_id="+HANDPOST_user_id+param; 
	    var formObject = document.getElementById("style_form");
	    if (formObject)
            YAHOO.util.Connect.setForm(formObject);
            
	    var transaction = YAHOO.util.Connect.asyncRequest('POST', "p_handpost.php", callback, postData);
		//TABS_select('wt');
	}

    function HANDPOST_setPgControls()
    {
        o = document.getElementById("chkpgsettings");
        if (!o) return;
        
        if (o.checked)
        {
            o = document.getElementById("pguser"); if (o) o.disabled=true;
            o = document.getElementById("pgpass"); if (o) o.disabled=true;
            o = document.getElementById("pgport"); if (o) o.disabled=true;
            o = document.getElementById("pgdbname"); if (o) o.disabled=true;
        }
        else
        {
            o = document.getElementById("pguser"); if (o) o.disabled=false;
            o = document.getElementById("pgpass"); if (o) o.disabled=false;
            o = document.getElementById("pgport"); if (o) o.disabled=false;
            o = document.getElementById("pgdbname"); if (o) o.disabled=false;
        }
    }

	function HANDPOST_copy(text2copy)
    {
		//alert(text2copy);
        if (window.clipboardData)
        {
            window.clipboardData.setData("Text",text2copy);
        }
        else
        {
            var flashcopier = 'flashcopier';
            if(!document.getElementById(flashcopier))
            {
                var divholder = document.createElement('div');
                divholder.id = flashcopier;
                document.body.appendChild(divholder);
            }
            
            document.getElementById(flashcopier).innerHTML = '';
            var divinfo = '<embed src="swf/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
            document.getElementById(flashcopier).innerHTML = divinfo;
        }
	}
        
    function HANDPOST_enableControls(x)
    {
        var tableform = document.getElementById("pgform");
        
        var o = document.getElementById("chkprofile");
        if (o) o.disabled=x;
        o = document.getElementById("chknames");
        if (o) o.disabled=x;                
        o = document.getElementById("chkresults");
        if (o) o.disabled=x;                
        o = document.getElementById("chkmarksd");
        if (o) o.disabled=x;                
        o = document.getElementById("chkmarkrel");
        if (o) o.disabled=x;
        o = document.getElementById("actioncombo_id");
        if (o) o.disabled=x;
        
        tableform.username.disabled=x;
        tableform.dbname.disabled=x;
        tableform.port.disabled=x;
        tableform.password.disabled=x;
    }
        
    function HANDPOST_comboUpdate()
    {
        var o = document.getElementById("actioncombo_id");
        if (o)
        {
            var value = o.options[o.selectedIndex].value;
				
            if (value>0&&value<200)
			{
				o = document.getElementById("chkheroaction");
				o.disabled=false;
				o = document.getElementById("chkresults");
				o.disabled=true;
			}
			else
			{
				o = document.getElementById("chkresults");
				o.disabled=false;
				o = document.getElementById("chkheroaction");
				o.disabled=true;
			}

			if (value>0)
				HANDPOST_updateAllHH();
        }
    }
    
	function HANDPOST_copyMain(x)
	{
        o = document.getElementById("hh_textarea"+x);
        
		if (o)
		{
			str = o.innerHTML;
			//n = str.length;
			//a = str.substring(5,n-6);
			HANDPOST_copy(str);
		}
        else
        {
            o = document.getElementById(HANDPOST_div_id);
            if (o)	{ str = o.innerHTML; HANDPOST_copy(str); }
        }
	}
	
	function HANDPOST_setButtons()
	{
		if (HANDPOST_fmt == 1)
		{
			o = document.getElementById("HTMLbtn"); if (o) o.disabled=true;
			o = document.getElementById("HTMLith"); if (o) o.disabled=false;
			o = document.getElementById("HTM2p2"); if (o) o.disabled=false;
			o = document.getElementById("HTMLraw"); if (o) o.disabled=false;
		}
		else if (HANDPOST_fmt == 0)
		{
			o = document.getElementById("HTMLbtn");
			if (o) o.disabled=false;
			o = document.getElementById("HTMLith");
			if (o) o.disabled=false;
			o = document.getElementById("HTM2p2");
			if (o) o.disabled=false;
			o = document.getElementById("HTMLraw");
			if (o) o.disabled=true;
		}
		else if (HANDPOST_fmt == 2)
		{
			o = document.getElementById("HTMLbtn");
			if (o) o.disabled=false;
			o = document.getElementById("HTMLith");
			if (o) o.disabled=true;
			o = document.getElementById("HTM2p2");  
			if (o) o.disabled=false;
			o = document.getElementById("HTMLraw");
			if (o) o.disabled=false;
		}
		else if (HANDPOST_fmt == 3)
		{
			o = document.getElementById("HTMLbtn");
			if (o) o.disabled=false;
			o = document.getElementById("HTMLith");
			if (o) o.disabled=false;
			o = document.getElementById("HTM2p2");
			if (o) o.disabled=true;
			o = document.getElementById("HTMLraw");
			if (o) o.disabled=false;
		}
		
	}

	function HANDPOST_setHTML()
	{
		if (!CONTENT_isposting)
		{
			x_updateContent(1);
			o = document.getElementById("status_div");
            if (o) o.style.visibility="visible";
			HANDPOST_fmt=1;
			HANDPOST_setButtons();
		}
	}
	
	function HANDPOST_setITH()
	{
		if (!CONTENT_isposting)
		{
			x_updateContent(2);
			o = document.getElementById("status_div");
                        if (o) o.style.visibility="visible";
			HANDPOST_fmt=2;
			HANDPOST_setButtons();
		}
	}

	function HANDPOST_set2p2()
	{
		if (!CONTENT_isposting)
		{
			x_updateContent(3);
			o = document.getElementById("status_div");
                        if (o) o.style.visibility="visible";
			HANDPOST_fmt=3;
			HANDPOST_setButtons();
		}
	}

	function HANDPOST_setRAW()
	{
		if (!CONTENT_isposting)
		{
			x_updateContent(0);
			o = document.getElementById("status_div");
            if (o) o.style.visibility="visible";
            
			HANDPOST_fmt=0;
			HANDPOST_setButtons();
			
		}
	}

    function cb_voted(x)
    {
        // update
	    if(x.responseText !== undefined)
        {
            o = document.getElementById("vote");
            if (o) o.innerHTML=x.responseText;
	    }
    }

    function HANDPOST_updateVote(x)
	{
	    var callback =
	    {
	      success:cb_voted,
	      failure:cb_responseFailure
	    };
	    
	    var postData = "voted=1&hand_id="+HANDPOST_id+"&user_id="+HANDPOST_user_id+"&index="+HANDPOST_actionindex+"&action="+x;
	    var transaction = YAHOO.util.Connect.asyncRequest('POST', "p_handpost.php", callback, postData);
	}

	function HANDPOST_vote(x)
    {
            HANDPOST_updateVote(x);
	}

	function cb_responseSuccess(o)
	{
	    /* Please see the Success Case section for more
	    * details on the response object's properties.
	    * o.tId
	    * o.status
	    * o.statusText
	    * o.getResponseHeader[ ]
	    * o.getAllResponseHeaders
	    * o.responseText
	    * o.responseXML
	    * o.argument
	    */
    
	    if(o.responseText !== undefined){
            b = document.getElementById("status_div");
            if (b) b.style.visibility="hidden";
        
            // force to html for now
            b = document.getElementById(HANDPOST_div_id);
            if (b) b.innerHTML=o.responseText
            
            HANDPOST_fmt=1;
            CONTENT_isposting=0;
            //vote(-1);
	    }
	}
    
	function x_updateContent(theFormat)
	{
	    var callback =
	    {
	      success:cb_updateContent,
	      failure:cb_responseFailure
	    };
	    
	    var postData = "updatecontent=1&fmt="+(theFormat)+"&hand_id="+HANDPOST_id;
	    var transaction = YAHOO.util.Connect.asyncRequest('POST', "p_handpost.php", callback, postData);
	}

/*
	function HANDPOST_initTabs(id) {
		HANDPOST_tabView = new YAHOO.widget.TabView('wttabctrl');
		var tab0 = HANDPOST_tabView.getTab(0);
		tab0.set('dataSrc', 'p_handpost.php?updatecontent=1&fmt=1&hand_id='+id );
	
		var tab1 = HANDPOST_tabView.getTab(1);
		tab1.set('dataSrc', 'p_handpost.php?updatecontent=1&fmt=0&hand_id='+id );
	
		var tab2 = HANDPOST_tabView.getTab(2);
		tab2.set('dataSrc', 'p_handpost.php?updatecontent=1&fmt=3&hand_id='+id );
	
		var tab3 = HANDPOST_tabView.getTab(3);
		tab3.set('dataSrc', 'p_handpost.php?updatecontent=1&fmt=2&hand_id='+id );
		
		tt0 = new YAHOO.widget.Tooltip("tt0",  
								{ context:"wtlk",  text:"html view" });	
		tt1 = new YAHOO.widget.Tooltip("tt1",  
								{ context:"rawlk",  text:"raw Hand History" });	
		tt2 = new YAHOO.widget.Tooltip("tt2",  
								{ context:"2p2lk",  text:"two plus two forum format" });	
		tt3 = new YAHOO.widget.Tooltip("tt3",  
								{ context:"phplk",  text:"phpbb format: ITH, FTR" });	
	
	}
*/    
    

