

function GET_HTTP_QueryString(Query_String_Name) {
    var i, pos, argname, argvalue, queryString, pairs;
    // get the string following the question mark
    queryString = location.href.substring(location.href.indexOf("?")+1);
    // split parameters into pairs, assuming pairs are separated by ampersands
    pairs = queryString.split("&");
    // for each pair, we get the name and the value
    for (i = 0; i < pairs.length; i++) {
        pos = pairs[i].indexOf('=');
        if (pos == -1) {
            continue;
        }
        argname = pairs[i].substring(0,pos);
        argvalue = pairs[i].substring(pos+1); 
        // Replaces "Google-style" + signs with the spaces they represent
        if (argname == Query_String_Name) {
            return unescape(argvalue.replace(/\+/g, " "));
        }
    }
    return false;
}

function printButton(id, displayLabel, link) {

    var button_string = "<tr>" +
                        "<td class=\"menuleft\"></td>" +
                        "<td nowrap class=\"menuButton\">" + "<a href=\"" + link + "\">" + displayLabel + "</a></td>" +
                        "<td class=\"menuright\"</td>" +
                        "<td class=\"menu_ButtonHeight\"></td>" +
                        "</tr>" +
                        "<tr><td colspan=\"3\" class=\"menu_h_space\"></td></tr>";
    document.write(button_string);
}

function printImage(imageSrc) {
    document.write("<img src=\"" + imageSrc + "\" alt=\"\">");
}
function printReturnLink(returnPage, returnString) {
    var return_link = "<a href=\"" + returnPage + "\">" + returnString + "</a>";
    document.write(return_link);
}

function printVideoLink(videoUrl, linkString) {
    var video_link = "<a href=\"" + videoUrl + "\">" + linkString + "</a>";
    document.write(video_link);
}

function printFileLink(fileUrl, linkString) {
    var file_link = "<a href=\"" + fileUrl + "\">" + linkString + "</a>";
    document.write(file_link);
}

function showAnimalProfile(name, animalType, returnPage) {
    //alert(name);
    window.location=encodeURI("animalProfile.htm?name=" + escape(name) +
                                               "&animalType=" + escape(animalType) +
                                               "&returnPage=" + escape(returnPage));
}

function makeNewWindowLink(url, linkText) {
    var beginALink = "<a href=\""+url+"\" onclick=\"window.open(this.href);return false;\">";
    var endALink = "</a>";
    return (beginALink + linkText + endALink);
}
    
function printYouTubeLink(url, name) {
    var linkText = "View YouTube video of " + name;
    document.write(makeNewWindowLink(url, linkText));
    document.write("<br>(clicking above link will open a new window)");
}

function printPedigreeLink(url, name) {
    var linkText = "View PEDIGREE information for " + name;
    document.write(makeNewWindowLink(url, linkText));
    document.write("<br>(clicking above link will open a new window)");

}

function printShorthornLink(url, description) {
    var link = makeNewWindowLink(url, description);
    document.write("<LI>" + link + "</LI>");
}

function oldprintShorthornLink(url, urlText, description) {
    var link = makeNewWindowLink(url, urlText);
    document.write("<LI>" + link + "&nbsp; &nbsp;" + description + "</LI>");
}


function printPictureLink(file, name, animalType, returnPage) {
    var thumbnail_image = "images/shorthorn/thumbnail/" + file + ".jpg";
    var fullsize_image = "images/shorthorn/fullsize/" + file + ".jpg";
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + file + "')\" OnMouseOut=\"imageLinkOut('" + file + "')\"";
    mouseMovementCode = "";
    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showAnimalProfile('" + name + "','" + animalType + "','" + returnPage + "');" +
        " return false;\"><img src=\"" + thumbnail_image + "\"></a>";
    //alert(image_link_code);
    document.write(image_link_code);
}

function printLabelLink(file, name, animalType, returnPage) {
    var thumbnail_image = "images/shorthorn/thumbnail/" + file + ".jpg";
    var fullsize_image = "images/shorthorn/fullsize/" + file + ".jpg";
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + file + "')\" OnMouseOut=\"imageLinkOut('" + file + "')\"";
    mouseMovementCode = "";
    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showAnimalProfile('" + name + "','" + animalType + "','" + returnPage + "');" +
        " return false;\">"+name+"</a>";
    //alert(image_link_code);
    document.write(image_link_code);
}


















function printAnimalCell(files, name, animalType, returnPage) {
    var ar=files.split("&");
    var part_num=0;

    document.write("<td align=\"left\">");
    while (part_num < ar.length) {
        printPictureLink(ar[part_num], name, animalType, returnPage);
        part_num+=1;
        document.write("&nbsp;")
    }
    document.write("</td>");

    document.write("<td align=\"left\"><font size=\"4\">" );
    printLabelLink(ar[0], name, animalType, returnPage);
    document.write("</font></td>");
}


function printAnimalRow(files, name, animalType, returnPage) {
	//if (1 == 1) return;
    var ar=files.split("&");
    var part_num=0;

    document.write("<tr>");
    document.write("<td align=\"left\"><font size=\"4\">" );
    printLabelLink(ar[0], name, animalType, returnPage);
    document.write("</font></td>");
    document.write("<td align=\"left\">");
    while (part_num < ar.length) {
        printPictureLink(ar[part_num], name, animalType, returnPage);
        part_num+=1;
        document.write("&nbsp;")
    }
    document.write("</td>");
    document.write("</tr>");
}

function oldprintAnimalRow(files, name, animalType, returnPage) {
    document.write("<tr>");

    document.write("<td align=\"left\">");
    var ar=files.split("&");
    var part_num=0;
    while (part_num < ar.length) {
        printPictureLink(ar[part_num], name, animalType, returnPage);
        part_num+=1;
        document.write("&nbsp;")
    }
    document.write("</td>");

    document.write("<td align=\"left\"><font size=\"4\">" );
    printLabelLink(ar[0], name, animalType, returnPage);
    document.write("</font></td>");

    document.write("</tr>");
}

function printSiteMeterCode() {

    //var meterID = "sm1crooked";
    //var meterHost = "sm1.sitemeter.com";
    var meterID = "s31crookedpost";
    var meterHost = "s31.sitemeter.com";

    document.write("<!-- Site Meter -->");
    document.write("<script type=\"text/javascript\" src=\"http://" + meterHost  + "/js/counter.js?site=" + meterID + "\">");
    document.write("</script>");
    document.write("<noscript>");
    document.write("<a href=\"http://" + meterHost  + "/stats.asp?site=" + meterID + "\" target=\"_top\">");
    document.write("<img src=\"http://" + meterHost  + "/meter.asp?site=" + meterID + "\" alt=\"Site Meter\" border=\"0\"/></a>");
    document.write("</noscript>");
    document.write("<!-- Copyright (c)2006 Site Meter -->");
}




function printCarPictureLink(file, name, carType, returnPage) {
    var thumbnail_image = "images/mustang/thumbnail/" + file + ".jpg";
    var fullsize_image = "images/mustang/fullsize/" + file + ".jpg";
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + file + "')\" OnMouseOut=\"imageLinkOut('" + file + "')\"";
    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showCarProfile('" + name + "','" + carType + "','" + fullsize_image + "','" + returnPage + "');" +
        " return false;\"><img src=\"" + thumbnail_image + "\"></a>";
    //alert(image_link_code);
    document.write(image_link_code);
}
function printCarLabelLink(file, name, carType, returnPage) {
    var thumbnail_image = "images/mustang/thumbnail/" + file + ".jpg";
    var fullsize_image = "images/mustang/fullsize/" + file + ".jpg";
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + file + "')\" OnMouseOut=\"imageLinkOut('" + file + "')\"";
    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showCarProfile('" + name + "','" + carType + "','" + fullsize_image + "','" + returnPage + "');" +
        " return false;\">"+name+"</a>";
    //alert(image_link_code);
    document.write(image_link_code);
}

function printCarCell(files, name, carType, returnPage) {
    var ar=files.split("&");
    var part_num=0;

    document.write("<td align=\"left\">");
    while (part_num < ar.length) {
        printCarPictureLink(ar[part_num], name, carType, returnPage);
        part_num+=1;
        document.write("&nbsp;")
    }
    document.write("</td>");
    document.write("<td align=\"left\"><font size=\"4\">" );
    printCarLabelLink(ar[0], name, carType, returnPage);
    document.write("</font></td>");
}

function showCarProfile(name, carType, picFile, returnPage) {
    //alert(name);
    window.location=encodeURI("carProfile.htm?name=" + escape(name) +
                                               "&carType=" + escape(carType) +
                                               "&picFile=" + escape(picFile) +
                                               "&returnPage=" + escape(returnPage));
}

















function redbold(value) {
    return "<b><span style=\"color:red\">" + value + "</span></b>";
    // return ("<b>" + value + "</b>");
}

function bluebold(value) {
    return "<b><span style=\"color:blue\">" + value + "</span></b>";
    // return ("<b>" + value + "</b>");
}

function printAnimalBreedAverageEPDsRow(ce, bw, ww, yw, milk, mw, mce) {
    document.write("<tr>");

    document.write("<td align=\"left\" colspan=7><font size=\"2\" >" + "<b>Breed Average EPDs</b>" + "</font></td>");

    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ce + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + bw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ww + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + yw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + milk + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mce + "</font></td>");

    document.write("</tr>");
}


function printAnimalRankForSaleRow(ce, birthWt, ww, yw, milk, mw, mce) {

    document.write("<tr>");

    document.write("<td align=\"center\" nowrap colspan=7><font size=\"2\" >" + "<b>Percentile Ranking Within Shorthorn Breed</b>" + "</font></td>");

    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ce + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + birthWt + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ww + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + yw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + milk + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mce + "</font></td>");

    document.write("</tr>");
}


// (TAG,DOB,HP,SIRE,DAMSSIRE,BW,WWT205,YWT365,MILK,MWWT)

// printAnimalForSaleRow("SLU 1T","30/01/2007","P","Goldmine 2109","Bodacious 12H","0.6/55","24/652","35.0/995","8","20",animalType, returnPage);

function printAnimalForSaleRow(tag, name, dob, color, hp, purity, sire, damsSire, ce, birthWt, ww, yw, milk, mw, mce, animalType, returnPage, soldStatus) {

    document.write("<tr>");

    document.write("<td align=\"center\" nowrap><font size=\"2\">" + bluebold(tag) + "</font></td>");
    //document.write("<td align=\"center\"><font size=\"2\">" + name + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + dob + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + color + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + hp + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + purity + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + sire + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + damsSire + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ce + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + birthWt + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + ww + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + yw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + milk + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mw + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + mce + "</font></td>");

    document.write("</tr>");
}

function printAnimalForSaleRowOld1(tag, dob, hp, sire, damsSire, birthWt, wwt205, ywt365, milk, mwwt, animalType, returnPage, soldStatus) {

    document.write("<tr>");
    document.write("<td align=\"left\"><font size=\"2\">");
    printForSaleLabelLink(tag, dob, hp, sire, damsSire, birthWt, wwt205, ywt365, milk, mwwt, animalType, returnPage, soldStatus);
    document.write("</font></td>");

    document.write("<td align=\"center\"><font size=\"2\">" + dob + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + hp + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + sire + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + damsSire + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + birthWt + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + wwt205 + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + ywt365 + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + milk + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + mwwt + "</font></td>");

    document.write("</tr>");
}







function printForSaleLabelLink(tag, dob, hp, sire, damsSire, birthWt, wwt205, ywt365, milk, mwwt, animalType, returnPage, soldStatus) {
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + tag + "')\" OnMouseOut=\"imageLinkOut('" + tag + "')\"";

//        "<a href=\"\"" + mouseMovementCode + "onclick=\"showAnimalForSaleProfile('" + tag + "','" + animalType + "','" + returnPage + "');" +


    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showAnimalForSaleProfile('" + tag + "','" + dob + "','" + hp + "','" + sire + "','" + damsSire + "','" + birthWt + "','" + wwt205 + "','" + ywt365 + "','" + milk + "','" + mwwt + "','" + soldStatus + "','" + animalType + "','" + returnPage + "');" +
        " return false;\">"+tag+"</a>";
    // document.write(image_link_code);
    document.write("<font size=\"2\">" + image_link_code + "</font>");
    document.write("&nbsp;<span style=\"color:red\">" + soldStatus + "</span>");



}

function showAnimalForSaleProfile(tag, dob, hp, sire, damsSire, birthWt, wwt205, ywt365, milk, mwwt, soldStatus, animalType, returnPage) {
    //alert(name);
    window.location=encodeURI("animalProfile.htm?tag=" + escape(tag) +
                                               "&dob=" + escape(dob) +
                                               "&hp=" + escape(hp) +
                                               "&sire=" + escape(sire) +
                                               "&damsSire=" + escape(damsSire) +
                                               "&birthWt=" + escape(birthWt) +
                                               "&wwt205=" + escape(wwt205) +
                                               "&ywt365=" + escape(ywt365) +
                                               "&milk=" + escape(milk) +
                                               "&mwwt=" + escape(mwwt) +
                                               "&soldStatus=" + escape(soldStatus) +
                                               "&animalType=" + escape(animalType) +
                                               "&returnPage=" + escape(returnPage));
}











// printAnimalScanningDataRow("SLU 1T","1060","4.35","2.92","11.36","73.30","1.12","65.00",animalType, returnPage);
// (Tag,Weight,Marbling,Backfat mm,REA in^2,REA cm^2,Weight adj REA in^2 per 100 #, % Lean Meat Yield)

function printAnimalScanningDataRow(tag, weight, marbling, backfatmm, reaIn, reaCm, weightAdj, pctLeanMeatYield, price, animalType, returnPage, soldStatus) {

    document.write("<tr>");

    var bs = "";
    var be = "";
/*
    if (tag == 'Avg') {

    	bs = "<b>";
    	be = "</b>";

    	document.write("<td align=\"center\"><font size=\"2\">" + bs + tag + be + "</font></td>");
    } else {
        document.write("<td align=\"left\"><font size=\"2\">");
        printAnimalScanningLabelLink(tag, weight, marbling, backfatmm, reaIn, reaCm, weightAdj, pctLeanMeatYield, animalType, returnPage, soldStatus);
        document.write("</font></td>");
    }
*/

    //document.write("<td align=\"center\"><font size=\"2\">" + tag + "</font></td>");
    document.write("<td align=\"center\" nowrap><font size=\"2\">" + bluebold(tag) + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + weight + be + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + marbling + be + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + backfatmm + be + "</font></td>");
    //document.write("<td align=\"center\"><font size=\"2\">" + bs + reaIn + be + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + reaCm + be + "</font></td>");
    //document.write("<td align=\"center\"><font size=\"2\">" + bs + weightAdj + be + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + pctLeanMeatYield + be + "</font></td>");
    document.write("<td align=\"center\"><font size=\"2\">" + bs + price + be + "</font></td>")

    document.write("</tr>");
}

function printAnimalScanningLabelLink(tag, weight, marbling, backfatmm, reaIn, reaCm, weightAdj, pctLeanMeatYield, animalType, returnPage, soldStatus) {
    var mouseMovementCode = "OnMouseOver=\"imageLinkOver('" + tag + "')\" OnMouseOut=\"imageLinkOut('" + tag + "')\"";

    var image_link_code =
        "<a href=\"\"" + mouseMovementCode + "onclick=\"showAnimalScanningProfile('" + tag + "','" + weight + "','" + marbling + "','" + backfatmm + "','" + reaIn + "','" + reaCm + "','" + weightAdj + "','" + pctLeanMeatYield + "','" + soldStatus + "','" + animalType + "','" + returnPage + "');" +
        " return false;\">"+tag+"</a>";
    document.write("<font size=\"2\">" + image_link_code + "</font>");
    document.write("&nbsp;<span style=\"color:red\">" + soldStatus + "</span>");
}

function showAnimalScanningProfile(tag, weight, marbling, backfatmm, reaIn, reaCm, weightAdj, pctLeanMeatYield, soldStatus, animalType, returnPage) {
    //alert(name);
    window.location=encodeURI("animalProfile.htm?tag=" + escape(tag) +
                                               "&dob=" + escape(weight) +
                                               "&hp=" + escape(marbling) +
                                               "&sire=" + escape(backfatmm) +
                                               "&damsSire=" + escape(reaIn) +
                                               "&birthWt=" + escape(reaCm) +
                                               "&wwt205=" + escape(weightAdj) +
                                               "&ywt365=" + escape(pctLeanMeatYield) +
                                               "&soldStatus=" + escape(soldStatus) +
                                               "&animalType=" + escape(animalType) +
                                               "&returnPage=" + escape(returnPage));
}
