//NUA = navigator.userAgent;
//by SB
// Browser detection
//
NUA = navigator.userAgent;
bFIREFOX = (NUA.indexOf("Firefox") != -1);
bOPERA = (NUA.indexOf('Opera') != -1);
bSAFARI = (NUA.indexOf('Safari') != -1);
bKONQUEROR = (!bSAFARI && (NUA.indexOf('Konqueror') != -1) ) ? true : false;
bMOZILLA= ((!bSAFARI && !bKONQUEROR ) && ( NUA.indexOf('Gecko') != -1 ) ) ? true : false;
bIE = ((NUA.indexOf('MSIE') != -1) && !bOPERA);
bWEB = true;  //used everywhere
if(window.location.toString().substring(0,4) == "file") {
    bWEB = false;  
    URLPATH = '';
}
//oLOCAL = window.location; // do we use it?

// should be set to 0 when pushing.
iDEBUG = 0; //  0 for production, changes servletpath below and in bottom.js hard links videoTour and forum.
//iDEBUG = 10; //  10 for development, 0 for production
SERVLETPATH = 'http://thermo.sdsu.edu/servlet';
FORUMLINK = 'blog/MyBlog.html';
VIDEOLINK = 'visualtour/index.html';
if(iDEBUG == 0){
    SERVLETPATH = 'http://test.sdsu.edu/servlet';
    FORUMLINK = 'http://test.sdsu.edu/testhome/blog/MyBlog.html';
    if(!bWEB) {
        VIDEOLINK = 'http://test.sdsu.edu/testhome/visualtour/index.html';
    }
}
bINPUT = false; // used for treating the chapters in commit vs. update mode.


//  check if the string ends with sSuffix
String.prototype.beginsWith = function (sPrefix){
    var sLong = this.toString();
    var sNew = sLong;
    var nLong = sLong.length;
    var nShort = sPrefix.length;
    var result = false;
    if(nLong>=nShort){
        var sSubString = sLong.substring(0,nShort);
        if (sSubString == sPrefix) result = true;
    }
    return result;        
}
    //used everywhere to check type of variable (undeclared)
function bIsDefined(variable) {
    return(typeof(variable) == 'undefined' ? false : true);
}
//  remove space and end of line from beginning and end
String.prototype.trim = function (){
    var str = this.toString();
    while (str.substring(0,1) == ' '){ // don't take out new line in the beginning (think blog)
        str = str.substring(1, str.length);
    }
    while (str.substring(str.length-1, str.length) == ' '|| str.substring(str.length-1, str.length) == '\n'){
        str = str.substring(0,str.length-1);
    }
    return str;
} 
//  test if string contains a char
String.prototype.containsChar = function (c){
    var str = this.toString();
    return (str.indexOf(c)!==-1); 
}

//function sleep(millis) {
//	setTimeout((yield CONTINUATION), millis);
//	yield SUSPEND;
//}

/**
 * Extracts and returns the content within a SOAP response message.
 *
 * @param  responseXML  SOAP response message
 * @return return tag content
 */
function getSOAPReturnData(responseXML) {
    var returnData = "";

    try {
        var root = responseXML.documentElement;
        var nodeList = root.getElementsByTagName("return");     // DOM 1,2
        if(nodeList[0].hasChildNodes()) {
            children = nodeList[0].childNodes;
            for(var i=0; i<children.length; i++) {
                returnData += children[i].nodeValue;            // DOM 1
                // returnData += children[i].textContent;       // Mozilla only?
                // returnData += children[i].data;              // DOM 1,2
            }
        }
    } catch(e) {
        noop();
    }

    //alert("in soap return done");
    return returnData;
}


// used to check if enter key is pressed
function bEnterEvent(e){
    var key=0;
    if(window.event) key = window.event.keyCode;     //IE
    else key = e.which;     //firefox
    return (key == 13);
}

// clonnig any object, including an arrays
Object.prototype.clone = function() {
  var newObj = (this instanceof Array) ? [] : {};
  for (i in this) {
    if (i == 'clone') continue;
    if (this[i] && typeof this[i] == "object") {
      newObj[i] = this[i].clone();
    } else newObj[i] = this[i]
  } return newObj;
};

// some commonly used global helper functions.
function noop() {
    // No operation
}
