﻿//Pagination functions

var aryAdFrame = new Array();

function qs() 
{
    var query = window.location.search.substring(1);
    var parms = query.split('&');
    for (var i=0; i<parms.length; i++) 
    {
        var pos = parms[i].indexOf('=');
        if (pos > 0) 
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
} 

function hideshow(which)
{
    if (!document.getElementById)
        return;
    
    if (!which)
        return;
        
    if (which.style.display=="block")
        which.style.display="none";
    else
        which.style.display="block";
}

function hidequestion(which)
{
    if (!document.getElementById)
        return;
    
    if (!which)
        return;
        
    which.style.display="none";
}

function hideallquestions()
{
    for (var i = 0; i < arrFAQs.length; i++)
    {
        hidequestion(document.getElementById('tw_question' + arrFAQs[i]));
    }
}

function showquestion(which)
{
    if (!document.getElementById)
        return;
    
    if (!which)
        return;
        
    which.style.display="block";
}

function gotoPage(frompage, topage)
{
    hideshow(document.getElementById(frompage));
    var re = /tw_page/;
    var ipage = topage.replace(re, '');
    logUserSitePageAccess(ipage);
    window.scrollBy(0,-200);
    hideshow(document.getElementById(topage));
}

var qsParm = new Array();

function loadpage()
{
    var iPage = '1';
    qsParm['page'] = null;
    qs(); 

    if (qsParm['page'])
    {
        if (!document.getElementById('tw_page' + qsParm['page']))
        {
            iPage = '1';
        }
        else
        {
            iPage = qsParm['page'];
        }
    }
    else
    {
        iPage = '1';
    }
        
    hideshow(document.getElementById('tw_page' + iPage));
}

function gotoqaPage(topage)
{
    var re = /tw_question/;
    var iNumerial = topage.replace(re, '');
    var iID = arrFAQs[iNumerial];
    
    hideallquestions();
    
    showquestion(document.getElementById('tw_question' + iID));
}

function gotoqaidPage(iID)
{
    hideallquestions();
    
    showquestion(document.getElementById('tw_question' + iID));
}

function logUserSitePageAccess(iPage)
{
	if(document.getElementById)
	{
   	    var el = parent.document.getElementById('frameUserSitePageAccess');

        if (el)
        {
            var ahref = el.src;
            var iIdx = ahref.indexOf('&pn=');
            if (iIdx > -1)
            {
                ahref = ahref.substring(0, iIdx);
            }
            ahref = ahref + '&pn=' + iPage;

            if (el.src != ahref)
            {
    	        el.src = ahref;
        	}
        }
        
        var iMax = aryAdFrame.length;
        var x = 0;
        for (x = 0; x < iMax; x++)
        {
   	        var el = parent.document.getElementById(aryAdFrame[x]);

            if (el)
            {
                var ahref = el.src;
                var iIdx = ahref.indexOf('&pn=');
                if (iIdx > -1)
                {
                    ahref = ahref.substring(0, iIdx);
                }
                ahref = ahref + '&pn=' + iPage;

                if (el.src != ahref)
                {
    	            el.src = ahref;
        	    }
            }        
        }
    }

}

function printpage()
{
    window.print();
}


