function clearDate(field_name)
{
    if (document.getElementById(field_name).value == 'MM-DD-YYYY') {
        document.getElementById(field_name).value = '';
    }
}


function changeInviteOwner(field)
{
    // If owner is 'me'
    if (field.value == '5') {
        // Reset group menu
        if (document.inviteform.group_id) {
            document.inviteform.group_id.value = '';
        }
        // Set subject
        document.inviteform.subject.value = 'Join my network on StoryLink!';
        // Set message
        document.inviteform.message.value = 'Hello,\n\nI\'m inviting you to join my network on StoryLink.\n\nStoryLink not only helps me stay current with the relationships that matter most to me, it also gives me access to new creative opportunities.';
    // If owner is 'group'
    } else if (field.value == '3') {
        // Set subject
        document.inviteform.subject.value = 'Join my group on StoryLink!';
        // Set message
        document.inviteform.message.value = 'Hello,\n\nI\'m inviting you to join my group on StoryLink.\n\nStoryLink not only helps me stay current with the relationships that matter most to me, it also gives me access to new creative opportunities.';
    }
}


function changeEventOwner(field)
{
    if (field.value == '5') {
        // Reset group menu
        if (document.eventform.group_id) {
            document.eventform.group_id.value = '';
        }
    }
}


function changeContestOwner(field)
{
    if (field.value == '5') {
        // Reset group menu
        if (document.contestform.group_id) {
            document.contestform.group_id.value = '';
        }
    }
}


function selectEventOwner(owner)
{
    if (owner == 'group') {
        document.eventform.entity_section_id[1].checked = true;
    }
}


function selectContestOwner(owner)
{
    if (owner == 'group') {
        document.contestform.entity_section_id[1].checked = true;
    }
}


function selectMessages() {
    master = document.messages.master;
    if (master.checked == true) {
        TheChk=document.messages["message[]"]
        for(i=0;i<TheChk.length;i++)
          TheChk[i].checked = true;
    } else {
        TheChk=document.messages["message[]"]
        for(i=0;i<TheChk.length;i++)
          TheChk[i].checked = false;
    }
}


function selectMessagesUndo() {
    document.messages["master"].checked = false;
}


function changeEventPrivacy(field)
{
    var store = new Array();
    // Discussion menu options for when privacy set to public and owner is self
    store[0] = new Array(
    	'','',
    	'Private','1',
    	'Personal contacts','2',
    	'Professional contacts','3',
    	'Personal & professional contacts','4',
    	'All contacts','5',
    	'Public can view and contacts can post','6',
    	'Public can view and post','7'
    );
    // Discussion menu options for when privacy set to public and owner is group
    store[1] = new Array(
    	'','',
    	'Group members','8',
    	'Public can view and members can post','6',
    	'Public can view and post','7'
    );
    // Discussion menu options for when privacy not set to public or private and owner is self
    store[3] = new Array(
    	'','',
    	'Private','1',
    	'Contacts who can view event','8'
    );
    // Discussion menu options for when privacy set to private and owner is self
    store[4] = new Array(
    	'Private','1'
    );
    // Discussion menu options for when privacy not set to public and owner is group
    store[5] = new Array(
    	'Group members','8'
    );
    // Clear discussions menu
    document.eventform.discussion.options.length = 0;
    if (field.value == '6' && document.eventform.entity_section_id.value == '5') {
        // Build discussions menu
    	for(i=0;i<store[0].length;i+=2)
    	{
    		document.eventform.discussion.options[i/2] = new Option(store[0][i],store[0][i+1]);
    	}
    } else if (field.value == '6' && document.eventform.entity_section_id.value == '3') {
        // Build discussions menu
    	for(i=0;i<store[1].length;i+=2)
    	{
    		document.eventform.discussion.options[i/2] = new Option(store[1][i],store[1][i+1]);
    	}
    } else if (field.value != '6' && field.value != '1' && document.eventform.entity_section_id.value == '5') {
        // Build discussions menu
    	for(i=0;i<store[3].length;i+=2)
    	{
    		document.eventform.discussion.options[i/2] = new Option(store[3][i],store[3][i+1]);
    	}
    } else if (field.value == '1' && document.eventform.entity_section_id.value == '5') {
        // Build discussions menu
    	for(i=0;i<store[4].length;i+=2)
    	{
    		document.eventform.discussion.options[i/2] = new Option(store[4][i],store[4][i+1]);
    	}
    } else if (field.value != '6' && document.eventform.entity_section_id.value == '3') {
        // Build discussions menu
    	for(i=0;i<store[5].length;i+=2)
    	{
    		document.eventform.discussion.options[i/2] = new Option(store[5][i],store[5][i+1]);
    	}
    }
}


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}


function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}


function displayServiceAccountName()
{
    var name = document.getElementById("taxpayer_name").value;
    document.getElementById("certification_name").innerHTML = name;
    document.getElementById("agreement_name").innerHTML = name;
}


// Set feedback rating and current rating width
function setFeedbackRating(rating)
{
    // Set feedback rating
    document.getElementById("feedback_rating").value = rating;
    // Set current rating width
    var currentRatingWidth = rating * 20;
    document.getElementById("current_rating_width").value = currentRatingWidth;
    document.getElementById("current_rating").style.width = currentRatingWidth + "%";
}


// Stolen from http://www.netlobo.com/div_hiding.html
function toggleLayer( whichLayer )
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'inline':'none';
  vis.display = (vis.display==''||vis.display=='inline')?'none':'inline';
}
