function thankYouAndRedirect(msg, url)
{
    alert(msg);
    window.location = url;
}

function clickOnce(ctl)
{
    setTimeout(function() { if (Page_IsValid) { ctl.disabled = true; } }, 10);
}

/* resume wizard */
function wizardHelp(sectionName)
{
    var iFrame = showIFrameWindow();
    iFrame.src = "WizardHelp.aspx?section=" + sectionName;
}

function setSectionText(sectionName, val)
{
    var allControls = document.getElementsByTagName('textarea');
    for(var i = 0; i < allControls.length; i++)
    {
        var ctlSectionName = allControls[i].getAttribute('SectionName');
        if (ctlSectionName != null && ctlSectionName == sectionName)
        {
            allControls[i].value = val;
        }
    }
}

/* resume editor */

function setEditableAreaListeners()
{
    var allDivs = document.getElementsByTagName('div');
    var foundFirst = false;
    for(var i = 0; i < allDivs.length; i++)
    {
      if (allDivs[i].getAttribute('editableArea') != null)
	  {
        
	    if (!foundFirst)
	    {
	        // we'll also set the "first" editable area to be selected
	        allDivs[i].className = "selectedEditableArea";
	        foundFirst = true;
	    }
	  
		var allLis = allDivs[i].getElementsByTagName('ul');
		for(var j = 0; j < allLis.length; j++)
		{
			allLis[j].onmouseover = liBug_mouseover;
			allLis[j].onmouseout = liBug_mouseout;
		}
	    
	    allDivs[i].onclick = toggleSelectedArea;
		allDivs[i].onmouseover = mouseoverSelectedArea;
		allDivs[i].onmouseout = mouseoutSelectedArea;
	  }
    }    
}

function liBug_mouseover(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;


	if (targ.getAttribute('editableArea') == null)
	{
		// this is a stupid ie6 bug.
		targ = targ.parentNode;

		while (targ != null && targ .getAttribute('editableArea') == null)
			targ = targ.parentNode;		

		if (targ  == null)
			return;
	}

	if (targ.className == 'editableArea')
		targ.className = 'editableArea_hover';
}

function liBug_mouseout(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;


	if (targ.getAttribute('editableArea') == null)
	{
		// this is a stupid ie6 bug.
		targ = targ.parentNode;

		while (targ != null && targ .getAttribute('editableArea') == null)
			targ = targ.parentNode;		

		if (targ  == null)
			return;
	}

	if (targ.className == 'editableArea_hover')
		targ.className = 'editableArea';
}

function mouseoverSelectedArea(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	if (targ.className == 'editableArea')
		targ.className = 'editableArea_hover';
}

function mouseoutSelectedArea(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	if (targ.className == 'editableArea_hover')
		targ.className = 'editableArea';
}

function toggleSelectedArea(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	if (targ.getAttribute('editableArea') == null)
	{
		// this is a stupid ie6 bug.
		targ = targ.parentNode;

		while (targ != null && targ .getAttribute('editableArea') == null)
			targ = targ.parentNode;		

		if (targ  == null)
			return;
	}

        var allDivs = document.getElementsByTagName('div');
        for(var i = 0; i < allDivs.length; i++)
        {
            if (allDivs[i].className == 'selectedEditableArea')
                allDivs[i].className = 'editableArea';
        }
        
        targ.className = 'selectedEditableArea';
}

function addSection(ResumeId, sectionTitleDropDown)
{
    var dropDown = document.getElementById(sectionTitleDropDown);
    if (dropDown.selectedIndex == 0)
        alert('Please select a section to add.');
    else
    {
        var SectionTitle = dropDown.options[dropDown.selectedIndex].value;
        var iFrame = showIFrameWindow();
        iFrame.src = "EditSection.aspx?ResumeId=" + ResumeId + "&SectionTitle=" + SectionTitle;
    }
}

/* functions for the resume editor */
function editSection(resumeSectionId)
{
    var iFrame = showIFrameWindow();
    
    iFrame.src = "EditSection.aspx?ResumeSectionId=" + resumeSectionId;
}

function showIFrameWindow()
{
    var iFrameContainer = document.getElementById('sectionEdit_iframecontainer');
    var iFrame = document.getElementById('sectionEdit_iframe');
    var divBlackout = document.getElementById('sectionEdit_blackout');
    
    if (iFrameContainer == null)
    {
        iFrameContainer = document.createElement("div");
        iFrameContainer.id = "sectionEdit_iframecontainer";
        iFrameContainer.className = "sectionEdit_iframecontainer";
        iFrameContainer.style.display = "none";
        document.body.appendChild(iFrameContainer);
    
        iFrame = document.createElement("iframe");
        iFrame.id = "sectionEdit_iframe";
        iFrame.className = "sectionEdit_iframe";
        iFrame.frameBorder = 0;
        iFrameContainer.appendChild(iFrame);
        
        divBlackout = document.createElement("div");
        divBlackout.id = "sectionEdit_blackout";
        divBlackout.className = "sectionEdit_blackout";
        divBlackout.style.display = "none";
        divBlackout.style.height = document.body.offsetHeight + "px";
        document.body.appendChild(divBlackout);
    }
    divBlackout.style.display = "block";
    iFrameContainer.style.display = "block";
    scroll(0,0);
    
    return iFrame;
}

function deleteSection(sectionTitle, resumeSectionId)
{
    if (confirm("Are you sure you want to delete '" + sectionTitle + "'?"))
        window.location.href = "EditSection.aspx?action=delete&ResumeSectionId=" + resumeSectionId;
}

function moveUpSection(resumeSectionId)
{
    window.location.href = "EditSection.aspx?action=moveUp&ResumeSectionId=" + resumeSectionId;
}

function moveDownSection(resumeSectionId)
{
    window.location.href = "EditSection.aspx?action=moveDown&ResumeSectionId=" + resumeSectionId;
}

function hideEditWindow()
{
    var iFrameContainer = document.getElementById('sectionEdit_iframecontainer');
    var divBlackout = document.getElementById('sectionEdit_blackout');
    
    if (iFrameContainer != null)
        iFrameContainer.style.display = "none";
        
    if (divBlackout != null)
        divBlackout.style.display = "none";
}
/* end */
