function resizeSearchImage(image, width, height)
{
    var newHeight = image.height * width / image.width;
    if (newHeight > 0)
    {
        image.height = newHeight;
        image.width = width;
    }
}

function resizeSearchImages()
{
    var images = document.getElementsByTagName("img");
    if (images != null)
    {
        for(var i = 0; i < images.length; i++)
        {
            var image = images[i];
            if (image.className == "search_image_mm")
            {
                resizeSearchImage(image, 300, 187 );
            }
            if (image.className == "search_image")
            {
                resizeSearchImage(image, 100, 60);
            }
            
            if (image.className == "search_image_large")
            {
                resizeSearchImage(image, 200, 125);
            }
            
            if (image.className == "search_image_small")
            {
                resizeSearchImage(image, 40, 30);
            }
        }
    }
}
String.prototype.endsWith = function(str) {return (this.match(str+"$")==str)}
function gotoSearchPage(newPageCtrl)
{
    if (newPageCtrl != null && newPageCtrl.value.length > 0)
    {
        var newPage = newPageCtrl.value;
        if (isNaN(newPage) || !/^[1-9]\d*$/.test(newPage))
        {
            alert("Please enter a valid page number");
            newPageCtrl.value = "";
            newPageCtrl.focus();
        }
        else
        {
            var path = document.location.pathname;
            var index = -1;
            var newPath = "";

            if (path.endsWith("/")) 
            {
                path = path + "index.html";
            }
            if (path.indexOf("/index") != -1)
            {
                index = path.indexOf("/index");
            }
            
            if (path.indexOf("/page") != -1)
            {
                index = path.indexOf("/page");
            }
            
            if (index != -1)
            {
                var end = path.indexOf(".", index);
                var beginStr = path.substring(0, index + 1);
                var endStr = path.substring(end);
                
                if (newPage == 0 || newPage == 1)
                {
                    newPath = beginStr + "index" + endStr;
                }
                else
                {
                    newPath = beginStr + "page" + newPage + endStr;
                }
                document.location.href = newPath + document.location.search;
            }
        }
    }
    else
    {
        alert("Please enter a page number");
        newPageCtrl.value = "";
        newPageCtrl.focus();
    }
}
function getReplaceString(searchString)
{
    var result = "";
    for (var i = 0; i < matches.length; i++)
    {
        if (searchString.toLowerCase().indexOf(matches[i]) != -1)
        {
            var start = searchString.toLowerCase().indexOf(matches[i]);
            replaceString = searchString.substring(start, start + matches[i].length + 1);
            break;
        }
    }
    result = searchString.replace(replaceString, "");
    return result;
}
var matches = new Array()
matches[0] = "classifieds";
matches[1] = "for sale";
matches[2] = "photo";
matches[3] = "photos";
matches[4] = "picture";
matches[5] = "pictures";
matches[6] = "image";
matches[7] = "images";
matches[8] = "photograph";
matches[9] = "photographs";
matches[10] = "video";
matches[11] = "videos";
matches[12] = "movie";
matches[13] = "movies";
                     

function matchQuery(searchString)
{
    var searchPage = "";
                     
    for (var i = 0; i < matches.length; i++)
    {
        if (searchString.toLowerCase().indexOf(matches[i]) != -1)
        {
            switch(matches[i])
            {
                case "classifieds":
                case "for sale":
                searchPage = "classifieds";
                break;
                
                case "photo":
                case "photos":
                case "picture":
                case "pictures":
                case "image":
                case "images":
                case "photograph":
                case "photographs":
                searchPage = "photos";
                break;
                
                case "video":
                case "videos":
                case "movie":
                case "movies":
                searchPage = "video";
                break;
            }
            break;
        }
    }                         
    return searchPage;
}
// gets selection of radiobutton list
function getRBListSelection(rbList)
{
    var result;
    if (rbList != null)
    {
        for(var i = 0; i < rbList.rows.length; i++)
        {
            var row = rbList.rows[i];
            if (row != null)
            {
                var ctrl = row.cells[0].firstChild;
                if (ctrl != null)
                {
                    if (ctrl.checked == true)
                    {
                        result = ctrl.value;
                    }
                }
            }
        }
    }
    return result;
}

