﻿
        
$(document).ready(function() {
    $("a.single").fancybox({
        'showLeftNav'	    :   true,
        'showCloseButton'	:   true,
        'titlePosition'     :   'inside',
        'autoDimensions'	:   false,
        'scrolling'         :   'no',
        'width'         	:   350,
        'height'        	:   'auto',
        'speedIn'		    :	400, 
        'speedOut'		    :	400, 
        'transitionIn'	    :	'fade',
        'transitionOut'	    :	'fade'
    });
/* Apply fancybox to multiple items */
    $("a.grouped_elements").fancybox({
        'showLeftNav'	    :   true,
        'showCloseButton'	:   true,
        'titlePosition'     :   'inside',
//	            'titleshow'         :   'true',
//				'title'			    :   this.title,
        'autoDimensions'	:   false,
        'scrolling'         :   'no',
        'width'         	:   350,
        'height'        	:   'auto',
        'speedIn'		    :	400, 
        'speedOut'		    :	400, 
        'transitionIn'	    :	'fade',
        'transitionOut'	    :	'fade',
        'titleFormat'		:   formatTitle
    });
    $('.imgPopupstart').bind('click', function(){
        //$find('mdlImageBox').show();
        ShowImageBox($(this).find('.latest_img').attr('src'));
    });
    $('.imgPopupclose').bind('click', function(){
        $find('mdlImageBox').hide();
    });
    $('.imgPopupleft').bind('click', function(){
        $find('mdlImageBox').hide();
    });
    $('.imgPopupright').bind('click', function(){
        $find('mdlImageBox').hide();
    });
    $('.iframePopupstart').bind('click', function(){
        ShowIframeBox('http://visitor.constantcontact.com/manage/optin/ea?v=001jYqn93s1IRDzbjcAkNuWGQ%3D%3D');
    });
    $('.iframeNewsPopupstart').bind('click', function(){
        ShowNewsIframeBox('http://visitor.constantcontact.com/manage/optin/ea?v=001jYqn93s1IRDzbjcAkNuWGQ%3D%3D');
    });
    $('.iframeMobilePopupstart').bind('click', function(){
        ShowIframeMobileBox('http://m.seedtechnologies.com');
    });
    $('.imgPopupclose').bind('click', function(){
        $find('mdlImageBox').hide();
    });
    $('.iframePopupclose').bind('click', function(){
        $find('mdlImageNewsBox').hide();    
    });
    $('.imgPopupclose_mobile').bind('click', function(){
        $find('mdlMobileImageBox').hide();    
    });
});

function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + '</div>';
}

$.preloadImages = function()  
{         
    for(var i = 0; i<arguments.length; i++)         
    {                 
    $("<img />").attr("src", arguments[i]);         
    }  
}    
    $(document).ready(function()  
{         
    $.preloadImages(
        "images/banner_bg.jpg",
        "images/bottom_lft_leaf.png",
        "images/bottom_rgt_leaf.png",
        "images/banner_leafs.png",
        "images/floating_leaf_rgt.png",
        "images/logo.png",
        "images/slide-img-1",
        "images/slide-img-2",
        "images/slide-img-3",
        "images/slide-img-4",
        "images/slide-img-5",
        "images/slide-img-6",
        "images/Phone-Icon.png",
        "images/sidemenu_top.jpg",
        "images/proposal.jpg",
        "images/join_our_newsletter.jpg",
        "images/FaceBook-Logo.png",
        "images/twitter-logo.png",
        "images/Linkedin-Logo.png"
    );  
});  





//if (document.images) {
//    image1 = new Image();
//    image1.src = "images/banner_bg.jpg"; // Banner Background
//    image2 = new Image();
//    image2.src = "images/bottom_lft_leaf.png"; // Footer Leaf Left
//    image3 = new Image();
//    image3.src = "images/bottom_rgt_leaf.png"; // Footer Leaf Right
//    image4 = new Image();
//    image4.src = "images/banner_leafs.png"; // Banner Leaf
//    image5 = new Image();
//    image5.src = "images/floating_leaf_rgt.png"; // Banner Floating Leaf
//    image6 = new Image();
//    image6.src = "images/logo.png"; // Seed Logo            
//}

if(!window.slider) 
    var slider={};
    slider.data=[
        {"id":"slide-img-1","client":"","desc":""},
        {"id":"slide-img-2","client":"","desc":""},
        {"id":"slide-img-3","client":"","desc":""},
        {"id":"slide-img-4","client":"","desc":""},
        {"id":"slide-img-5","client":"","desc":""},
        {"id":"slide-img-6","client":"","desc":""}            
    ];

function ShowImageBox(ImageURL){
    $('#imgPopup').attr('src', ImageURL);
    $find('mdlImageBox').show();
}

function ShowIframeBox(ImageURL){
    $('#iframePopup').attr('src', ImageURL);
    $find('mdlImageBox').show();
    $('#mdlImageBox_backgroundElement').bind('click', function(){
        $find('mdlImageBox').hide();
    });
}

function ShowNewsIframeBox(ImageURL){
    $('#iframeNewsPopup').attr('src', ImageURL);
    $find('mdlImageNewsBox').show();
    $('#mdlImageNewsBox_backgroundElement').bind('click', function(){
        $find('mdlImageNewsBox').hide();
    });
}

function ShowIframeMobileBox(ImageURL){
    $('#iframeMobilePopup').attr('src', ImageURL);
    $find('mdlMobileImageBox').show();
    $('#mdlMobileImageBox_backgroundElement').bind('click', function(){
        $find('mdlMobileImageBox').hide();
    });
}

function mailpage()
{
    mail_str = "mailto:?subject=A web site recommendation from (Input Your Name or Email)";
    mail_str += " &body=Based on our recent conversation, ";
    mail_str += " I wanted to send you the link to the website for Seedtechnologies. " + " http://www.seedtechnologies.com "; 
    mail_str += " I think you would find their website very helpful.";
    location.href = mail_str;
}

function CalculateTotalWeight(spanWeightID){
    var totalWeight = 0.0;
    var xCurrentWeight;
    var xCurrentQty;
    $('.gridCommoditiesRow').each(function(){
        xCurrentWeight = $(this).find('.gridviewItems_TextBox_Weight').val();
        xCurrentQty = $(this).find('.gridviewItems_TextBox_Quantity').val();
        if (IsNumeric(xCurrentWeight) && IsNumeric(xCurrentQty)){
            totalWeight += parseFloat(xCurrentWeight);// * parseFloat(xCurrentQty);
        }
    });
//    $('.gridviewItems_TextBox_Weight').each(function(){
//        if (IsNumeric($(this).val())) {
//            totalWeight = totalWeight + parseFloat($(this).val());
//        }
//    });
    $('#' + spanWeightID).html(totalWeight.toFixed(2));
}
function CalculateTotalQuantity(spanQuantityID){
    var totalQuantity = 0.0;
    $('.gridviewItems_TextBox_Quantity').each(function(){
        if (IsNumeric($(this).val())) {
            totalQuantity = totalQuantity + parseFloat($(this).val());
        }
    });
    $('#' + spanQuantityID).html(totalQuantity.toString());
}

function CalculateTotalCube(spanCubeID){
    var totalCube = 0.0;
    $('.gridviewItems_TextBox_Cube').each(function(){
        if (IsNumeric($(this).val())) {
            totalCube = totalCube + parseFloat($(this).val());
        }
    });
    $('#' + spanCubeID).html(totalCube.toFixed(2));
}

function CalculateTotalDensity(spanDensityID){
    var totalDensity = 0.0;
    $('.gridviewItems_TextBox_Density').each(function(){
        if (IsNumeric($(this).val())) {
            totalDensity = totalDensity + parseFloat($(this).val());
        }
    });
    $('#' + spanDensityID).html(totalDensity.toFixed(2));
}

function CalculateCube(length, width, height){
    if (IsNumeric(length) && IsNumeric(width) && IsNumeric(height)){
        var cube = 0.0;
        var xLength = parseFloat(length);
        var xWidth = parseFloat(width);
        var xHeight = parseFloat(height);
        cube = (xLength * xWidth * xHeight) / 1728.0;
        return cube;
    } else { return 0.0;}
}

function CalculateDensity(length, width, height, weight, quantity){
    if (IsNumeric(length) && IsNumeric(width) && IsNumeric(height) && IsNumeric(weight) && IsNumeric(quantity)){
        var density = 0.0;
        var xLength = parseFloat(length);
        var xWidth = parseFloat(width);
        var xHeight = parseFloat(height);
        var xWeight = parseFloat(weight);
        var xQuantity = parseFloat(quantity);
        xWeight == 0 || xQuantity == 0 ? density = 0 : density = xQuantity * xWeight * 1728 / (xLength * xWidth * xHeight);
        return density;
    } else { return 0.0;}
}

function IsNumeric(value){
    if (parseFloat(value) == 0 ){
        return true;
    } else if (parseFloat(value)/parseFloat(value) == 1){
        return true;
    }
    return false;
}
function Special_Keydown_Density(event, element){
    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    var modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
    if ((keyCode == 9 || keyCode == 13) && !modifiers){
        $('#divLineItems').scrollLeft(0);
    }
    return true;
}
function FilterTextbox_Numbers_KeyDown(event, element)
{
    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    if (keyCode == 13){
        $(":input:text:eq(" + ($(":input:text").index(element) + 1).toString() + ")").focus();
        event.preventDefault();
    }
    var modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
    isNumeric = (keyCode >= 48 /* KeyboardEvent.DOM_VK_0 */ && keyCode <= 57 /* KeyboardEvent.DOM_VK_9 */) ||
                (keyCode == 44 /* Comma */ ) || 
                /*(keyCode >= 96 /* KeyboardEvent.DOM_VK_NUMPAD0  && keyCode <= 105  KeyboardEvent.DOM_VK_NUMPAD9 ) ||*/
                (keyCode == 8 /*Backspace*/) ||
                (keyCode == 46 /*Delete*/) ||
                (keyCode == 110 /*NUMPAD.*/) ||
                (keyCode == 190 /*Keyboard.*/);
    if (modifiers && isNumeric) return false;

    return isNumeric;
}
function FilterTextbox_Money_KeyDown(event, element)
{
    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    if (keyCode == 9){return true;}
    if (keyCode == 13){
        element.blur();
        $(":input:text:eq(" + ($(":input:text").index(element) + 1).toString() + ")").focus();
        event.preventDefault();
    }
    var modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
    isNumeric = (keyCode >= 48 /* KeyboardEvent.DOM_VK_0 */ && keyCode <= 57 /* KeyboardEvent.DOM_VK_9 */) ||
                (keyCode == 44 /* Comma */ ) || 
                /*(keyCode >= 96 /* KeyboardEvent.DOM_VK_NUMPAD0  && keyCode <= 105  KeyboardEvent.DOM_VK_NUMPAD9 ) ||*/
                (keyCode == 8 /*Backspace*/) ||
                (keyCode == 46 /*Delete*/) ||
                (keyCode == 110 /*NUMPAD.*/) ||
                (keyCode == 190 /*Keyboard.*/);
    if (modifiers && isNumeric) return false;

    return isNumeric;
}
function FilterTextbox_Percent_KeyDown(event, element)
{
    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    if (keyCode == 9){return true;}
    if (keyCode == 13){
        $(":input:text:eq(" + ($(":input:text").index(element) + 1).toString() + ")").focus();
        event.preventDefault();
    }
    var modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
    isNumeric = (keyCode >= 48 /* KeyboardEvent.DOM_VK_0 */ && keyCode <= 57 /* KeyboardEvent.DOM_VK_9 */) ||
                (keyCode == 44 /* Comma */ ) || 
                /*(keyCode >= 96 /* KeyboardEvent.DOM_VK_NUMPAD0  && keyCode <= 105  KeyboardEvent.DOM_VK_NUMPAD9 ) ||*/
                (keyCode == 8 /*Backspace*/) ||
                (keyCode == 46 /*Delete*/) ||
                (keyCode == 110 /*NUMPAD.*/) ||
                (keyCode == 190 /*Keyboard.*/);
    if (modifiers && isNumeric) return false;

    return isNumeric;
}
function FilterTextbox_Pounds_KeyDown(event, element)
{
    var keyCode = (event.which === undefined) ? event.keyCode : event.which;
    if (keyCode == 9){return true;}
    if (keyCode == 13){
        $(":input:text:eq(" + ($(":input:text").index(element) + 1).toString() + ")").focus();
        event.preventDefault();
    }
    var modifiers = (event.altKey || event.ctrlKey || event.shiftKey);
    isNumeric = (keyCode >= 48 /* KeyboardEvent.DOM_VK_0 */ && keyCode <= 57 /* KeyboardEvent.DOM_VK_9 */) ||
                (keyCode == 44 /* Comma */ ) || 
                /*(keyCode >= 96 /* KeyboardEvent.DOM_VK_NUMPAD0  && keyCode <= 105  KeyboardEvent.DOM_VK_NUMPAD9 ) ||*/
                (keyCode == 8 /*Backspace*/) ||
                (keyCode == 46 /*Delete*/) ||
                (keyCode == 110 /*NUMPAD.*/) ||
                (keyCode == 190 /*Keyboard.*/);
    if (modifiers && isNumeric) return false;

    return isNumeric;
}
function RemoveChar(element, character, selectAll)
{
    var value = String(element.value);
    var charValue = String(character);
    var selAll = String(selectAll);
    var evalChar = new RegExp(charValue, "g");
    if (charValue == "$")   // $ has special meaning for replace functions
    {
        element.value = value.replace(/\$/g, "");
    }
    else
    {
        element.value = value.replace(evalChar, "");
    }
    
    if (selAll.toLowerCase() == "true")
    {
        element.focus();
        element.select();
    }
}
function SelectTextBox(element)
{
    var value = $(element).val();
    element.value = value.replace(' ', '');
    element.focus();
    element.select();
}

function FormatStringToCurrency(TextValue)
{
    var IsNegative = false;
    TextValue = TextValue.replace(/,/g, "");
    var sArray = new Array();
    sArray = TextValue.split('.');
    if (sArray.length > 2)
    {
        TextValue = TextValue.substring(0, TextValue.indexOf("."));
        alert("Invalid input, please use one period");
        return TextValue;
    }
    TextValue = TextValue.replace("$", "").replace(" ", "");
    if (TextValue.indexOf("(") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("(", "");
    }
    if (TextValue.indexOf(")") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace(")", "");
    }
    if (TextValue.indexOf("-") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("-", "");
    }
    if (TextValue.indexOf(".") != -1 )
    {
        var index = TextValue.indexOf(".") + 3;
        TextValue = TextValue + "00";   // This line exists to prevent values like { $80. } from returning
        TextValue = TextValue.substring(0, index);
    }
    else
    {
        TextValue = TextValue + ".00";
    }
    sArray = TextValue.split('.');
    
    if (sArray[0].length > 3)
    {
        var stringCount = Math.floor(sArray[0].length/3);
        var startIndex = sArray[0].length % 3;
        var tempString;
        if (startIndex == 0)
        {
            stringCount = stringCount - 1;
            startIndex = 3;
        }
        tempString = sArray[0].substring(0, startIndex);
        //alert(startIndex);
        for (var counter = 0; counter < stringCount; counter = counter + 1)
        {
            //tempString += TextValue.substring(0, startIndex + (counter*3)) + "," + TextValue.substring(startIndex + (counter*3), TextValue.length -1);
            tempString += "," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3);
            //alert("counter: " + counter)
            //alert("," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3));
        }
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;
        if (IsNegative)
        {
            TextValue = "($" + tempString + "." + sArray[1] + ")";
        }
        else
        {
            TextValue = "$" + tempString + "." + sArray[1];
        }
    }
    else
    {  
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;      
        if (IsNegative)
        {
            TextValue = "($" + TextValue + ")";
        }
        else
        {
            TextValue = "$" + TextValue;
        }
        
    }
    
    return TextValue;
}

function FormatToCurrency(element)
{
    var TextValue = String(element.value).replace(/,/g, "");
    var useInnerHTML = false;
    var IsNegative = false;
    
    if (TextValue == "undefined") {TextValue = element.innerHTML; useInnerHTML = true;}
    
    if (TextValue == "undefined") // this function has only been tested against text boxes.
    {
        alert("error");
        return;
    }
    var sArray = new Array();
    sArray = TextValue.split('.');
    if (sArray.length > 2)
    {
        element.value = TextValue.substring(0, TextValue.indexOf("."));
        alert("Invalid input, please use one period");
        return;
    }
    TextValue = TextValue.replace("$", "").replace(" ", "");
    if (TextValue.indexOf("(") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("(", "");
    }
    if (TextValue.indexOf(")") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace(")", "");
    }
    if (TextValue.indexOf("-") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("-", "");
    }
    if (TextValue.indexOf(".") != -1 )
    {
        var index = TextValue.indexOf(".") + 3;
        TextValue = TextValue + "00";   // This line exists to prevent values like { $80. } from returning
        TextValue = TextValue.substring(0, index);
    }
    else
    {
        TextValue = TextValue + ".00";
    }
    sArray = TextValue.split('.');
    
    if (sArray[0].length > 3)
    {
        var stringCount = Math.floor(sArray[0].length/3);
        var startIndex = sArray[0].length % 3;
        var tempString;
        if (startIndex == 0)
        {
            stringCount = stringCount - 1;
            startIndex = 3;
        }
        tempString = sArray[0].substring(0, startIndex);
        //alert(startIndex);
        for (var counter = 0; counter < stringCount; counter = counter + 1)
        {
            //tempString += TextValue.substring(0, startIndex + (counter*3)) + "," + TextValue.substring(startIndex + (counter*3), TextValue.length -1);
            tempString += "," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3);
            //alert("counter: " + counter)
            //alert("," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3));
        }
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;
        if (IsNegative)
        {
            TextValue = "($" + tempString + "." + sArray[1] + ")";
        }
        else
        {
            TextValue = "$" + tempString + "." + sArray[1];
        }
    }
    else
    {  
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;      
        if (IsNegative)
        {
            TextValue = "($" + TextValue + ")";
        }
        else
        {
            TextValue = "$" + TextValue;
        }
        
    }
    
    if (useInnerHTML == false) element.value = TextValue; else element.innerHTML = TextValue;
}

function FormatToPercent(element)
{
    var TextValue = String(element.value).replace(/,/g, "");
    var useInnerHTML = false;
    var IsNegative = false;
    
    if (TextValue == "undefined") {TextValue = element.innerHTML; useInnerHTML = true;}
    
    if (TextValue == "undefined") // this function has only been tested against text boxes.
    {
        alert("error");
        return;
    }
    var sArray = new Array();
    sArray = TextValue.split('.');
    if (sArray.length > 2)
    {
        element.value = TextValue.substring(0, TextValue.indexOf("."));
        alert("Invalid input, please use one period");
        return;
    }
    TextValue = TextValue.replace("$", "").replace(" ", "");
    if (TextValue.indexOf("(") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("(", "");
    }
    if (TextValue.indexOf(")") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace(")", "");
    }
    if (TextValue.indexOf("-") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("-", "");
    }
    if (TextValue.indexOf(".") != -1 )
    {
        var index = TextValue.indexOf(".") + 3;
        TextValue = TextValue + "00";   // This line exists to prevent values like { $80. } from returning
        TextValue = TextValue.substring(0, index);
    }
    else
    {
        TextValue = TextValue + ".00";
    }
    sArray = TextValue.split('.');
    
    if (sArray[0].length > 3)
    {
        var stringCount = Math.floor(sArray[0].length/3);
        var startIndex = sArray[0].length % 3;
        var tempString;
        if (startIndex == 0)
        {
            stringCount = stringCount - 1;
            startIndex = 3;
        }
        tempString = sArray[0].substring(0, startIndex);
        //alert(startIndex);
        for (var counter = 0; counter < stringCount; counter = counter + 1)
        {
            //tempString += TextValue.substring(0, startIndex + (counter*3)) + "," + TextValue.substring(startIndex + (counter*3), TextValue.length -1);
            tempString += "," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3);
            //alert("counter: " + counter)
            //alert("," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3));
        }
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;
        if (IsNegative)
        {
            TextValue = "(" + tempString + "." + sArray[1] + ")%";
        }
        else
        {
            TextValue = tempString + "." + sArray[1] + "%";
        }
    }
    else
    {  
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;      
        if (IsNegative)
        {
            TextValue = "(" + TextValue + ")%";
        }
        else
        {
            TextValue = TextValue + "%";
        }
        
    }
    
    if (useInnerHTML == false) element.value = TextValue; else element.innerHTML = TextValue;
}

function FormatToPounds(element)
{
    var TextValue = String(element.value).replace(/,/g, "");
    var useInnerHTML = false;
    var IsNegative = false;
    
    if (TextValue == "undefined") {TextValue = element.innerHTML; useInnerHTML = true;}
    
    if (TextValue == "undefined") // this function has only been tested against text boxes.
    {
        alert("error");
        return;
    }
    var sArray = new Array();
    sArray = TextValue.split('.');
    if (sArray.length > 2)
    {
        element.value = TextValue.substring(0, TextValue.indexOf("."));
        alert("Invalid input, please use one period");
        return;
    }
    TextValue = TextValue.replace("lbs", "").replace(" ", "");
    if (TextValue.indexOf("(") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("(", "");
    }
    if (TextValue.indexOf(")") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace(")", "");
    }
    if (TextValue.indexOf("-") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("-", "");
    }
    if (TextValue.indexOf(".") != -1 )
    {
        var index = TextValue.indexOf(".") + 3;
        TextValue = TextValue + "00";   // This line exists to prevent values like { $80. } from returning
        TextValue = TextValue.substring(0, index);
    }
    else
    {
        TextValue = TextValue + ".00";
    }
    sArray = TextValue.split('.');
    
    if (sArray[0].length > 3)
    {
        var stringCount = Math.floor(sArray[0].length/3);
        var startIndex = sArray[0].length % 3;
        var tempString;
        if (startIndex == 0)
        {
            stringCount = stringCount - 1;
            startIndex = 3;
        }
        tempString = sArray[0].substring(0, startIndex);
        //alert(startIndex);
        for (var counter = 0; counter < stringCount; counter = counter + 1)
        {
            //tempString += TextValue.substring(0, startIndex + (counter*3)) + "," + TextValue.substring(startIndex + (counter*3), TextValue.length -1);
            tempString += "," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3);
            //alert("counter: " + counter)
            //alert("," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3));
        }
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;
        if (IsNegative)
        {
            TextValue = "(" + tempString + "." + sArray[1] + ") lbs";
        }
        else
        {
            TextValue = tempString + "." + sArray[1] + " lbs";
        }
    }
    else
    {  
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;      
        if (IsNegative)
        {
            TextValue = "(" + TextValue + ") lbs";
        }
        else
        {
            TextValue = TextValue + " lbs";
        }
        
    }
    
    if (useInnerHTML == false) element.value = TextValue; else element.innerHTML = TextValue;
}

function FormatToNumber(element, decimalPlaces)
{
    if (decimalPlaces == null){decimalPlaces = 2;}
    var TextValue = String(element.value).replace(/,/g, "");
    var useInnerHTML = false;
    var IsNegative = false;
    var xTrailingZeros = '';
    
    if (TextValue == "undefined") {TextValue = element.innerHTML; useInnerHTML = true;}
    
    if (TextValue == "undefined") // this function has only been tested against text boxes.
    {
        alert("error");
        return;
    }
    TextValue = TextValue.replace("$", "").replace(" ", "");
    TextValue = String( Math.round( parseFloat(TextValue) * Math.pow(10, parseInt(decimalPlaces)) ) / Math.pow(10, parseInt(decimalPlaces)) );
    for(i = 0; i < decimalPlaces; i++){
        xTrailingZeros += '0';
    }
    
    var sArray = new Array();
    sArray = TextValue.split('.');
    if (sArray.length > 2)
    {
        element.value = TextValue.substring(0, TextValue.indexOf("."));
        alert("Invalid input, please use one decimal");
        return;
    }
    if (TextValue.indexOf("(") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("(", "");
    }
    if (TextValue.indexOf(")") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace(")", "");
    }
    if (TextValue.indexOf("-") != -1)
    {
        IsNegative = true;
        TextValue = TextValue.replace("-", "");
    }
    if (TextValue.indexOf(".") != -1 )
    {
        var index = TextValue.indexOf(".") + 3;
        TextValue = TextValue + xTrailingZeros;   // This line exists to prevent values like { $80. } from returning
        TextValue = TextValue.substring(0, index);
    }
    else
    {
        if(xTrailingZeros.toString().length > 0)
            TextValue = TextValue + "." + xTrailingZeros;
    }
    sArray = TextValue.split('.');
    
    if (sArray[0].length > 3)
    {
        var stringCount = Math.floor(sArray[0].length/3);
        var startIndex = sArray[0].length % 3;
        var tempString;
        if (startIndex == 0)
        {
            stringCount = stringCount - 1;
            startIndex = 3;
        }
        tempString = sArray[0].substring(0, startIndex);
        //alert(startIndex);
        for (var counter = 0; counter < stringCount; counter = counter + 1)
        {
            //tempString += TextValue.substring(0, startIndex + (counter*3)) + "," + TextValue.substring(startIndex + (counter*3), TextValue.length -1);
            tempString += "," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3);
            //alert("counter: " + counter)
            //alert("," + sArray[0].substring(((counter * 3) + startIndex), ((counter * 3) + startIndex) + 3));
        }
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;
        if (IsNegative)
        {
            if(xTrailingZeros.toString().length > 0)
                TextValue = "- " + tempString + "." + sArray[1] + "";
            else
                TextValue = "- " + tempString;
        }
        else
        {
            if(xTrailingZeros.toString().length > 0)
                TextValue = "" + tempString + "." + sArray[1];
            else
                TextValue = "" + tempString;
        }
    }
    else
    {  
        if (TextValue.indexOf(".") == 0)
            TextValue = "0" + TextValue;      
        if (IsNegative)
        {
            TextValue = "- " + TextValue + "";
        }
        else
        {
            TextValue = "" + TextValue;
        }
        
    }
    
    if (useInnerHTML == false) element.value = TextValue; else element.innerHTML = TextValue;
}

function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

function SetSearchText(objectID, text)
{
    if (objectID.toString().indexOf('#') == -1)
        objectID = '#' + objectID;
    $(objectID).val(text);
    $(objectID).css('color', '#cccccc');
    $(objectID).bind('focus', function(){
        if ($(objectID).val() == text)
        {
            $(objectID).val('');
            $(objectID).css('color', '#000000');
        }
        $(objectID).select();
    }).bind('blur', function(){
        if ($(objectID).val().toString().trim() == '')
        {
            $(objectID).val(text);
            $(objectID).css('color', '#cccccc');
        }
    });
}
    var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
function ShowContactDiv(divID)
{
    $('#' + divID).stop(false, true).show('expand');//, function(){
}
function HideContactDiv(divID)
{
    $('#' + divID).stop(false, true).hide("collapse");
}
function FormatPhone(inputString)
{
    inputString = inputString.replace(/\)/g, '').replace(/-/g, '').replace(/ /g, '').replace(/\)/g, '');
    
    if( IsNumeric(inputString) && inputString.length == 10 ){
        return '(' + inputString.substring(0, 3) + ') ' + inputString.substring(2, 5) + '-' + inputString.substring(5, 9)
    }else{
        return 'Invalid';
    }
}
