//  Documentation
//  28 May 2009 Mithu Mary         Bug 20787 - Inclusion/Exclusion of VAT toggle[Release 2]
//  03 Jun 2009 Mithu Mary         Bug 20787 - Modified to get index position of Vat toggle status from url
//  05 Jun 2009 Priya Menon        Bug 20787 - Modified to handle the URL in shoppingBasket page

/* --- BROWSER DETECTION --- */

var browserName = '';
var browserVersion = '';
var browserJavascript = '1.0';
var browserDHTML = '0';
var gnumMSIEVersion;
var currentSelectedTab = '';

if (navigator) {
	if (navigator.userAgent) {
		if (navigator.userAgent != null) {
			if (navigator.userAgent.toUpperCase().indexOf('OPERA') != -1) {
				browserName = 'OP';
			}
			else if (navigator.userAgent.toUpperCase().indexOf('SAFARI') != -1) 
				{
				browserName = 'SA';
				}
			
		}
	}
	if (browserName == '' && navigator.appName) {
		if (navigator.appName=='Microsoft Internet Explorer') {
			browserName='IE';
			gnumMSIEVersion = parseFloat(navigator.userAgent.substr(navigator.userAgent.toLowerCase().indexOf("msie") + 5,3));
		} else if (navigator.appName=='Netscape') {
			browserName='NN';
		}
	}
	if (navigator.appVersion) {
		browserVersion = navigator.appVersion.substring(0,3);
	}
}

if (browserName=='IE' && browserVersion=='4.0')
	browserDHTML = '1.0';


/* --- TABS --- */

function tabSelect(tabId, divId)
{
	// ******************************* DO NOT REMOVE ****************************************
	// Add the tab selection to the webabacus arrays so that they get posted back to the
	// server. 
	
	var tabCaption = "";
	if ($get(tabId).childNodes.length >= 1)
	{
		tabCaption = $get(tabId).childNodes[0].innerHTML;
	}
	else
	{
		tabCaption = tabId;
	}
	
	wacustomvarnames[wacustomvarnames.length] = 'eventtype';
	wacustomvarvalues[wacustomvarvalues.length] = 'tabChange';
	wacustomvarnames[wacustomvarnames.length] = 'event';
	wacustomvarvalues[wacustomvarvalues.length] = tabCaption;
	logclientdata('');
	wacustomvarnames=[];
	wacustomvarvalues=[];
	
	//*************************************************************************************** 

	var printerFriendly = (getQueryStringValue("printer") == 1);
	
	// Stop anything happening when in the printer friendly page version
	if (printerFriendly)
	{
		return;
	}
	
	$get('inpSelectedTabId').value = tabId;
	$get('inpSelectedTabBodyId').value = divId;

	if ($get('iframeCustomerReviews'))
	{
		if (tabId == 'tabCustomerReviews')
		{			
			showCustomerReviewsTab();
		}
		else 
		{
			//Hide any displayed messages
			$get('divCustomerReviewsPleaseWait').style.display = 'none';
			$get('divCustomerReviewsPleaseWaitLink').style.display = 'none';
			
			//Clear any timeouts set on Customer Reviews tab
			clearCustomerReviewsTimeouts();
		}
	}

	// When selecting the pricing tab show a please wait message if the recommendations are still loading
	if (tabId == 'tabPricing' && 
		$get('divRecommendationsContent') != null &&
		$get('divRecommendationsContent').innerHTML == '' &&
		Sys.UI.DomElement.containsCssClass($get('divRecommendationsContent'), 'hide') &&
		Sys.UI.DomElement.containsCssClass($get('divRecommendationsAJAXProblem'), 'hide') &&
		$get('divRecommendationsTimeout') == null)
	{
		displayRetrievingMessage();
	}
	    
    var headerNodesLevel = 0;
    var tabCount = 0;$get('tabHeaders').childNodes[headerNodesLevel].childNodes.length;
    
    if ($get('tabHeaders').childNodes[headerNodesLevel].nodeType != 1 && $get('tabHeaders').childNodes.length >= headerNodesLevel)
    {
        // for browsers which treat whitespaces as Text ChildNode in ChildNodes collection, e.g. Firefox
        headerNodesLevel++;
        tabCount = $get('tabHeaders').childNodes[headerNodesLevel].childNodes.length;
    }
    else
    {
        tabCount = $get('tabHeaders').childNodes[headerNodesLevel].childNodes.length;
    }
        
    var tabBodyCount = $get('tabBodies').childNodes.length;

    for(i = 0; i < tabCount; i++)
    {
        $get('tabHeaders').childNodes[headerNodesLevel].childNodes[i].className = '';
        if($get('tabHeaders').childNodes[headerNodesLevel].childNodes[i].id == tabId)
            $get('tabHeaders').childNodes[headerNodesLevel].childNodes[i].className = 'active_tab';
    }

    for(i = 0; i < tabBodyCount; i++)
    {
        if($get('tabBodies').childNodes[i].nodeType == 1)
        {
            $get('tabBodies').childNodes[i].style.display = 'none';
            if($get('tabBodies').childNodes[i].id == divId)
                $get('tabBodies').childNodes[i].style.display = 'block';
        }
    }  
    currentSelectedTab = tabCaption; 
}

/* --- CALLS TO ACTION --- */

function watchVideo(pstrCREF, plngHeight, plngWidth, pstrMediaPlayer, pstrQuality)
{
	var strURL = 'Content/StreamingMedia.asp?cref=' + pstrCREF + '&quality=' + pstrQuality + '&player=' + pstrMediaPlayer;
	window.open(strURL, 'winViewVideo', 'width=' + (plngWidth+300) + ',height=' + (plngHeight+130));
}

function takeTour(pstrCREF, plngHeight, plngWidth)
{
	var strURL = '/Download/DownloadSWF.asp?cref=' + pstrCREF;
	window.open(strURL, 'winTakeTour', 'width=' + plngWidth + ',height=' + plngHeight);
}


/* --- CUSTOMER REVIEWS --- */

var mnumCustomerReviewsPleaseWaitDotsTimeout;
var mnumLinkToCustomerReviewsTabTimeout;

var mstrCustomerReviewsOneLineSummaryDefaultText = '(e.g. \'I found this ideal for whole-class teaching\')';
var mstrOffStarSRC = '/_RMVirtual/images/customer_rating_off.gif';
var mstrEmptyStarSRC = '/_RMVirtual/images/customer_rating_empty.gif';
var mstrFilledStarSRC = '/_RMVirtual/images/customer_rating_full.gif';

function showCustomerReviewsTab() {
	if (document.forms[0].elements['inpIFrameLoaded'].value.length != 0)
	{
		if (browserName == 'SA') 
		{
			//Just resize when in Safari browser as oIframeDocument
			//is empty until tab actually displayed
			setTimeout('resizeCustomerReviewsIFrame(false, true);',1);
		} 
		else 
		{
			oIframeDocument = getCustomerReviewsIFrameDocument();
			if (oIframeDocument.body && oIframeDocument.body.innerHTML.replace(/^\s*|\s*$/g,'') != '')
			{
				//IFrame has contents other than for 'about:blank' document.
				//Force resize of IFrame based on current contents
				resizeCustomerReviewsIFrame(false, true);
			} 
			else 
			{
				//The contents of the IFrame were loaded previously
				//but have been 'lost'. This can happen when the back button is used.
				//Best option is to reload from server.
				navigateDirectToCustomerReviews();
			}
		}
	} 
	else 
	{
		//Initialise IFrame
		initialiseCustomerReviewsIFrame();
		
		//Display please wait message as IFrame
		//contents have not yet loaded
		displayCustomerReviewsPleaseWaitMessage();
	}
}

function initialiseCustomerReviewsIFrame() {
	var bDisplayWriteAReview = false;
	var bLoginForced = false;

	if (document.forms[0].elements['inpIFrameLoaded'].value.length == 0) {
		if (window.location.search.toLowerCase().indexOf('writeareview=visible') != -1) {
			bDisplayWriteAReview = true;
		}
		if (window.location.search.toLowerCase().indexOf('loginforced=true') != -1) {
			bLoginForced = true;
		}
		setCustomerReviewsIFrameSRC(bDisplayWriteAReview, bLoginForced);
	}
}

function setCustomerReviewsIFrameSRC(pbDisplayWriteAReview, pbLoginForced) {
	var strWriteAReviewVisibility = '';
	var strLoginForced = '';
	var dtDate = new Date();
	if (pbDisplayWriteAReview == true) {
		strWriteAReviewVisibility = '&writeareview=visible';
	}
	if (pbLoginForced == true) {
		strLoginForced = '&loginforced=true';
	}
	
	strContentRef = document.forms[0].elements['inpContentRef'].value;
	$get('iframeCustomerReviews').src = '/Products/CustomerProductReviews.asp?cref=' + strContentRef + strWriteAReviewVisibility + '&time=' + dtDate.getTime().toString() + strLoginForced;
}

function selectCustomerReviewsTab(pbDisplayWriteAReview) {
	var oIframeDocument;
	var bWriteAReviewVisible = false;
	
	tabSelect('tabCustomerReviews', 'divCustomerReviews');
	
	//Get IFrame contents after loading tab else will be empty in Safari browser
	oIframeDocument = getCustomerReviewsIFrameDocument();
	if (oIframeDocument.URL.toLowerCase().indexOf('writeareview=visible') != -1) {
		bWriteAReviewVisible = true;
	}
	if (pbDisplayWriteAReview == true && bWriteAReviewVisible == false) {
		setCustomerReviewsIFrameSRC(true);
	} else if (pbDisplayWriteAReview == false && bWriteAReviewVisible == true) {
		setCustomerReviewsIFrameSRC(false);
	}
}

function resizeCustomerReviewsIFrame(pbIFrameLoaded, pbCustomerReviewsTabVisible) {
	var oIframeDocument = getCustomerReviewsIFrameDocument();
	var bCustomerReviewsTabVisible;
	var bSetTimeout = false;
	var numHeight;
	
	if (pbCustomerReviewsTabVisible == null) {
		bCustomerReviewsTabVisible = $get('divCustomerReviews').style.display != 'none' ? true : false;
	} else {
		bCustomerReviewsTabVisible = pbCustomerReviewsTabVisible;
	}
	
	if (oIframeDocument.body && oIframeDocument.body.innerHTML.replace(/^\s*|\s*$/g,'') != '') {
		//IFrame has contents other than for 'about:blank' document
		clearCustomerReviewsTimeouts();
		$get('divCustomerReviewsPleaseWait').style.display = 'none';
		$get('divCustomerReviewsPleaseWaitLink').style.display = 'none';
		if (bCustomerReviewsTabVisible) {
			if (pbIFrameLoaded && browserName != 'IE') {
				//Reset height to 0 since some browsers e.g. Opera/Firefox retain the previous
				//pages scrollHeight value unless the IFrame is collapsed
				$get('iframeCustomerReviews').height = 0;
				//The IFrame height needs to be reset
				setTimeout('resizeCustomerReviewsIFrame(false, true)', 1);
			} else {
				numHeight = oIframeDocument.body.scrollHeight + 0;
				if ($get('iframeCustomerReviews').height != numHeight || $get('iframeCustomerReviews').height == 0) {
					if ($get('iframeCustomerReviews').height && numHeight == 0) {
						//Set height to 1 to get the ball rolling since some browsers e.g. Opera dont
						//adjust scrollHeight until the IFrame height is greater than zero 
						//and part of it's contents are displayed.
						numHeight = 1;
					} else if (browserName == 'NN') {
						//Add on 12 for Firefox to get correct gap at bottom
						numHeight = numHeight + 12;
					}
					//The IFrame height needs to be reset as i) it doesnt 
					//match the current scroll height of it's contents
					//or ii) has not yet been initialised and has zero height.
					//document.forms['frmCustomerReviewsHTML'].elements['inpIFrameLoaded'].value = 'true';
					document.forms[0].elements['inpIFrameLoaded'].value = 'true';
					$get('iframeCustomerReviews').height = numHeight;
					//Set timeout to attempt to resize IFrame again 
					//as IFrame contents scrollHeight value may not yet reflect full height 
					//of document at this point. This can occur
					//when css styling of elements is still occuring
					//after the IFrame has fired its onload event.
					setTimeout('resizeCustomerReviewsIFrame(false, true)', 1);
				}
			}
		} else if (pbIFrameLoaded) {
			//Reset flags to indicate IFrame has loaded
			//but at this point don't try to reset height
			//as IFrame is not visible to user and so contents scrollHeight value
			//will be zero thus preventing dynamic resizing
			//document.forms['frmCustomerReviewsHTML'].elements['inpIFrameLoaded'].value = 'true';
			document.forms[0].elements['inpIFrameLoaded'].value = 'true';
		}
	}
}

function showAllReviewsInPrintableVersion() {
	$get('hrefShowAllReviews').style.display = 'none';
	$get('hrefHideAllReviews').style.display = 'block';
	$get('divCustomerProductReviews').style.display = 'block';
}

function hideAllReviewsInPrintableVersion() {
	$get('hrefShowAllReviews').style.display = 'block';
	$get('hrefHideAllReviews').style.display = 'none';
	$get('divCustomerProductReviews').style.display = 'none';
}

function setCustomerReviewsPleaseWaitDots() {

	//Update dots in screen to indicate progress
	var strPriceUpdatingDots = $get('spanCustomerReviewsPleaseWait').innerHTML;
	if (strPriceUpdatingDots.length == 10) {
		$get('spanCustomerReviewsPleaseWait').innerHTML = '';
	} else {
		$get('spanCustomerReviewsPleaseWait').innerHTML = strPriceUpdatingDots + '.';
	}
	mnumCustomerReviewsPleaseWaitDotsTimeout = setTimeout('setCustomerReviewsPleaseWaitDots()', 500);
}

function displayCustomerReviewsPleaseWaitMessage() {
	$get('divCustomerReviewsPleaseWaitLink').style.display = 'none';
	$get('divCustomerReviewsPleaseWait').style.display = 'block';
	setCustomerReviewsPleaseWaitDots();
	if (mnumLinkToCustomerReviewsTabTimeout == null) {
		mnumLinkToCustomerReviewsTabTimeout = setTimeout('displayLinkToCustomerReviewsTab()', 10000);
	}
}

function displayLinkToCustomerReviewsTab() {
	clearCustomerReviewsTimeouts();
	$get('divCustomerReviewsPleaseWait').style.display = 'none';
	$get('divCustomerReviewsPleaseWaitLink').style.display = 'block';
}

function clearCustomerReviewsTimeouts() {
	clearTimeout(mnumLinkToCustomerReviewsTabTimeout);
	mnumLinkToCustomerReviewsTabTimeout = null;
	clearTimeout(mnumCustomerReviewsPleaseWaitDotsTimeout);
	mnumCustomerReviewsPleaseWaitDotsTimeout = null;
}

function getCustomerReviewsIFrameDocument() {
	if ($get('iframeCustomerReviews').contentDocument) { // firefox
		return $get('iframeCustomerReviews').contentDocument;
	} else { // IE
		return document.frames('iframeCustomerReviews').document;
	}
}

function navigateDirectToCustomerReviews() {
	//Clear any timeouts
	clearCustomerReviewsTimeouts();
	//Reset parameters that indicate IFrame has previously been loaded
	document.forms[0].elements['inpIFrameLoaded'].value = '';
	//Display please wait message
	displayCustomerReviewsPleaseWaitMessage();
	//Re-initialise IFrame
	initialiseCustomerReviewsIFrame();
}

function loadIFrameCustomerReviews() {
	var oIframeDocument = getCustomerReviewsIFrameDocument();
	var strProductRating;
	var strOneLineSummary;
	var numProductRating;
	if (oIframeDocument.body && oIframeDocument.body.innerHTML.replace(/^\s*|\s*$/g,'') != '') {	
		//IFrame has contents other than for 'about:blank' document
		if (oIframeDocument.frmWriteAReview) {
			if (oIframeDocument.frmWriteAReview.elements['inpPageLoaded'].value != '') {
				strProductRating = oIframeDocument.frmWriteAReview.elements['inpProductRating'].value;
				if (strProductRating.length > 0) {
					numProductRating = Number(strProductRating);
					setProductRating(oIframeDocument, numProductRating);
				}
				strOneLineSummary = oIframeDocument.frmWriteAReview.elements['inpOneLineSummary'].value;
				if (strOneLineSummary.length > 0 && strOneLineSummary != mstrCustomerReviewsOneLineSummaryDefaultText) {
					oIframeDocument.getElementById('enterreviewtitle').style.color = '#093';
					oIframeDocument.getElementById('enterreviewtitle').style.fontWeight = 'bold';
				}
			} else {

				oIframeDocument.frmWriteAReview.elements['inpPageLoaded'].value = 'True';
			}
		}
	}
	resizeCustomerReviewsIFrame(true);
}


function setProductRating(poIframeDocument,pnumProductRating) {
	setProductRatingText(poIframeDocument, pnumProductRating);
	setProductRatingImageSRC(poIframeDocument, pnumProductRating, 1);
	setProductRatingImageSRC(poIframeDocument, pnumProductRating, 2);
	setProductRatingImageSRC(poIframeDocument, pnumProductRating, 3);
	setProductRatingImageSRC(poIframeDocument, pnumProductRating, 4);
	setProductRatingImageSRC(poIframeDocument, pnumProductRating, 5);
	poIframeDocument.frmWriteAReview.elements['inpProductRating'].value = pnumProductRating;
}

function setProductRatingImageSRC(poIframeDocument, pnumProductRating, pnumImageNumber) {
	if (pnumProductRating == 0) {
		poIframeDocument.getElementById('imgProductRating' + pnumImageNumber).src = mstrOffStarSRC;
	} else if (pnumProductRating >= pnumImageNumber) {
		poIframeDocument.getElementById('imgProductRating' + pnumImageNumber).src = mstrFilledStarSRC;
	} else {
		poIframeDocument.getElementById('imgProductRating' + pnumImageNumber).src = mstrEmptyStarSRC;
	}
}

function setProductRatingText(poIframeDocument, pnumProductRating) {
	var strText = '';
	if (pnumProductRating == 1) {
		strText = 'I hate it';
	} else if (pnumProductRating == 2) {
		strText = 'I don\'t like it';
	} else if (pnumProductRating == 3) {
		strText = 'It\'s OK';
	} else if (pnumProductRating == 4) {
		strText = 'I like it';
	} else if (pnumProductRating == 5) {
		strText = 'I love it';
	} else {
		strText = 'Click the relevant star to rate this product';
	}
	poIframeDocument.getElementById('divProductRatingText').innerHTML = strText;
}


/* --- RECOMMENDATIONS --- */

var mnumSetPriceUpdatingDotsTimeout;

function ConfigureIT(pstrContentRef, plngSystemTypeID, plngRangeTypeID, pstrNavigationRange)
{
	displayLoadingMessage();
	
	$get('ContentRef').value=pstrContentRef;
	$get('SystemTypeID').value=plngSystemTypeID;
	$get('RangeTypeID').value=plngRangeTypeID;
	$get('NavigationRange').value=pstrNavigationRange;
	
	ConfigureItPostBack(false);
}

function AddRecommendationToBasket(pstrContentRef, plngSystemTypeID, plngRangeTypeID, pstrNavigationRange)
{
	displayLoadingMessage();
	
	$get('ContentRef').value=pstrContentRef;
	$get('SystemTypeID').value=plngSystemTypeID;
	$get('RangeTypeID').value=plngRangeTypeID;
	$get('NavigationRange').value=pstrNavigationRange;
	
	ConfigureItPostBack(true);
}

function displayLoadingMessage() {

	ShowBlanker();
	
	Sys.UI.DomElement.removeCssClass($get('divPleaseWait'), 'hide');
	Sys.UI.DomElement.addCssClass($get('divPleaseWait'), 'loadconfiguration');
	
	if ($get('spanPleaseWaitRetrieveRecommendations')) {
		$get('spanPleaseWaitRetrieveRecommendations').style.display = 'none';
	}
	
	$get('spanPleaseWaitMessage').style.display = 'inline';
	$get('spanPleaseWaitMessage').innerHTML = 'load your configuration';
	
	setPriceUpdatingDots();
}

function displayRetrievingMessage()
{
	Sys.UI.DomElement.removeCssClass($get('divPleaseWait'), 'hide');
	setPriceUpdatingDots();
}

function setPriceUpdatingDots() {
	//Update dots in screen to indicate progress
	var strPriceUpdatingDots = $get('spanPriceUpdatingDots').innerHTML;
	if (strPriceUpdatingDots.length == 10) {
		$get('spanPriceUpdatingDots').innerHTML = '';
	} else {
		$get('spanPriceUpdatingDots').innerHTML = strPriceUpdatingDots + '.';
	}	
	mnumSetPriceUpdatingDotsTimeout = setTimeout('setPriceUpdatingDots()', 500);
}

function navigateDirectToPricingTab(pstrReason) {
	
	// Navigate direct to pricing tab, adding inpReason for tracking purposes
	
	var currentUrl = location.href;
	var directUrl;
	
	// Set the selected tab to pricing (if one is already set, override to ensure it's current)
	if (currentUrl.indexOf('tab=') != -1)
	{
		directUrl = currentUrl.replace(/tab=[^&]+/, 'tab=pricing');
	}
	else
	{
		directUrl = currentUrl + '&tab=pricing';
	}

	// Set the reason for the redirect (if one is already set, override to ensure it's current)
	if (directUrl.indexOf('&inpReason=') != -1)
	{
		directUrl = directUrl.replace(/&inpReason=[^&]+/, '&inpReason=' + pstrReason);
	}
	else
	{
		directUrl = directUrl + '&inpReason=' + pstrReason;
	}
	
	location.href = directUrl;
}


/* --- MISC --- */

function getQueryStringValue(paramater) 
{ 
	var query = window.location.search.substring(1); 
	var parameters = query.split("&"); 
	for (var i=0;i<parameters.length;i++) 
	{ 
		var pair = parameters[i].split("="); 
		if (pair[0] == paramater) 
		{ 
			return pair[1]; 
		} 
	} 
} 

function OpenPrinterFriendlyWindow()
{
	var oPrinterWindow;
	var strUrl = window.location + '&Printer=1';
	oPrinterWindow = window.open(strUrl, 'PrinterWindow', 'width=710,height=450,scrollbars=yes,toolbar=yes');
	if (!((browserName == "IE") && (parseInt(browserVersion) <= 3)))
	{
		oPrinterWindow.focus();
	}
}

function clickButton(e, buttonid)
{
      var evt = e ? e : window.event;
      var bt = document.getElementById(buttonid);

      if (bt){
          if (evt.keyCode == 13){
                bt.click();
                return false;
          }
      }
}

function printWHPage() {
	if (window.print) {
		window.print();
	
		// ******************************* DO NOT REMOVE ****************************************
		// Add the print event to the webabacus arrays so that they get posted back to the
		// server. Try first as the function may not be available
		if(browserJavascript >= '1.3') {
			setWACustomVars('eventtype', 'printWindow', true, true);
		}
		//***************************************************************************************
	
	} else {
		alert("To print this page, please use your browser's Print button");
	}
}

function rblCustomerType_Click()
{
	var ctl = $get('inpSelectedCustomerType').value;
	
	if (ctl != '') {
		if ($get(ctl).checked == false) {
			Sys.UI.DomElement.addCssClass($get('divRecommendations'), 'hide');
			Sys.UI.DomElement.addCssClass($get('divCustomerTypeWrapper'), 'customertypeoverlay');
			Sys.UI.DomElement.addCssClass($get('divPleaseWait'), 'customertypeoverlay');
			displayRetrievingMessage();
		}
	}
}

function bodyOnLoad()
{
	if ($get('inpSelectedTabId') && $get('inpSelectedTabId')) {
	
		var selectedTabId = $get('inpSelectedTabId').value;
		var selectedTabBodyId = $get('inpSelectedTabBodyId').value
		
		if (selectedTabId != '' && selectedTabBodyId != '') {
			tabSelect(selectedTabId, selectedTabBodyId);
		}
	}
}
function CreateVATToggleURL(pstrRequestRul,pstrStatus)
{
    //Funstion to add querystring parameter vatToggleStatus and current tab in the URL
    var currentUrl; 
      
    //If pid is in the querystring removing the entire querystring attached to avoid incrementing quantity  
    if(pstrRequestRul.indexOf("pid") > 0 )
    {
        pstrRequestRul=pstrRequestRul.substring(0,pstrRequestRul.indexOf("?"));
    }   
    if(pstrRequestRul.indexOf("vatToggleStatus") == -1)
    {
         if (pstrStatus == "exclude")
            {
                if (pstrRequestRul.indexOf("?") == -1) 
                {
                        pstrRequestRul= pstrRequestRul + "?vatToggleStatus=exclude";
                }
                else 
                {
                    pstrRequestRul= pstrRequestRul + "&vatToggleStatus=exclude";
                }
             }
          else if(pstrStatus == "include")
          {
                if (pstrRequestRul.indexOf("?") == -1) 
                {
                    pstrRequestRul= pstrRequestRul + "?vatToggleStatus=include";
                }
                else 
                {
                    pstrRequestRul= pstrRequestRul + "&vatToggleStatus=include";
                }
          }
        if(currentSelectedTab != '')
        {
            if(pstrRequestRul.indexOf("tab") == -1)
            {    
                pstrRequestRul= pstrRequestRul + "&tab=" + currentSelectedTab;
            
            }
        }
        currentUrl =pstrRequestRul;
     }
     else
     {
         var targetUrl;
         var index =   pstrRequestRul.indexOf("vatToggleStatus");     
         targetUrl=pstrRequestRul.substring(0,index);
         if (pstrStatus == "exclude")
         { 
            currentUrl =   targetUrl + "vatToggleStatus=exclude";
         }
         else if(pstrStatus == "include")
         {
            currentUrl =   targetUrl + "vatToggleStatus=include";
         }
         if(currentSelectedTab != '')
         {
            if(currentUrl.indexOf("tab") == -1)
            {    
                currentUrl= currentUrl + "&tab=" + currentSelectedTab;
            }
         }
         else
         {
            var tab = getUrlParameters('tab');
            if(tab != '')
            {
                 currentUrl= currentUrl + "&tab=" + tab;
            }
         }
     
     }  
      
     window.location = currentUrl;    
}
//Parse the query string in your URL to grab certain values
function getUrlParameters(name)
{ 
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";  
    var regex = new RegExp( regexS ); 
    var results = regex.exec( window.location.href );  
    if( results == null )
    {   
        return ""; 
    }
    else    
    {
        return results[1];
    }
}

