var IE=window.external&&(navigator.platform=="Win32"||(window.ScriptEngine&&ScriptEngine().indexOf("InScript")+1));
var FF=navigator.userAgent.toLowerCase();
var GC=(FF.indexOf("chrome")+1)?true:false;
var FF=(FF.indexOf("firefox")+1)?true:false;
var OP=window.opera&&window.print;
var NS=window.netscape&&!OP;

var ieVer=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; case 5.8:return 8; }}()||@*/0;
if(/MSIE 6.0/i.test(navigator.userAgent)) {ieVer=6;}

var domain = document.domain.split('.')
domain = domain[domain.length - 2] + '.' + domain[domain.length - 1]

/*
	Developed by Robert Nyman, http://www.robertnyman.com
	Code/licensing: http://code.google.com/p/getelementsbyclassname/
*/	
var getElementsByClassName = function (className, tag, elm){
	if (document.getElementsByClassName) {
		getElementsByClassName = function (className, tag, elm) {
			elm = elm || document;
			var elements = elm.getElementsByClassName(className),
				nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
				returnElements = [],
				current;
			for(var i=0, il=elements.length; i<il; i+=1){
				current = elements[i];
				if(!nodeName || nodeName.test(current.nodeName)) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	else if (document.evaluate) {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = "",
				xhtmlNamespace = "http://www.w3.org/1999/xhtml",
				namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)? xhtmlNamespace : null,
				returnElements = [],
				elements,
				node;
			for(var j=0, jl=classes.length; j<jl; j+=1){
				classesToCheck += "[contains(concat(' ', @class, ' '), ' " + classes[j] + " ')]";
			}
			try	{
				elements = document.evaluate(".//" + tag + classesToCheck, elm, namespaceResolver, 0, null);
			}
			catch (e) {
				elements = document.evaluate(".//" + tag + classesToCheck, elm, null, 0, null);
			}
			while ((node = elements.iterateNext())) {
				returnElements.push(node);
			}
			return returnElements;
		};
	}
	else {
		getElementsByClassName = function (className, tag, elm) {
			tag = tag || "*";
			elm = elm || document;
			var classes = className.split(" "),
				classesToCheck = [],
				elements = (tag === "*" && elm.all)? elm.all : elm.getElementsByTagName(tag),
				current,
				returnElements = [],
				match;
			for(var k=0, kl=classes.length; k<kl; k+=1){
				classesToCheck.push(new RegExp("(^|\\s)" + classes[k] + "(\\s|$)"));
			}
			for(var l=0, ll=elements.length; l<ll; l+=1){
				current = elements[l];
				match = false;
				for(var m=0, ml=classesToCheck.length; m<ml; m+=1){
					match = classesToCheck[m].test(current.className);
					if (!match) {
						break;
					}
				}
				if (match) {
					returnElements.push(current);
				}
			}
			return returnElements;
		};
	}
	return getElementsByClassName(className, tag, elm);
};

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (true) {
            curleft += obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj = obj.offsetParent;
        }
    } else if(obj.x) {
        curleft += obj.x;
    }
    return curleft;
  }

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (true) {
            curtop += obj.offsetTop;
            if(!obj.offsetParent) {
                break;
            }
            obj = obj.offsetParent;
        }
    } else if(obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

Element.Methods.opacityTrans = function(element, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var i, timer = 0;
    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout(element.changeOpac.bind(element, i), (timer * speed));
            timer++;
        }
    } else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++) {
            setTimeout(element.changeOpac.bind(element, i), (timer * speed));
            timer++;
        }
    }
}
//change the opacity for different browsers
Element.Methods.changeOpac = function(element, opacity) {
    var object = element.style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

Element.Methods.fadeIn = function(element, speed, opacEnd) {
    if (opacEnd == null) opacEnd = 100
    element.opacityTrans(0, opacEnd, speed)
}

Element.Methods.fadeOut = function(element, speed, opacEnd) {
    if (opacEnd == null) opacEnd = 0
    element.opacityTrans(100, opacEnd, speed)
}

Element.Methods.disable = function(element, color) {
    if (element.style) element.style.color = color || '#666'
    element.disabled = true
}

Element.Methods.enable = function(element, color) {
    if (element.style) element.style.color = color || '#000'
    element.disabled = false
}

Array.prototype.includeObject = function(object) {
    var found = false;
    this.each(function(value) {
        if (typeof value == typeof object) {
            var serial1 = serialize(value)
            var serial2 = serialize(object)
            if (serial1 == serial2) {
                found = true;
                throw $break;
            }
        }
    });
    return found;
}

Array.prototype.indexOfObject = function(object) {
    var result = false;
    this.each(function(value, index) {
        if (typeof value == typeof object) {
            var serial1 = serialize(value)
            var serial2 = serialize(object)
            if (serial1 == serial2) {
                result = index;
                throw $break;
            }
        }
    });
    return result;
}


function selectElement(element) {
    if (document.selection) {
        var range = document.body.createTextRange();
        range.moveToElementText(element);
        range.select();
    } else if (window.getSelection) {
        var range = document.createRange();
        range.selectNodeContents(element);
        var selection = window.getSelection();
        selection.removeAllRanges();
        selection.addRange(range);
    }
}

function isHidden(element) {
    if (typeof(element) == 'string') {
        element = document.getElementById(element)
    }
    return (element.style.display == 'none')
}

function mostrar(element, estilo) {
    if (typeof(element) == 'string') {
        element = document.getElementById(element)
    }
    if (element.style) {
        estilo = (estilo == null) ? 'inline' : estilo
        if (element.style.setProperty) {
            element.style.setProperty('display', estilo, 'important')
        } else {
            element.style.display = estilo
        }
    }
}

function ocultar(element) {
    if (typeof(element) == 'string') {
        element = document.getElementById(element)
    }
    if (element.style) {
        if (element.style.setProperty) {
            element.style.setProperty('display', 'none', 'important')
        } else {
            element.style.display = 'none'
        }
    }
}

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function goUrl(main, second, lang) {
    var url = 'http://' 
    if (lang.length) {
        url += lang + '.'
    }
    url += domain + '/go/' + URLEncode(main)
    if (second.length) {
        url += '/' + URLEncode(second)
    }
    return url
}

function keywordName(main, second) {
    var result = main
    if (second.length) {
        result += ' (' + second + ')'
    }
    return result
}

function parseKeyword(keyword) {
    var result = []
    keyword = keyword.trim()
    if (keyword.indexOf('(') > -1) {
        result = keyword.split('(')
        result[0] = result[0].trim()
        result[1] = result[1].substr(0, result[1].length - 1)
    } else {
        result[0] = keyword
        result[1] = ''
    }
    return result
}

String.prototype.trim = function() {
    var s = this.replace(/\s+/gi, ' ');        // quitar espacios repetidos, dejando solo uno
    s = s.replace(/^\s+|\s+$/gi, '');   // quitar espacios blanco principio y final

    return s;
}

/**
 * sprintf() for JavaScript v.0.4
 *
 * Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
 * Thanks to David Baird (unit test and patch).
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 */

function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }

function sprintf () {
  var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
  while (f) {
    if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
    else if (m = /^\x25{2}/.exec(f)) o.push('%');
    else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
      if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
      if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
        throw("Expecting number but found " + typeof(a));
      switch (m[7]) {
        case 'b': a = a.toString(2); break;
        case 'c': a = String.fromCharCode(a); break;
        case 'd': a = parseInt(a); break;
        case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
        case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
        case 'o': a = a.toString(8); break;
        case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
        case 'u': a = Math.abs(a); break;
        case 'x': a = a.toString(16); break;
        case 'X': a = a.toString(16).toUpperCase(); break;
      }
      a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
      c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
      x = m[5] - String(a).length;
      p = m[5] ? str_repeat(c, x) : '';
      o.push(m[4] ? a + p : p + a);
    }
    else throw ("Huh ?!");
    f = f.substring(m[0].length);
  }
  return o.join('');
}

function setCookie(name, value, expiredays, path, domain, secure) {
    var expires = ''
    if (expiredays != null) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        expires = ";expires=" + exdate.toGMTString()
    }
    document.cookie = name + "=" + escape(value) + expires +
        ( ( path ) ? ";path=" + path : "" ) +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        ( ( secure ) ? ";secure" : "" );
}

function getCookie(name) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split(';');
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';

	for (var i = 0; i < a_all_cookies.length; i++ )	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split('=');
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].trim();
		// if the extracted name matches passed name
		if (cookie_name == name) {
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if (a_temp_cookie.length > 1) {
				cookie_value = unescape(a_temp_cookie[1].trim());
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
    return null;
}
	
function deleteCookie(name, path, domain) {
    var expires = ';expires=Thu, 01-Jan-70 00:00:01 GMT'
    var value = ''
    document.cookie = name + "=" + value +
        ( ( path ) ? ";path=" + path : "") +
        ( ( domain ) ? ";domain=" + domain : "" ) +
        expires;
}

// Add messages to the user message area
function addUserMessage(text) {
    var container = document.getElementById('header-messages');
    var newdiv = document.createElement('div');
    newdiv.setAttribute('class', 'updated');
    newdiv.innerHTML = '<p><strong>'+text+'</strong></p>';
    container.appendChild(newdiv);    
}

// http://www.strictly-software.com/eventsupport.htm
var TAGNAMES = {
    'select':'input','change':'input',
    'submit':'form','reset':'form',
    'error':'img','load':'img','abort':'img'
}
var cache = {}
function isEventSupported(eventName) {
    var key = (TAGNAMES[eventName] ||
        (eventName == "unload" || eventName == "resize") ? "window" : "div") + "_" + eventName;
    if (cache[key]) {
        return cache[key];
    }
    var el = document.createElement(TAGNAMES[eventName] || "div");
    var oneventName = "on" + eventName.toLowerCase();
    var isSupported = oneventName in el;
    if (!isSupported && (eventName == "unload" || eventName == "resize")) {
        isSupported = oneventName in win;
    }
    if (!isSupported && el.setAttribute) {
        el.setAttribute(oneventName, "return;");
        isSupported = typeof el[oneventName] == "function";
    }
    if (!isSupported && typeof win == "object" && win.Event && typeof win.Event == "object") {
        isSupported = eventName.toUpperCase() in win.Event;
    }
    el = null;
    cache[key] = isSupported;
    return isSupported;
}

// Vector de funciones que se llamarán en el onLoad
var _onload = new Array()
// Añade una llamada al vector
function onLoad(event) {
    _onload[_onload.length] = event
}

// Ejecuta todas las llamadas del vector
function load(event) {
    for (var i = 0; i < _onload.length; i++) {
        eval(_onload[i])
    }
}
window.onload = load

// Make help system links open in a new window.
function openInNewWindow(newContent) {
    window.open(newContent, 'nextWin', 'width=1002,height=675,toolbar=yes,scrollbars=yes,resizable=yes');
//    winContent.focus();
}
function externalLink(e) {
    var elem = getTarget(e)
    if (elem.href && (elem.href.toLowerCase().indexOf("/help/") != -1)) {
        openInNewWindow(elem.href);
        Event.stop(e)
    }
}
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i = 0; i < anchors.length; i++) {
        addEvent(anchors[i], 'click', externalLink);
    }
}
onLoad('externalLinks()')


