/* vim: set expandtab tabstop=4 shiftwidth=4: */
/* $Id: main.js,v 1.1.1.1 2006/11/17 09:39:18 pavanb Exp $ */

var browserVersion = parseInt(navigator.appVersion);
var isNetscape = navigator.appName.indexOf("Netscape") != -1;
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var agent = navigator.userAgent.toLowerCase();
var isWindows = agent.indexOf("win") != -1;
var isMac = agent.indexOf("mac") != -1;
var isNix = agent.indexOf("X11") != -1;

function doConfirm(text)
{
    val = confirm(text);
    return (!val) ? false : true;
}

function pageNav(increment)
{
    if (increment == "next") {
        document.pageNavForm.page_num.value++;
    }
    else if (increment == "prev")
    {
        document.pageNavForm.page_num.value--;
    }
    else
    {
        document.pageNavForm.page_num.value = increment;
    }
    document.pageNavForm.submit();
    return false;
}

function changeOrder(orderBy)
{
    var currentOrderBy = document.pageNavForm.order_by.value;
    var currentOrder   = document.pageNavForm.order.value;
    if (currentOrderBy == orderBy) {
        document.pageNavForm.order.value = (currentOrder == "DESC") ? "ASC" : "DESC";
    } else {
        document.pageNavForm.order.value = "ASC";
    }
    document.pageNavForm.order_by.value = orderBy;
    document.pageNavForm.submit();
    return false;
}

function selectItem(id)
{
    document.itemSelectForm.item_id.value = id;
    document.itemSelectForm.submit();
    return false;
}

function changeClass(obj, newClass)
{
    obj.className = newClass;
}

function changePointer (obj, pointer)
{
    pointer = (pointer != '') ? pointer : 'pointer';
    if (isIE && browserVersion < 6 && pointer == 'pointer') {
        pointer = 'hand';
    }

    obj.style.cursor = pointer;
}

function rowHover(obj, newClass)
{
  changePointer(obj, 'pointer');
  changeClass(obj, newClass);
}

function doConfirm(text)
{
  val=confirm(text);
  return (!val) ? false : true;
}

function openWindow(url, width, height, left, top, name, scroll, resize) {
        if (width==null) width = 500;
        if (height==null) height = 400;
        if (left == null) left = 10;
        if (top == null) top = 10;
        if (name == null) name = 'tjt_popup';
        if (scroll == null) scroll = 'no';
        if (resize == null) resize = 'no';

        window.open(url, name, 'toolbar=no,location=no,status=no,directories=no,menubar=no,scrollbars='+scroll+',resizable='+resize+',width='+width+',height='+height+',left='+left+',top='+top, 'replace=false');
}

function openCoupon(link){
    openWindow(link, 415, 510, 5, 5, "couponWindow", "no", "yes");
}

function openAddReview(link){
	window.open(link, "addReviewWindow", "width=415, height=540, location=no, directories=no, toolbar=no, resizable=yes, scrollbars=yes")
}

function openReviews(link){
	window.open(link, "reviewWindow", "width=600, height=500, location=no, directories=no, toolbar=no, resizable=yes, scrollbars=yes")
}

function populateSelect(selectID, options)
{
    var selectObj = document.getElementById(selectID)
    if (options.length == 0) {
        selectObj.options.length = 0;
        selectObj.selectedIndex  = 0;
        return;
    }

    selectObj.options.length = 1;
    selectObj.options.length = options.length + 1;
    selectObj.options[0].text  = '';
    selectObj.options[0].value = '';
    for (i = 0; i < options.length; i++) {
        selectObj.options[i+1].value = options[i].id;
        selectObj.options[i+1].text  = options[i].value;
	}
}

function showMap(sCntry,sCity,sAddress,sZip)
{
    var objMap;
    var iRand=Math.random();
    var sLink;

    sLink="http://www.mapquest.com/maps/map.adp?country=" + sCntry + "&city=" + sCity + "&address=" + sAddress + "&zip=" + sZip + "&zoom=10";
    objMap=window.open(sLink, "ShowMap", "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=650,height=500");

    objMap.focus();
}