<!--

  /**
   * Change the state of the submit button based on the privacy policy checkbox
   */
  function refreshPrivacyPolicy()
  {
    profile_form.submit.disabled = (! profile_form.privacy_read.checked);
    setTimeout("refreshPrivacyPolicy()",1000);
  }

  /**
   * Change an image on the page..based on an input on a form
   */
  function refreshImg(input_label, form, previous_value)
  {
    var image_src = document.forms[form].elements[input_label].value;
    var image_name = input_label + "_img";

    //if ((image_src.indexOf(":") >= 0) && (image_src.indexOf("http://") != 0))
    if (document.forms[form].elements[input_label].type.toLowerCase() == 'file')
    {
      while(image_src.indexOf("\\") >= 0)
        image_src = image_src.replace("\\","/");
      image_src = "file://" + image_src;
    }
    else if (image_src.indexOf("/") == 0)
    {
      image_src = "." + image_src;
    }

    if (previous_value != image_src)
    {
      document.images[image_name].border = 0;
      document.images[image_name].width = 75;
      document.images[image_name].height = 75;
      document.images[image_name].src = 'images/big-blank.gif';

      if ((image_src.toLowerCase().indexOf('.jpg') == (image_src.length - 4)) ||
          (image_src.toLowerCase().indexOf('.gif') == (image_src.length - 4)))
      {
        var img = new Image();
        img.src = image_src;

        var img_width = img.width;
        var img_height = img.height;

        var width = 75;
        var height = 75;

        if ((img_width > 0) && (img_height >0))
        {
          var scale_x = 75 / img_width;
          var scale_y = 75 / img_height;

          var scale = Math.min(scale_x,scale_y);
          width = Math.floor(scale * img_width);
          height = Math.floor(scale * img_height);

          document.images[image_name].border = 1;
          document.images[image_name].width = width-2;
          document.images[image_name].height = height-2;
          document.images[image_name].src = img.src;

          previous_value = image_src;
        }
      }
      else
        previous_value = '';
    }

    setTimeout("refreshImg('" + input_label + "','" + form + "','" + previous_value + "')",1000);
  }

  /**
   * Pops up preview window of what the bio will look like
   */
  function bio_preview(bio, name, organization, title, photo)
  {
    bio = validateStr(bio);
    name = validateStr(name);
    organization = validateStr(organization);
    title = validateStr(title);

    photo = validateImage(photo);

    var window_height = 300;
    var window_width = 450;

    url = "bio-preview.php?name=" + escape(name) + "&organization=" + escape(organization) + "&title=" + escape(title) + "&photo=" + escape(photo)  + "&bio=" + escape(bio);
    window.open(url,"preview","toolbar=no,resizable=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0,width=" + window_width + ",height=" + window_height);
  }

  /**
   * Pops up preview window of what the ticket2talk display will look like
   */
  function ticket2talk_preview(name, organization, title, photo, ticket_image, ticket_caption, ticket_type)
  {
    //if (checkProfileForm())
    var photo_obj = new Image();
    photo_obj.src = photo;
    var ticket_obj = new Image();
    ticket_obj.src = ticket_image;

    photo = validateImage(photo);
    ticket_image = validateImage(ticket_image);

    name = validateStr(name);
    organization = validateStr(organization);
    title = validateStr(title);


    ticket_caption = validateStr(ticket_caption);

    ticket_type = validateStr(ticket_type);

    var screen_width = screen.width;
    var screen_height = screen.height;

    var window_height = screen_height - 70; // give slack for start bar..
    var window_width = Math.floor((screen_height * 9) / 16);

    var photo_width = photo_obj.width;
    var photo_height = photo_obj.height;
    var ticket_width = ticket_obj.width;
    var ticket_height = ticket_obj.height;

    url = "ticket2talk-preview.php?name=" + escape(name) + 
          "&organization=" + escape(organization) + 
          "&title=" + escape(title) + 
          "&photo=" + escape(photo)  + 
          "&photo_width=" + photo_width +
          "&photo_height=" + photo_height +
          "&ticket_image=" + escape(ticket_image) + 
          "&ticket_width=" + ticket_width +
          "&ticket_height=" + ticket_height +
          "&ticket_caption=" + escape(ticket_caption) + 
          "&ticket_type=" + escape(ticket_type) + 
          "&height=" + window_height + 
          "&width=" + window_width;

// is flatpanel resolution 800 by 450?
//    window.open(url,"preview","toolbar=no,resizable=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0,width=545,height=880");
    window.open(url,"preview","location=no,toolbar=no,resizable=no,scrollbars=no,left=0,top=0,screenX=0,screenY=0,width=" + window_width + ",height=" + window_height);
  }

  /**
   * Pops up window of what is being uploaded
   */
  function show_upload_progress(upload1, upload2, upload3, upload4, upload5)
  {
    var upload1_str = "";
    if ((upload1 != null) && (upload1 != "null") && (upload1 != "") && (upload1 != "undefined"))
      upload1_str = "?upload1=" + upload1;

    var upload2_str = "";
    if ((upload2 != null) && (upload2 != "null") && (upload2 != "") && (upload2 != "undefined"))
      upload2_str = "&upload2=" + upload2;

    var upload3_str = "";
    if ((upload3 != null) && (upload3 != "null") && (upload3 != "") && (upload3 != "undefined"))
      upload3_str = "?upload3=" + upload3;

    var upload4_str = "";
    if ((upload4 != null) && (upload4 != "null") && (upload4 != "") && (upload4 != "undefined"))
      upload4_str = "?upload4=" + upload4;

    var upload5_str = "";
    if ((upload5 != null) && (upload5 != "null") && (upload5 != "") && (upload5 != "undefined"))
      upload5_str = "?upload5=" + upload5;


    url = "upload.php" + upload1_str + upload2_str + upload3_str + upload4_str + upload5_str;
    window.open(url,"upload_progress","toolbar=no,resizable=no,scrollbars=yes,left=10,top=10,screenX=10,screenY=10,width=230,height=300");
  }

  /**
   * Pops up window that upload has completed
   */
  function show_upload_completed()
  {
    url = "upload-completed.php";
    upload_progress = window.open(url,"upload_progress","toolbar=no,resizable=no,scrollbars=yes,left=10,top=10,screenX=10,screenY=10,width=230,height=300");

    setTimeout('null',1000);
    upload_progress.close();
  }

  /**
   * Pops up privacy policy in a small window
   */
  function showPrivacyPolicy()
  {
    window.open("privacy_policy-unformatted.php","privacy_policy","toolbar=no,resizable=no,scrollbars=yes,left=0,top=0,screenX=50,screenY=50,width=500,height=400");
  }

  /**
   * Converts a null string into a blank string...
   */
  function validateStr(str)
  {
    if ((str == null) || (str == "null") || (str == "undefined"))
      str = " ";

    return(str);
  }

  /**
   * Converts a null image pointer into a blank image...
   */
  function validateImage(str)
  {
    if ((str == null) || (str == "null") || (str == "") || (str == "undefined"))
      str = "./images/blank.gif";

    while(str.indexOf("\\") >= 0)
      str = str.replace("\\","/");

    return(str);
  }

  /**
   * Force the users to have all the fields entered.
   */
  function checkForm(form)
  {
    var i=0;
    for (i=0; i<document.forms[form].elements.length; i++)
    {
      if ((document.forms[form].elements[i].value == null) || (Trim(document.forms[form].elements[i].value).length == 0))
      {
        if (document.forms[form].elements.length > 1)
          alert('Please fill all entries before proceeding.');
        else
          alert('Please fill in the entry before submitting.');
        return(false);
      }
    }

    return(true);
  }

function confirmDeleteProfile() {
  var confirmation = confirm( "Delete your profile?" );
  if ( confirmation ) {
    window.location = "profile-deleted.php";
  }
}

  /**
   * Changes a form input component to a file input component
   * str is the name of the component (either 'photo' or 'ticket_0_image')
   */
  function toFile(str,form)
  {
    var newEl = document.createElement('input');
    newEl.setAttribute('type', 'file');
    newEl.setAttribute('size', '24');
    newEl.setAttribute('name', str);

    document.forms[form].elements[str].parentNode.replaceChild(newEl,document.forms[form].elements[str]);
    document.forms[form].elements[str] = newEl;
  }

  /**
   * Changes a form input component to a textfield input component
   * str is the name of the component (either 'photo' or 'ticket_0_image')
   */
  function toText(str,form)
  {
    var newEl = document.createElement('input');
    newEl.setAttribute('type', 'text');
    newEl.setAttribute('size', '37');
    // newEl.setAttribute('value', 'http://');
    newEl.setAttribute('name', str);

    document.forms[form].elements[str].parentNode.replaceChild(newEl,document.forms[form].elements[str]);
    document.forms[form].elements[str] = newEl;
  }



  function Trim(TRIM_VALUE)
  {
    if (TRIM_VALUE.length < 1)
      return"";

    TRIM_VALUE = RTrim(TRIM_VALUE);
    TRIM_VALUE = LTrim(TRIM_VALUE);
    if(TRIM_VALUE=="")
      return "";
    else
      return TRIM_VALUE;
  } //End Function

  function RTrim(VALUE)
  {
    var w_space = String.fromCharCode(32);
    var v_length = VALUE.length;
    var strTemp = "";
    if(v_length < 0)
      return"";

    var iTemp = v_length -1;
    while(iTemp > -1)
    {
      if(VALUE.charAt(iTemp) == w_space)
      {
      }
      else
      {
        strTemp = VALUE.substring(0,iTemp +1);
        break;
      }

      iTemp = iTemp-1;
    } //End While

    return strTemp;
  } //End Function

  function LTrim(VALUE)
  {
    var w_space = String.fromCharCode(32);
    if(v_length < 1)
      return"";

    var v_length = VALUE.length;
    var strTemp = "";

    var iTemp = 0;
    while(iTemp < v_length)
    {
      if(VALUE.charAt(iTemp) == w_space)
      {
      }
      else
      {
        strTemp = VALUE.substring(iTemp,v_length);
        break;
      }


      iTemp = iTemp + 1;
    } //End While

    return strTemp;
  } //End Function




//-->

