﻿function clearValues(element) {
   element.value = "";
}

function clearField(textBox, startValue) {
    if (textBox.value.indexOf(startValue) != -1) {
        textBox.value = '';
    }
}

function toggleValidator(validator,status) {

    validator.enabled = status;  
    ValidatorUpdateDisplay(validator);

}

function formatCurrency(num) {
    num = isNaN(num) || num === '' || num === null ? 0.00 : num;
    var fixed = parseFloat(num).toFixed(2);
    var numParts = fixed.split('.');
    num = numParts[1] === '00' ? numParts[0] : fixed;
    return num;
}

function changeClass(element,value,oldvalue) {

   if (element.className) {

      var currentclass = element.className;

      if (currentclass != value) {

         var newclass = currentclass.replace(oldvalue,value);
         element.className = newclass;

      }

   }

}

function poptastic(url) {
    var newwindow;
    newwindow = window.open(url, 'name', 'height=380,width=620,scrollbars=no,resizable=yes');
    if (window.focus) { newwindow.focus() }
}

function openBrWindow(theURL, winName, features) {
    var wHFHI = window.open(theURL, winName, features);
    wHFHI.focus();
}


function setFocus(fld) {
    var fobj;
    fobj = document.getElementById[fld];
    if (fobj)
        if (!fobj.disabled)
            fobj.focus();
}

function pk_fixnewlines_textarea(val) {
    // Adjust newlines so can do correct character counting for MySQL. MySQL counts a newline as 2 characters.
    if (val.indexOf('\r\n') != -1)
        ; // this is IE on windows. Puts both characters for a newline, just what MySQL does. No need to alter
    else if (val.indexOf('\r') != -1)
        val = val.replace(/\r/g, "\r\n");        // this is IE on a Mac. Need to add the line feed
    else if (val.indexOf('\n') != -1)
        val = val.replace(/\n/g, "\r\n");        // this is Firefox on any platform. Need to add carriage return
    else
        ;                                           // no newlines in the textarea  
    return val;
}
