function show(layername) {
  var layer = layername;
  document.getElementById(layer).style.display = "";
}
    
function hide(layername) {
  var layer = layername;
  document.getElementById(layer).style.display = "none";
}

function arrow_on(img) {
  document.getElementById(img).src = "http://www.goquiz.com/images/bullets/navigation_white.gif";
}

function arrow_off(img) {
  document.getElementById(img).src = "http://www.goquiz.com/images/bullets/navigation.gif";
}

String.prototype.trim = function () {
  return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function confirm_reset() {
  var check = confirm("Are you sure you want to reset this form?");

  if (check) {
    return true;
  } else {
    return false;
  }
}

function confirm_delete() {
  var check = confirm("Are you sure you want to delete this quiz?");

  if (check) {
    return true;
  } else {
    return false;
  }
}

function checkanswer(answerform, answercount) {
  var temp;

  for (var i = 0; i < answercount; i++) {
    temp = answerform.user_answer[i];
      if (temp.checked == true) {
        return true;
      }
  }

  alert("Sorry, indecisive person. You have to select an answer.");
  return false;
}

function check_multiple_answers(answerform, answercount) {
  var count = 0;

  for (var i = 0; i < answerform.elements.length; i++) {
    if (answerform.elements[i].checked == true) {
      count++;
    }
  }

  if (count == answercount) {
    return true;
  } else {
    alert("You must select an answer for each question.");
    return false;
  }
}

function checkrating(ratingform) {
  var temp;

  for (var i = 0; i < 5; i++) {
    temp = ratingform.quiz_rating[i];
      if (temp.checked == true) {
        return true;
      }
    }

  alert("You must select a rating.");
  return false;
}

function verify_form(quizform) {
  var quiztitle   = quizform.quiztitle.value.trim();
  var description = quizform.description.value.trim();

  if (!quiztitle) {
    alert('Please enter a quiz title.');
    return false;
  }
  
  if (quiztitle.length > 50) {
    alert('Sorry, quiz titles cannot be longer than 50 characters.\n\nYou\'re currently using ' + quiztitle.length + ' characters.');
    return false;
  }

  if (description.length > 300) {
    alert('Sorry, descriptions cannot be longer than 300 characters.\n\nYou\'re currently using ' + description.length + ' characters.');
    return false;
  }

  var category = quizform.catid.selectedIndex;

  if (category < 1) {
    alert('Please select a quiz category.');
    return false;
  }
}

function check_avatar() {
  if (document.forms['registerform'].avatarid.value == 0) {
    alert('Please select an avatar.');
    return false;
  } else {
    return true;
  }
}

function more_avatars() {
  hide("firstlinks");
  hide("firstavatars");
  show("morelinks");
  // Effect.Appear("moreavatars"); 
  $('#moreavatars').fadeIn('slow');
}

function first_avatars() {
  hide("morelinks");
  hide("moreavatars");
  show("firstlinks");
  // Effect.Appear("firstavatars")
  $('#firstavatars').fadeIn('slow');
}

function copy_to_clipboard(field) {
  var val = eval("document." + field)
  val.select()
    
  if (document.all) {
    range = val.createTextRange();
    range.execCommand("Copy");
    alert('Code successfully copied. Press Ctrl + V to paste.');
  }
}

function goto(url) {
  window.location = 'http://www.goquiz.com' + url;
}

function popup_window(url, name, width, height) {
  window.open(url, name, 'width = ' + width + ', height = ' + height + ', menubar = no, status = no, scrollbars = no, toolbar = no, location = no, resizable = no, top = 60, left = 60');
}

function cursor_on(obj) {
  obj.style.cursor = 'pointer';

}

function cursor_off(obj) {
  obj.style.cursor = 'default';
}

function box_on(box) {
  document.getElementById(box).className = 'box_title';
}

function box_off(box) {
  document.getElementById(box).className = 'box_title_gray';
}

function formfield_on(field, id) {
  if (field.type == 'textarea') {
    field.className = 'textbox_on';
  } else {
    field.style.border = '1px solid #FC5F00';
    document.getElementById(id).style.backgroundColor = '#FFFFFF';
  }
}

function formfield_off(field, id) {
  if (field.type == 'textarea') {
    field.className = 'textbox';
  } else {
    field.style.border = '1px solid #666666';
    document.getElementById(id).style.backgroundColor = '#F1F1F1';
  }
}

function rating_on(num) {
  for (i = 1; i <= num; i++) {
    document.getElementById('rating_' + i).src = '/images/ratings/rating_on.gif';
  }
}

function rating_off(num) {
  for (i = 1; i <= num; i++) {
    document.getElementById('rating_' + i).src = '/images/ratings/rating_off.gif';
  }
}

function rating_set(num) {
  document.getElementById('ratingimg').src = '/images/ratings/rating_' + num + '.gif';

  setrating.style.display = "";
  ratings.style.display   = "none";
}

function cat_on(catrow, catname) {
  catrow.bgColor='#FFFFFF';
  document.getElementById(catname).src = '/images/categories/' + catname + '_gray.gif'; 
  document.getElementById(catname + '_link').style.color = '#FC5F00';
  catrow.style.cursor = 'pointer';
}

function cat_off(catrow, catname) {
  catrow.bgColor = '#E9E9E9';
  document.getElementById(catname).src='/images/categories/' + catname + '_gray-off.gif'; 
  document.getElementById(catname + '_link').style.color = '#555555';
  catrow.style.cursor = 'default';
}

function label_on(txt) {
  if (txt == 'pub') {
    document.getElementById('pub').className  = 'label_on';
    document.getElementById('priv').className  = 'label';

    show('pub_check');
    hide('priv_check');
    document.forms['quizform'].private.value = 0;
  } else {
    document.getElementById('pub').className  = 'label';
    document.getElementById('priv').className  = 'label_on';

    show('priv_check');
    hide('pub_check');
    document.forms['quizform'].private.value = 1;
  }
}

function qlabel_on(txt) {
  if (txt == 'one') {
    document.getElementById('one').className  = 'qlabel_on';
    document.getElementById('multi').className  = 'qlabel';

    show('one_check');
    hide('multi_check');
    document.forms['quizform'].multiple.value = 0;
  } else {
    document.getElementById('one').className  = 'qlabel';
    document.getElementById('multi').className  = 'qlabel_on';

    show('multi_check');
    hide('one_check');
    document.forms['quizform'].multiple.value = 1;
  }
}

function switch_frame(type, quiztype) {
  if (type == 'link') {
    hide("link_off");
    show("link_on");
      
    hide("upload_on");
    show("upload_off");

    document.getElementById('uploadframe').src      = '/upload_link.html?type=' + quiztype;
    document.getElementById('linkcell').className   = 'cell_on';
    document.getElementById('uploadcell').className = 'cell_off';
  } else {
    hide("upload_off");
    show("upload_on");
      
    hide("link_on");
    show("link_off");

    document.getElementById('uploadframe').src      = '/upload.html?type=' + quiztype;
    document.getElementById('uploadcell').className = 'cell_on';
    document.getElementById('linkcell').className   = 'cell_off';
  }
}