﻿/*
** File        : common.js
** Author      : PSK
** Date        : Aug-10-2009
** Description : Common Javascript functions for SPS
*/

/*                                                                        */ 
/* ----------------- Common - Global Variables : [BEGIN] ---------------- */
/*                                                                        */

var NODE_RESULT          = "sps-result";
var ATTR_SUCCESS         = "success";
var ATTR_ERROR           = "error";
var ATTR_PAGE            = "page";
var ATTR_ID              = "id";

var HOME_PAGE            = "Home.aspx";

/*
** User types.
*/
var USER_TYPE_CONSULTANT = 0;
var USER_TYPE_MANAGER    = 1;
var USER_TYPE_STUDENT    = 2;
var USER_TYPE_INSTRUCTOR = 3;
var USER_TYPE_ADMIN      = 4;
var USER_TYPE_PUBLISHER  = 5;

/*
** Analysis page no.
*/
var ORG_ANALYSIS         = 1;
var EA_PEST_ANALYSIS     = 2;
var EA_SGA_ANALYSIS      = 3;
var EA_ILC_ANALYSIS      = 4
var EA_PORT_ANALYSIS     = 5;
var IA_RA_ANALYSIS       = 6;
var IA_VC_ANALYSIS       = 7;
var SWOT_ANALYSIS        = 8;
var ORG_PURPOSE          = 9;
var PHASE2_CRPS          = 10;
var PHASE2_CMPS          = 11;
var PHASE2_DVPS          = 12;

/*                                                                        */ 
/* ----------------- Common - Global Variables : [END] ------------------ */
/*                                                                        */

var g_SelectedPage       = -1;
var g_ItemClicked        = -1;

function ToDo() 
{
    alert("TODO:// This feature is to be implemented");
}

function OnBodyLoad() 
{
    lastTab = document.getElementById("SPS_tabbtnHome");
}

function $(id)
{
    return document.getElementById(id);
}

function $d()
{
    return document;
}

function $b()
{
    return document.body;
}

function $w()
{
    return window;
}

function $de()
{
    return document.documentElement;
}

function isBrowserIE()
{
    return ("Microsoft Internet Explorer" == navigator.appName);
}

function MakeDOMObject(t,doc)
{
    if(!doc)
    {
        doc = $d();
    }
    return doc.createElement(t);
}

function AppendDOMObject(o,p)
{
    if(!p || p == 'undefined')
    {
        p = $b().appendChild(o);
    }
    else
    {
        p.appendChild(o);
    }
}

function AttrOnDOMObject(o,a,v)
{
    if(o && o.setAttribute)
    {
        o.setAttribute(a,v);
    }
}

function AttrOfDOMObject(o,a)
{
    if(o && o.getAttribute)
    {
        return o.getAttribute(a);
    }
    return null;
}

function RemoveDOMObject(o,p)
{
    if(o && (!p || p == 'undefined'))
    {
        p = o.parentNode;
    }

    if(p && o)
    {
        p.removeChild(o);
    }
}

function RemoveListContent(listObj)
{
    if( null != listObj)
    {
   		while(listObj.options.length > 0) 
		{
			RemoveDOMObject(listObj.options[0], listObj);
		}
    }
}

/*
** Event related
*/
function Event(e,c)
{
    if(!e)
    {
        e = event;
    }

    if(c)
    {
        if(e.preventDefault)
        {
            e.preventDefault();
        }
        e.cancelBubble = true;
    }

    return  e;
}

function EventTarget(e)
{
    var t = null;

    if(e.srcElement)
    {
        t = e.srcElement;
    }
    else if(e.target)
    {
        t = e.target;
    }
    return t;
}

function Observe(o,e,f)
{
    if(o)
    {
        if(o.addEventListener)
        {
            o.addEventListener(e,f,false);
        }
        else if(o.attachEvent)
        {
            o.attachEvent("on"+e,f,false);
        }
    }
}

function UnObserve(o,e,f)
{
    if(o)
    {
        if(o.removeEventListener)
        {
            o.removeEventListener(e,f,false);
        }
        else if(o.detachEvent)
        {
            o.detachEvent("on"+e,f,false);
        }
    }
}

function ObjectLeft(o)
{
    var p = o.offsetLeft;

    while((o = o.offsetParent) != null)
    {
        p += o.offsetLeft;
    }
    return p;
}

function ObjectTop(o)
{
    var p = o.offsetTop;

    while((o = o.offsetParent) != null)
    {
        p += o.offsetTop;
    }
    return p;
}

function ObjectBottom(o)
{
    var p = ObjectTop(o);

    return p + o.offsetHeight;
}

function GetCursorPosition(e) 
{
	/* 
	** Locals
	*/
	var cursor = {x:0, y:0};

    e = Event(e, false); //e || window.event;

    if (undefined != e && (e.pageX || e.pageY)) 
	{
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else 
	{
        var de = document.documentElement;
        var b  = document.body;

        cursor.x = e.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    
    return [cursor.x, cursor.y];
}

function ObjectClientPos(o)
{
    var pos = [o.offsetLeft,o.offsetTop];

    while((o = o.offsetParent) != null)
    {
        pos[0] += o.offsetLeft;
        pos[1] += o.offsetTop;
    }

    return pos;
}

function GetParentByTagName(obj,tag)
{
    var par = null;
    var cur = obj;
    var idx = 0;
    
    tag = tag.toUpperCase();
    
    while(null != cur && null == par)
    {
        if(cur.tagName && tag == cur.tagName.toUpperCase() && idx != 0)
        {
            par = cur;
        }
        cur = cur.parentNode;
        idx++;
    }
    
    return par;
}


/*
** n - Number of column ( td )
** t - to append with ( tr to tbody)
*/
function MakeTableRow(n,t)
{
	/*
	** Locals.
	*/	
	var tr, td, ar;
	
	tr = MakeDOMObject("TR");
	ar = [tr];
	
	for(i=0;i<n;i++)
	{										
		td  = MakeDOMObject("TD");				
		AppendDOMObject(td,tr);
		ar.push(td);
	}

	if(t)
	{
		AppendDOMObject(tr,t);
	}

	return ar;
}

function MakeTable(p,s)
{
	/*
	** Locals.
	*/	
	var tb;
	var to;

	tb = MakeDOMObject("TABLE");
	to = MakeDOMObject("TBODY");

	if(p)
	{
		tb.cellPadding = p;
	}

	if(s)
	{
		tb.cellSpacing = s;
	}
	
	// To add tbody
	AppendDOMObject(to,tb);
	// To add table to doc body
	AppendDOMObject(tb);
	
	return [tb,to];				
}

/*
** Method for email id validation
*/
function IsValidEmailAddr(emVal)
{
    /*
    ** Locals.
    */
    var emOk  = false;

    /*
    ** Not null, and no spaces inside.
    */
    if(null != emVal && -1 == emVal.indexOf(' '))
    {
        /*
        ** Locals.
        */
        var atIdx;
        var dotIdx;

        atIdx  = emVal.lastIndexOf('@');
        dotIdx = emVal.lastIndexOf('.');

        emOk   = (-1 != atIdx && -1 != dotIdx) && /*'@' and '.' should be there */
                 (0 != atIdx    )              && /*'@' shouldn't be first one  */
                 (0 != emVal.indexOf('.')    ) && /*'.' shouldn't be first one  */
                 (emVal.length-1 != atIdx    ) && /*'@' shouldn't be last one   */
                 (emVal.length-1 != dotIdx   ) && /*'.' shouldn't be first one  */
                 (emVal.indexOf('@') == atIdx);   /*'@' should be only once     */
    }

    return emOk;
}

/*
** Method for left trim
*/
function TrimLeft(str)
{
    /*
    ** Locals.
    */
    var tstr = str;
    var idx  = -1;

    if(null != tstr)
    {
        idx = tstr.indexOf(' ');

        while( 0 == idx && idx+1 < tstr.length)
        {
            tstr = tstr.substring(idx+1,tstr.length);
            idx  = tstr.indexOf(' ');
        }
    }

    return tstr;
}

/*
** Method for right time
*/ 
function TrimRight(str)
{
    /*
    ** Locals.
    */
    var tstr = str;
    var idx  = -1;

    if(null != tstr)
    {
        idx = tstr.lastIndexOf(' ');

        while( idx == tstr.length-1 && -1 != idx)
        {
            tstr = tstr.substring(0,idx);
            idx  = tstr.lastIndexOf(' ');
        }
    }

    return tstr;

}

/*
** Method for trim
*/
function Trim(str)
{
    return TrimLeft(TrimRight(str));
}


/*
** Method to check for special characters.
*/
function CheckSpecialChar(value)
{
	/*
	** Special characters
	*/
	var iChars  = "!@#$%^~`&*()+=[]\\\;,/{}|\":<>?";
	
	return CheckSpecialCharEx(iChars, value);
}

/*
** Method to check for special characters.
*/
function CheckAdvancedSpecialChar(value)
{
	/*
	** Special characters
	*/
	var iChars  = "!@#$%^~`&*()+=[]\\\';,/{}|\":<>?";
	
	return CheckSpecialCharEx(iChars, value);
	
}

function CheckSpecialCharEx(iChars, value)
{
	for (var index = 0; index < value.length; index++)
	{
		if (iChars.indexOf(value.charAt(index)) != -1) 
		{
			return true;
		}
	}

	return false;

}

/*
** BUTTON CLICK - [BEGIN] 
*/

function OnTabBtnClicked(tabid) 
{
    /* 
    ** Redirect the user Based on the id
    */
    if (null != tabid)
     {
        switch(tabid)
        {
            case 1:
                document.location = "Home.aspx";
                break;
            case 2:
                document.location = "Demo.aspx";
                break;
            case 3:
                document.location = "FAQ.aspx";
                break;
            case 4:
                document.location = "Contacts.aspx";
                break;
            case 5:
                document.location = "About.aspx";
                break;
            case 6:
                document.location = "Support.aspx";
                break;
            default:
                break;                            
        }
    }
}

function SetFocusOn(id)
{
    /*
    ** Locals.
    */
    var ele = $(id);
    
    if( null != ele)
    {
        ele.focus();
    }
}

/* 
** Function to handle User Login...
*/

function OnUserLogin()
{
    ValidateLoginCredential();
    return false;
}

function OnForgotPassClick()
{
    ToDo();
}

/* 
** Function to show the login error message.
*/
function ShowLoginMessage(txtMsg)
{
    /* 
    ** Locals
    */
    var msgBar;
    var msg;
    
    try
    {
        if($("SPS_ERR_Message"))
        {
            clearTimeout($("SPS_ERR_Message").SetTOVar);
        }
    }
    catch(e)
    {
    }
    
    msgBar            = $("SPS_Login_MessageBar");
    msgBar.innerHTML  = "";
    msgBar.title      = "";
    
    msg               = MakeDOMObject("span");
    msg.id            = "SPS_ERR_Message"
    msg.innerHTML     = txtMsg;
    AppendDOMObject(msg, msgBar);
    msgBar.title      = txtMsg;
    
    ShowTimeoutControl("SPS_ERR_Message", 5000);
}

function IsValidDateFormat(dateStr)
{
    /*
    ** Locals.
    */
    var datePattern = null
    
    /*
    ** Date format pattern
    */
	//datePattern = /\b\d{1,2}[\/]\d{1,2}[\/]\d{4}\b/; //Format eg: 12-06-2009
	datePattern = /\b\d{1,2}[\/]\d{1,2}[\/]\d{4}\b/; //Format eg: 12/06/2009
	
    if (datePattern.test(dateStr)) 
	{
	    return true;
	}
	
	datePattern = /\b\d{1,2}[-]\d{1,2}[-]\d{4}\b/;
	
	if (datePattern.test(dateStr)) 
	{
	    return true;
	}
	
	return false;
}

/*
** Method to check the date format
*/
function IsValidDate(dateStr)
{
	/*
	** Locals.
	*/
	var month		= -1;
	var day			= -1;
	var	year		= -1;
	var newDate		= null;

	//var delimChar = (dateStr.indexOf("/") != -1) ? "/" : "-";
	var delimChar = "/";

	/*
	** Finding the index of delimited charater.
	*/
	var delim1	  = dateStr.indexOf(delimChar);
	var delim2	  = dateStr.lastIndexOf(delimChar);

	/*
	** Get the month.
	*/
	month	= parseInt(dateStr.substring(0, delim1), 10);

	/*
	** Get the day.
	*/
	day		= parseInt(dateStr.substring(delim1 + 1, delim2), 10);

	/*
	** Get the year.
	*/
	year	= parseInt(dateStr.substring(delim2 + 1), 10);

	/*
	** Preparing the new date with extracted values.
	*/
	newDate = new Date(year, month - 1, day);

	if (newDate.getDate()	   != day	|| 
		newDate.getMonth() + 1 != month ||  
		newDate.getFullYear()  != year
	   ) 
	{
	    return "Invalid date.";
	}
}

/* 
** Handling Key Press for Login
*/
function OnLoginKeyPress(e)
{
    /* 
    ** Locals.
    */
    var keycode;

    keycode = e.keyCode || e.which;

    if (13 == keycode) 
    {
        ValidateLoginCredential();
        return false;
    }
    
    return true;
}

function ShowSessionExpired()
{
    ShowAlert("\nCurrent session expired.");
}

function ShowAlert(message)
{
    /*
    ** Locals.
    */
    var msgBox  = null;
    var tempVal = null;
        
    msgBox           = $('SPS_Alert_OK_Message');
    
    if( null != msgBox && null != message )
    {
        msgBox.innerHTML    = message;
        msgBox.title        = message;
        
        /*if(message.length < 34 )
        {
            msgBox.parentNode.style.marginTop = "15px";
        }
        else
        {
            //TODO: Add \n to get two line.
            //message
        }*/
        
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_OK_Box');
    }
}

function OnNewUserRegistration() 
{
    /* 
    ** Locals.
    */
    var userType;

    userType = $("SPSNewUserType");

    if (null != userType)
    { 
        switch(userType.value)
        {
            case "0":
                document.location = "NewUserPaymentForm.aspx?UserType=0";
                break;
            case "1":
                document.location = "NewUserPaymentForm.aspx?UserType=1";
                break;
            case "2":
                document.location = "NewUserPaymentForm.aspx?UserType=2";
                break;
            case "3":
                document.location = "NewInstructorUserReg.aspx?UserType=3";
                break;                
            default:
                break;
        }
    }
    return false;
}

/*function OnInstructorRegSubmit() 
{
    RegisterNewInstructor();
}*/

function OnPaypalRegSubmit(userType)
{
    /*
    ** Paypal submission.
    */
    if (null != userType && USER_TYPE_CONSULTANT == userType) 
    {
        document.location = "NewCosultantUserReg.aspx";
    }
    else if (null != userType && USER_TYPE_MANAGER == userType) 
    {
        document.location = "NewManagerUserReg.aspx";
    }
    else if (null != userType && USER_TYPE_STUDENT == userType) 
    {
        document.location = "NewStudentUserReg.aspx";
    }
    else if (null != userType && USER_TYPE_INSTRUCTOR == userType) 
    {
        document.location = "NewInstructorUserReg.aspx";
    }    
}

function OnPurchaseCodeRegSubmit(userType) 
{
    /*
    ** Validating the purchase code.
    */
    if (null != userType && USER_TYPE_CONSULTANT == userType)
    {
        ValidatePurchaseCode(userType);
    }
    else if(null != userType && USER_TYPE_MANAGER == userType)
    {
        ValidatePurchaseCode(userType);
    }
    else if(null != userType && USER_TYPE_STUDENT == userType)
    {
        ValidatePurchaseCode(userType);
    }
    else if(null != userType && USER_TYPE_INSTRUCTOR == userType)
    {
        ValidatePurchaseCode(userType);
    }
}

function OnConsultantRegSubmit()
{
    RegisterNewConsultantUser();
}

function OnManagerRegSubmit()
{
    RegisterNewManagerUser();
}

function OnStudentRegSubmit() 
{
    RegisterNewStudent();
}

function OnInstructorRegSubmit() 
{
    RegisterNewInstructor();
}

/* 
** Function which handles the Process Start
*/

function OnStartProcess() 
{
    InitializeAnalysisMapping();
}

function InitAnalysisSave(bInit)
{
    /* 
    ** Locals
    */
    var btn;
    
    /* 
    ** Change the class name of Back, Save and Continue buttons
    */
    /*btn           = $("SPS_An_Back");
    btn.className = bInit ? "sps-module-navbar-back-disabled" : "sps-module-navbar-back";
    btn.disabled  = bInit;*/
    
    btn           = $("SPS_An_Continue");
    btn.className = bInit ? "sps-module-navbar-continue-disabled" : "sps-module-navbar-continue";
    btn.disabled  = bInit;
    btn           = $("SPS_An_Save");
    btn.className = bInit ? "sps-module-navbar-save-disabled" : "sps-module-navbar-save";
    btn.disabled  = bInit;
    
    $("SPS_An_Loading").style.display = bInit ?  "block" : "none";
}

function OnOrgAnalysisBack() 
{
    OnOrgAnalysisNavigate("Welcome.aspx");
}

function OnOrgAnalysisSave() 
{
    //InitAnalysisSave(true);
    InsertOrganisationDetails();
}

function OnOrgAnalysisContinue()
{
    //OnOrgAnalysisNavigate("ExternalAnalysisPolitical.aspx");
    OnOrgAnalysisNavigate("Srm.html#2");
}

function OnOrgAnalysisNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS_An_Save').disabled);
    
    if(!bSave)
    {
        crcVal  = GetOrgAnalysisCRC();    
        bOK     = ($('SPS_ORG_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_ORG_CRCValue').value = crcVal;
            OnOrgAnalysisSave();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page ;
        }
    }
    else
    {
        document.location = page;
    }
}

function OnExtBack()
{
    document.location = "OrgAnalysis.aspx";
}

function OnExtContinue()
{
    document.location = "ExternalAnalysisPolitical.aspx";
}
/* 
** Pest Analysis - Political Factors
*/

function OnExtPoliticalBack() 
{
    OnExtPoliticalNavigate("ExternalAnalysis.aspx");
}

function OnExtPoliticalContinue() 
{
    OnExtPoliticalNavigate("ExternalAnalysisPestleEconomic.aspx");
}

function OnExtPoliticalNavigate(page)
{   
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-ExtPestPol-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEAPoliticalCRC();    
        bOK     = ($('SPS_EA_Political_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_Political_CRCValue').value = crcVal;
            InsertPoliticalFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }
}

function OnExtPoliticalSave() 
{
    InsertPoliticalFactors();
}

/* 
** Pest Analysis - Economic Factors
*/

function OnExtEconomicBack() 
{
    OnExtEconomicNavigate("ExternalAnalysisPolitical.aspx");
}

function OnExtEconomicContinue() 
{
    OnExtEconomicNavigate("ExternalAnalysisPestleSocio.aspx");
}

function OnExtEconomicNavigate(page)
{     
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-ExtPestEcono-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEAEconomicCRC();    
        bOK     = ($('SPS_EA_Economi_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_Economi_CRCValue').value = crcVal;
            InsertEconomicFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnExtEconomicSave() 
{
    InsertEconomicFactors();
}

/* 
** Pest Analysis - Socio-cultural Factors
*/

function OnExtSocioBack() 
{
    OnExtSocioNavigate("ExternalAnalysisPestleEconomic.aspx");
}

function OnExtSocioContinue() 
{
    OnExtSocioNavigate("ExternalAnalysisPestleTechnological.aspx");
}

function OnExtSocioNavigate(page)
{  
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-ExtPestSocio-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEASocioCulturalCRC();    
        bOK     = ($('SPS_EA_Socio_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_Socio_CRCValue').value = crcVal;
            InsertSocioCulturalFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnExtSocioSave() 
{
    InsertSocioCulturalFactors();
}

/* 
** Pest Analysis - Technological Factors
*/

function OnExtTechnoBack()
{
    OnExtTechnoNavigate("ExternalAnalysisPestleSocio.aspx");
}

function OnExtTechnoContinue() 
{
    //OnExtTechnoNavigate(page);// + "?LoadSaved=true&hlId=s14");
    OnExtTechnoNavigate("ExternalAnalysisPestConclusion.aspx");// + "?LoadSaved=true&hlId=s14");
}

function OnExtTechnoNavigate(page)
{   
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-ExtPestTech-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEATechnologicalCRC();    
        bOK     = ($('SPS_EA_Technological_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_Technological_CRCValue').value = crcVal;
            InsertTechnologicalFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnExtTechnoSave() 
{
    InsertTechnologicalFactors();
}


/* 
** Pest Analysis - Conclusion ///TODO: Need to Start From here
*/

function OnPhase1PestConBack() 
{
    OnPestConNavigate("ExternalAnalysisPestleTechnological.aspx");
}

function OnPhase1PestConContinue(page) 
{
    //OnPestConNavigate("ExternalAnalysisPestleTechnological.aspx");
    OnPestConNavigate(page);// + "?LoadSaved=true&hlId=s14");
}

function OnPestConNavigate(page)
{  
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-P1-PEST-Con-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetPestConclusionCRC();    
        bOK     = ($('SPS_EA_PEST_Con_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_PEST_Con_CRCValue').value = crcVal;
            SavePestConclusion();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnPestConclusionSave() 
{
    SavePestConclusion();
}


/* 
** Porter's 5 Forces Analysis - Threat of New Entry
*/

function OnExtPortTNEBack() 
{
    OnExtPortTNENavigate("ExternalAnalysisILC.aspx");
}

function OnExtPortTNEContinue() 
{
    OnExtPortTNENavigate("ExternalAnalysisPorters5TS.aspx");
}

function OnExtPortTNENavigate(page)
{     
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-ExtPortTNE-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEANewEntryThreatCRC();    
        bOK     = ($('SPS_EA_NET_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_NET_CRCValue').value = crcVal;
            InsertNewEntryThreatFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnExtPortTNESave() 
{
    InsertNewEntryThreatFactors();
}

/* 
** Porter's 5 Forces Analysis - Threat of Substitutes
*/

function OnExtPortTSBack() 
{
    OnExtPortTSNavigate("ExternalAnalysisPorters5TNE.aspx");
}

function OnExtPortTSContinue() 
{
    OnExtPortTSNavigate("ExternalAnalysisPorters5BP.aspx");
}

function OnExtPortTSNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Ext-PortTS-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEASubstituteThreatCRC();    
        bOK     = ($('SPS_EA_ST_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_ST_CRCValue').value = crcVal;
            InsertSubstitutesThreatFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }
}

function OnExtPortTSSave()
{
    InsertSubstitutesThreatFactors();
}


/* 
** Porter's 5 Forces Analysis - Determinants of buyer power
*/

function OnExtPortBPBack() 
{
    OnExtPortBPNavigate("ExternalAnalysisPorters5TS.aspx");
}

function OnExtPortBPContinue() 
{
    OnExtPortBPNavigate("ExternalAnalysisPorters5SP.aspx");
}
function OnExtPortBPNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Ext-PortBP-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEABuyerPowerCRC();    
        bOK     = ($('SPS_EA_BP_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_BP_CRCValue').value = crcVal;
            InsertBuyersPowerFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnExtPortBPSave() 
{
    InsertBuyersPowerFactors();
}

/* 
** Porter's 5 Forces Analysis - Determinants of supplier power
*/

function OnExtPortSPBack() 
{
    OnExtPortSPNavigate("ExternalAnalysisPorters5BP.aspx");
}

function OnExtPortSPContinue() 
{
    OnExtPortSPNavigate("ExternalAnalysisPorters5CR.aspx");
}

function OnExtPortSPNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Ext-PortSP-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEASupplyPowerCRC();    
        bOK     = ($('SPS_EA_SP_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_SP_CRCValue').value = crcVal;
            InsertSuppliersPowerFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnExtPortSPSave() 
{
    InsertSuppliersPowerFactors();
}

/* 
** Porter's 5 Forces Analysis - Competitive rivalry determinants
*/

function OnExtPortCRBack() 
{
    OnExtPortCRNavigate("ExternalAnalysisPorters5SP.aspx");
}

function OnExtPortCRContinue()
{
    //OnExtPortCRNavigate(page);// + "?LoadSaved=true&hlId=s06");
    OnExtPortCRNavigate("ExternalAnalysisPorters5Conclusion.aspx");
}

function OnExtPortCRNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Ext-PortCR-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetEACompetitiveRivalryCRC();    
        bOK     = ($('SPS_EA_CR_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_CR_CRCValue').value = crcVal;
            InsertCompetitiveRivalryFactors();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnExtPortCRSave() 
{
    InsertCompetitiveRivalryFactors();
}


/* 
** Pest Analysis - Conclusion ///TODO: Need to Start From here
*/

function OnPhase1PortersConBack() 
{
    OnPortersConNavigate("ExternalAnalysisPorters5CR.aspx");
}

function OnPhase1PortersConContinue(page) 
{
    //OnPestConNavigate("ExternalAnalysisPestleTechnological.aspx");
    OnPortersConNavigate(page);// + "?LoadSaved=true&hlId=s14");
}

function OnPortersConNavigate(page)
{  
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-P1-PORTERS-Con-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetPortersConclusionCRC();    
        bOK     = ($('SPS_EA_PORTERS_Con_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_EA_PORTERS_Con_CRCValue').value = crcVal;
            SavePortersConclusion();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnPortersConclusionSave() 
{
    SavePortersConclusion();
}

function OnIntBack()
{
    document.location = "ExternalAnalysisPorters5Conclusion.aspx";
}

function OnIntContinue()
{
    document.location = "InternalAnalysisRAHuman.aspx";
}
/* 
** Resource Audit Analysis - Human Resources
*/

function OnIntRAHumanBack() 
{
    OnIntRAHumanNavigate("InternalAnalysis.aspx");
}

function OnIntRAHumanContinue() 
{
    OnIntRAHumanNavigate("InternalAnalysisRAPhysical.aspx");
}

function OnIntRAHumanNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-RAHuman-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAHumanCRC();    
        bOK     = ($('SPS_IA_HM_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_HM_CRCValue').value = crcVal;
            InsertHumanResources();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }       
}

function OnIntRAHumanSave() 
{
    InsertHumanResources();
}

/* 
** Resource Audit Analysis - Physical Resources
*/

function OnIntRAPhysicalBack() 
{
    OnIntRAPhysicalNavigate("InternalAnalysisRAHuman.aspx");
}

function OnIntRAPhysicalContinue() 
{
    OnIntRAPhysicalNavigate("InternalAnalysisRAFinancial.aspx");
}

function OnIntRAPhysicalNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-RAPhysical-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAPhysicalCRC();    
        bOK     = ($('SPS_IA_PH_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_PH_CRCValue').value = crcVal;
            InsertPhysicalResources();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnIntRAPhysicalSave() 
{
    InsertPhysicalResources();
}

/* 
** Resource Audit Analysis - Financial Resources
*/

function OnIntRAFinancialBack() 
{
    OnIntRAFinancialNavigate("InternalAnalysisRAPhysical.aspx");
}

function OnIntRAFinancialContinue() 
{
    OnIntRAFinancialNavigate("InternalAnalysisRAIntangible.aspx");
}

function OnIntRAFinancialNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-RAFinancial-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAFinancialCRC();    
        bOK     = ($('SPS_IA_FN_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_FN_CRCValue').value = crcVal;
            InsertFinancialResources();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnIntRAFinancialSave() 
{
    InsertFinancialResources();
}

/* 
** Resource Audit Analysis - Intangible Resources
*/

function OnIntRAIntangibleBack() 
{
    OnIntRAIntangibleNavigate("InternalAnalysisRAFinancial.aspx");
}

function OnIntRAIntangibleContinue(page) 
{
    OnIntRAIntangibleNavigate(page);// + "?LoadSaved=true&hlId=s16");
}

function OnIntRAIntangibleNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-RAIntangible-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAIntangibleCRC();    
        bOK     = ($('SPS_IA_IT_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_IT_CRCValue').value = crcVal;
            InsertIntangibleResources();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }      
}

function OnIntRAIntangibleSave() 
{
    InsertIntangibleResources();
}


/* 
** Value Chain Analysis
*/


//Primary activities
function OnIntVCPABack() 
{
    OnIntVCPANavigate("InternalAnalysisRAIntangible.aspx");
}

function OnIntVCPAContinue() 
{
    OnIntVCPANavigate("InternalAnalysisVCSA.aspx");
}

function OnIntVCPANavigate(page)
{    
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-VCPrimary-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAVCPrimaryCRC();    
        bOK     = ($('SPS_IA_VC_P_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_VC_P_CRCValue').value = crcVal;
            InsertVCPrimaryActivities();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }      
}

function OnIntVCPASave() 
{
    InsertVCPrimaryActivities();
}


//Secondary activities.
function OnIntVCSABack() 
{
    OnIntVCSANavigate("InternalAnalysisVCPA.aspx");
}

function OnIntVCSAContinue(page) 
{
    OnIntVCSANavigate(page);// + "?LoadSaved=true&hlId=s15")
}

function OnIntVCSANavigate(page)
{   
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-Int-VCSupport-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetIAVCSecondaryCRC();    
        bOK     = ($('SPS_IA_VC_S_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_IA_VC_S_CRCValue').value = crcVal;
            InsertVCSecondaryActivities();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }    
}

function OnIntVCSASave() 
{
    InsertVCSecondaryActivities();
}

/* 
** SWOT Analysis
*/

function OnIntSWOTBack() 
{
    OnIntSWOTNavigate("InternalAnalysisVCSA.aspx");
}

function OnIntSWOTContinue(page) 
{
    OnIntSWOTNavigate(page);// + "?LoadSaved=true&hlId=s09");
}

function OnIntSWOTNavigate(page)
{   
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS_SWOT-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetSwotCRC();  
        
        /*
        ** Checks the strategy, newly added SWOTs' removes SWOT's
        */  
        bOK    &= ($('SPS_SWOT_CRCValue').value == crcVal);
        bOK    &= (0 == g_Strengths.length);
        bOK    &= (0 == g_Weakness.length);
        bOK    &= (0 == g_Opportunities.length);
        bOK    &= (0 == g_Threats.length);
        bOK    &= (0 == g_rSWOT.length);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_SWOT_CRCValue').value = crcVal;
            OnSaveStrategies();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnIntSWOTSave() 
{
    OnSaveStrategies()
}

/* 
** Vision Analysis
*/

function OnIntVisionBack() 
{
    OnIntVisionNavigate("SWOTAnalysis.aspx");
}

function OnIntVisionContinue(page) 
{
    OnIntVisionNavigate(page);// + "?LoadSaved=true&hlId=s10");
}

function OnIntVisionNavigate(page)
{ 
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-OP-Vision-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetVisionDetailsCRC();
        bOK     = ($('SPS_OP_V_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_OP_V_CRCValue').value = crcVal;
            InsertVisionDetails();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }
    
    //document.location = "Welcome.aspx?m=2&hlId=s10";
}

function OnIntVisionSave() 
{
    InsertVisionDetails();
}

/* 
** Mission Analysis
*/

function OnIntMissionBack() 
{
    OnIntMissionNavigate("OPVision.aspx");
}

function OnIntMissionContinue(page) 
{
    OnIntMissionNavigate(page);// + "?LoadSaved=true&hlId=s11");
}

function OnIntMissionNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-OP-Mission-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetMissionCRC();    
        bOK     = ($('SPS_OP_M_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_OP_M_CRCValue').value = crcVal;
            InsertMissionDetails();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
        }
    }
    else
    {
        document.location = page;
    }     
}

function OnIntMissionSave() 
{
    InsertMissionDetails();
}


function OnIntObjectivesBack() 
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-OP-Objective-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetObjectiveCRC();    
        bOK     = ($('SPS_OP_O_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_OP_O_CRCValue').value = crcVal;
            InsertObjectiveDetails();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = "OPMission.aspx"
        }
    }
    else
    {
        document.location = "OPMission.aspx"
    }       
}

function OnIntObjectivesContinue(page) 
{
    OnIntObjectivesNavigate(page);
}

function OnIntObjectivesNavigate(page)
{
    /*
    ** Locals.
    */
    var bOK     = true;
    var bSave   = false;
    var crcVal  = ""
    
    bSave = ($('SPS-OP-Objective-SaveBtn').disabled);
    
    if(!bSave)
    {
        crcVal  = GetObjectiveCRC();    
        bOK     = ($('SPS_OP_O_CRCValue').value == crcVal);
    }
    
    if(!bOK)
    {
        /* 
        ** Show the Confirm Continue alert
        */
        ShowWnd(250 , 90, 'SPS', 'SPS_Alert_ConfirmBox');
        
        $("SPS_Alert_Yes").onclick = function()
        {
            WndClose();
            $('SPS_OP_O_CRCValue').value = crcVal;
            InsertObjectiveDetails();
        }
        
        $("SPS_Alert_No").onclick = function()
        {   
            WndClose();
            document.location = page;
            //ToDo();
        }
    }
    else
    {
        document.location = page;
        //ToDo();
    }     
}

function OnIntObjectivesSave() 
{
    InsertObjectiveDetails();
}


function IsOrganizationCheck()
{
    if($('SPS-OrgInfo-OrgType-Individual').checked)
    {
        $('SPS-OrgInfo-OrgType-Group').checked      = false;
        
        /*$('SPS-OrgInfo-OrgType-GroupInfo').disabled = true;
        $('SPS-OrgInfo-OrgType-GroupInfo').value    = "";
        $('SPS-OrgInfo-BusUnit').disabled           = true;
        $('SPS-OrgInfo-BusUnit').value              = "";*/
        
        $('SPS_Org_Group').className                = "sps-display-none";
    }
    else
    {
        $('SPS-OrgInfo-OrgType-Individual').checked = true;
        /*$('SPS-OrgInfo-OrgType-Group').checked      = true;
        $('SPS-OrgInfo-OrgType-GroupInfo').disabled = false;
        $('SPS-OrgInfo-BusUnit').disabled           = false;
        
        $('SPS_Org_Group').className                = "sps-display-block";*/
    }
}

function IsGroupCheck()
{
    if($('SPS-OrgInfo-OrgType-Group').checked)
    {
        $('SPS-OrgInfo-OrgType-Individual').checked = false;
        /*$('SPS-OrgInfo-OrgType-GroupInfo').disabled = false;
        $('SPS-OrgInfo-BusUnit').disabled           = false;
        
        $('SPS_Org_Group').className                = "sps-display-none";*/
        $('SPS_Org_Group').className                = "sps-display-block";
    }
    else
    {
        $('SPS-OrgInfo-OrgType-Group').checked        = true;
        
        /*$('SPS-OrgInfo-OrgType-Individual').checked = true;
        
        $('SPS-OrgInfo-OrgType-GroupInfo').disabled = true;
        $('SPS-OrgInfo-OrgType-GroupInfo').value    = "";
        $('SPS-OrgInfo-BusUnit').disabled           = true;
        $('SPS-OrgInfo-BusUnit').value              = "";
        
        $('SPS_Org_Group').className                = "sps-display-block";*/
    }
}

/*
** BUTTON CLICK - [END] 
*/



/* 
** Hiding controls after timeout
*/
function ShowTimeoutControl(controlId, timeout, ct)
{
    if(null != ct)
    {
        HideControl(ct);
    }
    
    $(controlId).style.display = "block";
    $(controlId).SetTOVar      = setTimeout(function(){ HideControl(controlId);}, timeout);
}

function HideControl(controlId)
{
    try
    {
        clearTimeout($(controlId).SetTOVar);
        $(controlId).style.display = "none";
    }
    catch(e)
    {
    }
}

/* 
** Menu Functions 
*/
function OnMenuLoad(menuId, elemGroup, label, icon)
{
	InitMenu(menuId);

    $(menuId + 'Holder').style.display = "block";
    
	for(var index=0; index<elemGroup.length; index++)
	{
		$(elemGroup[index] + "Group").style.display = "block";
		$(elemGroup[index] + "Icon").className      = "sps-menu-icon sps-menu-icon-down";
	}
	
	$(label).className = "sps-menu-label-selected";

	if(null != icon)
	{
		$(icon).className = "sps-menu-icon sps-menu-icon-down";
	}

	/* 
	** Set the Selected Label and the Selected Group to the Menu item as attributes
	*/
	$(menuId).SelectedGroup = elemGroup;
	$(menuId).SelectedLabel = label;
}

function SelectMenuItem(menuId, elemGroup, label)
{
	/* 
	** Locals.
	*/
	var selectedGroup;
	var selectedLabel;
	var bIsSameRoot;
	var index;

	selectedGroup = $(menuId).SelectedGroup;
	selectedLabel = $(menuId).SelectedLabel;

	bIsSameRoot =  (selectedGroup[0] === elemGroup[0]);
	
	if(bIsSameRoot)
	{
		var oldelem;
		var curelem;
		var oldlength;
		var curlength;
		var looplength;
		var lastindex;
		var lastdisplay;
				
		var groupObj;
		var iconObj;

		oldlength	= selectedGroup.length;
		curlength	= elemGroup.length;

		/* 
		** Check if the last elements are the same
		*/
		oldelem = selectedGroup[oldlength-1];
		curelem = elemGroup[curlength-1];
			
		if(oldelem == curelem)
		{
		    groupObj = $(curelem + "Group");
		    if(groupObj)
		    {
			    groupObj.style.display = (groupObj.style.display == "none") ? "block" : "none";
			}
			
			iconObj = $(curelem + "Icon");
			
			if(iconObj && groupObj)
			{
			    iconObj.className = (groupObj.style.display == "none") ? 
			                        "sps-menu-icon sps-menu-icon-normal" : 
			                        "sps-menu-icon sps-menu-icon-down";
			}
		}		
		else
		{
			looplength = (curlength >= oldlength) ? curlength : oldlength;

			for(index=0; index<looplength; index++)
			{
				oldelem = (index < oldlength) ? selectedGroup[index] : null;
				curelem = (index < curlength) ? elemGroup[index] : null;
				
				if(oldelem === curelem)
				{
					lastindex = index;
				}
			}

			/*
			** Check the state of the lastindex group 
			*/
			lastdisplay = $(elemGroup[lastindex] + "Group").style.display;

			for(index = oldlength-1; index >= lastindex; index--)
			{
			    groupObj = $(selectedGroup[index] + "Group");
			    if(groupObj)
			    {
				    groupObj.style.display = "none";
				}
				
				iconObj = $(selectedGroup[index] + "Icon");
				if(iconObj)
				{
				    iconObj.className     = "sps-menu-icon sps-menu-icon-normal";
			    }
			}

			for(index = lastindex; index < curlength; index++)
			{
			    groupObj = $(elemGroup[index] + "Group");
			    if(groupObj)
			    {
			        groupObj.style.display = "block";
			    }
			    
			    iconObj = $(elemGroup[index] + "Icon");
			    
			    if(iconObj)
			    {
				    iconObj.className		= "sps-menu-icon sps-menu-icon-down";
				}
			}

			if(lastindex == (curlength-1))
			{
			    groupObj    = $(elemGroup[lastindex] + "Group");
			    if(groupObj)
			    {
				    groupObj.style.display = (lastdisplay == "none") ? "block" : "none";
			    }
			    
			    iconObj = $(elemGroup[lastindex] + "Icon");
			    
			    if(iconObj)
			    {
				    iconObj.className	= (lastdisplay == "none") ?  
				                            "sps-menu-icon sps-menu-icon-down" : "sps-menu-icon sps-menu-icon-normal";
				}

			}

		}
	}
	else
	{
		/* 
		** Collapse the existing nodes
		*/
		for(index=0; index<selectedGroup.length; index++)
		{
		    groupObj            
		
			$(selectedGroup[index] + "Group").style.display = "none";
			$(selectedGroup[index] + "Icon").className      = "sps-menu-icon sps-menu-icon-normal";
		}

		/* 
		** Expand the input nodes
		*/
		for(index=0; index<elemGroup.length; index++)
		{
			$(elemGroup[index] + "Group").style.display = "block";
			$(elemGroup[index] + "Icon").className      = "sps-menu-icon sps-menu-icon-down";
		}
	}
	
	/* 
	** Set the Selected Label and the Selected Group to the Menu item as attributes
	*/
	$(menuId).SelectedGroup = elemGroup;
	$(menuId).SelectedLabel = label;
}

function InitMenu(menuId)
{
	/* 
	** Locals.
	*/
	var selectedGroup;
	var selectedLabel;

	/* 
	** collapse all the selected elements
	*/
	selectedGroup = $(menuId).SelectedGroup;

	if(null != selectedGroup && '' != selectedGroup)
	{
		for(var index = (selectedGroup.length -1) ; index >= 0; index--)
		{
			$(selectedGroup[index] + 'Group').style.display = "none";
			$(selectedGroup[index] + 'Icon').className      = "sps-menu-icon sps-menu-icon-normal";
		}
	}

	/* 
	** Change the className of the selected Label
	*/
	selectedLabel = $(menuId).SelectedLabel;
	
	if(null != selectedLabel && '' != selectedLabel)
	{
		$(selectedLabel).className = "sps-menu-label";
	}

}

/*
** Method to show theory window.
*/
function ShowTheoryWindow()
{
    /*
    ** Locals.
    */

    var width;
    var height;

    var left;
    var top;
    var params;
    
    width   = 630;
    height  = 350;
    
    left   = (screen.width  - width)/2;
    top    = (screen.height - height)/2;
    params = 'width=' + width + ', height=' + height;
    

    params += ', top='+ top +', left=' + left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=yes';
    params += ', status=no';
    params += ', toolbar=no';

    window.open("Theory.aspx?SelPage=" + g_SelectedPage, "TheoryWindow", params);
}

function ShowGlossaryWindow()
{
    /*
    ** Locals.
    */

    var width;
    var height;

    var left;
    var top;
    var params;
    
    width   = 680;
    height  = 350;
    
    left   = (screen.width  - width)/2;
    top    = (screen.height - height)/2;
    params = 'width=' + width + ', height=' + height;
    

    params += ', top='+ top +', left='+ left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=yes';
    params += ', status=no';
    params += ', toolbar=no';

    window.open("Glossary.aspx", "GlossaryWindow", params);
}

function ShowSWebsitesWindow()
{
    /*
    ** Locals.
    */

    var width;
    var height;

    var left;
    var top;
    var params;
    
    width   = 680;
    height  = 350;
    
    left   = (screen.width  - width)/2;
    top    = (screen.height - height)/2;
    params = 'width=' + width + ', height=' + height;
    

    params += ', top='+ top +', left='+ left;
    params += ', directories=no';
    params += ', location=no';
    params += ', menubar=no';
    params += ', resizable=no';
    params += ', scrollbars=yes';
    params += ', status=no';
    params += ', toolbar=no';

    window.open("SuggestedWebsites.aspx", "SuggestedWebsiteWindow", params);
}

function OnMenuItemNavigate(page)
{
    /*if( null != $('SPS_Indvl_Radio') && true == $('SPS_Indvl_Radio').checked )
    {
        if( null != $('SPS-Student-Course'))
        {
            page += "?CourseId=" + $('SPS-Student-Course').value;
        } 
    }
    else if( null != $('SPS_Anly_Radio'))
    {
        page  += "?GroupId=" + $('SPS-Student-Group').value;
    }*/

    document.location = page;   
}

function OnPageNavigate(page)
{
    document.location = page;
}

/* 
** Circular Menu
*/
function CirMI()
{
	/* 
	** Locals.
	*/
	var MIArray    = null;
	
	this.NavUpId   = null;
	this.NavDownId = null;
	
	this.Init     = function(miarray, navupid, navdownid)
	{
		MIArray        = miarray;
		this.NavUpId   = navupid;
		this.NavDownId = navdownid;
	}
	
	this.MoveUp   = function() 
	{
		/* 
		** Locals.
		*/
		var mi;
		var index;
		var top;
		var left;
        
        this.ChangeNavStyles(false);
        
        top  = MIArray[MIArray.length - 1].style.top;
		left = MIArray[MIArray.length - 1].style.left;
		top  = parseInt(top.replace(/px/gi, "")) + 20;

		for(index=0; index < MIArray.length; index++)
		{
			mi			    = MIArray[index];
			mi.StepCount    = 0;
			mi.NavDirection = 0;
			CirMINavigate(this, mi);
		}

		mi			    = MIArray.shift();
		mi.style.top    = top + "px";
		mi.style.left   = left;
		mi.StepCount    = 0;
		mi.NavDirection = 0;
		CirMINavigate(this, mi);
        
        MIArray.push(mi);
	}

	this.MoveDown = function()
	{
		/* 
		** Locals.
		*/
		var mi;
		var index;
		var top;
		var left;
		
		this.ChangeNavStyles(false);
		
		top  = MIArray[0].style.top;
		left = MIArray[0].style.left;
		top  = parseInt(top.replace(/px/gi, "")) - 20;

		for(index=MIArray.length -1 ; index >= 0; index--)
		{
			mi			    = MIArray[index];
			mi.StepCount    = 0;
			mi.NavDirection = 1;
			CirMINavigate(this, mi);
		}

		mi			    = MIArray.pop();
		mi.style.top    = top + "px";
		mi.style.left   = left;
		mi.StepCount    = 0;
		mi.NavDirection = 1;
		CirMINavigate(this, mi);

		MIArray.unshift(mi);
	}
	
	this.ChangeNavStyles = function(bEnable)
	{
	    /* 
	    ** Locals.
	    */
	    var upnav;
	    var downnav;
	    
	    upnav   = $(this.NavUpId);
	    downnav = $(this.NavDownId);
	    
	    upnav.Disabled  = bEnable ? false : true;
	    downnav.Disabled = bEnable ? false : true;
	    
	    upnav.className   = bEnable ? "sps-scirmenu-nav" : "sps-scirmenu-nav-disabled";
		downnav.className = bEnable ? "sps-scirmenu-nav" : "sps-scirmenu-nav-disabled";
	}
}

function CirMINavigate(menuObj, mi)
{
	try
	{
		if(mi.StepCount < 4)
		{
			/* 
			** Locals.
			*/
			var top;

			top				= mi.style.top;
			top				= top.replace(/px/gi, "");
			top             = (0 === mi.NavDirection) ? (parseInt(top) - 5) : (parseInt(top) + 5);
			mi.style.top	= top + "px";
			mi.StepCount	+= 1;
			setTimeout(function() { CirMINavigate(menuObj, mi) }, 40);
		}
		else
		{
		    menuObj.ChangeNavStyles(true);
		}
	}
	catch(e)
	{
	}
}

function LRTrim(str)
{ 
    while (str.substring(0,1) == ' ') 
	{
        str = str.substring(1, str.length);
	}

    while (str.substring(str.length-1,str.length) == ' ')
	{
        str = str.substring(0, str.length-1);
	}
   
	return str;
}

/*
** Function to remove the spaces.
*/
function RemoveSpaces(str)
{
    return str.replace(" ", "_");
}

/*
** Function to validate number.
*/
function ValidateNumber(e, iCode)
{
    /* 
    ** Locals.
    */
    var theEvent;
    var key;
    var regex;

    try
    {
        regex = /[0-9]/;
        
        if(null != iCode)
        {
            regex = GetRegExpression(iCode, false);
        }
        
        theEvent  = e || window.event;
        key       = theEvent.keyCode || theEvent.which;
        key       = String.fromCharCode( key );

        if(!regex.test(key))
        {
            return false;
        }
        return true;
    }
    catch(e)
    {
        return false;
    }
}

function ValidateValue(str, iCode)
{
    /* 
    ** Locals.
    */
    regex = /[^0-9]/;
    
    try
    {
        if(null != iCode)
        {
            regex = GetRegExpression(iCode, true);
        }
        
        if(regex.test(str))
        {
            return false;
        }
        return true;
    }
    catch(e)
    {
        return false;
    }
}

function GetRegExpression(iCode, bNegate)
{
    /* 
    ** Locals.
    */
    var regex;
    
    switch(iCode)
    { 
        case 0:         /* Phone */
            regex = bNegate ? /[^0-9-\+]/ : /[0-9]|-|\+/;
            break;
        case 1:         /* Zip or Postal Code */
            regex = bNegate ? /[^0-9-]/ : /[0-9]|-/;
            break;
        default:        /* Only numbers */
            regex = bNegate ? /[^0-9]/ : /[0-9]/;
            break;
    }
    
    return regex;
}

/*
** Function to remove the percent
** from the string.
*/
function RemovePercent(str)
{
    str = str.replace("%", "");
    return LRTrim(str);
}

/*
** Function to round the decimal values.
*/
function GetDecimal(str, dec)
{
    /*
    ** Locals.
    */
    
    var index = 0;
    
    index = str.lastIndexOf('.');
    
    if( -1 != index )
    {
        str = str.substring(0, (index + dec + 1));
    }
    
    return str;
}

/*
** Function to prepare ellipsis string
*/
function PrepareEllipsisString(str, len, bShow)
{
    /*
    ** Locals
    */
    
    if(undefined == bShow)
    {
        bShow = true;
    }
    
    if( null != str && str.length > len)
    {
        str  = str.substring(0, len);
        
        if(bShow)
        {
            str += "..."
        }
    }
    
    return str;
}

function PrepareFullWrappedText(charLen, textToWrapp)
{
	/*
	** Locals.
	*/
	
	var str			= "";
	var temp		= "";
	var bContinue	= true;
	
	charLen         = charLen - 4;
	
	if(textToWrapp.length > charLen)
	{
		while(bContinue)
		{
			str			 = textToWrapp.substring(0, charLen);
			temp        += str + "<br/>";
			textToWrapp	 = textToWrapp.substring(charLen, textToWrapp.length);
			
			/*
			** If the remaning text length is less than given 
			** charater length, then stop the iteration.
			*/
			if(textToWrapp.length == 0)
			{
				bContinue	= false;
			}
		}
	}
	else
	{
		temp = textToWrapp;
	}

	return temp;
}

function PrepareWrappedText(charLen, noOfLines, textToWrapp)
{
	/*
	** Locals.
	*/
	
	var str			= "";
	var temp		= "";
	var bContinue	= true;
	var lineIncr	= 1;
    var dSCharLen   = 3;
    
    charLen         = charLen - 4;
    
    if(textToWrapp.length > charLen)
    {
	    while(bContinue)
	    {
		    temp        += textToWrapp.substring(0, charLen);
		    textToWrapp	 = textToWrapp.substring(charLen, textToWrapp.length)
    		
    		/*
    		** If the remaning text length is less than given 
    		** charater length, then stop the iteration.
    		*/
		    if(textToWrapp.length < charLen)
		    {
			    bContinue = false;
			    
			    /*
			    ** In this condition, if the no.of line
			    ** is reached to the limit, then appending '...'
			    */
			    if(0 != noOfLines && lineIncr == noOfLines)
			    {
			        temp = temp.substring(0, (temp.length)) + "...";
			    }
			    else
			    {
			        temp += "<br/>" + textToWrapp;
			    }
		    }
		    
		    /*
		    ** If the above condition failed then check only for
		    ** the no.of line limit
		    ** 
		    */
		    if( bContinue && 0 != noOfLines && lineIncr == noOfLines)
		    {
			    bContinue = false;
			    temp      = temp.substring(0, (temp.length)) + "...";		    
		    }
		    
		    /*
		    ** If all the above conditions are failed
		    ** then adding the next line.
		    */
		    if(bContinue)
		    {
			    temp += "<br/>"
		    }
		    

		    lineIncr++;
	    }
	}
	else
	{
	    temp = textToWrapp;
	}

	return temp;
}

function PrepareSingleNodeXmlDoc(rootNode, value)
{
    /*
    ** Locals.
    */
    
    var xmlDoc;
    var xmlNode;
    var xml;
    
    try
    {
        xmlDoc  = CreateXmlDocument();
        xmlNode = xmlDoc.createElement(rootNode);
        
        /*
        ** Set the node text.
        */
        SetNodeText(xmlNode, value);
        
        xmlDoc.appendChild(xmlNode);
        
        /*
        ** Get serialized xml document
        */
        xml     = GetDocumentXML(xmlDoc);
    }
    catch(e)
    {
        alert(e);    
    }
    
    return xml;
}

function CheckFormat(input)
{
    try
    {
        var obj = parseFloat(input);
        if(obj != input && 0 != input.length)
        {
            
            $("SPS_ErrMsg_Message").innerHTML = "Please enter correct format.";
            ShowTimeoutControl("SPS_ErrMsg_Bar", 5000);
            
            return false; 
        }
        return true;
        
    }
    catch(ex)
    {
        alert("Enter correct format...");
    }
}

function addZero(input)
{
   if(0 == input.value.indexOf("."))
    {
        input.value = "0"+input.value;
    }
}

function ValidateDecimal(evnt, textVal)
{
    /*
    ** Locals.
    */
    var theEvent;
    var key;
    var regex;
    var bOK;
   
    try 
    {   
        theEvent = evnt ? evnt : window.event;
        key      = window.event ? theEvent.keyCode : theEvent.charCode;
        
        if(46 == key)
        {
            bOK = (-1 == textVal.indexOf("."));
        }
        else
        {
            bOK = (48 <= key && 57 >= key) || 8 == key || 0 == key ;
            
            if(null != evnt) 
            {
                if(evnt.ctrlKey)
                {
                    bOK = (118 == key || 120 == key || 122 == key || 86 == key || 88 == key || 
                            90 == key || 67 == key  || 99  == key);
                }
            }
        }
        if(bOK)
        {
            return true;
        }
        
		Event(theEvent, true);
        return false;
    }   
    catch(except)
    {
		alert("error " + except.message);
        return false;
    }   
}

function ValidateNumeric(evnt)
{
    /* 
    ** Locals.
    */
    var theEvent;
    var key;
    var regex;
    var bOK;
    var arg;

    try 
    {
        theEvent = evnt ? evnt : window.event;
        key      = window.event ? theEvent.keyCode : theEvent.charCode;
        arg      = arguments.length ;
       
        if (arguments[1]) 
        {
            bOK = (48 <= key && 57 >= key) || 8 == key || 0 == key;
            
            if(null != evnt) 
            {
                if(evnt.ctrlKey)
                {
                    bOK = (118 == key || 120 == key || 122 == key || 86 == key || 88 == key || 
                            90 == key || 67 == key  || 99  == key);
                }
            }
        }
        else 
        {
            bOK = ( 48 <= key && 57 >= key ) || 8 == key   || 9 == key  || 35 == key || 
                    36 == key || 37 == key   || 38 == key  || 39 == key || 40 == key || 
                    45 == key || 46 == key   || 0 == key;
            
            if(null != evnt) 
            {
                if(evnt.ctrlKey)
                {
                    bOK = (118 == key || 120 == key || 122 == key || 86 == key || 88 == key || 
                            90 == key || 67 == key  || 99  == key);
                }
            }
        }
        
        if(bOK)
        {
            return true;
        }
        
		Event(theEvent, true);
        return false;
    }
    catch(except)
    {
		alert("error " + except.message);
        return false;
    }

}

/* 
** Function to get the position of an element...
*/
function GetElementPosition(obj)
{
    /* 
    ** Locals.
    */
	var curleft = 0;
	var curtop  = 0;
	
	if (obj.offsetParent)
	{
		do 
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);

	
		return[curleft,curtop];
	}
	return null;
}

function GetFrameDoc(frame)
{
	var doc  = null;

	if(frame.contentWindow)
	{
		doc = frame.contentWindow.document;
	}
	else if(frame.contentDocument)
	{
		doc = frame.contentDocument;
	}

    return doc;
}

function GetFrameHTML(frame)
{
	var doc  = null;
	var html = null;

    doc  = GetFrameDoc(frame);
	html = doc.body.innerHTML;

	return html;
}

function GetFrameText(frame)
{
	var doc  = null;
	var txt  = null;

    doc  = GetFrameDoc(frame);
    
    if(doc.body.innerText)
    {
	    txt  = doc.body.innerText;
	}
	else
	{
	    txt = doc.body.innerHTML;
	    txt = txt.replace(/(<([^>]+)>)/ig,""); 
	}

	return txt;
}

/* 
** Function to get elements width and height
*/
function ObjectClientRect(o)
{
    var rect;
    var pos;

    pos  = ObjectClientPos(o);
    rect = [pos[0],pos[1],0,0];

    rect[2] = rect[0] + o.clientWidth;
    rect[3] = rect[1] + o.clientHeight;

    return rect;
}

function ObjectClientPos(o)
{
    var pos = [o.offsetLeft,o.offsetTop];

    while((o = o.offsetParent) != null)
    {
        pos[0] += o.offsetLeft;
        pos[1] += o.offsetTop;
    }

    return pos;
}

function GetPageFrame()
{
	/*
	** Locals.
	*/
    var frameWidth  = null;
    var frameHeight = null;
    
	if (document.body.clientWidth && document.body.scrollHeight)
	{
		frameWidth	= document.body.clientWidth;
		frameHeight = document.body.scrollHeight > document.body.clientHeight ?
		                document.body.scrollHeight: document.body.clientHeight;
	}
	else if (self.innerWidth)
	{
		frameWidth	= self.innerWidth;
		frameHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		frameWidth	= document.documentElement.clientWidth;
		frameHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{
		frameWidth	= document.body.clientWidth;
		frameHeight = document.body.clientHeight;
	}

	return [frameWidth ,frameHeight];
}

function MaskAnalysisPage(bMask)
{
    /* 
    ** Locals.
    */
    var mask    = $("SPS_ANM");
    var poselem = $("SPS_PAGE_CONTENT");
    
    if(null != mask)
    {
        var anload  = $("SPS_ANM_N");
        
        if(bMask && null != poselem)
        {
            bOK = PositionMask(mask, anload, poselem);
            
            if(bOK)
            {
                mask.style.display  = "block";
                if(null != anload)
                {
                    anload.style.display = "block";
                }
            }
                
        }
        
        if(!bMask)
        {
            mask.style.display  = "none";
            if(null != anload)
            {
                anload.style.display = "none";
            }
        }
    }
}

function PositionMask(mask, anload, poselem)
{
    /* 
    ** Locals. 
    */
    var bOK = false;
    
    if(null != mask && null != poselem)
    {
        var rect = ObjectClientRect(poselem);
        var w, h;
        
        bOK = (null != rect);
        
        if(bOK)
        {
            w                   = rect[2] - rect[0];
            h                   = rect[3] - rect[1];
            
            mask.style.left     = rect[0] + "px";
            mask.style.top      = rect[1] + "px";
            mask.style.width    = w + "px";
            mask.style.height   = h + "px";
            
            if(null != anload)
            {
                anload.style.left    = rect[0] + w/2 - 42 + "px";
                anload.style.top     = rect[1] + h/2 - 10 + "px";
            }
        }
    }
    return bOK;
}

function ResizeAnalysisMask()
{
    /* 
    ** Locals.
    */
    var mask    = $("SPS_ANM");
    
    if(null != mask && "none" != mask.style.display)
    {   
        var poselem = $("SPS_PAGE_CONTENT");
        var anload  = $("SPS_ANM_N");
        
        PositionMask(mask, anload, poselem);
    }
}

function OnSPSIntroLoad()
{
    /* 
	** Locals.
	*/
	var size;
	var h;

	size = GetPageFrame();
	h    = size[1]/2 - 240;

	/*$("SPS_Intro_Embed").style.marginTop = h + "px";*/
}

function AlertHttpStatus(status)
{
    /*
    ** Locals.
    */
    
    var msg;
    
    switch(status)
    {
        case 408:
            msg = "408: Request Timeout.";
        break;
        
        case 404:
            msg = "404: Not Found.";
        break;        
        
        case 500:
            msg = "500: Internal Server Error.";
        break;
        
        case 502:
            msg = "502 : Bad Gateway.";
        break;
        
        /*default:
            msg = "Other HTTP status error [Status : " + status + "].";*/
    }
    
    if(status)
    {
        alert(msg);
    }
}

function DoInputUnCheck(doUnCheckId)
{
    /*
    ** Locals.
    */
    var obj;
    
    obj = $(doUnCheckId);
    
    if( null != obj )
    {
        obj.checked = false;
    }
}

function DisplayLoadingImage(loaddivId, bShow) 
{
    /* 
    ** Locals
    */
    var loaddiv = null;

    loaddiv = $(loaddivId);
    loaddiv.style.display = bShow ? "block" : "none";
}

function ClearForgotPasswordValues()
{
    $('SPS_User_Name').value                = "";
    $('SPS_User_Email').value               = "";  
    $('SPS_User_SectionMessage').innerHTML  = "";
}


function CreateForgotPasswordDialog()
{    
    var htmlEle     = null;
    ClearForgotPasswordValues();    
    
    htmlEle       = $('SPS_Username');
    $('SPS_User_Name').value = htmlEle.value;
    /* 
    ** Show the forgot password window
    */
    ShowWnd(400, 130, 'Forgot Password', 'SPS_ForgotPassword', null);
    if(""!=htmlEle.value)
    {
        $("SPS_User_Email").focus();
    }
    else
    {
        $("SPS_User_Name").focus();
    }
}

function OnForgotPasswordCancel()
{
    ClearForgotPasswordValues(); 
    WndClose();
}

function OnValidateForgotPassword()
{
    var name  = null;
    var email = null;
    
    name    = Trim($('SPS_User_Name').value);
    email   = Trim($('SPS_User_Email').value);
    
    if( null != name && 0 == name.length)
    {
        $('SPS_User_SectionMessage').innerHTML = "User name should not be empty.";
    }
    else if(null != email && 0 == email.length)
    {
        $('SPS_User_SectionMessage').innerHTML = "User email should not be empty.";
    }
    else
    {
        //WndClose(); 
        
        ClearForgotPasswordValues(); 
        
        try
        {
            /* 
            ** Format and send the ajax request to validate send email.
            */
            reqUrl  = "./Home.aspx?METHOD=ValidateForgotPassword";
            reqUrl  += "&Name="     + encodeURIComponent(name);
            reqUrl  += "&Email="    + encodeURIComponent(email);           
            reqUrl  += "&kval="     + Math.random() + "&dval=" + new Date().getTime();
            
            ajaxReq  = new AjaxRequest(reqUrl, OnValidateForgotPasswordCB, true, true);
            ajaxReq.Send();
            
            bOK      = true;
        }
        catch(e)
        {
            alert(e);
        }
    }   
}

function OnValidateForgotPasswordCB(resXml, resStatus)
{
     /*
    ** Locals.
    */
    var resNode     = null;
    var result      = null;
    
    if (200 == resStatus && null != resXml)
    {
        /*
        ** Get the 'sps-result' node.
        */
        resNode = resXml.getElementsByTagName(NODE_RESULT);
        
        if( null != resNode && resNode.length > 0)
        {
            result = resNode[0].getAttribute(ATTR_PAGE);
            
            if( null == result )
            {
                /*
                ** Check for success message
                */
                result      = resNode[0].getAttribute(ATTR_SUCCESS);
                if( null == result)
                {
                    $("SPS_User_SectionMessage").innerHTML = resNode[0].getAttribute(ATTR_ERROR);     
                    $("SPS_User_Name").focus();               
                }
                else
                {
                   WndClose(); 
                }
            }
        }
        else
        {
            document.location = result;
        }
    }
    else
    {
        AlertHttpStatus(resStatus);
    }    
}

function OnCreateKeyPress(e, saveCallback, cancelCallback)
{
    /*
    ** Locals.
    */
    var keycode;

    keycode = e.keyCode || e.which;
    
    if (13 == keycode) 
    {
        if( null != saveCallback )
        {
            saveCallback();
            return false;
        }
    }
    else if( 27 == e.keyCode )
    {
        cancelCallback();
        return false;
    }
    
    return true;
}

function DoCleanupImage(url)
{
    setTimeout(function () { DoCleanupImageReq(url); }, 60000)
}

function DoCleanupImageReq(url)
{
    /*
    ** Locals.
    */
    var ajaxReq = null;
    var postUrl = null;
    var reqUrl  = null;
    var bOK     = false;

    try 
    {
        /* 
        ** Format and send the ajax request to save new project
        */
        postUrl          = "./CommonAjaxHandler.aspx?METHOD=CleanupImage";

        reqUrl           = "ImageURL=" + url;
        reqUrl          += "&kval=" + Math.random() + "&dval=" + new Date().getTime();

        ajaxReq         = new AjaxRequest(postUrl, OnDoCleanupImageCB, true, false);
        ajaxReq.headers = ["Content-Type", "application/x-www-form-urlencoded"];
        ajaxReq.Send(reqUrl);

        bOK = true;
    }
    catch (e) 
    {
        bOK = false;
    }

    return bOK;
}


function OnDoCleanupImageCB(resXML, resStatus)
{
    var test = "";
}


