﻿//**************************************************************************
//** DTBH.js
//**************************************************************************

//==========================================================
//== JQuery functions
//==========================================================

  //------------------------------------------------
  //-- SetIframe
  //------------------------------------------------
  function SetIframe(url,sz) {
//    if ( sz == 2 ) document.getElementById("Panel_Left").style.display="none";
    document.getElementById("Panel_Ctr_Title").innerHTML = "New Title";
    alert(url);
  }

  //------------------------------------------------
  //-- LoadComponent (render Ajax in center pane)
  //------------------------------------------------
    function LoadComponent(nP,C,T,Parms) {
      var SP = ( nP == 1 ) ? "block" : "none" ;
      document.getElementById("Panel_left").style.display = SP;
      var S = "";
      var fnC = "";
      S += "<TABLE CellPadding='0' CellSpacing='0' Border='1' Width='100%' >"
      S += " <TR Height='22'><TD Class='Panel_Top'>&nbsp;&nbsp;" + T + "</TD></TR>" 
      S += " <TR VAlign='Top'>"
      S += "  <TD>"
      S += "   <DIV Id='Panel_Center_Body'>&nbsp;</DIV>"
      S += "  </TD>"
      S += " </TR>"
      S += "</TABLE>"
      document.getElementById("Panel_Center").innerHTML = S;
      if ( C == "PosseMember" ) {
        document.getElementById("Panel_Center_Body").innerHTML = PosseBio(Parms);
        fnC = "http://www.DogTheBountyHunter.com/datafiles/Bio_" + Parms + ".htm"
        $("#MbrBio").load(fnC);
      } else {
        fnC = "http://www.DogTheBountyHunter.com/Fanclub/Components/C_" + C + ".aspx"
        if ( Parms != "" ) fnC += "?" + Parms;
        $("#Panel_Center_Body").load(fnC);
      }
    }
    

  //------------------------------------------------
  //-- PosseBio
  //------------------------------------------------
    function PosseBio(Mbr) {
      var S = "";
      S += "<center>"
      S += "<img src='../Images/BountyHunterPhotos/HDR_" + Mbr + ".png' width='610'/>"
      S += "</center>"
      S += "<center>"
      S += "<table width='95%' cellpadding='6' cellspacing='0' border='0'>"
      S += "    <tr>"
      S += "        <td colspan='2'>"
      S += "<span class='PosseMbr_Ttl'>"
      S += Mbr
      S += "</span>"
      S += "<br />"
      S += "</td>"        
      S += "    </tr>"
      S += "    <tr>"
      S += "        <td width='70%'>"
      S += "        <span class='PosseMbr_Bio'>"
      S += "         <DIV Id='MbrBio'></DIV>"
      S += "        </span>&nbsp;"
      S += "        </td>"
      S += "        <td>"
      S += "        </td>"
      S += "    </tr>"
      S += "</table>"
      S += "</center>"
      return S;
    }      
      
  //------------------------------------------------
  //-- JQuery dialog code
  //------------------------------------------------
   
	$.ui.dialog.defaults.bgiframe = true;
      
    function PopUpDialog(Id) { alert(Id); 
      $('#dialog').dialog('open');
    }
      
    $(function() {
	$("#dialog").dialog({
		bgiframe: true,
		autoOpen: false,
		resizable: false,
		height:140,
		modal: true,
		overlay: { backgroundColor: '#000',
			       opacity: 0.5
		         },
		buttons: { 'Go': function() {$(this).dialog('close'); },
		Cancel: function() { $(this).dialog('close'); }
		}
	});
    });	


//==========================================================
//== Fugitive section functions
//==========================================================

  //---------------------------------------------
  //-- TogTab
  //---------------------------------------------
  function TogTab(Tab) {
    TabState("Tab1","none");
    TabState("Tab2","none");
    TabState("Tab3","none");
    TabState("Tab4","none");
    TabState("Tab5","none");
    TabState("Tab6","none");
    TabState(Tab,"block");
  }

  //------------------------------------------------
  //-- Tog_Fug_Panel
  //------------------------------------------------
  function Tog_Fug_Panel(n,onoff) {
    var o = document.getElementById("Fug_Panel_"+n);
    if ( onoff == 1 ) o.style.display = 'block'; 
    if ( onoff == 0 ) o.style.display = 'none'; 
  }

     
  //---------------------------------------------
  //-- bSearch_Click
  //---------------------------------------------
  function TabState(Tab,State) {
    if ( document.getElementById(Tab) ) document.getElementById(Tab).style.display=State;
  }
      
  //---------------------------------------------
  //-- TogDisplay
  //---------------------------------------------
  function TogDisplay(Id) {
    if ( !document.getElementById(Id) ) return false;
    if ( document.getElementById(Id).style.display != "block" ) 
        { document.getElementById(Id).style.display = "block"; }
    else 
        { document.getElementById(Id).style.display = "none"; }
  }

      
  //---------------------------------------------
  //-- bSearch_Click
  //---------------------------------------------
  function bSearch_Click(){
    var ImgLoading;
    ImgLoading = "Loading"
    var URL="http://www.StraightShooter.net/CUFF.asp?Meth=3487hYt6ghTTrRe";
    URL += ChkCB("Gender");
    URL += ChkCB("Race");
    URL += ChkCB("Eye_Color");
    URL += ChkCB("Hair_Color");
    URL += ChkCB("Age");
    URL += ChkCB("Height");
    URL += ChkCB("Weight");
    URL += ChkCB("State1");
    URL += ChkCB("State2");
URL += "&Gender=Female&Race=Asian&Hair_Color=Black"
    document.getElementById("Tab4").innerHTML=URL;
    document.getElementById("Tab2").style.display="none";
    document.getElementById("Tab4").style.display="block";
    
    $.ajax({
      url: URL,
      dataType: 'jsonp',
      success: function(msg){ alert( "Data Saved: " + msg ); }
    });
 
  }

  //---------------------------------------------
  //-- bRreset_Click
  //---------------------------------------------
  function bReset_Click(){
    document.getElementById("Gender").selectedIndex=-1;
    document.getElementById("Race").selectedIndex=-1;
    document.getElementById("Eye_Color").selectedIndex=-1;
    document.getElementById("Hair_Color").selectedIndex=-1;
    document.getElementById("Age").selectedIndex=-1;
    document.getElementById("Height").selectedIndex=-1;
    document.getElementById("Weight").selectedIndex=-1;
    document.getElementById("State1").selectedIndex=-1;
    document.getElementById("State2").selectedIndex=-1;
  
    }
    
  //---------------------------------------------
  //-- ListDBFields
  //---------------------------------------------
  function ListDBFields() {
    var URL="http://www.StraightShooter.net/CUFF.asp?DBFields=List";
    $("#Tab4").load(URL);
  }  



//==========================================================
//== Form check functions
//==========================================================

  //------------------------------------------------
  //-- FChk
  //------------------------------------------------
  function FChk(id) {
    var o = document.getElementById(id);
    if ( trim(o.value) == "" ) {
      ElementOutline(o,true);
      alert("A valid entry is required in the highlighted field");
      o.focus();
      return false;
    }
    return true;
  }
    
  //------------------------------------------------
  //-- RSet
  //------------------------------------------------
  function RSet(id) { document.getElementById(id).style.outlineStyle = "none"; }

  
  //------------------------------------------------
  //-- echeck
  //------------------------------------------------
  function echeck(id) {
      var o = document.getElementById(id);
      var str = o.value;
      var status = true;
      var at="@"
      var dot="."
      var lat=str.indexOf(at)
      var lstr=str.length
      var ldot=str.indexOf(dot)
      if (str.indexOf(at)==-1) status = false;
      if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) status = false;
      if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) status = false;
      if (str.indexOf(at,(lat+1))!=-1) status = false;
      if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) status = false;
      if (str.indexOf(dot,(lat+2))==-1) status = false;
      if (str.indexOf(" ")!=-1) status = false;
      if ( !status ) {
         ElementOutline(o,true);
         alert("Invalid Email Address :: "+str);
       	 return false;
      }
      return true;
  }

  //---------------------------------------------
  //-- ChkCB
  //---------------------------------------------
  function ChkCB(n) {
    var u = "";
    var o = document.getElementById(n);
    if ( o ) if ( o.selectedIndex != 0 ) u += "&" + n + "=" + o[o.selectedIndex].text;
    return u;  
  }  
  
  
  //------------------------------------------------
  //-- ElementOutline
  //------------------------------------------------
  function ElementOutline(o,iset) {
        if (!o) return false;
        if ( iset ) {
          o.style.outlineStyle = "dotted";
          o.focus();
        } else {
          o.style.outlineStyle = "none";
        }
  }



//==========================================================
//== Misc functions
//==========================================================

  function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
  }
  function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
  }
  function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
  }
  
function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
