// Wintertree Spelling Server
// SubmissionScript.js:
// Client-side script used to submit a form to the server for
// spell-checking using Wintertree Spelling Server.
// Copyright (c) 2002 Wintertree Software Inc.
// www.wintertree-software.com
// $Id: SubmissionScript.js,v 1.7 2003/07/08 17:48:06 wsi Exp wsi $

var spellCheckWin = null;

function onCheckSpellingBtnBottom(formNum)
{
prepareSpellcheck(formNum, false); 
}

function onCheckSpellingBtn(formNum)
{
    prepareSpellcheck(formNum, true);   
}

var borderWidth = 7.5;
var borderHeight = 7.0;

function getFormIndexByName(formName)
{
    for (var i=0;i<document.forms.length; i++)
    {
        if (document.forms[i].name==formName)
        {
            return i;
            break;
        }
    }
    return -1;
}
function onCheckSpellingBtnByName(formName)
{
   var formIndex = getFormIndexByName(formName);

   if (formIndex>=0)
   {
        document.forms[formIndex].WSSFormNum.value = formIndex;
        prepareSpellcheck(formIndex, true);   
   }
}

function prepareSpellcheck(formNum, onTheTop) {
    if (spellCheckWin != null && !spellCheckWin.closed) {
        // The spell-check form is active. Bring it to the front.
        spellCheckWin.focus();
        return;
    }

    // Retrieve the option settings and user dictionary from a cookie.
    var options = 0;
    var cookies = document.cookie;
    var pos = cookies.indexOf("spellcheck=");
    var s;
    if (pos >= 0) {
        var start = pos + 11;
        var end = cookies.indexOf(";", start);
        if (end < 0) {
            end = cookies.length;
        }
        var scCookie = unescape(cookies.substring(start, end));
        end = scCookie.indexOf(":");
        if (end < 0) {
            end = scCookie.length;
        }
        s = scCookie.substring(0, end);
        options = s - 0;
        if (options != 0) {
            document.forms[formNum].WSSOptions.value = options;
        }
        if (end != scCookie.length) {
            start = end + 1;
            s = scCookie.substring(start, scCookie.length);
            document.forms[formNum].WSSUserDictionary.value = s;
        }
    }

                // close previous spellchecking popup
                elem = document.getElementById('checkpopUp');
        	    if (elem != null)
        	    {
        	        elem.parentNode.removeChild(elem);
        	    }

               var divTag = document.createElement("div");

				divTag.id  = "checkpopUp";
				if (onTheTop)
				{
				    divTag.style.left = "50px";
				    divTag.style.top = "100px";
				}
				else
				{
				    
				    divTag.style.left = "50px";
				    divTag.style.top = document.body.scrollTop+50;
				}
				
				if (Prototype.Browser.IE) borderWidth = 9;
				
				var sw = parseInt(screen.width * 420/1024);
				var sh = parseInt((200 * screen.height / 768));
				if (screen.height>768) sh=sh+ (90 * (screen.height - 768) / 768);
				else sh=sh+ (20 * (screen.height) / 768);
				var swf = sw + 50;
				var shf = sh + 65;

				divTag.style.width =  swf + 'px'; // was 32x62
				divTag.style.height = shf + 'px';
				divTag.className ="checkpopUp";
				divTag.style.visibility = "hidden";
				divTag.style.zIndex = "100";

				divTag.innerHTML = "<table width='" + swf + "px' height='"+ shf+ "px' style='border-collapse: collapse;background: #002B51' ><td valign='top' ><table style='border-collapse: collapse;background: #003564' ><td valign='top' ><table style='border-collapse: collapse;background: #00427E' ><td valign='top' ><table style='border-collapse: collapse;background: #00529B' ><td valign='top' ><table style='border-collapse: collapse;background: #005CAE' ><td valign='top' ><table style='border-collapse: collapse;background: #0061B7' ><td valign='top' ><table style='border-collapse: collapse;background: #0063BD' ><td valign='top' ><table style='border-collapse: collapse;background-image: url(BlueBlackStripeVertical.gif);' cellpadding='10' width='"+ (parseInt(swf) - 2*parseInt(borderWidth))+ "px' heigth='"+ (parseInt(shf) - 2*parseInt(borderHeight)) + "px'><td valign='top' ><div id='checkHandle'>Spell checking</div><iframe scrolling='no' name='frame1' id='frame1' width='"+ sw + "px' height='" + sh +"px' frameborder='0' allowtransparency='true' style='border:none;background-color:Transparent'></iframe></td></table></td></table></td></table></td></table></td></table></td></table></td></table></td></table><!--[if lte IE 6.5]><iframe id='checkpopUpiframe'></iframe><![endif]-->";
	
			
		        document.body.appendChild(divTag);

                new Draggable('checkpopUp',{ghosting:false, revert:false, handle:'checkHandle'});
				
				var originalAction = document.forms[formNum].action;
				var originalTarget = document.forms[formNum].target;
				
				//breakhere
				document.forms[formNum].action = "spellcheck_2.asp";
                document.forms[formNum].target = "frame1";
                document.forms[formNum].submit();
                
                
                document.forms[formNum].action = originalAction;
                document.forms[formNum].target = originalTarget;
                
//    }
}

// TODO Appraisal Atomization
function onSubmitBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
     new Ajax.Request('AppraisalRedirect.asp',
     {
		method:'post',
		parameters: $(document.forms[formNum].id).serialize(true),

		onFailure: function(t){ 
		alert('Something went wrong...'+ t.status + ' -- ' + t.statusText); }
     });
}

function onSubmitJBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "JobAdvertRedirect.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitSBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "SuggestionsRedirect.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitABtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "AddNewActivityRedirectRegistration.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitCBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "AddNewClientRedirectRegistration.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitDBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "AddNewDivisionRedirectRegistration.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitPBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "AddNewPFactorRedirectRegistration.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitAIBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "AInterviewRedirect.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitMBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "MentorSessionRedirect.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}

function onSubmitMeBtn(formNum) {
    // When the Submit button is pressed, submit the form to default.asp
    document.forms[formNum].action = "MentoreeSessionRedirect.asp";
    document.forms[formNum].target = "_self";
    document.forms[formNum].submit();
}