/*
     Common client-side functions

     Oleksandr Lishchuk

*/
function checkMail(emailstr)
{
  // list of inadmissible letters
  var WrongChars="#'()*+/;:,=<>?{}| " + '"';
  if (emailstr.length < 3) {
        return false;
  }else{
        for (i=0;i<WrongChars.length;i++)  {
             if (emailstr.indexOf(WrongChars.charAt(i),0)>-1)   {
                return false;
             }
        }
        var atPos;
        atPos=emailstr.indexOf('@',1);
        if (atPos==-1)
        {       
        return false;
        }
        if (emailstr.indexOf('@',atPos+1)!=-1) {
           return false;
        }
        var periodPos,p;
        periodPos=emailstr.indexOf('.',atPos+1);

        if (periodPos==-1) {
           return false;
        }
        var n;
        n=periodPos+1;
        while ( n <= emailstr.length)
        {
             if (emailstr.indexOf('.',n)==n) {
                if (emailstr.indexOf('.',n+1)==n+1){
                        return false;
                }else{
                        periodPos=n;
                        n+=2;
                }
             }else{
                n++;
             }
        }
        var l=emailstr.length;
        if ((periodPos+3>l) || (periodPos<l-4)) {
           return false;
        }
  return true
  }
}

function checkPhoneNum(iidee)
{
        var strHolder;
        var lengthHolder;
        strHolder = document.all(iidee).value;
        lengthHolder = strHolder.length;
        if(lengthHolder!=10)
        {
                        document.all.phone.value = 'Must be 10 digits!';
                        memberreg.phone.focus();
                        memberreg.phone.select();
        }
        //alert(lengthHolder);

}

function LoadItem(url, id) {

  //  if (window.netscape && netscape.security && netscape.security.PrivilegeManager.enablePrivilege) {
  //    netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead UniversalBrowserWrite');
  //  }

                  
    var element = document.getElementById(id);
    element.innerHTML = 'Loading ...';
    var xmlhttp;

    try {
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e) {
        try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
        } catch (e1) {
            try {
                  xmlhttp = new ActiveXObject("Microsoft.XMLDOM");
            } catch (e2) {
               try {
                  xmlhttp = new XMLHttpRequest();
               } catch (e3) {
                  xmlhttp=false
                  alert("Sorry, your Web Browser does not support XML. Please use IE5+ or NN 6.1+ or Mozilla compatable browser.");
                  return;
               }
            }
        }
    }

  
    xmlhttp.open("GET", url);
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            element.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.send(null);
}

function SetItem(id, stext) {

    var element = document.getElementById(id);
    element.innerHTML = stext;
}

function GetItem(id) {

    var element = document.getElementById(id);
    return element.innerHTML;

}

function Sleep(msec) {

    var t1 = new Date().getTime();
    while ( (new Date().getTime() - t1) < msec );
}

/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */

var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{

    var theCells = null;
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }


    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

  currentColor = theCells[0].style.backgroundColor;
  domDetect    = false;


    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0) 
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function


