function LTrim(s) {
	return s.replace(/^\s*/, '');
}
function RTrim(s) {
	return s.replace(/\s*$/, '');
}
function Trim(s) {
	return RTrim(LTrim(s));
}
function IsEmail(email){
    address = email;
    check1 = false;
    check2 = false;
    check3 = false;

    if (address.indexOf("@") > 0){check1 = true}
    if ((address.lastIndexOf(".") == address.length -4) || (address.lastIndexOf(".") == address.length -3) || (address.lastIndexOf(".") == address.length -5)) {check2 = true}
        
    //check ending chars
    first = address.charAt(address.length -3);
    second = address.charAt(address.length -2);
    third = address.charAt(address.length -1);
        
    suffix = first + second + third;
        
    if (suffix.toLowerCase() == "com" || suffix.toLowerCase() == "net" || suffix.toLowerCase() == "edu" || suffix.toLowerCase() == "gov" || suffix.toLowerCase() == "org" || suffix.toLowerCase() == "mil" || suffix.toLowerCase() == "us" || suffix.toLowerCase() == "biz" || suffix.toLowerCase() == "nfo" || suffix.toLowerCase() == ".tv" || suffix.toLowerCase() == ".cc" || suffix.toLowerCase() == ".bz"){check3 = true}

    //final check
    if (check1 == true & check2 == true & check3 == true) {
        return true;
    } else {
        return false;
    }
    //return (email.match(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i) != null);
}
function PhoneFormat(phone) {
    p = phone.replace(/^[1|0]/,'');
    //p = p.replace(/[^0-9]/gi,'');
    for(i = 0; i <= phone.length; i++) {
        p = p.replace(/[^0-9]/,'');
    }
    if (p.length == 10) {
        p = '(' + p.substring(0,3) + ')' + ' ' + p.substring(3,6) + '-' + p.substring(6,10);
    } else if (p.length == 7) {
        alert('Please include the area code');
        p = '';
    } else {
        alert('Invalid Format: Phone Number\n\nx = 1 thru 9\ny = 0 thru 9\n(xyy) yyy-yyyy');
        p = '';
    }
    return p;
}
function ExpireDateFormat(ccexpdate) {
    dt = Trim(ccexpdate);
    for (i=0; i<ccexpdate.length; i++) {
        dt = dt.replace(/[\.|\s|\/|\\]/,'-');
    }
    if ((arr = dt.split('-')).length == 2) {
        if (arr[0].length <= 2) {
            arr[0] = (arr[0].length == 1) ? '0' + arr[0] : arr[0];
            arr[1] = (arr[1].length == 2) ? '20' + arr[1] : arr[1];
            dt = arr[0] + '-' + arr[1];
        }
    }
    return dt;
}
function ContentContainer() {
    if (document.getElementById && document.getElementsByName('ContentContainer') && window.screen.availWidth <= 800) {
        //document.getElementById('ContentContainer').style.width = '700'; // 95%=740px, 90%=700px 
        setContainerWidth('ContentContainer','700');
    } else if (document.getElementById && document.getElementsByName('ContentContainer') && window.screen.availWidth > 800) {
        //document.getElementsByName('ContentContainer').style.width = '870'; // 85%=870px, 80%=801px, 75%=751
        setContainerWidth('ContentContainer','870');
    }
}
function setContainerWidth(container, width) {
    for (i = 0; i < document.getElementsByName(container).length; i++) {
        document.getElementsByName(container)[i].style.width = width;
    }
}
function doMouseDown(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : '');
    elem = (evt.target) ? evt.target : evt.srcElement;
}
function doMouseUp(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : '');
    elem = (evt.target) ? evt.target : evt.srcElement;
}
