var redirectURL = "";

function setThankYouHeader(radio_choice)
{
    var td = document.getElementById('thankyou_default');
    var sp = document.getElementById('subheader_default');
    
    if(radio_choice==1)
    {
        //haven't found a job
        var tn = document.getElementById('thankyou_notfoundjob');
        td.style.display = 'none';
        tn.style.display = '';
        
        var th = document.getElementById('help_notfoundjob');
        th.style.display = '';
        
        setupHelp();
    }
    
    if(radio_choice==2)
    {
        //Resume not updated
        var tn = document.getElementById('thankyou_resnotupdated');
        td.style.display = 'none';
        tn.style.display = '';
        
        var th = document.getElementById('help_resnotupdated');
        th.style.display = '';
 
        setupHelp();
    }
    
    if(radio_choice==4)
    {
        //Not sure how to apply
        var tn = document.getElementById('thankyou_notsureapply');
        td.style.display = 'none';
        tn.style.display = '';
        
        var th = document.getElementById('help_notsureapply');
        th.style.display = '';
        
        setupHelp();
    }
    
   
    
}


function setupHelp()
{
        var jr = document.getElementById('recommendedjobsad');
        jr.style.display = 'none';

        var help = document.getElementById('subheader_default');
        help.style.display = 'none';
        
        var hl = document.getElementById('helplinks');
        hl.style.display = '';
        
        var help = document.getElementById('subheader_help');
        help.style.display = '';

        var help = document.getElementById('helpsystem');
        help.style.display = '';
        
        var email = document.getElementById('hasemail');
        email.style.display = 'none';
        
        //if(email.style.display != 'none')
        //{
           var email2 = document.getElementById('hasemail2');
           email2.style.display = ''; 
        //}
        
        
        var email = document.getElementById('newemail');
        email.style.display = 'none';
        
        var email = document.getElementById('emailrequest');
        email.style.display = 'none';
}


function submitSurvey()
{
	//var frm = document.getElementById ('__aspnetForm');
	
	var forceSurvey = document.getElementById('_ctl0__ctl0_forceSurvey').value;

	// set var radio_choice to false
	var radio_choice = 0;
	
	var radObj = document.getElementsByName('_ctl0:_ctl0:radSurvey');
	
	// Loop from zero to the one minus the number of radio button selections
	for (counter = 0; counter < radObj.length; counter++)
	{
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (radObj[counter].checked)
		{
			radio_choice = radObj[counter].value; 
			break;//exit loop
		}
	}

	if (radio_choice == 0)
	{
		// If there were no selections made display an alert box 
		alert("Please select one answer.")
		return;
	}
	
	if(radio_choice == 7)
	{
		if(document.getElementById('txtOther').value == "")
		{
			alert("Please enter the Other Reason");
			return;
		}
	}
	
	var responseNo = radio_choice;
	var otherreason = document.getElementById('txtOther').value;
	var surveyid = 2;
	
	setThankYouHeader(radio_choice);
	
	//ajax call
	var data = 'SurveyID=' + surveyid + '&' +
				'TextBlob=' + otherreason + '&' +
				'Response=' + responseNo;
				
    if(forceSurvey == '1')
    {
        data += '&survey=true';
    }				
				   
	submitCallback(data, 'JobRecommendationsSurvey.aspx', handleSurveyResponse);
}

// handles the return signal from the AJAX page
function handleSurveyResponse(success, responseText)
{
	if(success)
	{
		//if(responseText.substr(0,7) == "FAILURE")
		//{
			//we couldn't submit the survey response from user
			//document.getElementById('ticker').innerHTML = "Do something!!!!";
			//return;
		//}
		
		//we managed to submit the survey response - show 2nd part of panel.
		//DO SOMETHING
		
		
		
		var firstsurvey = document.getElementById("bartext")
		firstsurvey.style.display = "none";
		
		var moresurvey = document.getElementById("surveymore")
		moresurvey.style.display = "block";
		
		
		
		
	}
	else
	{
		// something went wrong with the AJAX callback
		//DO SOMETHING
	}
}

function surveyNoThanks()
{
	//ajax call
	var data = 'nothanks=1';   
	submitCallback(data, 'JobRecommendationsSurvey.aspx', handleSurveyNoThanks);
}

// handles the return signal from the AJAX page
function handleSurveyNoThanks(success, responseText)
{
	//if(success)
	//{
		//DO SOMETHING
	//}
	//else
	//{
		//DO SOMETHING
	//}
	
	//we need to redirect them
	history.go(0);
}

function submitSurveyEmail()
{
	//var frm = document.jrsurveyform;

	//check first to see if they typed in the same email addresses
	
	var emailbox = document.getElementById('txtEmail');
	var emailboxconfirm = document.getElementById('txtEmailConfirm');
	
	if(emailbox.value == "" || emailboxconfirm.value == "")
	{
		if(emailbox.value == "")
			alert("Please enter your email address");
		else if(emailboxconfirm.value == "")
			alert("Please confirm your email address");
				
		return;
	}
	
	if(emailbox.value != emailboxconfirm.value)
	{
		alert("Your email address and confirmed email address are not the same! Please try again.");
		return;
	}

	
	var ret;
	ret = IsEmail(emailbox.value, true, true, emailbox);

	if(ret != true) //email is NOT OK
	{
		return;
	}

	//if we got to here, we are done with all client validations... now we fire to AJAX
	
	var emailaddr = emailbox.value;
	
	//ajax call
	var data = 'email=' + emailaddr;   
	submitCallback(data, 'JobRecommendationsSurvey.aspx', handleSurveyEmail);
}

// handles the return signal from the AJAX page
function handleSurveyEmail(success, responseText)
{
	//if(success)
	//{
		//DO SOMETHING
		var emailrequest = document.getElementById('emailrequest');
        emailrequest.style.display = 'none';
        
        var newemail = document.getElementById('newemail');
        newemail.style.display = 'block';
	//}
	//else
	//{
		//DO SOMETHING
	//}
}

function surveyClose()
{
	history.go(0);
}



/* SWEEPSTAKES*/
function postResumeSweepstakes()
{			   
	submitCallback('', 'PostaResumeSweepstakes.aspx', handleSweepstakesResponse);
}

// handles the return signal from the AJAX page
function handleSweepstakesResponse(success, responseText)
{

	if(success)
	{
		
		if(responseText.substr(0,7) == "FAILURE" || responseText.substr(0,7) == "INVALID")
		{
			//we couldn't submit the survey response from user
			//document.getElementById('ticker').innerHTML = "Do something!!!!";
			//return;
		}
		
		//we managed to submit the survey response - show 2nd part of panel.
		//DO SOMETHING
		
		location.href = redirectURL;
		
	}
	else
	{
		// something went wrong with the AJAX callback
		//DO SOMETHING
	}
}

function submitShowSweepstakes()
{
	//ajax call
	var data = 'show=1';   
	submitCallback(data, 'PostaResumeSweepstakes.aspx', handleShowSweepstakes);
}

// handles the return signal from the AJAX page
function handleShowSweepstakes(success, responseText)
{
	//if(success)
	//{
		//DO SOMETHING
	//}
	//else
	//{
		//DO SOMETHING
	//}
}



