    nbcu.util.common.loadClass("Nbcu.Sn.Form");
    nbcu.util.common.loadClass("Nbcu.Sn.Account");
    nbcu.util.common.loadClass("Nbcu.Template");
    
    //nbcu.sn.form.populateForm("main_form");
    
    template = new Nbcu.Template("Sn.Account.Default");
    template.assign("legend", "Log in to enter.");
    template.assign("callback", "displayForm('main_form');");
  
    jqN(function(){
     jqN('#loginMyNBC').click(function(){
                  jqN("#ugcHolder").html();
                  if(nbcu.sn.session.isLoggedIn())
                  {
                   displayUploadForm('IMAGE','')
                  }
                  else
                  {
                  displayForm('sn_login_form');
                  }
                  });  
     jqN('#loginFacebook').click(function(){
                loginTick("displayUploadForm('IMAGE','')");
                  });


});

  function loginTick(callback) {
      nbcuAccountInterval = setInterval('if (nbcu.sn.session.isLoggedInToExternalPlatform("facebook") && !nbcu.config.getParam("isStopTick")) { nbcu.config.setParam("isStopTick", true); eval("' + callback + '"); }' , 5000);
  }

  function displayForm(dataPanel){
   
   var formData = 'form[name='+dataPanel+']';
  
   jqN('#ugcHolder').slideUp(function (){
             jqN('#ugcHolder').html(jqN(formData));
             jqN('#ugcHolder').slideDown();
             if(nbcu.sn.session.isLoggedIn())
             {
               if(nbcu.sn.session.isLoggedInToExternalPlatform("facebook"))
               {
                //jqN("#snf_firstName").val('');
                //jqN("#snf_lastName").val('');
               }
               
               displayUploadForm('IMAGE','')
             }
             }); 
 
  }
   
  function displayUploadForm(mediaType,uuid)
  {
    jqN('#ugcHolder').slideUp(function (){
               template = new Nbcu.Template("Sn.Upload.Default");
               template.assign("communityName", "1001words");
               template.assign("redirectUrl", 'http://'+document.domain+'/thank-you/');
               template.assign("termsCheckbox", 'By checking this box, I agree to the terms and conditions of the Release Agreement  <a href="http://my.nbc.com/terms">Materials and Appearance Release.</a>');
               template.assign("contentType", mediaType.toUpperCase());
               template.assign("privacyLevelCode", "PRIVATE");
               template.assign("titleLabel", mediaType +" Title");
               template.assign("descriptionLabel", mediaType + " Description");
               template.assign("isLabelsStacked",true);

               nbcu.config.setParam("snasSiteName", "nbc.com");
               nbcu.config.setParam("snasSiteDomainName", "my.nbc.com")
               var formData = "<div id=''><h4>You may now  <span>upload your photo</span></h4></div>";
               formData += template.fetch("videoUploadForm");
               
               jqN('#ugcHolder').html(formData);
               if(uuid !=''){
               jqN('input[name=personUUID]').val(uuid); 
               jqN('input[name=tagXML]').val(generateTagXML(uuid)); 
               }
               jqN('input[name=btn_submit]').click(function(){
               
                validate('sn_upload_form');
                });
               jqN('#ugcHolder').slideDown();
             });
    
  }
  
function validate(thisForm)
  {
    var retVal = true;
    var msg = "";
    var isUpload = true;  
    if (jqN("#sn_title").val()=="")
    {
      msg += "Title is required.\n";
      retVal = false;
    }  
  
    if (jqN('input[name=contentDescription]').val()=="")
    {
      msg += "Description is required.\n";
      retVal = false;
    }
   
		if(jqN("#sn_uploadFile").val()=="")
		{
		  msg += "Missing file, nothing to upload.\n";
      retVal = false;
		}
    if (!jqN('input[name=terms]').attr('checked'))
    {
      msg += "You must agree to the Terms of Use.\n";
      retVal = false;
    }  
    if (retVal && ((jqN("#sn_uploadFile").val().length > 0) && (jqN("#sn_uploadFile").val()!="")))
    {  
      if ( jqN("#sn_title").val().length < 5 && jqN("#sn_uploadFile").val().length > 0 )
      {
        msg += template.getVar("titleLabel") + " must be at least 5 characters in length.\n";
        retVal = false;
      }
    
      if ( (jqN('input[name=contentDescription]').val()=="") && jqN("#sn_uploadFile").val().length > 0 )
      {
        msg += template.getVar("descriptionLabel") + " is required.\n";
        retVal = false;
      }  
    }
    
 if (template.getVar("contentType") == "IMAGE")
    {
      var extString = "gif,jpg,jpeg,png";
      var contentString = "image";
      var article = "a";
    }
  
    
    if ( jqN("#sn_uploadFile").val().length > 0 )
    {  
      if ( jqN("#sn_title").val().length < 5 && jqN("#sn_uploadFile").val().length > 0 )
      {
        msg += template.getVar("titleLabel") + " must be at least 5 characters in length.\n";
      }
    
      if ( (jqN('input[name=contentDescription]').val()=="") && jqN("#sn_uploadFile").val().length > 0 )
      {
        msg += template.getVar("descriptionLabel") + " is required.\n";
      }  
      
      extString = extString.toLowerCase();
      var validExt = extString.split(",");
      var ext = jqN("#sn_uploadFile").val();
      var li = ext.lastIndexOf(".");
    
      if (li != -1)
      {
        ext=ext.substring(li+1).toLowerCase();
        isValidFile = false;
        
        for (var i = 0; i < validExt.length; i++)
        {
          if (validExt[i].indexOf(ext) >= 0)
          {
            isValidFile = true;
            //break;
          }
        } 
        
        if (!isValidFile)
        {
          msg += "Please select a valid " + contentString + " file.\n";
           retVal = false;
        }
      }
      else
      {
        msg += "The " + contentString + " is not the right format.\n";
        retVal = false;
      }
    }
    else
    {
     retVal = false
    }
    
    
    if (!retVal)
    {
      alert(msg);
    }
    else
    {
  jqN('#ugcHolder').slideUp(function (){
             jqN('#ugcHolder').html('Thanks for your submission! Your upload may take a few minutes to complete depending on the size of your file.\nPlease do not leave this page until your upload is finished.');
             jqN('#ugcHolder').slideDown();
           });
    }
 	 
    return retVal;
  }

/*  function displayThanks(){
  jqN('#ugcHolder').slideUp(function (){
             jqN('#ugcHolder').html('Thanks for your submission! Your upload may take a few minutes to complete depending on the size of your file.\nPlease do not leave this page until your upload is finished.');
             jqN('#ugcHolder').slideDown();
           });
  }
*/
  function generateTagXML(uuid)
  {
    var tagXmlComplete='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><systemTag><person><personUUID>'+uuid+'</personUUID></person><tags><tag><classifier>siteId</classifier><tagText>'+showId+'</tagText><type>SYSTEM</type></tag></tags></systemTag>';
  return tagXmlComplete;
  }
