///////////////create prototype functions
///strings
//////////
String.prototype.trim = function()
{
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function()
{
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function()
{
    return this.replace(/\s+$/, "");
}
String.prototype.replaceWS = function()
{
    return this.replace(/\s/g, "");
}
String.prototype.replaceThis = function(c)
{
    var re = new RegExp(c + '+')
    return this.replace(re, "");
}
String.prototype.replaceWith = function(replaceThis, withThat)
{
    var re = "";
    if (typeof replaceThis == "string") 
    {
        replaceThis = new Array(replaceThis);
    }
    re = new RegExp('(\\' + replaceThis.join('|\\') + ')', 'gi');
    return this.replace(re, withThat);
}
String.prototype.repeat = function(l)
{
    return new Array(l + 1).join(this);
}
String.prototype.capFirst = function(c)
{
    var words = c.toLowerCase().split(" ");
    var capWords = '';
    var spacer = ' ';
    var wordLen = words.length;
    
    for (var x = 0; x < wordLen; x++) 
    {
        if (x == wordLen - 1) 
        {
            spacer = '';
        }
        capWords += words[x].substr(0, 1).toUpperCase();
        capWords += words[x].substr(1) + spacer;
    }
    return capWords;
}
String.prototype.toBoolean = function()
{
    if (this.toLowerCase() == 'false') 
    {
        return false;
    }
    else 
    {
        return true;
    }
}
Math.Round = function(num, places)
{
    nums = "1";
    for (x = 0; x < places; x++) 
    {
        nums += '0';
    }
    nums = parseInt(nums);
    return newNums = Math.round(num * nums) / nums;
}
//////////
///objects
//////////


//////////
///arrays
//////////

/*Array.prototype.indexOf = function(searchElement, fromIndex)
 {
 var i = (fromIndex < 0) ? this.length + fromIndex : fromIndex || 0;
 for (; i < this.length; i++)
 if (searchElement === this[i])
 return i;
 return -1
 }*/
/////////////////////////////////////////////
function windowDims()
{
    var myWidth = 0, myHeight = 0;
	
    if (typeof(window.innerWidth) == 'number') 
	{
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else 
	{
		if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
		{
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		}
		else 
		{
			if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
			{
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
		}
	} 
	var arr = new Array(myWidth,myHeight);
	return arr; 
}

function Mprompt(yesFunc, noFunc, cancelFunc)
{
    var self = this;
    this.yesFunct = yesFunc;
    this.noFunct = noFunc;
    this.cancelFunct = cancelFunc;
    var xPos = 100;
    var yPos = 200;
    var br = document.createElement('br');
    var space = document.createTextNode('\u00a0');
	var windowW = windowDims()[0];
	var windowH = windowDims()[1];	
	yPos = (parseInt(windowH) / 2) + parseInt(findScrollY($(window)));
	xPos = (parseInt(windowW) / 2.5);
    
    if ($('opaqPromptBack')) 
    {
        $('opaqPromptBack').show();
    }
    
    this.msgDiv = document.createElement('div');
    this.msgDiv.style.position = 'absolute';
    this.msgDiv.style.color = '#ffffff';
    this.msgDiv.style.border = '2px solid #ffffff';
    this.msgDiv.style.backgroundColor = '#6699CC';
    this.msgDiv.style.textAlign = 'center';
           
    this.msgDiv.style.top = yPos + 'px';
    this.msgDiv.style.left = parseInt(document.body.offsetWidth) / 2.5 + 'px';
    this.msgDiv.style.padding = '10px 20px 10px 20px';
    this.msgDiv.style.zIndex = 500;
    
    this.label = document.createElement('label');
    this.label.appendChild(document.createTextNode(''));
    this.label.style.fontWeight = 'bold';
    
    this.textInput = document.createElement('input');
    this.textInput.setAttribute('type', 'text');
    this.textInput.setAttribute('name', 'msgText');
    this.textInput.setAttribute('value', '');
    this.textInput.style.width = '160px';
    this.textInput.onkeypress = function(e)
    {
        var k = document.layers ? e.which : document.all ? event.keyCode : e.keyCode;
        
        if (k == 13) 
        {
            self.close();
            if (self.yesFunct) 
            {
                window[self.yesFunct](this.value);
            }
            delete self;
        }
    }
    
    this.textInputHolder = document.createElement('p');
    this.textInputHolder.setAttribute('id', 'textInputHolder');
    this.textInputHolder.appendChild(this.textInput);
    
    this.yesBtn = document.createElement('input');
    this.yesBtn.setAttribute('type', 'button');
    this.yesBtn.setAttribute('value', 'Yes');
    this.yesBtn.setAttribute('class', 'promptButton');
    this.yesBtn.setAttribute('name', 'Yes');
    this.yesBtn.onclick = function()
    {
        self.close();
        if (self.yesFunct) 
        {
            window[self.yesFunct](self.textInput.value);
        }
        delete self;
    }
    
    this.noBtn = document.createElement('input');
    this.noBtn.setAttribute('type', 'button');
    this.noBtn.setAttribute('value', 'No');
    this.noBtn.setAttribute('class', 'promptButton');
    this.noBtn.setAttribute('id', 'promptButton');
    this.noBtn.setAttribute('name', 'No');
    this.noBtn.onclick = function()
    {
        self.close();
        if (self.noFunct) 
        {
            window[self.noFunct]();
        }
        delete self;
    }
    
    this.cancelBtn = document.createElement('input');
    this.cancelBtn.setAttribute('type', 'button');
    this.cancelBtn.setAttribute('value', 'Cancel');
    this.cancelBtn.setAttribute('class', 'promptButton');
    this.cancelBtn.setAttribute('name', 'Cancel');
    this.cancelBtn.onclick = function()
    {
        self.close();
        if (self.cancelFunct) 
        {
            window[self.cancelFunct]();
        }
        delete self;
    }
    
    this.buttonHolder = document.createElement('p');
    this.buttonHolder.setAttribute('id', 'buttonHolder');
    this.buttonHolder.appendChild(this.yesBtn);
    this.buttonHolder.appendChild(space);
    this.buttonHolder.appendChild(this.noBtn);
    this.buttonHolder.appendChild(space.cloneNode(true));
    this.buttonHolder.appendChild(this.cancelBtn);
    
    this.msgDiv.appendChild(this.label);
    this.msgDiv.appendChild(this.textInputHolder);
    this.msgDiv.appendChild(this.buttonHolder);
}

Mprompt.prototype = 
{
    msg: function(msg)
    {
        this.label.innerHTML = msg;
    },
    
    show: function()
    {
        document.body.appendChild(this.msgDiv);
    },
    
    close: function()
    {
        this.msgDiv.style.display = 'none';
        if ($('opaqPromptBack')) 
        {
            $('opaqPromptBack').hide();
        }
    },
    
    hideElement: function(elem)
    {
        elem.style.display = 'none';
    }
}

function baseName(path, suffix)
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ash Searle (http://hexmen.com/blog/)
    // +   improved by: Lincoln Ramsay
    // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
    
    var b = path.replace(/^.*[\/\\]/g, '');
    if (typeof(suffix) == 'string' && b.substr(-suffix.length) == suffix) 
    {
        b = b.substr(0, b.length - suffix.length);
    }
    return b;
}

function testEmail(email)
{
    checkEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    return checkEmail.test(email);
}

function changeSelects(changeToThis, inThis)
{
    var selectObj = $(inThis);
    
    for (x = 0; x < selectObj.options.length; x++) 
    {
        if (selectObj.options[x].value == changeToThis) 
        {
            selectObj.options[x].selected = true;
        }
    }
    
    return;
}

function findHours(t)
{
    ampm = t < 12 ? "AM" : "PM";
    t == 0 ? t = 12 : t > 12 ? t = t - 12 : t = t;
    return t;
}

function getFractionResult(val, decPlaces)
{
    var divPos = '';
    var divThis = '';
    var answer = '';
    dashPos = val.indexOf('-');
    divPos = val.indexOf('/');
    addTo = 0;
    if (dashPos > -1) 
    {
        addTo = val.substr(0, dashPos);
    }
    
    divThis = val.substr(dashPos + 1, divPos - (dashPos + 1));
    byThis = val.substr(divPos + 1);
    answer = parseInt(addTo) + (parseInt(divThis) / parseInt(byThis));
    answer = answer.toFixed(decPlaces);
    
    return answer;
}

function getElemID(e)
{
    var el = '';
    var elId = '';
    
    if (window.event && window.event.srcElement) 
    {
        el = window.event.srcElement;
        try 
        {
            if (!e.srcElement) 
            {
                el = 'error';
                return el;
            }
        } 
        catch (err) 
        {
            //alert(err);
        }
    }
    if (e && e.target) 
    {
        el = e.target;
    }
    if (!el) 
    {
        el = 'error';
        return el;
    }
    
    elId = el.id;
    return elId;
}

function getKeyPressed(e)
{
    var key = '';
    if (!e) 
    {
        var e = window.event;
    }
    if (e.keyCode) 
    {
        key = e.keyCode;
    }
    else 
        if (e.which) 
        {
            key = e.which;
        }
    
    return key;
}

function convertUnixTime(t)
{
    var months = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    var monthsNum = new Array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
    var days = new Array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
    
    theDate = new Date(t * 1000);
    mo = monthsNum[theDate.getMonth()];
    da = theDate.getDate();
    yr = theDate.getFullYear().toString().substr(2, 2);
    hr = findHours(theDate.getHours());
    hr < 10 ? hr = '0' + hr : hr = hr;
    mi = theDate.getMinutes();
    mi < 10 ? mi = '0' + mi : mi = mi;
    se = theDate.getSeconds();
    se < 10 ? se = '0' + se : se = se;
    //nDate = mo+'/'+da+'/'+yr+'--'+hr+':'+mi+':'+se+':'+ampm;
    nDate = mo + '-' + da + '-' + yr + '--' + hr + ':' + mi + ':' + se + ':' + ampm;
    
    return nDate;
}

function addEvent(elmnt, evType, functionName, useCapture)
{
    //if(!elmnt){alert(functionName + '  '+ evType);}
    
    try 
    {
        if (elmnt.addEventListener) 
        {
            //try{
            elmnt.addEventListener(evType, functionName, useCapture);
            //}catch(e){alert(e+'\r\n id='+elmnt.id+'\r\n function='+functionName);}
            return true;
        }
        else 
            if (elmnt.attachEvent) 
            {
                var r = elmnt.attachEvent('on' + evType, functionName);
                return r;
            }
            else 
            {
                elmnt['on' + evType] = functionName;
            }
        
    } 
    catch (err) 
    {
        alert(err + '\r\n id=' + elmnt.id + '\r\n function=' + functionName);
    }
}

function blinkText(elemtId)
{
    textElem = document.getElementById(elemtId);
    textVal = textElem.innerHTML;
    zCount = 0;
    //textElem.style.color = "#FFFFFF";
    bText = setInterval("blinkIt(textElem)", 1000);
    
}

function blinkIt(textObj)
{
    zCount++;
    
    if (textObj.style.color != 'rgb(204, 51, 51)') 
    {
        textObj.style.color = '#CC3333';
    }
    else 
    {
        textObj.style.color = '#FFFFFF';
    }
    
    if (zCount == 4) 
    {
        clearInterval(bText);
    }
}


function countLetters(e)
{
    var el = '';
    if (window.event && window.event.srcElement) 
    {
        el = window.event.srcElement;
        thisKey = window.event.keyCode
    }
    if (e && e.target) 
    {
        el = e.target;
        thisKey = e.which
    }
    if (!el) 
    {
        el = 'no el';
    }
    
    var elId = el.id;
    useragent = navigator.userAgent;
    useragent = useragent.toLowerCase();
    opera1 = useragent.indexOf("opera");
    onemore = 1;
    if (opera1 > -1) 
    {
        onemore = 0
    }
    comments = document.getElementById(elId).value
    if (thisKey != 13) //&& thisKey != 32)
    {
        if (thisKey == 8) 
        {
            document.getElementById('lineno').value = ((comments.length + 1) - 1) - onemore;
        }
        else 
        {
            document.getElementById('lineno').value = comments.length + 1;
        }
    }
}

//////
function changeStates(e)
{

    var elId = getElemID(e) == 'error' ? e : getElemID(e);
    stateVal = document.getElementById(elId).value.trim();
    
    switch (stateVal)
    {
        case "Canada":
            document.getElementById('prov').style.display = '';
            document.getElementById('states').style.display = 'none';
            document.getElementById('states').value = '--';
            document.getElementById('statesAlt').style.display = 'none';
            document.getElementById('statesAlt').value = '';
            break;
        case "U.S.A.":
            document.getElementById('states').style.display = '';
            document.getElementById('statesAlt').style.display = 'none';
            document.getElementById('statesAlt').value = '';
            document.getElementById('prov').style.display = 'none';
            document.getElementById('prov').value = '--';
            break;
        default:
            document.getElementById('statesAlt').style.display = '';
            document.getElementById('states').style.display = 'none';
            document.getElementById('states').value = '--';
            document.getElementById('prov').style.display = 'none';
            document.getElementById('prov').value = '--';
    }
}

function yesNo(msg,func,backColor,borderColor)
{
    $('opaqBack').show();
    if (!backColor) 
    {
        backColor = '#cc0033';
    }
    if (!borderColor) 
    {
        borderColor = '#ffffff';
    }
    var self = this;
    this.yes = false;
    this.msgDiv = document.createElement('div');
    this.msgDiv.setAttribute('id', 'yesNoMsg');
    this.msgDiv.setAttribute('class', 'yesNoMsgBox');
    //this.msgDiv.setAttribute('style','position: absolute; text-align: center;padding: 10px;top: 400px;left: 400px;z-index: 40;border:2px solid white;background-color:'+backColor+';');
    this.msgDiv.style.backgroundColor = backColor;// = 'position: absolute; text-align: center;padding: 10px;top: 400px;left: 400px;z-index: 40;border:2px solid white;background-color:'+backColor+';';]
    this.msgDiv.style.textAlign = 'center';
    this.msgDiv.style.top = '400px';
    this.msgDiv.style.left = '400px';
    this.msgDiv.style.padding = '10px';
    this.msgDiv.style.zIndex = '40';
    this.msgDiv.style.position = 'absolute';
    this.msgDiv.style.color = '#ffffff';
    this.msgDiv.style.borderWidth = '2px';
    this.msgDiv.style.borderStyle = 'solid';
    this.msgDiv.style.borderColor = borderColor;
    
    msg = unescape(msg);
    var msgLabel = document.createElement('label');
    //msgLabel.appendChild(document.createTextNode(msg));
    msgLabel.setAttribute('class', 'medwhite');
    msgLabel.setAttribute('id', 'yesNoMsgLabel');
    
    
    var br = document.createElement('br');
    var br2 = document.createElement('br');
    var space = document.createElement('span');
    space.setAttribute('class', 'space2');
    space.appendChild(document.createTextNode(' '));
    
    var yesButton = document.createElement('input');
    yesButton.setAttribute('type', 'button');
    yesButton.setAttribute('id', 'yesNoYES');
    yesButton.setAttribute('value', 'Yes');
    yesButton.onclick = function()
    {
        func();
        $(self.msgDiv).hide();
        $('opaqBack').hide();
    }
    
    var noButton = document.createElement('input');
    noButton.setAttribute('type', 'button');
    noButton.setAttribute('id', 'yesNoNo');
    noButton.setAttribute('value', 'No');
    noButton.onclick = function()
    {
        $(self.msgDiv).hide();
        $('opaqBack').hide();
    }
    
    this.msgDiv.appendChild(msgLabel);
    this.msgDiv.appendChild(br);
    this.msgDiv.appendChild(br2);
    this.msgDiv.appendChild(yesButton);
    this.msgDiv.appendChild(space);
    this.msgDiv.appendChild(noButton);
    document.body.appendChild(this.msgDiv);
    $('yesNoMsgLabel').innerHTML = msg;
    
}

function mousePos(e)
{
    var IE = document.all ? true : false;
    
    if (IE) 
    {
        xMousePos = event.clientX + document.body.scrollLeft;
        yMousePos = event.clientY + document.body.scrollTop;
    }
    else 
    {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
    }
}

function showMessages(e, msg, styling, imgInfo)
{
    var elId = getElemID(e) == 'error' ? e : getElemID(e);
    var posX = xMousePos;
    var posY = yMousePos;
    var allImages = '';
    
    var imgStr = '';
    //styling color,backgroundColor,border  -- the border should be in this form 2px solid #fffff
    var style = styling.split(',');
    var textColor = style[0];
    var borderStyle = style[2];
    var bgColor = style[1];
    
    if (textColor == '') 
    {
        textColor = '#ffffff';
    }
    if (bgColor == '') 
    {
        bgColor = '#666666';
    }
    if (borderStyle == '') 
    {
        borderStyle = '2px solid #ffffff';
    }
    
    if (imgInfo) 
    {
        allImages = imgInfo.split(',');
        for (var x = 0; x < allImages.length; x++) 
        {
            imgStr += '<br / ><img id="tmpImg"+x src="/images/' + allImages[x] + '" alt="" />';
        }
    }
    $('messages').style.backgroundColor = bgColor;
    $('messages').style.color = textColor;
    $('messages').style.fontWeight = 'bold';
    $('messages').style.border = borderStyle;
    $('messages').innerHTML = msg + imgStr;
    
    if (browserName == 'msie') 
    {
        $('messages').style.top = parseInt(posY) - 10 + parseInt(findScrollY(window)) + 'px';
        $('messages').style.left = parseInt(posX) + 20 + parseInt(findScrollX($('customGearDiv'))) + 'px';
    }
    else 
    {
        $('messages').style.top = parseInt(posY) - 10 + 'px';
        $('messages').style.left = parseInt(posX) + 20 + 'px';
    }
    $('messages').show();
    
}

function hideMessages(e)
{
    $('messages').hide();
}

function aKeyWasPressed(e)
{
    var keyedValue = e.keyCode;
}

function enterKeyhandle(e)
{
    if (!e) 
    {
        var e = window.event;
    }
    if (e.keyCode) 
    {
        key = e.keyCode;
    }
    else 
        if (e.which) 
        {
            key = e.which;
        }
    
    enterKeyResult(key);
}

function showHide(elementId)
{
    if (document.getElementById(elementId).style.display != 'none') 
    {
        ShowElementObj = document.getElementById(elementId).style.display = 'none'
    }
    else 
    {
        HideElementObj = document.getElementById(elementId).style.display = ''
    }
}

function showHideLink(e)
{
    var elId = getElemID(e);
    
    elId == 'largerFiles' ? showHide('largerFilesLinks') : abc = 'none';
    elId == 'eLink' ? showHide('largerFilesLinks') : abc = 'none';
    
}

///////make a form's element visible or hidden
function showHideElement(ShowElementName, HideElementName)
{
    if (ShowElementName != 'none') 
    {
        ShowElementObj = document.getElementById(ShowElementName).style.display = ''
    }
    if (HideElementName != 'none') 
    {
        HideElementObj = document.getElementById(HideElementName).style.display = 'none'
    }
}

///////get the left position of an element
function findPosX(obj)
{
    var curleft = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else 
        if (obj.x) 
        {
            curleft += obj.x;
        }
    
    return curleft;
}

///////get the top postion of an element
function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent) 
    {
        while (obj.offsetParent) 
        {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else 
        if (obj.y) 
        {
            curtop += obj.y;
        }
    return curtop;
}

function findScrollX(obj)
{
    var oX, oY;
    if (obj.pageYOffset) // all except Explorer
    {
        oX = obj.pageXOffset;
    }
    else 
    {
        if (document.documentElement && document.documentElement.scrollTop) 
        // Explorer 6 Strict
        {
            oX = obj.scrollLeft;
        }
        else 
            if (document.body) // all other Explorers
            {
                oX = document.body.scrollLeft;
                if (oX == '0') 
                {
                    oX = document.documentElement.scrollLeft
                }
            }
    }
    return oX;
}

function findScrollY(obj)
{
    var oY;
    if (obj.pageYOffset) // all except Explorer
    {
        oY = obj.pageYOffset;
    }
    else 
    {
        if (document.documentElement && document.documentElement.scrollTop) 
        // Explorer 6 Strict
        {
            oY = document.documentElement.scrollTop;
        }
        else 
            if (document.body) // all other Explorers
            {
                oY = document.body.scrollTop;
            }
    }
    
    return oY;
}

function getPageSize()
{

    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else 
        if (document.body.scrollHeight > document.body.offsetHeight) 
        { // all but Explorer Mac
            xScroll = document.body.scrollWidth;
            yScroll = document.body.scrollHeight;
        }
        else 
        { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
            xScroll = document.body.offsetWidth;
            yScroll = document.body.offsetHeight;
        }
    
    var windowWidth, windowHeight;
    if (self.innerHeight) 
    { // all except Explorer
        windowWidth = self.innerWidth;
        windowHeight = self.innerHeight;
    }
    else 
        if (document.documentElement && document.documentElement.clientHeight) 
        { // Explorer 6 Strict Mode
            windowWidth = document.documentElement.clientWidth;
            windowHeight = document.documentElement.clientHeight;
        }
        else 
            if (document.body) 
            { // other Explorers
                windowWidth = document.body.clientWidth;
                windowHeight = document.body.clientHeight;
            }
    
    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) 
    {
        pageHeight = windowHeight;
    }
    else 
    {
        pageHeight = yScroll;
    }
    
    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) 
    {
        pageWidth = windowWidth;
    }
    else 
    {
        pageWidth = xScroll;
    }
    
    
    arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight)
    return arrayPageSize;
}


///////change an elements background color
function changeBackground(colorIt, elementname)
{
    document.getElementById(elementname).style.backgroundColor = colorIt;
    return;
}

///////change input background color
function changeBackColor(e)
{
    var elId = getElemID(e);
    
    formNames = document.getElementsByTagName("form").item(0).name;
    
    if (e.type == 'focus') 
    {
        //use switch in order to add more forms later
        switch (formNames)
        {
            case 'rfqform':
                bColor = '#333333';
                break
            default:
                bColor = '#FF6666';
        }
        document.getElementById(elId).style.backgroundColor = bColor;
    }
    if (e.type == 'blur') 
    {
        switch (formNames)
        {
            case 'rfqform':
                bColor = '#666666';
                break
            default:
                bColor = '#9999FF';
        }
        document.getElementById(elId).style.backgroundColor = bColor;
    }
    //changeBackground(bColor,elId);
    return;
}

///////toggle between view and hide instructions on a page
function viewInstructions(toggleView)
{
    if (toggleView == 'hide') 
    {
        document.getElementById('instructions').style.display = 'none'
        document.getElementById('hideInst').style.display = 'none'
        document.getElementById('viewInst').style.display = ''
        if (document.forms[0].name == 'partlookup') 
        {
            positionElements('dontshow');
        }
    }
    else 
    {
        document.getElementById('instructions').style.display = ''
        document.getElementById('viewInst').style.display = 'none'
        document.getElementById('hideInst').style.display = ''
        if (document.forms[0].name == 'partlookup') 
        {
            positionElements('dontshow');
        }
    }
}

///////call this function to get the radio button that was checked. radioButtons is (document.formname.radioButtonName) from the form
function findRadioBtn(radioButtons)
{
    for (counter = 0; counter < radioButtons.length; counter++) 
    {
        if (radioButtons[counter].checked) 
        {
            findRadioBtn.prototype.buttonValue = radioButtons[counter].value
        }
    }
}

///////use this function to check the radio button from it's label
function checkLabelsRadio(radioToCheck)
{
    document.getElementById(radioToCheck).checked = "true"
}

function changeRadios(e)
{
    var elId = getElemID(e);
    
    switch (elId)
    {
        case 'inchesLabel':
            document.getElementById('inches').checked = true;
            break;
        case 'mmLabel':
            document.getElementById('mm').checked = true;
            break;
        case 'normPitch':
            document.getElementById('ndp').checked = true;
            break;
        case 'pa1':
            document.getElementById('pa14deg').checked = true;
            break;
        case 'pa2':
            document.getElementById('pa20deg').checked = true;
            break;
        case 'pitchName1Label':
            document.getElementById('pitchName1').checked = true;
            break;
        case 'pitchName2Label':
            document.getElementById('pitchName2').checked = true;
            break;
        case 'pitchName3Label':
            document.getElementById('pitchName3').checked = true;
            break;
        case 'emailQuoteLabel':
            document.getElementById('emailQuote').checked = true;
            break;
        case 'faxQuoteLabel':
            document.getElementById('faxQuote').checked = true;
            break;
    }
}

/*function changestates(stateval)
 {
 switch(stateval)
 {
 case "Canada" :
 document.forms[0].prov.style.display = ''
 document.forms[0].mstates.style.display = 'none'
 document.forms[0].mstates.value = '--'
 document.forms[0].mstatesalt.style.display = 'none'
 document.forms[0].mstatesalt.value = ''
 break
 case  "U.S.A." :
 document.forms[0].mstates.style.display = ''
 document.forms[0].mstatesalt.style.display = 'none'
 document.forms[0].mstatesalt.value = ''
 document.forms[0].prov.style.display = 'none'
 document.forms[0].prov.value = '--'
 break
 default:
 document.forms[0].mstatesalt.style.display=''
 document.forms[0].mstates.style.display = 'none'
 document.forms[0].mstates.value = '--'
 document.forms[0].prov.style.display='none'
 document.forms[0].prov.value = '--'
 }
 }*/
function changeBtn(picElement, picName)
{
    document[picElement].src = eval(picName + "Img.src");
}

function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) 
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) 
            return null;
    }
    else 
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) 
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function createCookie(name, value, days)
{
    if (days) 
    {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else 
    {
        var expires = "";
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) 
    {
        var c = ca[i];
        while (c.charAt(0) == ' ') 
            c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) 
            return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name)
{
    createCookie(name, "", -1);
}

function clearText(e)
{
    var elId = getElemID(e);
    var textVal = document.getElementById(elId);
    if (textVal.value.toLowerCase() == 'search') 
    {
        textVal.value = '';
    }
}

function changeText(e)
{
    var elId = getElemID(e);
    textToUse = document.getElementById(elId).innerHTML;
    
    if (textToUse.indexOf('hide') > -1) 
    {
        textToUse = textToUse.replace('hide', 'view');
    }
    else 
        if (textToUse.indexOf('view') > -1) 
        {
            textToUse = textToUse.replace('view', 'hide');
        }
    
    if (textToUse.indexOf('Minimize') > -1) 
    {
        textToUse = textToUse.replace('Minimize', 'Maximize');
    }
    else 
        if (textToUse.indexOf('Maximize') > -1) 
        {
            textToUse = textToUse.replace('Maximize', 'Minimize');
        }
    
    document.getElementById(elId).innerHTML = textToUse;
}
