
	function funcAddCountry(strcountry)
		{
		 var str=document.URL
         var arrWinLox = str.split("txtBucketsActive=")
		 var newUrl = arrWinLox[0]+	"txtBucketsActive=Country;"+arrWinLox[1];
		 
		 var arrWinLox2 = newUrl.split("txtBucketsActiveValues=")
		 	newUrl = arrWinLox2[0] + "txtBucketsActiveValues=" + strcountry + ";" + arrWinLox2[1];
	
		var arrWinLox3 = newUrl.split("?")
		var counter = arrWinLox3[0].lastIndexOf("/")
			
		var newUrl2 = arrWinLox3[0].substring(0,counter)+"/MSDSresults.aspx?"+arrWinLox3[1];
			
			//document.write(newUrl2);
			window.location = newUrl2;
		 }
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	function fncBuildQueryString(strPage)
	{
		var strQueryString
		var	strQueryString = "?txtNavigateActive=" + txtNavigateActive
						   + "&txtBucketsActive=" + txtBucketsActive
						   + "&txtBucketsActiveValues=" + txtBucketsActiveValues
						   + "&txtPageStart=" + txtPageStart
						   + "&txtPageEnd=" + txtPageEnd
						   + "&txtCurrentPage=" + txtCurrentPage
						   + "&txtPagingActive=" + txtPagingActive
						   + "&txtSearch=" + fncURLEncode(txtSearch);
						   
		if (strPage == "MSDSResults.aspx")
		{
			strQueryString += "&txtSort=" + txtSort
						   + "&txtSortExp=" + txtSortExp;
		}
		document.location.href=strPage + strQueryString;
						
	}

	function txtSearch_onKeyPress()
	{
		if (event.keyCode == 13)
		{
			cmdSearch_onClick();
			return false;
		}

	}
	function cmdSearch_onClick()
	{
		document.getElementById("txtSearch").value = document.getElementById("txtSearch").value.replace("<", "");
		if (fncValidate(document.getElementById("txtSearch").value) == true)
		{
			txtPageStart = "1";
			txtCurrentPage = "1";
			txtPageEnd = "10";
			txtSearch = document.getElementById("txtSearch").value;
			fncBuildQueryString(strPage);
		}
	}
	
	function fncSetBucket(strBucketName, strBucketValue)
	{
		txtNavigateActive = "true";
		
		var arrBuckets = txtBucketsActive.split(';');
		var arrBucketsActiveValues = txtBucketsActiveValues.split(';');
		txtBucketsActive = "";
		txtBucketsActiveValues = "";
		if (arrBuckets[0] != "")
		{
			for (var i=0; i < arrBuckets.length; i++)
			{
				if (arrBuckets[i] != strBucketName)
				{
					txtBucketsActive += arrBuckets[i] + ";";
					txtBucketsActiveValues += arrBucketsActiveValues[i] + ";";
					
				}
			}
		}
		if (strBucketValue != "")
		{
			txtBucketsActive += strBucketName + ";";
			txtBucketsActiveValues += strBucketValue + ";";
		}

		if (txtBucketsActive.length > 0)
		{
			txtBucketsActive = txtBucketsActive.substring(0, txtBucketsActive.length - 1);
			txtBucketsActiveValues = txtBucketsActiveValues.substring(0, txtBucketsActiveValues.length - 1);
		}
		
		
		txtCurrentPage = "1";
		txtPageStart = "1";
		txtPageEnd = "10";
		txtSearch = fncURLDecode(txtSearch)
		fncBuildQueryString(strPage);

	}
	
	function fncChangePage(intPageID, intChangedFrom)
	{
		var intLastPage = parseInt(txtPageEnd);
		var intFirstPage = parseInt(txtPageStart);
		var intActivePage = parseInt(intPageID);
		txtSearch = fncURLDecode(txtSearch);
		if (intChangedFrom == 0)
		{
			intLastPage--;
			if (intFirstPage > 1)
			{
				intFirstPage--;
			}
			else
			{
				intFirstPage = 1;
			}
		}
		else if (intChangedFrom == 1)
		{
			intLastPage = intActivePage + 9;
			if (intActivePage > 9) 
			{
				intFirstPage = intActivePage - 9;
			}
			else
			{
				intFirstPage = 1;
			}	
		}
		else if (intChangedFrom == 2)
		{
			intLastPage = intLastPage + 1;
			if (intActivePage - 9 > 1)
			{
				intFirstPage = intFirstPage + 1;
			}
		}
		txtPageStart = intFirstPage;
		txtPageEnd = intLastPage;
		txtCurrentPage = intActivePage;
		txtPagingActive = "true";
		txtCurrentPage = intPageID + "," + intChangedFrom;
		fncBuildQueryString(strPage);
	}
	function fncValidate(strString)
	{
		//var strInvalidChars = "!#%^&;()~,'><;?\|";
		var strInvalidChars = "";
		if (strString.length == 0)
		{
			alert('Please enter a search criteria.');
			document.getElementById("txtSearch").focus();
			return false;
		}
		else
		{
			for (var i=0; i<strInvalidChars.length; i++)
			{
				if(strString.indexOf(strInvalidChars.charAt(i)) >= 0 ) 
				{
					alert('Please do not use invalid characters for search criteria.');
					return false;
				}				
			}
			return true;
		}	
	}
	
	function window_onload()
	{
		document.getElementById("txtSearch").value = fncURLDecode(txtSearch);
		document.getElementById("txtSearch").focus();
		try
		{
			document.getElementById("txtBoolFromMyAcct").style.visibility = "hidden";
		}
		catch(e)
		{
		}
	}
	
function fncURLEncode(str)
{
    var s0, i, s, u;
    s0 = "";                // encoded str
	
    for (i = 0; i < str.length; i++)
    {   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " ")
		{
			s0 += "+";
		}       // SP should be converted to "+"
        else 
        {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) &&				(u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <=				0x7a)))
            {       // check for escape
                s0 = s0 + s;            // don't escape
            }

            else 
            {// escape
                if ((u >= 0x0) && (u <= 0x7f))
                {     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff)
				{     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff)
                {        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }

                else 
                {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}


function fncURLDecode(str)
{

    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str

    for (i = 0; i < str.length; i++)
    {   // scan the source str
        s = str.charAt(i);
        if (s == "+")
		{
			s0 += " ";
		}       // "+" should be changed to SP
        else 
        {
            if (s != "%")
            {
				s0 += s;
			}     // add an unescaped char
            else
            {               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) 
                {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) 
                        {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (								sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) 
                            {
                                ss += sss;      // if hex, add the hex character
                            } 
                            else 
                            {
								--i; break;
							}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f)
					{
						u = n; 
						f = 1;
					}   // single byte format

                    if ((n >= 0xc0) && (n <= 0xdf))
                    {
						u = n & 0x1f;
						 f = 2;
					}   // double byte format

                    if ((n >= 0xe0) && (n <= 0xef))
                    {
                     u = n & 0x0f;
                     f = 3;
                    }   // triple byte format

                    if ((n >= 0xf0) && (n <= 0xf7))
                    {
						u = n & 0x07;
						f = 4;
					}   // quaternary byte format (extended)

                    if ((n >= 0x80) && (n <= 0xbf))
                    {
						u = (u << 6) + (n & 0x3f);
						--f;
					}// not a first, shift and add 6 lower bits

                    if (f <= 1)
                    {
						break;
					}// end of the utf byte sequence

                    if (str.charAt(i + 1) == "%")
                    { 
						i++;
					}// test for the next shift byte

                    else {break;}// abnormal, format error
                }
            s0 += String.fromCharCode(u);// add the escaped character
            }
        }
    }
    return s0;
}