
function trim_i(i) {
    return i.replace(/^\s+|\s+$/g, '');
}


function IsEmpty(id) {
    var input_text = document.getElementById(id).value;
    if (trim_i(input_text) == '')
        { return true; }
    else
        { return false; }
}

function IsMatching(id_1, id_2)
{
    var input_text_1 = document.getElementById(id_1).value;
    var input_text_2 = document.getElementById(id_2).value;
    
    if (input_text_1 == input_text_2)
        {return true;}
    else
        {return false;}
}


function IsEmail(id)
{
    var email_filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (email_filter.test(document.getElementById(id).value))
        {return true ;}
    else
        {return false;}
     }


function GetPos(e) {

    var e = document.getElementById(e);

    var obj = e;

    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;

    var obj = e;

    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;


    return { x: curleft, y: curtop };
}



function SelectVisibility(visibility) {

    var selElements = document.getElementsByTagName('select')
    var sel
    
    for ( sel in selElements) {
        if (document.getElementById(sel))
        { document.getElementById(sel).style.visibility = visibility }
    }



}

// **********************************************************//


function IsCustomerUserNameAvailable(user_name) {
    var IsAvailable = false


    IsAvailable = DataPost('/customer/customer_functions.asp', 'function=IsCustomerUserNameAvailable&user_name=' + escape(user_name) );
    
    return IsAvailable;

}


// **********************************************************//




function DataPost(post_action, post_data) {
    var ret;
    var xmlhttp;
    var sPath = window.location.host;

    var url = 'http://' + sPath + post_action;
    if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.open("POST", url, false);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlhttp.send(post_data);

    }
    else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp) {
            xmlhttp.open("POST", url, false);

            xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            xmlhttp.send(post_data);
        }
    }

    ret = xmlhttp.responseText;

    return ret;

}

// **********************************************************//

// **********************************************************//



function FormDisplay(form_container, action) {
    var DetailDisplayState
    if (action == 'hide') {
        DetailDisplayState = 'none'
        document.getElementById('modal_overlay').style.display = DetailDisplayState;
        SelectVisibility('visible');
        document.getElementById(form_container).style.display = DetailDisplayState;

    }
    else if (action == 'show') {
        DetailDisplayState = 'block';


        var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body


        var dsoctop = document.all ? iebody.scrollTop : window.pageYOffset;
        var dsocleft = document.all ? iebody.scrollLeft : window.pageXOffset;
        var windowheight = windowheight = document.all ? iebody.clientHeight : window.innerHeight;
        var windowwidth = windowwidth = document.all ? iebody.clientWidth : window.innerWidth;

        document.getElementById('modal_overlay').style.display = DetailDisplayState;
        document.getElementById('modal_overlay').style.height = document.body.scrollHeight + 'px';
        document.getElementById('modal_overlay').style.width = document.body.scrollWidth + 'px';
        SelectVisibility('hidden');


        document.getElementById(form_container).style.display = DetailDisplayState;

        var wOffset = document.getElementById(form_container).offsetWidth;
        var hOffset = document.getElementById(form_container).offsetHeight;

        document.getElementById(form_container).style.top = ((windowheight - hOffset) / 2) + dsoctop + 'px';
        document.getElementById(form_container).style.left = ((windowwidth - wOffset) / 2) + dsocleft + 'px';

    }

}



// **********************************************************//
