$(document).ready(function() {

  $('#tab-panel').tabs();
    
  $('#search input').focus(function() { ($(this).attr('value') == 'Search') ? $(this).attr('value','') : $(this).attr('value'); });
  $('#search input').blur(function() { ($(this).attr('value') == '') ? $(this).attr('value','Search') : $(this).attr('value'); });
 
  $('#side-navigation a').prepend('&raquo; ');
  $('.take-action a').prepend('&raquo; ');
  
  $('a[href$=pdf]').addClass('pdf');
  $('a.arrow').append(' &raquo;');
  
  /* Gallery Javascript moved to the DLV */
  
 /*Needed for tree branch to move slides*/ 
  var slideCounter = 1;
        $('#slideshow2 DIV').each(function() {
         $(this).attr('id','s'+slideCounter);
         slideCounter++;
});  
  
  $('h1').each(function() { if ( $(this).text() == 'dir' ) { $(this).text($('h1#user-name').text()); $('title').text($('h1#user-name').text()+' | Pacific Oaks College'); } });
  
  $('#user-profile-search-results li img').each(function() {
    if ( $(this).attr('src') == '/' || '' ) $(this).attr('src','/files/2f1b986d-cd9f-43e5-ab64-9e4600b1abdd/silhouette.gif');
  });
  
  if ( $('.portrait').attr('src') == '/' || $('.portrait').attr('src') == '' ) {
    var portrait = '/files/2f1b986d-cd9f-43e5-ab64-9e4600b1abdd/silhouette.gif';
  } else { var portrait = $('.portrait').attr('src'); }  
  
  
  $('.portrait').after('<div class="image-overlay" style="background-image:url('+portrait+')"></div>').hide();

  var rightNow   = new Date().toLocaleString();
  var referrer   = document.referrer;
  var currentURL = location.href;
  var eventName  = $('.event-name').text();
 
  $('div#FormTextBox-PageURL > input').val(referrer).attr('readonly','readonly').addClass('disabled-textbox');
  $('div#FormTextBox-CurrentURL > input').val(currentURL).attr('readonly','readonly').addClass('disabled-textbox');
  $('div#FormTextBox-SubmitDateTime > input').val(rightNow).attr('readonly','readonly').addClass('disabled-textbox');
  $('div#FormTextBox-EventName > input').val(eventName).attr('readonly','readonly').addClass('disabled-textbox');
  
  $('.treectl_loc li ul li:nth-child(1)').remove();
  
  if(document.referrer.indexOf("Our_Programs/Online_Learning") != -1){
   /*  $("#online-tab").removeClass("ui-state-default ui-corner-top");
     $("#online-tab").addClass("ui-state-default ui-corner-top ui-tabs-selected ui-state-active");*/
    
  $("#onground-tab").removeClass("ui-state-default ui-corner-top ui-tabs-selected ui-state-active");
  $("#online-tab").removeClass("ui-state-default ui-corner-top");
  $("#onground-tab").addClass("ui-state-default ui-corner-top");
  $("#online-tab").addClass("ui-state-default ui-corner-top ui-tabs-selected ui-state-active");
  
    
  $("#onground").removeClass("ui-tabs-panel ui-widget-content ui-corner-bottom");
  $("#online").removeClass("ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide");   
  $("#online").addClass("ui-tabs-panel ui-widget-content ui-corner-bottom");
  $("#onground").addClass("ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide");       
    
    
 
    
    
  };
  
/*
$('.location-cleanup').each(function() {
  //cleans up location, where class="new-Location"  
var sitename = $('.location-cleanup').text(); 
  alert(sitename);
var loc2 = "<ul>";
var words=sitename.split(",") //split using blank comma as delimiter
for (i=0; i<words.length; i++){
  var loc = words[i].split(":");//split again to get single campus
  var loc2 = (loc2 + "<li>"+ loc[1] +"</li>");//gets the second element that was split
}
var loc2 = (loc2 + "</ul>");
$('.location-cleanup').html(loc2);
});
  */
  
 
//cleans up location, where class="new-Location"  
$('.location-cleanup').each(function() { 
  var sitename = $(this).get(); 
  //alert($(sitename).text());

  var loc2 = "<ul>";
  var words = $(sitename).text().split(",") //split using blank comma as delimiter
  //alert(words + " inside words");

  for (i=0; i<words.length; i++){
    var loc = words[i].split(":");//split again to get single campus
    //alert(loc[1]);
  if (loc[1] != null){
    var loc2 = (loc2 + "<li>"+ loc[1] +"</li>");//gets the second element that was split
  }
  }

  var loc2 = (loc2 + "</ul>");
  $(this).html(loc2);
  //alert(loc2);
})  
  
//make Payroll Deduction form labels standard width and height
$('.alumniUpdateForm fieldset label + div, .payrollDeductionForm fieldset label + div').css({'display': 'inline-block', 'height': '30px'});
//$('.payrollDeductionForm label:empty').css('display','none');
$('.alumniUpdateForm label.full, input[type=submit], .payrollDeductionForm label.full, input[type=submit]').css({'position':'relative','left':'230px'});

//clean up Payroll Deduction checkbox
$('.alumniUpdateForm input[type=checkbox], .payrollDeductionForm input[type=checkbox]').css({'margin':'0 5px 0 0','vertical-align':'bottom'});

//Email and Confirm email match check for PAYROLL DEDUCTION FORM
$('form[action*="Payroll_Deduction"]').submit(function(){
  var emailField = $('input[name*="rpControls$ctl02$fiControl"]');
  var emailConfirmField = $('input[name*="rpControls$ctl03$fiControl"]');
  
  if (($(emailField).val().length < 2) || $(emailConfirmField).val().length < 2){
    $(window).scrollTop(0);
    alert('I\'m sorry, there is an error. The Email address fields can not be left blank or does not match. Please make sure your Email and Confirm Email match.');
    $('label:contains("Email *")').addClass('errorMessage');
    return false;
    
  } else if (($(emailConfirmField).val()!=$(emailField).val())){
    $('label:contains("Email *")').addClass('errorMessage');
    $(window).scrollTop(0);
    alert('I\'m sorry, there is an error. Your email address does not match. Please make sure your Email and Confirm Email match.');
    return false;
  }else {
    $(window).scrollTop(0);
    return true;
  }
});


//remove number of week from calendar
$('.payrollDeductionForm table[id*=calendar_Top][id*=DatePicker] tr:not(:first-child) td:first-child, .DaysOfWeek_Default:first-child:empty').css('display','none');

//Email and Confirm email match check for REQUEST A TOUR FORM
$('form[action*="Request_a_Tour"]').submit(function(){
  var emailField = $('input[name*="rpControls$ctl02$fiControl"]');
  var emailConfirmField = $('input[name*="rpControls$ctl03$fiControl"]');
  
  if (($(emailField).val().length < 2) || $(emailConfirmField).val().length < 2){
    $(window).scrollTop(0);
    alert('I\'m sorry, there is an error. The Email address fields can not be left blank or does not match. Please make sure your Email Address and Verify Email Address match.');
    $('label:contains("Email *")').addClass('errorMessage');
    return false;
    
  } else if (($(emailConfirmField).val()!=$(emailField).val())){
    $('label:contains("Email *")').addClass('errorMessage');
    $(window).scrollTop(0);
    alert('I\'m sorry, there is an error. Your email address does not match. Please make sure your Email and Confirm Email match.');
    return false;
  }else {
    $(window).scrollTop(0);
    return true;
  }
});


//Date checks for REQUEST A TOUR FORM
$('form[action*="Request_a_Tour"]').submit(function(){
  var dateFirstChoice= $('select[name*="rpControls$ctl09$fiControl"]');
  var dateSecondChoice = $('select[name*="rpControls$ctl10$fiControl"]');
  
 if (($(dateSecondChoice ).val()==$(dateFirstChoice).val())){
    $('label:contains("Email *")').addClass('errorMessage');
    $(window).scrollTop(0);
    alert('You have selected the same dates for your first and second Date of Interest choices. Please make sure you select different dates.');
    return false;
  }else {
    $(window).scrollTop(0);
    return true;
  }
});




  $("a.bigiframe").fancybox({
    'transitionIn'  :  'elastic',
    'transitionOut'  :  'elastic',
    'speedIn'    :  600,
    'speedOut'    :  200,
      'width'      :  605,
      'height'    :  345,
    'type'       :  'iframe'
  });
  $("a.fancy").fancybox({
    'transitionIn'  :  'elastic',
    'transitionOut'  :  'elastic',
    'speedIn'    :  600,
    'speedOut'    :  200,
    'titlePosition'  : 'over'
  });


$('iframe [name="googleSearchFrame"]').css('height','900px');


});//end document.ready
