// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var tweenInterval;
var newEventVisible = false;
var mainHeight = 0;
var ie = (document.all)? true:false;

function insertAtCursor(myField,myValue) {

  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
                  + myValue 
                  + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
}

if(document.images) {
    var top = new Image(800,26);
    var bottom = new Image(800,7);
    top.src = "/images/wrapper_top.png";
    bottom.src = "/images/wrapper_bottom.png";
}

function preloadRollovers(source) {
  if(document.images) {
    for(i=0;i<source.length;i++) {
      tmp_img = new Image(110,35);
      tmp_img.src = source[i];
    }
  }
}

$$$ = function(class_name, scope) {
  if(!scope) { scope = document; }
  scope = $(scope);
  return $A(document.getElementsByClassName(class_name, scope));
}

var activeTab = null;
var activeContent = null;
toggleTabs = function(el_a, el_d) {
    if($(activeTab) != null) $(activeTab).removeClassName('active');
    if($(activeContent) != null) $(activeContent).hide();
  if(activeTab != el_a) {
      activeTab = el_a;
      activeContent = el_d;
      $(activeTab).addClassName('active');
      $(activeContent).show();
  } else {
    activeTab = null;
    activeContent = null;
  }
}

forgotPassword = function(cancel) 
{
  if(cancel) {
    $('login_form').show();
    $('forgot_password_form').hide();
    $('box_title').innerHTML = 'Sign in';
    $('login_username').focus();
  } else {
    $('login_form').hide();
    $('forgot_password_form').show();
    $('box_title').innerHTML = 'Forgot Password';
    $('email').focus();
  }
}

setBlankTargets = function(el) 
{
  $$('#'+el+ ' a').each(function(el) {
    if(el.href.match('http')) {
      el.setAttribute('target', '_blank');
    }
  });
}

// for use with script.aculo.us
effectTimout = function(effectName, el, duration) 
{
  // call script.aculo.us Effect
  var eto = setInterval(function() {
    Effect[effectName](el);
    clearTimeout(eto);
  }, (duration*1000));
}

clearOverlay = function() 
{
  $('overlay').hide();
  $('user_overlay').hide();
  $('overlay_content').update('');
}

tweenElement = function()
{
  this.expandHeight = function(element, startH, endH, speed) {
    dir = startH < endH ? 1 : -1;
    if(expandInterval != undefined) clearInterval(expandInterval);
    var distance = Math.abs(endH-startH);
    var duration = speed ? speed : Math.round(distance/30);
    var counter = 0;
    var expandInterval = setInterval(function() {
      if(counter < duration) {
        newHeight = Math.easeOutQuad(counter, startH, (endH-startH), duration);
        element.style.height = newHeight+"px";
        counter ++;
      } else {
        element.style.height = endH+"px";
        clearInterval(expandInterval);
      }
    }, 10);
  }
}

balanceColumns = function(init)
{  
    // Set all column heights to auto
    $$(".col").each(function(el) {
      $A(el.getElementsByTagName("div")).first().style.height = "auto";
    });
    // Get the height of the containing element
    containerHeight = returnHeight('main');
    //alert(containerHeight);
    //alert("containerHeight = " + containerHeight);
    // Set the height of each column to the containers height
    $$(".col").each(function(el) {
      if(el.style.display != "none") {
        $A(el.getElementsByTagName("div")).first().style.height = containerHeight+"px";
      }
    });
    
    if(init || Element.visible('overlay')) {
      //$('main').style.height = containerHeight + "px";
    } else {
      $('main').prototype = new tweenElement;
      $('main').prototype.expandHeight($('main'), mainHeight, containerHeight);
    }
    mainHeight = returnHeight('main');
}

hScroll = function(dir) 
{
  $$("#choose_a_place .simplicity").each(function(el) {
    el.show();
  });
  curX = $$("#choose_place .mask_element").first().offsetLeft;
  endX = curX+(-200*dir);
  tween('choose_place', curX, endX);  
}

returnHeight = function(el) 
{
    //alert($$('#'+el+' div').first().getHeight());
  return $$('#'+el+' div')[1].offsetHeight;
}

getWindowHeight = function() 
{
  var windowHeight = 0;
  if (typeof(window.innerHeight) == 'number') {
    windowHeight=window.innerHeight;
  } else {
    if (document.documentElement && document.documentElement.clientHeight) {
      windowHeight = document.documentElement.clientHeight;
    }
    else {
      if (document.body && document.body.clientHeight) {
        windowHeight = document.body.clientHeight;
      }
    }
  }
  return windowHeight;
}

var activeZone;
var activeCategory;
var activeScene;
flyout = function(col, refererId, startX, endX, scene) 
{
  $(col).show();
  if(col == 'categories_and_scenes') {
    if(activeZone) $(activeZone).removeClassName('active');
    activeZone = refererId;
    if(activeCategory) {
      if(activeZone) $(activeZone).removeClassName('active');
      $(activeCategory).removeClassName('active');
      activeCategory = null;
      tween('places', endX, startX);
      balanceColumns();
    } else {
      /*if(!$(categories_and_scenes).addClassName("expanded")) {*/
                tween('categories_and_scenes', startX, endX);
           /*     $(categories_and_scenes).addClassName("expanded");
            } else {
                $(categories_and_scenes).removeClassName("expanded");            
            }*/
    }
  } else if (col == 'places') {
    if(activeCategory) {
      //if(refererId != null) new Effect.Highlight(refererId, {duration:'2', startcolor:'#EEEEEE', endcolor:'#e4e6ea', restorecolor:'#e4e6ea'});
      
            $(activeCategory).removeClassName('active');
    } else {
      tween('places', startX, endX);
    }
        if(activeScene) $(activeScene).removeClassName('active');
        activeScene = scene;
        $(activeScene).addClassName('active');
    activeCategory = refererId;
  }
  if(refererId != null) $(refererId).addClassName('active');
}

expandElement = function(el) 
{
  var expandA = $(el + '_expand');
  var expandOverview = $(el + '_overview');
  if($(el).hasClassName('expanded')) {
    $(el).removeClassName('expanded');
    expandOverview.hide();
    expandA.innerHTML = '+';
  } else {
    $(el).addClassName('expanded');
    expandOverview.show();
    //expandA.innerHTML = '-';
  }
  
}

/* Start the magic
*/
var ddz = 5000; var ddiz = 500;
var dropTimout;
var ddVisible = false;
var activeDropDown = 0;
var m_over = false;

toggleTagManager = function(el, hide) 
{
  el = $(el.id + '_tag_list');
  toggleAppearHide(el, hide, 0.5);
}

toggleAppearHide = function(el, bool, speed) 
{
  if(hide) {
    Effect.Appear(el, {duration: speed});
  } else {
    Effect.Fade(el, {duration: speed});
  }
}

toggleDropDown = function(id) 
{
  /*if(id != activeDropDown && activeDropDown != 0) {
    toggleDropDown(activeDropDown);
  }*/
  if($(id).hasClassName('active')) {
    $(id).addClassName('active');
    activeDropDown = null;
  } else {
    $(id).addClassName('active');
    activeDropDown = id;
  }
  $(id).style.zIndex = ddz++;
  $$('#'+id + ' .drop_down_i').each(function(el) {
    el.style.zIndex = ddiz++;
    if(el.hasClassName('visible')) {
      el.removeClassName('visible');
      /*Event.stopObserving(window, 'mousedown', hideDropDown);
      Event.stopObserving(el, 'mouseout', setMouseOut);
      Event.stopObserving(el, 'mouseover', setMouseOver);*/
      Effect.Fade(el, {duration: 0.1});
    } else {
      el.addClassName('visible');
      ddVisible = true;
      Effect.Appear(el, {duration: 0.2});  
      /*Event.observe(el, 'mouseout' , setMouseOut);
      Event.observe(el, 'mouseover', setMouseOver);
      Event.observe(window, 'mousedown', hideDropDown);*/
    }
  });
  $$('#'+id + ' .drop_down_a').each(function(el) {
    el.style.zIndex = ddiz++;
    if(el.hasClassName('active_drop_down')) {
      el.removeClassName('active_drop_down');
    } else {
      el.addClassName('active_drop_down');
    }  
  });  
  $$('#'+id + ' .drop_down_i ul li').each(function(el) {
    Event.observe(el, 'click', function() {
      if(this.hasClassName('checked')) {
        this.removeClassName('checked');
      } else {
        this.addClassName('checked');
      }
    }.bindAsEventListener(el));
  });
}
/* 
End the magic */

tween = function(id, startP, endP) 
{
  element = null;
  $(id).show();
  clearInterval(tweenInterval);
  element = $$('#'+id + ' .mask_element').first();
  if(element.style.marginLeft != endP) {
    margin = startP;
    element.style.marginLeft = startP+"px";
    dir = startP < endP ? 1 : 0;
    //distRatio = dir ? (endP/startP)*100 : (startP/endP)*100;
    var duration = 10//100-Math.round(100*distRatio);
    var counter = 0;
    tweenInterval = setInterval(function() {
      if(counter <= duration) {
        margin = Math.ceil(Math.easeOutQuad(counter, startP, (endP-startP)*1, duration));
        element.style.marginLeft = margin+"px";
        counter ++;
      } else {
        clearInterval(tweenInterval);
      }
    },10);
  }
}

/* highlight form elements
*/
highlight = function(element) 
{
  Event.observe(element, "focus", function() {
    this.style.backgroundColor = "#ebf4fb";
  }.bind(element));
  Event.observe(element, "blur", function() {
    this.style.backgroundColor = "#FFFFFF";
  }.bind(element));
}

animateMeetupContentArea = function(id, startP, endP) 
{
  if(!$(id).visible()) {
    $(id).show();
  }
  tween(id, startP, endP);
}

showMediaUploader = function(list, showID) {
  if($(showID).hasClassName('visible')) {
    $(list).removeClassName('highlighted');
    $(showID).removeClassName('visible');
    $(showID).hide();
  } else {
    //$$("#" + list + " a").first().style.backgroundColor = "#eaf1f5";
    $(showID).show();
    $(list).addClassName('highlighted');
    $(showID).addClassName('visible');
  }
  resetWindowHeight();
}

fixThumbnailOrder = function() {
  var children = $A($('media_thumbs').childNodes).map( 
    function(el) { 
      if(el.tagName == 'DIV') return el; return null; 
    }
  ).compact()
  var i = 1;
  children.each(function(el) {
    el.childNodes[1].childNodes[0].innerHTML = i;
    i++;
  });
}

toggleCommentForm = function(el) 
{
  $(el).toggle();
  resetWindowHeight();
  balanceColumns();
}

showComments = function(el) 
{
  $('show_all').hide();
  $('hide_all').show();
  document.getElementsByClassName('comment', el).each( function(value) {
    value.show();
  })
  resetWindowHeight();
  balanceColumns();
}

hideComments = function(el) 
{
  $('show_all').show();
  $('hide_all').hide();
  document.getElementsByClassName('comment', el).each( function(value) {
    value.hide();
  })
  resetWindowHeight();
  balanceColumns();
}

setOverlayWidth = function(el) 
{  
  $('overlay_content').style.width = "100%";
  $('overlay_content').style.width = $(el).clientWidth+12/*-padding*/ + "px";
}

// user_info, login
showUserOverlay = function(id) {
  $("login").hide();
  $("user_info").hide();
  $(id).show();
  $('overlay').show(); 
  showColorOverlay();
  
  $('user_overlay').show();
  $('user_info_form_submit').style.backgroundColor = "#0076CC";
  
  $$$("text", id).each(highlight);
  if(id) { $(id).show() };
  $$$("text", id).first().focus();
  $$$("text", id).first().select();
}

/* Loading Details
*/
showLoadingMessage = function() 
{
  showOverlay();
  $('overlay_content').innerHTML = "<div id=\"loading_dials\"><img src=\"/images/loading_dials.gif\" width=\"52\" height=\"52\" alt=\"...\" /></div>"
    
  /*Event.observe(window, 'keypress', function(Key) {
        if (Key.which == 113) {
            if(Key.altKey) {
                clearOverlay();
            }
        }
    });*/
}

showOverlay = function()
{
  document.documentElement.scrollTop = 0;
  if(!$('overlay').visible()) {
    $('overlay').show();
    showColorOverlay();
  }
}
showColorOverlay = function() 
{
  if ($('color_overlay')) {
  	$('color_overlay').show();
  	resetWindowHeight();
  }
}

resetWindowHeight = function() 
{
  var overlayHeight = $('overlay_content').offsetHeight + $('overlay_content').offsetTop;
  var wrapperHeight = $('wrapper').offsetHeight + $('wrapper').offsetTop + 40;
  var heightValues = [overlayHeight,wrapperHeight,getWindowHeight()];  
  var h = Math.maxNum(heightValues);
  $('color_overlay').style.height = h+'px';
  $('overlay').style.height = h+'px';
}

hideLoadingMessage = function() 
{
  $('overlay').hide();
  $('color_overlay').hide();
}
/*
END Loading Details */

resetToCityList = function() 
{
  Effect.Fade('city_label', {"duration":1});
  $('city_list').show();
  $('neighborhood_list').hide();
  $('places').hide();
  $('categories_and_scenes').hide();
  Effect.Appear('welcome_screen', {"duration":1});
  activeZone = null;
  activeCategory = null;
  activeScene = null;
  balanceColumns();
}

/* Contact List
*/
var populate = null;

clearTextField = function(el, val) {
  if(el.value == val) {
    el.value = "";
    el.style.color = "#000"
  }
}

restoreTextField = function(el, val) {
  if(el.value == "") {
    el.value = val;
    el.style.color = "#666"
  }
}

showAddressBook = function(version, submit_label) {
  $('invite_controls').hide();
  resetContactList($('list'));
  showOverlay(); 
  $('address_book_overlay').show();
  setOverlayWidth('contact_list');
  $('contact_list_header').update(version);
  if(version != "Address Book") $('invite_contacts_link').value = submit_label;
}

showImportOptions = function() {
  $('upload_with_evite').hide();
  $('upload_with_csv').hide();
  $('add_many_contacts_form').hide();
  Effect.Appear("add_many_contacts", {duration: 0.3})
  $('select_import_type').show();
}

resetContactList = function(el) { 
  if(populate != null) clearInterval(populate);
  $('address_book_overlay').hide();
  clearOverlay();
  el.innerHTML = "<li id=\"loading_contacts\">Loading Contacts...</li>";
  $("loading_contacts_spinner").show();
}

populateContacts = function(text, inviteMode, hideMobileNumbers) {
  contactInvitations = {}
  contactList = $("list");
  contactList.innerHTML = "";
  contactList.scrollTop = 0;
  $('no_contacts').hide();
  if(text != " ") {
    mod = 4;
    count = 0;
    group = "";
    if(hideMobileNumbers) {
      $('new_share').value = hideMobileNumbers;
    } else {
      $('new_share').value = "false";
    }
    if (inviteMode) {
      $('event_id').value = inviteMode;
      $('new_contact_event_id').value = inviteMode;
      $('invite_controls').show();
    } else {
      $('event_id').value = "";
      $('new_contact_event_id').value = "";
    }
    $$$("close_btn", "contact_list").each(function(el) {
      el.onclick = function() {
        if(inviteMode && !hideMobileNumbers) {
          if(confirm('Close without inviting any contacts?')){
            resetContactList(contactList);
          }
        } else if(inviteMode && hideMobileNumbers) {
  				if(confirm('Close without sending your event link to anyone?')) {
  					resetContactList(contactList);
  				}
  			} else {
          resetContactList(contactList);
        }
      	return false;
  		}  
    });
    contacts = text.split('~|~');
    rows = contacts.length;
    populate = setInterval( function() {
      group += contacts[count];
      if(count % mod == mod - 1) {
        contactList.innerHTML += group;
        group = "";
        contactList.scrollTop = contactList.scrollTop;
      }
      count++;
      if(count == rows) {
        contactList.innerHTML += group;
        $("loading_contacts_spinner").hide();
        clearInterval(populate);
        /*if(inviteMode) $$$("checkcell", "contact_list").each(rowSelection);*/
      }
    }, 10 * mod);
  } else {
    // There are no contacts
    $("loading_contacts_spinner").hide();
    $('no_contacts').show();
  }
}

// applied onmouseover
selectContactMethod = function(dom_id, contactMethod) {
  var row = $(dom_id);
  var cell = $(dom_id+"_"+contactMethod);
  cell.onmouseover = null;
  var options = 0;
  var selectedOptions = 0;
  var hasMobile = $("contacts_"+dom_id+"_sms");
  var hasEmail = $("contacts_"+dom_id+"_email");
  /*if(hasMobile) options++;
  if(hasEmail)  options++;*/
  cell.style.cursor = "pointer";
  cell.onclick = function(event) {
    if(!contactInvitations[dom_id]) contactInvitations[dom_id] = {};
    if(cell.hasClassName("sms") && hasMobile) {
      if($("contacts_"+dom_id+"_sms").hasClassName("selected")) {       
        selectedOptions--;
        contactInvitations[dom_id]['sms'] = false;
        $("contacts_"+dom_id+"_sms").removeClassName("selected");
      } else {
        selectedOptions++;
        contactInvitations[dom_id]['sms'] = true;
        $("contacts_"+dom_id+"_sms").addClassName("selected");
      }
    } else if(cell.hasClassName("email") && hasEmail) {
      if($("contacts_"+dom_id+"_email").hasClassName("selected")) {      
        selectedOptions--;
         contactInvitations[dom_id]['email'] = false;
        $("contacts_"+dom_id+"_email").removeClassName("selected");
      } else {        
        selectedOptions++;
         contactInvitations[dom_id]['email'] = true;
        $("contacts_"+dom_id+"_email").addClassName("selected");
      }
    }
    $('invitees').value = toJSON(contactInvitations);
  };
}
clearContactEvents = function(dom_id) {
  el = $(dom_id);
  el.removeAttribute("onmouseover");
  el.onclick = "null";
  el.style.cursor = "default";
  $("contacts_" + el.id).removeClassName('check');
  $("contacts_" + el.id).removeClassName('selected');
}
toJSON = function (invitations) {
  s = [];
  for (var contact in invitations) {
      s.push('"' + contact + '"' + ':' + '{"sms":' + toBoolean(invitations[contact]["sms"]) + ', "email":' + toBoolean(invitations[contact]["email"]) + "}")
  }
  return "{" + s.join(", ") + "}";
};
toBoolean = function(val) {
  return val == true;
}

var optionsPanelVis = 0;
createNewContact = function() {
  if ($('import_contacts_form')) {$('import_contacts_form').hide()};
  $('new_contact_form').hide();
  Effect.Appear('new_contact_form', {"duration":1});
  if(!optionsPanelVis) toggleOptionsPanel();
}
/*importContacts = function() {
  $('new_contact_form').hide();
    $('import_contacts_form').hide();
    Effect.Appear('import_contacts_form', {"duration":1});
  if(!optionsPanelVis) toggleOptionsPanel();
}*/

toggleOptionsPanel = function() {
  if(!optionsPanelVis) {
    $('options_expand').show();
    optionsPanelVis = 1;
    $('options_expand').prototype.expandHeight($('options_expand'), 0, 40, 10);
  } else {
    optionsPanelVis = 0;
    $('options_expand').prototype.expandHeight($('options_expand'), 40, 0, 10);    
  }
}

validate = function(formElement) {
  /* validate form elements */
  $('user_info_message').style.visibility = "hidden";
  error = 0;
  for(var i=0; i<formElement.elements.length; i++) {
    // Check if required
    el = formElement.elements[i];
    el.style.backgroundColor = "#FFF";
    if(el.hasClassName("required")) {
      if($F(el) == "") {
        $(el.id).style.backgroundColor = "#EBF4FB";
        returnStatus(el, "All fields required");
        error = 1;
        return false;
      } else if(!error && el.id == "user_info_username" && el.value.length < 4) {
        returnStatus(el, "Username must be at least 4 characters");
        error = 1;
        return false;
      } else if(!error && el.id == "user_info_raw_password" && el.value.length < 6) {
        returnStatus(el, "Password must be at least 6 characters");
        error = 1;
        return false;
      } else if(!error && el.id == "user_info_raw_password_confirmation" && el.value != formElement.elements[i-1].value) {
        returnStatus(el, "Passwords don't match");
        error = 1;
        return false;
      } else if(!error && el.id == "user_info_zip" && el.value.length != 5) {
        returnStatus(el, "Please enter a 5 character zip code");
        error = 1;
        return false;
      }
    }
  }
  return true;
}
function returnStatus(el, message) {
  $('user_info_message').innerHTML = message;
  $('user_info_message').style.visibility = "visible";
  el.focus();
}
blurLinks = function () {
  $$('body a').each(function(el) {
    el.setAttribute("onfocus", "this.blur();");
  });
}

applyUIMouseEvents = function() {
  $$('.ui_button', '.ui_button_small', '.submit_button').each(function(el){
    Event.observe(el, 'mousedown', function() {
      this.addClassName('on');
    }.bindAsEventListener(el));
    Event.observe(el, 'mouseup', function() {
      this.removeClassName('on');
    }.bindAsEventListener(el));
    Event.observe(el, 'mouseout', function() {
      this.removeClassName('on');
    }.bindAsEventListener(el));
  });
}

reInit = function() {  
  $$$("initially_hidden").each(function(el){ el.hide(); el.removeClassName('initially_hidden');});
  blurLinks();
  /*applyUIMouseEvents();*/
}

Math.maxNum = function(arr) {
  return arr.inject(null, function(result, n) {
  if(result == null || n > result) { result = n;}
     return result;
  })
}

 ///////////// ROBERT PENNER'S QUADRATIC EASING: t^2 ///////////////////

// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be in frames or seconds/milliseconds
Math.easeInQuad = function(t, b, c, d) {
  return c*(t/=d)*t + b;
};

// quadratic easing out - decelerating to zero velocity
Math.easeOutQuad = function(t, b, c, d) {
  return -c *(t/=d)*(t-2) + b;
};

// quadratic easing in/out - acceleration until halfway, then deceleration
Math.easeInOutQuad = function(t, b, c, d) {
  if ((t/=d/2) < 1) return c/2*t*t + b;
  return -c/2 * ((--t)*(t-2) - 1) + b;
};
/*
function loadGMap(map_el, lat, lon) {
  var container = $(map_el)
    
    if (container && GBrowserIsCompatible()) {
        var map = new GMap2(container);
        var center = new GLatLng(lat, lon);
        map.setCenter(center, 22);
    map.setZoom(13);
        var icon = new GIcon();
        icon.image = "/images/gmap_marker.png";
        icon.shadow = "/images/gmap_marker_shadow.png";
        icon.iconSize = new GSize(33, 51);
        icon.shadowSize = new GSize(47, 51);
        icon.iconAnchor = new GPoint(16,47);
        //icon.infoWindowAnchor();
        var marker = new GMarker(center, icon);
        map.addOverlay(marker);
    map.addControl(new GSmallMapControl())
    }
}*/

function toggleSmsCheckboxes() {
    // written by Daniel P 3/21/07
    // modified by Jason Frankovitz 5/25/07
    var inputlist = document.getElementsByTagName("input");
    var regex = new RegExp(/sms/);
    for (i = 0; i < inputlist.length; i++) {
	if ( inputlist[i].getAttribute("type") == 'checkbox' && regex.test(inputlist[i].getAttribute("name"))) {// look only at input elements that are checkboxes with "sms" in the name
	    if (inputlist[i].checked)inputlist[i].checked = false
					 else
inputlist[i].checked = true;
	}
    }
}

function toggleEmailCheckboxes() {
    // written by Daniel P 3/21/07
    // modified by Jason Frankovitz 5/25/07
    var inputlist = document.getElementsByTagName("input");
    var regex = new RegExp(/email/);
    for (i = 0; i < inputlist.length; i++) {
	if ( inputlist[i].getAttribute("type") == 'checkbox' && regex.test(inputlist[i].getAttribute("name"))) {// look only at input elements that are checkboxes with "sms" in the name
	    if (inputlist[i].checked)inputlist[i].checked = false
					 else
inputlist[i].checked = true;
	}
    }
}

function loadPage(pageName) {
   if (pageName != '') {
      document.location=pageName;
   }
}

function checkAll(formObj,check) {

   for (var i=0;i < formObj.length;i++) 
   {
      fldObj = formObj.elements[i];

      if (fldObj.type == 'checkbox' && fldObj.name != 'checkall')
      { 
            fldObj.checked = check;
       }
   }
}

//
//   VIDEO FUNCTIONS
//

var playerWidths = new Array();
playerWidths['mini'] = 320;
playerWidths['standard'] = 434;
playerWidths['wide'] = 640;
playerWidths['hd'] = 640;

var playerHeights = new Array();
playerHeights['mini'] = 268;
playerHeights['standard'] = 357;
playerHeights['wide'] = 508;
playerHeights['hd'] = 388;

playlist_config_list = function(video_urls, splash_image, autoplay, player_config) {

	video_urls_a = video_urls.split("|");
	//document.write(video_urls_a[0]);
	//document.write("<br>");
	//document.write(video_urls_a[1]);
	//document.write("<br>");
	//document.write(video_urls_a.length);
  if(autoplay) {
    //player_config.config_list.playList = [
    //  { url: video_urls_a[0] }, { overlayId: 'play' } ]
  } else {
    player_config.config.playList.push({ url: splash_image, overlayId: 'play' });
      //{ url: video_urls_a[0] }, { overlayId: 'play' } ]
  }
  player_config.config.playList.push( { url: video_urls_a[0] } );
  for (var i=1; i < video_urls_a.length; i++) {
  	player_config.config.playList.push( { url: video_urls_a[i], autoPlay: true } );
  }
  return player_config
}

// Create single-mode video object

show_video_list = function(mp4_url, flv_url, splash_image, player_dom_id, autoplay, size) {

  var player_config_list = { 
    config: {
      autoPlay: autoplay,
      autoRewind: true,
      usePlayOverlay: true,
      showStopButton: true,
      autoBuffering: false,
      showPlayListButtons: true,
      loop: false,
      initialScale: 'fit',
      menuItems: [ 1, 1, 1, 1, 1, 0, 0 ],
      playList: []
      }
    }
    
  player_config_list = playlist_config_list(mp4_url, splash_image, autoplay, player_config_list);
  
  flashembed(player_dom_id,
    {
      src: '/flash/flowplayer/FlowPlayerLight.swf',
      width: playerWidths[size],
      height: playerHeights[size],
      version: [9,115],
      onFail: function(flashVersion, flowplayerConfig) {
        this.version = null;
        this.onFail = null;
        flowplayerConfig = playlist_config_list(flv_url, splash_image, autoplay, flowplayerConfig);
        flashembed(player_dom_id, this, flowplayerConfig);
      }
    },
    player_config_list
  );
}

// Create single-mode video object

playlist_config_single = function(video_url, splash_image, autoplay, player_config) {
  if(autoplay) {
    player_config.config.playList = [
      { url: video_url }, { overlayId: 'play' } ]
  } else {
    player_config.config.playList = [
      { url: splash_image, overlayId: 'play' },
      { url: video_url }, { overlayId: 'play' } ]
  }
  return player_config
}

show_video_single = function(mp4_url, flv_url, splash_image, player_dom_id, autoplay, size) {

  var player_config_single = { 
    config: {
      autoPlay: autoplay,
      autoRewind: false,
      usePlayOverlay: true,
      showStopButton: true,
      autoBuffering: false,
      loop: false,
      initialScale: 'fit',
      menuItems: [ 1, 1, 1, 1, 1, 0, 0 ]
      }
    }
    
  player_config_single = playlist_config_single(mp4_url, splash_image, autoplay, player_config_single);
  
  flashembed(player_dom_id,
    {
      src: '/flash/flowplayer/FlowPlayerLight.swf',
      width: playerWidths[size],
      height: playerHeights[size],
      version: [9,115],
      onFail: function(flashVersion, flowplayerConfig) {
        this.version = null;
        this.onFail = null;
        flowplayerConfig = playlist_config_single(flv_url, splash_image, autoplay, flowplayerConfig);
        flashembed(player_dom_id, this, flowplayerConfig);
      }
    },
    player_config_single
  );
}



// ==== LEGACY FUNCTIONS ====


playlist_config = function(video_url, splash_image, autoplay, player_config) {
  if(autoplay) {
    player_config.config.playList = [
      { url: video_url }, { overlayId: 'play' } ]
  } else {
    player_config.config.playList = [
      { url: splash_image, overlayId: 'play' },
      { url: video_url }, { overlayId: 'play' } ]
  }
  return player_config
}

// Create video object
show_video = function(mp4_url, flv_url, splash_image, player_dom_id, autoplay) {
  var player_config = { 
    config: {
      autoPlay: autoplay,
      autoRewind: false,
      usePlayOverlay: true,
      showStopButton: true,
      autoBuffering: false,
      loop: false,
      initialScale: 'fit',
      menuItems: [ 1, 1, 1, 1, 1, 0, 0 ]
      }
    }
    
  player_config = playlist_config(mp4_url, splash_image, autoplay, player_config);
  
  flashembed(player_dom_id,
    {
      src: '/flash/flowplayer/FlowPlayerLight.swf',
      width: 433,
      height: 357,
      version: [9,115],
      onFail: function(flashVersion, flowplayerConfig) {
        this.version = null;
        this.onFail = null;
        flowplayerConfig = playlist_config(flv_url, splash_image, autoplay, flowplayerConfig);
        flashembed(player_dom_id, this, flowplayerConfig);
      }
    },
    player_config
  );
}

// Create wide-mode video object
show_video_wide = function(mp4_url, flv_url, splash_image, player_dom_id, autoplay) {
  var player_config_wide = { 
    config: {
      autoPlay: autoplay,
      autoRewind: false,
      usePlayOverlay: true,
      showStopButton: true,
      autoBuffering: false,
      loop: false,
      initialScale: 'fit',
      menuItems: [ 1, 1, 1, 1, 1, 0, 0 ]
      }
    }
    
  player_config_wide = playlist_config(mp4_url, splash_image, autoplay, player_config_wide);
  
  flashembed(player_dom_id,
    {
      src: '/flash/flowplayer/FlowPlayerLight.swf',
      width: 640,
      height: 508,
      version: [9,115],
      onFail: function(flashVersion, flowplayerConfig) {
        this.version = null;
        this.onFail = null;
        flowplayerConfig = playlist_config(flv_url, splash_image, autoplay, flowplayerConfig);
        flashembed(player_dom_id, this, flowplayerConfig);
      }
    },
    player_config_wide
  );
}

// Create mini-mode video object
show_video_mini = function(mp4_url, flv_url, splash_image, player_dom_id, autoplay) {
  var player_config_wide = { 
    config: {
      autoPlay: autoplay,
      autoRewind: false,
      usePlayOverlay: true,
      showStopButton: true,
      autoBuffering: false,
      loop: false,
      initialScale: 'fit',
      menuItems: [ 1, 1, 1, 1, 1, 0, 0 ]
      }
    }
    
  player_config_wide = playlist_config(mp4_url, splash_image, autoplay, player_config_wide);
  
  flashembed(player_dom_id,
    {
      src: '/flash/flowplayer/FlowPlayerLight.swf',
      width: 320,
      height: 268,
      version: [9,115],
      onFail: function(flashVersion, flowplayerConfig) {
        this.version = null;
        this.onFail = null;
        flowplayerConfig = playlist_config(flv_url, splash_image, autoplay, flowplayerConfig);
        flashembed(player_dom_id, this, flowplayerConfig);
      }
    },
    player_config_wide
  );
}

/*
  END VIDEO FUNCTIONS
*/