﻿if ( typeof(Page_IsValid) != "undefined" )
    Page_IsValid = false;

function NextPage() {

    //check if there was ajax postback on a page
    /*
    var flg_AJAXPostback = document.getElementById("AJAXPostback");
    if (flg_AJAXPostback != null)
    {
        if (flg_AJAXPostback.value == "1")
        {
            document.getElementById("AJAXPostback").value = 0;
            //get page validators ids and rebuild Page_Validators as it's broken after ajax postback
            if (document.getElementById("PageValidatorsIDs") != null) 
            {
                var str_ValidatorsIDs = document.getElementById("PageValidatorsIDs").value.split(",");
                if (str_ValidatorsIDs.length != 0)
                {
                    Page_Validators = new Array(str_ValidatorsIDs.length);
                    for (int_ValidatorIndex = 0; int_ValidatorIndex < str_ValidatorsIDs.length; int_ValidatorIndex++)
                    {
                        Page_Validators[int_ValidatorIndex] = document.getElementById(str_ValidatorsIDs[int_ValidatorIndex]);
                    }
                }
            }
        }
    }

    var ctl_PostcodeText = document.getElementById("ctl_Postcode$txt_Postcode");
    if ( ctl_PostcodeText == null ) 
    {
	ctl_PostcodeText = document.getElementById("ctl_Postcode_txt_Postcode")       
    }

    var ctl_PostcodeResults = document.getElementById("ctl_Postcode$ltb_PostcodeResults");
    if ( ctl_PostcodeResults == null ) 
    {
	ctl_PostcodeResults = document.getElementById("ctl_Postcode_ltb_PostcodeResults")       
    }

    
    if (ctl_PostcodeText != null)
    {

        if (ctl_PostcodeResults == null)
        {
            //return false;
        }
        else
        {
            if (ctl_PostcodeResults.selectedIndex == -1)
            {
                //return false;
            }    
        }
    }
    */
    //debugger;
    
    if ( typeof(Page_ClientValidate) == "function" )
        Page_ClientValidate();
    
    if ( typeof(Page_IsValid) == "undefined" )
    {
    	if ( document.FrmQuestion.PageIndex.value != document.FrmQuestion.PageNumber.value )
        {
            document.FrmQuestion.PageIndex.value = document.FrmQuestion.PageNumber.value;
        }
        document.FrmQuestion.MoveDirection.value = 1;
        document.FrmQuestion.PageIndex.value = parseInt(document.FrmQuestion.PageIndex.value) + 1;
        if (document.FrmQuestion.action.indexOf("&Track=") > 0) {
            document.FrmQuestion.action = document.FrmQuestion.action.replace(new RegExp("&Track=[0-9]{1,2}", "i"), "&Track=" + document.FrmQuestion.PageIndex.value)
        }
        else {
            document.FrmQuestion.action = document.FrmQuestion.action + '&Track=' + document.FrmQuestion.PageIndex.value;
        }
	    document.FrmQuestion.submit();
	    return true;	    
    }
    else
    {
        if ( Page_IsValid == true )	
        {
            if ( document.FrmQuestion.PageIndex.value != document.FrmQuestion.PageNumber.value )
            {
	            document.FrmQuestion.PageIndex.value = document.FrmQuestion.PageNumber.value;
	        }
	        document.FrmQuestion.MoveDirection.value = 1;
	        document.FrmQuestion.PageIndex.value = parseInt(document.FrmQuestion.PageIndex.value) + 1;
	        if (document.FrmQuestion.action.indexOf("&Track=") > 0) {
	            document.FrmQuestion.action = document.FrmQuestion.action.replace(new RegExp("&Track=[0-9]{1,2}", "i"), "&Track=" + document.FrmQuestion.PageIndex.value)
	        }
	        else {
	            document.FrmQuestion.action = document.FrmQuestion.action + '&Track=' + document.FrmQuestion.PageIndex.value;
	        }
	        document.FrmQuestion.submit();
	        return true;
    	}
    	else
    	{
    	    //Page_BlockSubmit = false;
    	    return false;
    	}
    }
}

function PrevPage()
{
    if ( Page_IsValid == true ) {
        document.FrmQuestion.MoveDirection.value = -1;
        document.FrmQuestion.PageIndex.value = parseInt(document.FrmQuestion.PageIndex.value) - 1;
	    document.FrmQuestion.submit();
	    return true;
	}
	else
	{
	    return false;
	}
}

function NavigateRedirect(str_RedirectURL, flg_NewWindow) 
{
    if (flg_NewWindow) {
        window.open(str_RedirectURL, "blank", "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
    }
    else {
        window.location = str_RedirectURL;
    }
}

function NavigateRedirect(str_RedirectURL, flg_NewWindow) 
{
    if (flg_NewWindow) {
        window.open(str_RedirectURL, "blank", "location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,height=400,width=600");
    }
    else {
        window.location = str_RedirectURL;
    }
}
