// additional functions for SiteCatalyst
var isPaging = false;

/* This functions captures weather the userID of the logged in user for the cookie. */
function sc_getUserId()
{
	var userID = '';
	var strCookie = '';
	var arrCookies = document.cookie.split('; ');
	for (var i=0; i < arrCookies.length; i++)
	{
		strCookie = arrCookies[i];
		
		if (strCookie.substring(0, 19) == 'QuestSupportCookie=')
		{
			var strSupportCookie = strCookie.substring(19, strCookie.length);
			var arrCookieDetails = strSupportCookie.split('&');
			for (var j=0; j < arrCookieDetails.length; j++)
			{
				if (arrCookieDetails[j].substring(0, 3) == 'un=')
				{
					userID = arrCookieDetails[j].substring(3, arrCookieDetails[j].length);
					userID = decodeURIComponent(userID);
					if ( userID != null )
					    return userID.toLowerCase();
				}
			}
		}
	}
	
	return userID;
}

/* This function captures the product search keyword entered in Documentation and Downloads & updates pages.
   This function captures the search keyword from the url param.
*/
function sc_getSearchKeyWord()
{        
        var parameters = window.location.search.substring(1).split('&');
        var selProd = "";
        var selPage = "";   
        var selPrefix = "";
        var selUiMode = "";       
	for (var i=0; i<parameters.length; i++) 
	{
                var pos = parameters[i].indexOf('=');
                // If there is an equal sign, separate the parameter into the name and value                
                if (pos > 0) {
                        var paramname = parameters[i].substring(0,pos);
                        var paramval = parameters[i].substring(pos+1);
                        if (paramname == "question_product")
                        {
                            selProd = unescape(paramval.replace(/\+/g,' '));
                        }
                        if ( paramname == "page" )
                        {
                            selPage = unescape(paramval.replace(/\+/g,' '));
                            if (selPage == 'documentation' )
                            {
                                selPrefix = 'DOC:'
                            }
                            else if ( selPage == 'downloads' )
                            {
                                selPrefix = 'DOW:'
                            }
                            else if ( selPage == 'productInformation' )
                            {
                                selPrefix = 'PR:'
                            }
                        }
                        if ( paramname == "ui_mode" || paramname == "offset")
                        {
                              selUiMode = unescape(paramval.replace(/\+/g,' '));
                              if (selUiMode != null && ( selUiMode == "paging" || selUiMode.length > 0 ) )
                              {
                                    isPaging = true;
                              }                        
                        }                        
                 } 
                 else 
                 {
                        // do nothing 
                 }
        }
        if ( selProd != null && selProd.length > 0 && !isPaging)
        {            
            var retVal = selPrefix+ decodeURIComponent(selProd);
            return s.getValOnce(retVal,selPage,0); 
        }
        
        return "";
 }
 
 /* This function captures the search knowledgebase search key words entered.
    This function captures the search keyword from the Form variables if the Form name 'frmConfig' is present.
 */
 function sc_getSearchKBKeyWord()
 {
        var fulSearchDetails = "KB:";
        var isSearch = true;   
        var search = "kbsearch";
        if (document != null && document.frmConfig != null && !isPaging )
        {
            if ( document.frmConfig.tb != null && typeof(document.frmConfig.tb.value)!="undefined" && document.frmConfig.tb.value.length > 0 )
            {
                fulSearchDetails = fulSearchDetails + document.frmConfig.tb.value;
            
            }
            else
            {
                isSearch = false;
            
            }
            if ( document.frmConfig.question_box != null && typeof( document.frmConfig.question_box.value )!="undefined" && document.frmConfig.question_box.value.length > 0 )
	    {
	        fulSearchDetails = fulSearchDetails + ":Q:"+ document.frmConfig.question_box.value;
	        isSearch = true;	                
            }
            else
            {
                fulSearchDetails = fulSearchDetails + ":Q:"
            }
            
            if ( document.frmConfig.question_source != null && typeof( document.frmConfig.question_source )!="undefined" )
	    {
	    
	         for (i = 0; i < document.frmConfig.question_source.length; i++)
	         {
	             if (document.frmConfig.question_source[i].checked)
	             {
	                   fulSearchDetails = fulSearchDetails + ":S:"+ document.frmConfig.question_source[i].value;
	             }
	         }  	                
            }       
            else
            {
                  fulSearchDetails = fulSearchDetails + ":S:"
            }
        
        }
        else if (document != null && document.question_form != null && !isPaging )
        {         
        
            if ( document.question_form.question_box != null && typeof( document.question_form.question_box.value )!="undefined" && document.question_form.question_box.value.length > 0 )
	    {
	  	 fulSearchDetails = "INT:"+ document.question_form.question_box.value;
	  	 search = 'cca';
	  	 isSearch = true;	                
            }
            else
            {
                 fulSearchDetails = "";
                 isSearch = false;
            }
        }
        else
        {
                isSearch = false;
        }
        
        if ( isSearch )
        {
            return s.getValOnce(fulSearchDetails,search,0);        
        }
        else
        {
            return "";        
        }
 
 
 }
	