﻿// Begin "Set Field Default"
// The section below allows you to set the default value for a field, either input or select
// use the following syntax: setLookupFromFieldName("PaperSubject", "Test");


function setLookupFromFieldName(fieldName, value) {
  if (value == undefined) return;

  var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
// if theSelect is null, it means that the target list has more than
// 20 items, and the Lookup is being rendered with an input element

  if (theSelect == null) {
    var theInput = getTagFromIdentifierAndTitle("select","",fieldName);
    //ShowDropdown(theInput.id); //this function is provided by SharePoint
    var opt=document.getElementById(theInput.id);

    setSelectedOption(opt, value);
    OptLoseFocus(opt); //this function is provided by SharePoint
  } else {
    setSelectedOption(theSelect, value);

  }
}

function setSelectedOption(select, value) {
  var opts = select.options;

  var l = opts.length;
  if (select == null) return;

  for (var i=0; i < l; i++) {
    if (opts[i].value == value) {
      select.selectedIndex = i;
      return true;
    }
  }

  return false;

}

function getTagFromIdentifierAndTitle(tagName, identifier, title) {
  var len = identifier.length;
  var tags = document.getElementsByTagName(tagName);

  for (var i=0; i < tags.length; i++) {
    var tempString = tags[i].id;

    if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) {
      return tags[i];
    }
  }
  return null;
}

// End "Set Field Default"

// popup function for login 
    function login(showhide){
    //alert('a');
    if(showhide == "show"){
        //alert('b');
        document.getElementById('popupbox').style.visibility="visible"; /* If the function is called with the variable 'show', show the login box */
        //alert('b1');
    }else if(showhide == "hide"){
        //alert('c');
        document.getElementById('popupbox').style.visibility="hidden"; /* If the function is called with the variable 'hide', hide the login box */
        //alert('c1');
    }
    //alert('d');
  }

