﻿var HTML_WAIT = '<div style=\'width:100%;height:100;text-align:center;\'><img src=\'/assets/images/ajax-loader.gif\' style=\'margin-top:100px;\'></div>'
var HTML_STATUS_BOX='<div class=\'statusBx\' id=\'bvisible\'></div>'
var HTML_EMAIL_BOX='<div class=\'statusBx\' id=\'bEmail\'></div>'
var HTML_NI_BOX='<div class=\'cancelBx\' id=\'bCancel\'></div>'
var HTML_ARCHIVE_BOX='<div class=\'archiveBx\' id=\'bArchive\'></div>'
var HTML_STAFFING_S_BOX='<div class=\'staffingbx\' id=\'bStaffing\'></div>'
var speed="fast"

$(document).ready(function() {
    $('#bucket').html(HTML_STATUS_BOX + HTML_EMAIL_BOX + HTML_EMAIL_BOX + HTML_NI_BOX + HTML_ARCHIVE_BOX + HTML_HIDDEN_CTLS + HTML_STAFFING_S_BOX)
 
 $(".chkAll").click(
    function (){
        if (this.checked){
            $(".chkMsg").each(
                function (i){
                    if (!this.checked){
                       this.checked=true;
                       msgCheck(this);
                    }
                }
             );
        }else{
             $(".chkMsg").each(
                function (i){
                    if (this.checked){
                       this.checked=false;
                       msgCheck(this);
                    }
                }
             );
        
        }
    
    }
 );
 
 function msgCheck(cbx){
    if (cbx.checked){
                checkToMsg +=1   
                $(".td" + this.value).css("background-color","#E6E8FA")
            }else{
                checkToMsg -=1
                $(".td" + this.value).css("background-color","")
            }
            if (checkToMsg==0){
             $(".msg").text("");
             $("#dbulkMsg").hide();
             $("#dnotes").show();
            }else{
                $("#dnotes").hide();
                $("#dbulkMsg").show();
                $(".msg").text("Message (" + checkToMsg + ")");
            }
 }
 

        $(".chkMsg").click(function(){
            msgCheck(this)
        });
 
});
  var checkToMsg =0



var HTML_HIDDEN_CTLS=""
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidLegacyStatusChange\' id=\'hidLegacyStatusChange\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidDoSend\' id=\'hidDoSend\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidstatusid\' id=\'hidstatusid\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidjsid\' id=\'hidjsid\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidbulkjsids\' id=\'hidbulkjsids\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidjbid\' id=\'hidjbid\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidtestduedate\' id=\'hidtestduedate\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidtestid\' id=\'hidtestid\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinterviewType\'  id=\'hidinterviewType\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinverviewNumber\' id=\'hidinverviewNumber\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinverviewHour\' id=\'hidinverviewHour\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinterviewMinute\' id=\'hidinterviewMinute\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinterviewAmpm\' id=\'hidinterviewAmpm\' />'
HTML_HIDDEN_CTLS+='<input type=\'hidden\' name=\'hidinverviewDate\' id=\'hidinverviewDate\' />'

function checkEmail(e)
	{
		var returnVal;
		var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
	
		returnVal = regex.test(document.getElementById(e).value);

		return returnVal;
	}
//Status functions

 var currjobid=0;
 var currJSID=0;
 var isOpenStatusOpen=false;
 var lastStatus;
 var lastBoxOpened=""
 function openStatusOptions(jbid,jsid,source,nocache){
  
    if (isOpenStatusOpen && lastSource==source){
         return hideAndClearAll();
    }   
    lastBoxOpened="status"
    hideAndClearAll();
    
    suppressJtip=true;
    
    currjobid=jbid;
    currJSID=jsid;
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)+100
    
    var x2
    x2= getAbsoluteLeft(source)-440
    
    $('#bvisible').html(HTML_WAIT);
    $('#bvisible').css({left: x+"px", top: y+"px",width: "0px",height:"0px"});
    
    //$('#bvisible').slideToggle(speed);
    //$('#bvisible').animate({ width: "show" }, speed).animate({ left:"100px" },speed);
    //$('#bvisible').animate({ width: "hide" }, speed); 
    
    $("#bvisible").animate({ 
        left: x2,
        width: "525px",
        height: "375px"
      }, 500 );

    
    //$('#bvisible').show('fast');
  
    
    $('#bvisible').load('/employer/tips/jsstatus.aspx?jbid=' + jbid +'&jsid=' + jsid + '&rnd=' + nocache)
    $('#hidjsid').val(jsid)
    $('#hidjbid').val(jbid)
    
  
    isOpenStatusOpen=true;
    lastSource=source;
    
    return false;
 }
 
 var isOpenArchive=false;
 function openArchive(jbid,jsid,source,nocache){
    if (isOpenArchive && lastSource==source){
         return hideAndClearAll();
    }   
    lastBoxOpened="archived"
  
    
    currjobid=jbid;
    currJSID=jsid;
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)+100
    var x2
    x2= getAbsoluteLeft(source)-405
   
    
    hideAndClearAll();
    
    suppressJtip=true;
    
    $('#bArchive').html(HTML_WAIT)
    //$('#bCancel').css({left: x+"px", top: y+"px"});
     $('#bArchive').css({left: x+"px", top: y+"px",width: "0px",height:"0px"});
  
     $("#bArchive").animate({ 
        left: x2,
        width: "500px",
        height: "100px"
      }, 500 );
    //$('#bCancel').show('fast');
    //$('#bCancel').slideToggle("slow");
    
    $('#bArchive').load('/employer/tips/jsclear.aspx?jbid=' + jbid +'&jsid=' + jsid + '&rnd=' + nocache)
    $('#hidjsid').val(jsid)
    $('#hidjbid').val(jbid)
    
     //also set the email location just in case we need it
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)-544
    $('#bvisible').css({left: x+"px", top: y+"px"});
    
    isOpenNotInterested=true;
    lastSource=source;
    
    return false;
 }
 
 var isOpenNotInterested=false;
 function openNotInterested(jbid,jsid,source,nocache,isBulk){
   
    
     if (isOpenNotInterested && lastSource==source){
         return hideAndClearAll();
    }  
  
      lastBoxOpened="ni"
      
    currjobid=jbid;
    currJSID=jsid;
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)+100
    var x2
    x2= getAbsoluteLeft(source)-280
   
    
    hideAndClearAll();
    
    suppressJtip=true;
    
    $('#bCancel').html(HTML_WAIT)
    //$('#bCancel').css({left: x+"px", top: y+"px"});
     $('#bCancel').css({left: x+"px", top: y+"px",width: "0px",height:"0px"});
    
     $("#bCancel").animate({ 
        left: x2,
        width: "375px",
        height: "150px"
      }, 500 );
    //$('#bCancel').show('fast');
    //$('#bCancel').slideToggle("slow");
    
    $('#bCancel').load('/employer/tips/jsNotInterested.aspx?jbid=' + jbid +'&jsid=' + jsid + '&rnd=' + nocache + '&isBulk=' + isBulk)
    $('#hidjsid').val(jsid)
    $('#hidjbid').val(jbid)
    
     //also set the email location just in case we need it
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)-544
    $('#bvisible').css({left: x+"px", top: y+"px"});
    
    isOpenNotInterested=true;
    lastSource=source;
    
    return false;
 }
 
 
 //-----------\
 //SS methods
 //------------
 var isOpenSS=false;
 function openStaffingSources(jbid,source,nocache){
    if (isOpenSS && lastSource==source){
         return hideAndClearAll();
    }   
    lastBoxOpened="ss"
     
    currjobid=jbid;
  
    var y,x
    y=getAbsoluteTop(source) + 15; //set y position
    x= getAbsoluteLeft(source)
    var x2
    x2= getAbsoluteLeft(source)
    hideAndClearAll();
    
    $('#bStaffing').html(HTML_WAIT)
    //$('#bCancel').css({left: x+"px", top: y+"px"});
     $('#bStaffing').css({left: x+"px", top: y+"px",width: "0px",height:"0px"});
  
     $("#bStaffing").animate({ 
       // left: x2,
        width: "600px",
        height: "300px"
      }, 500 );
    //$('#bCancel').show('fast');
    //$('#bCancel').slideToggle("slow");
    
    $('#bStaffing').load('/employer/tips/staffing.aspx?jbid=' + jbid +'&rnd=' + nocache)
    
     //also set the email location just in case we need it
    var y,x
    y=getAbsoluteTop(source) + 15; //set y position
    x= getAbsoluteLeft(source)
    $('#bvisible').css({left: x+"px", top: y+"px"});
    
    isOpenSS=true;
    lastSource=source;
    
    return false;
 }
 function chkActivate(isChecked,ssid,agencyName,jbid){
     
     
     if (isChecked){
        if (confirm("You have selected to allow " + agencyName + " to submit candidates through the ATS for this position. \n To send an e-mail alert to " + agencyName + ", click 'OK'. Click 'Cancel' if you do not wish to send an e-mail alert?")){
            showStaffingEmail(ssid,jbid,isChecked)
        }
        
     }else{
        if (confirm("You have deselected " + agencyName + " as a staffing source for this position.  They will no longer be allowed to submit candidates through the ATS for this position.  Do you wish to send an e-mail alerting them of this?")){
            showStaffingEmail(ssid,jbid,isChecked)
        }
     }
     //ajax call updats ss
     ActivateDeactivateSS(jbid,ssid,isChecked)
 }
 //-----------\
 // end SS methods
 //------------ 
 
 
 
 function hideAndClearAll(){
    
    
    $('#JT').remove()
    
    $('#bvisible').hide()
    $('#bvisible').html('')
    
    $('#bEmail').hide()
    $('#bEmail').html('')
     
    $('#bCancel').hide()
     $('#bCancel').html('')
     $('#bulkMedia').hide()
     $('#bStaffing').hide()
     $('#bStaffing').html('')
     isOpenStatusOpen=false;
     isOpenNotInterested=false;
     isOpenSS=false;
     
     //blind call out .. event like
     try {
        hideClearSubPage()
     } catch (e){}
     
 }
 function closeStatusOptions(){
   suppressJtip=false;
    $('#bvisible').hide()
    $('#bvisible').html('')
 }
 function closeNIOptions(){
   
   suppressJtip=false;
      $('#bCancel').hide()
     $('#bCancel').html('')
     
 }
 function closeArchiveOptions(){
   
        suppressJtip=false;
      $('#bArchive').hide()
     $('#bArchive').html('')
     
 }
 
 function saveNIOptions(isBulk){
   var doArchive
    if ($('#NIarchive').get(0).checked){
        $('#hidstatusid').val(8) //clear value
        doArchive=true
    }
    else{
        $('#hidstatusid').val(13) //pass value
        doArchive=false
    }
    
    //8 clare value
    if (document.getElementById('rdoNIActionEmail').checked){
        previewEmail=true;
    }else{
        previewEmail=false;
    }
    //push values into the normal 'options' logic flow to handle showing
    //email popup, etc
    if (isBulk!=1){
        return saveStatusChange();
    }else{
        doBulk(previewEmail,doArchive)
    }
 }
 
 

 
 function saveArchiveOptions(){

        previewEmail=false;
	    $('#hidstatusid').val(8);
	  
    //push values into the normal 'options' logic flow to handle showing
    //email popup, etc
    return saveStatusChange();
 }
 
 function sendShareProfileEmail(jsid,jbid,source,mid){
    var y,x
    currjobid=jbid
    currJSID=jsid
    if (mid==null){
        mid=0;
    }
    
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)-544
    $('#bvisible').css({left: x+"px", top: y+"px"});
     
    $('#bvisible').html(HTML_WAIT)
   
    //$('#bvisible').show('fast');
    $('#bvisible').slideToggle(speed);
    $('#bvisible').load('/employer/tips/jsstatusemail.aspx?share=1&jbid=' + jbid +'&jsid=' + jsid + '&ajaxEmail=1&mid='+mid);
    
    
 }
 
 function sendAjaxEmail(){
   
    var hasAddress=false;
     var ret
    var emailToStr
    
    $(".chkEmail").each(
        function (i){
            if (this.checked){
                emailToStr+=this.value + ';';
                hasAddress=true;
            }
        }
    );
    
     if (!checkEmail('FromEmail')){
        alert('Please check the from and to email addresses to ensure they are valid email addresses.')
        return false;
    }

    
    if (!hasAddress){
        if (document.getElementById('emailto').value.indexOf("@")==-1){
            alert('Please check the from and to email addresses to ensure they are valid email addresses.')
            return false;
        }
    }
    
//    alert($('#privateURL').val())
//    alert($('#publicURL').val())
    
    //send emails to teh users who can log in, users added through checkboxes
    if (hasAddress){
    ret = CHAjax.EmployerActions.SendEmailbyAjax(emailToStr,$('#FromEmail').val(),$('#Subject').val(),$('#Message').val()+"\n\r" + $('#privateURL').val(),false,scb)
    }
    emailToStr=''
    emailToStr = $('#emailto').val() +';'
    //send slightly different email to those who can't. those who can't go to a public url
    if (document.getElementById('emailto').value.indexOf("@")!=-1){
        ret= CHAjax.EmployerActions.SendEmailbyAjax(emailToStr,$('#FromEmail').val(),$('#Subject').val(),$('#Message').val()+"\n\r" + $('#publicURL').val(),false,scb)
    }
    
    
     hideAndClearAll();
     
 }
 function closeAjaxEmail(){
     hideAndClearAll();
 }
 function scb(result, eventArgs)
{
    
  }
 
 
 
 function showStaffingEmail(ssid,jbid,bActivate){
    hideAndClearAll();
    $('#bvisible').html(HTML_WAIT)
    $('#bvisible').slideToggle(speed);
    
    if (bActivate){
        $('#bvisible').load('/employer/tips/jsstatusemail.aspx?ajaxemail=1&activatess=1&jbid=' + jbid + '&ssid=' + ssid);
    }else{
        $('#bvisible').load('/employer/tips/jsstatusemail.aspx?ajaxemail=1&deactivatess=1&jbid=' + jbid + '&ssid=' + ssid);
    }
 }
 
  
 function showBulkMessageEmail(jbid,jsid,source,nocache){
 //
    var hasChecked

   
    var jslist=''
    hideAndClearAll()
    lastBoxOpened="msg"
    suppressJtip=true;
    
    if (jsid==0){
     jQuery.each($('.chkMsg'),function(){
         if (this.checked){
          hasChecked=true;
          jslist += this.value + ','
         }
        })
         $('#hidbulkjsids').val(jslist)
        $('#jsid').val('')
    }
    else{
        if (checkToMsg>1){
            alert('To send a message to multiple jobseekers, use the \'Send Message (' + checkToMsg + ')\' button above.')
            return false;
        }
        $('#hidjsid').val(jsid)
    }
    $('#hidjbid').val(jbid)
    
    var y,x
    y=getAbsoluteTop(source) + 19; //set y position
    x= getAbsoluteLeft(source)+100
    
    var x2
    x2= getAbsoluteLeft(source)-440
    
    $('#bvisible').html(HTML_WAIT);
    $('#bvisible').css({left: x+"px", top: y+"px",width: "0px",height:"0px"});
    
 $('#bvisible').show();
 
    $("#bvisible").animate({ 
        left: x2,
        width: "525px",
        height: "375px"
      }, 500 );
  $('#bvisible').html(HTML_WAIT)
 

    
    if (jsid==0){
        $('#bvisible').load('/employer/tips/jsstatusemail.aspx?noRefresh=1&JobSeekerIDs=' + jslist + '&jbid=' + jbid);
    }else{
         $('#bvisible').load('/employer/tips/jsstatusemail.aspx?noRefresh=1&jsid=' + jsid + '&jbid=' + jbid);
    }
      
  
 }
 
 function showStatusemail(statusid){
 
 var y,x
    
    hideAndClearAll();
   
    
  
    $('#bvisible').html(HTML_WAIT)
   
    //$('#bvisible').show('fast');
    $('#bvisible').slideToggle(speed);
    var additionalP =''
    if ($("#hidtestid").val()!= null && $("#hidtestid").val()!=''){
        additionalP = '&testid=' + $("#hidtestid").val()
    }
    $('#bvisible').load('/employer/tips/jsstatusemail.aspx?jbid=' + currjobid +'&jsid=' + currJSID + '&statusid=' + statusid + additionalP);
    

 }
 
 
 function showBulkStatusemail(jbid,jsids,statusid){
 
 var y,x
    
    hideAndClearAll();
   
    
  
    $('#bvisible').html(HTML_WAIT)
   
    //$('#bvisible').show('fast');
    $('#bvisible').slideToggle(speed);
    
    $('#bvisible').load('/employer/tips/jsstatusemail.aspx?jbid=' + currjobid +'&JobSeekerIDs=' + jsids + '&statusid=' + statusid);
    
 
 }
 
 var previewEmail =false;

	
 function showHideSections(id,emailSelected)
	{
	
	//previewEmail=emailSelected;
	$('#hidstatusid').val(id);
		switch (id)
		{
			case 15: //testing
				getE('testing').style.display = '';
				getE('interviewing').style.display = 'none';
				break;
			case 3: //interviewing
				getE('testing').style.display = 'none';
				getE('interviewing').style.display = '';
				break;
			case 13: //emploeyr passes
				getE('testing').style.display = 'none';
				getE('interviewing').style.display = 'none';
				break;			
			default:
			try{
				getE('testing').style.display = 'none';
				getE('interviewing').style.display = 'none';
				}catch(e){}
		}
	}
	
	
	
    function saveStatusChange(){
    
        
        
        if ($('#hidstatusid').val()==''){
            alert('Please select a new status or click \'Close\' to cancel.');
            return false;
        }
     
        
        $('#hidLegacyStatusChange').val('1');
        switch (parseInt($('#hidstatusid').val()))
		{
			case 15: //testing
			 
			    
			    
				$('#hidtestduedate').val($('#TestDueDate').val());
				
				try{
				$('#hidtestid').val($('#TestID').get(0).options[$('#TestID').get(0).selectedIndex].value);
				}catch (e){}
				break;
			case 3: //interviewing
			    if (getE('InterviewTypeLive').checked ){
			        $('#hidinterviewType').val(1);
			    }else if (getE('InterviewTypeUnsched').checked)
			    {
			        $('#hidinterviewType').val(0);
			    }
			    else
			    {
			        $('#hidinterviewType').val(2);
			    }
				
				$('#hidinverviewNumber').val($('#InterviewCount').get(0).options[$('#InterviewCount').get(0).selectedIndex].value);
				$('#hidinverviewHour').val($('#InterviewHour').get(0).options[$('#InterviewHour').get(0).selectedIndex].value);
				$('#hidinterviewMinute').val($('#InterviewMinute').get(0).options[$('#InterviewMinute').get(0).selectedIndex].value);
				$('#hidinterviewAmpm').val($('#InterviewAMPM').get(0).options[$('#InterviewAMPM').get(0).selectedIndex].value);
				$('#hidinverviewDate').val($('#InterviewDate').get(0).value);
				break;
		}
		
		//13=not intersted. if not that status, then we look at the statuses
		//checkbox to determine if we send preview or not
		
		if ( ( lastBoxOpened!='ni') && $('#hidstatusid').val()!=8 ){
		    previewEmail=$('#chkPreview' + $('#hidstatusid').val()).get(0).checked;
		}
		
		if (previewEmail) {
		    showStatusemail($('#hidstatusid').val());
		}else{

		   
		    document.location='/employer/xt_EmployerActivity.aspx?jsforjob=1&Action=' + $('#hidstatusid').val() + '&JobID=' + $('#hidjbid').val() + '&JobSeekerID=' +  $('#hidjsid').val() + getAdditionalParams()
		}
		
    }
    
    function getAdditionalParams(){
        if (fltrType==null){
            fltrType="";
        }
        var retstr='';
        switch (parseInt($('#hidstatusid').val()))
		    {
			    case 15: //testing
				    retstr += '&TestDueDate=' + $('#hidtestduedate').val();
				    retstr += '&TestID=' + $('#hidtestid').val();
				    break;
			    case 3: //interviewing
			        retstr += '&InterviewType=' + $('#hidinterviewType').val();
    				retstr += '&InterviewCount=' +  $('#hidinverviewNumber').val();
    				retstr += '&InterviewHour=' +  $('#hidinverviewHour').val();
    				retstr += '&InterviewMinute=' +  $('#hidinterviewMinute').val();
    				retstr += '&InterviewAMPM=' +  $('#hidinterviewAmpm').val();
    				retstr += '&InterviewDate=' +  $('#hidinverviewDate').val();
				    break;
		    }
		    
		    retstr += '&currentpage=' + $('#hidCurrentPage').val();
		    retstr += '&pagesize=' + $('#hidPageSize').val();
		    
		    return retstr + '&rdoFilterType=' + fltrType
    }
    
    function sendNoTest(fcn){
        if (confirm('Your test will not be sent! Are you sure you want to cancel?')){
            fcn();
        }
        return false;
    }
    
    function sendEmail(dosend){
        
        //$('#bvisible').html(HTML_WAIT)
        $('#hidDoSend').val(dosend);
        $('#hidLegacyStatusChange').get(0).form.submit();
    }
    
    
    function checkSend(ctl){
        setSendStatus(ctl.value,ctl.checked);
        
        if (ctl.checked){
            $('#divPreview' + ctl.value).slideToggle(speed);
             $('#divEdit' + ctl.value).slideToggle(speed);
            
            //$('#divPreview' + ctl.value).css({display: "inline"});
        }else{
            $('#chkPreview' + ctl.value).get(0).checked=false;
            $('#divPreview' + ctl.value).slideToggle(speed);
             $('#divEdit' + ctl.value).slideToggle(speed);
            //$('#divPreview' + ctl.value).css({display: "none"});
            //$('#divPreview' + ctl.value).slideToggle("slow");
        }
        
    }
    
    function doJsClear(){
	    
	}
    
    
    function setDisplayStatus(statusID,value){
        $.post("/employer/_ws/emailOptions.aspx",{updateType: "display", statusID: statusID, value: value });
    }
     function setSendStatus(statusID,value){
        $.post("/employer/_ws/emailOptions.aspx",{updateType: "send", statusID: statusID, value: value });
    }

    function setPreviewStatus(statusID,value){
        $.post("/employer/_ws/emailOptions.aspx",{updateType: "preview", statusID: statusID, value: value });
    }    
	// end Status functions