// JavaScript Document
function intval(e){
	if(isNaN(parseInt(e))){
		return 0;
	}else{
		return parseInt(e);
	}
}
function fireEvent(element,event){
    if (document.createEventObject){
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)
    }
    else{
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);
    }
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

Prototype.Browser.IE6 = Prototype.Browser.IE && parseInt(navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE")+5))==6;
Prototype.Browser.IE7 = Prototype.Browser.IE && !Prototype.Browser.IE6;


if (!document.ELEMENT_NODE) {
  document.ELEMENT_NODE = 1;
  document.ATTRIBUTE_NODE = 2;
  document.TEXT_NODE = 3;
  document.CDATA_SECTION_NODE = 4;
  document.ENTITY_REFERENCE_NODE = 5;
  document.ENTITY_NODE = 6;
  document.PROCESSING_INSTRUCTION_NODE = 7;
  document.COMMENT_NODE = 8;
  document.DOCUMENT_NODE = 9;
  document.DOCUMENT_TYPE_NODE = 10;
  document.DOCUMENT_FRAGMENT_NODE = 11;
  document.NOTATION_NODE = 12;
}
if(!document.importNode){

	document.importNode=function(p1,p2){
		xmlImportNode(document, p1, p2);
	};
}
document.createElementN = function (name, value) {
	v=document.createElement(name);
	if(value){
		n=document.createTextNode(value);
		v.appendChild(n);
	}
	return v;
}
function createNamedElement(dest, type, name) {
   var element = null;
   // Try the IE way; this fails on standards-compliant browsers
   try {
      element = dest.createElement('<'+type+' name="'+name+'">');
   } catch (e) {
   }
   if (!element || element.nodeName != type.toUpperCase()) {
      // Non-IE browser; use canonical method to create named element
      element = dest.createElement(type);
      element.name = name;
   }
   return element;
}







// MyNamespaceResolver
 
GoetasNamespaceResolver.prototype = new NamespaceResolver();
GoetasNamespaceResolver.prototype.constructor = GoetasNamespaceResolver;
GoetasNamespaceResolver.superclass = NamespaceResolver.prototype;
 
function GoetasNamespaceResolver() {
}
 
GoetasNamespaceResolver.prototype.getNamespace = function(prefix, n) {
  switch (prefix.toLowerCase().replace("/","").trim()) {
	 case "aj":
		return "AjaxForms";
	 case "xhtml":
	 case "html":
	 case "":
		return "http://www.w3.org/1999/xhtml";
  }
  //return this.superclass.getNamespace(prefix, n);
};





function gXPath(query){
	 
	// Create a new parser object
	this.parser = new XPathParser();
	 
	// Parse the XPath expression
	this.xpath = this.parser.parse(query);
	
	
	gxpath=this;

	this.evaluate = function (node){
		// Create a context for the XPath to be evaluated in

		context = new XPathContext(new VariableResolver(),new GoetasNamespaceResolver(),new FunctionResolver());

		context.expressionContextNode = node;

		return gxpath.xpath.evaluate(context).toArray();
	}
}




/* XMLDOM */

var userAgent = { };
userAgent.isOpera            = (navigator.userAgent.match(/\bOpera\b/));
userAgent.isInternetExplorer = (navigator.userAgent.match(/\bMSIE\b/) && !userAgent.isOpera);
userAgent.isMozilla          = (navigator.userAgent.match(/\bGecko\b/));
userAgent.isKHTML            = (navigator.userAgent.match(/\b(Konqueror|KHTML)\b/));

// Implements the Document.importNode DOM method. If the browser implements
// importNode natively, then that implementation is used.
//
// Parameters:
//     xmlDocument: The document to which to import the node.
//     node:        The node to import.
//     deep:        True to import all of the node's children, false to only
//                  import the node and its attributes.

function xmlImportNode(xmlDocument, node, deep) {
  if (typeof(xmlDocument.importNode) != "undefined" && !userAgent.isInternetExplorer) {
    // If using Opera and importing a node to the HTML document, we need to fix the
    // fake "-in-opera" namespace URI used. See loadDocument.js for more information
    // about this.
    if (!(xmlDocument == document && userAgent.isOpera)) {
      return xmlDocument.importNode(node, deep);
    }
  }
  var isHtml  = (xmlDocument.documentElement && xmlDocument.documentElement.tagName.toLowerCase() == "html");
  var newNode = null;

  switch (node.nodeType) {
    case 1: // Element
      if (xmlDocument.createElementNS) {
        newNode = xmlDocument.createElementNS(node.namespaceURI, node.nodeName);
      }
      else {
        newNode = xmlDocument.createElement(node.nodeName);
      }

      var atts   = node.attributes; 
      var attLen = atts.length;
      for (var i = 0; i < attLen; ++i) {
        var attribute = atts.item(i);

        if (attribute.specified && attribute.value) {
          newNode.setAttribute(attribute.name, attribute.value);
		  
         
          if (isHtml && userAgent.isInternetExplorer) {
            // Many attributes don't take effect unless you set them via element.property
            // syntax. Also, some of these properties are named/capitalized differently.
			
			//  register event handlers for IE, added by ASMIR, require prototype
 			if(attribute.name.substring(0,2)=="on"){
				eval("f=function(){"+attribute.value+"}");
				//Event.observe(newNode, attribute.name.substring(2),f);
				
				
				eval("newNode.attachEvent(\""+attribute.name+"\", f.bindAsEventListener(newNode));");
				
				//return;
			}		
			
            switch (attribute.name) {
              case "colspan":     newNode.colSpan       = attribute.value; break;
              case "rowspan":     newNode.rowSpan       = attribute.value; break;
              case "cellspacing": newNode.cellSpacing   = attribute.value; break;
              case "cellpadding": newNode.cellPadding   = attribute.value; break;
              case "style":       newNode.style.cssText = attribute.value; break;
              case "class":       newNode.className     = attribute.value; break;
              
              default:
                newNode[attribute.name] = attribute.value;
                break;
            }
          }
        }
      }

      break;

    case 2: // Attribute
      if (xmlDocument.createAttributeNS) {
        newNode = xmlDocument.createAttributeNS(node.namespaceURI, node.name);
      }
      else {
        newNode = xmlDocument.createAttribute(node.name);
      }
    
      newNode.value = node.value;
      break;

    case 3: // Text
      newNode = xmlDocument.createTextNode(node.data);
      break;

    case 4: // CDATA section
      newNode = xmlDocument.createCDATASection(node.data);
      break;

    case 5: // Entity reference
      newNode = xmlDocument.createEntityReference(node.nodeName);
      break;

    case 7: // Processing instruction
      newNode = xmlDocument.createProcessingInstruction(node.target, node.data);
      break;

    case 8: // Comment
      newNode = xmlDocument.createComment(node.data);
      break;

    case 11: // Document fragment
      newNode = xmlDocument.createDocumentFragment();
      break;

    default:
      throw new XmlException("Cannot import node: " + node.nodeName);
  }

  if (deep) {
    for (var child = node.firstChild; child != null; child = child.nextSibling) {
      newNode.appendChild(xmlImportNode(xmlDocument, child, true));
    }
  }
  
  return newNode;
};

function isTextNode(node) {
  return node.nodeType == 3 || node.nodeType == 4;
};







// Copyright (c) 2000-2005 Progeny Systems Corporation.
//
// Consult license.html in the documentation directory for licensing
// information.


// Creates a new XML document with the specified document element. If
// unspecified, an element called "root" with no namespace is created.
//
// Opera does not allow the creation of a document without a root element, so it
// is not possible to create a completely blank document with this function.
// Furthermore, in Opera you cannot change, rename, or remove the document
// element either.
//
// Parameters:
//     documentElement: The root element of the document. 
function xmlNewDocument(documentElement) {
  if (documentElement == null) {
    documentElement = document.createElement("root");
  }
  
  if (document.implementation && document.implementation.createDocument) {
    var xmlDocument = document.implementation.createDocument(documentElement.namespaceURI, documentElement.tagName, null);
  }
  else if (typeof(window.ActiveXObject) != "undefined") {
    var xmlDocument = xmlNewMSXMLDocument();
  }
  else {
    throw new XmlException("Incompatible web browser; cannot create new XML document.");
  }
  
  if (documentElement) {
    documentElement = xmlImportNode(xmlDocument, documentElement, true);
    
    if (xmlDocument.firstChild) {
      while (documentElement.hasChildNodes()) {
        xmlDocument.firstChild.appendChild(documentElement.firstChild);
      }
      
      var isHtml = (documentElement.tagName.toLowerCase() == "html");
      var atts   = documentElement.attributes;
      
      for (var i = atts.length - 1; i >= 0; --i) {
        var attribute = atts.item(i);

        if (attribute.specified && attribute.value) {
          xmlDocument.firstChild.setAttribute(attribute.name, attribute.value);
          
          if (isHtml && userAgent.isInternetExplorer) {
            // Many attributes don't take effect unless you set them via element.property
            // syntax. Also, some of these properties are named/capitalized differently.
            switch (attribute.name) {
              case "colspan":     xmlDocument.firstChild.colSpan       = attribute.value; break;
              case "rowspan":     xmlDocument.firstChild.rowSpan       = attribute.value; break;
              case "cellspacing": xmlDocument.firstChild.cellSpacing   = attribute.value; break;
              case "cellpadding": xmlDocument.firstChild.cellPadding   = attribute.value; break;
              case "style":       xmlDocument.firstChild.style.cssText = attribute.value; break;
              case "class":       xmlDocument.firstChild.className     = attribute.value; break;
              
              default:
                xmlDocument.firstChild[attribute.name] = attribute.value;
                break;
            }
          }
        }
      }
      
    }
    else {
      xmlDocument.appendChild(documentElement);
    }
  }
  
  return xmlDocument;
};

// Returns an MSXML ActiveX DOM document, trying different program IDs until it
// finds one that works.
function xmlNewMSXMLDocument() {
  var programIds = xmlNewMSXMLDocument.programIds;
  
  while (programIds.length > 0) {
    try {
      return new ActiveXObject(programIds[0]);
    }
    catch (e) {
      // Didn't work. Try the next program.
      programIds.shift();
    }
  }
  
  throw new XmlException("Unable to create new MSXML DOM document.");
};

xmlNewMSXMLDocument.programIds = [
  "Msxml2.DOMDocument.5.0",
  "Msxml2.DOMDocument.4.0",
  "Msxml2.DOMDocument.3.0",
  "MSXML2.DOMDocument",
  "MSXML.DOMDocument",
  "Microsoft.XMLDOM"
];










var FrameworkUtils = {DOMLoaded:false};
document.observe('dom:loaded', function () { window.FrameworkUtils.DOMLoaded=true; });









