﻿﻿$(document).ready(function() {
    $('.ptypes').change(function() {        
         if($('.ptypes:checked').val().toLowerCase()=="attend the lectures")
             {
                 $('.divLect').show();
                 $('.field.download').hide();
                 $('.divPoster').hide();
                 $('.showOnPoster').hide();
                 $('.field.upload').hide();
             }
         else if($('.ptypes:checked').val().toLowerCase()=="present a poster")
             {
                  $('.divLect').hide();
                  $('.field.download').show();
                  $('.divPoster').show();
                  $('.showOnPoster').show();
                  $('.field.upload').show();
             } 
    });
    
//    $('.sendEmailFunction').click( function() { window.open("/AdminRounds/SendEmail", "width=400; height=500; toolbar=no; menubar=no"); return false; });
        $('.sendEmailFunction').click( function() {
            $('#sendEmailID').show();  
        });
        $('.closeEmail').click( function() {
            $('#sendEmailID').hide();  
        });
  try{  
    if($('.ptypes:checked').val().toLowerCase()=="attend the lectures")
        {
         $('.divLect').show();
         $('.field.download').hide();
         $('.divPoster').hide();
          $('.showOnPoster').hide();
         $('.field.upload').hide();
        }
        
     
     if($('.:checked').val().toLowerCase()=="present a poster")
        {
         $('.divLect').hide();
         $('.field.download').show();
          $('.divPoster').show();
          $('.showOnPoster').show();
          $('.field.upload').show();
        }
        
      if($('#ddLPtypes option:selected').text().toLowerCase()=="attend the lectures and present a poster")
      {
         $('.divLect').hide();
         $('.divPoster').show();
         $('.showOnPoster').show();
      }
      }catch(e){}
        
    $('#ddPresenter').change(function(){
        if($('#ddPresenter  option:selected').text().toLowerCase()=="the contact person for the poster")
           {
             $('.divPrePoster').show();
             $('.divPresenter').hide();
           }
           else
           {
           $('.divPresenter').show();
            $('.divPrePoster').hide();
           }
    });
    
    if($('#ddPresenter  option:selected').text().toLowerCase()=="the contact person for the poster")
       {
         $('.divPrePoster').show();
         $('.divPresenter').hide();
       }
    if($('#ddPresenter  option:selected').text().toLowerCase()=="the presenter")
       {
         $('.divPrePoster').hide();
         $('.divPresenter').show();
       }
    
       /*$('input[submit].btn').click(function(){
            if('#Name').val() == 'asd'){
            alert('hi');
            }
       });
       $('input[type=text].btn').click(function(){
            if($('form[action=/TellaFriend/Step2] #Name').val()==""){
                alert('hi');
            }
       });*/
       
       $('#Neuro_file_upload').uploadify({
                                    'uploader' : '/Scripts/uploadify/uploadify.swf',
                                    'script' : '/AdminRounds/Upload',
                                    'cancelImg' : '/Scripts/uploadify/cancel.png',
                                    'folder' : '/Content/Neuroscience',
                                    'onComplete' : function(event, ID, fileObj, response, data){
                                                 $('#FilePath').val(response);
                                                 triggerSave();
                                    },
                                    'onError' : function(event,Id,fileObj,errorObj){
                                                        if (errorObj.status == 404)
                                                          alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
                                                        else if (errorObj.type === "HTTP")
                                                           alert('error '+errorObj.type+": "+errorObj.status);
                                                        else if (errorObj.type ==="File Size")
                                                           alert(c.name+' '+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB');
                                                        else
                                                           alert('error '+errorObj.type+": "+errorObj.text);
                                                  }
                                        });
                                     
                                     
                                     
       $('#btnSaveDay').click(function(model){
           $('#Neuro_file_upload').uploadifyUpload();
       });   
       
       
       $('#LOI_file_upload').uploadify({
                                    'uploader' : '/Scripts/uploadify/uploadify.swf',
                                    'script' : '/AdminRounds/Upload',
                                    'cancelImg' : '/Scripts/uploadify/cancel.png',
                                    'folder' : '/Content/GrandRounds',
                                    'onComplete' : function(event, ID, fileObj, response, data){                                  
                                                 $('#LOIFilePath').val(response);
                                                 triggerGrant();
                                    },
                                    'onError' : function(event,Id,fileObj,errorObj){
                                                        if (errorObj.status == 404)
                                                          alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
                                                        else if (errorObj.type === "HTTP")
                                                           alert('error '+errorObj.type+": "+errorObj.status);
                                                        else if (errorObj.type ==="File Size")
                                                           alert(c.name+' '+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB');
                                                        else
                                                           alert('error '+errorObj.type+": "+errorObj.text);
                                                  }
                                        });
                                        
            $('#Grant_file_upload').uploadify({
                                    'uploader' : '/Scripts/uploadify/uploadify.swf',
                                    'script' : '/AdminRounds/Upload',
                                    'cancelImg' : '/Scripts/uploadify/cancel.png',
                                    'folder' : '/Content/GrantRounds',
                                    'onComplete' : function(event, ID, fileObj, response, data){                                  
                                                 $('#GrantFilePath').val(response);
                                                 triggerSave();
                                    },
                                    'onError' : function(event,Id,fileObj,errorObj){
                                                        if (errorObj.status == 404)
                                                          alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
                                                        else if (errorObj.type === "HTTP")
                                                           alert('error '+errorObj.type+": "+errorObj.status);
                                                        else if (errorObj.type ==="File Size")
                                                           alert(c.name+' '+errorObj.type+' Limit: '+Math.round(errorObj.sizeLimit/1024)+'KB');
                                                        else
                                                           alert('error '+errorObj.type+": "+errorObj.text);
                                                  }
                                        });
                                     
                                     
                                     
       $('#btnSaveGrant').click(function(model){
           $('#LOI_file_upload').uploadifyUpload();
       });                                   
       
});

function triggerNeuroDay(){
if($('#Neuro_file_uploadQueue').html() == "" ||$('#Neuro_file_uploadQueue').html() == null){
triggerSave();
}else{
$('#Neuro_file_upload').uploadifyUpload();
}
}

function triggerLOI(){
if($('#LOI_file_uploadQueue').html() == "" ||$('#LOI_file_uploadQueue').html() == null){
triggerGrant();
}else{
$('#LOI_file_upload').uploadifyUpload();
}
}

function triggerGrant(){
if($('#Grant_file_uploadQueue').html() == "" ||$('#Grant_file_uploadQueue').html() == null){
triggerSave();
}else{
$('#Grant_file_upload').uploadifyUpload();
}
}

function triggerSave(){
$('#btnSave').click();
}

function showWarning(email,o){
$('.popupWarning .type',$(o).parent()).html($(o).html());
$('.popupWarning .email',$(o).parent()).html(email);
$('.popupWarning',$(o).parent()).css({
    top:($(window).height()-$('.popupWarning',$(o).parent()).height())/2 + "px",
    left:($(window).width()-$('.popupWarning',$(o).parent()).width())/2 + "px",
    position:'fixed'
});
$('.popupWarning',$(o).parent()).slideDown();
}

function ADDFiles()
{
 var hdn= $('.hdnFileNO').val();
 hdn++;
 $('.hdnFileNO').val(hdn);
 $('.addUploadFiles').append(" <span class=\"field\"><input type=\"file\" id=\"File"+hdn+"\" name=\SourceFile"+hdn+"\" /></span><br/>");
 //increase the hidden value

}


