/**
 * global.js - Global javascript variables and functions
 *
 * @author Mike Lee <mlee11111@yahoo.com>
 * @version 1.0 - Feb 28, 2007
 */

// === Include Common Classes ===
document.writeln("<script type=\"text/javascript\" src=\"/js/cookie.js\"><\/script>");

// === Display Functions ===
/**
  * jn_drawLogin - Outputs html based on user's login status.
  * @uses cookie.js
  */
function jn_drawLogin() {
    var user = Cookie.get("cUser");
    var html = "";

    if (user) {
        html = "Welcome " + user + "! <a href=\"/profile.php\">Back to your Profile</a> | <a href=\"/t/logout.php\">Log out &gt;&gt;</a>";
    } else {
        html = "<a href=\"/user_login.php\">User Login &gt;&gt;";
    }

    document.writeln(html);
    return;
}

/**
  * jn_drawAd - Outputs js to draw Google Ads
  * @param adType Type of ad (text, image, text_image, link4, link5, firefox, custom).
  * @param width Width.
  * @param height height.
  *
  */
function jn_drawAd(adType, width, height) {
    // base options
    google_ad_client = "pub-5503790274779358";
    if (adType == 'firefox') {
        google_cpa_choice = "";
	} else {
        google_ad_type = adType;
    }
    google_ad_channel = "0772406066";
    google_color_border = "336699";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_text = "000000";
    google_color_url = "008000";
    google_ui_features = "rc:0";

    // configurable options
    google_ad_width = width;
    google_ad_height = height;
    if (adType == 'link4') {
        google_ad_format = "" + width + "x" + height + "_0ads_al";
    } else if (adType == 'link5') {
        google_ad_format = "" + width + "x" + height + "_0ads_al_s";
    } else if (adType == 'firefox') {
        google_ad_slot = "8266155947";
	} else {
        google_ad_format = "" + width + "x" + height + "_as";
    }

    // output ad script
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></scr' + 'ipt>');
}

/**
 * jn_searchSubmit - Checks validity of submit form.
 * @param frm Form object.
 * @param searchPage Form type. (basic|advanced)
 * @return boolean true if form good.
 */
function jn_searchSubmit(oForm, searchPage) {
    var searchTerm = oForm.txtSearch.value;
    oForm.txtSearch.value = searchTerm = searchTerm.replace(/(^ +| +$)/g, '');

    if (searchPage == 'basic' && searchTerm == "") {
        oForm.txtSearch.focus();
        alert("Please enter a keyword first.");
        return(false);
    } else if (searchPage == 'advanced' && searchTerm == "" && oForm.selState.selectedIndex == 0) {
        alert("Please enter a keyword first and/or location first.");
        return(false);
    }

    return(true);
}

/**
  * jn_trim - Removes whitespace from ends of string.
  * @param txt String input.
  * @return Trimmed string.
  */
function jn_trim(txt) {
    return(txt.replace(/(^ +| +$)/g, ''));
}

