/*********************************************************************
* Returns associative array of name value pairs where the key is the
* URL parameter name and the value is the value associated with that
* parameter.
*
* NOTE: This function only retrieves URL parameters, NOT HTTP POST
* variables. Also, URL parameters consist of everything between the
* "?" and "#" symbols. URL parameters using SEO friendly formats
* would NOT fit under this criteria and thus would not be recognized
* as URL parameters by this function.
*********************************************************************/
function jsGetUrlParamsForContainers(strCurrentUrl) {
    var arrNamePairs = new Array();
    var hashUrlParams = new Array(); //note: it is possible that some url parameters in this array will have the value of "undefined"
    var strQueryString = "";
    var intQuestionMarkIndex = strCurrentUrl.indexOf("?");

    if (intQuestionMarkIndex != -1) {
        strQueryString = strCurrentUrl.substring(intQuestionMarkIndex + 1, strCurrentUrl.length);
    } else {
        return hashUrlParams;
    }

    var intUrlAnchorIndex = strQueryString.indexOf("#");
    if (intUrlAnchorIndex != -1) {
        strQueryString = strQueryString.substring(0, intUrlAnchorIndex);
    }

    if (strQueryString == "") {
        return hashUrlParams;
    } else {
        arrNamePairs = strQueryString.split("&");
        for (var i = 0; i < arrNamePairs.length; i++) {
            arrTmpCurrentRow = arrNamePairs[i].split("=");
            hashUrlParams[arrTmpCurrentRow[0]] = arrTmpCurrentRow[1];
        }

        return hashUrlParams;
    }
}

/*********************************************************************
 * Lawrence
 * Extracts the category id from the browser's address bar for
 * specific URL formats.
 *
 * Test URL formats Supported By This Function:
 * /catnc/19466-2326/Oral-B-Power-Toothbrushes.html
 * /catnc/19466/Oral-B-Power-Toothbrushes.html
 * /catnc/19466-2326/
 * /catnc/19466/
 * /catnc/19466-2326
 * /catnc/19466
 * /Category/CategoryListNoCache.aspx?category_id=19466&container_id=2326&keywords=Oral-B-Power-Toothbrushes
 *
 * /cat/19466-2326/Oral-B-Power-Toothbrushes.html
 * /cat/19466/Oral-B-Power-Toothbrushes.html
 * /cat/19466-2326/
 * /cat/19466/
 * /cat/19466-2326
 * /cat/19466
 * /Category/CategoryList.aspx?category_id=19466&container_id=2326&keywords=Oral-B-Power-Toothbrushes
 *********************************************************************/
function jsGetCategoryIdFromUrl()
{
    var strCurrentUrl = window.location.href;

    var intCatIdSectionStartIndex;

    var boolCatIdInParam;

    var intCategoryId;

    // +7 for /catnc/, +5 for /cat/
    if (strCurrentUrl.indexOf("/catnc/") != -1) {
        intCatIdSectionStartIndex = strCurrentUrl.indexOf("/catnc/") + 7;
        boolCatIdInParam = false;
    } else if (strCurrentUrl.indexOf("/cat/") != -1) {
        intCatIdSectionStartIndex = strCurrentUrl.indexOf("/cat/") + 5;
        boolCatIdInParam = false;
    } else if (((strCurrentUrl.indexOf("CategoryListNoCache.aspx") != -1) || (strCurrentUrl.indexOf("CategoryList.aspx") != -1)) && (strCurrentUrl.indexOf("category_id=") != -1)) {
        boolCatIdInParam = true;
    }

    if (boolCatIdInParam) {
        var hashUrlParams = jsGetUrlParamsForContainers(strCurrentUrl);

        intCategoryId = hashUrlParams["category_id"];
    } else {
        var intCatIdSectionEndIndex;

        if (strCurrentUrl.substring(intCatIdSectionStartIndex).indexOf("/") != -1) {
            intCatIdSectionEndIndex = intCatIdSectionStartIndex + strCurrentUrl.substring(intCatIdSectionStartIndex).indexOf("/");
        } else {
            intCatIdSectionEndIndex = strCurrentUrl.length;
        }

        var strCatSection = strCurrentUrl.substring(intCatIdSectionStartIndex, intCatIdSectionEndIndex);

        var intCatIdStartIndex = intCatIdSectionStartIndex;

        var intCatIdEndIndex;

        if (strCatSection.indexOf("-") != -1) {
            intCatIdEndIndex = intCatIdStartIndex + strCatSection.indexOf("-");
        } else {
            intCatIdEndIndex = intCatIdSectionEndIndex;
        }

        intCategoryId = strCurrentUrl.substring(intCatIdStartIndex, intCatIdEndIndex);

        //alert("strCurrentUrl: " + strCurrentUrl + "\nintCatIdSectionStartIndex: " + intCatIdSectionStartIndex + "\nintCatIdSectionEndIndex: " + intCatIdSectionEndIndex + "\nstrCatSection: " + strCatSection + "\nintCatIdStartIndex: " + intCatIdStartIndex + "\nintCatIdEndIndex: " + intCatIdEndIndex + "\ncat id: " + intCategoryId);
    }

    return intCategoryId;
}

/*********************************************************************
 * Lawrence 3/22/2010
 * Outputs heading for battery finder page.
 *********************************************************************/
function jsGetBatteryFinderHeading(strNonSearchHeading, strSearchHeading)
{
	var hashUrlParamsForFinder = jsGetUrlParamsForContainers(window.location.href);
	
	if ((hashUrlParamsForFinder == undefined) || (hashUrlParamsForFinder["search_term"] == undefined)) {
		strBatteryFinderHeading = strNonSearchHeading;
	} else {	
		var strBatterySearchTerm = unescape(hashUrlParamsForFinder["search_term"]);
		var strBatteryFinderHeading = "";

		strBatterySearchTerm = strBatterySearchTerm.replace("+^phone_replacement_battery^", "");
		strBatterySearchTerm = strBatterySearchTerm.replace("%20^phone_replacement_battery^", "");
		
		strBatterySearchTerm = strBatterySearchTerm.replace("+^handset_finder^", "");
		strBatterySearchTerm = strBatterySearchTerm.replace("%20^handset_finder^", "");
	
		if ((strBatterySearchTerm == undefined) || (strBatterySearchTerm == "")) {
			strBatteryFinderHeading = strNonSearchHeading;
		} else {
			strBatteryFinderHeading = strSearchHeading + strBatterySearchTerm;
		}
	}
	
	return strBatteryFinderHeading;
}


/*********************************************************************
 * Nathan 4/16/2010
 * Outputs appearance and link for flypage additional handsets section.
 *********************************************************************/

/************************* Uniden DECT 6**************************************/

function DCX100()
{
return ('<a href="/details/0-8541/DCX100.html" target="blank">Uniden DCX100</a>');
}

function DCX150()
{
return ('<a href="/details/0-9420/DCX150.html" target="blank">Uniden DCX150</a>');
}

function DCX200()
{
return ('<a href="/details/0-6063/DCX200.html" target="blank">Uniden DCX200</a>'
	+ '<li><a href="/details/0-6063/DCX200.html" target="blank">Uniden DCX200BLK</a> (Black)</li>'
	+ '<li><a href="/details/0-6063/DCX200.html" target="blank">Uniden DCX200BLU</a> (Blue)</li>'
	+ '<li><a href="/details/0-6063/DCX200.html" target="blank">Uniden DCX200WHT</a> (White)</li>');
}


function DCX210()
{
return ('<a href="/details/0-11116/DCX210.html" target="blank">Uniden DCX210</a>');
}

function DCX300()
{
return ('<a href="/details/0-5635/DCX300.html" target="blank">Uniden DCX300</a>');
}

function DCX330()
{
return ('<a href="/details/7704-15656/DCX330.html" target="_blank">Uniden DCX330</a>');
}

function DCX400()
{
return ('<a href="/details/0-11869/DCX400.html" target="blank">Uniden DCX400</a>');
}

function DRX332()
{
return ('<a href="/details/0-23951/DRX332.html" target="blank">Uniden DRX332</a>');
}

function DRX402()
{
return ('<a href="/details/0-23952/DRX402.html" target="blank">Uniden DRX402</a>');
}

function DWX207()
{
return ('<a href="/details/0-5767/DWX207.html" target="blank">Uniden DWX207</a> (Waterproof)');
}

function DWX337()
{
return ('<a href="/details/0-34542/DWX337.html" target="blank">Uniden DWX337</a> (Waterproof)');
}

function EZX290()
{
return ('<a href="/details/0-10146/EZX290.html" target="blank">Uniden EZX290</a>');
}

/************************* Uniden 5.8GHz****************************************/

function ELX500()
{
return ('<a href="/details/0-8515/ELX500.html" target="blank">Uniden ELX500</a>');
}

function TCX800()
{
return ('<a href="/details/0-392/TCX800.html" target="blank">Uniden TCX800</a>');
}

function TCX860()
{
return ('<a href="/details/0-382/TCX860.html" target="blank">Uniden TCX860</a>');
}

function TCX905()
{
return ('<a href="/details/0-378/TCX905.html" target="blank">Uniden TCX905</a>');
}

function TCX930()
{
return ('<a href="/details/0-1163/TCX930.html" target="blank">Uniden TCX930</a>');
}

function TCX950()
{
return ('<a href="/details/0-5677/TCX950.html" target="blank">Uniden TCX950</a>');
}

function TWX955()
{
return ('<a href="/details/0-9844/TWX955.html" target="blank">Uniden TWX955</a> (Waterproof)');
}

function TWX977()
{
return ('<a href="/details/0-383/TWX977.html" target="blank">Uniden TWX977</a> (Waterproof)');
}


/************************* Uniden 2.4GHz****************************************/

function TCX400()
{
return ('<a href="/details/0-397/TCX400.html" target="blank">Uniden TCX400</a>');
}

function TCX440()
{
return ('<a href="/details/0-403/TCX440.html" target="blank">Uniden TCX440</a>');
}

function TCX580()
{
return ('<a href="/details/0-8504/TCX580.html" target="blank">Uniden TCX580</a>');
}

function DCX640()
{
return ('<a href="/details/0-8543/DCX640.html" target="blank">Uniden DCX640</a>');
}

function DCX700()
{
return ('<a href="/details/0-6405/DCX700.html" target="blank">Uniden DCX700</a>');
}

function DCX730()
{
return ('<a href="/details/0-1047/DCX730.html" target="blank">Uniden DCX730</a>');
}

function DCX750()
{
return ('<a href="/details/0-374/DCX750.html" target="blank">Uniden DCX750</a>');
}

function DCX770()
{
return ('<a href="/details/0-406/DCX770.html" target="blank">Uniden DCX770</a>');
}


/*********************************************************************
 * End handset appearance output
 *********************************************************************/
