/********************************************************
 mapfunc.js
 Created	: 19.june 2003, 08:00
 Author	: Powel Gemini As/jet,ks
 Purpose	: Javascript variables and functions for map.jsp
 History :
 - 19.03.2004 / ks
 References between frames has been altered. parent
 should allways be used instead of top.


 ********************************************************/

var undefined;
// For compability with IE 5 (and other earlier browsers). This is NOT an error! See http://www.webreference.com/programming/javascript/gr/column9/index.html

var iHeight = 0;
// MapHeight
var iWidth = 0;
// MapWidth
var currXMin = 0;
// MapExtension's
var currYMin = 0;
var currXMax = 0;
var currYMax = 0;
var theImageUrl = "";
var theLegendUrl = "";
var scale = "";

// Global variables to hold reference to frames
//var dTools = top.frames['ToolFrame'];
//var dTop = top.frames['TopFrame'];
//var dFooter = top.frames['FooterFrame'];
//var dProcess = top.frames['ProcessFrame'];
//var dImage = top.frames['ImageFrame'];
//var dEvent = top.frames['EventFrame'];
//var dDebug = top.frames['DebugFrame'];
//var dMap = top.frames['MapFrame'];

var dTools = parent.frames['ToolFrame'];
var dTop = parent.frames['TopFrame'];
var dLeftTop = parent.frames['LeftMenu1'];
var dFooter = parent.frames['FooterFrame'];
var dProcess = parent.frames['ProcessFrame'];
var dImage = parent.frames['ImageFrame'];
var dEvent = parent.frames['EventFrame'];
var dDebug = parent.frames['DebugFrame'];
var dMap = parent.frames['MapFrame'];
var dMapTabs = parent.frames['MapTabs'];
var dMap2Levels = parent.parent.frames['MapFrame'];
var dTop2Levels = parent.parent.frames['TopFrame'];


// Replace text in string
function SearchAndReplace(Content, SearchFor, ReplaceWith) {
    var tmpContent = Content;
    var tmpBefore = new String();
    var tmpOutput = new String();
    var intBefore = 0;
    var intAfter = 0;
    if (SearchFor.length == 0)
        return;
    while (tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase()) > -1) {
        // Get all content before the match
        intBefore = tmpContent.toUpperCase().indexOf(SearchFor.toUpperCase());
        tmpBefore = tmpContent.substring(0, intBefore);
        tmpOutput = tmpOutput + tmpBefore;
        // Get the string to replace
        tmpOutput = tmpOutput + ReplaceWith;
        // Get the rest of the content after the match until
        // the next match or the end of the content
        intAfter = tmpContent.length - SearchFor.length + 1;
        tmpContent = tmpContent.substring(intBefore + SearchFor.length);
    }
    return tmpOutput + tmpContent;
}


//performs a validation upon resolution is lower than 1025x768
function hasLowRes() {
    if ((screen.width < 1024) || (screen.height < 768)) {
        hasLowRes = true;
    }
    return hasLowRes;
}


// Check if valid int
function validInt(nr) {
    return (("" + parseInt(nr)) == nr);
}


// Check if string contains numbers
function hasNumber(str) {
    var valid = false;
    for (i = 0; i < str.length; i++) {
        if (validInt(str.substr(i, 1))) {
            valid = true;
        }
    }
    return valid;
}

// Check if string not just contains numbers
function hasOtherThanNumber(str) {
    var valid = false;
    for (i = 0; i < str.length; i++) {
        if (!validInt(str.substr(i, 1))) {
            valid = true;
        }
    }
    if (str.length < 0) {
        valid = true;
    }
    return valid;
}

// Check if string contains invalid character
function hasInvalidChar(str) {
    var valid = false;
    for (i = 0; i < str.length; i++) {
        if ((str.substr(i, 1) == '*') ||
            (str.substr(i, 1) == '%') ||
            (str.substr(i, 1) == '$') ||
            (str.substr(i, 1) == '?') ||
            (str.substr(i, 1) == '+') ||
            (str.substr(i, 1) == '=') ||
            (str.substr(i, 1) == '&') ||
            (str.substr(i, 1) == '@') ||
            (str.substr(i, 1) == "'")
                ) {
            valid = true;
        }
    }
    if (str.length < 0) valid = true;
    return valid;
}


// Trim string and supress blanks
function trim(inputString) {
    if (typeof inputString != "string") {
        return inputString;
    }
    var retValue = inputString;
    var ch = retValue.substring(0, 1);
    while (ch == " ") { // Check for spaces at the beginning of the string
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
    ch = retValue.substring(retValue.length - 1, retValue.length);
    while (ch == " ") { // Check for spaces at the end of the string
        retValue = retValue.substring(0, retValue.length - 1);
        ch = retValue.substring(retValue.length - 1, retValue.length);
    }
    while (retValue.indexOf("  ") != -1) {
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
    }
    return retValue;
}
